Modifying cnos-facts, cnos_command and cnos-config in line with the design followed in Ansible. Adding unit test cases for these modules. Added plugins to support them. (#39955)

* Modifying cnos-facts, cnos_command and cnos-config in line with the design followed in Ansible. Adding unit test cases for these modules. Added plugins to support them.

* Removing doc fragment conflicts with other modules

* Replacing show with display
This commit is contained in:
Anil Kumar Muraleedharan
2018-05-17 19:36:24 +05:30
committed by Nathaniel Case
parent 30f992f260
commit 1cb4619c9a
27 changed files with 3395 additions and 216 deletions

View File

@@ -880,7 +880,6 @@ lib/ansible/modules/network/cnos/cnos_backup.py E322
lib/ansible/modules/network/cnos/cnos_backup.py E323
lib/ansible/modules/network/cnos/cnos_backup.py E326
lib/ansible/modules/network/cnos/cnos_bgp.py E326
lib/ansible/modules/network/cnos/cnos_command.py E326
lib/ansible/modules/network/cnos/cnos_conditional_command.py E326
lib/ansible/modules/network/cnos/cnos_conditional_template.py E326
lib/ansible/modules/network/cnos/cnos_factory.py E326

View File

@@ -0,0 +1,117 @@
# Copyright (C) 2017 Lenovo, 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
import os
import json
from ansible.compat.tests import unittest
from ansible.compat.tests.mock import patch
from ansible.module_utils import basic
from ansible.module_utils._text import to_bytes
def set_module_args(args):
args = json.dumps({'ANSIBLE_MODULE_ARGS': args})
basic._ANSIBLE_ARGS = to_bytes(args)
fixture_path = os.path.join(os.path.dirname(__file__), 'fixtures')
fixture_data = {}
def load_fixture(name):
path = os.path.join(fixture_path, name)
if path in fixture_data:
return fixture_data[path]
with open(path) as f:
data = f.read()
try:
data = json.loads(data)
except:
pass
fixture_data[path] = data
return data
class AnsibleExitJson(Exception):
pass
class AnsibleFailJson(Exception):
pass
class TestCnosModule(unittest.TestCase):
def execute_module(self, failed=False, changed=False, commands=None,
sort=True, defaults=False):
self.load_fixtures(commands)
if failed:
result = self.failed()
self.assertTrue(result['failed'], result)
else:
result = self.changed(changed)
self.assertEqual(result['changed'], changed, result)
if commands is not None:
if sort:
self.assertEqual(sorted(commands), sorted(result['commands']),
result['commands'])
else:
self.assertEqual(commands, result['commands'],
result['commands'])
return result
def failed(self):
def fail_json(*args, **kwargs):
kwargs['failed'] = True
raise AnsibleFailJson(kwargs)
with patch.object(basic.AnsibleModule, 'fail_json', fail_json):
with self.assertRaises(AnsibleFailJson) as exc:
self.module.main()
result = exc.exception.args[0]
self.assertTrue(result['failed'], result)
return result
def changed(self, changed=False):
def exit_json(*args, **kwargs):
if 'changed' not in kwargs:
kwargs['changed'] = False
raise AnsibleExitJson(kwargs)
with patch.object(basic.AnsibleModule, 'exit_json', exit_json):
with self.assertRaises(AnsibleExitJson) as exc:
self.module.main()
result = exc.exception.args[0]
self.assertEqual(result['changed'], changed, result)
return result
def load_fixtures(self, commands=None):
pass

View File

@@ -0,0 +1,334 @@
!
version "10.8.0.42"
!
hostname ip10-241-107-39
!
banner motd NMS India CNOS
banner motd NMS India CNOS G8272
!
clock timezone EDT 0 0
!
logging console 7
vrf context management
ip route 0.0.0.0/0 10.241.107.1
!
!
port-channel load-balance ethernet destination-mac
port-channel load-balance ethernet source-interface
feature telnet
ip domain-name labs.lenovo.com vrf management
ip domain-list labs.lenovo.com vrf management
ip name-server 10.241.104.120 vrf management
ip name-server 10.240.0.10 vrf management
ip host ip10-241-107-39.labs.lenovo.com 10.241.107.39 vrf management
ip host ip10-241-107-39 10.241.107.39 vrf management
ip domain-name labs.lenovo.com vrf default
ip domain-list labs.lenovo.com vrf default
ip name-server 10.240.0.10 vrf default
ip name-server 10.241.104.120 vrf default
ip host ip10-241-107-39.labs.lenovo.com 10.241.107.39 vrf default
ip host ip10-241-107-39 10.241.107.39 vrf default
ntp server 173.230.154.254 prefer
ntp server 97.127.86.33 prefer
ntp server 129.250.35.250 prefer
ntp server 174.136.103.130 prefer
ntp server 69.10.161.7 prefer
ntp server 96.226.123.196 prefer
ntp server 104.238.179.130 prefer
ntp server 108.61.73.244 prefer
ntp server 208.75.89.4 prefer
snmp-server community public group network-operator
snmp-server community private group network-admin
snmp-server contact Ralph
username admin role network-admin password encrypted $6$bJoWyEu/$9pzSgFPAKGRm1stpTCEl3I39htbjxiFCfhqiHag1NQiKHv/IiLQ2lYW0V3p7p72SgSmVHp38em9P9R/EdePpk/
logging server 10.241.107.231
logging server 10.241.107.222
feature restApi
ovsdb pki ovsdb_mgmt vrf management
ovsdb pki ovsdb_default vrf default
lacp system-priority 32769
vlag tier-id 313
vlag priority 1313
vlag isl port-channel 100
vlag hlthchk keepalive-attempts 5
vlag hlthchk peer-ip 1.2.3.4
vlag auto-recovery 266
vlag startup-delay 323
vlag enable
vlag instance 1 port-channel 1003
vlag instance 1 enable
vlag instance 2 port-channel 20
vlag instance 2 enable
vlag instance 12 port-channel 23
vlag instance 33 port-channel 333
vlag instance 33 enable
spanning-tree mode mst
telemetry heartbeat enabled interval 15
!
policy-map type control-plane copp-system-policy
class type control-plane copp-s-pvst-bpdu
police pps 500
class type control-plane copp-s-ecp
police pps 3000
class type control-plane copp-s-igmp
police pps 3000
!
vlan 1-2
no flood ipv4
!
vlan 3
!
vlan 5
!
vlan 12
!
vlan 13
name dave
!
vlan dot1q tag native egress-only
!
interface Ethernet1/1
description Link 1 to LP21
load-interval counter 2 33
switchport access vlan 33
storm-control broadcast level 12.50
mtu 66
channel-group 33 mode on
!
interface Ethernet1/2
description Link 2 to LP21
channel-group 1001 mode active
!
interface Ethernet1/3
description Link 1 to LP22
switchport mode trunk
channel-group 1003 mode active
!
interface Ethernet1/4
description Link 2 to LP22
switchport mode trunk
channel-group 1004 mode active
!
interface Ethernet1/5
description Link 1 to LP23
no switchport
ip address 20.131.1.1/30
!
interface Ethernet1/6
description Link 2 to LP23
no switchport
ip address 20.131.2.1/30
!
interface Ethernet1/7
description Link 1 to LP24
no switchport
ip address 20.141.1.1/30
!
interface Ethernet1/8
description Link 2 to LP24
no switchport
ip address 20.141.2.1/30
!
interface Ethernet1/9
!
interface Ethernet1/10
!
interface Ethernet1/11
no switchport
mtu 1402
ip address 1.1.1.2/8
!
!
interface Ethernet1/12
ip address 100.10.10.10/24
mtu 1402
no switchport
!
interface Ethernet1/13
description test string
no switchport
ip address 10.241.107.54/24
vrrp 254
address 10.241.107.55
priority 254
no shutdown
ip arp timeout 1500
!
interface Ethernet1/14
!
interface Ethernet1/15
!
interface Ethernet1/16
!
interface Ethernet1/17
!
interface Ethernet1/18
!
interface Ethernet1/19
!
interface Ethernet1/20
!
interface Ethernet1/21
!
interface Ethernet1/22
!
interface Ethernet1/23
channel-group 11 mode active
lacp port-priority 32769
!
interface Ethernet1/24
!
interface Ethernet1/25
!
interface Ethernet1/26
!
interface Ethernet1/27
!
interface Ethernet1/28
!
interface Ethernet1/29
!
interface Ethernet1/30
!
interface Ethernet1/31
!
interface Ethernet1/32
!
interface Ethernet1/33
description Hentammoo
load-interval counter 2 33
switchport access vlan 33
storm-control broadcast level 12.50
mtu 66
microburst-detection enable threshold 25
lldp tlv-select max-frame-size
lacp port-priority 33
spanning-tree mst 33-35 cost 33
spanning-tree bpduguard enable
!
interface Ethernet1/34
!
interface Ethernet1/35
!
interface Ethernet1/36
!
interface Ethernet1/37
!
interface Ethernet1/38
!
interface Ethernet1/39
!
interface Ethernet1/40
!
interface Ethernet1/41
!
interface Ethernet1/42
!
interface Ethernet1/43
!
interface Ethernet1/44
!
interface Ethernet1/45
!
interface Ethernet1/46
!
interface Ethernet1/47
!
interface Ethernet1/48
!
interface Ethernet1/49
!
interface Ethernet1/50
!
interface Ethernet1/51
!
interface Ethernet1/52
!
interface Ethernet1/53
!
interface Ethernet1/54
!
interface loopback0
no switchport
!
interface mgmt0
no switchport
vrf member management
no ip address dhcp
ip address 10.241.107.39/24
no ipv6 address dhcp
!
interface Vlan1
no switchport
!
interface port-channel1
!
interface port-channel2
!
interface port-channel11
lacp min-links 2
!
interface port-channel13
switchport mode trunk
!
interface port-channel17
switchport mode trunk
!
interface port-channel20
!
interface port-channel33
description Hentammoo
load-interval counter 2 33
switchport access vlan 33
storm-control broadcast level 12.50
mtu 66
spanning-tree mst 33-35 cost 33
spanning-tree bpduguard enable
!
interface port-channel100
switchport mode trunk
!
interface port-channel1001
!
interface port-channel1002
!
interface port-channel1003
switchport mode trunk
!
interface port-channel1004
switchport mode trunk
!
router bgp 33
router-id 1.2.3.4
bestpath always-compare-med
cluster-id 1.2.3.4
confederation identifier 333
enforce-first-as
bgp as-local-count 33
bestpath compare-confed-aspath
maxas-limit 333
graceful-restart-helper
graceful-restart stalepath-time 333
timers bgp 333 3333
address-family ipv4 unicast
synchronization
network 0.0.0.0 backdoor
dampening 13 233 333 15 33
neighbor 10.241.107.40 remote-as 13
bfd
address-family ipv4 unicast
next-hop-self
!
route-map anil permit 10
!
ip arp timeout 1000
!
line con 0
line vty 0
exec-timeout 90 0
line vty 1 39
!
!
!
end

View File

@@ -0,0 +1,6 @@
!
hostname foo
!
interface ethernet 1/13
speed 10000
!

View File

@@ -0,0 +1,92 @@
--------------------------------------------------------------------------------
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 33 eth access 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
po13 1 eth trunk 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,72 @@
--------------------------------------------------------------------------------
Interface Mac-Address Burn-in Mac-Address
--------------------------------------------------------------------------------
Ethernet1/1 a48c.db33.bc02 a48c.db33.bc02
Ethernet1/2 a48c.db33.bc03 a48c.db33.bc03
Ethernet1/3 a48c.db33.bc04 a48c.db33.bc04
Ethernet1/4 a48c.db33.bc05 a48c.db33.bc05
Ethernet1/5 a48c.db33.bc01 a48c.db33.bc06
Ethernet1/6 a48c.db33.bc01 a48c.db33.bc07
Ethernet1/7 a48c.db33.bc01 a48c.db33.bc08
Ethernet1/8 a48c.db33.bc01 a48c.db33.bc09
Ethernet1/9 a48c.db33.bc0a a48c.db33.bc0a
Ethernet1/10 a48c.db33.bc0b a48c.db33.bc0b
Ethernet1/11 a48c.db33.bc01 a48c.db33.bc0c
Ethernet1/12 a48c.db33.bc01 a48c.db33.bc0d
Ethernet1/13 a48c.db33.bc01 a48c.db33.bc0e
Ethernet1/14 a48c.db33.bc0f a48c.db33.bc0f
Ethernet1/15 a48c.db33.bc10 a48c.db33.bc10
Ethernet1/16 a48c.db33.bc11 a48c.db33.bc11
Ethernet1/17 a48c.db33.bc12 a48c.db33.bc12
Ethernet1/18 a48c.db33.bc13 a48c.db33.bc13
Ethernet1/19 a48c.db33.bc14 a48c.db33.bc14
Ethernet1/20 a48c.db33.bc15 a48c.db33.bc15
Ethernet1/21 a48c.db33.bc16 a48c.db33.bc16
Ethernet1/22 a48c.db33.bc17 a48c.db33.bc17
Ethernet1/23 a48c.db33.bc18 a48c.db33.bc18
Ethernet1/24 a48c.db33.bc19 a48c.db33.bc19
Ethernet1/25 a48c.db33.bc1a a48c.db33.bc1a
Ethernet1/26 a48c.db33.bc1b a48c.db33.bc1b
Ethernet1/27 a48c.db33.bc1c a48c.db33.bc1c
Ethernet1/28 a48c.db33.bc1d a48c.db33.bc1d
Ethernet1/29 a48c.db33.bc1e a48c.db33.bc1e
Ethernet1/30 a48c.db33.bc1f a48c.db33.bc1f
Ethernet1/31 a48c.db33.bc20 a48c.db33.bc20
Ethernet1/32 a48c.db33.bc21 a48c.db33.bc21
Ethernet1/33 a48c.db33.bc22 a48c.db33.bc22
Ethernet1/34 a48c.db33.bc23 a48c.db33.bc23
Ethernet1/35 a48c.db33.bc24 a48c.db33.bc24
Ethernet1/36 a48c.db33.bc25 a48c.db33.bc25
Ethernet1/37 a48c.db33.bc26 a48c.db33.bc26
Ethernet1/38 a48c.db33.bc27 a48c.db33.bc27
Ethernet1/39 a48c.db33.bc28 a48c.db33.bc28
Ethernet1/40 a48c.db33.bc29 a48c.db33.bc29
Ethernet1/41 a48c.db33.bc2a a48c.db33.bc2a
Ethernet1/42 a48c.db33.bc2b a48c.db33.bc2b
Ethernet1/43 a48c.db33.bc2c a48c.db33.bc2c
Ethernet1/44 a48c.db33.bc2d a48c.db33.bc2d
Ethernet1/45 a48c.db33.bc2e a48c.db33.bc2e
Ethernet1/46 a48c.db33.bc2f a48c.db33.bc2f
Ethernet1/47 a48c.db33.bc30 a48c.db33.bc30
Ethernet1/48 a48c.db33.bc31 a48c.db33.bc31
Ethernet1/49 a48c.db33.bc32 a48c.db33.bc32
Ethernet1/50 a48c.db33.bc33 a48c.db33.bc33
Ethernet1/51 a48c.db33.bc34 a48c.db33.bc34
Ethernet1/52 a48c.db33.bc35 a48c.db33.bc35
Ethernet1/53 a48c.db33.bc36 a48c.db33.bc36
Ethernet1/54 a48c.db33.bc37 a48c.db33.bc37
mgmt0 a48c.db33.bc00 a48c.db33.bc00
po1 0e00.0000.0001 (not set)
po2 0e00.0000.0002 (not set)
po11 a48c.db33.bc18 (not set)
po13 0e00.0000.0003 (not set)
po17 0e00.0000.0004 (not set)
po20 0e00.0000.0005 (not set)
po33 a48c.db33.bc02 (not set)
po100 0e00.0000.0006 (not set)
po1001 a48c.db33.bc03 (not set)
po1002 0e00.0000.0007 (not set)
po1003 a48c.db33.bc04 (not set)
po1004 a48c.db33.bc05 (not set)
Vlan1 a48c.db33.bc01 (not set)

View File

@@ -0,0 +1,74 @@
--------------------------------------------------------------------------------
Port Name Status Vlan Duplex Speed Type
--------------------------------------------------------------------------------
Ethernet1/1 Link 1 to LP21 notconnec 33 full 10000 eth
Ethernet1/2 Link 2 to LP21 notconnec 1 full 10000 eth
Ethernet1/3 Link 1 to LP22 notconnec trunk full 10000 eth
Ethernet1/4 Link 2 to LP22 notconnec trunk full 10000 eth
Ethernet1/5 Link 1 to LP23 notconnec routed full 10000 eth
Ethernet1/6 Link 2 to LP23 notconnec routed full 10000 eth
Ethernet1/7 Link 1 to LP24 notconnec routed full 10000 eth
Ethernet1/8 Link 2 to LP24 notconnec routed full 10000 eth
Ethernet1/9 -- notconnec 1 full 10000 eth
Ethernet1/10 -- notconnec 1 full 10000 eth
Ethernet1/11 -- notconnec routed full 10000 eth
Ethernet1/12 -- notconnec routed full 10000 eth
Ethernet1/13 -- notconnec routed full 10000 eth
Ethernet1/14 -- notconnec 1 full 10000 eth
Ethernet1/15 -- notconnec 1 full 10000 eth
Ethernet1/16 -- notconnec 1 full 10000 eth
Ethernet1/17 -- notconnec 1 full 10000 eth
Ethernet1/18 -- notconnec 1 full 10000 eth
Ethernet1/19 -- notconnec 1 full 10000 eth
Ethernet1/20 -- notconnec 1 full 10000 eth
Ethernet1/21 -- notconnec 1 full 10000 eth
Ethernet1/22 -- notconnec 1 full 10000 eth
Ethernet1/23 -- notconnec 1 full 10000 eth
Ethernet1/24 -- notconnec 1 full 10000 eth
Ethernet1/25 -- notconnec 1 full 10000 eth
Ethernet1/26 -- notconnec 1 full 10000 eth
Ethernet1/27 -- notconnec 1 full 10000 eth
Ethernet1/28 -- notconnec 1 full 10000 eth
Ethernet1/29 -- notconnec 1 full 10000 eth
Ethernet1/30 -- notconnec 1 full 10000 eth
Ethernet1/31 -- notconnec 1 full 10000 eth
Ethernet1/32 -- notconnec 1 full 10000 eth
Ethernet1/33 Hentammoo notconnec 33 full 10000 eth
Ethernet1/34 -- notconnec 1 full 10000 eth
Ethernet1/35 -- notconnec 1 full 10000 eth
Ethernet1/36 -- notconnec 1 full 10000 eth
Ethernet1/37 -- notconnec 1 full 10000 eth
Ethernet1/38 -- notconnec 1 full 10000 eth
Ethernet1/39 -- notconnec 1 full 10000 eth
Ethernet1/40 -- notconnec 1 full 10000 eth
Ethernet1/41 -- notconnec 1 full 10000 eth
Ethernet1/42 -- notconnec 1 full 10000 eth
Ethernet1/43 -- notconnec 1 full 10000 eth
Ethernet1/44 -- notconnec 1 full 10000 eth
Ethernet1/45 -- notconnec 1 full 10000 eth
Ethernet1/46 -- notconnec 1 full 10000 eth
Ethernet1/47 -- notconnec 1 full 10000 eth
Ethernet1/48 -- notconnec 1 full 10000 eth
Ethernet1/49 -- notconnec 1 full 40000 eth
Ethernet1/50 -- notconnec 1 full 40000 eth
Ethernet1/51 -- notconnec 1 full 40000 eth
Ethernet1/52 -- notconnec 1 full 40000 eth
Ethernet1/53 -- notconnec 1 full 40000 eth
Ethernet1/54 -- notconnec 1 full 40000 eth
po1 -- notconnec 1 full NA eth
po2 -- notconnec 1 full NA eth
po11 -- notconnec 1 full NA eth
po13 -- notconnec trunk full NA eth
po17 -- notconnec trunk full NA eth
po20 -- notconnec 1 full NA eth
po33 Hentammoo notconnec 33 full NA eth
po100 -- notconnec trunk full NA eth
po1001 -- notconnec 1 full NA eth
po1002 -- notconnec 1 full NA eth
po1003 -- notconnec trunk full NA eth
po1004 -- notconnec trunk full NA eth
mgmt0 -- connected routed full 1000 eth
loopback0 -- connected routed half NA eth
loopback3 -- connected routed half NA eth
Vlan1 -- notconnec routed auto NA --

View File

@@ -0,0 +1,10 @@
Interface IP-Address Admin-Status Link-Status VRF
Ethernet1/5 20.131.1.1 up down default
Ethernet1/6 20.131.2.1 up down default
Ethernet1/7 20.141.1.1 up down default
Ethernet1/8 20.141.2.1 up down default
Ethernet1/11 1.1.1.2 up down default
Ethernet1/12 100.10.10.10 up down default
Ethernet1/13 10.241.107.54 up down default
mgmt0 10.241.107.39 up up management

View File

@@ -0,0 +1,5 @@
Interface IPv6 Address/Link-local Address Admin-Status Link-Status VRF
loopback0 fe80::200:ff:fe00:0 up up default
loopback3 fe80::200:ff:fe00:0 up up default
mgmt0 fe80::a68c:dbff:fe33:bc00 up up management

View File

@@ -0,0 +1,8 @@
Capability codes:
(R) Router, (B) Bridge, (T) Telephone, (C) DOCSIS Cable Device
(W) WLAN Access Point, (P) Repeater, (S) Station, (O) Other
Device ID Local Intf Hold-time Capability Port ID
INDIA-LAB-1-C3750X.l... mgmt0 120 BR Gi1/0/30
Total entries displayed: 1

View File

@@ -0,0 +1,38 @@
PID MemAlloc StkSize RSSMem LibMem StackBase/Ptr Process
----- -------- ---------- ------- ------- ------------------ ----------
1 6204 8388608 12312 5380 bff01bc0/bff01590 nsm
4 2608 8388608 5264 5312 bfa92080/bfa91ab0 ospfd
7 14152 8388608 5924 5284 bfaa7250/bfaa6c20 hostpd
10 2092 8388608 4652 5312 bfafcbf0/bfafc620 mribd
11 2024 8388608 3108 5284 bfb7c650/bfb7c080 pimd
14 2016 8388608 4896 5312 bff0ff10/bff0f940 lacpd
17 48608 8388608 36200 5312 bfc10e30/bfc10830 mstpd
24 2520 8388608 5340 5312 bf90ad00/bf90a730 onmd
26 228628 8388608 77312 5376 bfb34e10/bfb34830 hsl
28 2020 8388608 4784 5312 bff3c410/bff3be10 oam
39 21396 8388608 8184 5312 bf9b1a50/bf9b1460 vrrpd
40 2480 8388608 4064 5336 bfe5f020/bfe5ea20 ndd
42 2860 8388608 5672 5364 bfe83aa0/bfe83470 ribd
44 3528 8388608 7140 5328 bf90b720/bf90b110 bgpd
45 1772 8388608 4404 5312 bf9fc250/bf9fbc80 hostmibd
46 39564 8388608 25632 5428 bfe30db0/bfe30780 l2mribd
62 1876 8388608 3920 5312 bf81c210/bf81bc40 sysmgr
63 94380 8388608 13804 5292 bfcb67d0/bfcb61d0 nwvd
64 1920 8388608 5664 5676 bfc28470/bfc27ea0 ovsdbd
65 96548 8388608 55168 5292 bfdbcf80/bfdbc980 vlagd
66 1756 8388608 3808 5284 bfa15ab0/bfa154e0 slpd
71 2116 8388608 5880 10076 bfe8abd0/bfe8a600 npad
72 2220 8388608 5452 7936 bf9e6da0/bf9e67d0 hscd
73 1920 8388608 2760 5284 bfbc6cd0/bfbc6700 dhcpsnpd
74 58620 8388608 16168 9956 bfe1af70/bfe1a970 telemetryd
75 1756 8388608 3456 5284 bfb21da0/bfb217d0 securityd
76 2152 8388608 4216 5284 bfc36900/bfc36330 l2fd
77 1920 8388608 3876 5284 bf91e480/bf91dec0 sflowd
78 1888 8388608 3772 5284 bffd10c0/bffd0af0 qosd
69 70520 8388608 5584 5260 bfca0980/bfca0490 platform_mgr
70 26828 8388608 2116 2040 bfce09c0/bfce0440 service_mgr
total used free shared buff/cache available
Mem: 4081464 442136 3144092 153168 495236 3452732
Swap: 0 0 0

View File

@@ -0,0 +1,331 @@
!
version "10.8.0.42"
!
hostname ip10-241-107-39
!
banner motd NMS India CNOS
banner motd NMS India CNOS G8272
!
clock timezone EDT 0 0
!
logging console 7
vrf context management
ip route 0.0.0.0/0 10.241.107.1
!
!
port-channel load-balance ethernet destination-mac
port-channel load-balance ethernet source-interface
feature telnet
ip domain-name labs.lenovo.com vrf management
ip domain-list labs.lenovo.com vrf management
ip name-server 10.241.104.120 vrf management
ip name-server 10.240.0.10 vrf management
ip host ip10-241-107-39.labs.lenovo.com 10.241.107.39 vrf management
ip host ip10-241-107-39 10.241.107.39 vrf management
ip domain-name labs.lenovo.com vrf default
ip domain-list labs.lenovo.com vrf default
ip name-server 10.240.0.10 vrf default
ip name-server 10.241.104.120 vrf default
ip host ip10-241-107-39.labs.lenovo.com 10.241.107.39 vrf default
ip host ip10-241-107-39 10.241.107.39 vrf default
ntp server 173.230.154.254 prefer
ntp server 97.127.86.33 prefer
ntp server 129.250.35.250 prefer
ntp server 174.136.103.130 prefer
ntp server 69.10.161.7 prefer
ntp server 96.226.123.196 prefer
ntp server 104.238.179.130 prefer
ntp server 108.61.73.244 prefer
ntp server 208.75.89.4 prefer
snmp-server community public group network-operator
snmp-server community private group network-admin
snmp-server contact Ralph
username admin role network-admin password encrypted $6$bJoWyEu/$9pzSgFPAKGRm1stpTCEl3I39htbjxiFCfhqiHag1NQiKHv/IiLQ2lYW0V3p7p72SgSmVHp38em9P9R/EdePpk/
logging server 10.241.107.231
logging server 10.241.107.222
feature restApi
ovsdb pki ovsdb_mgmt vrf management
ovsdb pki ovsdb_default vrf default
lacp system-priority 32769
vlag tier-id 313
vlag priority 1313
vlag isl port-channel 100
vlag hlthchk keepalive-attempts 5
vlag hlthchk peer-ip 1.2.3.4
vlag auto-recovery 266
vlag startup-delay 323
vlag enable
vlag instance 1 port-channel 1003
vlag instance 1 enable
vlag instance 2 port-channel 20
vlag instance 2 enable
vlag instance 12 port-channel 23
vlag instance 33 port-channel 333
vlag instance 33 enable
spanning-tree mode mst
telemetry heartbeat enabled interval 15
!
policy-map type control-plane copp-system-policy
class type control-plane copp-s-pvst-bpdu
police pps 500
class type control-plane copp-s-ecp
police pps 3000
class type control-plane copp-s-igmp
police pps 3000
!
vlan 1-2
no flood ipv4
!
vlan 3
!
vlan 5
!
vlan 12
!
vlan 13
name dave
!
vlan dot1q tag native egress-only
!
interface Ethernet1/1
description Link 1 to LP21
load-interval counter 2 33
switchport access vlan 33
storm-control broadcast level 12.50
mtu 66
channel-group 33 mode on
!
interface Ethernet1/2
description Link 2 to LP21
channel-group 1001 mode active
!
interface Ethernet1/3
description Link 1 to LP22
switchport mode trunk
channel-group 1003 mode active
!
interface Ethernet1/4
description Link 2 to LP22
switchport mode trunk
channel-group 1004 mode active
!
interface Ethernet1/5
description Link 1 to LP23
no switchport
ip address 20.131.1.1/30
!
interface Ethernet1/6
description Link 2 to LP23
no switchport
ip address 20.131.2.1/30
!
interface Ethernet1/7
description Link 1 to LP24
no switchport
ip address 20.141.1.1/30
!
interface Ethernet1/8
description Link 2 to LP24
no switchport
ip address 20.141.2.1/30
!
interface Ethernet1/9
!
interface Ethernet1/10
!
interface Ethernet1/11
no switchport
mtu 1402
ip address 1.1.1.2/8
!
interface Ethernet1/12
no switchport
ip address 100.10.10.10/24
!
interface Ethernet1/13
no switchport
ip address 10.241.107.54/24
vrrp 254
address 10.241.107.55
priority 254
no shutdown
ip arp timeout 1500
!
interface Ethernet1/14
!
interface Ethernet1/15
!
interface Ethernet1/16
!
interface Ethernet1/17
!
interface Ethernet1/18
!
interface Ethernet1/19
!
interface Ethernet1/20
!
interface Ethernet1/21
!
interface Ethernet1/22
!
interface Ethernet1/23
channel-group 11 mode active
lacp port-priority 32769
!
interface Ethernet1/24
!
interface Ethernet1/25
!
interface Ethernet1/26
!
interface Ethernet1/27
!
interface Ethernet1/28
!
interface Ethernet1/29
!
interface Ethernet1/30
!
interface Ethernet1/31
!
interface Ethernet1/32
!
interface Ethernet1/33
description Hentammoo
load-interval counter 2 33
switchport access vlan 33
storm-control broadcast level 12.50
mtu 66
microburst-detection enable threshold 25
lldp tlv-select max-frame-size
lacp port-priority 33
spanning-tree mst 33-35 cost 33
spanning-tree bpduguard enable
!
interface Ethernet1/34
!
interface Ethernet1/35
!
interface Ethernet1/36
!
interface Ethernet1/37
!
interface Ethernet1/38
!
interface Ethernet1/39
!
interface Ethernet1/40
!
interface Ethernet1/41
!
interface Ethernet1/42
!
interface Ethernet1/43
!
interface Ethernet1/44
!
interface Ethernet1/45
!
interface Ethernet1/46
!
interface Ethernet1/47
!
interface Ethernet1/48
!
interface Ethernet1/49
!
interface Ethernet1/50
!
interface Ethernet1/51
!
interface Ethernet1/52
!
interface Ethernet1/53
!
interface Ethernet1/54
!
interface loopback0
no switchport
!
interface mgmt0
no switchport
vrf member management
no ip address dhcp
ip address 10.241.107.39/24
no ipv6 address dhcp
!
interface Vlan1
no switchport
!
interface port-channel1
!
interface port-channel2
!
interface port-channel11
lacp min-links 2
!
interface port-channel13
switchport mode trunk
!
interface port-channel17
switchport mode trunk
!
interface port-channel20
!
interface port-channel33
description Hentammoo
load-interval counter 2 33
switchport access vlan 33
storm-control broadcast level 12.50
mtu 66
spanning-tree mst 33-35 cost 33
spanning-tree bpduguard enable
!
interface port-channel100
switchport mode trunk
!
interface port-channel1001
!
interface port-channel1002
!
interface port-channel1003
switchport mode trunk
!
interface port-channel1004
switchport mode trunk
!
router bgp 33
router-id 1.2.3.4
bestpath always-compare-med
cluster-id 1.2.3.4
confederation identifier 333
enforce-first-as
bgp as-local-count 33
bestpath compare-confed-aspath
maxas-limit 333
graceful-restart-helper
graceful-restart stalepath-time 333
timers bgp 333 3333
address-family ipv4 unicast
synchronization
network 0.0.0.0 backdoor
dampening 13 233 333 15 33
neighbor 10.241.107.40 remote-as 13
bfd
address-family ipv4 unicast
next-hop-self
!
route-map anil permit 10
!
ip arp timeout 1000
!
line con 0
line vty 0
exec-timeout 90 0
line vty 1 39
!
!
!
end

View File

@@ -0,0 +1,331 @@
!
version "10.8.0.42"
!
hostname ip10-241-107-39
!
banner motd NMS India CNOS
banner motd NMS India CNOS G8272
!
clock timezone EDT 0 0
!
logging console 7
vrf context management
ip route 0.0.0.0/0 10.241.107.1
!
!
port-channel load-balance ethernet destination-mac
port-channel load-balance ethernet source-interface
feature telnet
ip domain-name labs.lenovo.com vrf management
ip domain-list labs.lenovo.com vrf management
ip name-server 10.241.104.120 vrf management
ip name-server 10.240.0.10 vrf management
ip host ip10-241-107-39.labs.lenovo.com 10.241.107.39 vrf management
ip host ip10-241-107-39 10.241.107.39 vrf management
ip domain-name labs.lenovo.com vrf default
ip domain-list labs.lenovo.com vrf default
ip name-server 10.240.0.10 vrf default
ip name-server 10.241.104.120 vrf default
ip host ip10-241-107-39.labs.lenovo.com 10.241.107.39 vrf default
ip host ip10-241-107-39 10.241.107.39 vrf default
ntp server 173.230.154.254 prefer
ntp server 97.127.86.33 prefer
ntp server 129.250.35.250 prefer
ntp server 174.136.103.130 prefer
ntp server 69.10.161.7 prefer
ntp server 96.226.123.196 prefer
ntp server 104.238.179.130 prefer
ntp server 108.61.73.244 prefer
ntp server 208.75.89.4 prefer
snmp-server community public group network-operator
snmp-server community private group network-admin
snmp-server contact Ralph
username admin role network-admin password encrypted $6$bJoWyEu/$9pzSgFPAKGRm1stpTCEl3I39htbjxiFCfhqiHag1NQiKHv/IiLQ2lYW0V3p7p72SgSmVHp38em9P9R/EdePpk/
logging server 10.241.107.231
logging server 10.241.107.222
feature restApi
ovsdb pki ovsdb_mgmt vrf management
ovsdb pki ovsdb_default vrf default
lacp system-priority 32769
vlag tier-id 313
vlag priority 1313
vlag isl port-channel 100
vlag hlthchk keepalive-attempts 5
vlag hlthchk peer-ip 1.2.3.4
vlag auto-recovery 266
vlag startup-delay 323
vlag enable
vlag instance 1 port-channel 1003
vlag instance 1 enable
vlag instance 2 port-channel 20
vlag instance 2 enable
vlag instance 12 port-channel 23
vlag instance 33 port-channel 333
vlag instance 33 enable
spanning-tree mode mst
telemetry heartbeat enabled interval 15
!
policy-map type control-plane copp-system-policy
class type control-plane copp-s-pvst-bpdu
police pps 500
class type control-plane copp-s-ecp
police pps 3000
class type control-plane copp-s-igmp
police pps 3000
!
vlan 1-2
no flood ipv4
!
vlan 3
!
vlan 5
!
vlan 12
!
vlan 13
name dave
!
vlan dot1q tag native egress-only
!
interface Ethernet1/1
description Link 1 to LP21
load-interval counter 2 33
switchport access vlan 33
storm-control broadcast level 12.50
mtu 66
channel-group 33 mode on
!
interface Ethernet1/2
description Link 2 to LP21
channel-group 1001 mode active
!
interface Ethernet1/3
description Link 1 to LP22
switchport mode trunk
channel-group 1003 mode active
!
interface Ethernet1/4
description Link 2 to LP22
switchport mode trunk
channel-group 1004 mode active
!
interface Ethernet1/5
description Link 1 to LP23
no switchport
ip address 20.131.1.1/30
!
interface Ethernet1/6
description Link 2 to LP23
no switchport
ip address 20.131.2.1/30
!
interface Ethernet1/7
description Link 1 to LP24
no switchport
ip address 20.141.1.1/30
!
interface Ethernet1/8
description Link 2 to LP24
no switchport
ip address 20.141.2.1/30
!
interface Ethernet1/9
!
interface Ethernet1/10
!
interface Ethernet1/11
no switchport
mtu 1402
ip address 1.1.1.2/8
!
interface Ethernet1/12
no switchport
ip address 100.10.10.10/24
!
interface Ethernet1/13
no switchport
ip address 10.241.107.54/24
vrrp 254
address 10.241.107.55
priority 254
no shutdown
ip arp timeout 1500
!
interface Ethernet1/14
!
interface Ethernet1/15
!
interface Ethernet1/16
!
interface Ethernet1/17
!
interface Ethernet1/18
!
interface Ethernet1/19
!
interface Ethernet1/20
!
interface Ethernet1/21
!
interface Ethernet1/22
!
interface Ethernet1/23
channel-group 11 mode active
lacp port-priority 32769
!
interface Ethernet1/24
!
interface Ethernet1/25
!
interface Ethernet1/26
!
interface Ethernet1/27
!
interface Ethernet1/28
!
interface Ethernet1/29
!
interface Ethernet1/30
!
interface Ethernet1/31
!
interface Ethernet1/32
!
interface Ethernet1/33
description Hentammoo
load-interval counter 2 33
switchport access vlan 33
storm-control broadcast level 12.50
mtu 66
microburst-detection enable threshold 25
lldp tlv-select max-frame-size
lacp port-priority 33
spanning-tree mst 33-35 cost 33
spanning-tree bpduguard enable
!
interface Ethernet1/34
!
interface Ethernet1/35
!
interface Ethernet1/36
!
interface Ethernet1/37
!
interface Ethernet1/38
!
interface Ethernet1/39
!
interface Ethernet1/40
!
interface Ethernet1/41
!
interface Ethernet1/42
!
interface Ethernet1/43
!
interface Ethernet1/44
!
interface Ethernet1/45
!
interface Ethernet1/46
!
interface Ethernet1/47
!
interface Ethernet1/48
!
interface Ethernet1/49
!
interface Ethernet1/50
!
interface Ethernet1/51
!
interface Ethernet1/52
!
interface Ethernet1/53
!
interface Ethernet1/54
!
interface loopback0
no switchport
!
interface mgmt0
no switchport
vrf member management
no ip address dhcp
ip address 10.241.107.39/24
no ipv6 address dhcp
!
interface Vlan1
no switchport
!
interface port-channel1
!
interface port-channel2
!
interface port-channel11
lacp min-links 2
!
interface port-channel13
switchport mode trunk
!
interface port-channel17
switchport mode trunk
!
interface port-channel20
!
interface port-channel33
description Hentammoo
load-interval counter 2 33
switchport access vlan 33
storm-control broadcast level 12.50
mtu 66
spanning-tree mst 33-35 cost 33
spanning-tree bpduguard enable
!
interface port-channel100
switchport mode trunk
!
interface port-channel1001
!
interface port-channel1002
!
interface port-channel1003
switchport mode trunk
!
interface port-channel1004
switchport mode trunk
!
router bgp 33
router-id 1.2.3.4
bestpath always-compare-med
cluster-id 1.2.3.4
confederation identifier 333
enforce-first-as
bgp as-local-count 33
bestpath compare-confed-aspath
maxas-limit 333
graceful-restart-helper
graceful-restart stalepath-time 333
timers bgp 333 3333
address-family ipv4 unicast
synchronization
network 0.0.0.0 backdoor
dampening 13 233 333 15 33
neighbor 10.241.107.40 remote-as 13
bfd
address-family ipv4 unicast
next-hop-self
!
route-map anil permit 10
!
ip arp timeout 1000
!
line con 0
line vty 0
exec-timeout 90 0
line vty 1 39
!
!
!
end

View File

@@ -0,0 +1,62 @@
*** show boot ***
Current ZTP State: Enable
Current FLASH software:
active image: version 10.8.0.42, downloaded 09:40:15 EDT Mon May 7 2018
standby image: version 10.7.0.6, downloaded 11:02:12 EDT Thu Mar 29 2018
Uboot: version 10.7.0.6, downloaded 11:02:14 EDT Thu Mar 29 2018
ONIE: empty
Currently set to boot software active image
Current port mode: default mode
Next boot port mode: default mode
Currently scheduled reboot time: none
*** show env fan detail ***
Total Fan: 8
+--------+-----+-----------------+---------------+-------+--------+
| Module | Fan | Name | Air-Flow | Speed | Speed |
| Number | ID | | Direction | (%) | (RPM) |
+--------+-----+-----------------+---------------+-------+--------+
01 01 Fan1 Front-to-Back 23 4023
01 02 Fan2 Front-to-Back 23 4285
02 03 Fan3 Front-to-Back 23 4032
02 04 Fan4 Front-to-Back 23 4147
03 05 Fan5 Front-to-Back 23 4192
03 06 Fan6 Front-to-Back 23 4397
04 07 Fan7 Front-to-Back 23 4153
04 08 Fan8 Front-to-Back 23 4451
*** show env power ***
Total Power Supplies: 2
+----+-----------------+----------------+-----------------+------------------+
| ID | Name | Manufacturer | Model | State |
+----+-----------------+----------------+-----------------+------------------+
01 Power Supply 1 DELTA XXXXXXXXXX Normal ON
02 Power Supply 2 DELTA XXXXXXXXXX 12V Output Fault
*** show env temperature ***
+----+------------------+----------+--------+
| ID | Name | Temp | State |
| | | (Celsius)| |
+----+------------------+----------+--------+
01 CPU Local 32 OK
02 Ambient 31 OK
03 Hot Spot 47 OK
System Name : G8272
System Description : G8272 ("48x10GE + 6x40GE")
System Model : Lenovo RackSwitch G8272
System VPD Version : 3
System Manufacture Date : 1542 (YYWW)
System Part Number : 00CJ066
System Serial Number : Y052MV59Y052
System FRU Number : 00FM430
System Machine Type Model : 7159-HCV
System Machine Serial Number : MM11945
System Hardware Revision : 1
System Management MAC : A4:8C:DB:33:BC:00
System Software Revision : 10.8.0.42

View File

@@ -0,0 +1,19 @@
Lenovo Networking Operating System (NOS) Software
Technical Assistance Center: http://www.lenovo.com
Copyright (C) Lenovo, 2016. All rights reserved.
Software:
Bootloader version: 10.7.0.6
System version: 10.8.0.42
System compile time: May 03 11:06:25 PDT 2018
Hardware:
G8272 ("48x10GE + 6x40GE")
NXP P2020 CPU with 4096 MB of memory
Device name: ip10-241-107-39
Boot Flash: 16 MB
Kernel uptime is 2 day(s), 21 hour(s), 26 minute(s), 14 second(s)
Last Reset Reason: Reset by CLI reload command

View File

@@ -0,0 +1,106 @@
# Copyright (C) 2017 Lenovo, 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
import json
from ansible.compat.tests.mock import patch
from ansible.modules.network.cnos import cnos_command
from units.modules.utils import set_module_args
from .cnos_module import TestCnosModule, load_fixture
class TestCnosCommandModule(TestCnosModule):
module = cnos_command
def setUp(self):
super(TestCnosCommandModule, self).setUp()
self.mock_run_commands = patch('ansible.modules.network.cnos.cnos_command.run_commands')
self.run_commands = self.mock_run_commands.start()
def tearDown(self):
super(TestCnosCommandModule, self).tearDown()
self.mock_run_commands.stop()
def load_fixtures(self, commands=None):
def load_from_file(*args, **kwargs):
module, commands = args
output = list()
for item in commands:
try:
command = item
except ValueError:
command = 'display version'
filename = str(command).replace(' ', '_')
output.append(load_fixture(filename))
return output
self.run_commands.side_effect = load_from_file
def test_cnos_command_simple(self):
set_module_args(dict(commands=['display version']))
result = self.execute_module()
self.assertEqual(len(result['stdout']), 1)
self.assertTrue(result['stdout'][0].startswith('Lenovo Networking Operating System (NOS) Software'))
def test_cnos_command_multiple(self):
set_module_args(dict(commands=['display version', 'display running-config']))
result = self.execute_module()
self.assertEqual(len(result['stdout']), 2)
self.assertTrue(result['stdout'][0].startswith('Lenovo Networking Operating System (NOS) Software'))
def test_cnos_command_wait_for(self):
wait_for = 'result[0] contains "Lenovo Networking Operating System (NOS) Software"'
set_module_args(dict(commands=['display version'], wait_for=wait_for))
self.execute_module()
def test_cnos_command_wait_for_fails(self):
wait_for = 'result[0] contains "test string"'
set_module_args(dict(commands=['display version'], wait_for=wait_for))
self.execute_module(failed=True)
self.assertEqual(self.run_commands.call_count, 10)
def test_cnos_command_retries(self):
wait_for = 'result[0] contains "test string"'
set_module_args(dict(commands=['display version'], wait_for=wait_for, retries=2))
self.execute_module(failed=True)
self.assertEqual(self.run_commands.call_count, 2)
def test_cnos_command_match_any(self):
wait_for = ['result[0] contains "Lenovo Networking Operating System (NOS) Software"',
'result[0] contains "test string"']
set_module_args(dict(commands=['display version'], wait_for=wait_for, match='any'))
self.execute_module()
def test_cnos_command_match_all(self):
wait_for = ['result[0] contains "Lenovo Networking Operating System (NOS) Software"',
'result[0] contains "Lenovo"']
set_module_args(dict(commands=['display version'], wait_for=wait_for, match='all'))
self.execute_module()
def test_cnos_command_match_all_failure(self):
wait_for = ['result[0] contains "Lenovo ENOS"',
'result[0] contains "test string"']
commands = ['display version', 'display run']
set_module_args(dict(commands=commands, wait_for=wait_for, match='all'))
self.execute_module(failed=True)

View File

@@ -0,0 +1,125 @@
#
# (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
import json
from ansible.compat.tests.mock import patch
from ansible.modules.network.cnos import cnos_config
from .cnos_module import TestCnosModule, load_fixture, set_module_args
class TestCnosConfigModule(TestCnosModule):
module = cnos_config
def setUp(self):
self.patcher_get_config = patch('ansible.modules.network.cnos.cnos_config.get_config')
self.mock_get_config = self.patcher_get_config.start()
self.patcher_exec_command = patch('ansible.modules.network.cnos.cnos_config.load_config')
self.mock_exec_command = self.patcher_exec_command.start()
def tearDown(self):
self.patcher_get_config.stop()
self.patcher_exec_command.stop()
def load_fixtures(self, commands=None):
config_file = 'cnos_config_config.cfg'
self.mock_get_config.return_value = load_fixture(config_file)
self.mock_exec_command.return_value = 'dummy diff'
def test_cnos_config_unchanged(self):
src = load_fixture('cnos_config_config.cfg')
set_module_args(dict(src=src))
self.execute_module()
def test_cnos_config_src(self):
src = load_fixture('cnos_config_src.cfg')
set_module_args(dict(src=src))
commands = ['hostname foo', 'interface ethernet 1/13',
'speed 10000']
self.execute_module(changed=True, commands=commands)
def test_cnos_config_backup(self):
set_module_args(dict(backup=True))
result = self.execute_module()
self.assertIn('__backup__', result)
def test_cnos_config_lines_wo_parents(self):
set_module_args(dict(lines=['hostname foo']))
commands = ['hostname foo']
self.execute_module(changed=True, commands=commands)
def test_cnos_config_lines_w_parents(self):
set_module_args(dict(lines=['shutdown'], parents=['interface ethernet 1/13']))
commands = ['interface ethernet 1/13', 'shutdown']
self.execute_module(changed=True, commands=commands)
def test_cnos_config_before(self):
set_module_args(dict(lines=['hostname foo'], before=['test1', 'test2']))
commands = ['test1', 'test2', 'hostname foo']
self.execute_module(changed=True, commands=commands, sort=False)
def test_cnos_config_after(self):
set_module_args(dict(lines=['hostname foo'], after=['test1', 'test2']))
commands = ['hostname foo', 'test1', 'test2']
self.execute_module(changed=True, commands=commands, sort=False)
def test_cnos_config_before_after_no_change(self):
set_module_args(dict(lines=['hostname ip10-241-107-39'],
before=['test1', 'test2'],
after=['test2', 'test3']))
self.execute_module()
def test_cnos_config_config(self):
config = 'hostname localhost'
set_module_args(dict(lines=['hostname ip10-241-107-39'], config=config))
commands = ['hostname ip10-241-107-39']
self.execute_module(changed=True, commands=commands)
def test_cnos_config_replace_block(self):
lines = ['description test string', 'test string']
parents = ['interface ethernet 1/13']
set_module_args(dict(lines=lines, replace='block', parents=parents))
commands = parents + lines
self.execute_module(changed=True, commands=commands)
def test_cnos_config_match_none(self):
lines = ['ip address 1.2.3.4 255.255.255.0', 'description test string']
parents = ['interface ethernet 1/13']
set_module_args(dict(lines=lines, parents=parents, match='none'))
commands = parents + lines
self.execute_module(changed=True, commands=commands, sort=False)
def test_cnos_config_match_strict(self):
lines = ['ip address 100.10.10.10/24', 'no switchport']
parents = ['interface Ethernet1/12']
set_module_args(dict(lines=lines, parents=parents, match='strict'))
commands = parents + ['no switchport']
self.execute_module(changed=True, commands=commands, sort=False)
def test_cnos_config_match_exact(self):
lines = ['ip address 1.2.3.4 255.255.255.0', 'description test string',
'no shutdown']
parents = ['interface ethernet 1/13']
set_module_args(dict(lines=lines, parents=parents, match='exact'))
commands = parents + lines
self.execute_module(changed=True, commands=commands, sort=False)

View File

@@ -0,0 +1,82 @@
# (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
import json
from ansible.compat.tests.mock import patch
from .cnos_module import TestCnosModule, load_fixture
from ansible.modules.network.cnos import cnos_facts
from units.modules.utils import set_module_args
class TestCnosFacts(TestCnosModule):
module = cnos_facts
def setUp(self):
super(TestCnosFacts, self).setUp()
self.mock_run_commands = patch(
'ansible.modules.network.cnos.cnos_facts.run_commands')
self.run_commands = self.mock_run_commands.start()
def tearDown(self):
super(TestCnosFacts, self).tearDown()
self.mock_run_commands.stop()
def load_fixtures(self, commands=None):
def load_from_file(*args, **kwargs):
module, commands = args
output = list()
for item in commands:
try:
obj = json.loads(item)
command = obj['command']
except ValueError:
command = item
filename = str(command).replace(' ', '_')
filename = filename.replace('/', '7')
output.append(load_fixture(filename))
return output
self.run_commands.side_effect = load_from_file
def test_cnos_facts_gather_subset_default(self):
set_module_args(dict())
result = self.execute_module()
ansible_facts = result['ansible_facts']
self.assertIn('hardware', ansible_facts['ansible_net_gather_subset'])
self.assertIn('default', ansible_facts['ansible_net_gather_subset'])
self.assertIn('interfaces', ansible_facts['ansible_net_gather_subset'])
self.assertEquals('ip10-241-107-39', ansible_facts['ansible_net_hostname'])
self.assertIn('Ethernet1/1', ansible_facts['ansible_net_interfaces'].keys())
self.assertEquals(3985.8046875, ansible_facts['ansible_net_memtotal_mb'])
self.assertEquals(3070.40234375, ansible_facts['ansible_net_memfree_mb'])
def test_cnos_facts_gather_subset_config(self):
set_module_args({'gather_subset': 'config'})
result = self.execute_module()
ansible_facts = result['ansible_facts']
self.assertIn('default', ansible_facts['ansible_net_gather_subset'])
self.assertIn('config', ansible_facts['ansible_net_gather_subset'])
self.assertEquals('ip10-241-107-39', ansible_facts['ansible_net_hostname'])
self.assertIn('ansible_net_config', ansible_facts)