Skip to content

Commit

Permalink
Use backwards incompatible change from ansible-compat 4.0.1 (#3904)
Browse files Browse the repository at this point in the history
* Use run, not exec, for ansible-compat 4.0.2

4.0.2 dropped the use of `exec`, needs to be replaced with `run`

Fixes #3903

ansible/ansible-compat#256

* bump ansible-compat 4.1.2

ansible-compat 4.0.1 included a breaking change. If we want to use
latest, minimum version must be at least 4.0.1.

ansible-compat < 4.1.2 has an issue that causes an unhandled exception
for certain log levels. ansible/ansible-lint#3522
Since this issue caused CI trouble, we go ahead and bump to 4.1.2.

* fixup

* [DATALAD RUNCMD] recompile requirements.lock.txt

=== Do not change lines below ===
{
 "chain": [],
 "cmd": "pip-compile --no-annotate --output-file=.config/requirements-lock.txt --resolver=backtracking --strip-extras --unsafe-package=ruamel-yaml-clib pyproject.toml",
 "exit": 0,
 "extra_inputs": [],
 "inputs": [],
 "outputs": [],
 "pwd": "."
}
^^^ Do not change lines above ^^^

* fix tests for command init role and init scenario

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.

* [DATALAD RUNCMD] recompile requirements.txt

=== Do not change lines below ===
{
 "chain": [],
 "cmd": "pip-compile --extra=docs --extra=test --no-annotate --output-file=.config/requirements.txt --resolver=backtracking --strip-extras pyproject.toml",
 "exit": 0,
 "extra_inputs": [],
 "inputs": [],
 "outputs": [],
 "pwd": "."
}
^^^ Do not change lines above ^^^

* Fake 3.9 for autogenerated files

I used 3.10, but CI will run this on 3.9, and fail if there is a diff.
This means it is safe to change this by hand, since it will be checked.

---------

Co-authored-by: Daniel Ziegenberg <daniel@ziegenberg.at>
  • Loading branch information
asmacdo and ziegenberg committed Jun 7, 2023
1 parent 9bb5b4f commit 3f97a41
Show file tree
Hide file tree
Showing 10 changed files with 32 additions and 19 deletions.
2 changes: 1 addition & 1 deletion .config/requirements-lock.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
#
# pip-compile --no-annotate --output-file=.config/requirements-lock.txt --resolver=backtracking --strip-extras --unsafe-package=ruamel-yaml-clib pyproject.toml
#
ansible-compat==3.0.2
ansible-compat==4.1.2
ansible-core==2.14.4
arrow==1.2.3
attrs==23.1.0
Expand Down
2 changes: 1 addition & 1 deletion .config/requirements.in
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
ansible-compat >= 2.2.0, < 4.0.0
ansible-compat >= 4.1.2
ansible-core >= 2.12.10
click >= 8.0, < 9
click-help-colors >= 0.9
Expand Down
2 changes: 1 addition & 1 deletion .config/requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
# pip-compile --extra=docs --extra=test --no-annotate --output-file=.config/requirements.txt --resolver=backtracking --strip-extras pyproject.toml
#
ansi2html==1.8.0
ansible-compat==3.0.2
ansible-compat==4.1.2
ansible-core==2.14.4
ansible-lint==6.14.6
arrow==1.2.3
Expand Down
4 changes: 2 additions & 2 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ repos:
entry: mypy src/
pass_filenames: false
additional_dependencies:
- ansible-compat>=2.2.0,<4.0.0
- ansible-compat>=4.1.2
- click>=8.0.1
- enrich>=1.2.7
- importlib-metadata>=4.6.1
Expand All @@ -81,7 +81,7 @@ repos:
args:
- --output-format=colorized
additional_dependencies:
- ansible-compat>=2.2.0,<4.0.0
- ansible-compat>=4.1.2
- click
- click-help-colors
- cookiecutter
Expand Down
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
2 changes: 1 addition & 1 deletion src/molecule/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ def run_command(
if debug:
print_environment_vars(env)

result = app.runtime.exec(
result = app.runtime.run(
args=args,
env=env,
cwd=cwd,
Expand Down

0 comments on commit 3f97a41

Please sign in to comment.