From 3fc15de068f0ba3586f899f2592476aec9f5dc18 Mon Sep 17 00:00:00 2001 From: Till Maas Date: Thu, 28 May 2020 22:54:45 +0200 Subject: [PATCH] Library: Introduce debug flags Allow to disable the checkpoint feature with a debug flag to make debugging easier. --- contributing.md | 14 ++++++++++++++ library/network_connections.py | 13 ++++++++++--- tasks/main.yml | 1 + 3 files changed, 25 insertions(+), 3 deletions(-) diff --git a/contributing.md b/contributing.md index e67106e..a76bbf1 100644 --- a/contributing.md +++ b/contributing.md @@ -220,6 +220,20 @@ You may want to read this for a more detailed explanation (and links to other po how to write a good commit message). This content is licensed under [CC-BY-SA](https://creativecommons.org/licenses/by-sa/4.0/). +### Debugging + +When using the `nm` provider, NetworkManager create a checkpoint and reverts the changes +on failures. This makes it hard to debug the error. To disable this, set the Ansible +variable `__network_debug_flags to include the value `disable-checkpoints`. Also tests +clean up by default in case there are failures. They should be tagged as +`tests::cleanup` and can be skipped. To use both, run the test playbooks like this: + +```bash +ansible-playbook --skip-tags tests::cleanup \ + -e "__network_debug_flags=disable-checkpoints" \ + -i testhost, tests/playbooks/tests_802_1x.yml +``` + ### Continuous integration The [continuous integration](https://en.wikipedia.org/wiki/Continuous_integration) (CI) diff --git a/library/network_connections.py b/library/network_connections.py index 2ff210a..217a178 100644 --- a/library/network_connections.py +++ b/library/network_connections.py @@ -1471,6 +1471,7 @@ class RunEnvironmentAnsible(RunEnvironment): "force_state_change": {"required": False, "default": False, "type": "bool"}, "provider": {"required": True, "default": None, "type": "str"}, "connections": {"required": False, "default": None, "type": "list"}, + "__debug_flags": {"required": False, "default": "", "type": "str"}, } def __init__(self): @@ -1604,6 +1605,7 @@ class Cmd(object): is_check_mode=False, ignore_errors=False, force_state_change=False, + debug_flags="", ): self.run_env = run_env self.validate_one_type = None @@ -1617,6 +1619,7 @@ class Cmd(object): self._connections_data = None self._check_mode = CheckMode.PREPARE self._is_changed_modified_system = False + self._debug_flags = debug_flags def run_command(self, argv, encoding=None): return self.run_env.run_command(argv, encoding=encoding) @@ -1953,9 +1956,12 @@ class Cmd_nm(Cmd): def start_transaction(self): Cmd.start_transaction(self) - self._checkpoint = self.nmutil.create_checkpoint( - len(self.connections) * DEFAULT_ACTIVATION_TIMEOUT - ) + if "disable-checkpoints" in self._debug_flags: + pass + else: + self._checkpoint = self.nmutil.create_checkpoint( + len(self.connections) * DEFAULT_ACTIVATION_TIMEOUT + ) def rollback_transaction(self, idx, action, error): Cmd.rollback_transaction(self, idx, action, error) @@ -2455,6 +2461,7 @@ def main(): is_check_mode=run_env_ansible.module.check_mode, ignore_errors=params["ignore_errors"], force_state_change=params["force_state_change"], + debug_flags=params["__debug_flags"], ) connections = cmd.connections run_env_ansible.on_failure = cmd.on_failure diff --git a/tasks/main.yml b/tasks/main.yml index 514ab0e..5bcc9cf 100644 --- a/tasks/main.yml +++ b/tasks/main.yml @@ -64,6 +64,7 @@ ignore_errors: "{{ network_ignore_errors | default(omit) }}" force_state_change: "{{ network_force_state_change | default(omit) }}" connections: "{{ network_connections | default([]) }}" + __debug_flags: "{{ __network_debug_flags | default(omit) }}" register: __network_connections_result - name: Show debug messages