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

Reference Validator for Heat Templates (in progress) #84

Open
wants to merge 71 commits into
base: master
Choose a base branch
from

Conversation

Tlacenka
Copy link
Contributor

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

  • the code was restructured into multiple files for better readability
  • remains compatibility for both Python 2.x and 3.x
  • some optimizations were made (but there are more to come)
  • the main parameters are called the same as when creating stack using heat client

Added functionality

  • the script is now able to resolve multiple nested references across multiple files and some of the AutoScaling/ResourceGroup specialties (not all)
  • the script should be able to resolve hierarchical mapping that can use wildcards
  • additional parameters and environment parameters and defaults are inserted into the templates and taken into account
  • the script also validates resource dependencies
  • a new parameter -t (--print-tree) enables the user to print the tree structure of the templates connected to the root template

Katka Pilatova added 30 commits March 30, 2016 16:48
…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
Katka Pilatova added 23 commits September 30, 2016 14:55
…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
@tomassedovic
Copy link
Collaborator

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 run_tests.sh file seems to require sudo, but I don't see any reason why it should? Can we remove that?

I'm happy to merge this PR once that's been cleared up.

Other general comments:

  1. I've tested this on the Mitaka tripleo-heat-templates (tag 2.1.0) and it seems to be working fine. There are some complaints about unused parameters, etc. that might indicate I'm not passing all the environment files in, but we can figure that out later.
  2. This won't work with the Newton templates, because they've added Jinja2 templating. In addition, in Newton and onwards, the generated template may never even appear on the disk. We'll have to address that, but again: later. This is useful to pre-Newton templates.
  3. I'm wondering whether we can reduce the size of the code and some of the functions. Like pulling out duplicated bits into functions, etc. You know the codebase better than I do so you tell me: can we make this smaller? (if we can't, oh well)

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>
Copy link
Collaborator

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)
Copy link
Collaborator

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>
Copy link
Collaborator

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):
Copy link
Collaborator

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.
Copy link
Collaborator

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']:
Copy link
Collaborator

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]:
Copy link
Collaborator

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]:
Copy link
Collaborator

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")
Copy link
Collaborator

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
Copy link
Collaborator

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.

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

2 participants