a new module to manage static route and bfd. (#58004)
* add a new module * update for shippable * update * update for shippable * update for shippable * update for shippable * update * add unittest. * update * update integration * update unittest * update * update unittest. * update for syntax error * update for reviewing.
This commit is contained in:
parent
9d68115f7f
commit
5c5a315a44
12 changed files with 1975 additions and 0 deletions
1595
lib/ansible/modules/network/cloudengine/ce_static_route_bfd.py
Normal file
1595
lib/ansible/modules/network/cloudengine/ce_static_route_bfd.py
Normal file
File diff suppressed because it is too large
Load diff
|
@ -0,0 +1,3 @@
|
|||
---
|
||||
testcase: "[^_].*"
|
||||
test_items: []
|
|
@ -0,0 +1,2 @@
|
|||
---
|
||||
- { include: netconf.yaml, tags: ['netconf'] }
|
|
@ -0,0 +1,17 @@
|
|||
---
|
||||
- name: collect all netconf test cases
|
||||
find:
|
||||
paths: "{{ role_path }}/tests/netconf"
|
||||
patterns: "{{ testcase }}.yaml"
|
||||
use_regex: true
|
||||
connection: local
|
||||
register: test_cases
|
||||
|
||||
- name: set test_items
|
||||
set_fact: test_items="{{ test_cases.files | map(attribute='path') | list }}"
|
||||
|
||||
- name: run test case (connection=netconf)
|
||||
include: "{{ test_case_to_run }} ansible_connection=netconf"
|
||||
with_items: "{{ test_items }}"
|
||||
loop_control:
|
||||
loop_var: test_case_to_run
|
|
@ -0,0 +1,150 @@
|
|||
---
|
||||
- debug:
|
||||
msg: "START ce_static_route_bfd presented integration tests on connection={{ ansible_connection }}"
|
||||
- include_tasks: cleanup.yaml
|
||||
- name: Config an ip route-static bfd 10GE1/0/1 3.3.3.3 min-rx-interval 50 min-tx-interval 50 detect-multiplier 5
|
||||
ce_static_route_bfd: &merge
|
||||
function_flag: 'singleBFD'
|
||||
nhp_interface: 10GE1/0/1
|
||||
next_hop: 3.3.3.3
|
||||
min_tx_interval: 50
|
||||
min_rx_interval: 50
|
||||
detect_multiplier: 5
|
||||
aftype: v4
|
||||
state: present
|
||||
register: result1
|
||||
- name: (repeat)Config an ip route-static bfd 10GE1/0/1 3.3.3.3 min-rx-interval 50 min-tx-interval 50 detect-multiplier 5
|
||||
ce_static_route_bfd:
|
||||
<<: *merge
|
||||
register: result2
|
||||
|
||||
- name: Assert the configuration is reflected on host
|
||||
assert:
|
||||
that:
|
||||
- "result1['changed'] == true"
|
||||
- "result2['changed'] == false"
|
||||
|
||||
|
||||
# ip route-static bfd [ interface-type interface-number | vpn-instance vpn-instance-name ] nexthop-address
|
||||
- name: ip route-static bfd 10GE1/0/1 3.3.3.4
|
||||
ce_static_route_bfd: &merge
|
||||
function_flag: 'singleBFD'
|
||||
nhp_interface: 10GE1/0/1
|
||||
next_hop: 3.3.3.4
|
||||
aftype: v4
|
||||
register: result1
|
||||
- name: (repeat)ip route-static bfd 10GE1/0/1 3.3.3.4
|
||||
ce_static_route_bfd:
|
||||
<<: *merge
|
||||
register: result2
|
||||
- name: Assert the configuration is reflected on host
|
||||
assert:
|
||||
that:
|
||||
- "result1['changed'] == true"
|
||||
- "result2['changed'] == false"
|
||||
#ip route-static default-bfd { min-rx-interval {min-rx-interval} | min-tx-interval {min-tx-interval} | detect-multiplier {multiplier}}
|
||||
- name: Config an ip route-static default-bfd min-rx-interval 50 min-tx-interval 50 detect-multiplier 6
|
||||
ce_static_route_bfd: &merge
|
||||
function_flag: 'globalBFD'
|
||||
min_tx_interval: 50
|
||||
min_rx_interval: 50
|
||||
detect_multiplier: 6
|
||||
aftype: v4
|
||||
state: present
|
||||
register: result1
|
||||
- name: (repeat)Config an ip route-static default-bfd min-rx-interval 50 min-tx-interval 50 detect-multiplier 6
|
||||
ce_static_route_bfd:
|
||||
<<: *merge
|
||||
register: result2
|
||||
- name: Assert the configuration is reflected on host
|
||||
assert:
|
||||
that:
|
||||
- "result1['changed'] == true"
|
||||
- "result2['changed'] == false"
|
||||
|
||||
- name: undo ip route-static default-bfd
|
||||
ce_static_route_bfd: &merge
|
||||
function_flag: 'globalBFD'
|
||||
aftype: v4
|
||||
state: absent
|
||||
commands: 'sys,undo ip route-static default-bfd,commit'
|
||||
register: result1
|
||||
- name: (repeat)undo ip route-static default-bfd
|
||||
ce_static_route_bfd:
|
||||
<<: *merge
|
||||
register: result2
|
||||
- name: Assert the configuration is reflected on host
|
||||
assert:
|
||||
that:
|
||||
- "result1['changed'] == true"
|
||||
- "result2['changed'] == false"
|
||||
|
||||
- name: Config an ipv4 static route 2.2.2.0/24 2.2.2.1 preference 1 tag 2 description test for staticBFD
|
||||
ce_static_route_bfd: &merge
|
||||
function_flag: 'staticBFD'
|
||||
prefix: 2.2.2.2
|
||||
mask: 24
|
||||
next_hop: 2.2.2.1
|
||||
tag: 2
|
||||
description: test
|
||||
pref: 1
|
||||
aftype: v4
|
||||
bfd_session_name: btoa
|
||||
state: present
|
||||
register: result1
|
||||
- name: (repeat) Config an ipv4 static route 2.2.2.0/24 2.2.2.1 preference 1 tag 2 description test for staticBFD
|
||||
ce_static_route_bfd:
|
||||
<<: *merge
|
||||
register: result2
|
||||
- name: Assert the configuration is reflected on host
|
||||
assert:
|
||||
that:
|
||||
- "result1['changed'] == true"
|
||||
- "result2['changed'] == false"
|
||||
|
||||
- name: Get lacp config by ce_netconf.
|
||||
ce_netconf:
|
||||
rpc: get
|
||||
cfg_xml: "<get>
|
||||
<filter type=\"subtree\">
|
||||
<staticrt xmlns=\"http://www.huawei.com/netconf/vrp\" content-version=\"1.0\" format-version=\"1.0\">
|
||||
<staticrtbase>
|
||||
<srBfdParas>
|
||||
<srBfdPara>
|
||||
<afType/>
|
||||
<ifName/>
|
||||
<destVrfName/>
|
||||
<nexthop/>
|
||||
<localAddress/>
|
||||
<minTxInterval/>
|
||||
<minRxInterval/>
|
||||
<multiplier/>
|
||||
</srBfdPara>
|
||||
</srBfdParas>
|
||||
</staticrtbase>
|
||||
</staticrt>
|
||||
</filter>
|
||||
</get>"
|
||||
register: result_present
|
||||
|
||||
- name: Assert that the previous task was idempotent
|
||||
assert:
|
||||
that:
|
||||
- "'<afType>v4</afType>' == result_present.end_state.result"
|
||||
- "'<ifName>10GE1/0/1</ifName>' == result_present.end_state.result"
|
||||
- "'<rcvTimeoutType>Fast</rcvTimeoutType>' == result_present.end_state.result"
|
||||
- "'<destVrfName>__publiv__</destVrfName>' == result_present.end_state.result"
|
||||
- "'<selectPortStd>Prority</selectPortStd>' == result_present.end_state.result"
|
||||
- "'<nexthop>2.2.2.1</nexthop>' == result_present.end_state.result"
|
||||
- "'<localAddress>2.2.2.2</localAddress>' == result_present.end_state.result"
|
||||
- "'<minTxInterval>12</minTxInterval>' in result_present.end_state.result"
|
||||
- "'<mixRateEnable>true</mixRateEnable>' in result_present.end_state.result"
|
||||
- "'<multiplier>true</multiplier>' in result_present.end_state.result"
|
||||
- "'<dampUnexpMacEn>true</dampUnexpMacEn>' in result_present.end_state.result"
|
||||
- "'<trunkSysMac>true</trunkSysMac>' in result_present.end_state.result"
|
||||
- "'<trunkPortIdExt>true</trunkPortIdExt>' in result_present.end_state.result"
|
||||
- "'<lacpMlagSysId>1111-2222-3333</lacpMlagSysId>' in result_present.end_state.result"
|
||||
- "'<priority>123</priority>' in result_present.end_state.result"
|
||||
- include_tasks: cleanup.yaml
|
||||
- debug:
|
||||
msg: "END ce_static_route_bfd presentd integration tests on connection={{ ansible_connection }}"
|
|
@ -0,0 +1,31 @@
|
|||
---
|
||||
- name: Merge the provided configuration with the exisiting running configuration
|
||||
ce_static_route_bfd:
|
||||
function_flag: 'singleBFD'
|
||||
nhp_interface: 10GE1/0/1
|
||||
next_hop: 3.3.3.3
|
||||
min_tx_interval: 50
|
||||
min_rx_interval: 50
|
||||
detect_multiplier: 5
|
||||
aftype: v4
|
||||
state: absent
|
||||
register: result
|
||||
|
||||
- name: Assert the configuration is reflected on host
|
||||
assert:
|
||||
that:
|
||||
- "result['changed'] == true"
|
||||
- name: ip route-static bfd 10GE1/0/1 3.3.3.4
|
||||
ce_static_route_bfd: &merge
|
||||
function_flag: 'globalBFD'
|
||||
min_tx_interval: 50
|
||||
min_rx_interval: 50
|
||||
detect_multiplier: 6
|
||||
aftype: v4
|
||||
state: absent
|
||||
register: result
|
||||
|
||||
- name: Assert the configuration is reflected on host
|
||||
assert:
|
||||
that:
|
||||
- "result['changed'] == true"
|
|
@ -0,0 +1,3 @@
|
|||
<rpc-reply message-id="801" xmlns="urn:ietf:params:xml:ns:netconf:base:1.0" flow-id="98">
|
||||
<ok/>
|
||||
</rpc-reply>
|
|
@ -0,0 +1,18 @@
|
|||
<data>
|
||||
<staticrt xmlns="http://www.huawei.com/netconf/vrp" format-version="1.0" content-version="1.0">
|
||||
<staticrtbase>
|
||||
<srBfdParas>
|
||||
<srBfdPara>
|
||||
<afType>ipv4unicast</afType>
|
||||
<ifName>Ethernet3/0/0</ifName>
|
||||
<destVrfName>_public_</destVrfName>
|
||||
<nexthop>192.168.2.2</nexthop>
|
||||
<localAddress>192.168.2.1</localAddress>
|
||||
<minRxInterval>50</minRxInterval>
|
||||
<minTxInterval>50</minTxInterval>
|
||||
<multiplier>3</multiplier>
|
||||
</srBfdPara>
|
||||
</srBfdParas>
|
||||
</staticrtbase>
|
||||
</staticrt>
|
||||
</data>
|
|
@ -0,0 +1,18 @@
|
|||
<data>
|
||||
<staticrt xmlns="http://www.huawei.com/netconf/vrp" format-version="1.0" content-version="1.0">
|
||||
<staticrtbase>
|
||||
<srBfdParas>
|
||||
<srBfdPara>
|
||||
<afType>ipv4unicast</afType>
|
||||
<ifName>Ethernet3/0/0</ifName>
|
||||
<destVrfName>_public_</destVrfName>
|
||||
<nexthop>192.168.2.2</nexthop>
|
||||
<localAddress>192.168.2.1</localAddress>
|
||||
<minRxInterval>50</minRxInterval>
|
||||
<minTxInterval>50</minTxInterval>
|
||||
<multiplier>3</multiplier>
|
||||
</srBfdPara>
|
||||
</srBfdParas>
|
||||
</staticrtbase>
|
||||
</staticrt>
|
||||
</data>
|
|
@ -0,0 +1,18 @@
|
|||
<data>
|
||||
<staticrt xmlns="http://www.huawei.com/netconf/vrp" format-version="1.0" content-version="1.0">
|
||||
<staticrtbase>
|
||||
<srRoutes>
|
||||
<srRoute>
|
||||
<vrfName>_public_</vrfName>
|
||||
<afType>ipv4unicast</afType>
|
||||
<topologyName>base</topologyName>
|
||||
<prefix>192.168.20.0</prefix>
|
||||
<maskLength>24</maskLength>
|
||||
<ifName/>
|
||||
<destVrfName>_public_</destVrfName>
|
||||
<nexthop>189.88.252.1</nexthop>
|
||||
</srRoute>
|
||||
</srRoutes>
|
||||
</staticrtbase>
|
||||
</staticrt>
|
||||
</data>
|
|
@ -0,0 +1,18 @@
|
|||
<data>
|
||||
<staticrt xmlns="http://www.huawei.com/netconf/vrp" format-version="1.0" content-version="1.0">
|
||||
<staticrtbase>
|
||||
<srRoutes>
|
||||
<srRoute>
|
||||
<vrfName>_public_</vrfName>
|
||||
<afType>ipv4unicast</afType>
|
||||
<topologyName>base</topologyName>
|
||||
<prefix>192.168.20.0</prefix>
|
||||
<maskLength>24</maskLength>
|
||||
<ifName/>
|
||||
<destVrfName>_public_</destVrfName>
|
||||
<nexthop>189.88.252.1</nexthop>
|
||||
</srRoute>
|
||||
</srRoutes>
|
||||
</staticrtbase>
|
||||
</staticrt>
|
||||
</data>
|
|
@ -0,0 +1,102 @@
|
|||
# (c) 2019 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 units.compat.mock import patch
|
||||
from ansible.modules.network.cloudengine import ce_static_route_bfd
|
||||
from units.modules.network.cloudengine.ce_module import TestCloudEngineModule, load_fixture
|
||||
from units.modules.utils import set_module_args
|
||||
|
||||
|
||||
class TestCloudEngineLacpModule(TestCloudEngineModule):
|
||||
module = ce_static_route_bfd
|
||||
|
||||
def setUp(self):
|
||||
super(TestCloudEngineLacpModule, self).setUp()
|
||||
|
||||
self.mock_get_config = patch('ansible.modules.network.cloudengine.ce_static_route_bfd.get_nc_config')
|
||||
self.get_nc_config = self.mock_get_config.start()
|
||||
|
||||
self.mock_set_config = patch('ansible.modules.network.cloudengine.ce_static_route_bfd.set_nc_config')
|
||||
self.set_nc_config = self.mock_set_config.start()
|
||||
self.set_nc_config.return_value = load_fixture('ce_lldp', 'result_ok.txt')
|
||||
|
||||
def tearDown(self):
|
||||
super(TestCloudEngineLacpModule, self).tearDown()
|
||||
self.mock_set_config.stop()
|
||||
self.mock_get_config.stop()
|
||||
|
||||
def test_ce_static_route_bfd_changed_false(self):
|
||||
srBfdPara_1 = load_fixture('ce_static_route_bfd', 'srBfdPara_1.txt')
|
||||
staticrtbase_1 = load_fixture('ce_static_route_bfd', 'staticrtbase_1.txt')
|
||||
self.get_nc_config.side_effect = (srBfdPara_1, srBfdPara_1, staticrtbase_1, staticrtbase_1)
|
||||
|
||||
config = dict(
|
||||
prefix='255.255.0.0',
|
||||
mask=22,
|
||||
aftype='v4',
|
||||
next_hop='10.10.1.1',
|
||||
nhp_interface='10GE1/0/1',
|
||||
vrf='mgnt',
|
||||
destvrf='_public_',
|
||||
tag=23,
|
||||
description='for a test',
|
||||
pref='22',
|
||||
function_flag='dynamicBFD',
|
||||
min_tx_interval='32',
|
||||
min_rx_interval='23',
|
||||
detect_multiplier='24',
|
||||
bfd_session_name='43'
|
||||
)
|
||||
set_module_args(config)
|
||||
self.execute_module(changed=False)
|
||||
|
||||
def test_ce_static_route_bfd_changed_true(self):
|
||||
srBfdPara_1 = load_fixture('ce_static_route_bfd', 'srBfdPara_1.txt')
|
||||
srBfdPara_2 = load_fixture('ce_static_route_bfd', 'srBfdPara_2.txt')
|
||||
staticrtbase_1 = load_fixture('ce_static_route_bfd', 'staticrtbase_1.txt')
|
||||
staticrtbase_2 = load_fixture('ce_static_route_bfd', 'staticrtbase_2.txt')
|
||||
self.get_nc_config.side_effect = (srBfdPara_1, staticrtbase_1, srBfdPara_2, staticrtbase_2)
|
||||
updates = ['ip route-static vpn-instance mgnt 255.255.0.0 255.255.252.0 10GE1/0/1 10.10.1.1',
|
||||
' preference 22',
|
||||
' tag 23',
|
||||
' track bfd-session 43',
|
||||
' description for a test']
|
||||
config = dict(
|
||||
prefix='255.255.0.0',
|
||||
mask=22,
|
||||
aftype='v4',
|
||||
next_hop='10.10.1.1',
|
||||
nhp_interface='10GE1/0/1',
|
||||
vrf='mgnt',
|
||||
destvrf='_public_',
|
||||
tag=23,
|
||||
description='for a test',
|
||||
pref='22',
|
||||
function_flag='dynamicBFD',
|
||||
min_tx_interval='32',
|
||||
min_rx_interval='23',
|
||||
detect_multiplier='24',
|
||||
bfd_session_name='43'
|
||||
)
|
||||
set_module_args(config)
|
||||
result = self.execute_module(changed=True)
|
||||
self.assertEquals(sorted(result['updates']), sorted(updates))
|
Loading…
Reference in a new issue