Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(gres)!: add mappings for managing GRESName and GRESNode objects #40

Open
wants to merge 5 commits into
base: main
Choose a base branch
from

Conversation

NucciTheBoss
Copy link
Member

This PR adds the GRESNameMapping and GRESNodeMapping objects to make it easier to manage gres.conf data model objects. Rather than throw lists and dictionaries out there all loosey goosey for GRESConfig, instead these new maps help facilitate interacting with the configured generic resources and easily share them between the slurmctld and slurmd operators. Couple key changes:

  • There's now stricter validation for the gres.conf related models by using jsonschema. Helps make sure the input we're putting into the maps are valid.
  • Methods for encoding and decoding dictionaries with nested data models. Makes it easier to validate with jsonschema and send "across the wire," but still enable us to take advantage of the data models and the descriptors + methods that they provide.
    • The expand function is an anamorphism that recursively expands a dictionary with nested data model objects. This makes it easier to punch objects into a JSON schema validator. Custom object hooks are used with the JSON decoder to parse the data models back into Python objects.
  • I introduced a BaseMapping object to provide methods necessary for GRESNameMapping and GRESNodeMapping, but in the future I could see BaseMapping becoming the new BaseModel. The classes do similar things, but BaseMapping is more flexible and uses JSON schemas to validate the data models.

Breaking changes

The names and nodes properties from GRESConfig now return GRESNameMapping and GRESNodeMapping objects respectively rather than list and dict types.

Related issues

Misc.

  • I updated the annotations for some functions to be compliant with recommendations set forth by Python 3.10. Big thing is that the many of the types provided by the typing module are now deprecated, so their imports are now updated. Another thing is the inclusion of the typing-extensions module. This is an official module maintained by the Python team. I bring it in as dependency since it provides the Self type which wasn't introduced into Python until 3.11. Since py310 is still a supported Python version, figured it doesn't hurt to bring typing-extensions in.

    MutableMapping and Sequence are the recommend annotations for arguments that are either type dict or list respectively.

`jsonschema` is now included as a dependency to help validate Slurm
data models as they're exchanged between classes and read in.
`typing-extensions` is added because the `Self` type annotation
is not available within Python 3.10 add is still a support version
of Python for security maintenance and Jammy Jellyfish.

Signed-off-by: Jason C. Nucciarone <[email protected]>
Changes:

* Change `names` and `nodes` property on `GRESConfig` to return `GRESNameMapping` and `GRESNodeMapping` respectively.
* Add `_slice` method to enable quick slicing of the internal data store dictionaries.
* Add `BaseMapping` ABC that can be used to create other mappings that can be used within slurm.conf files.
* Add `expand` method for recursively expanding dictionaries with nested Slurm data model objects.
* Introduce JSON schemas for validating `GRESNameMapping` and `GRESNodeMapping` objects.
* Define JSON decoders that can be used to parse dictionary objects into Slurm data models.

Signed-off-by: Jason C. Nucciarone <[email protected]>
Changes:

* Add addition test case where the same `NodeName` can have multiple generic resource configurations.

Signed-off-by: Jason C. Nucciarone <[email protected]>
@NucciTheBoss NucciTheBoss added the Type: Enhancement Proposes a new feature to be added to the project. label Dec 20, 2024
Copy link

@dsloanm dsloanm left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good and solves the issue I was hitting!

I've not spotted the stricter validation, however. I accidentally generated a few invalid gres.conf files when testing since I can get away with things like:

$ python
Python 3.12.3 (main, Nov  6 2024, 18:32:19) [GCC 13.2.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> from slurmutils.editors import gresconfig
>>> with gresconfig.edit("gres-testing.conf") as config:
...   config.nodes["123"] = [456]
... 
>>> 
$ cat gres-testing.conf
456
$

config.names.append(name.dict())
config.nodes.updaten(node.dict())
config.names[new_gres.name] = [new_gres]
config.nodes[new_node.node_name] = [new_node]
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

NodeName is both the key and a value?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Type: Enhancement Proposes a new feature to be added to the project.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Support for multiple lines with same NodeName in gres.conf
2 participants