Skip to content

Commit

Permalink
fix tests for command init role and init scenario
Browse files Browse the repository at this point in the history
Currently the tests fail for `test_command_init_role` and
`test_command_init_scneario`. The tests execute `ansible-lint` on the
newly-created roles and the linter recently got more restrictive, so we
now have to adapt.
  • Loading branch information
ziegenberg authored and asmacdo committed Jun 5, 2023
1 parent 60c1637 commit 25de3e1
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 13 deletions.
15 changes: 13 additions & 2 deletions src/molecule/command/init/role.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ def execute(self, action_args=None):

if namespace:
# we need to inject namespace info into meta/main.yml
cmd = [
cmd_meta = [
"ansible",
"localhost",
"-o", # one line output
Expand All @@ -99,7 +99,18 @@ def execute(self, action_args=None):
"-a",
f'path={role_name}/meta/main.yml line=" namespace: {namespace}" insertafter=" author: your name"',
]
util.run_command(cmd, check=True)
util.run_command(cmd_meta, check=True)
# we need to inject namespace info into tests/test.yml
cmd_tests = [
"ansible",
"localhost",
"-o", # one line output
"-m",
"lineinfile",
"-a",
f'path={role_name}/tests/test.yml line=" - {namespace}.{role_name}" regex="^(.*) - {role_name}"',
]
util.run_command(cmd_tests, check=True)

scenario_base_directory = os.path.join(role_directory, role_name)
templates = [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,10 @@

# TODO: Developer must implement and populate 'server' variable

- when: server.changed | default(false) | bool
- name: Create instance config
when: server.changed | default(false) | bool # noqa no-handler
block:
- name: Populate instance config dict
- name: Populate instance config dict # noqa jinja
ansible.builtin.set_fact:
instance_conf_dict: {
'instance': "{{ }}",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,5 @@
{{ instance_conf | to_json | from_json | to_yaml }}
dest: "{{ molecule_instance_config }}"
mode: 0600
when: server.changed | default(false) | bool
when: server.changed | default(false) | bool # noqa no-handler
{%- endraw %}
14 changes: 7 additions & 7 deletions src/molecule/test/functional/.ansible-lint
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
---
# ansible-lint config for functional testing, used to bypass expected metadata
# errors in molecule-generated roles. Loaded via the metadata_lint_update
# pytest helper. For reference, see "E7xx - metadata" in:
# https://docs.ansible.com/ansible-lint/rules/default_rules.html

# https://docs.ansible.com/ansible-lint/rules/default_rules.html

skip_list:
# metadata/201 - Trailing whitespace
- '201'
# metadata/701 - Role info should contain platforms
- '701'
# metadata/703 - Should change default metadata: <field>"
- '703'
- meta-incorrect
- schema[meta]
- name[play]
# See https://github.com/ansible/ansible/issues/63734
3 changes: 2 additions & 1 deletion src/molecule/test/functional/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,8 @@ def metadata_lint_update(role_directory: str) -> None:
# the customize ansible-lint config is used.
with change_dir_to(role_directory):
cmd = ["ansible-lint", "."]
assert run_command(cmd).returncode == 0
result = run_command(cmd)
assert result.returncode == 0


def list_cmd(x):
Expand Down

0 comments on commit 25de3e1

Please sign in to comment.