diff options
Diffstat (limited to 'tests/integration/targets/vyos_config')
13 files changed, 513 insertions, 0 deletions
diff --git a/tests/integration/targets/vyos_config/aliases b/tests/integration/targets/vyos_config/aliases new file mode 100644 index 0000000..539d957 --- /dev/null +++ b/tests/integration/targets/vyos_config/aliases @@ -0,0 +1 @@ +shippable/network diff --git a/tests/integration/targets/vyos_config/defaults/main.yaml b/tests/integration/targets/vyos_config/defaults/main.yaml new file mode 100644 index 0000000..9ef5ba5 --- /dev/null +++ b/tests/integration/targets/vyos_config/defaults/main.yaml @@ -0,0 +1,3 @@ +--- +testcase: "*" +test_items: [] diff --git a/tests/integration/targets/vyos_config/tasks/cli.yaml b/tests/integration/targets/vyos_config/tasks/cli.yaml new file mode 100644 index 0000000..890d3ac --- /dev/null +++ b/tests/integration/targets/vyos_config/tasks/cli.yaml @@ -0,0 +1,22 @@ +--- +- name: collect all cli test cases + find: + paths: "{{ role_path }}/tests/cli" + patterns: "{{ testcase }}.yaml" + register: test_cases + delegate_to: localhost + +- name: set test_items + set_fact: test_items="{{ test_cases.files | map(attribute='path') | list }}" + +- name: run test case (connection=network_cli) + include: "{{ test_case_to_run }} ansible_connection=network_cli" + with_items: "{{ test_items }}" + loop_control: + loop_var: test_case_to_run + +- name: run test case (connection=local) + include: "{{ test_case_to_run }} ansible_connection=local" + with_first_found: "{{ test_items }}" + loop_control: + loop_var: test_case_to_run diff --git a/tests/integration/targets/vyos_config/tasks/cli_config.yaml b/tests/integration/targets/vyos_config/tasks/cli_config.yaml new file mode 100644 index 0000000..f5d5b55 --- /dev/null +++ b/tests/integration/targets/vyos_config/tasks/cli_config.yaml @@ -0,0 +1,16 @@ +--- +- name: collect all cli_config test cases + find: + paths: "{{ role_path }}/tests/cli_config" + patterns: "{{ testcase }}.yaml" + register: test_cases + delegate_to: localhost + +- name: set test_items + set_fact: test_items="{{ test_cases.files | map(attribute='path') | list }}" + +- name: run test case (connection=network_cli) + include: "{{ test_case_to_run }} ansible_connection=network_cli" + with_items: "{{ test_items }}" + loop_control: + loop_var: test_case_to_run diff --git a/tests/integration/targets/vyos_config/tasks/main.yaml b/tests/integration/targets/vyos_config/tasks/main.yaml new file mode 100644 index 0000000..5e327e8 --- /dev/null +++ b/tests/integration/targets/vyos_config/tasks/main.yaml @@ -0,0 +1,3 @@ +--- +- { include: cli.yaml, tags: ['cli'] } +- { include: cli_config.yaml, tags: ['cli_config'] } diff --git a/tests/integration/targets/vyos_config/tests/cli/backup.yaml b/tests/integration/targets/vyos_config/tests/cli/backup.yaml new file mode 100644 index 0000000..0ef0986 --- /dev/null +++ b/tests/integration/targets/vyos_config/tests/cli/backup.yaml @@ -0,0 +1,113 @@ +--- +- debug: msg="START vyos/backup.yaml on connection={{ ansible_connection }}" + +- name: collect any backup files + find: + paths: "{{ role_path }}/backup" + pattern: "{{ inventory_hostname_short }}_config*" + register: backup_files + connection: local + +- name: delete backup files + file: + path: "{{ item.path }}" + state: absent + with_items: "{{backup_files.files|default([])}}" + +- name: take configure backup + vyos.vyos.vyos_config: + backup: yes + register: result + +- assert: + that: + - "result.changed == true" + +- name: collect any backup files + 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: + path: "{{ item }}" + state: absent + with_items: + - "{{ role_path }}/backup_test_dir/" + - "{{ role_path }}/backup/backup.cfg" + +- name: take configuration backup in custom filename and directory path + vyos.vyos.vyos_config: + backup: yes + backup_options: + filename: backup.cfg + dir_path: "{{ role_path }}/backup_test_dir/{{ inventory_hostname_short }}" + become: yes + register: result + +- assert: + that: + - "result.changed == true" + +- name: check if the backup file-1 exist + 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 + vyos.vyos.vyos_config: + backup: yes + backup_options: + filename: backup.cfg + become: yes + register: result + +- assert: + that: + - "result.changed == true" + +- name: check if the backup file-2 exist + 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 + vyos.vyos.vyos_config: + backup: yes + backup_options: + dir_path: "{{ role_path }}/backup_test_dir/{{ inventory_hostname_short }}" + become: yes + register: result + +- assert: + that: + - "result.changed == true" + +- name: check if the backup file-3 exist + 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 new file mode 100644 index 0000000..b90ec7b --- /dev/null +++ b/tests/integration/targets/vyos_config/tests/cli/check_config.yaml @@ -0,0 +1,63 @@ +--- +- 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 + vyos.vyos.vyos_config: + lines: + - interfaces + - interfaces loopback lo + - interfaces loopback lo description test + register: result + +# note collapsing the duplicate lines doesn't work if +# lines: +# - interfaces loopback lo description test +# - interfaces loopback lo +# - interfaces + +- 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 + vyos.vyos.vyos_config: + lines: delete interfaces loopback lo + register: result + +- assert: + that: + - "result.changed == true" + +- name: check config_check config command idempontent + vyos.vyos.vyos_config: + lines: delete interfaces loopback lo + register: result + +- assert: + that: + - "result.changed == false" + +- name: check multiple line config filter is working + vyos.vyos.vyos_config: + lines: + - set system login user esa level admin + - set system login user esa authentication encrypted-password '!abc!' + - set system login user vyos level admin + - set system login user vyos authentication encrypted-password 'abc' + register: result + +- assert: + that: + - "{{ result.filtered|length }} == 2" + +- debug: msg="END cli/config_check.yaml on connection={{ ansible_connection }}" diff --git a/tests/integration/targets/vyos_config/tests/cli/comment.yaml b/tests/integration/targets/vyos_config/tests/cli/comment.yaml new file mode 100644 index 0000000..2cd1350 --- /dev/null +++ b/tests/integration/targets/vyos_config/tests/cli/comment.yaml @@ -0,0 +1,34 @@ +--- +- debug: msg="START cli/comment.yaml on connection={{ ansible_connection }}" + +- name: setup + vyos.vyos.vyos_config: + lines: set system host-name {{ inventory_hostname_short }} + match: none + +- name: configure using comment + vyos.vyos.vyos_config: + lines: set system host-name foo + comment: this is a test + register: result + +- assert: + that: + - "result.changed == true" + - "'set system host-name foo' in result.commands" + +- name: collect system commits + vyos.vyos.vyos_command: + commands: show system commit + register: result + +- assert: + that: + - "'this is a test' in result.stdout_lines[0][1]" + +- name: teardown + vyos.vyos.vyos_config: + lines: set system host-name {{ inventory_hostname_short }} + match: none + +- debug: msg="END cli/comment.yaml on connection={{ ansible_connection }}" diff --git a/tests/integration/targets/vyos_config/tests/cli/save.yaml b/tests/integration/targets/vyos_config/tests/cli/save.yaml new file mode 100644 index 0000000..d8e45e2 --- /dev/null +++ b/tests/integration/targets/vyos_config/tests/cli/save.yaml @@ -0,0 +1,54 @@ +--- +- debug: msg="START cli/save.yaml on connection={{ ansible_connection }}" + +- name: setup + vyos.vyos.vyos_config: + lines: set system host-name {{ inventory_hostname_short }} + match: none + +- name: configure hostaname and save + vyos.vyos.vyos_config: + lines: set system host-name foo + save: true + register: result + +- assert: + that: + - "result.changed == true" + - "'set system host-name foo' in result.commands" + +- name: configure hostaname and don't save + vyos.vyos.vyos_config: + lines: set system host-name bar + register: result + +- assert: + that: + - "result.changed == true" + - "'set system host-name bar' in result.commands" + +- name: save config + vyos.vyos.vyos_config: + save: true + register: result + +- assert: + that: + - "result.changed == true" + +- name: save config again + vyos.vyos.vyos_config: + save: true + register: result + +- assert: + that: + - "result.changed == false" + +- name: teardown + vyos.vyos.vyos_config: + lines: set system host-name {{ inventory_hostname_short }} + match: none + save: true + +- debug: msg="END cli/simple.yaml on connection={{ ansible_connection }}" diff --git a/tests/integration/targets/vyos_config/tests/cli/simple.yaml b/tests/integration/targets/vyos_config/tests/cli/simple.yaml new file mode 100644 index 0000000..af211f5 --- /dev/null +++ b/tests/integration/targets/vyos_config/tests/cli/simple.yaml @@ -0,0 +1,33 @@ +--- +- debug: msg="START cli/simple.yaml on connection={{ ansible_connection }}" + +- name: setup + vyos.vyos.vyos_config: + lines: set system host-name {{ inventory_hostname_short }} + match: none + +- name: configure simple config command + vyos.vyos.vyos_config: + lines: set system host-name foo + register: result + +- assert: + that: + - "result.changed == true" + - "'set system host-name foo' in result.commands" + +- name: check simple config command idempontent + vyos.vyos.vyos_config: + lines: set system host-name foo + register: result + +- assert: + that: + - "result.changed == false" + +- name: teardown + vyos.vyos.vyos_config: + lines: set system host-name {{ inventory_hostname_short }} + match: none + +- debug: msg="END cli/simple.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 new file mode 100644 index 0000000..8057705 --- /dev/null +++ b/tests/integration/targets/vyos_config/tests/cli_config/cli_backup.yaml @@ -0,0 +1,113 @@ +- debug: msg="END cli_config/backup.yaml on connection={{ ansible_connection }}" + +- name: delete configurable backup file path + file: + path: "{{ item }}" + state: absent + with_items: + - "{{ role_path }}/backup_test_dir/" + - "{{ role_path }}/backup/backup.cfg" + +- name: collect any backup files + find: + paths: "{{ role_path }}/backup" + pattern: "{{ inventory_hostname_short }}_config*" + register: backup_files + connection: local + +- name: delete backup files + file: + path: "{{ item.path }}" + state: absent + with_items: "{{backup_files.files|default([])}}" + +- name: take config backup + network.cli.cli_config: + backup: yes + become: yes + register: result + +- assert: + that: + - "result.changed == true" + +- name: collect any backup files + 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 + network.cli.cli_config: + backup: yes + backup_options: + filename: backup.cfg + dir_path: "{{ role_path }}/backup_test_dir/{{ inventory_hostname_short }}" + become: yes + register: result + +- assert: + that: + - "result.changed == true" + +- name: check if the backup file-1 exist + 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 + network.cli.cli_config: + backup: yes + backup_options: + filename: backup.cfg + become: yes + register: result + +- assert: + that: + - "result.changed == true" + +- name: check if the backup file-2 exist + 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 + network.cli.cli_config: + backup: yes + backup_options: + dir_path: "{{ role_path }}/backup_test_dir/{{ inventory_hostname_short }}" + become: yes + register: result + +- assert: + that: + - "result.changed == true" + +- name: check if the backup file-3 exist + 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 }}" diff --git a/tests/integration/targets/vyos_config/tests/cli_config/cli_basic.yaml b/tests/integration/targets/vyos_config/tests/cli_config/cli_basic.yaml new file mode 100644 index 0000000..e5e3edb --- /dev/null +++ b/tests/integration/targets/vyos_config/tests/cli_config/cli_basic.yaml @@ -0,0 +1,28 @@ +--- +- debug: msg="START cli_config/cli_basic.yaml on connection={{ ansible_connection }}" + +- name: setup - remove interface description + network.cli.cli_config: &rm + config: delete interfaces loopback lo description + +- name: configure device with config + network.cli.cli_config: &conf + config: set interfaces loopback lo description 'this is a test' + register: result + +- assert: + that: + - "result.changed == true" + +- name: Idempotence + network.cli.cli_config: *conf + register: result + +- assert: + that: + - "result.changed == false" + +- name: teardown + network.cli.cli_config: *rm + +- debug: msg="END cli_config/cli_basic.yaml on connection={{ ansible_connection }}" diff --git a/tests/integration/targets/vyos_config/tests/cli_config/cli_comment.yaml b/tests/integration/targets/vyos_config/tests/cli_config/cli_comment.yaml new file mode 100644 index 0000000..ecc9e8c --- /dev/null +++ b/tests/integration/targets/vyos_config/tests/cli_config/cli_comment.yaml @@ -0,0 +1,30 @@ +--- +- debug: msg="START cli_config/cli_comment.yaml on connection={{ ansible_connection }}" + +- name: setup + network.cli.cli_config: &rm + config: set system host-name {{ inventory_hostname_short }} + +- name: configure using comment + network.cli.cli_config: + config: set system host-name foo + commit_comment: this is a test + register: result + +- assert: + that: + - "result.changed == true" + +- name: collect system commits + vyos.vyos.vyos_command: + commands: show system commit + register: result + +- assert: + that: + - "'this is a test' in result.stdout_lines[0][1]" + +- name: teardown + network.cli.cli_config: *rm + +- debug: msg="END cli_config/cli_comment.yaml on connection={{ ansible_connection }}" |