mirror of
https://github.com/linux-system-roles/network.git
synced 2026-01-23 02:15:17 +00:00
Library: Introduce debug flags
Allow to disable the checkpoint feature with a debug flag to make debugging easier.
This commit is contained in:
parent
c9d2f8f3b7
commit
3fc15de068
3 changed files with 25 additions and 3 deletions
|
|
@ -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)
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue