add a new module ce_lldp_interface. (#58252)

* add a new module ce_lldp_interface.

* update for shipabble

* update

* ad unittest

* update

* update

* update

* update

* update

* upate

* update

* update for shipable.

* update & add intergration tests.

* update for shippable.

* update

* import future.

* update.

* update.

* update docs.

* missing whitespace after ','

* update docs.

* update docs.

* update docs.

* Update ce_lldp_interface.py

* Update ce_lldp_interface.py

* update for reviewing
pull/63952/head
Xu Yuandong 5 years ago committed by John R Barker
parent bfb8b015c9
commit 68c997e4dd

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,155 @@
---
- debug:
msg: "START ce_lldp_interface merged integration tests on connection={{ ansible_connection }}"
- block:
- name: Merge the provided configuration with the exisiting running configuration - basic-tlv
ce_lldp_interface: &merged
config:
msg_interval: 8
ifname: 10GE 1/0/1
admin_status: txandrx
basic_tlv:
management_addr: true
port_desc: true
system_capability: true
system_description: true
system_name: true
register: result1
- name: Merge the provided configuration with the existing running configuration (REPEAT)
ce_lldp_interface: *merged
register: result2
- name: "Netconf get operation"
ce_netconf:
rpc: get
cfg_xml: '<filter type=\"subtree\">
<lldp xmlns=\"http://www.huawei.com/netconf/vrp\" content-version=\"1.0\" format-version=\"1.0\">
<lldpInterfaces>
<lldpInterface>
<ifName>10GE1/0/1</ifName>
<msgInterval>
<txInterval></txInterval>
</msgInterval>
<lldpAdminStatus></lldpAdminStatus>
<tlvTxEnable>
<manAddrTxEnable></manAddrTxEnable>
<portDescTxEnable></portDescTxEnable>
<sysCapTxEnable></sysCapTxEnable>
</tlvTxEnable>
</lldpInterface>
</lldpInterfaces>
</lldp>
</filter>'
register: result3
- name: Assert the configuration is reflected on host
assert:
that:
- "result1['changed'] == true"
- "result2['changed'] == false"
- "'<txInterval>8</txInterval>' in result3.endstate.result"
- "'<lldpAdminStatus>txAndRx</lldpAdminStatus>' in result3.endstate.result"
- "'<manAddrTxEnable>true</manAddrTxEnable>' in result3.endstate.result"
- "'<portDescTxEnable>true</portDescTxEnable>' in result3.endstate.result"
- "'<sysCapTxEnable>true</sysCapTxEnable>' in result3.endstate.result"
- name: Merge the provided configuration with the exisiting running configuration - dot1-tlv
ce_lldp_interface: &merged
config:
msg_interval: 8
ifname: 10GE 1/0/1
dot1_tlv:
port_vlan_enable: true
port_desc: true
prot_vlan_enable: true
prot_vlan_id: 123
vlan_name: 234
vlan_name_enable: true
register: result1
- name: Merge the provided configuration with the existing running configuration (REPEAT)
ce_lldp_interface: *merged
register: result2
- name: "Netconf get operation"
ce_netconf:
rpc: get
cfg_xml: '<filter type=\"subtree\">
<lldp xmlns=\"http://www.huawei.com/netconf/vrp\" content-version=\"1.0\" format-version=\"1.0\">
<lldpInterfaces>
<lldpInterface>
<ifName>10GE1/0/1</ifName>
<msgInterval>
<txInterval></txInterval>
</msgInterval>
<lldpAdminStatus></lldpAdminStatus>
<tlvTxEnable>
<portVlanTxEnable></portVlanTxEnable>
<protoVlanTxEnable></protoVlanTxEnable>
<txProtocolVlanId></txProtocolVlanId>
<vlanNameTxEnable></vlanNameTxEnable>
<txVlanNameId></txVlanNameId>
<protoIdTxEnable></protoIdTxEnable>
</tlvTxEnable>
</lldpInterface>
</lldpInterfaces>
</lldp>
</filter>'
register: result3
- name: Assert the configuration is reflected on host
assert:
that:
- "result1['changed'] == true"
- "result2['changed'] == false"
- "'<portVlanTxEnable>true</portVlanTxEnable>' in result3.endstate.result"
- "'<protoVlanTxEnable>true</protoVlanTxEnable>' in result3.endstate.result"
- "'<txProtocolVlanId>123</txProtocolVlanId>' in result3.endstate.result"
- "'<vlanNameTxEnable>true</vlanNameTxEnable>' in result3.endstate.result"
- "'<txVlanNameId>true</txVlanNameId>' in result3.endstate.result"
- "'<protoIdTxEnable>true</protoIdTxEnable>' in result3.endstate.result"
- name: Merge the provided configuration with the exisiting running configuration - dot3-tlv
ce_lldp_interface: &merged
config:
msg_interval: 8
ifname: 10GE 1/0/1
dot3_tlv:
eee: true
link_aggregation: true
mac_physic: true
max_frame_size: true
register: result1
- name: Merge the provided configuration with the existing running configuration (REPEAT)
ce_lldp_interface: *merged
register: result2
- name: "Netconf get operation"
ce_netconf:
rpc: get
cfg_xml: '<filter type=\"subtree\">
<lldp xmlns=\"http://www.huawei.com/netconf/vrp\" content-version=\"1.0\" format-version=\"1.0\">
<lldpInterfaces>
<lldpInterface>
<ifName>10GE1/0/1</ifName>
<msgInterval>
<txInterval></txInterval>
</msgInterval>
<lldpAdminStatus></lldpAdminStatus>
<tlvTxEnable>
<macPhyTxEnable></macPhyTxEnable>
<linkAggreTxEnable></linkAggreTxEnable>
<maxFrameTxEnable></maxFrameTxEnable>
<eee></eee>
</tlvTxEnable>
</lldpInterface>
</lldpInterfaces>
</lldp>
</filter>'
register: result3
- name: Assert the configuration is reflected on host
assert:
that:
- "result1['changed'] == true"
- "result2['changed'] == false"
- "'<macPhyTxEnable>true</macPhyTxEnable>' in result3.endstate.result"
- "'<linkAggreTxEnable>true</linkAggreTxEnable>' in result3.endstate.result"
- "'<maxFrameTxEnable>123</maxFrameTxEnable>' in result3.endstate.result"
- debug:
msg: "END ce_lldp_interface merged integration tests on connection={{ ansible_connection }}"

@ -0,0 +1,29 @@
<data>
<lldp xmlns="http://www.huawei.com/netconf/vrp" content-version="1.0" format-version="1.0">
<lldpInterfaces>
<lldpInterface>
<ifName>10GE1/0/1</ifName>
<lldpAdminStatus>txAndRx</lldpAdminStatus>
<msgInterval operation="merge">
<txInterval>8</txInterval>
</msgInterval>
<tlvTxEnable>
<manAddrTxEnable>true</manAddrTxEnable>
<portDescTxEnable>true</portDescTxEnable>
<sysCapTxEnable>true</sysCapTxEnable>
<sysDescTxEnable>true</sysDescTxEnable>
<sysNameTxEnable>true</sysNameTxEnable>
<portVlanTxEnable>true</portVlanTxEnable>
<protoVlanTxEnable>true</protoVlanTxEnable>
<txProtocolVlanId>112</txProtocolVlanId>
<vlanNameTxEnable>true</vlanNameTxEnable>
<txVlanNameId>32</txVlanNameId>
<linkAggreTxEnable>true</linkAggreTxEnable>
<macPhyTxEnable>true</macPhyTxEnable>
<maxFrameTxEnable>true</maxFrameTxEnable>
<eee>true</eee>
</tlvTxEnable>
</lldpInterface>
</lldpInterfaces>
</lldp>
</data>

@ -0,0 +1,29 @@
<data>
<lldp xmlns="http://www.huawei.com/netconf/vrp" content-version="1.0" format-version="1.0">
<lldpInterfaces>
<lldpInterface>
<ifName>10GE1/0/1</ifName>
<lldpAdminStatus>txOnly</lldpAdminStatus>
<msgInterval operation="merge">
<txInterval>1</txInterval>
</msgInterval>
<tlvTxEnable>
<manAddrTxEnable>false</manAddrTxEnable>
<portDescTxEnable>false</portDescTxEnable>
<sysCapTxEnable>false</sysCapTxEnable>
<sysDescTxEnable>false</sysDescTxEnable>
<sysNameTxEnable>false</sysNameTxEnable>
<portVlanTxEnable>false</portVlanTxEnable>
<protoVlanTxEnable>false</protoVlanTxEnable>
<txProtocolVlanId></txProtocolVlanId>
<vlanNameTxEnable>false</vlanNameTxEnable>
<txVlanNameId></txVlanNameId>
<linkAggreTxEnable>false</linkAggreTxEnable>
<macPhyTxEnable>false</macPhyTxEnable>
<maxFrameTxEnable>false</maxFrameTxEnable>
<eee></eee>
</tlvTxEnable>
</lldpInterface>
</lldpInterfaces>
</lldp>
</data>

@ -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,111 @@
# (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_lldp_interface
from units.modules.network.cloudengine.ce_module import TestCloudEngineModule, load_fixture
from units.modules.utils import set_module_args
class TestCloudEngineLacpModule(TestCloudEngineModule):
module = ce_lldp_interface
def setUp(self):
super(TestCloudEngineLacpModule, self).setUp()
# self.mock_get_config = patch('ansible.modules.network.cloudengine.ce_lldp.get_nc_config')
self.mock_get_config = patch('ansible.modules.network.cloudengine.ce_lldp_interface.get_nc_config')
self.get_nc_config = self.mock_get_config.start()
self.mock_set_nc_config = patch('ansible.modules.network.cloudengine.ce_lldp_interface.set_nc_config')
self.set_nc_config = self.mock_set_nc_config.start()
self.xml_absent = load_fixture('ce_lldp_interface', 'lldp_interface_existing.txt')
self.xml_present = load_fixture('ce_lldp_interface', 'lldp_interface_changed.txt')
self.result_ok = load_fixture('ce_lldp_interface', 'result_ok.txt')
def tearDown(self):
super(TestCloudEngineLacpModule, self).tearDown()
self.mock_set_nc_config.stop()
self.mock_get_config.stop()
def test_lldp_present(self):
self.get_nc_config.side_effect = (self.xml_absent, self.xml_present) * 5
self.set_nc_config.return_value = self.result_ok
config = dict(
lldpenable='enabled',
function_lldp_interface_flag='disableINTERFACE',
type_tlv_disable='basic_tlv',
type_tlv_enable='dot1_tlv',
ifname='10GE1/0/1',
lldpadminstatus='txOnly',
manaddrtxenable=True,
portdesctxenable=True,
syscaptxenable=True,
sysdesctxenable=True,
sysnametxenable=True,
portvlantxenable=True,
protovlantxenable=True,
txprotocolvlanid=True,
vlannametxenable=True,
txvlannameid=8,
txinterval=8,
protoidtxenable=True,
macphytxenable=True,
linkaggretxenable=True,
maxframetxenable=True,
eee=True,
dcbx=True
)
set_module_args(config)
result = self.execute_module(changed=True)
def test_lldp_absent(self):
self.get_nc_config.side_effect = (self.xml_present, self.xml_present, self.xml_absent, self.xml_absent)
self.set_nc_config.return_value = self.result_ok
config = dict(
lldpenable='enabled',
function_lldp_interface_flag='disableINTERFACE',
type_tlv_disable='basic_tlv',
type_tlv_enable='dot1_tlv',
ifname='10GE1/0/1',
lldpadminstatus='txOnly',
manaddrtxenable=False,
portdesctxenable=False,
syscaptxenable=False,
sysdesctxenable=False,
sysnametxenable=False,
portvlantxenable=False,
protovlantxenable=False,
txprotocolvlanid=False,
vlannametxenable=False,
txvlannameid=18,
txinterval=18,
protoidtxenable=False,
macphytxenable=False,
linkaggretxenable=False,
maxframetxenable=False,
eee=False,
dcbx=False,
state='absent'
)
set_module_args(config)
result = self.execute_module(changed=False)
Loading…
Cancel
Save