diff --git a/changelogs/fragments/t9053_vyos_module_bugfix.yml b/changelogs/fragments/t9053_vyos_module_bugfix.yml new file mode 100644 index 00000000..b8d0a3d9 --- /dev/null +++ b/changelogs/fragments/t9053_vyos_module_bugfix.yml @@ -0,0 +1,3 @@ +--- +bugfixes: + - vyos_config.py - Fixing test case diff --git a/tests/integration/targets/vyos_config/tests/cli/backup.yaml b/tests/integration/targets/vyos_config/tests/cli/backup.yaml index adfa2ad7..3bcd5d35 100644 --- a/tests/integration/targets/vyos_config/tests/cli/backup.yaml +++ b/tests/integration/targets/vyos_config/tests/cli/backup.yaml @@ -1,111 +1,113 @@ --- - debug: msg="START vyos/backup.yaml on connection={{ ansible_connection }}" - name: collect any backup files - find: + ansible.builtin.find: paths: "{{ role_path }}/backup" pattern: "{{ inventory_hostname_short }}_config*" register: backup_files connection: local - name: delete backup files - file: + ansible.builtin.file: path: "{{ item.path }}" state: absent with_items: "{{ backup_files.files|default([]) }}" + connection: local - name: take configure backup register: result vyos.vyos.vyos_config: backup: true - assert: that: - result.changed == true - name: collect any backup files - find: + ansible.builtin.find: paths: "{{ role_path }}/backup" pattern: "{{ inventory_hostname_short }}_config*" register: backup_files connection: local - assert: that: - backup_files.files is defined - name: delete configurable backup file path - file: + ansible.builtin.file: path: "{{ item }}" state: absent with_items: - "{{ role_path }}/backup_test_dir/" - "{{ role_path }}/backup/backup.cfg" run_once: true + connection: local - name: take configuration backup in custom filename and directory path register: result vyos.vyos.vyos_config: backup: true backup_options: filename: backup.cfg dir_path: "{{ role_path }}/backup_test_dir/{{ inventory_hostname_short }}" - assert: that: - result.changed == true - name: check if the backup file-1 exist - find: + ansible.builtin.find: paths: "{{ role_path }}/backup_test_dir/{{ inventory_hostname_short }}/backup.cfg" register: backup_file connection: local - assert: that: - backup_file.files is defined - name: take configuration backup in custom filename register: result vyos.vyos.vyos_config: backup: true backup_options: filename: backup.cfg - assert: that: - result.changed == true - name: check if the backup file-2 exist - find: + ansible.builtin.find: paths: "{{ role_path }}/backup/backup.cfg" register: backup_file connection: local - assert: that: - backup_file.files is defined - name: take configuration backup in custom path and default filename register: result vyos.vyos.vyos_config: backup: true backup_options: dir_path: "{{ role_path }}/backup_test_dir/{{ inventory_hostname_short }}" - assert: that: - result.changed == true - name: check if the backup file-3 exist - find: + ansible.builtin.find: paths: "{{ role_path }}/backup_test_dir/{{ inventory_hostname_short }}" pattern: "{{ inventory_hostname_short }}_config*" register: backup_file connection: local - assert: that: - backup_file.files is defined - debug: msg="END vyos/backup.yaml on connection={{ ansible_connection }}" diff --git a/tests/integration/targets/vyos_config/tests/cli/check_config.yaml b/tests/integration/targets/vyos_config/tests/cli/check_config.yaml index 83a62197..a03a3115 100644 --- a/tests/integration/targets/vyos_config/tests/cli/check_config.yaml +++ b/tests/integration/targets/vyos_config/tests/cli/check_config.yaml @@ -1,91 +1,111 @@ --- - debug: msg="START cli/config_check.yaml on connection={{ ansible_connection }}" - name: setup- ensure interface is not present vyos.vyos.vyos_config: lines: delete interfaces loopback lo - name: setup- create interface register: result vyos.vyos.vyos_config: lines: - interfaces - interfaces loopback lo - interfaces loopback lo description test - name: Check that multiple duplicate lines collapse into a single commands assert: that: - result.commands|length == 1 - name: Check that set is correctly prepended assert: that: - result.commands[0] == 'set interfaces loopback lo description test' - name: configure config_check config command register: result vyos.vyos.vyos_config: lines: delete interfaces loopback lo - assert: that: - result.changed == true - name: check config_check config command idempontent register: result vyos.vyos.vyos_config: lines: delete interfaces loopback lo - assert: that: - result.changed == false -- name: check multiple line config filter is working - register: result +- name: setup- ensure test login accounts are not present vyos.vyos.vyos_config: lines: - - set system login user esa full-name 'ESA admin' - - set system login user esa authentication encrypted-password '!abc!' - - set system login user vyos full-name 'VyOS admin' - - set system login user vyos authentication encrypted-password 'abc' - - set system login user john full-name 'John' - - set system login user john authentication plaintext-password 'xyz' + - delete system login user testesa + - delete system login user testadmin + - delete system login user testjohn + match: none + ignore_errors: true -- assert: - that: - - result.filtered|length == 2 +- block: + - name: check multiple line config filter is working + register: result + vyos.vyos.vyos_config: + lines: + - set system login user testesa full-name 'ESA admin' + - set system login user testesa authentication encrypted-password '!abc!' + - set system login user testadmin full-name 'Test admin' + - set system login user testadmin authentication encrypted-password 'abc' + - set system login user testjohn full-name 'John' + - set system login user testjohn authentication plaintext-password 'xyz' -- name: check multiple line config filter is working - register: result - vyos.vyos.vyos_config: - allow_password_change: none - lines: - - set system login user esa full-name 'ESA admin' - - set system login user esa authentication encrypted-password '!abc!' - - set system login user vyos full-name 'VyOS admin' - - set system login user vyos authentication encrypted-password 'abc' - - set system login user john full-name 'John' - - set system login user john authentication plaintext-password 'xyz' + - assert: + that: + - result.filtered|length == 2 -- assert: - that: - - result.filtered|length == 3 + - name: check multiple line config filter is working + register: result + vyos.vyos.vyos_config: + allow_password_change: none + lines: + - set system login user testesa full-name 'ESA admin' + - set system login user testesa authentication encrypted-password '!abc!' + - set system login user testadmin full-name 'Test admin' + - set system login user testadmin authentication encrypted-password 'abc' + - set system login user testjohn full-name 'John' + - set system login user testjohn authentication plaintext-password 'xyz' -- name: check multiple line config filter is working - register: result - vyos.vyos.vyos_config: - allow_password_change: all - lines: - - set system login user esa full-name 'ESA admin' - - set system login user esa authentication encrypted-password '!abc!' - - set system login user vyos full-name 'VyOS admin' - - set system login user vyos authentication encrypted-password 'abc' - - set system login user john full-name 'John' - - set system login user john authentication plaintext-password 'xyz' + - assert: + that: + - result.filtered|length == 3 -- assert: - that: - - result.filtered|length == 0 + - name: check multiple line config filter is working + register: result + vyos.vyos.vyos_config: + allow_password_change: all + lines: + - set system login user testesa full-name 'ESA admin' + - set system login user testesa authentication encrypted-password '$5$jR0jeXg3jHzSN7k3$33fO1qz3CVzsWJhxksLE7.KTIizYWGAMsd6LH9ItJmB' + - set system login user testadmin full-name 'Test admin' + - set system login user testadmin authentication encrypted-password '$5$YVhfNdmQbKQpDROb$N1b2nKh69wvrtQu7JwiIp/IsWlLHU8QCDcNGVaRWh6.' + - set system login user testjohn full-name 'John' + - set system login user testjohn authentication plaintext-password 'xyz' + + - assert: + that: + - result.filtered|length == 0 + + always: + - name: cleanup test login accounts created by password filter checks + vyos.vyos.vyos_config: + lines: + - delete system login user testesa + - delete system login user testadmin + - delete system login user testjohn + match: none + ignore_errors: true - debug: msg="END cli/config_check.yaml on connection={{ ansible_connection }}" diff --git a/tests/integration/targets/vyos_config/tests/cli/confirm.yaml b/tests/integration/targets/vyos_config/tests/cli/confirm.yaml index 73674a17..a7a3cff4 100644 --- a/tests/integration/targets/vyos_config/tests/cli/confirm.yaml +++ b/tests/integration/targets/vyos_config/tests/cli/confirm.yaml @@ -1,44 +1,55 @@ --- - debug: msg="START cli/confirm.yaml on connection={{ ansible_connection }}" - name: setup vyos.vyos.vyos_config: lines: set system host-name {{ inventory_hostname_short }} match: none - name: configure with confirm (manual) register: result vyos.vyos.vyos_config: lines: set system host-name foo comment: confirm manual test confirm: manual confirm_timeout: 1 - assert: that: - result.changed == true - "'set system host-name foo' in result.commands" - name: verify hostname changed to foo register: hostname_after vyos.vyos.vyos_command: commands: show host name - assert: that: - "'foo' in hostname_after.stdout[0]" +- name: pause to allow confirm timeout to elapse and device to revert/reboot + pause: + seconds: 75 + +- name: reset connection to avoid stale ssh channel after device reboot + meta: reset_connection + - name: wait until config auto-reverts (no confirmation) register: hostname_reverted vyos.vyos.vyos_command: commands: show host name retries: 18 - delay: 5 - until: inventory_hostname_short in hostname_reverted.stdout[0] + delay: 10 + until: hostname_reverted is succeeded and inventory_hostname_short in hostname_reverted.stdout[0] + ignore_unreachable: true + +- name: reset connection after device reboot recovery + meta: reset_connection - name: teardown vyos.vyos.vyos_config: lines: set system host-name {{ inventory_hostname_short }} match: none - debug: msg="END cli/confirm.yaml on connection={{ ansible_connection }}" diff --git a/tests/integration/targets/vyos_config/tests/cli_config/cli_backup.yaml b/tests/integration/targets/vyos_config/tests/cli_config/cli_backup.yaml index 03450c31..681a22ee 100644 --- a/tests/integration/targets/vyos_config/tests/cli_config/cli_backup.yaml +++ b/tests/integration/targets/vyos_config/tests/cli_config/cli_backup.yaml @@ -1,111 +1,113 @@ --- - debug: msg="END cli_config/backup.yaml on connection={{ ansible_connection }}" - name: delete configurable backup file path - file: + ansible.builtin.file: path: "{{ item }}" state: absent with_items: - "{{ role_path }}/backup_test_dir/" - "{{ role_path }}/backup/backup.cfg" run_once: true + connection: local - name: collect any backup files - find: + ansible.builtin.find: paths: "{{ role_path }}/backup" pattern: "{{ inventory_hostname_short }}_config*" register: backup_files connection: local - name: delete backup files - file: + ansible.builtin.file: path: "{{ item.path }}" state: absent with_items: "{{backup_files.files|default([])}}" + connection: local - name: take config backup register: result ansible.netcommon.cli_config: backup: true - assert: that: - result.changed == true - name: collect any backup files - find: + ansible.builtin.find: paths: "{{ role_path }}/backup" pattern: "{{ inventory_hostname_short }}_config*" register: backup_files connection: local - assert: that: - backup_files.files is defined - name: take configuration backup in custom filename and directory path register: result ansible.netcommon.cli_config: backup: true backup_options: filename: backup.cfg dir_path: "{{ role_path }}/backup_test_dir/{{ inventory_hostname_short }}" - assert: that: - result.changed == true - name: check if the backup file-1 exist - find: + ansible.builtin.find: paths: "{{ role_path }}/backup_test_dir/{{ inventory_hostname_short }}/backup.cfg" register: backup_file connection: local - assert: that: - backup_file.files is defined - name: take configuration backup in custom filename register: result ansible.netcommon.cli_config: backup: true backup_options: filename: backup.cfg - assert: that: - result.changed == true - name: check if the backup file-2 exist - find: + ansible.builtin.find: paths: "{{ role_path }}/backup/backup.cfg" register: backup_file connection: local - assert: that: - backup_file.files is defined - name: take configuration backup in custom path and default filename register: result ansible.netcommon.cli_config: backup: true backup_options: dir_path: "{{ role_path }}/backup_test_dir/{{ inventory_hostname_short }}" - assert: that: - result.changed == true - name: check if the backup file-3 exist - find: + ansible.builtin.find: paths: "{{ role_path }}/backup_test_dir/{{ inventory_hostname_short }}" pattern: "{{ inventory_hostname_short }}_config*" register: backup_file connection: local - assert: that: - backup_file.files is defined - debug: msg="END cli_config/backup.yaml on connection={{ ansible_connection }}"