mirror of
https://github.com/ansible-collections/community.general.git
synced 2025-10-23 12:33:59 -07:00
Refactoring to persistence connection BGP, factory, reload, save, showrun modules (#43534)
* Refactoring to persistence connection BGP, factory, reload, save, showrun modules * Refactoring methods from Util to module file * Removing BGP Utility methods * Adding to errors that need to be ignored
This commit is contained in:
parent
32c01644d4
commit
119376a685
8 changed files with 1072 additions and 1114 deletions
24
test/units/modules/network/cnos/fixtures/cnos_bgp_config.cfg
Normal file
24
test/units/modules/network/cnos/fixtures/cnos_bgp_config.cfg
Normal file
|
|
@ -0,0 +1,24 @@
|
|||
!
|
||||
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
|
||||
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
|
||||
!
|
||||
|
||||
99
test/units/modules/network/cnos/test_cnos_bgp.py
Normal file
99
test/units/modules/network/cnos/test_cnos_bgp.py
Normal file
|
|
@ -0,0 +1,99 @@
|
|||
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_bgp
|
||||
from units.modules.utils import set_module_args
|
||||
from .cnos_module import TestCnosModule, load_fixture
|
||||
|
||||
|
||||
class TestCnosBgpModule(TestCnosModule):
|
||||
|
||||
module = cnos_bgp
|
||||
|
||||
def setUp(self):
|
||||
super(TestCnosBgpModule, self).setUp()
|
||||
|
||||
self.mock_run_cnos_commands = patch('ansible.module_utils.network.cnos.cnos.run_cnos_commands')
|
||||
self.run_cnos_commands = self.mock_run_cnos_commands.start()
|
||||
|
||||
def tearDown(self):
|
||||
super(TestCnosBgpModule, self).tearDown()
|
||||
self.mock_run_cnos_commands.stop()
|
||||
|
||||
def load_fixtures(self, commands=None, transport='cli'):
|
||||
self.run_cnos_commands.return_value = [load_fixture('cnos_bgp_config.cfg')]
|
||||
|
||||
def test_bgp_neighbor(self):
|
||||
set_module_args({'username': 'admin', 'password': 'pass',
|
||||
'host': '10.241.107.39', 'deviceType': 'g8272_cnos',
|
||||
'outputfile': 'test.log', 'asNum': '33',
|
||||
'bgpArg1': 'neighbor', 'bgpArg2': '10.241.107.40',
|
||||
'bgpArg3': '13', 'bgpArg4': 'address-family',
|
||||
'bgpArg5': 'ipv4', 'bgpArg6': 'next-hop-self'})
|
||||
result = self.execute_module(changed=True)
|
||||
file = open('Anil.txt', "a")
|
||||
file.write(str(result))
|
||||
file.close()
|
||||
expected_result = 'BGP configurations accomplished'
|
||||
self.assertEqual(result['msg'], expected_result)
|
||||
|
||||
def test_cnos_bgp_dampening(self):
|
||||
set_module_args({'username': 'admin', 'password': 'pass',
|
||||
'host': '10.241.107.39', 'deviceType': 'g8272_cnos',
|
||||
'outputfile': 'test.log', 'asNum': '33',
|
||||
'bgpArg1': 'address-family', 'bgpArg2': 'ipv4',
|
||||
'bgpArg3': 'dampening', 'bgpArg4': '13',
|
||||
'bgpArg5': '233', 'bgpArg6': '333',
|
||||
'bgpArg7': '15', 'bgpArg8': '33'})
|
||||
result = self.execute_module(changed=True)
|
||||
expected_result = 'BGP configurations accomplished'
|
||||
self.assertEqual(result['msg'], expected_result)
|
||||
|
||||
def test_cnos_bgp_network(self):
|
||||
set_module_args({'username': 'admin', 'password': 'pass',
|
||||
'host': '10.241.107.39', 'deviceType': 'g8272_cnos',
|
||||
'outputfile': 'test.log', 'asNum': '33',
|
||||
'bgpArg1': 'address-family', 'bgpArg2': 'ipv4',
|
||||
'bgpArg3': 'network', 'bgpArg4': '1.2.3.4/5',
|
||||
'bgpArg5': 'backdoor'})
|
||||
result = self.execute_module(changed=True)
|
||||
expected_result = 'BGP configurations accomplished'
|
||||
self.assertEqual(result['msg'], expected_result)
|
||||
|
||||
def test_cnos_bgp_clusterid(self):
|
||||
set_module_args({'username': 'admin', 'password': 'pass',
|
||||
'host': '10.241.107.39', 'deviceType': 'g8272_cnos',
|
||||
'outputfile': 'test.log', 'asNum': '33',
|
||||
'bgpArg1': 'cluster-id', 'bgpArg2': '10.241.107.40'})
|
||||
result = self.execute_module(changed=True)
|
||||
expected_result = 'BGP configurations accomplished'
|
||||
self.assertEqual(result['msg'], expected_result)
|
||||
|
||||
def test_cnos_bgp_graceful_restart(self):
|
||||
set_module_args({'username': 'admin', 'password': 'pass',
|
||||
'host': '10.241.107.39', 'deviceType': 'g8272_cnos',
|
||||
'outputfile': 'test.log', 'asNum': '33',
|
||||
'bgpArg1': 'graceful-restart', 'bgpArg2': '333'})
|
||||
result = self.execute_module(changed=True)
|
||||
expected_result = 'BGP configurations accomplished'
|
||||
self.assertEqual(result['msg'], expected_result)
|
||||
|
||||
def test_cnos_bgp_routerid(self):
|
||||
set_module_args({'username': 'admin', 'password': 'pass',
|
||||
'host': '10.241.107.39', 'deviceType': 'g8272_cnos',
|
||||
'outputfile': 'test.log', 'asNum': '33',
|
||||
'bgpArg1': 'router-id', 'bgpArg2': '1.2.3.4'})
|
||||
result = self.execute_module(changed=True)
|
||||
expected_result = 'BGP configurations accomplished'
|
||||
self.assertEqual(result['msg'], expected_result)
|
||||
|
||||
def test_cnos_bgp_vrf(self):
|
||||
set_module_args({'username': 'admin', 'password': 'pass',
|
||||
'host': '10.241.107.39', 'deviceType': 'g8272_cnos',
|
||||
'outputfile': 'test.log', 'asNum': '33',
|
||||
'bgpArg1': 'vrf'})
|
||||
result = self.execute_module(changed=True)
|
||||
expected_result = 'BGP configurations accomplished'
|
||||
self.assertEqual(result['msg'], expected_result)
|
||||
Loading…
Add table
Add a link
Reference in a new issue