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

Support python dict in sysctl_create #15

Merged
merged 4 commits into from May 2, 2018

Conversation

javacruft
Copy link
Collaborator

Add support for directly passing a python dict rather than a
YAML formatted string to sysctl_create to make it easier for
charms to set sane defaults without hopping via YAML first.

Add support for directly passing a python dict rather than a
YAML formatted string to sysctl_create to make it easier for
charms to set sane defaults without hopping via YAML first.
Copy link
Collaborator

@ajkavanagh ajkavanagh left a comment

Choose a reason for hiding this comment

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

Just a thought on the dict detection and possibly making it more flexible.

log("Error parsing YAML sysctl_dict: {}".format(sysctl_dict),
level=ERROR)
return
if type(sysctl_dict) is not dict:
Copy link
Collaborator

Choose a reason for hiding this comment

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

This would probably be more flexible if it used:

if isinstance(syctl_dict, dict):

as it would allow dict like objects to also be used. If you wanted to be really flexible, then you could use:

if isinstance(sysctl_dict, collections.abc.Mapping):

Then it would allow any object that supports the dictionary specific methods (e.g. getattr, iter, etc.) to be used.

log("Error parsing YAML sysctl_dict: {}".format(sysctl_dict),
level=ERROR)
return
if type(sysctl_dict) is not dict:
Copy link
Contributor

Choose a reason for hiding this comment

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

You might consider using if not isinstance(sysctl_dict, collections.Mapping): instead, on the off chance that the charm wants to pass in, e.g., an OrderedDict instead. Not really a blocker, though, since the order wouldn't be preserved with the existing code, either.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Indeed, collections.Mapping is Py2 compatible.

Copy link
Contributor

Choose a reason for hiding this comment

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

importing collections.Mapping raises a warning under Py3.7, and should be collections.abc.Mapping. We might need a conditional import.

@johnsca johnsca merged commit 1ee7022 into juju:master May 2, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants