mirror of
https://github.com/ansible-collections/community.general.git
synced 2026-05-06 13:22:48 +00:00
Fix unit tests which modify the source tree. (#45763)
* Fix CNOS unit test log usage. * Use temp dir for Galaxy unit tests. * Write to temp files in interfaces_file unit test. * Fix log placement in netapp_e_ldap unit test.
This commit is contained in:
@@ -21,6 +21,7 @@ __metaclass__ = type
|
||||
|
||||
import os
|
||||
import json
|
||||
import tempfile
|
||||
|
||||
from ansible.compat.tests import unittest
|
||||
from ansible.compat.tests.mock import patch
|
||||
@@ -59,6 +60,15 @@ class AnsibleFailJson(Exception):
|
||||
|
||||
|
||||
class TestCnosModule(unittest.TestCase):
|
||||
def setUp(self):
|
||||
super(TestCnosModule, self).setUp()
|
||||
|
||||
self.test_log = tempfile.mkstemp(prefix='ansible-test-cnos-module-', suffix='.log')[1]
|
||||
|
||||
def tearDown(self):
|
||||
super(TestCnosModule, self).tearDown()
|
||||
|
||||
os.remove(self.test_log)
|
||||
|
||||
def execute_module(self, failed=False, changed=False, commands=None,
|
||||
sort=True, defaults=False):
|
||||
|
||||
@@ -22,7 +22,6 @@ class TestCnosBgpModule(TestCnosModule):
|
||||
def tearDown(self):
|
||||
super(TestCnosBgpModule, self).tearDown()
|
||||
self.mock_run_cnos_commands.stop()
|
||||
os.remove('test.log')
|
||||
|
||||
def load_fixtures(self, commands=None, transport='cli'):
|
||||
self.run_cnos_commands.return_value = [load_fixture('cnos_bgp_config.cfg')]
|
||||
@@ -30,7 +29,7 @@ class TestCnosBgpModule(TestCnosModule):
|
||||
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',
|
||||
'outputfile': self.test_log, 'asNum': '33',
|
||||
'bgpArg1': 'neighbor', 'bgpArg2': '10.241.107.40',
|
||||
'bgpArg3': '13', 'bgpArg4': 'address-family',
|
||||
'bgpArg5': 'ipv4', 'bgpArg6': 'next-hop-self'})
|
||||
@@ -41,7 +40,7 @@ class TestCnosBgpModule(TestCnosModule):
|
||||
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',
|
||||
'outputfile': self.test_log, 'asNum': '33',
|
||||
'bgpArg1': 'address-family', 'bgpArg2': 'ipv4',
|
||||
'bgpArg3': 'dampening', 'bgpArg4': '13',
|
||||
'bgpArg5': '233', 'bgpArg6': '333',
|
||||
@@ -53,7 +52,7 @@ class TestCnosBgpModule(TestCnosModule):
|
||||
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',
|
||||
'outputfile': self.test_log, 'asNum': '33',
|
||||
'bgpArg1': 'address-family', 'bgpArg2': 'ipv4',
|
||||
'bgpArg3': 'network', 'bgpArg4': '1.2.3.4/5',
|
||||
'bgpArg5': 'backdoor'})
|
||||
@@ -64,7 +63,7 @@ class TestCnosBgpModule(TestCnosModule):
|
||||
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',
|
||||
'outputfile': self.test_log, 'asNum': '33',
|
||||
'bgpArg1': 'cluster-id', 'bgpArg2': '10.241.107.40'})
|
||||
result = self.execute_module(changed=True)
|
||||
expected_result = 'BGP configurations accomplished'
|
||||
@@ -73,7 +72,7 @@ class TestCnosBgpModule(TestCnosModule):
|
||||
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',
|
||||
'outputfile': self.test_log, 'asNum': '33',
|
||||
'bgpArg1': 'graceful-restart', 'bgpArg2': '333'})
|
||||
result = self.execute_module(changed=True)
|
||||
expected_result = 'BGP configurations accomplished'
|
||||
@@ -82,7 +81,7 @@ class TestCnosBgpModule(TestCnosModule):
|
||||
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',
|
||||
'outputfile': self.test_log, 'asNum': '33',
|
||||
'bgpArg1': 'router-id', 'bgpArg2': '1.2.3.4'})
|
||||
result = self.execute_module(changed=True)
|
||||
expected_result = 'BGP configurations accomplished'
|
||||
@@ -91,7 +90,7 @@ class TestCnosBgpModule(TestCnosModule):
|
||||
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',
|
||||
'outputfile': self.test_log, 'asNum': '33',
|
||||
'bgpArg1': 'vrf'})
|
||||
result = self.execute_module(changed=True)
|
||||
expected_result = 'BGP configurations accomplished'
|
||||
|
||||
@@ -22,7 +22,6 @@ class TestCnosEthernetModule(TestCnosModule):
|
||||
def tearDown(self):
|
||||
super(TestCnosEthernetModule, self).tearDown()
|
||||
self.mock_run_cnos_commands.stop()
|
||||
os.remove('test.log')
|
||||
|
||||
def load_fixtures(self, commands=None, transport='cli'):
|
||||
self.run_cnos_commands.return_value = [load_fixture('cnos_ethernet_config.cfg')]
|
||||
@@ -30,7 +29,7 @@ class TestCnosEthernetModule(TestCnosModule):
|
||||
def test_ethernet_channelgroup(self):
|
||||
set_module_args({'username': 'admin', 'password': 'pass',
|
||||
'host': '10.241.107.39', 'deviceType': 'g8272_cnos',
|
||||
'outputfile': 'test.log', 'interfaceOption': 'ethernet', 'interfaceRange': '33',
|
||||
'outputfile': self.test_log, 'interfaceOption': 'ethernet', 'interfaceRange': '33',
|
||||
'interfaceArg1': 'channel-group', 'interfaceArg2': '33', 'interfaceArg3': 'on'})
|
||||
result = self.execute_module(changed=True)
|
||||
expected_result = 'Interface Configuration is Accomplished'
|
||||
@@ -39,7 +38,7 @@ class TestCnosEthernetModule(TestCnosModule):
|
||||
def test_cnos_ethernet_lacp(self):
|
||||
set_module_args({'username': 'admin', 'password': 'pass',
|
||||
'host': '10.241.107.39', 'deviceType': 'g8272_cnos',
|
||||
'outputfile': 'test.log', 'interfaceOption': 'ethernet', 'interfaceRange': '33',
|
||||
'outputfile': self.test_log, 'interfaceOption': 'ethernet', 'interfaceRange': '33',
|
||||
'interfaceArg1': 'lacp', 'interfaceArg2': 'port-priority', 'interfaceArg3': '33'})
|
||||
result = self.execute_module(changed=True)
|
||||
expected_result = 'Interface Configuration is Accomplished'
|
||||
@@ -48,7 +47,7 @@ class TestCnosEthernetModule(TestCnosModule):
|
||||
def test_cnos_ethernet_duplex(self):
|
||||
set_module_args({'username': 'admin', 'password': 'pass',
|
||||
'host': '10.241.107.39', 'deviceType': 'g8272_cnos',
|
||||
'outputfile': 'test.log', 'interfaceOption': 'ethernet', 'interfaceRange': '33',
|
||||
'outputfile': self.test_log, 'interfaceOption': 'ethernet', 'interfaceRange': '33',
|
||||
'interfaceArg1': 'duplex', 'interfaceArg2': 'auto'})
|
||||
result = self.execute_module(changed=True)
|
||||
expected_result = 'Interface Configuration is Accomplished'
|
||||
@@ -57,7 +56,7 @@ class TestCnosEthernetModule(TestCnosModule):
|
||||
def test_cnos_ethernet_mtu(self):
|
||||
set_module_args({'username': 'admin', 'password': 'pass',
|
||||
'host': '10.241.107.39', 'deviceType': 'g8272_cnos',
|
||||
'outputfile': 'test.log', 'interfaceOption': 'ethernet', 'interfaceRange': '33',
|
||||
'outputfile': self.test_log, 'interfaceOption': 'ethernet', 'interfaceRange': '33',
|
||||
'interfaceArg1': 'mtu', 'interfaceArg2': '1300'})
|
||||
result = self.execute_module(changed=True)
|
||||
expected_result = 'Interface Configuration is Accomplished'
|
||||
@@ -66,7 +65,7 @@ class TestCnosEthernetModule(TestCnosModule):
|
||||
def test_cnos_ethernet_spanningtree(self):
|
||||
set_module_args({'username': 'admin', 'password': 'pass',
|
||||
'host': '10.241.107.39', 'deviceType': 'g8272_cnos',
|
||||
'outputfile': 'test.log', 'interfaceOption': 'ethernet', 'interfaceRange': '33',
|
||||
'outputfile': self.test_log, 'interfaceOption': 'ethernet', 'interfaceRange': '33',
|
||||
'interfaceArg1': 'spanning-tree', 'interfaceArg2': 'mst',
|
||||
'interfaceArg3': '33-35', 'interfaceArg4': 'cost',
|
||||
'interfaceArg5': '33'})
|
||||
@@ -77,7 +76,7 @@ class TestCnosEthernetModule(TestCnosModule):
|
||||
def test_cnos_ethernet_ip(self):
|
||||
set_module_args({'username': 'admin', 'password': 'pass',
|
||||
'host': '10.241.107.39', 'deviceType': 'g8272_cnos',
|
||||
'outputfile': 'test.log', 'interfaceOption': 'ethernet', 'interfaceRange': '33',
|
||||
'outputfile': self.test_log, 'interfaceOption': 'ethernet', 'interfaceRange': '33',
|
||||
'interfaceArg1': 'ip', 'interfaceArg2': 'port',
|
||||
'interfaceArg3': 'anil'})
|
||||
result = self.execute_module(changed=True)
|
||||
|
||||
@@ -22,7 +22,6 @@ class TestCnosPortchannelModule(TestCnosModule):
|
||||
def tearDown(self):
|
||||
super(TestCnosPortchannelModule, self).tearDown()
|
||||
self.mock_run_cnos_commands.stop()
|
||||
os.remove('test.log')
|
||||
|
||||
def load_fixtures(self, commands=None, transport='cli'):
|
||||
self.run_cnos_commands.return_value = [load_fixture('cnos_portchannel_config.cfg')]
|
||||
@@ -30,7 +29,7 @@ class TestCnosPortchannelModule(TestCnosModule):
|
||||
def test_portchannel_channelgroup(self):
|
||||
set_module_args({'username': 'admin', 'password': 'pass',
|
||||
'host': '10.241.107.39', 'deviceType': 'g8272_cnos',
|
||||
'outputfile': 'test.log', 'interfaceRange': '33',
|
||||
'outputfile': self.test_log, 'interfaceRange': '33',
|
||||
'interfaceArg1': 'channel-group', 'interfaceArg2': '33', 'interfaceArg3': 'on'})
|
||||
result = self.execute_module(changed=True)
|
||||
expected_result = 'Port Channel Configuration is done'
|
||||
@@ -39,7 +38,7 @@ class TestCnosPortchannelModule(TestCnosModule):
|
||||
def test_cnos_portchannel_lacp(self):
|
||||
set_module_args({'username': 'admin', 'password': 'pass',
|
||||
'host': '10.241.107.39', 'deviceType': 'g8272_cnos',
|
||||
'outputfile': 'test.log', 'interfaceRange': '33',
|
||||
'outputfile': self.test_log, 'interfaceRange': '33',
|
||||
'interfaceArg1': 'lacp', 'interfaceArg2': 'port-priority', 'interfaceArg3': '33'})
|
||||
result = self.execute_module(changed=True)
|
||||
expected_result = 'Port Channel Configuration is done'
|
||||
@@ -48,7 +47,7 @@ class TestCnosPortchannelModule(TestCnosModule):
|
||||
def test_cnos_portchannel_duplex(self):
|
||||
set_module_args({'username': 'admin', 'password': 'pass',
|
||||
'host': '10.241.107.39', 'deviceType': 'g8272_cnos',
|
||||
'outputfile': 'test.log', 'interfaceRange': '2',
|
||||
'outputfile': self.test_log, 'interfaceRange': '2',
|
||||
'interfaceArg1': 'duplex', 'interfaceArg2': 'auto'})
|
||||
result = self.execute_module(changed=True)
|
||||
expected_result = 'Port Channel Configuration is done'
|
||||
@@ -57,7 +56,7 @@ class TestCnosPortchannelModule(TestCnosModule):
|
||||
def test_cnos_portchannel_mtu(self):
|
||||
set_module_args({'username': 'admin', 'password': 'pass',
|
||||
'host': '10.241.107.39', 'deviceType': 'g8272_cnos',
|
||||
'outputfile': 'test.log', 'interfaceRange': '33',
|
||||
'outputfile': self.test_log, 'interfaceRange': '33',
|
||||
'interfaceArg1': 'mtu', 'interfaceArg2': '1300'})
|
||||
result = self.execute_module(changed=True)
|
||||
expected_result = 'Port Channel Configuration is done'
|
||||
@@ -66,7 +65,7 @@ class TestCnosPortchannelModule(TestCnosModule):
|
||||
def test_cnos_portchannel_spanningtree(self):
|
||||
set_module_args({'username': 'admin', 'password': 'pass',
|
||||
'host': '10.241.107.39', 'deviceType': 'g8272_cnos',
|
||||
'outputfile': 'test.log', 'interfaceRange': '33',
|
||||
'outputfile': self.test_log, 'interfaceRange': '33',
|
||||
'interfaceArg1': 'spanning-tree', 'interfaceArg2': 'mst',
|
||||
'interfaceArg3': '33-35', 'interfaceArg4': 'cost',
|
||||
'interfaceArg5': '33'})
|
||||
@@ -77,7 +76,7 @@ class TestCnosPortchannelModule(TestCnosModule):
|
||||
def test_cnos_portchannel_ip(self):
|
||||
set_module_args({'username': 'admin', 'password': 'pass',
|
||||
'host': '10.241.107.39', 'deviceType': 'g8272_cnos',
|
||||
'outputfile': 'test.log', 'interfaceRange': '33',
|
||||
'outputfile': self.test_log, 'interfaceRange': '33',
|
||||
'interfaceArg1': 'ip', 'interfaceArg2': 'port',
|
||||
'interfaceArg3': 'anil'})
|
||||
result = self.execute_module(changed=True)
|
||||
|
||||
@@ -22,7 +22,6 @@ class TestCnosVlagModule(TestCnosModule):
|
||||
def tearDown(self):
|
||||
super(TestCnosVlagModule, self).tearDown()
|
||||
self.mock_run_cnos_commands.stop()
|
||||
os.remove('test.log')
|
||||
|
||||
def load_fixtures(self, commands=None, transport='cli'):
|
||||
self.run_cnos_commands.return_value = [load_fixture('cnos_vlag_config.cfg')]
|
||||
@@ -30,7 +29,7 @@ class TestCnosVlagModule(TestCnosModule):
|
||||
def test_cnos_vlag_enable(self):
|
||||
set_module_args({'username': 'admin', 'password': 'admin',
|
||||
'host': '10.241.107.39', 'deviceType': 'g8272_cnos',
|
||||
'outputfile': 'test.log', 'vlagArg1': 'enable'})
|
||||
'outputfile': self.test_log, 'vlagArg1': 'enable'})
|
||||
result = self.execute_module(changed=True)
|
||||
expected_result = 'VLAG configurations accomplished'
|
||||
self.assertEqual(result['msg'], expected_result)
|
||||
@@ -38,7 +37,7 @@ class TestCnosVlagModule(TestCnosModule):
|
||||
def test_cnos_vlag_instance(self):
|
||||
set_module_args({'username': 'admin', 'password': 'pass',
|
||||
'host': '10.241.107.39', 'deviceType': 'g8272_cnos',
|
||||
'outputfile': 'test.log', 'vlagArg1': 'instance',
|
||||
'outputfile': self.test_log, 'vlagArg1': 'instance',
|
||||
'vlagArg2': '33', 'vlagArg3': '333'})
|
||||
result = self.execute_module(changed=True)
|
||||
expected_result = 'VLAG configurations accomplished'
|
||||
@@ -47,7 +46,7 @@ class TestCnosVlagModule(TestCnosModule):
|
||||
def test_cnos_vlag_hlthchk(self):
|
||||
set_module_args({'username': 'admin', 'password': 'pass',
|
||||
'host': '10.241.107.39', 'deviceType': 'g8272_cnos',
|
||||
'outputfile': 'test.log', 'vlagArg1': 'hlthchk',
|
||||
'outputfile': self.test_log, 'vlagArg1': 'hlthchk',
|
||||
'vlagArg2': 'keepalive-interval', 'vlagArg3': '131'})
|
||||
result = self.execute_module(changed=True)
|
||||
expected_result = 'VLAG configurations accomplished'
|
||||
|
||||
@@ -22,7 +22,6 @@ class TestCnosVlanModule(TestCnosModule):
|
||||
def tearDown(self):
|
||||
super(TestCnosVlanModule, self).tearDown()
|
||||
self.mock_run_cnos_commands.stop()
|
||||
os.remove('test.log')
|
||||
|
||||
def load_fixtures(self, commands=None, transport='cli'):
|
||||
self.run_cnos_commands.return_value = [load_fixture('cnos_vlan_config.cfg')]
|
||||
@@ -30,7 +29,7 @@ class TestCnosVlanModule(TestCnosModule):
|
||||
def test_cnos_vlan_create(self):
|
||||
set_module_args({'username': 'admin', 'password': 'pass',
|
||||
'host': '10.241.107.39', 'deviceType': 'g8272_cnos',
|
||||
'outputfile': 'test.log', 'vlanArg1': '13',
|
||||
'outputfile': self.test_log, 'vlanArg1': '13',
|
||||
'vlanArg2': 'name', 'vlanArg3': 'anil'})
|
||||
result = self.execute_module(changed=True)
|
||||
expected_result = 'VLAN configuration is accomplished'
|
||||
@@ -39,7 +38,7 @@ class TestCnosVlanModule(TestCnosModule):
|
||||
def test_cnos_vlan_state(self):
|
||||
set_module_args({'username': 'admin', 'password': 'pass',
|
||||
'host': '10.241.107.39', 'deviceType': 'g8272_cnos',
|
||||
'outputfile': 'test.log', 'vlanArg1': '13',
|
||||
'outputfile': self.test_log, 'vlanArg1': '13',
|
||||
'vlanArg2': 'state', 'vlanArg3': 'active'})
|
||||
result = self.execute_module(changed=True)
|
||||
expected_result = 'VLAN configuration is accomplished'
|
||||
|
||||
Reference in New Issue
Block a user