summaryrefslogtreecommitdiff
path: root/tests/integration/targets/vyos_hostname
diff options
context:
space:
mode:
authorGomathiselviS <gomathiselvi@gmail.com>2022-02-17 10:10:20 -0500
committerGitHub <noreply@github.com>2022-02-17 15:10:20 +0000
commit4662d6d03742ecc2fd09c530cf4b70217975e5bb (patch)
tree8847ac8ab689e9345cc3bd854bec3ca7bc7a9d94 /tests/integration/targets/vyos_hostname
parentb30bbaed76a22d002395802a0f72966fa2dde64a (diff)
downloadvyos-ansible-collection-4662d6d03742ecc2fd09c530cf4b70217975e5bb.tar.gz
vyos-ansible-collection-4662d6d03742ecc2fd09c530cf4b70217975e5bb.zip
Add Vyos hostname resource module (#237)
Add Vyos hostname resource module SUMMARY ISSUE TYPE New Module Pull Request COMPONENT NAME ADDITIONAL INFORMATION Reviewed-by: Nilashish Chakraborty <nilashishchakraborty8@gmail.com> Reviewed-by: None <None>
Diffstat (limited to 'tests/integration/targets/vyos_hostname')
-rw-r--r--tests/integration/targets/vyos_hostname/defaults/main.yaml3
-rw-r--r--tests/integration/targets/vyos_hostname/meta/main.yaml2
-rw-r--r--tests/integration/targets/vyos_hostname/tasks/cli.yaml19
-rw-r--r--tests/integration/targets/vyos_hostname/tasks/main.yaml4
-rw-r--r--tests/integration/targets/vyos_hostname/tests/cli/_parsed.cfg1
-rw-r--r--tests/integration/targets/vyos_hostname/tests/cli/_populate_config.yaml8
-rw-r--r--tests/integration/targets/vyos_hostname/tests/cli/_remove_config.yaml8
-rw-r--r--tests/integration/targets/vyos_hostname/tests/cli/deleted.yaml40
-rw-r--r--tests/integration/targets/vyos_hostname/tests/cli/empty_config.yaml60
-rw-r--r--tests/integration/targets/vyos_hostname/tests/cli/gathered.yaml28
-rw-r--r--tests/integration/targets/vyos_hostname/tests/cli/merged.yaml45
-rw-r--r--tests/integration/targets/vyos_hostname/tests/cli/overridden.yaml42
-rw-r--r--tests/integration/targets/vyos_hostname/tests/cli/parsed.yaml17
-rw-r--r--tests/integration/targets/vyos_hostname/tests/cli/rendered.yaml21
-rw-r--r--tests/integration/targets/vyos_hostname/tests/cli/replaced.yaml42
-rw-r--r--tests/integration/targets/vyos_hostname/vars/main.yaml12
16 files changed, 352 insertions, 0 deletions
diff --git a/tests/integration/targets/vyos_hostname/defaults/main.yaml b/tests/integration/targets/vyos_hostname/defaults/main.yaml
new file mode 100644
index 0000000..852a6be
--- /dev/null
+++ b/tests/integration/targets/vyos_hostname/defaults/main.yaml
@@ -0,0 +1,3 @@
+---
+testcase: '[^_].*'
+test_items: []
diff --git a/tests/integration/targets/vyos_hostname/meta/main.yaml b/tests/integration/targets/vyos_hostname/meta/main.yaml
new file mode 100644
index 0000000..91da2a7
--- /dev/null
+++ b/tests/integration/targets/vyos_hostname/meta/main.yaml
@@ -0,0 +1,2 @@
+---
+...
diff --git a/tests/integration/targets/vyos_hostname/tasks/cli.yaml b/tests/integration/targets/vyos_hostname/tasks/cli.yaml
new file mode 100644
index 0000000..93eb2fe
--- /dev/null
+++ b/tests/integration/targets/vyos_hostname/tasks/cli.yaml
@@ -0,0 +1,19 @@
+---
+- name: Collect all cli test cases
+ find:
+ paths: '{{ role_path }}/tests/cli'
+ patterns: '{{ testcase }}.yaml'
+ use_regex: true
+ 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=ansible.netcommon.network_cli)
+ include: '{{ test_case_to_run }}'
+ vars:
+ ansible_connection: ansible.netcommon.network_cli
+ with_items: '{{ test_items }}'
+ loop_control:
+ loop_var: test_case_to_run
diff --git a/tests/integration/targets/vyos_hostname/tasks/main.yaml b/tests/integration/targets/vyos_hostname/tasks/main.yaml
new file mode 100644
index 0000000..b957d2f
--- /dev/null
+++ b/tests/integration/targets/vyos_hostname/tasks/main.yaml
@@ -0,0 +1,4 @@
+---
+- include: cli.yaml
+ tags:
+ - network_cli
diff --git a/tests/integration/targets/vyos_hostname/tests/cli/_parsed.cfg b/tests/integration/targets/vyos_hostname/tests/cli/_parsed.cfg
new file mode 100644
index 0000000..3353c40
--- /dev/null
+++ b/tests/integration/targets/vyos_hostname/tests/cli/_parsed.cfg
@@ -0,0 +1 @@
+set system host-name 'vyosTest'
diff --git a/tests/integration/targets/vyos_hostname/tests/cli/_populate_config.yaml b/tests/integration/targets/vyos_hostname/tests/cli/_populate_config.yaml
new file mode 100644
index 0000000..4d33289
--- /dev/null
+++ b/tests/integration/targets/vyos_hostname/tests/cli/_populate_config.yaml
@@ -0,0 +1,8 @@
+---
+- name: setup
+ vyos.vyos.vyos_config:
+ lines:
+ - set system host-name 'vyos'
+ ignore_errors: true
+ vars:
+ ansible_connection: ansible.netcommon.network_cli
diff --git a/tests/integration/targets/vyos_hostname/tests/cli/_remove_config.yaml b/tests/integration/targets/vyos_hostname/tests/cli/_remove_config.yaml
new file mode 100644
index 0000000..229c79c
--- /dev/null
+++ b/tests/integration/targets/vyos_hostname/tests/cli/_remove_config.yaml
@@ -0,0 +1,8 @@
+---
+- name: Remove pre-existing hostname config
+ vyos.vyos.vyos_hostname:
+ config:
+ state: deleted
+ ignore_errors: true
+ vars:
+ ansible_connection: ansible.netcommon.network_cli
diff --git a/tests/integration/targets/vyos_hostname/tests/cli/deleted.yaml b/tests/integration/targets/vyos_hostname/tests/cli/deleted.yaml
new file mode 100644
index 0000000..5f9df51
--- /dev/null
+++ b/tests/integration/targets/vyos_hostname/tests/cli/deleted.yaml
@@ -0,0 +1,40 @@
+---
+- debug:
+ msg: START vyos_hostname deleted integration tests on connection={{ansible_connection }}
+
+- include_tasks: _remove_config.yaml
+
+- include_tasks: _populate_config.yaml
+
+- block:
+
+ - name: Delete the provided configuration
+ register: result
+ vyos.vyos.vyos_hostname: &id001
+ config:
+ state: deleted
+
+ - name: Assert that before dicts were correctly generated
+ assert:
+ that:
+ - result.changed == true
+ - result.commands == deleted.commands
+
+ - name: Assert that the after dicts were correctly generated
+ assert:
+ that:
+ - result.after == {}
+
+ - name: Delete the existing configuration with the provided running configuration
+ (IDEMPOTENT)
+ register: result
+ vyos.vyos.vyos_hostname: *id001
+
+ - name: Assert that the previous task was idempotent
+ assert:
+ that:
+ - result['changed'] == false
+
+ always:
+
+ - include_tasks: _remove_config.yaml
diff --git a/tests/integration/targets/vyos_hostname/tests/cli/empty_config.yaml b/tests/integration/targets/vyos_hostname/tests/cli/empty_config.yaml
new file mode 100644
index 0000000..8efead2
--- /dev/null
+++ b/tests/integration/targets/vyos_hostname/tests/cli/empty_config.yaml
@@ -0,0 +1,60 @@
+---
+- debug:
+ msg: START vyos_hostname empty_config integration tests on connection={{
+ ansible_connection }}
+
+- name: Merged with empty config should give appropriate error message
+ register: result
+ ignore_errors: true
+ vyos.vyos.vyos_hostname:
+ config:
+ state: merged
+
+- assert:
+ that:
+ - result.msg == 'value of config parameter must not be empty for state merged'
+
+- name: Replaced with empty config should give appropriate error message
+ register: result
+ ignore_errors: true
+ vyos.vyos.vyos_hostname:
+ config:
+ state: replaced
+
+- assert:
+ that:
+ - result.msg == 'value of config parameter must not be empty for state replaced'
+
+- name: Overridden with empty config should give appropriate error message
+ register: result
+ ignore_errors: true
+ vyos.vyos.vyos_hostname:
+ config:
+ state: overridden
+
+- assert:
+ that:
+ - result.msg == 'value of config parameter must not be empty for state overridden'
+
+- name: Parsed with empty running_config should give appropriate error message
+ register: result
+ ignore_errors: true
+ vyos.vyos.vyos_hostname:
+ running_config:
+ state: parsed
+
+- assert:
+ that:
+ - result.msg == 'value of running_config parameter must not be empty for state
+ parsed'
+
+- name: Rendered with empty config should give appropriate error message
+ register: result
+ ignore_errors: true
+ vyos.vyos.vyos_hostname:
+ config:
+ state: rendered
+
+- assert:
+ that:
+ - result.msg == 'value of config parameter must not be empty for state rendered'
diff --git a/tests/integration/targets/vyos_hostname/tests/cli/gathered.yaml b/tests/integration/targets/vyos_hostname/tests/cli/gathered.yaml
new file mode 100644
index 0000000..0509fc5
--- /dev/null
+++ b/tests/integration/targets/vyos_hostname/tests/cli/gathered.yaml
@@ -0,0 +1,28 @@
+---
+- debug:
+ msg: START vyos_hostname gathered integration tests on connection={{
+ ansible_connection }}
+
+- include_tasks: _remove_config.yaml
+
+- include_tasks: _populate_config.yaml
+
+- block:
+
+ - name: Gather config from the device in structured format.
+ register: result
+ vyos.vyos.vyos_hostname:
+ state: gathered
+
+ - vyos.vyos.vyos_facts:
+ gather_network_resources: hostname
+
+ - name: Assert that facts are correctly generated
+ assert:
+ that:
+ - result.changed == false
+ - result.gathered == ansible_facts['network_resources']['hostname']
+
+ always:
+
+ - include_tasks: _remove_config.yaml
diff --git a/tests/integration/targets/vyos_hostname/tests/cli/merged.yaml b/tests/integration/targets/vyos_hostname/tests/cli/merged.yaml
new file mode 100644
index 0000000..f9b28c7
--- /dev/null
+++ b/tests/integration/targets/vyos_hostname/tests/cli/merged.yaml
@@ -0,0 +1,45 @@
+---
+- debug:
+ msg: START vyos_hostname merged integration tests on connection={{
+ ansible_connection }}
+
+- include_tasks: _remove_config.yaml
+
+- block:
+ - name: Merge the provided configuration with the existing running configuration
+ register: result
+ vyos.vyos.vyos_hostname: &id001
+ config:
+ hostname: "vyosTest"
+ state: merged
+
+ - vyos.vyos.vyos_facts:
+ gather_network_resources: hostname
+
+ - assert:
+ that:
+ - result.commands|length == 1
+ - result.changed == true
+ - result.commands|symmetric_difference(merged.commands) == []
+ - result.after == ansible_facts['network_resources']['hostname']
+ - result.after == merged.after
+
+
+ - name: Assert that before dicts were correctly generated
+ assert:
+ that:
+ - result.before == {}
+
+ - name:
+ Merge the provided configuration with the existing running configuration
+ (IDEMPOTENT)
+ register: result
+ vyos.vyos.vyos_hostname: *id001
+
+ - name: Assert that the previous task was idempotent
+ assert:
+ that:
+ - result['changed'] == false
+
+ always:
+ - include_tasks: _remove_config.yaml
diff --git a/tests/integration/targets/vyos_hostname/tests/cli/overridden.yaml b/tests/integration/targets/vyos_hostname/tests/cli/overridden.yaml
new file mode 100644
index 0000000..d9fd76d
--- /dev/null
+++ b/tests/integration/targets/vyos_hostname/tests/cli/overridden.yaml
@@ -0,0 +1,42 @@
+---
+- debug:
+ msg: START vyos_hostname overridden integration tests on connection={{
+ ansible_connection }}
+
+- include_tasks: _remove_config.yaml
+
+- include_tasks: _populate_config.yaml
+
+- block:
+ - name: override the provided configuration with the existing running configuration
+ register: result
+ vyos.vyos.vyos_hostname: &id001
+ config:
+ hostname: "vyosTest"
+ state: overridden
+
+ - vyos.vyos.vyos_facts:
+ gather_network_resources: hostname
+
+ - assert:
+ that:
+ - result.commands|length == 1
+ - result.changed == true
+ - result.commands|symmetric_difference(merged.commands) == []
+ - result.after == ansible_facts['network_resources']['hostname']
+ - result.after == merged.after
+
+
+ - name:
+ override the provided configuration with the existing running configuration
+ (IDEMPOTENT)
+ register: result
+ vyos.vyos.vyos_hostname: *id001
+
+ - name: Assert that the previous task was idempotent
+ assert:
+ that:
+ - result['changed'] == false
+
+ always:
+ - include_tasks: _remove_config.yaml
diff --git a/tests/integration/targets/vyos_hostname/tests/cli/parsed.yaml b/tests/integration/targets/vyos_hostname/tests/cli/parsed.yaml
new file mode 100644
index 0000000..f6c00bb
--- /dev/null
+++ b/tests/integration/targets/vyos_hostname/tests/cli/parsed.yaml
@@ -0,0 +1,17 @@
+---
+- debug:
+ msg: START vyos_hostname parsed integration tests on connection={{ ansible_connection
+ }}
+
+- name: Provide the running configuration for parsing (config to be parsed)
+ register: result
+ vyos.vyos.vyos_hostname:
+ running_config: "{{ lookup('file', '_parsed.cfg') }}"
+ state: parsed
+
+
+- name: Assert that config was correctly parsed
+ assert:
+ that:
+ - result.changed == false
+ - result.parsed == merged.after
diff --git a/tests/integration/targets/vyos_hostname/tests/cli/rendered.yaml b/tests/integration/targets/vyos_hostname/tests/cli/rendered.yaml
new file mode 100644
index 0000000..28ec797
--- /dev/null
+++ b/tests/integration/targets/vyos_hostname/tests/cli/rendered.yaml
@@ -0,0 +1,21 @@
+---
+- debug:
+ msg: START vyos_hostname rendered integration tests on connection={{
+ ansible_connection }}
+
+- include_tasks: _remove_config.yaml
+
+- block:
+ - name: Render the given configuration in the form of native commands
+ register: result
+ vyos.vyos.vyos_hostname:
+ config:
+ hostname: 'vyosTest'
+ state: rendered
+
+ - assert:
+ that:
+ - result.changed == false
+ - result.rendered|symmetric_difference(merged.commands) == []
+ always:
+ - include_tasks: _remove_config.yaml
diff --git a/tests/integration/targets/vyos_hostname/tests/cli/replaced.yaml b/tests/integration/targets/vyos_hostname/tests/cli/replaced.yaml
new file mode 100644
index 0000000..6acb993
--- /dev/null
+++ b/tests/integration/targets/vyos_hostname/tests/cli/replaced.yaml
@@ -0,0 +1,42 @@
+---
+- debug:
+ msg: START vyos_hostname replaced integration tests on connection={{
+ ansible_connection }}
+
+- include_tasks: _remove_config.yaml
+
+- include_tasks: _populate_config.yaml
+
+- block:
+ - name: Replace the provided configuration with the existing running configuration
+ register: result
+ vyos.vyos.vyos_hostname: &id001
+ config:
+ hostname: "vyosTest"
+ state: replaced
+
+ - vyos.vyos.vyos_facts:
+ gather_network_resources: hostname
+
+ - assert:
+ that:
+ - result.commands|length == 1
+ - result.changed == true
+ - result.commands|symmetric_difference(merged.commands) == []
+ - result.after == ansible_facts['network_resources']['hostname']
+ - result.after == merged.after
+
+
+ - name:
+ Replace the provided configuration with the existing running configuration
+ (IDEMPOTENT)
+ register: result
+ vyos.vyos.vyos_hostname: *id001
+
+ - name: Assert that the previous task was idempotent
+ assert:
+ that:
+ - result['changed'] == false
+
+ always:
+ - include_tasks: _remove_config.yaml
diff --git a/tests/integration/targets/vyos_hostname/vars/main.yaml b/tests/integration/targets/vyos_hostname/vars/main.yaml
new file mode 100644
index 0000000..a6b4986
--- /dev/null
+++ b/tests/integration/targets/vyos_hostname/vars/main.yaml
@@ -0,0 +1,12 @@
+---
+merged:
+ before: {}
+ commands:
+ - set system host-name vyosTest
+ after:
+ hostname: 'vyosTest'
+
+deleted:
+ commands:
+ - delete system host-name vyos
+ after: {}