1
0
Fork 0
mirror of https://github.com/ansible-collections/community.general.git synced 2026-03-27 07:27:33 +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:
Felix Fontein 2020-03-31 10:42:38 +02:00 committed by GitHub
parent ab3c2120fb
commit be191cce6c
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
1170 changed files with 732 additions and 751 deletions

View file

@ -0,0 +1,90 @@
# Copyright (c) 2019 Red Hat
#
# This file is a 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.plugins.modules.utils import AnsibleExitJson, AnsibleFailJson, ModuleTestCase
fixture_path = os.path.join(os.path.dirname(__file__), 'fixtures')
fixture_data = {}
def load_fixture(module_name, name, device=''):
path = os.path.join(fixture_path, module_name, device, name)
if not os.path.exists(path):
path = os.path.join(fixture_path, module_name, 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 TestCloudEngineModule(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

View file

@ -0,0 +1,11 @@
<data>
<isiscomm xmlns="http://www.huawei.com/netconf/vrp" content-version="1.0" format-version="1.0">
<isSites>
<isSite>
<instanceId>100</instanceId>
<vpnName>_public_</vpnName>
<description>ISIS</description>
</isSite>
</isSites>
</isiscomm>
</data>

View file

@ -0,0 +1,11 @@
<data>
<isiscomm xmlns="http://www.huawei.com/netconf/vrp" content-version="1.0" format-version="1.0">
<isSites>
<isSite>
<instanceId></instanceId>
<vpnName></vpnName>
<description></description>
</isSite>
</isSites>
</isiscomm>
</data>

View file

@ -0,0 +1,26 @@
<data>
<isiscomm>
<isSites>
<isSite>
<instanceId>100</instanceId>
<isCircuits>
<isCircuit>
<ifName></ifName>
<circuitLevelType>level_1</circuitLevelType>
<level1DisPriority>10</level1DisPriority>
<level2DisPriority>10</level2DisPriority>
<silentEnable>true</silentEnable>
<silentCost>true</silentCost>
<typeP2pEnable>true</typeP2pEnable>
<snpaCheck>true</snpaCheck>
<p2pNegotiationMode>2_way</p2pNegotiationMode>
<p2pPeerIPIgnore>true</p2pPeerIPIgnore>
<pPPOsicpCheckEnable>true</pPPOsicpCheckEnable>
<level1Cost>10</level1Cost>
<level2Cost>10</level2Cost>
</isCircuit>
</isCircuits>
</isSite>
</isSites>
</isiscomm>
</data>

View file

@ -0,0 +1,26 @@
<data>
<isiscomm>
<isSites>
<isSite>
<instanceId>100</instanceId>
<isCircuits>
<isCircuit>
<ifName></ifName>
<circuitLevelType></circuitLevelType>
<level1DisPriority></level1DisPriority>
<level2DisPriority></level2DisPriority>
<silentEnable></silentEnable>
<silentCost></silentCost>
<typeP2pEnable></typeP2pEnable>
<snpaCheck></snpaCheck>
<p2pNegotiationMode></p2pNegotiationMode>
<p2pPeerIPIgnore></p2pPeerIPIgnore>
<pPPOsicpCheckEnable></pPPOsicpCheckEnable>
<level1Cost></level1Cost>
<level2Cost></level2Cost>
</isCircuit>
</isCircuits>
</isSite>
</isSites>
</isiscomm>
</data>

View file

@ -0,0 +1,104 @@
<data>
<isiscomm>
<isSites>
<isSite>
<instanceId>100</instanceId>
<vpnName>_public_</vpnName>
<description>ISIS</description>
<isLevel>level_1</isLevel>
<costStyle>narrow</costStyle>
<relaxSpfLimit>true</relaxSpfLimit>
<stdLevel1Cost>60</stdLevel1Cost>
<stdLevel2Cost>60</stdLevel2Cost>
<stdbandwidth>100</stdbandwidth>
<stdAutoCostEnable>true</stdAutoCostEnable>
<stdAutoCostEnableCompatible>true</stdAutoCostEnableCompatible>
<isNetEntitys>
<isNetEntity>
<netEntity>netentity</netEntity>
</isNetEntity>
</isNetEntitys>
<isSiteMTs>
<isSiteMT>
<addressFamily>afIpv4</addressFamily>
<mtId>0</mtId>
<bfdMinRx>100</bfdMinRx>
<bfdMinTx>100</bfdMinTx>
<bfdMultNum>10</bfdMultNum>
<maxLoadBalancing>32</maxLoadBalancing>
<isPreferences>
<isPreference>
<preferenceValue>100</preferenceValue>
<routePolicyName>route</routePolicyName>
</isPreference>
</isPreferences>
<isNextHopWeights>
<isNextHopWeight>
<ipAddress>1.1.1.1</ipAddress>
<weight>100</weight>
</isNextHopWeight>
</isNextHopWeights>
<isFilterImports>
<isFilterImport>
<aclNumOrName>3001</aclNumOrName>
<ipPrefix>ip</ipPrefix>
<routePolicyName>route</routePolicyName>
<policyType>level_1</policyType>
</isFilterImport>
</isFilterImports>
<isFilterExports>
<isFilterExport>
<protocol>ospf</protocol>
<processId>100</processId>
<policyType>level_1</policyType>
</isFilterExport>
</isFilterExports>
<isDefaultRoutes>
<isDefaultRoute>
<defaultMode>always</defaultMode>
<routePolicyName>mode</routePolicyName>
<cost>100</cost>
<tag>100</tag>
<levelType>level_1</levelType>
<avoidLearning>true</avoidLearning>
</isDefaultRoute>
</isDefaultRoutes>
<isImportRoutes>
<isImportRoute>
<protocol>import</protocol>
<processId>100</processId>
<costType>level_1</costType>
<cost>100</cost>
<tag>100</tag>
<policyType>level_1</policyType>
<routePolicyName>import</routePolicyName>
<levelType>level_1</levelType>
<inheritCost>100</inheritCost>
<permitIbgp>true</permitIbgp>
</isImportRoute>
</isImportRoutes>
<isLeakRouteLevel1ToLevel2s>
<isLeakRouteLevel1ToLevel2>
<tag>100</tag>
<routePolicyName>route</routePolicyName>
<aclNumOrName>3001</aclNumOrName>
<ipPrefix>ip</ipPrefix>
<leakEnableFlag>true</leakEnableFlag>
<allowFilter>true</allowFilter>
</isLeakRouteLevel1ToLevel2>
</isLeakRouteLevel1ToLevel2s>
<isLeakRouteLevel2ToLevel1s>
<isLeakRouteLevel2ToLevel1>
<tag>100</tag>
<routePolicyName>route</routePolicyName>
<aclNumOrName>3001</aclNumOrName>
<ipPrefix>ip</ipPrefix>
<allowFilter>true</allowFilter>
</isLeakRouteLevel2ToLevel1>
</isLeakRouteLevel2ToLevel1s>
</isSiteMT>
</isSiteMTs>
</isSite>
</isSites>
</isiscomm>
</data>

View file

@ -0,0 +1,10 @@
<data>
<isiscomm>
<isSites>
<isSite>
<instanceId>100</instanceId>
<vpnName>_public_</vpnName>
</isSite>
</isSites>
</isiscomm>
</data>

View file

@ -0,0 +1,26 @@
<?xml version="1.0" encoding="UTF-8"?>
<rpc-reply xmlns="urn:ietf:params:xml:ns:netconf:base:1.0" message-id="1024">
<data>
<ifmtrunk xmlns="http://www.huawei.com/netconf/vrp" content-version="1.0" format-version="1.0">
<TrunkIfs>
<TrunkIf>
<ifName>Eth-Trunk10</ifName>
<lacpTrunk>
<isSupportPrmpt>false</isSupportPrmpt>
<rcvTimeoutType>Fast</rcvTimeoutType>
<fastTimeoutUserDefinedValue>3</fastTimeoutUserDefinedValue>
<selectPortStd>Speed</selectPortStd>
<promptDelay>30</promptDelay>
<maxActiveNum>1</maxActiveNum>
<collectMaxDelay>0</collectMaxDelay>
<mixRateEnable>false</mixRateEnable>
<dampStaFlapEn>false</dampStaFlapEn>
<dampUnexpMacEn>false</dampUnexpMacEn>
<trunkSysMac>11-22-33</trunkSysMac>
<trunkPortIdExt>false</trunkPortIdExt>
</lacpTrunk>
</TrunkIf>
</TrunkIfs>
</ifmtrunk>
</data>
</rpc-reply>

View file

@ -0,0 +1,26 @@
<?xml version="1.0" encoding="UTF-8"?>
<rpc-reply xmlns="urn:ietf:params:xml:ns:netconf:base:1.0" message-id="1024">
<data>
<ifmtrunk xmlns="http://www.huawei.com/netconf/vrp" content-version="1.0" format-version="1.0">
<TrunkIfs>
<TrunkIf>
<ifName>Eth-Trunk10</ifName>
<lacpTrunk>
<isSupportPrmpt>true</isSupportPrmpt>
<rcvTimeoutType>Fast</rcvTimeoutType>
<fastTimeoutUserDefinedValue>10</fastTimeoutUserDefinedValue>
<selectPortStd>Speed</selectPortStd>
<promptDelay>130</promptDelay>
<maxActiveNum>13</maxActiveNum>
<collectMaxDelay>12</collectMaxDelay>
<mixRateEnable>true</mixRateEnable>
<dampStaFlapEn>true</dampStaFlapEn>
<dampUnexpMacEn>true</dampUnexpMacEn>
<trunkSysMac>0000-1111-2222</trunkSysMac>
<trunkPortIdExt>true</trunkPortIdExt>
</lacpTrunk>
</TrunkIf>
</TrunkIfs>
</ifmtrunk>
</data>
</rpc-reply>

View file

@ -0,0 +1,10 @@
<?xml version="1.0" encoding="UTF-8"?>
<rpc-reply xmlns="urn:ietf:params:xml:ns:netconf:base:1.0" message-id="1024">
<data>
<ifmtrunk xmlns="http://www.huawei.com/netconf/vrp" content-version="1.0" format-version="1.0">
<lacpSysInfo>
<priority>32768</priority>
</lacpSysInfo>
</ifmtrunk>
</data>
</rpc-reply>

View file

@ -0,0 +1,10 @@
<?xml version="1.0" encoding="UTF-8"?>
<rpc-reply xmlns="urn:ietf:params:xml:ns:netconf:base:1.0" message-id="1024">
<data>
<ifmtrunk xmlns="http://www.huawei.com/netconf/vrp" content-version="1.0" format-version="1.0">
<lacpSysInfo>
<priority>32769</priority>
</lacpSysInfo>
</ifmtrunk>
</data>
</rpc-reply>

View file

@ -0,0 +1,21 @@
<?xml version="1.0" encoding="UTF-8"?>
<rpc-reply xmlns="urn:ietf:params:xml:ns:netconf:base:1.0" message-id="1024">
<data>
<lldp xmlns="http://www.huawei.com/netconf/vrp" content-version="1.0" format-version="1.0">
<lldpSys>
<lldpSysParameter>
<messageTxInterval>30</messageTxInterval>
<messageTxHoldMultiplier>4</messageTxHoldMultiplier>
<reinitDelay>2</reinitDelay>
<txDelay>2</txDelay>
<notificationInterval>5</notificationInterval>
<fastMessageCount>4</fastMessageCount>
<mdnNotificationInterval>5</mdnNotificationInterval>
<mdnNotificationEnable>disabled</mdnNotificationEnable>
<configManAddr></configManAddr>
<bindifName></bindifName>
</lldpSysParameter>
</lldpSys>
</lldp>
</data>
</rpc-reply>

View file

@ -0,0 +1,21 @@
<?xml version="1.0" encoding="UTF-8"?>
<rpc-reply xmlns="urn:ietf:params:xml:ns:netconf:base:1.0" message-id="1024">
<data>
<lldp xmlns="http://www.huawei.com/netconf/vrp" content-version="1.0" format-version="1.0">
<lldpSys>
<lldpSysParameter>
<messageTxInterval>8</messageTxInterval>
<messageTxHoldMultiplier>8</messageTxHoldMultiplier>
<reinitDelay>8</reinitDelay>
<txDelay>8</txDelay>
<notificationInterval>8</notificationInterval>
<fastMessageCount>8</fastMessageCount>
<mdnNotificationInterval>8</mdnNotificationInterval>
<mdnNotificationEnable>enabled</mdnNotificationEnable>
<configManAddr>1.1.1.1</configManAddr>
<bindifName>bind-name</bindifName>
</lldpSysParameter>
</lldpSys>
</lldp>
</data>
</rpc-reply>

View file

@ -0,0 +1,11 @@
<?xml version="1.0" encoding="UTF-8"?>
<rpc-reply xmlns="urn:ietf:params:xml:ns:netconf:base:1.0" message-id="1024">
<data>
<lldp xmlns="http://www.huawei.com/netconf/vrp" content-version="1.0" format-version="1.0">
<lldpSys>
<lldpEnable>disabled</lldpEnable>
<mdnStatus>disabled</mdnStatus>
</lldpSys>
</lldp>
</data>
</rpc-reply>

View file

@ -0,0 +1,11 @@
<?xml version="1.0" encoding="UTF-8"?>
<rpc-reply xmlns="urn:ietf:params:xml:ns:netconf:base:1.0" message-id="1024">
<data>
<lldp xmlns="http://www.huawei.com/netconf/vrp" content-version="1.0" format-version="1.0">
<lldpSys>
<lldpEnable>enabled</lldpEnable>
<mdnStatus>rxOnly</mdnStatus>
</lldpSys>
</lldp>
</data>
</rpc-reply>

View file

@ -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>

View file

@ -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>

View file

@ -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>

View file

@ -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>

View file

@ -0,0 +1,14 @@
<data>
<lldp>
<lldpSys>
<lldpEnable>enabled</lldpEnable>
<mdnStatus>enabled</mdnStatus>
</lldpSys>
<mdnInterfaces>
<mdnInterface>
<ifName>10GE1/0/1</ifName>
<mdnStatus>rxOnly</mdnStatus>
</mdnInterface>
</mdnInterfaces>
</lldp>
</data>

View file

@ -0,0 +1,14 @@
<data>
<lldp>
<lldpSys>
<lldpEnable>disabled</lldpEnable>
<mdnStatus>disabled</mdnStatus>
</lldpSys>
<mdnInterfaces>
<mdnInterface>
<ifName>10GE1/0/1</ifName>
<mdnStatus>disabled</mdnStatus>
</mdnInterface>
</mdnInterfaces>
</lldp>
</data>

View file

@ -0,0 +1,10 @@
<data>
<mcastbase>
<mcastAfsEnables>
<mcastAfsEnable>
<vrfName>vpna</vrfName>
<addressFamily>ipv4unicast</addressFamily>
</mcastAfsEnable>
</mcastAfsEnables>
</mcastbase>
</data>

View file

@ -0,0 +1,22 @@
<data>
<l2mc >
<l2McSnpgEnables>
<l2McSnpgEnable>
<addrFamily>ipv4unicast</addrFamily>
<sendQueryEnable>false</sendQueryEnable>
<sendQuerySrcIpAddr>192.168.0.1</sendQuerySrcIpAddr>
</l2McSnpgEnable>
</l2McSnpgEnables>
<vlan>
<l2McVlanCfgs>
<l2McVlanCfg>
<addrFamily>ipv4unicast</addrFamily>
<vlanId>1</vlanId>
<version>2</version>
<snoopingEnable>true</snoopingEnable>
<proxyEnable>true</proxyEnable>
</l2McVlanCfg>
</l2McVlanCfgs>
</vlan>
</l2mc>
</data>

View file

@ -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>

View file

@ -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>

View file

@ -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>

View file

@ -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>

View file

@ -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>

View file

@ -0,0 +1,71 @@
# (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 ansible_collections.community.general.tests.unit.compat.mock import patch
from ansible_collections.community.general.plugins.modules.network.cloudengine import ce_is_is_instance
from ansible_collections.community.general.tests.unit.plugins.modules.network.cloudengine.ce_module import TestCloudEngineModule, load_fixture
from ansible_collections.community.general.tests.unit.plugins.modules.utils import set_module_args
class TestCloudEngineLacpModule(TestCloudEngineModule):
module = ce_is_is_instance
def setUp(self):
super(TestCloudEngineLacpModule, self).setUp()
self.mock_get_config = patch('ansible_collections.community.general.plugins.modules.network.cloudengine.ce_is_is_instance.get_nc_config')
self.get_nc_config = self.mock_get_config.start()
self.mock_set_config = patch('ansible_collections.community.general.plugins.modules.network.cloudengine.ce_is_is_instance.set_nc_config')
self.set_nc_config = self.mock_set_config.start()
self.set_nc_config.return_value = None
def tearDown(self):
super(TestCloudEngineLacpModule, self).tearDown()
self.mock_set_config.stop()
self.mock_get_config.stop()
def test_isis_instance_present(self):
xml_existing = load_fixture('ce_is_is_instance', 'before.txt')
xml_end_state = load_fixture('ce_is_is_instance', 'after.txt')
update = ['isis 100', 'vpn-instance __public__']
self.get_nc_config.side_effect = (xml_existing, xml_end_state)
config = dict(
instance_id=100,
vpn_name='__public__',
state='present')
set_module_args(config)
result = self.execute_module(changed=True)
self.assertEquals(sorted(result['updates']), sorted(update))
def test_isis_instance_present(self):
xml_existing = load_fixture('ce_is_is_instance', 'after.txt')
xml_end_state = load_fixture('ce_is_is_instance', 'before.txt')
update = ['undo isis 100']
self.get_nc_config.side_effect = (xml_existing, xml_end_state)
config = dict(
instance_id=100,
vpn_name='__public__',
state='absent')
set_module_args(config)
result = self.execute_module(changed=True)
self.assertEquals(sorted(result['updates']), sorted(update))

View file

@ -0,0 +1,100 @@
# (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 ansible_collections.community.general.tests.unit.compat.mock import patch
from ansible_collections.community.general.plugins.modules.network.cloudengine import ce_is_is_interface
from ansible_collections.community.general.tests.unit.plugins.modules.network.cloudengine.ce_module import TestCloudEngineModule, load_fixture
from ansible_collections.community.general.tests.unit.plugins.modules.utils import set_module_args
class TestCloudEngineLacpModule(TestCloudEngineModule):
module = ce_is_is_interface
def setUp(self):
super(TestCloudEngineLacpModule, self).setUp()
self.mock_get_config = patch('ansible_collections.community.general.plugins.modules.network.cloudengine.ce_is_is_interface.get_nc_config')
self.get_nc_config = self.mock_get_config.start()
self.mock_set_config = patch('ansible_collections.community.general.plugins.modules.network.cloudengine.ce_is_is_interface.set_nc_config')
self.set_nc_config = self.mock_set_config.start()
self.set_nc_config.return_value = None
self.before = load_fixture('ce_is_is_interface', 'before_interface.txt')
self.after = load_fixture('ce_is_is_interface', 'after_interface.txt')
def tearDown(self):
super(TestCloudEngineLacpModule, self).tearDown()
self.mock_set_config.stop()
self.mock_get_config.stop()
def test_isis_interface_present(self):
update = ['interface 10GE1/0/1',
'isis enable 100',
'isis circuit-level level-1',
'isis dis-priority 10 level-1',
'isis ppp-negotiation 2-way',
'isis cost 10 level-2']
self.get_nc_config.side_effect = (self.before, self.after)
config = dict(
instance_id=100,
ifname='10GE1/0/1',
leveltype='level_1',
level1dispriority=10,
silentenable=True,
silentcost=True,
typep2penable=True,
snpacheck=True,
p2pnegotiationmode='2_way',
p2ppeeripignore=True,
ppposicpcheckenable=True,
level2cost=10
)
set_module_args(config)
result = self.execute_module(changed=True)
print(result['updates'])
self.assertEquals(sorted(result['updates']), sorted(update))
def test_isis_interface_absent(self):
update = ['interface 10GE1/0/1',
'undo isis enable',
'undo isis circuit-level',
'undo isis ppp-negotiation']
self.get_nc_config.side_effect = (self.after, self.before)
config = dict(
instance_id=100,
ifname='10GE1/0/1',
leveltype='level_1',
level1dispriority=10,
silentenable=True,
silentcost=True,
typep2penable=True,
snpacheck=True,
p2pnegotiationmode='2_way',
p2ppeeripignore=True,
ppposicpcheckenable=True,
level2cost=10,
state='absent'
)
set_module_args(config)
result = self.execute_module(changed=True)
self.assertEquals(sorted(result['updates']), sorted(update))

View file

@ -0,0 +1,248 @@
# (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 ansible_collections.community.general.tests.unit.compat.mock import patch
from ansible_collections.community.general.plugins.modules.network.cloudengine import ce_is_is_view
from ansible_collections.community.general.tests.unit.plugins.modules.network.cloudengine.ce_module import TestCloudEngineModule, load_fixture
from ansible_collections.community.general.tests.unit.plugins.modules.utils import set_module_args
class TestCloudEngineLacpModule(TestCloudEngineModule):
module = ce_is_is_view
def setUp(self):
super(TestCloudEngineLacpModule, self).setUp()
self.mock_get_config = patch('ansible_collections.community.general.plugins.modules.network.cloudengine.ce_is_is_view.get_nc_config')
self.get_nc_config = self.mock_get_config.start()
self.mock_set_config = patch('ansible_collections.community.general.plugins.modules.network.cloudengine.ce_is_is_view.set_nc_config')
self.set_nc_config = self.mock_set_config.start()
self.set_nc_config.return_value = None
self.before = load_fixture('ce_is_is_view', 'before.txt')
self.after = load_fixture('ce_is_is_view', 'after.txt')
def tearDown(self):
super(TestCloudEngineLacpModule, self).tearDown()
self.mock_set_config.stop()
self.mock_get_config.stop()
def test_ce_is_is_view_absent(self):
self.get_nc_config.side_effect = (self.after, self.before)
config = dict(
instance_id=100,
description='ISIS',
islevel='level_1',
coststyle='narrow',
stdlevel2cost=60,
stdbandwidth=100,
autocostenable=True,
autocostenablecompatible=True,
netentity='netentity',
preference_value=100,
route_policy_name='route',
max_load=32,
ip_address='1.1.1.1',
weight=100,
penetration_direct='level2-level1',
import_routepolicy_name='import',
tag=100,
allow_filter=True,
allow_up_down=True,
enablelevel1tolevel2=True,
defaultmode='always',
mode_routepolicyname='mode',
cost=100,
mode_tag=100,
level_type='level_1',
avoid_learning=True,
protocol='ospf',
processid=100,
cost_type='external',
import_cost=100,
import_tag=100,
import_route_policy='import',
impotr_leveltype='level_1',
inheritcost=True,
permitibgp=True,
export_protocol='ospf',
export_policytype='aclNumOrName',
export_processid=100,
export_ipprefix='export',
export_routepolicyname='export',
import_aclnumorname='acl',
import_routepolicyname='import',
bfd_min_rx=100,
bfd_min_tx=100,
bfd_multiplier_num=10,
state='absent'
)
set_module_args(config)
self.execute_module(changed=True)
def test_ce_is_is_view_present(self):
self.get_nc_config.side_effect = (self.before, self.after)
update = ['isis 100',
'description ISIS',
'is-level level_1',
'cost-style narrow',
'circuit-cost 60 level-2',
'bandwidth-reference 100',
'network-entity netentity',
'preference 100 route-policy route',
'maximum load-balancing 32',
'nexthop 1.1.1.1 weight 100',
'import-route isis level-2 into level-1 filter-policy route-policy import tag 100 direct allow-filter-policy allow-up-down-bit',
'preference 100 route-policy route',
'undo import-route isis level-1 into level-2 disable',
'default-route-advertise always cost 100 tag 100 level-1 avoid-learning',
'import-route isis level-2 into level-1 filter-policy route-policy import tag 100 direct allow-filter-policy allow-up-down-bit',
'preference 100 route-policy route',
'import-route ospf 100 inherit-cost cost-type external cost 100 tag 100 route-policy import level-1',
'default-route-advertise always cost 100 tag 100 level-1 avoid-learning',
'import-route isis level-2 into level-1 filter-policy route-policy import tag 100 direct allow-filter-policy allow-up-down-bit',
'preference 100 route-policy route',
'bfd all-interfaces enable',
'bfd all-interfaces min-rx-interval 100 min-tx-interval 100 detect-multiplier 10',
'import-route ospf 100 inherit-cost cost-type external cost 100 tag 100 route-policy import level-1',
'default-route-advertise always cost 100 tag 100 level-1 avoid-learning',
'import-route isis level-2 into level-1 filter-policy route-policy import tag 100 direct allow-filter-policy allow-up-down-bit',
'preference 100 route-policy route',
'filter-policy ip-prefix export route-policy export export ospf 100',
'bfd all-interfaces min-rx-interval 100 min-tx-interval 100 detect-multiplier 10',
'import-route ospf 100 inherit-cost cost-type external cost 100 tag 100 route-policy import level-1',
'default-route-advertise always cost 100 tag 100 level-1 avoid-learning',
'import-route isis level-2 into level-1 filter-policy route-policy import tag 100 direct allow-filter-policy allow-up-down-bit',
'preference 100 route-policy route',
'filter-policy acl-name acl route-policy importimport',
'filter-policy ip-prefix export route-policy export export ospf 100',
'bfd all-interfaces min-rx-interval 100 min-tx-interval 100 detect-multiplier 10',
'import-route ospf 100 inherit-cost cost-type external cost 100 tag 100 route-policy import level-1',
'default-route-advertise always cost 100 tag 100 level-1 avoid-learning',
'import-route isis level-2 into level-1 filter-policy route-policy import tag 100 direct allow-filter-policy allow-up-down-bit',
'preference 100 route-policy route',
'auto-cost enable',
'auto-cost enable compatible']
config = dict(
instance_id=100,
description='ISIS',
islevel='level_1',
coststyle='narrow',
stdlevel2cost=60,
stdbandwidth=100,
autocostenable=True,
autocostenablecompatible=True,
netentity='netentity',
preference_value=100,
route_policy_name='route',
max_load=32,
ip_address='1.1.1.1',
weight=100,
penetration_direct='level2-level1',
import_routepolicy_name='import',
tag=100,
allow_filter=True,
allow_up_down=True,
enablelevel1tolevel2=True,
defaultmode='always',
mode_routepolicyname='mode',
cost=100,
mode_tag=100,
level_type='level_1',
avoid_learning=True,
protocol='ospf',
processid=100,
cost_type='external',
import_cost=100,
import_tag=100,
import_route_policy='import',
impotr_leveltype='level_1',
inheritcost=True,
permitibgp=True,
export_protocol='ospf',
export_policytype='aclNumOrName',
export_processid=100,
export_ipprefix='export',
export_routepolicyname='export',
import_aclnumorname='acl',
import_routepolicyname='import',
bfd_min_rx=100,
bfd_min_tx=100,
bfd_multiplier_num=10
)
set_module_args(config)
result = self.execute_module(changed=True)
self.assertEquals(sorted(result['updates']), sorted(update))
def test_ce_is_is_view_no_changed(self):
self.get_nc_config.side_effect = (self.after, self.after)
config = dict(
instance_id=100,
description='ISIS',
islevel='level_1',
coststyle='narrow',
stdlevel2cost=60,
stdbandwidth=100,
autocostenable=True,
autocostenablecompatible=True,
netentity='netentity',
preference_value=100,
route_policy_name='route',
max_load=32,
ip_address='1.1.1.1',
weight=100,
penetration_direct='level2-level1',
import_routepolicy_name='import',
tag=100,
allow_filter=True,
allow_up_down=True,
enablelevel1tolevel2=True,
defaultmode='always',
mode_routepolicyname='mode',
cost=100,
mode_tag=100,
level_type='level_1',
avoid_learning=True,
protocol='ospf',
processid=100,
cost_type='external',
import_cost=100,
import_tag=100,
import_route_policy='import',
impotr_leveltype='level_1',
inheritcost=True,
permitibgp=True,
export_protocol='ospf',
export_policytype='aclNumOrName',
export_processid=100,
export_ipprefix='export',
export_routepolicyname='export',
import_aclnumorname='acl',
import_routepolicyname='import',
bfd_min_rx=100,
bfd_min_tx=100,
bfd_multiplier_num=10
)
set_module_args(config)
self.execute_module(changed=False)

View file

@ -0,0 +1,134 @@
# (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 ansible_collections.community.general.tests.unit.compat.mock import patch
from ansible_collections.community.general.plugins.modules.network.cloudengine import ce_lacp
from ansible_collections.community.general.tests.unit.plugins.modules.utils import set_module_args
from .ce_module import TestCloudEngineModule, load_fixture
class TestCloudEngineLacpModule(TestCloudEngineModule):
module = ce_lacp
def setUp(self):
super(TestCloudEngineLacpModule, self).setUp()
self.mock_get_config = patch('ansible_collections.community.general.plugins.modules.network.cloudengine.ce_lacp.get_nc_config')
self.get_nc_config = self.mock_get_config.start()
self.mock_set_config = patch('ansible_collections.community.general.plugins.modules.network.cloudengine.ce_lacp.set_nc_config')
self.set_nc_config = self.mock_set_config.start()
self.set_nc_config.return_value = None
def tearDown(self):
super(TestCloudEngineLacpModule, self).tearDown()
self.mock_set_config.stop()
self.mock_get_config.stop()
def test_lacp_eturnk_present(self):
xml_existing = load_fixture('ce_lacp', 'ce_lacp_00.txt')
xml_end_state = load_fixture('ce_lacp', 'ce_lacp_01.txt')
update = ['lacp max active-linknumber 13',
'lacp dampening state-flapping',
'lacp port-id-extension enable',
'lacp collector delay 12',
'lacp preempt enable',
'lacp system-id 0000-1111-2222',
'lacp mixed-rate link enable',
'lacp preempt delay 130',
'lacp timeout user-defined 10',
'lacp dampening unexpected-mac disable']
self.get_nc_config.side_effect = (xml_existing, xml_end_state)
set_module_args(dict(
mode='Dynamic',
trunk_id='10',
preempt_enable='true',
state_flapping='true',
port_id_extension_enable='true',
unexpected_mac_disable='true',
system_id='0000-1111-2222',
timeout_type='Fast',
fast_timeout='10',
mixed_rate_link_enable='true',
preempt_delay=11,
collector_delay=12,
max_active_linknumber=13,
select='Speed',
state='present'))
result = self.execute_module(changed=True)
self.assertEqual(sorted(result['updates']), sorted(update))
def test_lacp_eturnk_absent(self):
xml_existing = load_fixture('ce_lacp', 'ce_lacp_10.txt')
xml_end_state = load_fixture('ce_lacp', 'ce_lacp_00.txt')
default_values = ['undo lacp priority',
'lacp timeout Fast',
'lacp max active-linknumber 1',
'lacp collector delay 0',
'lacp preempt enable false',
'lacp dampening state-flapping false',
'lacp dampening unexpected-mac disable false',
'lacp mixed-rate link enable false',
'lacp port-id-extension enable false',
'lacp preempt delay 30',
'lacp select Speed',
'lacp system-id 11-22-33',
'lacp timeout user-defined 3']
self.get_nc_config.side_effect = (xml_existing, xml_end_state)
set_module_args(dict(
mode='Dynamic',
trunk_id='10',
preempt_enable='true',
state_flapping='true',
port_id_extension_enable='true',
unexpected_mac_disable='true',
system_id='0000-1111-2222',
timeout_type='Fast',
fast_timeout='10',
mixed_rate_link_enable='true',
preempt_delay=11,
collector_delay=12,
max_active_linknumber=13,
select='Speed',
state='absent'
))
result = self.execute_module(changed=True)
self.assertEqual(sorted(result['updates']), sorted(default_values))
def test_lacp_global_present(self):
xml_existing = load_fixture('ce_lacp', 'ce_lacp_10.txt')
xml_end_state = load_fixture('ce_lacp', 'ce_lacp_11.txt')
self.get_nc_config.side_effect = (xml_existing, xml_end_state)
set_module_args(dict(global_priority=32769,
state='present'))
result = self.execute_module(changed=True)
self.assertEqual(result['updates'], ['lacp priority 32769'])
def test_lacp_global_absent(self):
xml_existing = load_fixture('ce_lacp', 'ce_lacp_11.txt')
xml_end_state = load_fixture('ce_lacp', 'ce_lacp_10.txt')
self.get_nc_config.side_effect = (xml_existing, xml_end_state)
set_module_args(dict(global_priority=32769,
state='absent'))
result = self.execute_module(changed=True)
# excpect: lacp priority is set to default value(32768)
self.assertEqual(result['updates'], ['lacp priority 32768'])

View file

@ -0,0 +1,113 @@
# (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 ansible_collections.community.general.tests.unit.compat.mock import patch
from ansible_collections.community.general.plugins.modules.network.cloudengine import ce_lldp
from ansible_collections.community.general.tests.unit.plugins.modules.network.cloudengine.ce_module import TestCloudEngineModule, load_fixture
from ansible_collections.community.general.tests.unit.plugins.modules.utils import set_module_args
class TestCloudEngineLacpModule(TestCloudEngineModule):
module = ce_lldp
def setUp(self):
super(TestCloudEngineLacpModule, self).setUp()
self.mock_get_config = patch('ansible_collections.community.general.plugins.modules.network.cloudengine.ce_lldp.get_nc_config')
self.get_nc_config = self.mock_get_config.start()
self.mock_set_config = patch('ansible_collections.community.general.plugins.modules.network.cloudengine.ce_lldp.set_nc_config')
self.set_nc_config = self.mock_set_config.start()
self.set_nc_config.return_value = None
xml_existing_1 = load_fixture('ce_lldp', 'ce_lldp_global_00.txt')
xml_existing_2 = load_fixture('ce_lldp', 'ce_lldp_global_01.txt')
xml_end_state_1 = load_fixture('ce_lldp', 'ce_lldpSysParameter_00.txt')
xml_end_state_2 = load_fixture('ce_lldp', 'ce_lldpSysParameter_01.txt')
self.get_side_effect = (xml_existing_1, xml_existing_2, xml_end_state_1, xml_end_state_2)
self.result_ok = 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_lldp_global_present(self):
update = ['lldp enable',
'lldp mdn enable',
'lldp mdn enable',
'lldp transmit interval 8',
'lldp transmit multiplier 8',
'lldp restart 8',
'lldp transmit delay 8',
'lldp trap-interval 8',
'lldp fast-count 8',
'lldp mdn trap-interval 8',
'lldp management-address 1.1.1.1',
'lldp management-address bind interface bind-name']
self.get_nc_config.side_effect = self.get_side_effect
self.set_nc_config.side_effect = [self.result_ok] * 11
set_module_args(dict(
lldpenable='enabled',
mdnstatus='rxOnly',
interval=8,
hold_multiplier=8,
restart_delay=8,
transmit_delay=8,
notification_interval=8,
fast_count=8,
mdn_notification_interval=8,
management_address='1.1.1.1',
bind_name='bind-name')
)
result = self.execute_module(changed=True)
self.assertEqual(sorted(result['updates']), sorted(update))
def test_lacp_sys_parameter_present(self):
update = ['lldp enable',
'lldp mdn enable',
'lldp mdn enable',
'lldp transmit interval 8',
'lldp transmit multiplier 8',
'lldp restart 8',
'lldp transmit delay 8',
'lldp trap-interval 8',
'lldp fast-count 8',
'lldp mdn trap-interval 8',
'lldp management-address 1.1.1.1',
'lldp management-address bind interface bind-name']
self.get_nc_config.side_effect = self.get_side_effect
self.set_nc_config.side_effect = [self.result_ok] * 11
set_module_args(dict(
lldpenable='enabled',
mdnstatus='rxOnly',
interval=8,
hold_multiplier=8,
restart_delay=8,
transmit_delay=8,
notification_interval=8,
fast_count=8,
mdn_notification_interval=8,
management_address='1.1.1.1',
bind_name='bind-name')
)
result = self.execute_module(changed=True)
self.assertEqual(sorted(result['updates']), sorted(update))

View file

@ -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 ansible_collections.community.general.tests.unit.compat.mock import patch
from ansible_collections.community.general.plugins.modules.network.cloudengine import ce_lldp_interface
from ansible_collections.community.general.tests.unit.plugins.modules.network.cloudengine.ce_module import TestCloudEngineModule, load_fixture
from ansible_collections.community.general.tests.unit.plugins.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_collections.community.general.plugins.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_collections.community.general.plugins.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)

View file

@ -0,0 +1,67 @@
# (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 ansible_collections.community.general.tests.unit.compat.mock import patch
from ansible_collections.community.general.plugins.modules.network.cloudengine import ce_mdn_interface
from ansible_collections.community.general.tests.unit.plugins.modules.network.cloudengine.ce_module import TestCloudEngineModule, load_fixture
from ansible_collections.community.general.tests.unit.plugins.modules.utils import set_module_args
class TestCloudEngineLacpModule(TestCloudEngineModule):
module = ce_mdn_interface
def setUp(self):
super(TestCloudEngineLacpModule, self).setUp()
self.mock_get_config = patch('ansible_collections.community.general.plugins.modules.network.cloudengine.ce_mdn_interface.get_nc_config')
self.get_nc_config = self.mock_get_config.start()
self.mock_set_config = patch('ansible_collections.community.general.plugins.modules.network.cloudengine.ce_mdn_interface.set_nc_config')
self.set_nc_config = self.mock_set_config.start()
self.set_nc_config.return_value = "<ok/>"
self.before = load_fixture('ce_mdn_interface', 'before.txt')
self.after = load_fixture('ce_mdn_interface', 'after.txt')
def tearDown(self):
super(TestCloudEngineLacpModule, self).tearDown()
self.mock_set_config.stop()
self.mock_get_config.stop()
def test_mdn_enable(self):
update = [['lldp enable', 'interface 10GE1/0/1', 'lldp mdn enable']]
self.get_nc_config.side_effect = (self.before, self.before, self.after, self.after)
set_module_args(dict(
lldpenable='enabled',
mdnstatus='rxOnly',
ifname='10GE1/0/1')
)
result = self.execute_module(changed=True)
self.assertEquals(sorted(result['updates']), sorted(update))
def test_repeat_enable(self):
self.get_nc_config.side_effect = (self.after, self.after, self.after, self.after, )
set_module_args(dict(
lldpenable='enabled',
mdnstatus='rxOnly',
ifname='10GE1/0/1')
)
self.execute_module(changed=False)

View file

@ -0,0 +1,69 @@
# (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 ansible_collections.community.general.tests.unit.compat.mock import patch
from ansible_collections.community.general.plugins.modules.network.cloudengine import ce_multicast_global
from ansible_collections.community.general.tests.unit.plugins.modules.network.cloudengine.ce_module import TestCloudEngineModule, load_fixture
from ansible_collections.community.general.tests.unit.plugins.modules.utils import set_module_args
class TestCloudEngineLacpModule(TestCloudEngineModule):
module = ce_multicast_global
def setUp(self):
super(TestCloudEngineLacpModule, self).setUp()
self.mock_get_config = patch('ansible_collections.community.general.plugins.modules.network.cloudengine.ce_multicast_global.get_nc_config')
self.get_nc_config = self.mock_get_config.start()
self.mock_set_config = patch('ansible_collections.community.general.plugins.modules.network.cloudengine.ce_multicast_global.set_nc_config')
self.set_nc_config = self.mock_set_config.start()
self.set_nc_config.return_value = "<ok/>"
self.before = load_fixture('ce_multicast_global', 'before.txt')
self.after = load_fixture('ce_multicast_global', 'after.txt')
def tearDown(self):
super(TestCloudEngineLacpModule, self).tearDown()
self.mock_set_config.stop()
self.mock_get_config.stop()
def test_multicast_enable(self):
update = ['multicast routing-enable']
self.get_nc_config.side_effect = (self.before, self.after)
set_module_args(dict(
aftype='v4',
vrf='vpna',
state='present')
)
result = self.execute_module(changed=True)
self.assertEquals(sorted(result['updates']), sorted(update))
def test_multicast_undo_enable(self):
update = ['undo multicast routing-enable']
self.get_nc_config.side_effect = (self.after, self.before)
set_module_args(dict(
aftype='v4',
vrf='vpna',
state='absent')
)
result = self.execute_module(changed=True)
self.assertEquals(sorted(result['updates']), sorted(update))

View file

@ -0,0 +1,80 @@
# (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 ansible_collections.community.general.tests.unit.compat.mock import patch
from ansible_collections.community.general.plugins.modules.network.cloudengine import ce_multicast_igmp_enable
from ansible_collections.community.general.tests.unit.plugins.modules.network.cloudengine.ce_module import TestCloudEngineModule, load_fixture
from ansible_collections.community.general.tests.unit.plugins.modules.utils import set_module_args
class TestCloudEngineLacpModule(TestCloudEngineModule):
module = ce_multicast_igmp_enable
def setUp(self):
super(TestCloudEngineLacpModule, self).setUp()
self.mock_get_config = patch('ansible_collections.community.general.plugins.modules.network.cloudengine.ce_multicast_igmp_enable.get_nc_config')
self.get_nc_config = self.mock_get_config.start()
self.mock_set_config = patch('ansible_collections.community.general.plugins.modules.network.cloudengine.ce_multicast_igmp_enable.set_nc_config')
self.set_nc_config = self.mock_set_config.start()
self.set_nc_config.return_value = "<ok/>"
self.before = load_fixture('ce_multicast_igmp_enable', 'before.txt')
self.after = load_fixture('ce_multicast_igmp_enable', 'after.txt')
def tearDown(self):
super(TestCloudEngineLacpModule, self).tearDown()
self.mock_set_config.stop()
self.mock_get_config.stop()
def test_igmp_enable(self):
update = ['igmp snooping enable',
'igmp snooping version 2',
'igmp snooping proxy']
self.get_nc_config.side_effect = (self.before, self.after)
set_module_args(dict(
aftype='v4',
features='vlan',
vlan_id=1,
igmp=True,
version=2,
proxy=True)
)
result = self.execute_module(changed=True)
self.assertEquals(sorted(result['updates']), sorted(update))
def test_igmp_undo_enable(self):
update = ['undo igmp snooping enable',
'undo igmp snooping version',
'undo igmp snooping proxy']
self.get_nc_config.side_effect = (self.after, self.before)
set_module_args(dict(
aftype='v4',
features='vlan',
vlan_id=1,
igmp=True,
version=2,
proxy=True,
state='absent')
)
result = self.execute_module(changed=True)
self.assertEquals(sorted(result['updates']), sorted(update))

View file

@ -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 ansible_collections.community.general.tests.unit.compat.mock import patch
from ansible_collections.community.general.plugins.modules.network.cloudengine import ce_static_route_bfd
from ansible_collections.community.general.tests.unit.plugins.modules.network.cloudengine.ce_module import TestCloudEngineModule, load_fixture
from ansible_collections.community.general.tests.unit.plugins.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_collections.community.general.plugins.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_collections.community.general.plugins.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.assertEqual(sorted(result['updates']), sorted(updates))