mirror of
https://github.com/ansible-collections/community.general.git
synced 2026-03-30 17:06:19 +00:00
Move modules and module_utils unit tests to correct place (#81)
* Move modules and module_utils unit tests to correct place. * Update ignore.txt * Fix imports. * Fix typos. * Fix more typos.
This commit is contained in:
parent
ab3c2120fb
commit
be191cce6c
1170 changed files with 732 additions and 751 deletions
0
tests/unit/plugins/modules/network/enos/__init__.py
Normal file
0
tests/unit/plugins/modules/network/enos/__init__.py
Normal file
119
tests/unit/plugins/modules/network/enos/enos_module.py
Normal file
119
tests/unit/plugins/modules/network/enos/enos_module.py
Normal file
|
|
@ -0,0 +1,119 @@
|
|||
# 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_collections.community.general.tests.unit.compat import unittest
|
||||
from ansible_collections.community.general.tests.unit.compat.mock import patch
|
||||
from ansible.module_utils import basic
|
||||
|
||||
|
||||
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 Exception:
|
||||
pass
|
||||
|
||||
fixture_data[path] = data
|
||||
return data
|
||||
|
||||
|
||||
class AnsibleExitJson(Exception):
|
||||
pass
|
||||
|
||||
|
||||
class AnsibleFailJson(Exception):
|
||||
pass
|
||||
|
||||
|
||||
class TestEnosModule(unittest.TestCase):
|
||||
|
||||
def setUp(self):
|
||||
self.mock_sleep = patch('time.sleep')
|
||||
self.mock_sleep.start()
|
||||
|
||||
def tearDown(self):
|
||||
self.mock_sleep.stop()
|
||||
|
||||
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
|
||||
|
|
@ -0,0 +1,47 @@
|
|||
Current configuration:
|
||||
!
|
||||
version "8.4.3.12"
|
||||
switch-type "Lenovo RackSwitch G8272"
|
||||
iscli-new
|
||||
!
|
||||
!
|
||||
access https enable
|
||||
|
||||
snmp-server location "Location:,Room:,Rack:Rack 3,LRU:40"
|
||||
snmp-server read-community "public"
|
||||
snmp-server trap-source 128
|
||||
!
|
||||
!
|
||||
!
|
||||
no system dhcp
|
||||
no system default-ip mgt
|
||||
hostname router
|
||||
!
|
||||
!
|
||||
!
|
||||
!interface ip 1
|
||||
! addr <default>
|
||||
! enable
|
||||
!
|
||||
interface ip 13
|
||||
ip address 1.2.3.4 255.255.255.0
|
||||
enable
|
||||
exit
|
||||
!
|
||||
interface ip 128
|
||||
ip address 10.241.105.24 255.255.255.0
|
||||
enable
|
||||
exit
|
||||
!
|
||||
ip gateway 4 address 10.241.105.1
|
||||
ip gateway 4 enable
|
||||
!
|
||||
!
|
||||
!
|
||||
!
|
||||
router bgp
|
||||
as 100
|
||||
!
|
||||
!
|
||||
end
|
||||
|
||||
|
|
@ -0,0 +1,6 @@
|
|||
!
|
||||
hostname foo
|
||||
!
|
||||
interface ip 13
|
||||
no ip ospf enable
|
||||
!
|
||||
|
|
@ -0,0 +1,9 @@
|
|||
Interface information:
|
||||
1: IP4 192.168.49.50 255.255.255.0 192.168.49.255, vlan 1, up
|
||||
128: IP4 10.241.105.24 255.255.255.0 10.241.105.255, vlan 4095, up
|
||||
|
||||
Routed Port Interface Information:
|
||||
|
||||
Loopback interface information:
|
||||
|
||||
|
||||
|
|
@ -0,0 +1,59 @@
|
|||
-----------------------------------------------------------------------
|
||||
Port Speed Duplex Flow Ctrl Link Description
|
||||
------- ------ -------- --TX-----RX-- ------ -------------
|
||||
1 1G/10G full no no down 1
|
||||
2 1G/10G full no no down 2
|
||||
3 1G/10G full no no down 3
|
||||
4 1G/10G full no no down 4
|
||||
5 1G/10G full no no down 5
|
||||
6 1G/10G full no no down 6
|
||||
7 1G/10G full no no down 7
|
||||
8 1G/10G full no no down 8
|
||||
9 1G/10G full no no down 9
|
||||
10 1G/10G full no no down 10
|
||||
11 1G/10G full no no down 11
|
||||
12 1G/10G full no no down 12
|
||||
13 1G/10G full no no down 13
|
||||
14 1G/10G full no no down 14
|
||||
15 1G/10G full no no down 15
|
||||
16 1G/10G full no no down 16
|
||||
17 1G/10G full no no down 17
|
||||
18 1G/10G full no no down 18
|
||||
19 1G/10G full no no down 19
|
||||
20 1G/10G full no no down 20
|
||||
21 1G/10G full no no down 21
|
||||
22 1G/10G full no no down 22
|
||||
23 1G/10G full no no down 23
|
||||
24 1G/10G full no no down 24
|
||||
25 1G/10G full no no down 25
|
||||
26 1G/10G full no no down 26
|
||||
27 1G/10G full no no down 27
|
||||
28 1G/10G full no no down 28
|
||||
29 1G/10G full no no down 29
|
||||
30 1G/10G full no no down 30
|
||||
31 1G/10G full no no down 31
|
||||
32 1G/10G full no no down 32
|
||||
33 1G/10G full no no down 33
|
||||
34 1G/10G full no no down 34
|
||||
35 1G/10G full no no down 35
|
||||
36 1G/10G full no no down 36
|
||||
37 1G/10G full no no down 37
|
||||
38 1000 full no no up 38
|
||||
39 1G/10G full no no down 39
|
||||
40 1G/10G full no no down 40
|
||||
41 1G/10G full no no down 41
|
||||
42 1G/10G full no no down 42
|
||||
43 1G/10G full no no down 43
|
||||
44 1G/10G full no no down 44
|
||||
45 1G/10G full no no down 45
|
||||
46 1G/10G full no no down 46
|
||||
47 1G/10G full no no down 47
|
||||
48 10000 full no no down 48
|
||||
49 40000 full no no down 49
|
||||
50 40000 full no no down 50
|
||||
51 40000 full no no down 51
|
||||
52 40000 full no no down 52
|
||||
53 40000 full no no down 53
|
||||
54 40000 full no no down 54
|
||||
MGT 1000 full yes yes up MGT
|
||||
|
||||
|
|
@ -0,0 +1,60 @@
|
|||
LLDP Port Info
|
||||
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
Port MAC address MTU PortEnabled AdminStatus RxChange TrapNotify
|
||||
======= ================= ==== =========== =========== ======== ==========
|
||||
1 a8:97:dc:dd:e2:00 9216 disabled tx_rx no disabled
|
||||
2 a8:97:dc:dd:e2:00 9216 disabled tx_rx no disabled
|
||||
3 a8:97:dc:dd:e2:00 9216 disabled tx_rx no disabled
|
||||
4 a8:97:dc:dd:e2:00 9216 disabled tx_rx no disabled
|
||||
5 a8:97:dc:dd:e2:00 9216 disabled tx_rx no disabled
|
||||
6 a8:97:dc:dd:e2:00 9216 disabled tx_rx no disabled
|
||||
7 a8:97:dc:dd:e2:00 9216 disabled tx_rx no disabled
|
||||
8 a8:97:dc:dd:e2:00 9216 disabled tx_rx no disabled
|
||||
9 a8:97:dc:dd:e2:00 9216 disabled tx_rx no disabled
|
||||
10 a8:97:dc:dd:e2:00 9216 disabled tx_rx no disabled
|
||||
11 a8:97:dc:dd:e2:00 9216 disabled tx_rx no disabled
|
||||
12 a8:97:dc:dd:e2:00 9216 disabled tx_rx no disabled
|
||||
13 a8:97:dc:dd:e2:00 9216 disabled tx_rx no disabled
|
||||
14 a8:97:dc:dd:e2:00 9216 disabled tx_rx no disabled
|
||||
15 a8:97:dc:dd:e2:00 9216 disabled tx_rx no disabled
|
||||
16 a8:97:dc:dd:e2:00 9216 disabled tx_rx no disabled
|
||||
17 a8:97:dc:dd:e2:00 9216 disabled tx_rx no disabled
|
||||
18 a8:97:dc:dd:e2:00 9216 disabled tx_rx no disabled
|
||||
19 a8:97:dc:dd:e2:00 9216 disabled tx_rx no disabled
|
||||
20 a8:97:dc:dd:e2:00 9216 disabled tx_rx no disabled
|
||||
21 a8:97:dc:dd:e2:00 9216 disabled tx_rx no disabled
|
||||
22 a8:97:dc:dd:e2:00 9216 disabled tx_rx no disabled
|
||||
23 a8:97:dc:dd:e2:00 9216 disabled tx_rx no disabled
|
||||
24 a8:97:dc:dd:e2:00 9216 disabled tx_rx no disabled
|
||||
25 a8:97:dc:dd:e2:00 9216 disabled tx_rx no disabled
|
||||
26 a8:97:dc:dd:e2:00 9216 disabled tx_rx no disabled
|
||||
27 a8:97:dc:dd:e2:00 9216 disabled tx_rx no disabled
|
||||
28 a8:97:dc:dd:e2:00 9216 disabled tx_rx no disabled
|
||||
29 a8:97:dc:dd:e2:00 9216 disabled tx_rx no disabled
|
||||
30 a8:97:dc:dd:e2:00 9216 disabled tx_rx no disabled
|
||||
31 a8:97:dc:dd:e2:00 9216 disabled tx_rx no disabled
|
||||
32 a8:97:dc:dd:e2:00 9216 disabled tx_rx no disabled
|
||||
33 a8:97:dc:dd:e2:00 9216 disabled tx_rx no disabled
|
||||
34 a8:97:dc:dd:e2:00 9216 disabled tx_rx no disabled
|
||||
35 a8:97:dc:dd:e2:00 9216 disabled tx_rx no disabled
|
||||
36 a8:97:dc:dd:e2:00 9216 disabled tx_rx no disabled
|
||||
37 a8:97:dc:dd:e2:00 9216 disabled tx_rx no disabled
|
||||
38 a8:97:dc:dd:e2:00 9216 enabled tx_rx no disabled
|
||||
39 a8:97:dc:dd:e2:00 9216 disabled tx_rx no disabled
|
||||
40 a8:97:dc:dd:e2:00 9216 disabled tx_rx no disabled
|
||||
41 a8:97:dc:dd:e2:00 9216 disabled tx_rx no disabled
|
||||
42 a8:97:dc:dd:e2:00 9216 disabled tx_rx no disabled
|
||||
43 a8:97:dc:dd:e2:00 9216 disabled tx_rx no disabled
|
||||
44 a8:97:dc:dd:e2:00 9216 disabled tx_rx no disabled
|
||||
45 a8:97:dc:dd:e2:00 9216 disabled tx_rx no disabled
|
||||
46 a8:97:dc:dd:e2:00 9216 disabled tx_rx no disabled
|
||||
47 a8:97:dc:dd:e2:00 9216 disabled tx_rx no disabled
|
||||
48 a8:97:dc:dd:e2:00 9216 disabled tx_rx no disabled
|
||||
49 a8:97:dc:dd:e2:00 9216 disabled tx_rx no disabled
|
||||
50 a8:97:dc:dd:e2:00 9216 disabled tx_rx no disabled
|
||||
51 a8:97:dc:dd:e2:00 9216 disabled tx_rx no disabled
|
||||
52 a8:97:dc:dd:e2:00 9216 disabled tx_rx no disabled
|
||||
53 a8:97:dc:dd:e2:00 9216 disabled tx_rx no disabled
|
||||
54 a8:97:dc:dd:e2:00 9216 disabled tx_rx no disabled
|
||||
MGT a8:97:dc:dd:e2:fe 9216 enabled tx_rx no disabled
|
||||
|
||||
|
|
@ -0,0 +1,12 @@
|
|||
LLDP Remote Devices Information
|
||||
Legend(possible values in DMAC column) :
|
||||
NB - Nearest Bridge - 01-80-C2-00-00-0E
|
||||
NnTB - Nearest non-TPMR Bridge - 01-80-C2-00-00-03
|
||||
NCB - Nearest Customer Bridge - 01-80-C2-00-00-00
|
||||
Total number of current entries: 1
|
||||
|
||||
LocalPort | Index | Remote Chassis ID | Remote Port | Remote System Name | DMAC
|
||||
----------|-------|---------------------------|----------------------|-------------------------------|---------
|
||||
MGT | 1 | 74 26 ac 3d 3c c0 | Gi3/18 | INDIA-LAB-1-C4506E-A.labs.l...| NB
|
||||
|
||||
|
||||
59
tests/unit/plugins/modules/network/enos/fixtures/show_run
Normal file
59
tests/unit/plugins/modules/network/enos/fixtures/show_run
Normal file
|
|
@ -0,0 +1,59 @@
|
|||
Current configuration:
|
||||
!
|
||||
version "8.4.3.12"
|
||||
switch-type "Lenovo RackSwitch G8272"
|
||||
iscli-new
|
||||
!
|
||||
!
|
||||
access https enable
|
||||
|
||||
snmp-server location "Location:,Room:,Rack:Rack 3,LRU:40"
|
||||
snmp-server read-community "public"
|
||||
snmp-server trap-source 128
|
||||
!
|
||||
!
|
||||
!
|
||||
no system dhcp
|
||||
no system default-ip mgt
|
||||
hostname "test1"
|
||||
!
|
||||
!
|
||||
!
|
||||
!
|
||||
!
|
||||
!
|
||||
!
|
||||
!
|
||||
!
|
||||
!
|
||||
!
|
||||
!
|
||||
!
|
||||
!
|
||||
!
|
||||
!
|
||||
!
|
||||
!
|
||||
!interface ip 1
|
||||
! addr <default>
|
||||
! enable
|
||||
!
|
||||
interface ip 128
|
||||
ip address 10.241.105.24 255.255.255.0
|
||||
enable
|
||||
exit
|
||||
!
|
||||
ip gateway 4 address 10.241.105.1
|
||||
ip gateway 4 enable
|
||||
!
|
||||
!
|
||||
!
|
||||
!
|
||||
!
|
||||
!
|
||||
router bgp
|
||||
as 100
|
||||
!
|
||||
!
|
||||
end
|
||||
|
||||
|
|
@ -0,0 +1,59 @@
|
|||
Current configuration:
|
||||
!
|
||||
version "8.4.3.12"
|
||||
switch-type "Lenovo RackSwitch G8272"
|
||||
iscli-new
|
||||
!
|
||||
!
|
||||
access https enable
|
||||
|
||||
snmp-server location "Location:,Room:,Rack:Rack 3,LRU:40"
|
||||
snmp-server read-community "public"
|
||||
snmp-server trap-source 128
|
||||
!
|
||||
!
|
||||
!
|
||||
no system dhcp
|
||||
no system default-ip mgt
|
||||
hostname "test1"
|
||||
!
|
||||
!
|
||||
!
|
||||
!
|
||||
!
|
||||
!
|
||||
!
|
||||
!
|
||||
!
|
||||
!
|
||||
!
|
||||
!
|
||||
!
|
||||
!
|
||||
!
|
||||
!
|
||||
!
|
||||
!
|
||||
!interface ip 1
|
||||
! addr <default>
|
||||
! enable
|
||||
!
|
||||
interface ip 128
|
||||
ip address 10.241.105.24 255.255.255.0
|
||||
enable
|
||||
exit
|
||||
!
|
||||
ip gateway 4 address 10.241.105.1
|
||||
ip gateway 4 enable
|
||||
!
|
||||
!
|
||||
!
|
||||
!
|
||||
!
|
||||
!
|
||||
router bgp
|
||||
as 100
|
||||
!
|
||||
!
|
||||
end
|
||||
|
||||
|
|
@ -0,0 +1,166 @@
|
|||
------------------------------------------------------------------
|
||||
|
||||
Memory utilization:
|
||||
MemTotal: 4088580 kB
|
||||
MemFree: 3464304 kB
|
||||
MemAvailable: 3586864 kB
|
||||
Buffers: 2016 kB
|
||||
Cached: 173236 kB
|
||||
SwapCached: 0 kB
|
||||
Active: 504316 kB
|
||||
Inactive: 38056 kB
|
||||
Active(anon): 376332 kB
|
||||
Inactive(anon): 27460 kB
|
||||
Active(file): 127984 kB
|
||||
Inactive(file): 10596 kB
|
||||
Unevictable: 0 kB
|
||||
Mlocked: 0 kB
|
||||
HighTotal: 3407860 kB
|
||||
HighFree: 2952904 kB
|
||||
LowTotal: 680720 kB
|
||||
LowFree: 511400 kB
|
||||
SwapTotal: 0 kB
|
||||
SwapFree: 0 kB
|
||||
Dirty: 0 kB
|
||||
Writeback: 0 kB
|
||||
AnonPages: 367120 kB
|
||||
Mapped: 20664 kB
|
||||
Shmem: 36672 kB
|
||||
Slab: 8240 kB
|
||||
SReclaimable: 3492 kB
|
||||
SUnreclaim: 4748 kB
|
||||
KernelStack: 760 kB
|
||||
PageTables: 1592 kB
|
||||
NFS_Unstable: 0 kB
|
||||
Bounce: 0 kB
|
||||
WritebackTmp: 0 kB
|
||||
CommitLimit: 2044288 kB
|
||||
Committed_AS: 1128364 kB
|
||||
VmallocTotal: 241652 kB
|
||||
VmallocUsed: 17116 kB
|
||||
VmallocChunk: 223920 kB
|
||||
HugePages_Total: 0
|
||||
HugePages_Free: 0
|
||||
HugePagesPercentage used 15
|
||||
|
||||
Memory tracing: enabled
|
||||
Extended Memory tracing: disabled
|
||||
High-water monitoring: enabled
|
||||
|
||||
Memory high-water: 20 percent (at 1818 seconds from boot)
|
||||
|
||||
Memory stats:
|
||||
allocs: 16484474
|
||||
frees: 16481108
|
||||
current: 3378
|
||||
alloc fails: 0
|
||||
|
||||
STEM thread memory stats:
|
||||
thid name allocs frees diff current * largest
|
||||
0 INIT 2655 933 1722 69381079 31982881
|
||||
1 STEM 0 0 0 0 0
|
||||
2 STP 13 6 7 41165721 16673868
|
||||
3 MFDB 1 0 1 6 6
|
||||
4 TND 41745 42134 -389 847441 336
|
||||
5 CONS 3867 3866 1 26622356 6291456
|
||||
6 TNET 3806775 3809157 -2382 1032303745 12582912
|
||||
7 TNET 126519 127060 -541 269598653 12582912
|
||||
8 TNET 1 0 1 6131 6131
|
||||
9 TNET 1 0 1 6131 6131
|
||||
10 TNET 1 0 1 6131 6131
|
||||
11 TNET 1 0 1 6131 6131
|
||||
12 LOG 441 441 0 61437 272
|
||||
13 TRAP 16911 16911 0 1416745 544
|
||||
14 NTP 0 0 0 0 0
|
||||
15 RMON 0 0 0 0 0
|
||||
18 IP 40 7 33 26152 4248
|
||||
19 RIP 0 0 0 0 0
|
||||
20 AGR 24643 23177 1466 8949189 6131
|
||||
21 EPI 0 0 0 0 0
|
||||
22 PORT 56 0 56 60032 16384
|
||||
23 BGP 0 10 -10 0 0
|
||||
27 MGMT 335 162 173 48883648 524436
|
||||
28 SCAN 0 0 0 0 0
|
||||
29 OSPF 0 20 -20 0 0
|
||||
30 VRRP 1 0 1 16 16
|
||||
31 SNMP 4670978 4670164 814 2315549793 12582912
|
||||
32 SNMP 1108 1068 40 208175203 12582912
|
||||
34 SSHD 800286 796910 3376 271976834 2017
|
||||
36 DT1X 0 0 0 0 0
|
||||
37 NCFD 1 0 1 6131 6131
|
||||
38 NCFD 1 0 1 6131 6131
|
||||
39 NCFD 1 0 1 6131 6131
|
||||
40 NCFD 1 0 1 6131 6131
|
||||
41 SWR 0 0 0 0 0
|
||||
42 SWRH 0 0 0 0 0
|
||||
43 OBS 0 0 0 0 0
|
||||
44 TEAM 0 0 0 0 0
|
||||
45 I2C 0 0 0 0 0
|
||||
46 LACP 72 0 72 1152 16
|
||||
47 SFP 0 0 0 0 0
|
||||
48 SWKY 0 0 0 0 0
|
||||
49 HLNK 0 0 0 0 0
|
||||
50 LLDP 5794454 5794373 81 598072737 14336
|
||||
51 IPV6 0 0 0 0 0
|
||||
52 RTM6 0 0 0 0 0
|
||||
53 PNG6 0 0 0 0 0
|
||||
55 OSP3 0 0 0 0 0
|
||||
56 VMAC 0 0 0 0 0
|
||||
57 MEMM 0 0 0 0 0
|
||||
58 UDLD 0 0 0 0 0
|
||||
59 FCOE 0 0 0 0 0
|
||||
60 SFLO 0 0 0 0 0
|
||||
61 PROX 0 0 0 0 0
|
||||
62 OAM 0 0 0 0 0
|
||||
63 PIM 0 0 0 0 0
|
||||
64 DCBX 1 1 0 126 126
|
||||
65 NBOO 1 0 1 6131 6131
|
||||
66 VLAG 0 0 0 0 0
|
||||
67 MLD6 0 0 0 0 0
|
||||
68 DHCP 0 0 0 0 0
|
||||
69 ETMR 0 0 0 0 0
|
||||
70 IKE2 0 0 0 0 0
|
||||
71 ACLG 1 0 1 5120 5120
|
||||
72 HWRT 0 0 0 0 0
|
||||
73 OFLO 17 0 17 32244 8048
|
||||
74 SFM 0 0 0 0 0
|
||||
75 UPTM 0 0 0 0 0
|
||||
76 VSDB 0 2 -2 0 0
|
||||
77 ECPT 3 0 3 168532 168000
|
||||
78 ECPR 0 0 0 0 0
|
||||
79 VDPT 5 0 5 5260 1460
|
||||
80 VFDB 0 1 -1 0 0
|
||||
81 PTP 0 0 0 0 0
|
||||
82 PBR 0 0 0 0 0
|
||||
83 HIST 0 0 0 0 0
|
||||
84 SLP 699757 701435 -1678 254297215 262140
|
||||
85 UFP 217 73 144 12908 132
|
||||
86 CDCP 0 0 0 0 0
|
||||
87 IGMP 0 0 0 0 0
|
||||
88 ICMP 0 0 0 0 0
|
||||
89 HCM 0 0 0 0 0
|
||||
90 CFCF 0 0 0 0 0
|
||||
91 FDF@ 0 0 0 0 0
|
||||
92 NAT 0 0 0 0 0
|
||||
93 OCM1 11 0 11 44 4
|
||||
94 OCM2 0 0 0 0 0
|
||||
95 OFDT 0 0 0 0 0
|
||||
96 OSFM 5 0 5 2636 1024
|
||||
97 OBSC 0 0 0 0 0
|
||||
98 STPM 0 0 0 0 0
|
||||
99 ARP 0 0 0 0 0
|
||||
100 VXLN 0 0 0 0 0
|
||||
101 OVSD 0 0 0 0 0
|
||||
102 OVSC 0 0 0 0 0
|
||||
103 VTEP 0 0 0 0 0
|
||||
104 BFD 18 0 18 440 44
|
||||
105 STPR 0 0 0 0 0
|
||||
106 VMFD 0 0 0 0 0
|
||||
107 NORM 0 0 0 0 0
|
||||
108 DONE 494136 493788 348 280129530 6291456
|
||||
Total 16485149 16481768 3381 1132837544
|
||||
|
||||
Non-STEM allocs 0
|
||||
Non-STEM frees 2
|
||||
Overhead 1780
|
||||
|
||||
|
|
@ -0,0 +1,60 @@
|
|||
System Information at 11:37:06 Fri Oct 27, 2017
|
||||
Time zone: No timezone configured
|
||||
Daylight Savings Time Status: Disabled
|
||||
|
||||
Lenovo RackSwitch G8272
|
||||
|
||||
Switch has been up for 30 days, 10 hours, 43 minutes and 14 seconds.
|
||||
Last boot: 00:53:32 Wed Sep 27, 2017 (power cycle)
|
||||
|
||||
MAC address: a8:97:dc:dd:e2:00 IP (If 1) address: 192.168.49.50
|
||||
Management Port MAC Address: a8:97:dc:dd:e2:fe
|
||||
Management Port IP Address (if 128): 10.241.105.24
|
||||
Hardware Revision: 0
|
||||
Board Revision:
|
||||
Hardware Part No: 00CJ066
|
||||
Old Hardware Part No: 2MV4CR01W
|
||||
Switch Serial No: Y052MV4CR01W
|
||||
Manufacturing date: 14/51
|
||||
|
||||
MTM Value: 7159-HCV
|
||||
Old MTM Value:
|
||||
ESN: MM01086
|
||||
|
||||
|
||||
WARNING: This is UNRELEASED SOFTWARE for LAB TESTING ONLY.
|
||||
DO NOT USE IN A PRODUCTION NETWORK.
|
||||
|
||||
|
||||
Software Version 8.4.3.12 (FLASH image1), active configuration.
|
||||
Boot kernel version 8.4.3.12
|
||||
|
||||
USB Boot: disabled
|
||||
|
||||
|
||||
|
||||
Temperature CPU Local : 31 C
|
||||
Temperature Ambient : 32 C
|
||||
Temperature Hot Spot : 44 C
|
||||
Temperature Asic Max : 63 C
|
||||
|
||||
System Warning at 85 C / Shutdown at 95 C / Set Point is 70 C
|
||||
|
||||
Fan 1 Module 1: 4054rpm 60pwm(23%) Front-To-Back
|
||||
Fan 2 Module 1: 4404rpm 60pwm(23%) Front-To-Back
|
||||
Fan 3 Module 2: 4112rpm 60pwm(23%) Front-To-Back
|
||||
Fan 4 Module 2: 4372rpm 60pwm(23%) Front-To-Back
|
||||
Fan 5 Module 3: 4072rpm 60pwm(23%) Front-To-Back
|
||||
Fan 6 Module 3: 4306rpm 60pwm(23%) Front-To-Back
|
||||
Fan 7 Module 4: 4134rpm 60pwm(23%) Front-To-Back
|
||||
Fan 8 Module 4: 4326rpm 60pwm(23%) Front-To-Back
|
||||
|
||||
System Fan Airflow: Front-To-Back
|
||||
|
||||
Power Supply 1: Front-To-Back [DPS-460KB C]
|
||||
Power Supply 2: Front-To-Back [DPS-460KB C]
|
||||
|
||||
Power Faults: PS1-Pwr
|
||||
Fan Faults: None
|
||||
Service Faults: Too-Few-PS
|
||||
|
||||
104
tests/unit/plugins/modules/network/enos/test_enos_command.py
Normal file
104
tests/unit/plugins/modules/network/enos/test_enos_command.py
Normal file
|
|
@ -0,0 +1,104 @@
|
|||
# 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
|
||||
|
||||
from ansible_collections.community.general.tests.unit.compat.mock import patch
|
||||
from ansible_collections.community.general.plugins.modules.network.enos import enos_command
|
||||
from ansible_collections.community.general.tests.unit.plugins.modules.utils import set_module_args
|
||||
from .enos_module import TestEnosModule, load_fixture
|
||||
|
||||
|
||||
class TestEnosCommandModule(TestEnosModule):
|
||||
|
||||
module = enos_command
|
||||
|
||||
def setUp(self):
|
||||
super(TestEnosCommandModule, self).setUp()
|
||||
self.mock_run_commands = patch('ansible_collections.community.general.plugins.modules.network.enos.enos_command.run_commands')
|
||||
self.run_commands = self.mock_run_commands.start()
|
||||
|
||||
def tearDown(self):
|
||||
super(TestEnosCommandModule, 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 = 'show version'
|
||||
filename = str(command).replace(' ', '_')
|
||||
output.append(load_fixture(filename))
|
||||
return output
|
||||
|
||||
self.run_commands.side_effect = load_from_file
|
||||
|
||||
def test_enos_command_simple(self):
|
||||
set_module_args(dict(commands=['show version']))
|
||||
result = self.execute_module()
|
||||
self.assertEqual(len(result['stdout']), 1)
|
||||
self.assertTrue(result['stdout'][0].startswith('System Information'))
|
||||
|
||||
def test_enos_command_multiple(self):
|
||||
set_module_args(dict(commands=['show version', 'show run']))
|
||||
result = self.execute_module()
|
||||
self.assertEqual(len(result['stdout']), 2)
|
||||
self.assertTrue(result['stdout'][0].startswith('System Information'))
|
||||
|
||||
def test_enos_command_wait_for(self):
|
||||
wait_for = 'result[0] contains "System Information"'
|
||||
set_module_args(dict(commands=['show version'], wait_for=wait_for))
|
||||
self.execute_module()
|
||||
|
||||
def test_enos_command_wait_for_fails(self):
|
||||
wait_for = 'result[0] contains "test string"'
|
||||
set_module_args(dict(commands=['show version'], wait_for=wait_for))
|
||||
self.execute_module(failed=True)
|
||||
self.assertEqual(self.run_commands.call_count, 10)
|
||||
|
||||
def test_enos_command_retries(self):
|
||||
wait_for = 'result[0] contains "test string"'
|
||||
set_module_args(dict(commands=['show version'], wait_for=wait_for, retries=2))
|
||||
self.execute_module(failed=True)
|
||||
self.assertEqual(self.run_commands.call_count, 2)
|
||||
|
||||
def test_enos_command_match_any(self):
|
||||
wait_for = ['result[0] contains "System Information"',
|
||||
'result[0] contains "test string"']
|
||||
set_module_args(dict(commands=['show version'], wait_for=wait_for, match='any'))
|
||||
self.execute_module()
|
||||
|
||||
def test_enos_command_match_all(self):
|
||||
wait_for = ['result[0] contains "System Information"',
|
||||
'result[0] contains "Lenovo"']
|
||||
set_module_args(dict(commands=['show version'], wait_for=wait_for, match='all'))
|
||||
self.execute_module()
|
||||
|
||||
def test_enos_command_match_all_failure(self):
|
||||
wait_for = ['result[0] contains "Lenovo ENOS"',
|
||||
'result[0] contains "test string"']
|
||||
commands = ['show version', 'show run']
|
||||
set_module_args(dict(commands=commands, wait_for=wait_for, match='all'))
|
||||
self.execute_module(failed=True)
|
||||
125
tests/unit/plugins/modules/network/enos/test_enos_config.py
Normal file
125
tests/unit/plugins/modules/network/enos/test_enos_config.py
Normal 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
|
||||
|
||||
from ansible_collections.community.general.tests.unit.compat.mock import patch
|
||||
from ansible_collections.community.general.plugins.modules.network.enos import enos_config
|
||||
from .enos_module import TestEnosModule, load_fixture
|
||||
|
||||
from ansible_collections.community.general.tests.unit.plugins.modules.utils import set_module_args
|
||||
|
||||
|
||||
class TestEnosConfigModule(TestEnosModule):
|
||||
|
||||
module = enos_config
|
||||
|
||||
def setUp(self):
|
||||
self.patcher_get_config = patch('ansible_collections.community.general.plugins.modules.network.enos.enos_config.get_config')
|
||||
self.mock_get_config = self.patcher_get_config.start()
|
||||
self.patcher_exec_command = patch('ansible_collections.community.general.plugins.modules.network.enos.enos_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 = 'enos_config_config.cfg'
|
||||
self.mock_get_config.return_value = load_fixture(config_file)
|
||||
self.mock_exec_command.return_value = 'dummy diff'
|
||||
|
||||
def test_enos_config_unchanged(self):
|
||||
src = load_fixture('enos_config_config.cfg')
|
||||
set_module_args(dict(src=src))
|
||||
self.execute_module()
|
||||
|
||||
def test_enos_config_src(self):
|
||||
src = load_fixture('enos_config_src.cfg')
|
||||
set_module_args(dict(src=src))
|
||||
commands = ['hostname foo', 'interface ip 13',
|
||||
'no ip ospf enable']
|
||||
self.execute_module(changed=True, commands=commands)
|
||||
|
||||
def test_enos_config_backup(self):
|
||||
set_module_args(dict(backup=True))
|
||||
result = self.execute_module()
|
||||
self.assertIn('__backup__', result)
|
||||
|
||||
def test_enos_config_lines_wo_parents(self):
|
||||
set_module_args(dict(lines=['hostname foo']))
|
||||
commands = ['hostname foo']
|
||||
self.execute_module(changed=True, commands=commands)
|
||||
|
||||
def test_enos_config_lines_w_parents(self):
|
||||
set_module_args(dict(lines=['shutdown'], parents=['interface ip 13']))
|
||||
commands = ['interface ip 13', 'shutdown']
|
||||
self.execute_module(changed=True, commands=commands)
|
||||
|
||||
def test_enos_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_enos_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_enos_config_before_after_no_change(self):
|
||||
set_module_args(dict(lines=['hostname router'],
|
||||
before=['test1', 'test2'],
|
||||
after=['test3', 'test4']))
|
||||
self.execute_module()
|
||||
|
||||
def test_enos_config_config(self):
|
||||
config = 'hostname localhost'
|
||||
set_module_args(dict(lines=['hostname router'], config=config))
|
||||
commands = ['hostname router']
|
||||
self.execute_module(changed=True, commands=commands)
|
||||
|
||||
def test_enos_config_replace_block(self):
|
||||
lines = ['description test string', 'test string']
|
||||
parents = ['interface ip 13']
|
||||
set_module_args(dict(lines=lines, replace='block', parents=parents))
|
||||
commands = parents + lines
|
||||
self.execute_module(changed=True, commands=commands)
|
||||
|
||||
def test_enos_config_match_none(self):
|
||||
lines = ['ip address 1.2.3.4 255.255.255.0', 'description test string']
|
||||
parents = ['interface ip 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_enos_config_match_strict(self):
|
||||
lines = ['ip address 1.2.3.4 255.255.255.0', 'exit']
|
||||
parents = ['interface ip 13']
|
||||
set_module_args(dict(lines=lines, parents=parents, match='strict'))
|
||||
commands = parents + ['exit']
|
||||
self.execute_module(changed=True, commands=commands, sort=False)
|
||||
|
||||
def test_enos_config_match_exact(self):
|
||||
lines = ['ip address 1.2.3.4 255.255.255.0', 'description test string',
|
||||
'shutdown']
|
||||
parents = ['interface ip 13']
|
||||
set_module_args(dict(lines=lines, parents=parents, match='exact'))
|
||||
commands = parents + lines
|
||||
self.execute_module(changed=True, commands=commands, sort=False)
|
||||
82
tests/unit/plugins/modules/network/enos/test_enos_facts.py
Normal file
82
tests/unit/plugins/modules/network/enos/test_enos_facts.py
Normal 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_collections.community.general.tests.unit.compat.mock import patch
|
||||
from .enos_module import TestEnosModule, load_fixture
|
||||
from ansible_collections.community.general.plugins.modules.network.enos import enos_facts
|
||||
from ansible_collections.community.general.tests.unit.plugins.modules.utils import set_module_args
|
||||
|
||||
|
||||
class TestEnosFacts(TestEnosModule):
|
||||
|
||||
module = enos_facts
|
||||
|
||||
def setUp(self):
|
||||
super(TestEnosFacts, self).setUp()
|
||||
self.mock_run_commands = patch(
|
||||
'ansible_collections.community.general.plugins.modules.network.enos.enos_facts.run_commands')
|
||||
self.run_commands = self.mock_run_commands.start()
|
||||
|
||||
def tearDown(self):
|
||||
super(TestEnosFacts, 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_enos_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.assertEqual('test1', ansible_facts['ansible_net_hostname'])
|
||||
self.assertIn('MGT', ansible_facts['ansible_net_interfaces'].keys())
|
||||
self.assertEqual(3992.75390625, ansible_facts['ansible_net_memtotal_mb'])
|
||||
self.assertEqual(3383.109375, ansible_facts['ansible_net_memfree_mb'])
|
||||
|
||||
def test_enos_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.assertEqual('test1', ansible_facts['ansible_net_hostname'])
|
||||
self.assertIn('ansible_net_config', ansible_facts)
|
||||
Loading…
Add table
Add a link
Reference in a new issue