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
Reference Validator for Heat Templates (in progress) #84
base: master
Are you sure you want to change the base?
Conversation
…hecking references with access path leading to different files
…ing complex references README.md: added requirement - validating references moved after loading all additional information
…L_Prop_Par) - object YAML_Prop_Par applied for property x parameter pairs - adjusted validating properties against parameters - created method for merging Parameter and Property object attributes (at the beginning, they are not connected)
- solve SnmpdReadonlyUserPassword problem - create states so that more options can continue with the same next state
- if referred resource(s) exist(s), sets usage flag - if not, new invalid reference type implemented
…L_Enums.py, YAML_Hotfile.py - code structured into files - reference_validator: parses arguments, runs validator, returns output - YAML_HotValidator: contains corresponding class without subclasses - YAML_Hotfile: contains corresponding class without subclasses - YAML_Enums: all enumeration types (YAML_Types, YAML_colours, YAML_tree_info) - YAML_HotClasses: other classes previously in YAML_HotValidator (YAML_Env, YAML_Prop_Par, YAML_Reference, YAML_Resource)
- improved formatting - optimized code - removed attribute "children" from YAML_Hotfile (self.resources.child used instead), left at YAML_Env
…ping - resolves hierarchical mapping, wildcards (*) - params_default from environment added to parameters where needed
… functionality - -e and -f parameter longer versions changed according to heat - added -P parameter for adding parameters and/or values to root templates (or only values?) - adding parameters from environments and prompt to root template implemented
…t_ are now based on FSM - get_param FSM in final stages - in order to enable mapping to be used multiple times, a deep copy with some shared mutable objects that are not modified (such as structure) is created - applying mappings is adjusted accordingly
…r changes - parameter with value added via environment or prompt that has no match in root template has a new error type - parameter default added via environment without match in the stack has a new error type - environemnt file error output fixed, improved
- duplicate messages fixed - checking matching parameters fixed
- tests structure improved, log files and diff files used - test nr. 6 finished, test nr. 7 to be added
- mapping is done using DFS, it goes through nodes and applies mapping repeatedly for specific resources
Okay, this is cool! I like the tests. I've looked through the code once, but there's a lot of it and I didn't try to understand everything yet. So my comments now are from a superficial reading of it and I hope to do a more substantive read later on. One thing that's unclear to me: The I'm happy to merge this PR once that's been cleared up. Other general comments:
I'll write up a few inline comments as well, but those are mostly about the code style, etc. so feel free to ignore them if you disagree. And anyway, that's something we can do in subsequent patches, I don't want to block this pull request with it. |
@@ -1,29 +1,58 @@ | |||
Reference Validator | |||
=================== | |||
|
|||
<h1>WARNING: Work in progress, may return invalid results </h1> | |||
<h2> Introduction </h2> |
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.
Markdown has syntax for header levels. For h2 it's:
Introduction
--------------
or:
## Introduction
<h2> Introduction </h2> | ||
|
||
This script goes through all HOT files associated with root template, taking mapped resources from environment files into account. It validates references and detects unused variables/instances in YAML files. It accepts the same basic parameters as heat (root template and environments). | ||
- nyanbar (for Python 2.x) |
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.
nyanbar is optional. Can we make it clear here?
|
||
<h2> Usage </h2> | ||
|
||
$ python[3] reference_validator.py -f <path/to/yaml/root template> -e <path/to/yaml/environment file>[<another/path/to/env/files>] [-p/--pretty-format] [-u/--unused] [-h/--help] | ||
$ python[3] reference_validator.py -f <path/to/yaml/root template> -e <path/to/yaml/environment file> [<another/path/to/env/files>] [-p/--pretty-format] [-u/--print-unused] [-n/--nyan] [-h/--help] [-t/--print-tree] | ||
|
||
<h3> Parameters </h3> |
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.
h3 in markdown is:
### Parameters
(h4 is four hash marks, h5 is five, etc.)
Each parameter and its corresponding property share one. | ||
''' | ||
|
||
def __init__(self, structure, isPar): |
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.
Could you describe what isPar
means/is used for? It's not immediately clear to me reading this function. As in, when is it True and when False?
Also, Python function parameters and local names are usually in snake_case, so something like is_par
would be more idiomatic.
|
||
def clone(self): | ||
''' Create a deep copy of the object, | ||
mutable objects such as structure are shared. |
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.
It's not a deep copy if parts of it are shared.
elif cur_state == enum.GetParamStates.PARAM_NAME: | ||
if type(hierarchy) == str: | ||
# Resolve pseudo parameters | ||
if hierarchy in ['OS::stack_name', 'OS::stack_id', 'OS::project_id']: |
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.
This should probably be a tuple, too.
print('') | ||
|
||
# Unused parameters | ||
if False in [x.used for x in node.params]: |
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.
This can be written as:
if not all(x.used for x in node.params):
which I think is a bit clearer.
print('') | ||
|
||
# Print hidden parameters (optional) | ||
if (self.print_unused) and [True for x in node.params if x.hidden]: |
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.
I think this can be simplified into:
if self.print_unused and any(x.hidden for x in node.params):
|
||
# Load tests | ||
TEST01=("Test 1 - Parsing valid YAML file:" \ | ||
"sudo python reference_validator.py -f tests/test_files/01_root.yaml -u") |
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.
The sudo shouldn't be necessary here.
@@ -0,0 +1,23 @@ | |||
#!/bin/bash |
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.
This line doesn't belong here. Same in all the other yaml test files.
…ments, in progress
This version should handle stacks containing template file together with additional parameters and environments.
During development, the program is tested on tripleo templates and associated environments.
Code improvements and characteristics
Added functionality