summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
Diffstat (limited to 'tests')
-rw-r--r--tests/integration/targets/vyos_lag_interfaces/tests/cli/_add_bond.yaml6
-rw-r--r--tests/integration/targets/vyos_lag_interfaces/tests/cli/_parsed_config.cfg4
-rw-r--r--tests/integration/targets/vyos_lag_interfaces/tests/cli/_populate.yaml4
-rw-r--r--tests/integration/targets/vyos_lag_interfaces/tests/cli/_remove_bond.yaml4
-rw-r--r--tests/integration/targets/vyos_lag_interfaces/tests/cli/deleted.yaml8
-rw-r--r--tests/integration/targets/vyos_lag_interfaces/tests/cli/gathered.yaml2
-rw-r--r--tests/integration/targets/vyos_lag_interfaces/tests/cli/merged.yaml8
-rw-r--r--tests/integration/targets/vyos_lag_interfaces/tests/cli/overridden.yaml8
-rw-r--r--tests/integration/targets/vyos_lag_interfaces/tests/cli/parsed.yaml2
-rw-r--r--tests/integration/targets/vyos_lag_interfaces/tests/cli/rendered.yaml2
-rw-r--r--tests/integration/targets/vyos_lag_interfaces/tests/cli/replaced.yaml8
-rw-r--r--tests/integration/targets/vyos_lag_interfaces/tests/cli/rtt.yaml8
-rw-r--r--tests/integration/targets/vyos_lag_interfaces/tests/redirection/cli/shortname.yaml8
-rw-r--r--tests/integration/targets/vyos_lag_interfaces/vars/main.yaml18
-rw-r--r--tests/unit/modules/network/vyos/fixtures/vyos_lag_interfaces_config.cfg5
-rw-r--r--tests/unit/modules/network/vyos/test_vyos_interfaces.py6
-rw-r--r--tests/unit/modules/network/vyos/test_vyos_lag_interfaces.py157
17 files changed, 210 insertions, 48 deletions
diff --git a/tests/integration/targets/vyos_lag_interfaces/tests/cli/_add_bond.yaml b/tests/integration/targets/vyos_lag_interfaces/tests/cli/_add_bond.yaml
index fa191ed3..3c6743c2 100644
--- a/tests/integration/targets/vyos_lag_interfaces/tests/cli/_add_bond.yaml
+++ b/tests/integration/targets/vyos_lag_interfaces/tests/cli/_add_bond.yaml
@@ -2,7 +2,7 @@
- ansible.builtin.include_tasks: _remove_bond.yaml
- name: Add Bond
- vars:
- lines: "set interfaces bonding bond0\nset interfaces bonding bond1\n"
ansible.netcommon.cli_config:
- config: "{{ lines }}"
+ config: |-
+ set interfaces bonding bond0
+ set interfaces bonding bond1
diff --git a/tests/integration/targets/vyos_lag_interfaces/tests/cli/_parsed_config.cfg b/tests/integration/targets/vyos_lag_interfaces/tests/cli/_parsed_config.cfg
index 1a275bdd..d9f18551 100644
--- a/tests/integration/targets/vyos_lag_interfaces/tests/cli/_parsed_config.cfg
+++ b/tests/integration/targets/vyos_lag_interfaces/tests/cli/_parsed_config.cfg
@@ -4,5 +4,5 @@ set interfaces bonding bond0 primary 'eth1'
set interfaces bonding bond1 hash-policy 'layer2+3'
set interfaces bonding bond1 mode 'active-backup'
set interfaces bonding bond1 primary 'eth2'
-set interfaces ethernet eth1 bond-group 'bond0'
-set interfaces ethernet eth2 bond-group 'bond1'
+set interfaces bonding bond0 member interface 'eth1'
+set interfaces bonding bond1 member interface 'eth2'
diff --git a/tests/integration/targets/vyos_lag_interfaces/tests/cli/_populate.yaml b/tests/integration/targets/vyos_lag_interfaces/tests/cli/_populate.yaml
index be0d6351..728a8cf0 100644
--- a/tests/integration/targets/vyos_lag_interfaces/tests/cli/_populate.yaml
+++ b/tests/integration/targets/vyos_lag_interfaces/tests/cli/_populate.yaml
@@ -7,12 +7,12 @@
set interfaces bonding bond0
set interfaces bonding bond0 hash-policy 'layer2'
set interfaces bonding bond0 mode 'active-backup'
- set interfaces ethernet eth1 bond-group bond0
+ set interfaces bonding bond0 member interface 'eth1'
set interfaces bonding bond1
set interfaces bonding bond0 primary 'eth1'
set interfaces bonding bond1 hash-policy 'layer2+3'
set interfaces bonding bond1 mode 'active-backup'
- set interfaces ethernet eth2 bond-group bond1
+ set interfaces bonding bond1 member interface 'eth2'
set interfaces bonding bond1 primary 'eth2'
ansible.netcommon.cli_config:
config: "{{ lines }}"
diff --git a/tests/integration/targets/vyos_lag_interfaces/tests/cli/_remove_bond.yaml b/tests/integration/targets/vyos_lag_interfaces/tests/cli/_remove_bond.yaml
index e22a6ca7..3643ae32 100644
--- a/tests/integration/targets/vyos_lag_interfaces/tests/cli/_remove_bond.yaml
+++ b/tests/integration/targets/vyos_lag_interfaces/tests/cli/_remove_bond.yaml
@@ -2,11 +2,11 @@
vars:
lines: |-
delete interfaces bonding bond0 hash-policy
- delete interfaces ethernet eth1 bond-group bond0
+ delete interfaces bonding bond0 member interface 'eth1'
delete interfaces bonding bond0 mode
delete interfaces bonding bond0 primary
delete interfaces bonding bond1 hash-policy
- delete interfaces ethernet eth2 bond-group bond1
+ delete interfaces bonding bond1 member interface 'eth2'
delete interfaces bonding bond1 mode
delete interfaces bonding bond1 primary
ansible.netcommon.cli_config:
diff --git a/tests/integration/targets/vyos_lag_interfaces/tests/cli/deleted.yaml b/tests/integration/targets/vyos_lag_interfaces/tests/cli/deleted.yaml
index e30be078..d273f040 100644
--- a/tests/integration/targets/vyos_lag_interfaces/tests/cli/deleted.yaml
+++ b/tests/integration/targets/vyos_lag_interfaces/tests/cli/deleted.yaml
@@ -17,17 +17,17 @@
- name: Assert that the before dicts were correctly generated
assert:
that:
- - "{{ populate | symmetric_difference(result['before']) |length == 0 }}"
+ - populate | symmetric_difference(result['before']) |length == 0
- name: Assert that the correct set of commands were generated
assert:
that:
- - "{{ deleted['commands'] | symmetric_difference(result['commands']) |length == 0 }}"
+ - deleted['commands'] | symmetric_difference(result['commands']) |length == 0
- name: Assert that the after dicts were correctly generated
assert:
that:
- - "{{ deleted['after'] | symmetric_difference(result['after']) |length == 0 }}"
+ - deleted['after'] | symmetric_difference(result['after']) |length == 0
- name: Delete attributes of given interfaces (IDEMPOTENT)
register: result
@@ -41,6 +41,6 @@
- name: Assert that the before dicts were correctly generated
assert:
that:
- - "{{ deleted['after'] | symmetric_difference(result['before']) |length == 0 }}"
+ - deleted['after'] | symmetric_difference(result['before']) |length == 0
always:
- include_tasks: _remove_bond.yaml
diff --git a/tests/integration/targets/vyos_lag_interfaces/tests/cli/gathered.yaml b/tests/integration/targets/vyos_lag_interfaces/tests/cli/gathered.yaml
index f6c281f5..ff7f9c7d 100644
--- a/tests/integration/targets/vyos_lag_interfaces/tests/cli/gathered.yaml
+++ b/tests/integration/targets/vyos_lag_interfaces/tests/cli/gathered.yaml
@@ -14,7 +14,7 @@
- name: Assert that gathered dicts was correctly generated
assert:
that:
- - "{{ populate | symmetric_difference(result['gathered']) |length == 0 }}"
+ - populate | symmetric_difference(result['gathered']) |length == 0
always:
- include_tasks: _remove_bond.yaml
diff --git a/tests/integration/targets/vyos_lag_interfaces/tests/cli/merged.yaml b/tests/integration/targets/vyos_lag_interfaces/tests/cli/merged.yaml
index 64ac9a4a..2274f301 100644
--- a/tests/integration/targets/vyos_lag_interfaces/tests/cli/merged.yaml
+++ b/tests/integration/targets/vyos_lag_interfaces/tests/cli/merged.yaml
@@ -26,17 +26,17 @@
- name: Assert that before dicts were correctly generated
assert:
- that: "{{ merged['before'] | symmetric_difference(result['before']) |length == 0 }}"
+ that: merged['before'] | symmetric_difference(result['before']) |length == 0
- name: Assert that correct set of commands were generated
assert:
that:
- - "{{ merged['commands'] | symmetric_difference(result['commands']) |length == 0 }}"
+ - merged['commands'] | symmetric_difference(result['commands']) |length == 0
- name: Assert that after dicts was correctly generated
assert:
that:
- - "{{ merged['after'] | symmetric_difference(result['after']) |length == 0 }}"
+ - merged['after'] | symmetric_difference(result['after']) |length == 0
- name: Merge the provided configuration with the existing running configuration (IDEMPOTENT)
register: result
@@ -50,6 +50,6 @@
- name: Assert that before dicts were correctly generated
assert:
that:
- - "{{ merged['after'] | symmetric_difference(result['before']) |length == 0 }}"
+ - merged['after'] | symmetric_difference(result['before']) |length == 0
always:
- include_tasks: _remove_bond.yaml
diff --git a/tests/integration/targets/vyos_lag_interfaces/tests/cli/overridden.yaml b/tests/integration/targets/vyos_lag_interfaces/tests/cli/overridden.yaml
index 482d54d1..b1f0065c 100644
--- a/tests/integration/targets/vyos_lag_interfaces/tests/cli/overridden.yaml
+++ b/tests/integration/targets/vyos_lag_interfaces/tests/cli/overridden.yaml
@@ -20,17 +20,17 @@
- name: Assert that before dicts were correctly generated
assert:
that:
- - "{{ populate | symmetric_difference(result['before']) |length == 0 }}"
+ - populate | symmetric_difference(result['before']) |length == 0
- name: Assert that correct commands were generated
assert:
that:
- - "{{ overridden['commands'] | symmetric_difference(result['commands']) |length == 0 }}"
+ - overridden['commands'] | symmetric_difference(result['commands']) |length == 0
- name: Assert that after dicts were correctly generated
assert:
that:
- - "{{ overridden['after'] | symmetric_difference(result['after']) |length == 0 }}"
+ - overridden['after'] | symmetric_difference(result['after']) |length == 0
- name: Overrides all device configuration with provided configurations (IDEMPOTENT)
register: result
@@ -44,6 +44,6 @@
- name: Assert that before dicts were correctly generated
assert:
that:
- - "{{ overridden['after'] | symmetric_difference(result['before']) |length == 0 }}"
+ - overridden['after'] | symmetric_difference(result['before']) |length == 0
always:
- include_tasks: _remove_bond.yaml
diff --git a/tests/integration/targets/vyos_lag_interfaces/tests/cli/parsed.yaml b/tests/integration/targets/vyos_lag_interfaces/tests/cli/parsed.yaml
index 81a7b46d..c3dd4ff2 100644
--- a/tests/integration/targets/vyos_lag_interfaces/tests/cli/parsed.yaml
+++ b/tests/integration/targets/vyos_lag_interfaces/tests/cli/parsed.yaml
@@ -21,7 +21,7 @@
- name: Assert that correct parsing done
assert:
- that: "{{ ansible_facts['network_resources']['lag_interfaces'] | symmetric_difference(result['parsed']) |length == 0 }}"
+ that: ansible_facts['network_resources']['lag_interfaces'] | symmetric_difference(result['parsed']) |length == 0
always:
- include_tasks: _remove_bond.yaml
diff --git a/tests/integration/targets/vyos_lag_interfaces/tests/cli/rendered.yaml b/tests/integration/targets/vyos_lag_interfaces/tests/cli/rendered.yaml
index 7d86a3ae..0241b7c4 100644
--- a/tests/integration/targets/vyos_lag_interfaces/tests/cli/rendered.yaml
+++ b/tests/integration/targets/vyos_lag_interfaces/tests/cli/rendered.yaml
@@ -26,7 +26,7 @@
- name: Assert that correct set of commands were generated
assert:
that:
- - "{{ rendered['commands'] | symmetric_difference(result['rendered']) |length == 0 }}"
+ - rendered['commands'] | symmetric_difference(result['rendered']) |length == 0
always:
- include_tasks: _remove_bond.yaml
diff --git a/tests/integration/targets/vyos_lag_interfaces/tests/cli/replaced.yaml b/tests/integration/targets/vyos_lag_interfaces/tests/cli/replaced.yaml
index 66e55df7..caf3f1d1 100644
--- a/tests/integration/targets/vyos_lag_interfaces/tests/cli/replaced.yaml
+++ b/tests/integration/targets/vyos_lag_interfaces/tests/cli/replaced.yaml
@@ -19,17 +19,17 @@
- name: Assert that correct set of commands were generated
assert:
that:
- - "{{ replaced['commands'] | symmetric_difference(result['commands']) |length == 0 }}"
+ - replaced['commands'] | symmetric_difference(result['commands']) |length == 0
- name: Assert that before dicts are correctly generated
assert:
that:
- - "{{ populate | symmetric_difference(result['before']) |length == 0 }}"
+ - populate | symmetric_difference(result['before']) |length == 0
- name: Assert that after dict is correctly generated
assert:
that:
- - "{{ replaced['after'] | symmetric_difference(result['after']) |length == 0 }}"
+ - replaced['after'] | symmetric_difference(result['after']) |length == 0
- name: Replace device configurations of listed LAG interfaces with provided configurarions (IDEMPOTENT)
register: result
@@ -43,6 +43,6 @@
- name: Assert that before dict is correctly generated
assert:
that:
- - "{{ replaced['after'] | symmetric_difference(result['before']) |length == 0 }}"
+ - replaced['after'] | symmetric_difference(result['before']) |length == 0
always:
- include_tasks: _remove_bond.yaml
diff --git a/tests/integration/targets/vyos_lag_interfaces/tests/cli/rtt.yaml b/tests/integration/targets/vyos_lag_interfaces/tests/cli/rtt.yaml
index 5e9dc752..b4c07abe 100644
--- a/tests/integration/targets/vyos_lag_interfaces/tests/cli/rtt.yaml
+++ b/tests/integration/targets/vyos_lag_interfaces/tests/cli/rtt.yaml
@@ -37,20 +37,20 @@
config:
- name: bond0
hash_policy: layer2+3
- mode: 802.3ad
+ mode: transmit-load-balance
members:
- member: eth1
- name: bond1
hash_policy: layer2
- mode: xor-hash
+ mode: adaptive-load-balance
members:
- member: eth2
state: merged
- name: Assert that changes were applied
assert:
- that: "{{ round_trip['after'] | symmetric_difference(result['after']) |length == 0 }}"
+ that: round_trip['after'] | symmetric_difference(result['after']) |length == 0
- name: Revert back to base config using facts round trip
register: revert
@@ -60,6 +60,6 @@
- name: Assert that config was reverted
assert:
- that: "{{ base_config['after'] | symmetric_difference(revert['after']) |length == 0 }}"
+ that: base_config['after'] | symmetric_difference(revert['after']) |length == 0
always:
- include_tasks: _remove_bond.yaml
diff --git a/tests/integration/targets/vyos_lag_interfaces/tests/redirection/cli/shortname.yaml b/tests/integration/targets/vyos_lag_interfaces/tests/redirection/cli/shortname.yaml
index 40c5fe2b..fd2c10a5 100644
--- a/tests/integration/targets/vyos_lag_interfaces/tests/redirection/cli/shortname.yaml
+++ b/tests/integration/targets/vyos_lag_interfaces/tests/redirection/cli/shortname.yaml
@@ -26,17 +26,17 @@
- name: Assert that before dicts were correctly generated
assert:
- that: "{{ merged['before'] | symmetric_difference(result['before']) |length == 0 }}"
+ that: merged['before'] | symmetric_difference(result['before']) |length == 0
- name: Assert that correct set of commands were generated
assert:
that:
- - "{{ merged['commands'] | symmetric_difference(result['commands']) |length == 0 }}"
+ - merged['commands'] | symmetric_difference(result['commands']) |length == 0
- name: Assert that after dicts was correctly generated
assert:
that:
- - "{{ merged['after'] | symmetric_difference(result['after']) |length == 0 }}"
+ - merged['after'] | symmetric_difference(result['after']) |length == 0
- name: Merge the provided configuration with the existing running configuration (IDEMPOTENT)
register: result
@@ -50,6 +50,6 @@
- name: Assert that before dicts were correctly generated
assert:
that:
- - "{{ merged['after'] | symmetric_difference(result['before']) |length == 0 }}"
+ - merged['after'] | symmetric_difference(result['before']) |length == 0
always:
- include_tasks: _remove_bond.yaml
diff --git a/tests/integration/targets/vyos_lag_interfaces/vars/main.yaml b/tests/integration/targets/vyos_lag_interfaces/vars/main.yaml
index 9784fb97..40b6a9d8 100644
--- a/tests/integration/targets/vyos_lag_interfaces/vars/main.yaml
+++ b/tests/integration/targets/vyos_lag_interfaces/vars/main.yaml
@@ -6,11 +6,11 @@ merged:
commands:
- set interfaces bonding bond0 hash-policy 'layer2'
- set interfaces bonding bond0 mode 'active-backup'
- - set interfaces ethernet eth1 bond-group 'bond0'
+ - set interfaces bonding bond0 member interface 'eth1'
- set interfaces bonding bond0 primary 'eth1'
- set interfaces bonding bond1 hash-policy 'layer2+3'
- set interfaces bonding bond1 mode 'active-backup'
- - set interfaces ethernet eth2 bond-group 'bond1'
+ - set interfaces bonding bond1 member interface 'eth2'
- set interfaces bonding bond1 primary 'eth2'
after:
- name: bond0
@@ -58,7 +58,7 @@ replaced:
overridden:
commands:
- delete interfaces bonding bond0 hash-policy
- - delete interfaces ethernet eth1 bond-group 'bond0'
+ - delete interfaces bonding bond0 member interface 'eth1'
- delete interfaces bonding bond0 mode
- delete interfaces bonding bond0 primary
- set interfaces bonding bond1 hash-policy 'layer2'
@@ -73,11 +73,11 @@ overridden:
deleted:
commands:
- delete interfaces bonding bond0 hash-policy
- - delete interfaces ethernet eth1 bond-group 'bond0'
+ - delete interfaces bonding bond0 member interface 'eth1'
- delete interfaces bonding bond0 mode
- delete interfaces bonding bond0 primary
- delete interfaces bonding bond1 hash-policy
- - delete interfaces ethernet eth2 bond-group 'bond1'
+ - delete interfaces bonding bond1 member interface 'eth2'
- delete interfaces bonding bond1 mode
- delete interfaces bonding bond1 primary
after:
@@ -86,11 +86,11 @@ deleted:
rendered:
commands:
- set interfaces bonding bond0 hash-policy 'layer2'
- - set interfaces ethernet eth1 bond-group 'bond0'
+ - set interfaces bonding bond0 member interface 'eth1'
- set interfaces bonding bond0 mode 'active-backup'
- set interfaces bonding bond0 primary 'eth1'
- set interfaces bonding bond1 hash-policy 'layer2+3'
- - set interfaces ethernet eth2 bond-group 'bond1'
+ - set interfaces bonding bond1 member interface 'eth2'
- set interfaces bonding bond1 mode 'active-backup'
- set interfaces bonding bond1 primary 'eth2'
round_trip:
@@ -99,11 +99,11 @@ round_trip:
hash_policy: layer2+3
members:
- member: eth1
- mode: 802.3ad
+ mode: transmit-load-balance
primary: eth1
- name: bond1
hash_policy: layer2
members:
- member: eth2
- mode: xor-hash
+ mode: adaptive-load-balance
primary: eth2
diff --git a/tests/unit/modules/network/vyos/fixtures/vyos_lag_interfaces_config.cfg b/tests/unit/modules/network/vyos/fixtures/vyos_lag_interfaces_config.cfg
new file mode 100644
index 00000000..645cbdb1
--- /dev/null
+++ b/tests/unit/modules/network/vyos/fixtures/vyos_lag_interfaces_config.cfg
@@ -0,0 +1,5 @@
+set interfaces bonding bond0 member interface 'eth0'
+set interfaces bonding bond0 member interface 'eth1'
+set interfaces bonding bond0 primary 'eth0'
+set interfaces bonding bond0 mode '802.3ad'
+set interfaces bonding bond0 hash-policy 'layer2+3'
diff --git a/tests/unit/modules/network/vyos/test_vyos_interfaces.py b/tests/unit/modules/network/vyos/test_vyos_interfaces.py
index 8549d768..f4a5d2a5 100644
--- a/tests/unit/modules/network/vyos/test_vyos_interfaces.py
+++ b/tests/unit/modules/network/vyos/test_vyos_interfaces.py
@@ -29,11 +29,11 @@ from ansible_collections.vyos.vyos.tests.unit.modules.utils import set_module_ar
from .vyos_module import TestVyosModule, load_fixture
-class TestVyosFirewallInterfacesModule(TestVyosModule):
+class TestVyosInterfacesModule(TestVyosModule):
module = vyos_interfaces
def setUp(self):
- super(TestVyosFirewallInterfacesModule, self).setUp()
+ super(TestVyosInterfacesModule, self).setUp()
self.mock_get_config = patch(
"ansible_collections.ansible.netcommon.plugins.module_utils.network.common.network.Config.get_config",
)
@@ -63,7 +63,7 @@ class TestVyosFirewallInterfacesModule(TestVyosModule):
self.fixture_path = "vyos_interfaces_config.cfg"
def tearDown(self):
- super(TestVyosFirewallInterfacesModule, self).tearDown()
+ super(TestVyosInterfacesModule, self).tearDown()
self.mock_get_resource_connection_config.stop()
self.mock_get_resource_connection_facts.stop()
self.mock_get_config.stop()
diff --git a/tests/unit/modules/network/vyos/test_vyos_lag_interfaces.py b/tests/unit/modules/network/vyos/test_vyos_lag_interfaces.py
new file mode 100644
index 00000000..406ca598
--- /dev/null
+++ b/tests/unit/modules/network/vyos/test_vyos_lag_interfaces.py
@@ -0,0 +1,157 @@
+# (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 unittest.mock import patch
+
+from ansible_collections.vyos.vyos.plugins.modules import vyos_lag_interfaces
+from ansible_collections.vyos.vyos.tests.unit.modules.utils import set_module_args
+
+from .vyos_module import TestVyosModule, load_fixture
+
+
+class TestVyosLagInterfacesModule(TestVyosModule):
+ module = vyos_lag_interfaces
+
+ def setUp(self):
+ super(TestVyosLagInterfacesModule, self).setUp()
+ self.mock_get_config = patch(
+ "ansible_collections.ansible.netcommon.plugins.module_utils.network.common.network.Config.get_config",
+ )
+ self.get_config = self.mock_get_config.start()
+
+ self.mock_load_config = patch(
+ "ansible_collections.ansible.netcommon.plugins.module_utils.network.common.network.Config.load_config",
+ )
+ self.load_config = self.mock_load_config.start()
+
+ self.mock_get_resource_connection_config = patch(
+ "ansible_collections.ansible.netcommon.plugins.module_utils.network.common.cfg.base.get_resource_connection",
+ )
+ self.get_resource_connection_config = self.mock_get_resource_connection_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.lag_interfaces.lag_interfaces.Lag_interfacesFacts.get_config",
+ )
+ self.execute_show_command = self.mock_execute_show_command.start()
+ # define the default fixture for the vyos_interfaces module
+ self.fixture_path = "vyos_lag_interfaces_config.cfg"
+
+ def tearDown(self):
+ super(TestVyosLagInterfacesModule, self).tearDown()
+ self.mock_get_resource_connection_config.stop()
+ self.mock_get_resource_connection_facts.stop()
+ self.mock_get_config.stop()
+ self.mock_load_config.stop()
+ self.mock_execute_show_command.stop()
+
+ def load_fixtures(self, commands=None, filename=None):
+ def load_from_file(*args, **kwargs):
+ return load_fixture(self.fixture_path)
+
+ self.execute_show_command.side_effect = load_from_file
+
+ def test_vyos_interfaces_merged(self):
+ set_module_args(
+ dict(
+ config=[
+ dict(
+ name="bond1",
+ members=[{"member": "eth2"}, {"member": "eth3"}],
+ mode="802.3ad",
+ hash_policy="layer2+3",
+ primary="eth2",
+ ),
+ ],
+ state="merged",
+ ),
+ )
+
+ commands = [
+ "set interfaces bonding bond1 member interface 'eth2'",
+ "set interfaces bonding bond1 member interface 'eth3'",
+ "set interfaces bonding bond1 primary 'eth2'",
+ "set interfaces bonding bond1 mode '802.3ad'",
+ "set interfaces bonding bond1 hash-policy 'layer2+3'",
+ ]
+ self.execute_module(changed=True, commands=commands)
+
+ def test_vyos_interfaces_replaced(self):
+ set_module_args(
+ dict(
+ config=[
+ dict(
+ name="bond1",
+ members=[{"member": "eth2"}, {"member": "eth3"}],
+ mode="802.3ad",
+ hash_policy="layer2+3",
+ primary="eth2",
+ ),
+ ],
+ state="replaced",
+ ),
+ )
+
+ commands = [
+ "set interfaces bonding bond1 member interface 'eth2'",
+ "set interfaces bonding bond1 member interface 'eth3'",
+ "set interfaces bonding bond1 primary 'eth2'",
+ "set interfaces bonding bond1 mode '802.3ad'",
+ "set interfaces bonding bond1 hash-policy 'layer2+3'",
+ ]
+ self.execute_module(changed=True, commands=commands)
+
+ def test_vyos_interfaces_overridden(self):
+ set_module_args(
+ dict(
+ config=[
+ dict(
+ name="bond1",
+ members=[{"member": "eth2"}, {"member": "eth3"}],
+ mode="802.3ad",
+ hash_policy="layer2+3",
+ primary="eth2",
+ ),
+ ],
+ state="overridden",
+ ),
+ )
+
+ commands = [
+ "delete interfaces bonding bond0 member interface 'eth0'",
+ "delete interfaces bonding bond0 member interface 'eth1'",
+ "delete interfaces bonding bond0 primary",
+ "delete interfaces bonding bond0 mode",
+ "delete interfaces bonding bond0 hash-policy",
+ "set interfaces bonding bond1 member interface 'eth2'",
+ "set interfaces bonding bond1 member interface 'eth3'",
+ "set interfaces bonding bond1 primary 'eth2'",
+ "set interfaces bonding bond1 mode '802.3ad'",
+ "set interfaces bonding bond1 hash-policy 'layer2+3'",
+ ]
+ self.execute_module(changed=True, commands=commands)