summaryrefslogtreecommitdiff
path: root/tests/integration/targets
diff options
context:
space:
mode:
authorYVarshitha <63169351+YVarshitha@users.noreply.github.com>2021-10-02 13:28:30 -0400
committerGitHub <noreply@github.com>2021-10-02 17:28:30 +0000
commit85ea49f10a6167dea4c08e71a1e8e5a62cb57395 (patch)
tree0bfd9aa0bc06c1d342944fef3bc18f7c3d7ec047 /tests/integration/targets
parent88689227265b7f6b272b695a275f4a47735ddcc2 (diff)
downloadvyos.vyos-85ea49f10a6167dea4c08e71a1e8e5a62cb57395.tar.gz
vyos.vyos-85ea49f10a6167dea4c08e71a1e8e5a62cb57395.zip
Add vyos_ntp resource module (#175)
Add vyos_ntp resource module SUMMARY Resource module vyos_ntp ISSUE TYPE New Module Pull Request COMPONENT NAME vyos_ntp ADDITIONAL INFORMATION Reviewed-by: GomathiselviS <None> Reviewed-by: Nilashish Chakraborty <nilashishchakraborty8@gmail.com> Reviewed-by: None <None>
Diffstat (limited to 'tests/integration/targets')
-rw-r--r--tests/integration/targets/vyos_ntp_global/defaults/main.yaml3
-rw-r--r--tests/integration/targets/vyos_ntp_global/tasks/cli.yaml19
-rw-r--r--tests/integration/targets/vyos_ntp_global/tasks/main.yaml4
-rw-r--r--tests/integration/targets/vyos_ntp_global/tests/cli/_parsed.cfg5
-rw-r--r--tests/integration/targets/vyos_ntp_global/tests/cli/_populate_config.yaml13
-rw-r--r--tests/integration/targets/vyos_ntp_global/tests/cli/_remove_config.yaml8
-rw-r--r--tests/integration/targets/vyos_ntp_global/tests/cli/deleted.yaml40
-rw-r--r--tests/integration/targets/vyos_ntp_global/tests/cli/empty_config.yaml60
-rw-r--r--tests/integration/targets/vyos_ntp_global/tests/cli/gathered.yaml24
-rw-r--r--tests/integration/targets/vyos_ntp_global/tests/cli/merged.yaml58
-rw-r--r--tests/integration/targets/vyos_ntp_global/tests/cli/overridden.yaml53
-rw-r--r--tests/integration/targets/vyos_ntp_global/tests/cli/parsed.yaml17
-rw-r--r--tests/integration/targets/vyos_ntp_global/tests/cli/rendered.yaml33
-rw-r--r--tests/integration/targets/vyos_ntp_global/tests/cli/replaced.yaml42
-rw-r--r--tests/integration/targets/vyos_ntp_global/tests/cli/rtt.yaml70
-rw-r--r--tests/integration/targets/vyos_ntp_global/vars/main.yaml108
16 files changed, 557 insertions, 0 deletions
diff --git a/tests/integration/targets/vyos_ntp_global/defaults/main.yaml b/tests/integration/targets/vyos_ntp_global/defaults/main.yaml
new file mode 100644
index 0000000..852a6be
--- /dev/null
+++ b/tests/integration/targets/vyos_ntp_global/defaults/main.yaml
@@ -0,0 +1,3 @@
+---
+testcase: '[^_].*'
+test_items: []
diff --git a/tests/integration/targets/vyos_ntp_global/tasks/cli.yaml b/tests/integration/targets/vyos_ntp_global/tasks/cli.yaml
new file mode 100644
index 0000000..93eb2fe
--- /dev/null
+++ b/tests/integration/targets/vyos_ntp_global/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_ntp_global/tasks/main.yaml b/tests/integration/targets/vyos_ntp_global/tasks/main.yaml
new file mode 100644
index 0000000..b957d2f
--- /dev/null
+++ b/tests/integration/targets/vyos_ntp_global/tasks/main.yaml
@@ -0,0 +1,4 @@
+---
+- include: cli.yaml
+ tags:
+ - network_cli
diff --git a/tests/integration/targets/vyos_ntp_global/tests/cli/_parsed.cfg b/tests/integration/targets/vyos_ntp_global/tests/cli/_parsed.cfg
new file mode 100644
index 0000000..0608aef
--- /dev/null
+++ b/tests/integration/targets/vyos_ntp_global/tests/cli/_parsed.cfg
@@ -0,0 +1,5 @@
+set system ntp server 10.3.6.5 noselect
+set system ntp server 10.3.6.5 dynamic
+set system ntp server 0.pool.ntp.org
+set system ntp server 1.pool.ntp.org
+set system ntp server 2.pool.ntp.org
diff --git a/tests/integration/targets/vyos_ntp_global/tests/cli/_populate_config.yaml b/tests/integration/targets/vyos_ntp_global/tests/cli/_populate_config.yaml
new file mode 100644
index 0000000..035fcba
--- /dev/null
+++ b/tests/integration/targets/vyos_ntp_global/tests/cli/_populate_config.yaml
@@ -0,0 +1,13 @@
+---
+- name: setup
+ vyos.vyos.vyos_config:
+ lines:
+ - set system ntp server server4 dynamic
+ - set system ntp server server5 preempt
+ - set system ntp server 10.3.6.5 noselect
+ - set system ntp server 10.3.6.5 preempt
+ - set system ntp server server4 noselect
+ - set system ntp server 10.3.6.5 prefer
+ ignore_errors: true
+ vars:
+ ansible_connection: ansible.netcommon.network_cli
diff --git a/tests/integration/targets/vyos_ntp_global/tests/cli/_remove_config.yaml b/tests/integration/targets/vyos_ntp_global/tests/cli/_remove_config.yaml
new file mode 100644
index 0000000..6017bdb
--- /dev/null
+++ b/tests/integration/targets/vyos_ntp_global/tests/cli/_remove_config.yaml
@@ -0,0 +1,8 @@
+---
+- name: Remove pre-existing ntp_global config
+ vyos.vyos.vyos_ntp_global:
+ config:
+ state: deleted
+ ignore_errors: true
+ vars:
+ ansible_connection: ansible.netcommon.network_cli
diff --git a/tests/integration/targets/vyos_ntp_global/tests/cli/deleted.yaml b/tests/integration/targets/vyos_ntp_global/tests/cli/deleted.yaml
new file mode 100644
index 0000000..530e2ad
--- /dev/null
+++ b/tests/integration/targets/vyos_ntp_global/tests/cli/deleted.yaml
@@ -0,0 +1,40 @@
+---
+- debug:
+ msg: START vyos_ntp_global 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_ntp_global: &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 == populate.config
+
+ - name: Delete the existing configuration with the provided running configuration
+ (IDEMPOTENT)
+ register: result
+ vyos.vyos.vyos_ntp_global: *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_ntp_global/tests/cli/empty_config.yaml b/tests/integration/targets/vyos_ntp_global/tests/cli/empty_config.yaml
new file mode 100644
index 0000000..ec29f16
--- /dev/null
+++ b/tests/integration/targets/vyos_ntp_global/tests/cli/empty_config.yaml
@@ -0,0 +1,60 @@
+---
+- debug:
+ msg: START vyos_ntp_global 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_ntp_global:
+ 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_ntp_global:
+ 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_ntp_global:
+ 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_ntp_global:
+ 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_ntp_global:
+ 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_ntp_global/tests/cli/gathered.yaml b/tests/integration/targets/vyos_ntp_global/tests/cli/gathered.yaml
new file mode 100644
index 0000000..5ac350d
--- /dev/null
+++ b/tests/integration/targets/vyos_ntp_global/tests/cli/gathered.yaml
@@ -0,0 +1,24 @@
+---
+- debug:
+ msg: START vyos_ntp_global 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_ntp_global:
+ state: gathered
+
+ - vyos.vyos.vyos_facts:
+ gather_network_resources: ntp_global
+
+ - name: Assert that facts are correctly generated
+ assert:
+ that:
+ - result.changed == false
+ - result.gathered == ansible_facts['network_resources']['ntp_global']
diff --git a/tests/integration/targets/vyos_ntp_global/tests/cli/merged.yaml b/tests/integration/targets/vyos_ntp_global/tests/cli/merged.yaml
new file mode 100644
index 0000000..2a22ad8
--- /dev/null
+++ b/tests/integration/targets/vyos_ntp_global/tests/cli/merged.yaml
@@ -0,0 +1,58 @@
+---
+- debug:
+ msg: START vyos_ntp_global 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_ntp_global: &id001
+ config:
+ servers:
+ - server: server5
+
+ - server: server4
+ options:
+ - noselect
+ - dynamic
+
+ - server: 10.3.6.5
+ options:
+ - noselect
+ - preempt
+ - dynamic
+ - prefer
+ state: merged
+
+ - vyos.vyos.vyos_facts:
+ gather_network_resources: ntp_global
+
+ - assert:
+ that:
+ - result.commands|length == 7
+ - result.changed == true
+ - result.commands|symmetric_difference(merged.commands) == []
+ - result.after == ansible_facts['network_resources']['ntp_global']
+ - result.after == merged.after
+
+
+ - name: Assert that before dicts were correctly generated
+ assert:
+ that:
+ - result.before == populate.config
+
+ - name:
+ Merge the provided configuration with the existing running configuration
+ (IDEMPOTENT)
+ register: result
+ vyos.vyos.vyos_ntp_global: *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_ntp_global/tests/cli/overridden.yaml b/tests/integration/targets/vyos_ntp_global/tests/cli/overridden.yaml
new file mode 100644
index 0000000..2269e74
--- /dev/null
+++ b/tests/integration/targets/vyos_ntp_global/tests/cli/overridden.yaml
@@ -0,0 +1,53 @@
+---
+- debug:
+ msg: START vyos_ntp_global overridden integration tests on connection={{
+ ansible_connection }}
+
+- include_tasks: _remove_config.yaml
+
+- include_tasks: _populate_config.yaml
+
+- block:
+
+ - name: Override the existing configuration with the provided running configuration
+ register: result
+ vyos.vyos.vyos_ntp_global: &id001
+ config:
+ servers:
+ - server: server1
+ options:
+ - dynamic
+ - prefer
+
+ - server: server2
+ options:
+ - noselect
+ - preempt
+
+ - server: server_add
+ options:
+ - preempt
+ state: overridden
+
+ - vyos.vyos.vyos_facts:
+ gather_network_resources: ntp_global
+
+ - assert:
+ that:
+ - result.changed == true
+ - result.after == ansible_facts['network_resources']['ntp_global']
+ - result.after == overridden.after
+
+ - name: Override the existing configuration with the provided running configuration
+ (IDEMPOTENT)
+ register: result
+ vyos.vyos.vyos_ntp_global: *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_ntp_global/tests/cli/parsed.yaml b/tests/integration/targets/vyos_ntp_global/tests/cli/parsed.yaml
new file mode 100644
index 0000000..c660ac4
--- /dev/null
+++ b/tests/integration/targets/vyos_ntp_global/tests/cli/parsed.yaml
@@ -0,0 +1,17 @@
+---
+- debug:
+ msg: START vyos_ntp_global parsed integration tests on connection={{ ansible_connection
+ }}
+
+- name: Provide the running configuration for parsing (config to be parsed)
+ register: result
+ vyos.vyos.vyos_ntp_global:
+ running_config: "{{ lookup('file', '_parsed.cfg') }}"
+ state: parsed
+
+
+- name: Assert that config was correctly parsed
+ assert:
+ that:
+ - result.changed == false
+ - result.parsed == parsed.after
diff --git a/tests/integration/targets/vyos_ntp_global/tests/cli/rendered.yaml b/tests/integration/targets/vyos_ntp_global/tests/cli/rendered.yaml
new file mode 100644
index 0000000..1c1edd7
--- /dev/null
+++ b/tests/integration/targets/vyos_ntp_global/tests/cli/rendered.yaml
@@ -0,0 +1,33 @@
+---
+- debug:
+ msg: START vyos_ntp_global rendered integration tests on connection={{
+ ansible_connection }}
+
+- include_tasks: _remove_config.yaml
+
+- block:
+
+ - name: Structure provided configuration into device specific commands
+ register: result
+ vyos.vyos.vyos_ntp_global: &id001
+ config:
+ servers:
+ - server: server5
+
+ - server: server4
+ options:
+ - noselect
+ - dynamic
+
+ - server: 10.3.6.5
+ options:
+ - noselect
+ - preempt
+ - dynamic
+ - prefer
+ state: rendered
+
+ - assert:
+ that:
+ - result.changed == false
+ - result.rendered|symmetric_difference(merged.commands) == []
diff --git a/tests/integration/targets/vyos_ntp_global/tests/cli/replaced.yaml b/tests/integration/targets/vyos_ntp_global/tests/cli/replaced.yaml
new file mode 100644
index 0000000..8d1241b
--- /dev/null
+++ b/tests/integration/targets/vyos_ntp_global/tests/cli/replaced.yaml
@@ -0,0 +1,42 @@
+---
+- debug:
+ msg: START vyos_ntp_global 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_ntp_global: &id001
+ config:
+ servers:
+ - server: server_new
+ options:
+ - prefer
+ state: replaced
+
+ - vyos.vyos.vyos_facts:
+ gather_network_resources: ntp_global
+
+ - assert:
+ that:
+ - result.changed == true
+ - result.after == ansible_facts['network_resources']['ntp_global']
+ - result.after == replaced.after
+
+ - name:
+ Replace the provided configuration with the existing running configuration
+ (IDEMPOTENT)
+ register: result
+ vyos.vyos.vyos_ntp_global: *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_ntp_global/tests/cli/rtt.yaml b/tests/integration/targets/vyos_ntp_global/tests/cli/rtt.yaml
new file mode 100644
index 0000000..86f75f4
--- /dev/null
+++ b/tests/integration/targets/vyos_ntp_global/tests/cli/rtt.yaml
@@ -0,0 +1,70 @@
+---
+- debug:
+ msg: START vyos_ntp_global rtt integration tests on connection={{
+ ansible_connection }}
+
+- include_tasks: _remove_config.yaml
+
+- block:
+ - name: Merge the provided configuration with the existing running configuration
+ register: baseconfig
+ vyos.vyos.vyos_ntp_global:
+ config:
+ servers:
+ - server: 10.3.6.5
+ options:
+ - noselect
+ - dynamic
+ - preempt
+ - prefer
+
+ - server: server4
+ options:
+ - noselect
+ - dynamic
+
+ - server: 0.pool.ntp.org
+
+ - server: 1.pool.ntp.org
+
+ - server: 2.pool.ntp.org
+
+ state: merged
+
+ - vyos.vyos.vyos_facts:
+ gather_network_resources: ntp_global
+
+ - assert:
+ that:
+ - baseconfig.commands|length == 6
+ - baseconfig.changed == true
+ - baseconfig.commands|symmetric_difference(rtt.commands) == []
+ - baseconfig.after == ansible_facts['network_resources']['ntp_global']
+
+ - name: Merge the existing configuration with the provided running configuration
+ register: result
+ vyos.vyos.vyos_ntp_global:
+ config:
+ servers:
+ - server: server1
+ options:
+ - dynamic
+ - prefer
+
+ - server: server2
+ options:
+ - noselect
+ - preempt
+
+ - name: Revert back to base config using facts round trip
+ register: revert
+ vyos.vyos.vyos_ntp_global:
+ config: "{{ ansible_facts['network_resources']['ntp_global'] }}"
+ state: overridden
+
+ - name: Assert that config was reverted
+ assert:
+ that: baseconfig.after == revert.after
+
+ always:
+ - include_tasks: _remove_config.yaml
diff --git a/tests/integration/targets/vyos_ntp_global/vars/main.yaml b/tests/integration/targets/vyos_ntp_global/vars/main.yaml
new file mode 100644
index 0000000..3b4dbc4
--- /dev/null
+++ b/tests/integration/targets/vyos_ntp_global/vars/main.yaml
@@ -0,0 +1,108 @@
+---
+rtt:
+ commands:
+ - set system ntp server server4 dynamic
+ - set system ntp server 10.3.6.5 noselect
+ - set system ntp server 10.3.6.5 dynamic
+ - set system ntp server 10.3.6.5 preempt
+ - set system ntp server server4 noselect
+ - set system ntp server 10.3.6.5 prefer
+
+merged:
+ commands:
+ - set system ntp server server5
+ - set system ntp server server4 dynamic
+ - set system ntp server 10.3.6.5 noselect
+ - set system ntp server 10.3.6.5 dynamic
+ - set system ntp server 10.3.6.5 preempt
+ - set system ntp server server4 noselect
+ - set system ntp server 10.3.6.5 prefer
+
+ after:
+ servers:
+ - server: 0.pool.ntp.org
+ - server: 1.pool.ntp.org
+ - server: 10.3.6.5
+ options:
+ - dynamic
+ - noselect
+ - preempt
+ - prefer
+ - server: 2.pool.ntp.org
+
+ - server: server4
+ options:
+ - dynamic
+ - noselect
+
+ - server: server5
+
+replaced:
+ commands:
+ - delete system ntp server 10.3.6.5
+ - delete system ntp server server4
+ - delete system ntp server server5
+ - set system ntp server server_new prefer
+
+ after:
+ servers:
+ - server: 0.pool.ntp.org
+ - server: 1.pool.ntp.org
+ - server: 2.pool.ntp.org
+ - options:
+ - prefer
+ server: server_new
+
+overridden:
+ commands:
+ - delete system ntp server server_new
+ - set system ntp server server1 dynamic
+ - set system ntp server server1 prefer
+ - set system ntp server server2 noselect
+ - set system ntp server server2 preempt
+ - set system ntp server server_add preempt
+
+
+ after:
+ servers:
+ - server: 0.pool.ntp.org
+ - server: 1.pool.ntp.org
+ - server: 2.pool.ntp.org
+ - server: server1
+ options:
+ - dynamic
+ - prefer
+
+ - server: server2
+ options:
+ - noselect
+ - preempt
+ - server: server_add
+ options:
+ - preempt
+
+deleted:
+ commands:
+ - delete system ntp server 10.3.6.5
+ - delete system ntp server server4
+ - delete system ntp server server5
+
+parsed:
+ after:
+ servers:
+ - server: 0.pool.ntp.org
+
+ - server: 1.pool.ntp.org
+ - server: 10.3.6.5
+ options:
+ - dynamic
+ - noselect
+ - server: 2.pool.ntp.org
+
+populate:
+ config:
+ servers:
+ - server: 0.pool.ntp.org
+
+ - server: 1.pool.ntp.org
+ - server: 2.pool.ntp.org