From 00566d13eaeae3128ffe611a1bd6f2274eef66f4 Mon Sep 17 00:00:00 2001 From: Paul Belanger Date: Fri, 31 May 2019 10:57:22 -0400 Subject: [PATCH] Fix yamllint issue This makes our code base pass yamllint, it also adds missing test-requirements.txt file and default yamllint config file. A follow up patch will address flake8 issues and add zuul job to gate. Signed-off-by: Paul Belanger --- .gitignore | 3 +- .yamllint | 13 ++ roles/init/tasks/main.yml | 7 +- roles/init/vars/main.yml | 25 ++-- roles/resource_module/tasks/main.yml | 2 +- roles/resource_module/tasks/template.yml | 1 + roles/resource_module/vars/main.yml | 91 ++++++------ site.yml | 7 +- test-requirements.txt | 1 + tests/inventory.yml | 3 +- tests/roles/tests/tasks/argspec.yml | 171 ++++++++++++----------- tests/roles/tests/tasks/facts.yml | 18 +-- tests/roles/tests/tasks/main.yml | 1 + tests/test.yml | 9 +- 14 files changed, 193 insertions(+), 159 deletions(-) create mode 100644 .yamllint create mode 100644 test-requirements.txt diff --git a/.gitignore b/.gitignore index 7c6571e..d4b42f0 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ -venv +.tox/ *.pyc +venv diff --git a/.yamllint b/.yamllint new file mode 100644 index 0000000..2ceb272 --- /dev/null +++ b/.yamllint @@ -0,0 +1,13 @@ +extends: default + +ignore: | + .tox + +rules: + braces: + max-spaces-inside: 1 + level: error + brackets: + max-spaces-inside: 1 + level: error + line-length: disable diff --git a/roles/init/tasks/main.yml b/roles/init/tasks/main.yml index bb58d4b..fa204d9 100644 --- a/roles/init/tasks/main.yml +++ b/roles/init/tasks/main.yml @@ -1,8 +1,9 @@ +--- - name: Ensure 'parent' variable is set (see README.md) assert: that: parent is defined -- name: Ensure 'structure' variable is set and one of 'role' or 'collection' (see README.md) +- name: Ensure 'structure' variable is 'role' or 'collection' (see README.md) assert: that: structure is defined and structure in ['role', 'collection'] @@ -34,12 +35,12 @@ src: "{{ rm['LICENSE'] | default('gpl-3.0.txt') }}" dest: "{{ parent }}/LICENSE.txt" -- name: Ensure the 'collection_org' is set when 'structure' is set to collection +- name: Ensure the 'collection_org' is set when 'structure' is collection assert: that: collection_org is defined when: structure == 'collection' -- name: Ensure the 'collection_name' is set when 'structure' is set to collection +- name: Ensure the 'collection_name' is set when 'structure' is collection assert: that: collection_name is defined when: structure == 'collection' diff --git a/roles/init/vars/main.yml b/roles/init/vars/main.yml index b4b205d..d149080 100644 --- a/roles/init/vars/main.yml +++ b/roles/init/vars/main.yml @@ -1,13 +1,14 @@ +--- directories: - collection: - - plugins/modules - - plugins/module_utils - - plugins/filter - - plugins/action - - plugins/inventory - - playbooks - - docs - - roles - role: - - library - - module_utils + collection: + - plugins/modules + - plugins/module_utils + - plugins/filter + - plugins/action + - plugins/inventory + - playbooks + - docs + - roles + role: + - library + - module_utils diff --git a/roles/resource_module/tasks/main.yml b/roles/resource_module/tasks/main.yml index a47cdba..2c25beb 100644 --- a/roles/resource_module/tasks/main.yml +++ b/roles/resource_module/tasks/main.yml @@ -1,4 +1,4 @@ - +--- - name: "Create the resource module directory structure" file: path: "{{ parent_directory }}/{{ item }}" diff --git a/roles/resource_module/tasks/template.yml b/roles/resource_module/tasks/template.yml index e56b344..555e409 100644 --- a/roles/resource_module/tasks/template.yml +++ b/roles/resource_module/tasks/template.yml @@ -1,3 +1,4 @@ +--- - name: Check to see if the file exists stat: path: "{{ parent_directory}}/{{ template['destination'] }}" diff --git a/roles/resource_module/vars/main.yml b/roles/resource_module/vars/main.yml index 0dabd89..2425e85 100644 --- a/roles/resource_module/vars/main.yml +++ b/roles/resource_module/vars/main.yml @@ -1,3 +1,4 @@ +--- # basic vars to make the templates cleaner network_os: "{{ rm['NETWORK_OS'] }}" resource: "{{ rm['RESOURCE'] }}" @@ -25,51 +26,51 @@ import_path: "{{ import_paths[structure] }}.network" # all the directories that need to be built resource_module_directories: -- "{{ module_directory }}" -- module_utils -- module_utils/network -- module_utils/network/{{ network_os }} -- module_utils/network/{{ network_os }}/argspec -- module_utils/network/{{ network_os }}/argspec/facts -- module_utils/network/{{ network_os }}/argspec/{{ resource }} -- module_utils/network/{{ network_os }}/config -- module_utils/network/{{ network_os }}/config/{{ resource }} -- module_utils/network/{{ network_os }}/facts -- module_utils/network/{{ network_os }}/facts/{{ resource }} -- module_utils/network/{{ network_os }}/utils + - "{{ module_directory }}" + - module_utils + - module_utils/network + - module_utils/network/{{ network_os }} + - module_utils/network/{{ network_os }}/argspec + - module_utils/network/{{ network_os }}/argspec/facts + - module_utils/network/{{ network_os }}/argspec/{{ resource }} + - module_utils/network/{{ network_os }}/config + - module_utils/network/{{ network_os }}/config/{{ resource }} + - module_utils/network/{{ network_os }}/facts + - module_utils/network/{{ network_os }}/facts/{{ resource }} + - module_utils/network/{{ network_os }}/utils # each of the files to be templated resource_module_templates: -- source: README.md.j2 - destination: "{{ parent }}/README.md" - overwrite: False -- source: module_directory/network_os/network_os_resource.py.j2 - destination: "{{ parent_directory }}/{{ module_directory }}/{{ network_os }}_{{ resource }}.py" - overwrite: True -- source: module_directory/network_os/network_os_facts.py.j2 - destination: "{{ parent_directory }}/{{ module_directory }}/{{ network_os }}_facts.py" - overwrite: False -- source: module_utils/network_os/argspec/facts/facts.py.j2 - destination: "{{ parent_directory}}/module_utils/network/{{ network_os }}/argspec/facts/facts.py" - overwrite: False -- source: module_utils/network_os/argspec/resource/resource.py.j2 - destination: "{{ parent_directory }}/module_utils/network/{{ network_os }}/argspec/{{ resource }}/{{ resource }}.py" - overwrite: True -- source: module_utils/network_os/config/base.py.j2 - destination: "{{ parent_directory }}/module_utils/network/{{ network_os }}/config/base.py" - overwrite: False -- source: module_utils/network_os/config/resource/resource.py.j2 - destination: "{{ parent_directory }}/module_utils/network/{{ network_os }}/config/{{ resource }}/{{ resource }}.py" - overwrite: False -- source: module_utils/network_os/facts/base.py.j2 - destination: "{{ parent_directory }}/module_utils/network/{{ network_os }}/facts/base.py" - overwrite: False -- source: module_utils/network_os/facts/facts.py.j2 - destination: "{{ parent_directory}}/module_utils/network/{{ network_os }}/facts/facts.py" - overwrite: False -- source: module_utils/network_os/facts/resource/resource.py.j2 - destination: "{{ parent_directory}}/module_utils/network/{{ network_os }}/facts/{{ resource }}/{{ resource }}.py" - overwrite: False -- source: module_utils/network_os/utils/utils.py.j2 - destination: "{{ parent_directory}}/module_utils/network/{{ network_os }}/utils/utils.py" - overwrite: False + - source: README.md.j2 + destination: "{{ parent }}/README.md" + overwrite: false + - source: module_directory/network_os/network_os_resource.py.j2 + destination: "{{ parent_directory }}/{{ module_directory }}/{{ network_os }}_{{ resource }}.py" + overwrite: true + - source: module_directory/network_os/network_os_facts.py.j2 + destination: "{{ parent_directory }}/{{ module_directory }}/{{ network_os }}_facts.py" + overwrite: false + - source: module_utils/network_os/argspec/facts/facts.py.j2 + destination: "{{ parent_directory}}/module_utils/network/{{ network_os }}/argspec/facts/facts.py" + overwrite: false + - source: module_utils/network_os/argspec/resource/resource.py.j2 + destination: "{{ parent_directory }}/module_utils/network/{{ network_os }}/argspec/{{ resource }}/{{ resource }}.py" + overwrite: true + - source: module_utils/network_os/config/base.py.j2 + destination: "{{ parent_directory }}/module_utils/network/{{ network_os }}/config/base.py" + overwrite: false + - source: module_utils/network_os/config/resource/resource.py.j2 + destination: "{{ parent_directory }}/module_utils/network/{{ network_os }}/config/{{ resource }}/{{ resource }}.py" + overwrite: false + - source: module_utils/network_os/facts/base.py.j2 + destination: "{{ parent_directory }}/module_utils/network/{{ network_os }}/facts/base.py" + overwrite: false + - source: module_utils/network_os/facts/facts.py.j2 + destination: "{{ parent_directory}}/module_utils/network/{{ network_os }}/facts/facts.py" + overwrite: false + - source: module_utils/network_os/facts/resource/resource.py.j2 + destination: "{{ parent_directory}}/module_utils/network/{{ network_os }}/facts/{{ resource }}/{{ resource }}.py" + overwrite: false + - source: module_utils/network_os/utils/utils.py.j2 + destination: "{{ parent_directory}}/module_utils/network/{{ network_os }}/utils/utils.py" + overwrite: false diff --git a/site.yml b/site.yml index 65d473b..9449cdc 100644 --- a/site.yml +++ b/site.yml @@ -1,5 +1,6 @@ +--- - hosts: localhost - gather_facts: no + gather_facts: false roles: - - init - - resource_module + - init + - resource_module diff --git a/test-requirements.txt b/test-requirements.txt new file mode 100644 index 0000000..b2c729c --- /dev/null +++ b/test-requirements.txt @@ -0,0 +1 @@ +yamllint diff --git a/tests/inventory.yml b/tests/inventory.yml index 6120e74..6ed08d9 100644 --- a/tests/inventory.yml +++ b/tests/inventory.yml @@ -1,3 +1,4 @@ +--- all: children: eos: @@ -9,7 +10,7 @@ all: ansible_user: admin ansible_connection: network_cli ansible_password: password - ansible_become: True + ansible_become: true ansible_become_method: enable ansible_become_pass: password ansible_facts_modules: myos_facts diff --git a/tests/roles/tests/tasks/argspec.yml b/tests/roles/tests/tasks/argspec.yml index 7ff0984..e851ee4 100644 --- a/tests/roles/tests/tasks/argspec.yml +++ b/tests/roles/tests/tasks/argspec.yml @@ -1,172 +1,181 @@ +--- - name: Set the expected response as a fact set_fact: expected_response: before: - - name: rsrc_a - some_bool: true - some_string: choice_a - - name: rscrc_b - some_dict: - property_01: value - some_int: 10 + - name: rsrc_a + some_bool: true + some_string: choice_a + - name: rscrc_b + some_dict: + property_01: value + some_int: 10 changed: false commands: [] failed: false + - name: Check for correct argspec and default state myos_interfaces: config: "{{ ansible_network_resources['interfaces'] }}" register: result + - debug: var: result + - name: Compare the module result to the expected response assert: that: "{{ result == expected_response }}" - - name: Check for correct argspec (states) myos_interfaces: config: - - name: rsrc_a - some_string: choice_a - - name: rsrc_b - some_bool: False - some_int: 10 - - name: rsrc_c - some_dict: - property_01: a_string + - name: rsrc_a + some_string: choice_a + - name: rsrc_b + some_bool: false + some_int: 10 + - name: rsrc_c + some_dict: + property_01: a_string state: "{{ state }}" loop: - - merged - - deleted - - overridden - - replaced + - merged + - deleted + - overridden + - replaced loop_control: loop_var: state - - name: Check for incorrect argspec (states) myos_interfaces: config: - - name: rsrc_a - some_string: choice_a - - name: rsrc_b - some_bool: False - some_int: 10 - - name: rsrc_c - some_dict: - property_01: a_string + - name: rsrc_a + some_string: choice_a + - name: rsrc_b + some_bool: false + some_int: 10 + - name: rsrc_c + some_dict: + property_01: a_string state: wrong register: result - ignore_errors: True + ignore_errors: true + - name: Set a fact for the expected error message set_fact: error: 'value of state must be one of: merged, replaced, overridden, deleted' + - name: Confirm the error message assert: that: "{{ error in result['msg'] }}" - - name: Check for incorrect argspec (choice) myos_interfaces: config: - - name: rsrc_a - some_string: xxxxxx - - name: rsrc_b - some_bool: False - some_int: 10 - - name: rsrc_c - some_dict: - property_01: a_string + - name: rsrc_a + some_string: xxxxxx + - name: rsrc_b + some_bool: false + some_int: 10 + - name: rsrc_c + some_dict: + property_01: a_string register: result - ignore_errors: True + ignore_errors: true + - name: Set a fact for the expected error message set_fact: error: 'value of some_string must be one of: choice_a, choice_b, choice_c, got: xxxxxx found in config' + - name: Confirm the error message assert: that: "{{ error in result['msg'] }}" - - name: Check for incorrect argspec (bad bool) myos_interfaces: config: - - name: rsrc_a - some_string: choice_a - - name: rsrc_b - some_bool: NotABoolean - some_int: 10 - - name: rsrc_c - some_dict: - property_01: a_string + - name: rsrc_a + some_string: choice_a + - name: rsrc_b + some_bool: NotABoolean + some_int: 10 + - name: rsrc_c + some_dict: + property_01: a_string register: result - ignore_errors: True + ignore_errors: true + - name: Set a fact for the expected error message set_fact: error: is not a valid boolean + - name: Confirm the error message assert: that: "{{ error in result['msg'] }}" - - name: Check for incorrect argspec (not int) myos_interfaces: config: - - name: rsrc_a - some_string: choice_a - - name: rsrc_b - some_bool: False - some_int: I'm a string - - name: rsrc_c - some_dict: - property_01: a_string + - name: rsrc_a + some_string: choice_a + - name: rsrc_b + some_bool: false + some_int: I'm a string + - name: rsrc_c + some_dict: + property_01: a_string register: result - ignore_errors: True + ignore_errors: true + - name: Set a fact for the expected error message set_fact: error: unable to convert to int + - name: Confirm the error message assert: that: "{{ error in result['msg'] }}" - - name: Check for incorrect argspec (invalid key) myos_interfaces: config: - - name: rsrc_a - some_string: choice_a - wrong_key: error - - name: rsrc_b - some_bool: False - some_int: I'm a string - - name: rsrc_c - some_dict: - property_01: a_string + - name: rsrc_a + some_string: choice_a + wrong_key: error + - name: rsrc_b + some_bool: false + some_int: I'm a string + - name: rsrc_c + some_dict: + property_01: a_string register: result - ignore_errors: True + ignore_errors: true + - name: Set a fact for the expected error message set_fact: error: Unsupported parameters + - name: Confirm the error message assert: that: "{{ error in result['msg'] }}" - - name: Check for incorrect argspec (invalid property) myos_interfaces: config: - - name: rsrc_a - some_string: choice_a - - name: rsrc_b - some_bool: False - some_int: 10 - - name: rsrc_c - some_dict: - property_99: a_string + - name: rsrc_a + some_string: choice_a + - name: rsrc_b + some_bool: false + some_int: 10 + - name: rsrc_c + some_dict: + property_99: a_string register: result - ignore_errors: True + ignore_errors: true + - name: Set a fact for the expected error message set_fact: error: Unsupported parameters + - name: Confirm the error message assert: that: "{{ error in result['msg'] }}" diff --git a/tests/roles/tests/tasks/facts.yml b/tests/roles/tests/tasks/facts.yml index 7fc97f5..6ad1f3f 100644 --- a/tests/roles/tests/tasks/facts.yml +++ b/tests/roles/tests/tasks/facts.yml @@ -1,13 +1,15 @@ +--- - name: Set a fact for the expect facts set_fact: expected: - - name: rsrc_a - some_bool: true - some_string: choice_a - - name: rscrc_b - some_dict: - property_01: value - some_int: 10 + - name: rsrc_a + some_bool: true + some_string: choice_a + - name: rscrc_b + some_dict: + property_01: value + some_int: 10 + - name: Check for accurate facts assert: - that: "{{ ansible_network_resources['interfaces'] == expected }}" + that: "{{ ansible_network_resources['interfaces'] == expected }}" diff --git a/tests/roles/tests/tasks/main.yml b/tests/roles/tests/tasks/main.yml index a4af458..1399569 100644 --- a/tests/roles/tests/tasks/main.yml +++ b/tests/roles/tests/tasks/main.yml @@ -1,3 +1,4 @@ +--- - include: "{{ item }}" loop: - facts.yml diff --git a/tests/test.yml b/tests/test.yml index be88ddc..a57e8a8 100644 --- a/tests/test.yml +++ b/tests/test.yml @@ -1,10 +1,11 @@ +--- - hosts: myos101 module_defaults: myos_facts: gather_subset: min gather_network_resources: - - interfaces - gather_facts: True + - interfaces + gather_facts: true roles: - - my_role - - tests + - my_role + - tests