summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
Diffstat (limited to 'tests')
-rw-r--r--tests/integration/targets/vyos_bgp_global/defaults/main.yaml3
-rw-r--r--tests/integration/targets/vyos_bgp_global/meta/main.yaml3
-rw-r--r--tests/integration/targets/vyos_bgp_global/tasks/cli.yaml19
-rw-r--r--tests/integration/targets/vyos_bgp_global/tasks/main.yaml4
-rw-r--r--tests/integration/targets/vyos_bgp_global/tests/cli/_parsed_config.cfg30
-rw-r--r--tests/integration/targets/vyos_bgp_global/tests/cli/_populate.yaml37
-rw-r--r--tests/integration/targets/vyos_bgp_global/tests/cli/_populate_af.yaml12
-rw-r--r--tests/integration/targets/vyos_bgp_global/tests/cli/_preconfig.yaml10
-rw-r--r--tests/integration/targets/vyos_bgp_global/tests/cli/_remove_config.yaml11
-rw-r--r--tests/integration/targets/vyos_bgp_global/tests/cli/deleted.yaml42
-rw-r--r--tests/integration/targets/vyos_bgp_global/tests/cli/deleted_af.yaml26
-rw-r--r--tests/integration/targets/vyos_bgp_global/tests/cli/empty_config.yaml49
-rw-r--r--tests/integration/targets/vyos_bgp_global/tests/cli/gathered.yaml24
-rw-r--r--tests/integration/targets/vyos_bgp_global/tests/cli/merged.yaml71
-rw-r--r--tests/integration/targets/vyos_bgp_global/tests/cli/parsed.yaml16
-rw-r--r--tests/integration/targets/vyos_bgp_global/tests/cli/purged.yaml32
-rw-r--r--tests/integration/targets/vyos_bgp_global/tests/cli/rendered.yaml45
-rw-r--r--tests/integration/targets/vyos_bgp_global/tests/cli/replaced.yaml72
-rw-r--r--tests/integration/targets/vyos_bgp_global/tests/cli/replaced_af.yaml56
-rw-r--r--tests/integration/targets/vyos_bgp_global/vars/main.yaml150
-rw-r--r--tests/unit/modules/network/vyos/fixtures/vyos_bgp_global_af_config.cfg5
-rw-r--r--tests/unit/modules/network/vyos/fixtures/vyos_bgp_global_config.cfg23
-rw-r--r--tests/unit/modules/network/vyos/test_vyos_bgp_global.py562
-rw-r--r--tests/unit/modules/network/vyos/vyos_module.py8
24 files changed, 1308 insertions, 2 deletions
diff --git a/tests/integration/targets/vyos_bgp_global/defaults/main.yaml b/tests/integration/targets/vyos_bgp_global/defaults/main.yaml
new file mode 100644
index 0000000..852a6be
--- /dev/null
+++ b/tests/integration/targets/vyos_bgp_global/defaults/main.yaml
@@ -0,0 +1,3 @@
+---
+testcase: '[^_].*'
+test_items: []
diff --git a/tests/integration/targets/vyos_bgp_global/meta/main.yaml b/tests/integration/targets/vyos_bgp_global/meta/main.yaml
new file mode 100644
index 0000000..7413320
--- /dev/null
+++ b/tests/integration/targets/vyos_bgp_global/meta/main.yaml
@@ -0,0 +1,3 @@
+---
+dependencies:
+ - prepare_vyos_tests
diff --git a/tests/integration/targets/vyos_bgp_global/tasks/cli.yaml b/tests/integration/targets/vyos_bgp_global/tasks/cli.yaml
new file mode 100644
index 0000000..93eb2fe
--- /dev/null
+++ b/tests/integration/targets/vyos_bgp_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_bgp_global/tasks/main.yaml b/tests/integration/targets/vyos_bgp_global/tasks/main.yaml
new file mode 100644
index 0000000..b957d2f
--- /dev/null
+++ b/tests/integration/targets/vyos_bgp_global/tasks/main.yaml
@@ -0,0 +1,4 @@
+---
+- include: cli.yaml
+ tags:
+ - network_cli
diff --git a/tests/integration/targets/vyos_bgp_global/tests/cli/_parsed_config.cfg b/tests/integration/targets/vyos_bgp_global/tests/cli/_parsed_config.cfg
new file mode 100644
index 0000000..2338b03
--- /dev/null
+++ b/tests/integration/targets/vyos_bgp_global/tests/cli/_parsed_config.cfg
@@ -0,0 +1,30 @@
+set policy access-list 20 description 'acl20'
+set policy access-list 40 description 'acl40'
+set policy route-map map01 description 'map01'
+set protocols bgp 65536 aggregate-address 192.0.2.0/24 'summary-only'
+set protocols bgp 65536 aggregate-address 203.0.113.0/24 'as-set'
+set protocols bgp 65536 maximum-paths ebgp '20'
+set protocols bgp 65536 maximum-paths ibgp '55'
+set protocols bgp 65536 neighbor 192.0.2.25 'disable-connected-check'
+set protocols bgp 65536 neighbor 192.0.2.25 timers holdtime '30'
+set protocols bgp 65536 neighbor 192.0.2.25 timers keepalive '10'
+set protocols bgp 65536 neighbor 203.0.113.5 attribute-unchanged 'as-path'
+set protocols bgp 65536 neighbor 203.0.113.5 attribute-unchanged 'med'
+set protocols bgp 65536 neighbor 203.0.113.5 attribute-unchanged 'next-hop'
+set protocols bgp 65536 neighbor 203.0.113.5 ebgp-multihop '2'
+set protocols bgp 65536 neighbor 203.0.113.5 remote-as '101'
+set protocols bgp 65536 neighbor 203.0.113.5 update-source '192.0.2.25'
+set protocols bgp 65536 neighbor 5001::64 distribute-list export '20'
+set protocols bgp 65536 neighbor 5001::64 distribute-list import '40'
+set protocols bgp 65536 neighbor 5001::64 maximum-prefix '34'
+set protocols bgp 65536 network 192.1.13.0/24 'backdoor'
+set protocols bgp 65536 parameters bestpath as-path 'confed'
+set protocols bgp 65536 parameters bestpath 'compare-routerid'
+set protocols bgp 65536 parameters confederation identifier '66'
+set protocols bgp 65536 parameters confederation peers '20'
+set protocols bgp 65536 parameters confederation peers '55'
+set protocols bgp 65536 parameters default 'no-ipv4-unicast'
+set protocols bgp 65536 parameters router-id '192.1.2.9'
+set protocols bgp 65536 redistribute connected route-map 'map01'
+set protocols bgp 65536 redistribute kernel metric '45'
+set protocols bgp 65536 timers keepalive '35'
diff --git a/tests/integration/targets/vyos_bgp_global/tests/cli/_populate.yaml b/tests/integration/targets/vyos_bgp_global/tests/cli/_populate.yaml
new file mode 100644
index 0000000..ec237d9
--- /dev/null
+++ b/tests/integration/targets/vyos_bgp_global/tests/cli/_populate.yaml
@@ -0,0 +1,37 @@
+---
+- name: setup
+ vyos.vyos.vyos_config:
+ lines:
+ - set policy access-list 20 description 'acl20'
+ - set policy access-list 40 description 'acl40'
+ - set policy route-map map01 description 'map01'
+ - set protocols bgp 65536 aggregate-address 192.0.2.0/24 'summary-only'
+ - set protocols bgp 65536 aggregate-address 203.0.113.0/24 'as-set'
+ - set protocols bgp 65536 maximum-paths ebgp '20'
+ - set protocols bgp 65536 maximum-paths ibgp '55'
+ - set protocols bgp 65536 neighbor 192.0.2.25 'disable-connected-check'
+ - set protocols bgp 65536 neighbor 192.0.2.25 timers holdtime '30'
+ - set protocols bgp 65536 neighbor 192.0.2.25 timers keepalive '10'
+ - set protocols bgp 65536 neighbor 203.0.113.5 attribute-unchanged 'as-path'
+ - set protocols bgp 65536 neighbor 203.0.113.5 attribute-unchanged 'med'
+ - set protocols bgp 65536 neighbor 203.0.113.5 attribute-unchanged 'next-hop'
+ - set protocols bgp 65536 neighbor 203.0.113.5 ebgp-multihop '2'
+ - set protocols bgp 65536 neighbor 203.0.113.5 remote-as '101'
+ - set protocols bgp 65536 neighbor 203.0.113.5 update-source '192.0.2.25'
+ - set protocols bgp 65536 neighbor 5001::64 distribute-list export '20'
+ - set protocols bgp 65536 neighbor 5001::64 distribute-list import '40'
+ - set protocols bgp 65536 neighbor 5001::64 maximum-prefix '34'
+ - set protocols bgp 65536 network 192.1.13.0/24 'backdoor'
+ - set protocols bgp 65536 parameters bestpath as-path 'confed'
+ - set protocols bgp 65536 parameters bestpath 'compare-routerid'
+ - set protocols bgp 65536 parameters confederation identifier '66'
+ - set protocols bgp 65536 parameters confederation peers '20'
+ - set protocols bgp 65536 parameters confederation peers '55'
+ - set protocols bgp 65536 parameters default 'no-ipv4-unicast'
+ - set protocols bgp 65536 parameters router-id '192.1.2.9'
+ - set protocols bgp 65536 redistribute connected route-map 'map01'
+ - set protocols bgp 65536 redistribute kernel metric '45'
+ - set protocols bgp 65536 timers keepalive '35'
+ ignore_errors: true
+ vars:
+ ansible_connection: ansible.netcommon.network_cli
diff --git a/tests/integration/targets/vyos_bgp_global/tests/cli/_populate_af.yaml b/tests/integration/targets/vyos_bgp_global/tests/cli/_populate_af.yaml
new file mode 100644
index 0000000..59f3d92
--- /dev/null
+++ b/tests/integration/targets/vyos_bgp_global/tests/cli/_populate_af.yaml
@@ -0,0 +1,12 @@
+---
+- name: setup
+ vyos.vyos.vyos_config:
+ lines:
+ - set protocols bgp 65536 neighbor 5001::64 address-family 'ipv6-unicast'
+ - set protocols bgp 65536 neighbor 5001::64 ebgp-multihop '2'
+ - set protocols bgp 65536 neighbor 5001::64 maximum-prefix '34'
+ - set protocols bgp 65536 neighbor 5001::64 remote-as '65535'
+ - set protocols bgp 65536 neighbor 5001::64 update-source '2001:db8::1'
+ ignore_errors: true
+ vars:
+ ansible_connection: ansible.netcommon.network_cli
diff --git a/tests/integration/targets/vyos_bgp_global/tests/cli/_preconfig.yaml b/tests/integration/targets/vyos_bgp_global/tests/cli/_preconfig.yaml
new file mode 100644
index 0000000..8ab69e0
--- /dev/null
+++ b/tests/integration/targets/vyos_bgp_global/tests/cli/_preconfig.yaml
@@ -0,0 +1,10 @@
+---
+- name: setup
+ vyos.vyos.vyos_config:
+ lines:
+ - set policy access-list 20 description 'acl20'
+ - set policy access-list 40 description 'acl40'
+ - set policy route-map map01 description 'map01'
+ ignore_errors: true
+ vars:
+ ansible_connection: ansible.netcommon.network_cli
diff --git a/tests/integration/targets/vyos_bgp_global/tests/cli/_remove_config.yaml b/tests/integration/targets/vyos_bgp_global/tests/cli/_remove_config.yaml
new file mode 100644
index 0000000..07d4aa4
--- /dev/null
+++ b/tests/integration/targets/vyos_bgp_global/tests/cli/_remove_config.yaml
@@ -0,0 +1,11 @@
+---
+- name: Remove pre-existing bgp processes
+ vyos.vyos.vyos_config:
+ lines:
+ - delete protocols bgp 65536
+ - delete policy access-list 20
+ - delete policy access-list 40
+ - delete policy route-map map01
+ ignore_errors: true
+ vars:
+ ansible_connection: ansible.netcommon.network_cli
diff --git a/tests/integration/targets/vyos_bgp_global/tests/cli/deleted.yaml b/tests/integration/targets/vyos_bgp_global/tests/cli/deleted.yaml
new file mode 100644
index 0000000..e1a7754
--- /dev/null
+++ b/tests/integration/targets/vyos_bgp_global/tests/cli/deleted.yaml
@@ -0,0 +1,42 @@
+---
+- debug:
+ msg: START vyos_bgp_global deleted integration tests on connection={{
+ ansible_connection }}
+
+- include_tasks: _remove_config.yaml
+
+- include_tasks: _populate.yaml
+
+- block:
+
+ - name: Delete the provided configuration
+ register: result
+ vyos.vyos.vyos_bgp_global: &id001
+ config:
+ as_number: "65536"
+ state: deleted
+
+ - become: true
+ vyos.vyos.vyos_facts:
+ gather_network_resources: bgp_global
+
+ - assert:
+ that:
+ - result.commands|length == 9
+ - result.changed == true
+ - result.commands|symmetric_difference(deleted.commands) == []
+ - result.after == ansible_facts['network_resources']['bgp_global']
+
+ - name: Delete the existing configuration with the provided running configuration
+ (IDEMPOTENT)
+ register: result
+ vyos.vyos.vyos_bgp_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_bgp_global/tests/cli/deleted_af.yaml b/tests/integration/targets/vyos_bgp_global/tests/cli/deleted_af.yaml
new file mode 100644
index 0000000..9792125
--- /dev/null
+++ b/tests/integration/targets/vyos_bgp_global/tests/cli/deleted_af.yaml
@@ -0,0 +1,26 @@
+---
+- debug:
+ msg: START vyos_bgp_global replaced integration tests on connection={{
+ ansible_connection }}
+
+- include_tasks: _remove_config.yaml
+
+- include_tasks: _populate_af.yaml
+
+- block:
+
+ - name: Delete the existing configuration, in presence of an af under neighbor.
+ register: result
+ ignore_errors: true
+ vyos.vyos.vyos_bgp_global: &id001
+ config:
+ as_number: "65536"
+ state: deleted
+
+ - assert:
+ that:
+ - result.msg == 'Use the _bgp_address_family module to delete the address_family under neighbor 5001::64, before replacing/deleting the neighbor.'
+
+ always:
+
+ - include_tasks: _remove_config.yaml
diff --git a/tests/integration/targets/vyos_bgp_global/tests/cli/empty_config.yaml b/tests/integration/targets/vyos_bgp_global/tests/cli/empty_config.yaml
new file mode 100644
index 0000000..7e52d1c
--- /dev/null
+++ b/tests/integration/targets/vyos_bgp_global/tests/cli/empty_config.yaml
@@ -0,0 +1,49 @@
+---
+- debug:
+ msg: START vyos_bgp_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_bgp_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_bgp_global:
+ config:
+ state: replaced
+
+- assert:
+ that:
+ - result.msg == 'value of config parameter must not be empty for state replaced'
+
+- name: Parsed with empty running_config should give appropriate error message
+ register: result
+ ignore_errors: true
+ vyos.vyos.vyos_bgp_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_bgp_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_bgp_global/tests/cli/gathered.yaml b/tests/integration/targets/vyos_bgp_global/tests/cli/gathered.yaml
new file mode 100644
index 0000000..7ec1da8
--- /dev/null
+++ b/tests/integration/targets/vyos_bgp_global/tests/cli/gathered.yaml
@@ -0,0 +1,24 @@
+---
+- debug:
+ msg: START vyos_bgp_global gathered integration tests on connection={{
+ ansible_connection }}
+
+- include_tasks: _remove_config.yaml
+
+- include_tasks: _populate.yaml
+
+- block:
+
+ - name: Gather config from the device in structured format.
+ register: result
+ vyos.vyos.vyos_bgp_global:
+ state: gathered
+
+ - become: true
+ vyos.vyos.vyos_facts:
+ gather_network_resources: bgp_global
+
+ - assert:
+ that:
+ - result.changed == false
+ - result.gathered == ansible_facts['network_resources']['bgp_global']
diff --git a/tests/integration/targets/vyos_bgp_global/tests/cli/merged.yaml b/tests/integration/targets/vyos_bgp_global/tests/cli/merged.yaml
new file mode 100644
index 0000000..8a09c01
--- /dev/null
+++ b/tests/integration/targets/vyos_bgp_global/tests/cli/merged.yaml
@@ -0,0 +1,71 @@
+---
+- debug:
+ msg: START vyos_bgp_global merged integration tests on connection={{
+ ansible_connection }}
+
+- include_tasks: _remove_config.yaml
+
+- include_tasks: _preconfig.yaml
+
+- block:
+
+ - name: Merge the provided configuration with the exisiting running configuration
+ register: result
+ vyos.vyos.vyos_bgp_global: &id001
+ config:
+ as_number: "65536"
+ aggregate_address:
+ - prefix: "203.0.113.0/24"
+ as_set: true
+ - prefix: "192.0.2.0/24"
+ summary_only: true
+ network:
+ - address: "192.1.13.0/24"
+ backdoor: true
+ redistribute:
+ - protocol: "kernel"
+ metric: 45
+ - protocol: "connected"
+ route_map: "map01"
+ maximum_paths:
+ - path: "ebgp"
+ count: 20
+ - path: "ibgp"
+ count: 55
+ timers:
+ keepalive: 35
+ bgp_params:
+ bestpath:
+ as_path: "confed"
+ compare_routerid: true
+ default:
+ no_ipv4_unicast: true
+ router_id: "192.1.2.9"
+ state: merged
+
+ - become: true
+ vyos.vyos.vyos_facts:
+ gather_network_resources: bgp_global
+
+ - assert:
+ that:
+ - result.commands|length == 12
+ - result.changed == true
+ - result.commands|symmetric_difference(merged.commands) == []
+ - result.after == ansible_facts['network_resources']['bgp_global']
+ - result.before == {}
+ - result.after == merged.after
+
+ - name: Merge the provided configuration with the existing running configuration
+ (IDEMPOTENT)
+ register: result
+ vyos.vyos.vyos_bgp_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_bgp_global/tests/cli/parsed.yaml b/tests/integration/targets/vyos_bgp_global/tests/cli/parsed.yaml
new file mode 100644
index 0000000..419df6a
--- /dev/null
+++ b/tests/integration/targets/vyos_bgp_global/tests/cli/parsed.yaml
@@ -0,0 +1,16 @@
+---
+- debug:
+ msg: START vyos_bgp_global parsed integration tests on connection={{ ansible_connection
+ }}
+
+- name: Provide the running configuration for parsing (config to be parsed)
+ become: true
+ register: result
+ vyos.vyos.vyos_bgp_global:
+ running_config: "{{ lookup('file', '_parsed_config.cfg') }}"
+ state: parsed
+
+- assert:
+ that:
+ - result.changed == false
+ - result.parsed == populate.global
diff --git a/tests/integration/targets/vyos_bgp_global/tests/cli/purged.yaml b/tests/integration/targets/vyos_bgp_global/tests/cli/purged.yaml
new file mode 100644
index 0000000..9588e80
--- /dev/null
+++ b/tests/integration/targets/vyos_bgp_global/tests/cli/purged.yaml
@@ -0,0 +1,32 @@
+---
+- debug:
+ msg: START vyos_bgp_global purged integration tests on connection={{
+ ansible_connection }}
+
+- include_tasks: _remove_config.yaml
+
+- include_tasks: _populate.yaml
+
+- block:
+
+ - name: Purge the provided configuration
+ register: result
+ vyos.vyos.vyos_bgp_global: &id001
+ config:
+ as_number: "65536"
+ state: purged
+
+ - become: true
+ vyos.vyos.vyos_facts:
+ gather_network_resources: bgp_global
+
+ - assert:
+ that:
+ - result.commands|length == 1
+ - result.changed == true
+ - "'delete protocols bgp 65536' in result.commands"
+ - ansible_facts.network_resources.bgp_global == []
+
+ always:
+
+ - include_tasks: _remove_config.yaml
diff --git a/tests/integration/targets/vyos_bgp_global/tests/cli/rendered.yaml b/tests/integration/targets/vyos_bgp_global/tests/cli/rendered.yaml
new file mode 100644
index 0000000..3a44a5e
--- /dev/null
+++ b/tests/integration/targets/vyos_bgp_global/tests/cli/rendered.yaml
@@ -0,0 +1,45 @@
+---
+- debug:
+ msg: START vyos_bgp_global merged integration tests on connection={{
+ ansible_connection }}
+
+- block:
+
+ - name: Render given bgp_global configuration
+ register: result
+ vyos.vyos.vyos_bgp_global: &id001
+ config:
+ as_number: "65536"
+ aggregate_address:
+ - prefix: "203.0.113.0/24"
+ as_set: true
+ - prefix: "192.0.2.0/24"
+ summary_only: true
+ network:
+ - address: "192.1.13.0/24"
+ backdoor: true
+ redistribute:
+ - protocol: "kernel"
+ metric: 45
+ - protocol: "connected"
+ route_map: "map01"
+ maximum_paths:
+ - path: "ebgp"
+ count: 20
+ - path: "ibgp"
+ count: 55
+ timers:
+ keepalive: 35
+ bgp_params:
+ bestpath:
+ as_path: "confed"
+ compare_routerid: true
+ default:
+ no_ipv4_unicast: true
+ router_id: "192.1.2.9"
+ state: rendered
+
+ - assert:
+ that:
+ - result.changed == false
+ - result.rendered|symmetric_difference(merged.commands) == []
diff --git a/tests/integration/targets/vyos_bgp_global/tests/cli/replaced.yaml b/tests/integration/targets/vyos_bgp_global/tests/cli/replaced.yaml
new file mode 100644
index 0000000..2a8b407
--- /dev/null
+++ b/tests/integration/targets/vyos_bgp_global/tests/cli/replaced.yaml
@@ -0,0 +1,72 @@
+---
+- debug:
+ msg: START vyos_bgp_global replaced integration tests on connection={{
+ ansible_connection }}
+
+- include_tasks: _remove_config.yaml
+
+- include_tasks: _populate.yaml
+
+- block:
+
+ - name: Replace the existing configuration with the provided running configuration
+ register: result
+ vyos.vyos.vyos_bgp_global: &id001
+ config:
+ as_number: "65536"
+ network:
+ - address: "203.0.113.0/24"
+ route_map: map01
+ redistribute:
+ - protocol: "static"
+ route_map: "map01"
+ bgp_params:
+ always_compare_med: true
+ dampening:
+ start_suppress_time: 5
+ max_suppress_time: 20
+ half_life: 33
+ re_use: 60
+ bestpath:
+ as_path: "confed"
+ compare_routerid: true
+ default:
+ no_ipv4_unicast: true
+ neighbor:
+ - address: "192.0.2.43"
+ disable_connected_check: true
+ advertisement_interval: 72
+ capability:
+ dynamic: true
+ timers:
+ holdtime: 30
+ keepalive: 10
+ - address: "203.0.113.0"
+ capability:
+ orf: "receive"
+ state: replaced
+
+ - become: true
+ vyos.vyos.vyos_facts:
+ gather_network_resources: bgp_global
+
+ - assert:
+ that:
+ - result.commands|length == 24
+ - result.changed == true
+ - result.commands|symmetric_difference(replaced.commands) == []
+ - result.after == ansible_facts['network_resources']['bgp_global']
+
+ - name: Replace the existing configuration with the provided running configuration
+ (IDEMPOTENT)
+ register: result
+ vyos.vyos.vyos_bgp_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_bgp_global/tests/cli/replaced_af.yaml b/tests/integration/targets/vyos_bgp_global/tests/cli/replaced_af.yaml
new file mode 100644
index 0000000..abcb177
--- /dev/null
+++ b/tests/integration/targets/vyos_bgp_global/tests/cli/replaced_af.yaml
@@ -0,0 +1,56 @@
+---
+- debug:
+ msg: START vyos_bgp_global replaced integration tests on connection={{
+ ansible_connection }}
+
+- include_tasks: _remove_config.yaml
+
+- include_tasks: _populate_af.yaml
+
+- block:
+
+ - name: Replace the existing af configuration with the provided running configuration
+ register: result
+ ignore_errors: true
+ vyos.vyos.vyos_bgp_global: &id001
+ config:
+ as_number: "65536"
+ network:
+ - address: "203.0.113.0/24"
+ route_map: map01
+ redistribute:
+ - protocol: "static"
+ route_map: "map01"
+ bgp_params:
+ always_compare_med: true
+ dampening:
+ start_suppress_time: 5
+ max_suppress_time: 20
+ half_life: 33
+ re_use: 60
+ bestpath:
+ as_path: "confed"
+ compare_routerid: true
+ default:
+ no_ipv4_unicast: true
+ neighbor:
+ - address: "192.0.2.43"
+ disable_connected_check: true
+ advertisement_interval: 72
+ capability:
+ dynamic: true
+ timers:
+ holdtime: 30
+ keepalive: 10
+ - address: "203.0.113.0"
+ capability:
+ orf: "receive"
+ state: replaced
+
+ - assert:
+ that:
+ - result.msg == 'Use the _bgp_address_family module to delete the address_family under neighbor 5001::64, before replacing/deleting the neighbor.'
+
+ always:
+
+ - include_tasks: _remove_config.yaml
diff --git a/tests/integration/targets/vyos_bgp_global/vars/main.yaml b/tests/integration/targets/vyos_bgp_global/vars/main.yaml
new file mode 100644
index 0000000..fec5e43
--- /dev/null
+++ b/tests/integration/targets/vyos_bgp_global/vars/main.yaml
@@ -0,0 +1,150 @@
+---
+merged:
+ commands:
+ - set protocols bgp 65536 redistribute kernel metric 45
+ - set protocols bgp 65536 redistribute connected route-map map01
+ - set protocols bgp 65536 network 192.1.13.0/24 backdoor
+ - set protocols bgp 65536 aggregate-address 203.0.113.0/24 as-set
+ - set protocols bgp 65536 aggregate-address 192.0.2.0/24 summary-only
+ - set protocols bgp 65536 parameters bestpath as-path confed
+ - set protocols bgp 65536 parameters bestpath compare-routerid
+ - set protocols bgp 65536 parameters default no-ipv4-unicast
+ - set protocols bgp 65536 parameters router-id 192.1.2.9
+ - set protocols bgp 65536 maximum-paths ebgp 20
+ - set protocols bgp 65536 maximum-paths ibgp 55
+ - set protocols bgp 65536 timers keepalive 35
+ after:
+ aggregate_address:
+ - prefix: "192.0.2.0/24"
+ summary_only: true
+ - prefix: "203.0.113.0/24"
+ as_set: true
+ as_number: 65536
+ bgp_params:
+ bestpath:
+ as_path: "confed"
+ compare_routerid: true
+ default:
+ no_ipv4_unicast: true
+ router_id: "192.1.2.9"
+ maximum_paths:
+ - count: 20
+ path: "ebgp"
+ - count: 55
+ path: "ibgp"
+ network:
+ - address: "192.1.13.0/24"
+ backdoor: true
+ redistribute:
+ - protocol: "connected"
+ route_map: "map01"
+ - metric: 45
+ protocol: "kernel"
+ timers:
+ keepalive: 35
+
+replaced:
+ commands:
+ - delete protocols bgp 65536 timers
+ - delete protocols bgp 65536 maximum-paths
+ - delete protocols bgp 65536 parameters router-id 192.1.2.9
+ - delete protocols bgp 65536 parameters confederation
+ - delete protocols bgp 65536 aggregate-address
+ - delete protocols bgp 65536 network 192.1.13.0/24
+ - delete protocols bgp 65536 redistribute kernel
+ - delete protocols bgp 65536 redistribute connected
+ - delete protocols bgp 65536 neighbor 5001::64
+ - delete protocols bgp 65536 neighbor 203.0.113.5
+ - delete protocols bgp 65536 neighbor 192.0.2.25
+ - set protocols bgp 65536 neighbor 192.0.2.43 disable-connected-check
+ - set protocols bgp 65536 neighbor 192.0.2.43 advertisement-interval 72
+ - set protocols bgp 65536 neighbor 192.0.2.43 capability dynamic
+ - set protocols bgp 65536 neighbor 192.0.2.43 timers holdtime 30
+ - set protocols bgp 65536 neighbor 192.0.2.43 timers keepalive 10
+ - set protocols bgp 65536 neighbor 203.0.113.0 capability orf prefix-list receive
+ - set protocols bgp 65536 redistribute static route-map map01
+ - set protocols bgp 65536 network 203.0.113.0/24 route-map map01
+ - set protocols bgp 65536 parameters always-compare-med
+ - set protocols bgp 65536 parameters dampening half-life 33
+ - set protocols bgp 65536 parameters dampening max-suppress-time 20
+ - set protocols bgp 65536 parameters dampening re-use 60
+ - set protocols bgp 65536 parameters dampening start-suppress-time 5
+
+deleted:
+ commands:
+ - delete protocols bgp 65536 timers
+ - delete protocols bgp 65536 maximum-paths
+ - delete protocols bgp 65536 parameters
+ - delete protocols bgp 65536 aggregate-address
+ - delete protocols bgp 65536 network
+ - delete protocols bgp 65536 redistribute
+ - delete protocols bgp 65536 neighbor 5001::64
+ - delete protocols bgp 65536 neighbor 203.0.113.5
+ - delete protocols bgp 65536 neighbor 192.0.2.25
+
+rendered:
+ commands:
+ - set interfaces ethernet eth1 firewall in name 'INBOUND'
+ - set interfaces ethernet eth1 firewall out name 'OUTBOUND'
+ - set interfaces ethernet eth1 firewall local name 'LOCAL'
+ - set interfaces ethernet eth1 firewall local ipv6-name 'V6-LOCAL'
+ - set interfaces ethernet eth2 firewall in name 'INBOUND'
+ - set interfaces ethernet eth2 firewall out name 'OUTBOUND'
+ - set interfaces ethernet eth2 firewall local name 'LOCAL'
+ - set interfaces ethernet eth2 firewall local ipv6-name 'V6-LOCAL'
+
+populate:
+ global:
+ aggregate_address:
+ - prefix: "192.0.2.0/24"
+ summary_only: true
+ - prefix: "203.0.113.0/24"
+ as_set: true
+ as_number: 65536
+ bgp_params:
+ bestpath:
+ as_path: "confed"
+ compare_routerid: true
+ confederation:
+ - identifier: 66
+ - peers: 20
+ - peers: 55
+ default:
+ no_ipv4_unicast: true
+ router_id: "192.1.2.9"
+ maximum_paths:
+ - count: 20
+ path: "ebgp"
+ - count: 55
+ path: "ibgp"
+ neighbor:
+ - address: "192.0.2.25"
+ disable_connected_check: true
+ timers:
+ holdtime: 30
+ keepalive: 10
+ - address: "203.0.113.5"
+ attribute_unchanged:
+ as_path: true
+ med: true
+ next_hop: true
+ ebgp_multihop: 2
+ remote_as: 101
+ update_source: "192.0.2.25"
+ - address: "5001::64"
+ distribute_list:
+ - acl: 20
+ action: "export"
+ - acl: 40
+ action: "import"
+ maximum_prefix: 34
+ network:
+ - address: "192.1.13.0/24"
+ backdoor: true
+ redistribute:
+ - protocol: "connected"
+ route_map: "map01"
+ - metric: 45
+ protocol: "kernel"
+ timers:
+ keepalive: 35
diff --git a/tests/unit/modules/network/vyos/fixtures/vyos_bgp_global_af_config.cfg b/tests/unit/modules/network/vyos/fixtures/vyos_bgp_global_af_config.cfg
new file mode 100644
index 0000000..7d990d6
--- /dev/null
+++ b/tests/unit/modules/network/vyos/fixtures/vyos_bgp_global_af_config.cfg
@@ -0,0 +1,5 @@
+set protocols bgp 65536 neighbor 5001::64 address-family 'ipv6-unicast'
+set protocols bgp 65536 neighbor 5001::64 ebgp-multihop '2'
+set protocols bgp 65536 neighbor 5001::64 maximum-prefix '34'
+set protocols bgp 65536 neighbor 5001::64 remote-as '65535'
+set protocols bgp 65536 neighbor 5001::64 update-source '2001:db8::1'
diff --git a/tests/unit/modules/network/vyos/fixtures/vyos_bgp_global_config.cfg b/tests/unit/modules/network/vyos/fixtures/vyos_bgp_global_config.cfg
new file mode 100644
index 0000000..00c615f
--- /dev/null
+++ b/tests/unit/modules/network/vyos/fixtures/vyos_bgp_global_config.cfg
@@ -0,0 +1,23 @@
+set protocols bgp 65536 neighbor 10.0.0.4 'disable-connected-check'
+set protocols bgp 65536 neighbor 10.0.0.4 timers holdtime '30'
+set protocols bgp 65536 neighbor 10.0.0.4 timers keepalive '10'
+set protocols bgp 65536 neighbor 192.168.0.2 attribute-unchanged 'as-path'
+set protocols bgp 65536 neighbor 192.168.0.2 attribute-unchanged 'med'
+set protocols bgp 65536 neighbor 192.168.0.2 ebgp-multihop '2'
+set protocols bgp 65536 neighbor 192.168.0.2 remote-as '65535'
+set protocols bgp 65536 neighbor 192.168.0.2 soft-reconfiguration 'inbound'
+set protocols bgp 65536 neighbor 192.168.0.2 update-source '192.168.0.1'
+set protocols bgp 65536 neighbor 2001:db8::2 ebgp-multihop '2'
+set protocols bgp 65536 neighbor 2001:db8::2 maximum-prefix '34'
+set protocols bgp 65536 neighbor 2001:db8::2 remote-as '65535'
+set protocols bgp 65536 neighbor 2001:db8::2 update-source '2001:db8::1'
+set protocols bgp 65536 network 172.16.42.32/27 'backdoor'
+set protocols bgp 65536 network 172.16.42.251/32 route-map 'map01'
+set protocols bgp 65536 parameters bestpath as-path 'confed'
+set protocols bgp 65536 parameters bestpath 'compare-routerid'
+set protocols bgp 65536 parameters default 'no-ipv4-unicast'
+set protocols bgp 65536 parameters router-id '10.1.1.1'
+set protocols bgp 65536 neighbor 10.0.0.4 capability orf prefix-list 'receive'
+set protocols bgp 65536 redistribute kernel route-map 'map01'
+set protocols bgp 65536 redistribute static metric '20'
+set protocols bgp 65536 redistribute static route-map 'map01'
diff --git a/tests/unit/modules/network/vyos/test_vyos_bgp_global.py b/tests/unit/modules/network/vyos/test_vyos_bgp_global.py
new file mode 100644
index 0000000..bdb29c0
--- /dev/null
+++ b/tests/unit/modules/network/vyos/test_vyos_bgp_global.py
@@ -0,0 +1,562 @@
+# (c) 2016 Red Hat Inc.
+#
+# This file is part of Ansible
+#
+# Ansible is free software: you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+#
+# Ansible is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with Ansible. If not, see <http://www.gnu.org/licenses/>.
+
+# Make coding more python3-ish
+from __future__ import absolute_import, division, print_function
+
+__metaclass__ = type
+
+from ansible_collections.vyos.vyos.tests.unit.compat.mock import patch
+from ansible_collections.vyos.vyos.plugins.modules import vyos_bgp_global
+from ansible_collections.vyos.vyos.tests.unit.modules.utils import (
+ set_module_args,
+)
+from .vyos_module import TestVyosModule, load_fixture
+
+
+class TestVyosBgpglobalModule(TestVyosModule):
+
+ module = vyos_bgp_global
+
+ def setUp(self):
+ super(TestVyosBgpglobalModule, self).setUp()
+
+ self.mock_get_resource_connection_config = patch(
+ "ansible_collections.ansible.netcommon.plugins.module_utils.network.common.rm_base.resource_module_base.get_resource_connection"
+ )
+ self.get_resource_connection_config = (
+ self.mock_get_resource_connection_config.start()
+ )
+
+ self.mock_execute_show_command_config = patch(
+ "ansible_collections.vyos.vyos.plugins.module_utils.network.vyos.config.bgp_global.bgp_global.Bgp_global._get_config"
+ )
+ self.execute_show_command_config = (
+ self.mock_execute_show_command_config.start()
+ )
+
+ self.mock_get_resource_connection_facts = patch(
+ "ansible_collections.ansible.netcommon.plugins.module_utils.network.common.facts.facts.get_resource_connection"
+ )
+ self.get_resource_connection_facts = (
+ self.mock_get_resource_connection_facts.start()
+ )
+
+ self.mock_execute_show_command = patch(
+ "ansible_collections.vyos.vyos.plugins.module_utils.network.vyos.facts.bgp_global.bgp_global.Bgp_globalFacts.get_device_data"
+ )
+
+ self.execute_show_command = self.mock_execute_show_command.start()
+
+ def tearDown(self):
+ super(TestVyosBgpglobalModule, self).tearDown()
+ self.mock_get_resource_connection_config.stop()
+ self.mock_get_resource_connection_facts.stop()
+ self.mock_execute_show_command.stop()
+ self.mock_execute_show_command_config.stop()
+
+ def load_fixtures(self, commands=None, transport="cli", filename=None):
+ if filename is None:
+ filename = "vyos_bgp_global_config.cfg"
+
+ def load_from_file(*args, **kwargs):
+ output = load_fixture(filename)
+ return output
+
+ self.execute_show_command.side_effect = load_from_file
+ self.execute_show_command_config.side_effect = load_from_file
+
+ def test_vyos_bgp_global_merged_idempotent(self):
+ set_module_args(
+ dict(
+ config=dict(
+ as_number="65536",
+ neighbor=[
+ dict(
+ address="10.0.0.4",
+ disable_connected_check=True,
+ timers=dict(holdtime=30, keepalive=10),
+ capability=dict(orf="receive"),
+ ),
+ dict(
+ address="192.168.0.2",
+ attribute_unchanged=dict(as_path=True, med=True),
+ ebgp_multihop=2,
+ remote_as="65535",
+ soft_reconfiguration=True,
+ update_source="192.168.0.1",
+ ),
+ dict(
+ address="2001:db8::2",
+ ebgp_multihop=2,
+ remote_as="65535",
+ maximum_prefix=34,
+ update_source="2001:db8::1",
+ ),
+ ],
+ network=[
+ dict(address="172.16.42.32/27", backdoor=True),
+ dict(address="172.16.42.251/32", route_map="map01"),
+ ],
+ bgp_params=dict(
+ bestpath=dict(as_path="confed", compare_routerid=True),
+ default=dict(no_ipv4_unicast=True),
+ router_id="10.1.1.1",
+ ),
+ redistribute=[
+ dict(protocol="kernel", route_map="map01"),
+ dict(protocol="static", metric=20),
+ dict(protocol="static", route_map="map01"),
+ ],
+ ),
+ state="merged",
+ )
+ )
+ self.execute_module(changed=False, commands=[])
+
+ def test_vyos_bgp_global_merged(self):
+ set_module_args(
+ dict(
+ config=dict(
+ as_number="65536",
+ maximum_paths=[
+ dict(path="ebgp", count=20),
+ dict(path="ibgp", count=45),
+ ],
+ neighbor=[
+ dict(
+ address="2001:db8::2",
+ ebgp_multihop=2,
+ remote_as="65535",
+ maximum_prefix=34,
+ update_source="2001:db8::1",
+ distribute_list=[
+ dict(action="export", acl=31),
+ dict(action="import", acl=9),
+ ],
+ )
+ ],
+ bgp_params=dict(
+ confederation=[dict(peers=20), dict(identifier=66)],
+ router_id="10.1.1.1",
+ ),
+ ),
+ state="merged",
+ )
+ )
+ commands = [
+ "set protocols bgp 65536 neighbor 2001:db8::2 distribute-list export 31",
+ "set protocols bgp 65536 neighbor 2001:db8::2 distribute-list import 9",
+ "set protocols bgp 65536 parameters confederation peers 20",
+ "set protocols bgp 65536 parameters confederation identifier 66",
+ "set protocols bgp 65536 maximum-paths ebgp 20",
+ "set protocols bgp 65536 maximum-paths ibgp 45",
+ ]
+ self.execute_module(changed=True, commands=commands)
+
+ def test_vyos_bgp_global_replaced_idempotent(self):
+ set_module_args(
+ dict(
+ config=dict(
+ as_number="65536",
+ neighbor=[
+ dict(
+ address="10.0.0.4",
+ disable_connected_check=True,
+ timers=dict(holdtime=30, keepalive=10),
+ capability=dict(orf="receive"),
+ ),
+ dict(
+ address="192.168.0.2",
+ attribute_unchanged=dict(as_path=True, med=True),
+ ebgp_multihop=2,
+ remote_as="65535",
+ soft_reconfiguration=True,
+ update_source="192.168.0.1",
+ ),
+ dict(
+ address="2001:db8::2",
+ ebgp_multihop=2,
+ remote_as="65535",
+ maximum_prefix=34,
+ update_source="2001:db8::1",
+ ),
+ ],
+ network=[
+ dict(address="172.16.42.32/27", backdoor=True),
+ dict(address="172.16.42.251/32", route_map="map01"),
+ ],
+ bgp_params=dict(
+ bestpath=dict(as_path="confed", compare_routerid=True),
+ default=dict(no_ipv4_unicast=True),
+ router_id="10.1.1.1",
+ ),
+ redistribute=[
+ dict(protocol="kernel", route_map="map01"),
+ dict(protocol="static", metric=20),
+ dict(protocol="static", route_map="map01"),
+ ],
+ ),
+ state="replaced",
+ )
+ )
+ self.execute_module(changed=False, commands=[])
+
+ #
+ def test_vyos_bgp_global_replaced(self):
+ set_module_args(
+ dict(
+ config=dict(
+ as_number="65536",
+ timers=dict(holdtime=30, keepalive=10),
+ neighbor=[
+ dict(
+ address="200.11.155.3",
+ prefix_list=[
+ dict(action="export", prefix_list=10),
+ ],
+ allowas_in=10,
+ ),
+ dict(
+ address="2001:db8::2",
+ remote_as="65535",
+ as_override=True,
+ default_originate="map01",
+ route_map=[
+ dict(action="export", route_map="map01"),
+ ],
+ ),
+ ],
+ bgp_params=dict(
+ log_neighbor_changes=True,
+ no_client_to_client_reflection=True,
+ confederation=[dict(peers=20), dict(identifier=66)],
+ router_id="10.1.1.1",
+ ),
+ ),
+ state="replaced",
+ )
+ )
+ commands = [
+ "delete protocols bgp 65536 parameters default",
+ "delete protocols bgp 65536 parameters bestpath compare-routerid",
+ "delete protocols bgp 65536 parameters bestpath as-path confed",
+ "delete protocols bgp 65536 network",
+ "delete protocols bgp 65536 redistribute",
+ "delete protocols bgp 65536 neighbor 2001:db8::2 update-source 2001:db8::1",
+ "delete protocols bgp 65536 neighbor 2001:db8::2 maximum-prefix 34",
+ "delete protocols bgp 65536 neighbor 2001:db8::2 ebgp-multihop 2",
+ "delete protocols bgp 65536 neighbor 192.168.0.2",
+ "delete protocols bgp 65536 neighbor 10.0.0.4",
+ "set protocols bgp 65536 neighbor 200.11.155.3 prefix-list export 10",
+ "set protocols bgp 65536 neighbor 200.11.155.3 allowas-in number 10",
+ "set protocols bgp 65536 neighbor 2001:db8::2 as-override",
+ "set protocols bgp 65536 neighbor 2001:db8::2 route-map export map01",
+ "set protocols bgp 65536 parameters log-neighbor-changes",
+ "set protocols bgp 65536 parameters no-client-to-client-reflection",
+ "set protocols bgp 65536 parameters confederation peers 20",
+ "set protocols bgp 65536 parameters confederation identifier 66",
+ "set protocols bgp 65536 timers holdtime 30",
+ "set protocols bgp 65536 timers keepalive 10",
+ ]
+ self.execute_module(changed=True, commands=commands)
+
+ #
+ def test_vyos_bgp_global_purged(self):
+ set_module_args(dict(config=dict(as_number="65536"), state="purged"))
+ #
+ commands = ["delete protocols bgp 65536"]
+ self.execute_module(changed=True, commands=commands)
+
+ #
+ def test_vyos_bgp_global_incorrect_instance(self):
+ set_module_args(
+ dict(
+ config=dict(
+ as_number="100",
+ timers=dict(holdtime=30, keepalive=10),
+ neighbor=[
+ dict(
+ address="200.11.155.3",
+ prefix_list=[
+ dict(action="export", prefix_list=10),
+ ],
+ allowas_in=10,
+ ),
+ dict(
+ address="2001:db8::2",
+ remote_as="65535",
+ as_override=True,
+ default_originate="map01",
+ route_map=[
+ dict(action="export", route_map="map01"),
+ ],
+ ),
+ ],
+ bgp_params=dict(
+ log_neighbor_changes=True,
+ no_client_to_client_reflection=True,
+ confederation=[dict(peers=20), dict(identifier=66)],
+ router_id="10.1.1.1",
+ ),
+ ),
+ state="replaced",
+ )
+ )
+ result = self.execute_module(failed=True)
+ self.assertIn(
+ "Only one bgp instance is allowed per device", result["msg"]
+ )
+
+ def test_vyos_bgp_global_replaced_af(self):
+ set_module_args(
+ dict(
+ config=dict(
+ as_number="65536",
+ timers=dict(holdtime=30, keepalive=10),
+ neighbor=[
+ dict(
+ address="200.11.155.3",
+ prefix_list=[
+ dict(action="export", prefix_list=10),
+ ],
+ allowas_in=10,
+ ),
+ dict(
+ address="2001:db8::2",
+ remote_as="65535",
+ as_override=True,
+ default_originate="map01",
+ route_map=[
+ dict(action="export", route_map="map01"),
+ ],
+ ),
+ ],
+ bgp_params=dict(
+ log_neighbor_changes=True,
+ no_client_to_client_reflection=True,
+ confederation=[dict(peers=20), dict(identifier=66)],
+ router_id="10.1.1.1",
+ ),
+ ),
+ state="replaced",
+ )
+ )
+ result = self.execute_module(
+ failed=True, filename="vyos_bgp_global_af_config.cfg"
+ )
+ self.assertIn(
+ "Use the _bgp_address_family module to delete the address_family under neighbor 5001::64, before replacing/deleting the neighbor.",
+ result["msg"],
+ )
+
+ def test_vyos_bgp_global_rendered(self):
+ set_module_args(
+ dict(
+ config=dict(
+ as_number="65536",
+ neighbor=[
+ dict(
+ address="10.0.0.4",
+ disable_connected_check=True,
+ timers=dict(holdtime=30, keepalive=10),
+ capability=dict(orf="receive"),
+ ),
+ dict(
+ address="192.168.0.2",
+ attribute_unchanged=dict(as_path=True, med=True),
+ ebgp_multihop=2,
+ remote_as="65535",
+ soft_reconfiguration=True,
+ update_source="192.168.0.1",
+ ),
+ dict(
+ address="2001:db8::2",
+ ebgp_multihop=2,
+ remote_as="65535",
+ maximum_prefix=34,
+ update_source="2001:db8::1",
+ ),
+ ],
+ network=[
+ dict(address="172.16.42.32/27", backdoor=True),
+ dict(address="172.16.42.251/32", route_map="map01"),
+ ],
+ bgp_params=dict(
+ bestpath=dict(as_path="confed", compare_routerid=True),
+ default=dict(no_ipv4_unicast=True),
+ router_id="10.1.1.1",
+ ),
+ redistribute=[
+ dict(protocol="kernel", route_map="map01"),
+ dict(protocol="static", metric=20),
+ dict(protocol="static", route_map="map01"),
+ ],
+ ),
+ state="rendered",
+ )
+ )
+ rendered_cmds = [
+ "set protocols bgp 65536 neighbor 10.0.0.4 disable-connected-check",
+ "set protocols bgp 65536 neighbor 10.0.0.4 timers holdtime 30",
+ "set protocols bgp 65536 neighbor 10.0.0.4 timers keepalive 10",
+ "set protocols bgp 65536 neighbor 10.0.0.4 capability orf prefix-list receive",
+ "set protocols bgp 65536 neighbor 192.168.0.2 attribute-unchanged as-path",
+ "set protocols bgp 65536 neighbor 192.168.0.2 attribute-unchanged med",
+ "set protocols bgp 65536 neighbor 192.168.0.2 attribute-unchanged next-hop",
+ "set protocols bgp 65536 neighbor 192.168.0.2 ebgp-multihop 2",
+ "set protocols bgp 65536 neighbor 192.168.0.2 remote-as 65535",
+ "set protocols bgp 65536 neighbor 192.168.0.2 soft-reconfiguration",
+ "set protocols bgp 65536 neighbor 192.168.0.2 update-source 192.168.0.1",
+ "set protocols bgp 65536 neighbor 2001:db8::2 ebgp-multihop 2",
+ "set protocols bgp 65536 neighbor 2001:db8::2 remote-as 65535",
+ "set protocols bgp 65536 neighbor 2001:db8::2 maximum-prefix 34",
+ "set protocols bgp 65536 neighbor 2001:db8::2 update-source 2001:db8::1",
+ "set protocols bgp 65536 redistribute kernel route-map map01",
+ "set protocols bgp 65536 redistribute static route-map map01",
+ "set protocols bgp 65536 network 172.16.42.32/27 backdoor",
+ "set protocols bgp 65536 network 172.16.42.251/32 route-map map01",
+ "set protocols bgp 65536 parameters bestpath as-path confed",
+ "set protocols bgp 65536 parameters bestpath compare-routerid",
+ "set protocols bgp 65536 parameters default no-ipv4-unicast",
+ "set protocols bgp 65536 parameters router-id 10.1.1.1",
+ ]
+ result = self.execute_module(changed=False)
+ self.assertEqual(
+ sorted(result["rendered"]),
+ sorted(rendered_cmds),
+ result["rendered"],
+ )
+
+ def test_vyos_bgp_global_parsed(self):
+
+ commands = [
+ "set protocols bgp 65536 neighbor 10.0.0.4 disable-connected-check",
+ "set protocols bgp 65536 neighbor 10.0.0.4 timers holdtime 30",
+ "set protocols bgp 65536 neighbor 10.0.0.4 timers keepalive 10",
+ "set protocols bgp 65536 neighbor 10.0.0.4 capability orf prefix-list receive",
+ "set protocols bgp 65536 neighbor 192.168.0.2 attribute-unchanged as-path",
+ "set protocols bgp 65536 neighbor 192.168.0.2 attribute-unchanged med",
+ "set protocols bgp 65536 neighbor 192.168.0.2 attribute-unchanged next-hop",
+ "set protocols bgp 65536 neighbor 192.168.0.2 ebgp-multihop 2",
+ "set protocols bgp 65536 neighbor 192.168.0.2 remote-as 65535",
+ "set protocols bgp 65536 neighbor 192.168.0.2 soft-reconfiguration",
+ "set protocols bgp 65536 neighbor 192.168.0.2 update-source 192.168.0.1",
+ "set protocols bgp 65536 neighbor 2001:db8::2 ebgp-multihop 2",
+ "set protocols bgp 65536 neighbor 2001:db8::2 remote-as 65535",
+ "set protocols bgp 65536 neighbor 2001:db8::2 maximum-prefix 34",
+ "set protocols bgp 65536 neighbor 2001:db8::2 update-source 2001:db8::1",
+ "set protocols bgp 65536 redistribute kernel route-map map01",
+ "set protocols bgp 65536 redistribute static route-map map01",
+ "set protocols bgp 65536 network 172.16.42.32/27 backdoor",
+ "set protocols bgp 65536 network 172.16.42.251/32 route-map map01",
+ "set protocols bgp 65536 parameters bestpath as-path confed",
+ "set protocols bgp 65536 parameters bestpath compare-routerid",
+ "set protocols bgp 65536 parameters default no-ipv4-unicast",
+ "set protocols bgp 65536 parameters router-id 10.1.1.1",
+ ]
+ parsed_str = "\n".join(commands)
+ set_module_args(dict(running_config=parsed_str, state="parsed"))
+ result = self.execute_module(changed=False)
+ parsed_list = {
+ "as_number": 65536,
+ "bgp_params": {
+ "bestpath": {"as_path": "confed", "compare_routerid": True},
+ "default": {"no_ipv4_unicast": True},
+ "router_id": "10.1.1.1",
+ },
+ "neighbor": [
+ {
+ "address": "10.0.0.4",
+ "capability": {"orf": "receive"},
+ "disable_connected_check": True,
+ "timers": {"holdtime": 30, "keepalive": 10},
+ },
+ {
+ "address": "192.168.0.2",
+ "attribute_unchanged": {
+ "as_path": True,
+ "med": True,
+ "next_hop": True,
+ },
+ "ebgp_multihop": 2,
+ "remote_as": 65535,
+ "update_source": "192.168.0.1",
+ },
+ {
+ "address": "2001:db8::2",
+ "ebgp_multihop": 2,
+ "maximum_prefix": 34,
+ "remote_as": 65535,
+ "update_source": "2001:db8::1",
+ },
+ ],
+ "network": [
+ {"address": "172.16.42.32/27", "backdoor": True},
+ {"address": "172.16.42.251/32", "route_map": "map01"},
+ ],
+ "redistribute": [
+ {"protocol": "kernel", "route_map": "map01"},
+ {"protocol": "static", "route_map": "map01"},
+ ],
+ }
+ self.assertEqual(sorted(parsed_list), sorted(result["parsed"]))
+
+ def test_vyos_bgp_global_gathered(self):
+ set_module_args(dict(state="gathered"))
+ result = self.execute_module(changed=False)
+ gather_list = {
+ "as_number": 65536,
+ "bgp_params": {
+ "bestpath": {"as_path": "confed", "compare_routerid": True},
+ "default": {"no_ipv4_unicast": True},
+ "router_id": "10.1.1.1",
+ },
+ "neighbor": [
+ {
+ "address": "10.0.0.4",
+ "capability": {"orf": "receive"},
+ "disable_connected_check": True,
+ "timers": {"holdtime": 30, "keepalive": 10},
+ },
+ {
+ "address": "192.168.0.2",
+ "attribute_unchanged": {"as_path": True, "med": True},
+ "ebgp_multihop": 2,
+ "remote_as": 65535,
+ "soft_reconfiguration": True,
+ "update_source": "192.168.0.1",
+ },
+ {
+ "address": "2001:db8::2",
+ "ebgp_multihop": 2,
+ "maximum_prefix": 34,
+ "remote_as": 65535,
+ "update_source": "2001:db8::1",
+ },
+ ],
+ "network": [
+ {"address": "172.16.42.32/27", "backdoor": True},
+ {"address": "172.16.42.251/32", "route_map": "map01"},
+ ],
+ "redistribute": [
+ {"protocol": "kernel", "route_map": "map01"},
+ {"metric": 20, "protocol": "static"},
+ {"protocol": "static", "route_map": "map01"},
+ ],
+ }
+ self.assertEqual(sorted(gather_list), sorted(result["gathered"]))
diff --git a/tests/unit/modules/network/vyos/vyos_module.py b/tests/unit/modules/network/vyos/vyos_module.py
index 49d4652..cb7874f 100644
--- a/tests/unit/modules/network/vyos/vyos_module.py
+++ b/tests/unit/modules/network/vyos/vyos_module.py
@@ -62,7 +62,11 @@ class TestVyosModule(ModuleTestCase):
defaults=False,
filename=None,
):
- self.load_fixtures(commands)
+
+ if filename is None:
+ self.load_fixtures(commands)
+ else:
+ self.load_fixtures(commands, filename=filename)
if failed:
result = self.failed()
@@ -101,5 +105,5 @@ class TestVyosModule(ModuleTestCase):
self.assertEqual(result["changed"], changed, result)
return result
- def load_fixtures(self, commands=None):
+ def load_fixtures(self, commands=None, filename=None):
pass