Lenovo port to persistence 1 (#43194)

* CNOS Vlag module is refactored to use persistence connection instead of paramiko.

* Changing interface and port channel modules to persistent connection and adding UT for them.

* Fixing pep8 issues

* Removing trailing new line

* Removing trailing new line

* Removing trailing new line

* Correcting indentation mistake

* Update cnos_vlag.py

* Removing commented examples

They are commented because those configurations are not meant for L2 ports
This commit is contained in:
Anil Kumar Muraleedharan
2018-07-27 20:17:02 +05:30
committed by Nathaniel Case
parent e24041449e
commit f2c9a6b126
11 changed files with 540 additions and 334 deletions

View File

@@ -0,0 +1,96 @@
--------------------------------------------------------------------------------
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 --

View File

@@ -0,0 +1,25 @@
Flags:
D - Down P - Up in port-channel (members)
S - Switched R - Routed
I - Individual s - Suspended
U - Up (port-channel)
B - standBy (members)
------+----------------+--------+-----------------------------------------------
Group Port-Channel Protocol Member Ports
------+----------------+--------+-----------------------------------------------
1 po1 (SD) NONE
2 po2 (SD) NONE
11 po11 (SD) LACP Ethernet1/23(D)
12 po12 (SD) NONE
13 po13 (SD) NONE
14 po14 (SD) NONE
15 po15 (SD) NONE
17 po17 (SD) NONE
20 po20 (SD) NONE
33 po33 (SD) NONE Ethernet1/1(D)
100 po100 (SD) NONE
1001 po1001 (SD) LACP Ethernet1/2(D)
1002 po1002 (SD) NONE
1003 po1003 (SD) LACP Ethernet1/3(D)
1004 po1004 (SD) LACP Ethernet1/4(D)

View File

@@ -0,0 +1,63 @@
Global State : enabled
VRRP active/active mode : enabled
vLAG system MAC : 08:17:f4:c3:de:38
ISL Information:
PCH Ifindex State Previous State
-------+-----------+-----------+---------------------------------
33 100033 Down Down
Mis-Match Information:
Local Peer
-------------+---------------------------+-----------------------
Match Result : Mis-match Mis-match
Tier ID : 313 0
System Type : G8272
OS Version : 10.8.x.x 0.0.x.x
Role Information:
Local Peer
-------------+---------------------------+-----------------------
Admin Role : Primary Unselected
Oper Role : Primary Unselected
Priority : 1313 0
System MAC : a4:8c:db:33:bc:01 00:00:00:00:00:00
Consistency Checking Information:
State : enabled
Strict Mode : enabled
Final Result : pass
FDB refresh Information:
FDB is doing refresh with below setting:
FDB refresh is configured
Bridge FDB aging timer is 1800 second(s)
FDB synchronization Information:
FDB is NOT being synchronized.
Auto Recovery Interval 266s (Finished)
Startup Delay Interval 323s (Finished)
Health Check Information:
Health check Peer IP Address: 1.2.3.4
Health check Local IP Address: 0.0.0.0
Health check retry interval: 133 seconds
Health check number of keepalive attempts: 13
Health check keepalive interval: 131 seconds
Health check status: DOWN
Peer Gateway State : enabled
VLAG instance 1 : enabled
Instance Information
PCH ifindex State Previous State Cons Res
----------+-----------+--------------+-----------------+--------
1003 101003 Down Down pass
VLAG instance 33 : enabled
Instance Information
PCH ifindex State Previous State Cons Res
----------+-----------+--------------+-----------------+--------
333 0 Down Down pass

View File

@@ -0,0 +1,86 @@
from __future__ import (absolute_import, division, print_function)
__metaclass__ = type
import json
from ansible.compat.tests.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': 'test.log', 'interfaceOption': 'ethernet', 'interfaceRange': '33',
'interfaceArg1': 'channel-group', 'interfaceArg2': '33', 'interfaceArg3': 'on'})
result = self.execute_module(changed=True)
file = open('Anil.txt', "a")
file.write(str(result))
file.close()
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': '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': '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': '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': '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': '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)

View File

@@ -0,0 +1,86 @@
from __future__ import (absolute_import, division, print_function)
__metaclass__ = type
import json
from ansible.compat.tests.mock import patch
from ansible.modules.network.cnos import cnos_portchannel
from units.modules.utils import set_module_args
from .cnos_module import TestCnosModule, load_fixture
class TestCnosPortchannelModule(TestCnosModule):
module = cnos_portchannel
def setUp(self):
super(TestCnosPortchannelModule, 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(TestCnosPortchannelModule, 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_portchannel_config.cfg')]
def test_portchannel_channelgroup(self):
set_module_args({'username': 'admin', 'password': 'pass',
'host': '10.241.107.39', 'deviceType': 'g8272_cnos',
'outputfile': 'test.log', 'interfaceRange': '33',
'interfaceArg1': 'channel-group', 'interfaceArg2': '33', 'interfaceArg3': 'on'})
result = self.execute_module(changed=True)
file = open('Anil.txt', "a")
file.write(str(result))
file.close()
expected_result = 'Port Channel Configuration is done'
self.assertEqual(result['msg'], expected_result)
def test_cnos_portchannel_lacp(self):
set_module_args({'username': 'admin', 'password': 'pass',
'host': '10.241.107.39', 'deviceType': 'g8272_cnos',
'outputfile': 'test.log', 'interfaceRange': '33',
'interfaceArg1': 'lacp', 'interfaceArg2': 'port-priority', 'interfaceArg3': '33'})
result = self.execute_module(changed=True)
expected_result = 'Port Channel Configuration is done'
self.assertEqual(result['msg'], expected_result)
def test_cnos_portchannel_duplex(self):
set_module_args({'username': 'admin', 'password': 'pass',
'host': '10.241.107.39', 'deviceType': 'g8272_cnos',
'outputfile': 'test.log', 'interfaceRange': '2',
'interfaceArg1': 'duplex', 'interfaceArg2': 'auto'})
result = self.execute_module(changed=True)
expected_result = 'Port Channel Configuration is done'
self.assertEqual(result['msg'], expected_result)
def test_cnos_portchannel_mtu(self):
set_module_args({'username': 'admin', 'password': 'pass',
'host': '10.241.107.39', 'deviceType': 'g8272_cnos',
'outputfile': 'test.log', 'interfaceRange': '33',
'interfaceArg1': 'mtu', 'interfaceArg2': '1300'})
result = self.execute_module(changed=True)
expected_result = 'Port Channel Configuration is done'
self.assertEqual(result['msg'], expected_result)
def test_cnos_portchannel_spanningtree(self):
set_module_args({'username': 'admin', 'password': 'pass',
'host': '10.241.107.39', 'deviceType': 'g8272_cnos',
'outputfile': 'test.log', 'interfaceRange': '33',
'interfaceArg1': 'spanning-tree', 'interfaceArg2': 'mst',
'interfaceArg3': '33-35', 'interfaceArg4': 'cost',
'interfaceArg5': '33'})
result = self.execute_module(changed=True)
expected_result = 'Port Channel Configuration is done'
self.assertEqual(result['msg'], expected_result)
def test_cnos_portchannel_ip(self):
set_module_args({'username': 'admin', 'password': 'pass',
'host': '10.241.107.39', 'deviceType': 'g8272_cnos',
'outputfile': 'test.log', 'interfaceRange': '33',
'interfaceArg1': 'ip', 'interfaceArg2': 'port',
'interfaceArg3': 'anil'})
result = self.execute_module(changed=True)
expected_result = 'Port Channel Configuration is done'
self.assertEqual(result['msg'], expected_result)

View File

@@ -0,0 +1,55 @@
from __future__ import (absolute_import, division, print_function)
__metaclass__ = type
import json
from ansible.compat.tests.mock import patch
from ansible.modules.network.cnos import cnos_vlag
from units.modules.utils import set_module_args
from .cnos_module import TestCnosModule, load_fixture
class TestCnosVlagModule(TestCnosModule):
module = cnos_vlag
def setUp(self):
super(TestCnosVlagModule, 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(TestCnosVlagModule, 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_vlag_config.cfg')]
def test_cnos_vlag_enable(self):
set_module_args({'username': 'admin', 'password': 'admin',
'host': '10.241.107.39', 'deviceType': 'g8272_cnos',
'outputfile': 'test.log', 'vlagArg1': 'enable'})
result = self.execute_module(changed=True)
file = open('Anil.txt', "a")
file.write(str(result))
file.close()
expected_result = 'VLAG configurations accomplished'
self.assertEqual(result['msg'], expected_result)
def test_cnos_vlag_instance(self):
set_module_args({'username': 'admin', 'password': 'pass',
'host': '10.241.107.39', 'deviceType': 'g8272_cnos',
'outputfile': 'test.log', 'vlagArg1': 'instance',
'vlagArg2': '33', 'vlagArg3': '333'})
result = self.execute_module(changed=True)
expected_result = 'VLAG configurations accomplished'
self.assertEqual(result['msg'], expected_result)
def test_cnos_vlag_hlthchk(self):
set_module_args({'username': 'admin', 'password': 'pass',
'host': '10.241.107.39', 'deviceType': 'g8272_cnos',
'outputfile': 'test.log', 'vlagArg1': 'hlthchk',
'vlagArg2': 'keepalive-interval', 'vlagArg3': '131'})
result = self.execute_module(changed=True)
expected_result = 'VLAG configurations accomplished'
self.assertEqual(result['msg'], expected_result)