-
Notifications
You must be signed in to change notification settings - Fork 4
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
base: main
Are you sure you want to change the base?
feat(gres)!: add mappings for managing GRESName
and GRESNode
objects
#40
Conversation
`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]>
Signed-off-by: Jason C. Nucciarone <[email protected]>
Signed-off-by: Jason C. Nucciarone <[email protected]>
There was a problem hiding this 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] |
There was a problem hiding this comment.
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?
This PR adds the
GRESNameMapping
andGRESNodeMapping
objects to make it easier to manage gres.conf data model objects. Rather than throw lists and dictionaries out there all loosey goosey forGRESConfig
, 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:jsonschema
. Helps make sure the input we're putting into the maps are valid.jsonschema
and send "across the wire," but still enable us to take advantage of the data models and the descriptors + methods that they provide.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.BaseMapping
object to provide methods necessary forGRESNameMapping
andGRESNodeMapping
, but in the future I could seeBaseMapping
becoming the newBaseModel
. The classes do similar things, butBaseMapping
is more flexible and uses JSON schemas to validate the data models.Breaking changes
The
names
andnodes
properties fromGRESConfig
now returnGRESNameMapping
andGRESNodeMapping
objects respectively rather thanlist
anddict
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 thetyping-extensions
module. This is an official module maintained by the Python team. I bring it in as dependency since it provides theSelf
type which wasn't introduced into Python until 3.11. Sincepy310
is still a supported Python version, figured it doesn't hurt to bringtyping-extensions
in.MutableMapping
andSequence
are the recommend annotations for arguments that are either typedict
orlist
respectively.