Add script which compares two minions#1
Conversation
akaRem
left a comment
There was a problem hiding this comment.
Please check your code with pylint and add some more annotations. In general it should work. But output is surprise for everyone. If you are going to use it as executable, then it's a very good idea to add simple CLI wrapper with help and brief description.
| Fore = Back = Style = ColorFallback() | ||
|
|
||
| def color_diff(diff): | ||
| '''Colorize lines in the diff generator object''' |
There was a problem hiding this comment.
PEP257 docstring should be enclosed in """ ... """
|
|
||
| diffs = {} | ||
| for key in comparable_properties: | ||
| diffs[key] = color_diff ( |
There was a problem hiding this comment.
style: extra space betw. func name and parens
| ) | ||
|
|
||
| result = "\n".join( | ||
| [ |
There was a problem hiding this comment.
you may use ( .. ) instead of [ .. ] here
| ) | ||
| return result | ||
|
|
||
|
|
There was a problem hiding this comment.
if __name__ == '__main__': ... otherwise this module will execute following lines on import
|
|
||
| @property | ||
| def pillar_items(self): | ||
| return json.loads(json.dumps(self.salt['pillar.items'](saltenv='javaci'))) |
There was a problem hiding this comment.
why to dump and load?? If this is some kind of workaround, please add annotations
| indent=4 | ||
| ) | ||
|
|
||
| def minions_diff(minionA, minionB): |
There was a problem hiding this comment.
It would be more reusable in form of class
| "\n".join( [key.upper(), "\n".join(value)] ) for key, value in diffs.items() | ||
| ] | ||
| ) | ||
| return result |
There was a problem hiding this comment.
result lives for 2 lines. You can throw it away
| ) | ||
| ) | ||
|
|
||
| result = "\n".join( |
There was a problem hiding this comment.
please add output example as this templating is very complex and hard to trace
| ) | ||
|
|
||
| def minions_diff(minionA, minionB): | ||
| '''Generate multiline string from colorized diffs''' |
There was a problem hiding this comment.
Actually not. this generates multiline colorized diff from 2 minions. And you don't have any functionality for jyst getting colorized or non-colorized diff.
|
|
||
| default_config = '/opt/{name}/minion' | ||
|
|
||
| def __init__(self, name=None, config=None): |
There was a problem hiding this comment.
config is not used and could be removed from params, so name is one and only required param (as far as I see from this script)
Script can be used to compare pillars, highstates and grains for two minions, or for two different snapshots of the salt states code. To use it for pull request verification one can: 1) checkout destination branch to dirA, 2) checkout pull-request branch to dirB, 3) setup minion config /opt/minionA/minion to use states and pillars from dirA 4) setup minion config in /opt/minionB/minion to use states and pillars from dirB 5) put the same grains file into /opt/minionA/grains and /opt/minionB/grains 6) run the script This way you'll get the difference given by the salt states code changes applied to the same minion (i.e. grains input)
Script can be used to compare pillars, highstates and grains for two minions,
or for two different snapshots of the salt states code.
To use it for pull request verification one can:
This way you'll get the difference given by the salt states code changes applied to the same minion (i.e. grains input)