mirror of
https://github.com/ansible-collections/community.general.git
synced 2026-04-19 07:11:25 +00:00
Added new module - frr_facts (#51804)
* Add new module frr_facts Signed-off-by: NilashishC <nilashishchakraborty8@gmail.com> * Fix return value Signed-off-by: NilashishC <nilashishchakraborty8@gmail.com> * Fix review comments Signed-off-by: NilashishC <nilashishchakraborty8@gmail.com> * Fix review comments Signed-off-by: NilashishC <nilashishchakraborty8@gmail.com> * Handle empty row for mpls ldp neighbors Signed-off-by: NilashishC <nilashishchakraborty8@gmail.com> * Fix review comments Signed-off-by: NilashishC <nilashishchakraborty8@gmail.com> * Fix CI Signed-off-by: NilashishC <nilashishchakraborty8@gmail.com> * Remove timestamp from cliconf pluging * Updated examples Signed-off-by: NilashishC <nilashishchakraborty8@gmail.com> * Fix sanity tests Signed-off-by: NilashishC <nilashishchakraborty8@gmail.com>
This commit is contained in:
committed by
GitHub
parent
2b9341f139
commit
bc403dbcda
0
test/units/modules/network/frr/__init__.py
Normal file
0
test/units/modules/network/frr/__init__.py
Normal file
0
test/units/modules/network/frr/fixtures/__init__.py
Normal file
0
test/units/modules/network/frr/fixtures/__init__.py
Normal file
@@ -0,0 +1,36 @@
|
||||
Interface eth0 is up, line protocol is up
|
||||
Link ups: 0 last: (never)
|
||||
Link downs: 0 last: (never)
|
||||
vrf: Default-IP-Routing-Table
|
||||
index 2 metric 0 mtu 1450 speed 0
|
||||
flags: <UP,BROADCAST,RUNNING,MULTICAST>
|
||||
Type: Ethernet
|
||||
HWaddr: fa:16:3e:d4:32:b2
|
||||
bandwidth 4048 Mbps
|
||||
inet 192.168.1.8/24 broadcast 192.168.1.255
|
||||
inet6 fe80::f816:3eff:fed4:32b2/64
|
||||
Interface Type Other
|
||||
Interface eth1 is up, line protocol is up
|
||||
Link ups: 0 last: (never)
|
||||
Link downs: 0 last: (never)
|
||||
vrf: Default-IP-Routing-Table
|
||||
Description: Secondary Interface
|
||||
index 3 metric 0 mtu 1500 speed 0
|
||||
flags: <UP,BROADCAST,RUNNING,MULTICAST>
|
||||
Type: Ethernet
|
||||
HWaddr: fa:16:3e:95:88:f7
|
||||
inet 192.168.1.21/24 broadcast 192.168.1.255
|
||||
inet 192.168.1.19/24 broadcast 192.168.1.255 secondary
|
||||
inet 192.168.1.18/24 broadcast 192.168.1.255 secondary
|
||||
inet6 fe80::f816:3eff:fe95:88f7/64
|
||||
inet6 3ffe:506::1/48
|
||||
inet6 3ffe:504::1/48
|
||||
Interface Type Other
|
||||
Interface lo is up, line protocol is up
|
||||
Link ups: 0 last: (never)
|
||||
Link downs: 0 last: (never)
|
||||
vrf: Default-IP-Routing-Table
|
||||
index 1 metric 0 mtu 65536 speed 0
|
||||
flags: <UP,LOOPBACK,RUNNING>
|
||||
Type: Loopback
|
||||
Interface Type Other
|
||||
@@ -0,0 +1,82 @@
|
||||
Memory statistics for zebra:
|
||||
System allocator statistics:
|
||||
Total heap allocated: 4200 KiB
|
||||
Holding block headers: 0 bytes
|
||||
Used small blocks: 0 bytes
|
||||
Used ordinary blocks: 2927 KiB
|
||||
Free small blocks: 2096 bytes
|
||||
Free ordinary blocks: 1273 KiB
|
||||
Ordinary blocks: 14
|
||||
Small blocks: 60
|
||||
Holding blocks: 0
|
||||
(see system documentation for 'mallinfo' for meaning)
|
||||
--- qmem libfrr ---
|
||||
Buffer : 18 24 448
|
||||
Buffer data : 1 4120 4120
|
||||
Host config : 4 (variably sized) 96
|
||||
Command Tokens : 3162 72 228128
|
||||
Command Token Text : 2362 (variably sized) 77344
|
||||
Command Token Help : 2362 (variably sized) 56944
|
||||
Command Argument : 2 (variably sized) 48
|
||||
Command Argument Name : 534 (variably sized) 12912
|
||||
FRR POSIX Thread : 28 (variably sized) 2016
|
||||
POSIX synchronization primitives: 28 (variably sized) 1344
|
||||
Graph : 24 8 576
|
||||
Graph Node : 3744 32 150112
|
||||
Hash : 2495 (variably sized) 119880
|
||||
Hash Bucket : 778 32 31296
|
||||
Hash Index : 1248 (variably sized) 363040
|
||||
Hook entry : 12 48 672
|
||||
Interface : 3 248 744
|
||||
Connected : 8 40 320
|
||||
Informational Link Parameters : 1 96 104
|
||||
Link List : 43 40 1720
|
||||
Link Node : 1308 24 31456
|
||||
Logging : 1 80 88
|
||||
Temporary memory : 23 (variably sized) 42584
|
||||
Nexthop : 27 112 3256
|
||||
NetNS Context : 2 (variably sized) 128
|
||||
NetNS Name : 1 18 24
|
||||
Priority queue : 15 32 600
|
||||
Priority queue data : 15 256 3960
|
||||
Prefix : 12 48 672
|
||||
Privilege information : 2 (variably sized) 80
|
||||
Stream : 36 (variably sized) 591264
|
||||
Stream FIFO : 28 64 2016
|
||||
Route table : 14 48 784
|
||||
Route node : 43 (variably sized) 4920
|
||||
Thread : 51 176 9384
|
||||
Thread master : 59 (variably sized) 251016
|
||||
Thread Poll Info : 30 8192 246000
|
||||
Thread stats : 52 64 3744
|
||||
Vector : 7543 16 181432
|
||||
Vector index : 7543 (variably sized) 246776
|
||||
VRF : 1 184 184
|
||||
VRF bit-map : 28 8 672
|
||||
VTY : 6 (variably sized) 19440
|
||||
Work queue : 2 (variably sized) 224
|
||||
Work queue name string : 1 22 24
|
||||
Redistribution instance IDs : 1 2 24
|
||||
--- qmem Label Manager ---
|
||||
Label Manager Chunk : 1 16 24
|
||||
--- qmem zebra ---
|
||||
ZEBRA VRF : 1 656 664
|
||||
Route Entry : 27 80 2392
|
||||
RIB destination : 19 48 1080
|
||||
RIB table info : 4 16 96
|
||||
Nexthop tracking object : 2 200 400
|
||||
Zebra Name Space : 1 312 312
|
||||
PTM BFD process registration table.: 3 32 120
|
||||
--- qmem Table Manager ---
|
||||
|
||||
Memory statistics for ripd:
|
||||
System allocator statistics:
|
||||
Total heap allocated: 936 KiB
|
||||
Holding block headers: 0 bytes
|
||||
Used small blocks: 0 bytes
|
||||
Used ordinary blocks: 901 KiB
|
||||
Free small blocks: 1504 bytes
|
||||
Free ordinary blocks: 35 KiB
|
||||
Ordinary blocks: 4
|
||||
Small blocks: 44
|
||||
Holding blocks: 0
|
||||
@@ -0,0 +1,16 @@
|
||||
FRRouting 6.0 (rtr1).
|
||||
Copyright 1996-2005 Kunihiro Ishiguro, et al.
|
||||
configured with:
|
||||
'--build=x86_64-redhat-linux-gnu' '--host=x86_64-redhat-linux-gnu' '--program-prefix='
|
||||
'--disable-dependency-tracking' '--prefix=/usr' '--exec-prefix=/usr' '--bindir=/usr/bin'
|
||||
'--sysconfdir=/etc' '--datadir=/usr/share' '--includedir=/usr/include' '--libdir=/usr/lib64'
|
||||
'--libexecdir=/usr/libexec' '--localstatedir=/var' '--sharedstatedir=/var/lib' '--mandir=/usr/share/man'
|
||||
'--infodir=/usr/share/info' '--sbindir=/usr/lib/frr' '--sysconfdir=/etc/frr' '--localstatedir=/var/run/frr'
|
||||
'--disable-static' '--disable-werror' '--enable-irdp' '--enable-multipath=256' '--enable-vtysh'
|
||||
'--enable-ospfclient' '--enable-ospfapi' '--enable-rtadv' '--enable-ldpd' '--enable-pimd'
|
||||
'--enable-pbrd' '--enable-nhrpd' '--enable-eigrpd' '--enable-babeld' '--enable-user=frr'
|
||||
'--enable-group=frr' '--enable-vty-group=frrvty' '--enable-fpm' '--enable-watchfrr' '--disable-bgp-vnc'
|
||||
'--enable-isisd' '--enable-systemd' '--disable-rpki' '--enable-bfdd' 'build_alias=x86_64-redhat-linux-gnu'
|
||||
'host_alias=x86_64-redhat-linux-gnu' 'PKG_CONFIG_PATH=:/usr/lib64/pkgconfig:/usr/share/pkgconfig'
|
||||
'CFLAGS=-O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector-strong
|
||||
--param=ssp-buffer-size=4 -grecord-gcc-switches -m64 -mtune=generic' 'LDFLAGS=-Wl,-z,relro '
|
||||
75
test/units/modules/network/frr/frr_module.py
Normal file
75
test/units/modules/network/frr/frr_module.py
Normal file
@@ -0,0 +1,75 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
# (c) 2019, Ansible by Red Hat, inc
|
||||
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
|
||||
|
||||
from __future__ import (absolute_import, division, print_function)
|
||||
__metaclass__ = type
|
||||
|
||||
import os
|
||||
import json
|
||||
|
||||
from units.modules.utils import AnsibleExitJson, AnsibleFailJson, ModuleTestCase
|
||||
|
||||
|
||||
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 TestFrrModule(ModuleTestCase):
|
||||
|
||||
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):
|
||||
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):
|
||||
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
|
||||
114
test/units/modules/network/frr/test_frr_facts.py
Normal file
114
test/units/modules/network/frr/test_frr_facts.py
Normal file
@@ -0,0 +1,114 @@
|
||||
# (c) 2019, Ansible by Red Hat, inc
|
||||
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
|
||||
|
||||
from __future__ import (absolute_import, division, print_function)
|
||||
__metaclass__ = type
|
||||
|
||||
from units.compat.mock import patch
|
||||
from ansible.modules.network.frr import frr_facts
|
||||
from units.modules.utils import set_module_args
|
||||
from .frr_module import TestFrrModule, load_fixture
|
||||
|
||||
|
||||
class TestFrrFactsModule(TestFrrModule):
|
||||
|
||||
module = frr_facts
|
||||
|
||||
def setUp(self):
|
||||
super(TestFrrFactsModule, self).setUp()
|
||||
self.mock_run_commands = patch('ansible.modules.network.frr.frr_facts.run_commands')
|
||||
self.run_commands = self.mock_run_commands.start()
|
||||
|
||||
self.mock_get_capabilities = patch('ansible.modules.network.frr.frr_facts.get_capabilities')
|
||||
self.get_capabilities = self.mock_get_capabilities.start()
|
||||
self.get_capabilities.return_value = {
|
||||
'device_info': {
|
||||
'network_os': 'frr',
|
||||
'network_os_hostname': 'rtr1',
|
||||
'network_os_version': '6.0',
|
||||
},
|
||||
'supported_protocols': {
|
||||
'ldp': False
|
||||
},
|
||||
'network_api': 'cliconf'
|
||||
}
|
||||
|
||||
def tearDown(self):
|
||||
super(TestFrrFactsModule, self).tearDown()
|
||||
self.mock_run_commands.stop()
|
||||
self.mock_get_capabilities.stop()
|
||||
|
||||
def load_fixtures(self, commands=None):
|
||||
def load_from_file(*args, **kwargs):
|
||||
commands = kwargs['commands']
|
||||
output = list()
|
||||
|
||||
for command in commands:
|
||||
filename = str(command).split(' | ')[0].replace(' ', '_')
|
||||
output.append(load_fixture('frr_facts_%s' % filename))
|
||||
return output
|
||||
|
||||
self.run_commands.side_effect = load_from_file
|
||||
|
||||
def test_frr_facts_default(self):
|
||||
set_module_args(dict(gather_subset='default'))
|
||||
result = self.execute_module()
|
||||
self.assertEqual(
|
||||
result['ansible_facts']['ansible_net_hostname'], 'rtr1'
|
||||
)
|
||||
self.assertEqual(
|
||||
result['ansible_facts']['ansible_net_version'], '6.0'
|
||||
)
|
||||
self.assertEqual(
|
||||
result['ansible_facts']['ansible_net_system'], 'frr'
|
||||
)
|
||||
|
||||
def test_frr_facts_interfaces(self):
|
||||
set_module_args(dict(gather_subset='interfaces'))
|
||||
result = self.execute_module()
|
||||
self.assertEqual(
|
||||
result['ansible_facts']['ansible_net_interfaces']['eth0']['macaddress'], 'fa:16:3e:d4:32:b2'
|
||||
)
|
||||
self.assertEqual(
|
||||
result['ansible_facts']['ansible_net_interfaces']['eth1']['macaddress'], 'fa:16:3e:95:88:f7'
|
||||
)
|
||||
self.assertEqual(
|
||||
result['ansible_facts']['ansible_net_interfaces']['eth0']['ipv4'], [{"address": "192.168.1.8",
|
||||
"subnet": "24"}]
|
||||
)
|
||||
self.assertEqual(
|
||||
result['ansible_facts']['ansible_net_interfaces']['eth0']['ipv6'], [{"address": "fe80::f816:3eff:fed4:32b2",
|
||||
"subnet": "64"}]
|
||||
)
|
||||
self.assertEqual(
|
||||
sorted(result['ansible_facts']['ansible_net_all_ipv4_addresses']), sorted(["192.168.1.19",
|
||||
"192.168.1.18",
|
||||
"192.168.1.21",
|
||||
"192.168.1.8"])
|
||||
)
|
||||
self.assertEqual(
|
||||
sorted(result['ansible_facts']['ansible_net_all_ipv6_addresses']), sorted(["fe80::f816:3eff:fe95:88f7",
|
||||
"3ffe:506::1",
|
||||
"3ffe:504::1",
|
||||
"fe80::f816:3eff:fed4:32b2"])
|
||||
)
|
||||
|
||||
def test_frr_facts_hardware(self):
|
||||
set_module_args(dict(gather_subset='hardware'))
|
||||
result = self.execute_module()
|
||||
|
||||
self.assertEqual(
|
||||
result['ansible_facts']['ansible_net_mem_stats']["zebra"]['total_heap_allocated'], '4200 KiB'
|
||||
)
|
||||
|
||||
self.assertEqual(
|
||||
result['ansible_facts']['ansible_net_mem_stats']["ripd"]['total_heap_allocated'], '936 KiB'
|
||||
)
|
||||
|
||||
self.assertEqual(
|
||||
result['ansible_facts']['ansible_net_mem_stats']["ripd"]['used_ordinary_blocks'], '901 KiB'
|
||||
)
|
||||
|
||||
self.assertEqual(
|
||||
result['ansible_facts']['ansible_net_mem_stats']["ripd"]['holding_block_headers'], '0 bytes'
|
||||
)
|
||||
Reference in New Issue
Block a user