salt-formulas / reclass

A recursive external node classifier for automation tools like Ansible, Puppet, and Salt
Other
53 stars 23 forks source link

fix relative class names #70

Closed AndrewPickford closed 6 years ago

AndrewPickford commented 6 years ago

The implementation of the relative class name functionality has some bugs, leading to parameters not being correctly set. For example with:

# nodes/node1.yml
classes:
- one.alpha

# classes/one/alpha.yml
classes:
- .beta
- two.beta

parameters:
  test1: ${one_beta}
  test2: ${two_beta}

# classes/one/beta.yml
parameters:
  one_beta: 1

# classes/two/beta.yml
parameters:
  two_beta: 2

then a nodeinfo fails:

reclass.py --nodeinfo node1
-> node1
   Cannot resolve ${two_beta}, at test2, in yaml_fs:///some_path/classes/one/alpha.yml

It looks like the class two.beta does not get loaded so the two_beta parameter never gets set.

This patch reworks relative class names by converting any relative class names to absolute class names when first encountered in the YamlData.get_entity method. Some additional tests for relative class names and the compose class name option are also added.