mirror of
https://github.com/ansible-collections/community.general.git
synced 2026-05-07 05:42:50 +00:00
Refactoring of cnos_interface module like what followed by other vendors (#49927)
* Refactoring of cnos_interface module like what followed by other vendors * To remove cnos-interface from E326 validation ignore list * Effect of default parameters impacted UT
This commit is contained in:
committed by
Nathaniel Case
parent
1829a72885
commit
eab3b02cb3
@@ -227,6 +227,9 @@ interface Ethernet1/42
|
||||
interface Ethernet1/43
|
||||
!
|
||||
interface Ethernet1/44
|
||||
ip address 6.7.8.9 255.255.255.0
|
||||
description test string
|
||||
shutdown
|
||||
!
|
||||
interface Ethernet1/45
|
||||
!
|
||||
|
||||
@@ -1,96 +0,0 @@
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
Ethernet PVID Type Mode Status Reason Speed Port
|
||||
Interface NVLAN Ch#
|
||||
--------------------------------------------------------------------------------
|
||||
Ethernet1/1 33 eth access down Link not connected 10000 33
|
||||
Ethernet1/2 1 eth access down Link not connected 10000 1001
|
||||
Ethernet1/3 1 eth trunk down Link not connected 10000 1003
|
||||
Ethernet1/4 1 eth trunk down Link not connected 10000 1004
|
||||
Ethernet1/5 -- eth routed down Link not connected 10000 --
|
||||
Ethernet1/6 -- eth routed down Link not connected 10000 --
|
||||
Ethernet1/7 -- eth routed down Link not connected 10000 --
|
||||
Ethernet1/8 -- eth routed down Link not connected 10000 --
|
||||
Ethernet1/9 1 eth access down Link not connected 10000 --
|
||||
Ethernet1/10 1 eth access down Link not connected 10000 --
|
||||
Ethernet1/11 -- eth routed down Link not connected 10000 --
|
||||
Ethernet1/12 -- eth routed down Link not connected 10000 --
|
||||
Ethernet1/13 -- eth routed down Link not connected 10000 --
|
||||
Ethernet1/14 1 eth access down Link not connected 10000 --
|
||||
Ethernet1/15 1 eth access down Link not connected 10000 --
|
||||
Ethernet1/16 1 eth access down Link not connected 10000 --
|
||||
Ethernet1/17 1 eth access down Link not connected 10000 --
|
||||
Ethernet1/18 1 eth access down Link not connected 10000 --
|
||||
Ethernet1/19 1 eth access down Link not connected 10000 --
|
||||
Ethernet1/20 1 eth access down Link not connected 10000 --
|
||||
Ethernet1/21 1 eth access down Link not connected 10000 --
|
||||
Ethernet1/22 1 eth access down Link not connected 10000 --
|
||||
Ethernet1/23 1 eth access down Link not connected 10000 11
|
||||
Ethernet1/24 1 eth access down Link not connected 10000 --
|
||||
Ethernet1/25 1 eth access down Link not connected 10000 --
|
||||
Ethernet1/26 1 eth access down Link not connected 10000 --
|
||||
Ethernet1/27 1 eth access down Link not connected 10000 --
|
||||
Ethernet1/28 1 eth access down Link not connected 10000 --
|
||||
Ethernet1/29 1 eth access down Link not connected 10000 --
|
||||
Ethernet1/30 1 eth access down Link not connected 10000 --
|
||||
Ethernet1/31 1 eth access down Link not connected 10000 --
|
||||
Ethernet1/32 1 eth access down Link not connected 10000 --
|
||||
Ethernet1/33 -- eth routed down Link not connected 10000 --
|
||||
Ethernet1/34 1 eth access down Link not connected 10000 --
|
||||
Ethernet1/35 1 eth access down Link not connected 10000 --
|
||||
Ethernet1/36 1 eth access down Link not connected 10000 --
|
||||
Ethernet1/37 1 eth access down Link not connected 10000 --
|
||||
Ethernet1/38 1 eth access down Link not connected 10000 --
|
||||
Ethernet1/39 1 eth access down Link not connected 10000 --
|
||||
Ethernet1/40 1 eth access down Link not connected 10000 --
|
||||
Ethernet1/41 1 eth access down Link not connected 10000 --
|
||||
Ethernet1/42 1 eth access down Link not connected 10000 --
|
||||
Ethernet1/43 1 eth access down Link not connected 10000 --
|
||||
Ethernet1/44 1 eth access down Link not connected 10000 --
|
||||
Ethernet1/45 1 eth access down Link not connected 10000 --
|
||||
Ethernet1/46 1 eth access down Link not connected 10000 --
|
||||
Ethernet1/47 1 eth access down Link not connected 10000 --
|
||||
Ethernet1/48 1 eth access down Link not connected 10000 --
|
||||
Ethernet1/49 1 eth access down Link not connected 40000 --
|
||||
Ethernet1/50 1 eth access down Link not connected 40000 --
|
||||
Ethernet1/51 1 eth access down Link not connected 40000 --
|
||||
Ethernet1/52 1 eth access down Link not connected 40000 --
|
||||
Ethernet1/53 1 eth access down Link not connected 40000 --
|
||||
Ethernet1/54 1 eth access down Link not connected 40000 --
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
Port-channel PVID Type Mode Status Reason Speed Protocol
|
||||
Interface NVLAN
|
||||
--------------------------------------------------------------------------------
|
||||
po1 1 eth access down No link up members NA none
|
||||
po2 1 eth access down No link up members NA none
|
||||
po11 1 eth access down No link up members NA lacp
|
||||
po12 1 eth access down No link up members NA none
|
||||
po13 1 eth trunk down No link up members NA none
|
||||
po14 1 eth access down No link up members NA none
|
||||
po15 1 eth access down No link up members NA none
|
||||
po17 1 eth trunk down No link up members NA none
|
||||
po20 1 eth access down No link up members NA none
|
||||
po33 33 eth access down No link up members NA none
|
||||
po100 1 eth trunk down No link up members NA none
|
||||
po1001 1 eth access down No link up members NA lacp
|
||||
po1002 1 eth access down No link up members NA none
|
||||
po1003 1 eth trunk down No link up members NA lacp
|
||||
po1004 1 eth trunk down No link up members NA lacp
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
Port VRF Status IP Address Speed MTU
|
||||
--------------------------------------------------------------------------------
|
||||
mgmt0 management up 10.241.107.39 1000 1500
|
||||
|
||||
-------------------------------------------------------------------------------
|
||||
Interface Secondary VLAN(Type) Status Reason
|
||||
-------------------------------------------------------------------------------
|
||||
Vlan1 -- down VLAN is down
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
Interface Status Description
|
||||
--------------------------------------------------------------------------------
|
||||
loopback0 up --
|
||||
loopback3 up --
|
||||
|
||||
@@ -1,84 +0,0 @@
|
||||
from __future__ import (absolute_import, division, print_function)
|
||||
__metaclass__ = type
|
||||
|
||||
import json
|
||||
import os
|
||||
from units.compat.mock import patch
|
||||
from ansible.modules.network.cnos import cnos_interface
|
||||
from units.modules.utils import set_module_args
|
||||
from .cnos_module import TestCnosModule, load_fixture
|
||||
|
||||
|
||||
class TestCnosEthernetModule(TestCnosModule):
|
||||
|
||||
module = cnos_interface
|
||||
|
||||
def setUp(self):
|
||||
super(TestCnosEthernetModule, self).setUp()
|
||||
|
||||
self.mock_run_cnos_commands = patch('ansible.module_utils.network.cnos.cnos.run_cnos_commands')
|
||||
self.run_cnos_commands = self.mock_run_cnos_commands.start()
|
||||
|
||||
def tearDown(self):
|
||||
super(TestCnosEthernetModule, self).tearDown()
|
||||
self.mock_run_cnos_commands.stop()
|
||||
|
||||
def load_fixtures(self, commands=None, transport='cli'):
|
||||
self.run_cnos_commands.return_value = [load_fixture('cnos_ethernet_config.cfg')]
|
||||
|
||||
def test_ethernet_channelgroup(self):
|
||||
set_module_args({'username': 'admin', 'password': 'pass',
|
||||
'host': '10.241.107.39', 'deviceType': 'g8272_cnos',
|
||||
'outputfile': self.test_log, 'interfaceOption': 'ethernet', 'interfaceRange': '33',
|
||||
'interfaceArg1': 'channel-group', 'interfaceArg2': '33', 'interfaceArg3': 'on'})
|
||||
result = self.execute_module(changed=True)
|
||||
expected_result = 'Interface Configuration is Accomplished'
|
||||
self.assertEqual(result['msg'], expected_result)
|
||||
|
||||
def test_cnos_ethernet_lacp(self):
|
||||
set_module_args({'username': 'admin', 'password': 'pass',
|
||||
'host': '10.241.107.39', 'deviceType': 'g8272_cnos',
|
||||
'outputfile': self.test_log, 'interfaceOption': 'ethernet', 'interfaceRange': '33',
|
||||
'interfaceArg1': 'lacp', 'interfaceArg2': 'port-priority', 'interfaceArg3': '33'})
|
||||
result = self.execute_module(changed=True)
|
||||
expected_result = 'Interface Configuration is Accomplished'
|
||||
self.assertEqual(result['msg'], expected_result)
|
||||
|
||||
def test_cnos_ethernet_duplex(self):
|
||||
set_module_args({'username': 'admin', 'password': 'pass',
|
||||
'host': '10.241.107.39', 'deviceType': 'g8272_cnos',
|
||||
'outputfile': self.test_log, 'interfaceOption': 'ethernet', 'interfaceRange': '33',
|
||||
'interfaceArg1': 'duplex', 'interfaceArg2': 'auto'})
|
||||
result = self.execute_module(changed=True)
|
||||
expected_result = 'Interface Configuration is Accomplished'
|
||||
self.assertEqual(result['msg'], expected_result)
|
||||
|
||||
def test_cnos_ethernet_mtu(self):
|
||||
set_module_args({'username': 'admin', 'password': 'pass',
|
||||
'host': '10.241.107.39', 'deviceType': 'g8272_cnos',
|
||||
'outputfile': self.test_log, 'interfaceOption': 'ethernet', 'interfaceRange': '33',
|
||||
'interfaceArg1': 'mtu', 'interfaceArg2': '1300'})
|
||||
result = self.execute_module(changed=True)
|
||||
expected_result = 'Interface Configuration is Accomplished'
|
||||
self.assertEqual(result['msg'], expected_result)
|
||||
|
||||
def test_cnos_ethernet_spanningtree(self):
|
||||
set_module_args({'username': 'admin', 'password': 'pass',
|
||||
'host': '10.241.107.39', 'deviceType': 'g8272_cnos',
|
||||
'outputfile': self.test_log, 'interfaceOption': 'ethernet', 'interfaceRange': '33',
|
||||
'interfaceArg1': 'spanning-tree', 'interfaceArg2': 'mst',
|
||||
'interfaceArg3': '33-35', 'interfaceArg4': 'cost',
|
||||
'interfaceArg5': '33'})
|
||||
result = self.execute_module(changed=True)
|
||||
expected_result = 'Interface Configuration is Accomplished'
|
||||
self.assertEqual(result['msg'], expected_result)
|
||||
|
||||
def test_cnos_ethernet_ip(self):
|
||||
set_module_args({'username': 'admin', 'password': 'pass',
|
||||
'host': '10.241.107.39', 'deviceType': 'g8272_cnos',
|
||||
'outputfile': self.test_log, 'interfaceOption': 'ethernet', 'interfaceRange': '33',
|
||||
'interfaceArg1': 'ip', 'interfaceArg2': 'port',
|
||||
'interfaceArg3': 'anil'})
|
||||
result = self.execute_module(changed=True)
|
||||
expected_result = 'Interface Configuration is Accomplished'
|
||||
self.assertEqual(result['msg'], expected_result)
|
||||
146
test/units/modules/network/cnos/test_cnos_interface.py
Normal file
146
test/units/modules/network/cnos/test_cnos_interface.py
Normal file
@@ -0,0 +1,146 @@
|
||||
#
|
||||
# (c) 2018 Red Hat Inc.
|
||||
# Copyright (C) 2017 Lenovo.
|
||||
#
|
||||
# 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/>.
|
||||
#
|
||||
from __future__ import (absolute_import, division, print_function)
|
||||
__metaclass__ = type
|
||||
|
||||
import re
|
||||
import json
|
||||
|
||||
from units.compat.mock import patch
|
||||
from ansible.modules.network.cnos import cnos_interface
|
||||
from units.modules.utils import set_module_args
|
||||
from .cnos_module import TestCnosModule, load_fixture
|
||||
|
||||
|
||||
class TestCnosInterfaceModule(TestCnosModule):
|
||||
module = cnos_interface
|
||||
|
||||
def setUp(self):
|
||||
super(TestCnosInterfaceModule, self).setUp()
|
||||
self._patch_get_config = patch(
|
||||
'ansible.modules.network.cnos.cnos_interface.get_config'
|
||||
)
|
||||
self._patch_load_config = patch(
|
||||
'ansible.modules.network.cnos.cnos_interface.load_config'
|
||||
)
|
||||
self._patch_exec_command = patch(
|
||||
'ansible.modules.network.cnos.cnos_interface.exec_command'
|
||||
)
|
||||
|
||||
self._get_config = self._patch_get_config.start()
|
||||
self._load_config = self._patch_load_config.start()
|
||||
self._exec_command = self._patch_exec_command.start()
|
||||
|
||||
def tearDown(self):
|
||||
super(TestCnosInterfaceModule, self).tearDown()
|
||||
self._patch_get_config.stop()
|
||||
self._patch_load_config.stop()
|
||||
self._patch_exec_command.stop()
|
||||
|
||||
def load_fixtures(self, commands=None):
|
||||
config_file = 'cnos_config_config.cfg'
|
||||
self._get_config.return_value = load_fixture(config_file)
|
||||
self._load_config.return_value = None
|
||||
|
||||
def test_cnos_interface_description(self, *args, **kwargs):
|
||||
set_module_args(dict(
|
||||
name='Ethernet1/2',
|
||||
description='show version'
|
||||
))
|
||||
result = self.execute_module(changed=True)
|
||||
self.assertEqual(
|
||||
result,
|
||||
{
|
||||
'commands': [
|
||||
'interface Ethernet1/2',
|
||||
'description show version',
|
||||
'duplex auto'
|
||||
],
|
||||
'changed': True
|
||||
}
|
||||
)
|
||||
|
||||
def test_cnos_interface_speed(self, *args, **kwargs):
|
||||
set_module_args(dict(
|
||||
name='Ethernet1/2',
|
||||
speed=1000
|
||||
))
|
||||
result = self.execute_module(changed=True)
|
||||
self.assertEqual(
|
||||
result,
|
||||
{
|
||||
'commands': [
|
||||
'interface Ethernet1/2',
|
||||
'speed 1000',
|
||||
'duplex auto'
|
||||
],
|
||||
'changed': True
|
||||
}
|
||||
)
|
||||
|
||||
def test_cnos_interface_mtu(self, *args, **kwargs):
|
||||
set_module_args(dict(
|
||||
name='Ethernet1/2',
|
||||
mtu=1548
|
||||
))
|
||||
result = self.execute_module(changed=True)
|
||||
self.assertEqual(
|
||||
result,
|
||||
{
|
||||
'commands': [
|
||||
'interface Ethernet1/2',
|
||||
'duplex auto',
|
||||
'mtu 1548'
|
||||
],
|
||||
'changed': True
|
||||
}
|
||||
)
|
||||
|
||||
def test_cnos_interface_mtu_out_of_range(self, *args, **kwargs):
|
||||
set_module_args(dict(
|
||||
name='Ethernet0/2',
|
||||
mtu=15000
|
||||
))
|
||||
result = self.execute_module(failed=True)
|
||||
self.assertEqual(
|
||||
result,
|
||||
{
|
||||
'msg': 'mtu must be between 64 and 9216',
|
||||
'failed': True
|
||||
}
|
||||
)
|
||||
|
||||
def test_cnos_interface_enabled(self, *args, **kwargs):
|
||||
set_module_args(dict(
|
||||
name='Ethernet1/44',
|
||||
enabled=True
|
||||
))
|
||||
result = self.execute_module(changed=True)
|
||||
self.assertEqual(
|
||||
result,
|
||||
{
|
||||
'commands': [
|
||||
'interface Ethernet1/44',
|
||||
'duplex auto',
|
||||
'no shutdown'
|
||||
],
|
||||
'changed': True
|
||||
}
|
||||
)
|
||||
Reference in New Issue
Block a user