mirror of
https://github.com/ansible-collections/community.general.git
synced 2026-05-06 13:22:48 +00:00
Convert nxos_vlan to DI module (#31866)
* Convert nxos_vlan to DI * fix conflict * push fix for qalthos's comment Signed-off-by: Trishna Guha <trishnaguha17@gmail.com>
This commit is contained in:
105
test/integration/targets/nxos_vlan/tests/common/interface.yaml
Normal file
105
test/integration/targets/nxos_vlan/tests/common/interface.yaml
Normal file
@@ -0,0 +1,105 @@
|
||||
---
|
||||
- set_fact: testint1="{{ nxos_int1 }}"
|
||||
- set_fact: testint2="{{ nxos_int2 }}"
|
||||
|
||||
- name: setup - remove vlan used in test
|
||||
nxos_config:
|
||||
lines:
|
||||
- no vlan 100
|
||||
provider: "{{ connection }}"
|
||||
|
||||
- name: setup - remove vlan from interfaces used in test(part1)
|
||||
nxos_config:
|
||||
lines:
|
||||
- no switchport access vlan 100
|
||||
parents: switchport
|
||||
before: "interface {{ testint1 }}"
|
||||
provider: "{{ connection }}"
|
||||
|
||||
- name: setup - remove vlan from interfaces used in test(part2)
|
||||
nxos_config:
|
||||
lines:
|
||||
- no switchport access vlan 100
|
||||
parents: switchport
|
||||
before: "interface {{ testint2 }}"
|
||||
provider: "{{ connection }}"
|
||||
|
||||
- name: create vlan
|
||||
nxos_vlan:
|
||||
vlan_id: 100
|
||||
provider: "{{ connection }}"
|
||||
|
||||
- name: Add interfaces to vlan
|
||||
nxos_vlan: &interfaces
|
||||
vlan_id: 100
|
||||
interfaces:
|
||||
- "{{ testint1 }}"
|
||||
- "{{ testint2 }}"
|
||||
provider: "{{ connection }}"
|
||||
register: result
|
||||
|
||||
- assert:
|
||||
that:
|
||||
- 'result.changed == true'
|
||||
- '"interface {{ testint1 }}" in result.commands'
|
||||
- '"switchport" in result.commands'
|
||||
- '"switchport mode access" in result.commands'
|
||||
- '"switchport access vlan 100" in result.commands'
|
||||
- '"interface {{ testint2 }}" in result.commands'
|
||||
- '"switchport" in result.commands'
|
||||
- '"switchport mode access" in result.commands'
|
||||
- '"switchport access vlan 100" in result.commands'
|
||||
|
||||
- name: Add interfaces to vlan(idempotence)
|
||||
nxos_vlan: *interfaces
|
||||
register: result
|
||||
|
||||
- assert:
|
||||
that:
|
||||
- 'result.changed == false'
|
||||
|
||||
- name: Remove interface from vlan
|
||||
nxos_vlan: &single_int
|
||||
vlan_id: 100
|
||||
interfaces:
|
||||
- "{{ testint2 }}"
|
||||
provider: "{{ connection }}"
|
||||
register: result
|
||||
|
||||
- assert:
|
||||
that:
|
||||
- 'result.changed == true'
|
||||
- '"interface {{ testint1 }}" in result.commands'
|
||||
- '"switchport" in result.commands'
|
||||
- '"switchport mode access" in result.commands'
|
||||
- '"no switchport access vlan 100" in result.commands'
|
||||
|
||||
- name: Remove interface from vlan(idempotence)
|
||||
nxos_vlan: *single_int
|
||||
register: result
|
||||
|
||||
- assert:
|
||||
that:
|
||||
- 'result.changed == false'
|
||||
|
||||
- name: teardown(part1)
|
||||
nxos_config:
|
||||
lines:
|
||||
- no vlan 100
|
||||
provider: "{{ connection }}"
|
||||
|
||||
- name: teardown - remove vlan from interfaces used in test(part1)
|
||||
nxos_config:
|
||||
lines:
|
||||
- no switchport access vlan 100
|
||||
parents: switchport
|
||||
before: "interface {{ testint1 }}"
|
||||
provider: "{{ connection }}"
|
||||
|
||||
- name: teardown - remove vlan from interfaces used in test(part2)
|
||||
nxos_config:
|
||||
lines:
|
||||
- no switchport access vlan 100
|
||||
parents: switchport
|
||||
before: "interface {{ testint2 }}"
|
||||
provider: "{{ connection }}"
|
||||
@@ -1,20 +0,0 @@
|
||||
{
|
||||
"TABLE_vlanbriefid": {
|
||||
"ROW_vlanbriefid": {
|
||||
"vlanshowbr-vlanid": 16777216,
|
||||
"vlanshowbr-vlanid-utf": 1,
|
||||
"vlanshowbr-vlanname": "default",
|
||||
"vlanshowbr-vlanstate": "active",
|
||||
"vlanshowbr-shutstate": "noshutdown"
|
||||
}
|
||||
},
|
||||
"TABLE_mtuinfoid": {
|
||||
"ROW_mtuinfoid": {
|
||||
"vlanshowinfo-vlanid": 1,
|
||||
"vlanshowinfo-media-type": "enet",
|
||||
"vlanshowinfo-vlanmode": "ce-vlan"
|
||||
}
|
||||
},
|
||||
"vlanshowrspan-vlantype": "notrspan",
|
||||
"is-vtp-manageable": "enabled"
|
||||
}
|
||||
@@ -42,10 +42,16 @@ class TestNxosVlanModule(TestNxosModule):
|
||||
self.mock_get_config = patch('ansible.modules.network.nxos.nxos_vlan.get_config')
|
||||
self.get_config = self.mock_get_config.start()
|
||||
|
||||
self.mock_get_capabilities = patch('ansible.modules.network.nxos.nxos_vlan.get_capabilities')
|
||||
self.get_capabilities = self.mock_get_capabilities.start()
|
||||
self.get_capabilities.return_value = {'network_api': 'cliconf'}
|
||||
|
||||
def tearDown(self):
|
||||
super(TestNxosVlanModule, self).tearDown()
|
||||
self.mock_run_commands.stop()
|
||||
self.mock_load_config.stop()
|
||||
self.mock_get_config.stop()
|
||||
self.mock_get_capabilities.stop()
|
||||
|
||||
def load_fixtures(self, commands=None, device=''):
|
||||
def load_from_file(*args, **kwargs):
|
||||
@@ -64,11 +70,11 @@ class TestNxosVlanModule(TestNxosModule):
|
||||
|
||||
self.run_commands.side_effect = load_from_file
|
||||
self.load_config.return_value = None
|
||||
self.get_config.return_value = load_fixture('nxos_vlan', 'config.cfg')
|
||||
|
||||
def test_nxos_vlan_range(self):
|
||||
set_module_args(dict(vlan_range='6-10'))
|
||||
result = self.execute_module(changed=True)
|
||||
self.assertEqual(result['commands'], ['vlan 6', 'vlan 7', 'vlan 8', 'vlan 9', 'vlan 10'])
|
||||
self.execute_module(changed=True, commands=['vlan 6', 'vlan 7', 'vlan 8', 'vlan 9', 'vlan 10'])
|
||||
|
||||
def test_nxos_vlan_range_absent(self):
|
||||
set_module_args(dict(vlan_range='1-5', state='absent'))
|
||||
@@ -78,7 +84,7 @@ class TestNxosVlanModule(TestNxosModule):
|
||||
def test_nxos_vlan_id(self):
|
||||
set_module_args(dict(vlan_id='15', state='present'))
|
||||
result = self.execute_module(changed=True)
|
||||
self.assertEqual(result['commands'], ['vlan 15', 'exit'])
|
||||
self.assertEqual(result['commands'], ['vlan 15', 'state active', 'no shutdown', 'exit'])
|
||||
|
||||
def test_nxos_vlan_id_absent(self):
|
||||
set_module_args(dict(vlan_id='1', state='absent'))
|
||||
@@ -88,7 +94,7 @@ class TestNxosVlanModule(TestNxosModule):
|
||||
def test_nxos_vlan_named_vlan(self):
|
||||
set_module_args(dict(vlan_id='15', name='WEB'))
|
||||
result = self.execute_module(changed=True)
|
||||
self.assertEqual(result['commands'], ['vlan 15', 'name WEB', 'exit'])
|
||||
self.assertEqual(result['commands'], ['vlan 15', 'name WEB', 'state active', 'no shutdown', 'exit'])
|
||||
|
||||
def test_nxos_vlan_shut_down(self):
|
||||
set_module_args(dict(vlan_id='1', admin_state='down'))
|
||||
|
||||
Reference in New Issue
Block a user