Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix unit tests which modify the source tree. #45763

Merged
merged 4 commits into from
Sep 18, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 6 additions & 0 deletions test/units/cli/test_galaxy.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,9 @@ def setUpClass(cls):
'''creating prerequisites for installing a role; setUpClass occurs ONCE whereas setUp occurs with every method tested.'''
# class data for easy viewing: role_dir, role_tar, role_name, role_req, role_path

cls.temp_dir = tempfile.mkdtemp(prefix='ansible-test_galaxy-')
os.chdir(cls.temp_dir)

if os.path.exists("./delete_me"):
shutil.rmtree("./delete_me")

Expand Down Expand Up @@ -89,6 +92,9 @@ def tearDownClass(cls):
if os.path.isdir(cls.role_path):
shutil.rmtree(cls.role_path)

os.chdir('/')
shutil.rmtree(cls.temp_dir)

def setUp(self):
self.default_args = ['ansible-galaxy']

Expand Down
10 changes: 10 additions & 0 deletions test/units/modules/network/cnos/cnos_module.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@

import os
import json
import tempfile

from ansible.compat.tests import unittest
from ansible.compat.tests.mock import patch
Expand Down Expand Up @@ -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):
Expand Down
15 changes: 7 additions & 8 deletions test/units/modules/network/cnos/test_cnos_bgp.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,14 @@ def setUp(self):
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')]

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'})
Expand All @@ -41,7 +40,7 @@ def test_bgp_neighbor(self):
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',
Expand All @@ -53,7 +52,7 @@ def test_cnos_bgp_dampening(self):
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'})
Expand All @@ -64,7 +63,7 @@ def test_cnos_bgp_network(self):
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'
Expand All @@ -73,7 +72,7 @@ def test_cnos_bgp_clusterid(self):
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'
Expand All @@ -82,7 +81,7 @@ def test_cnos_bgp_graceful_restart(self):
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'
Expand All @@ -91,7 +90,7 @@ def test_cnos_bgp_routerid(self):
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'
Expand Down
13 changes: 6 additions & 7 deletions test/units/modules/network/cnos/test_cnos_ethernet.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,14 @@ def setUp(self):
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')]

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'
Expand All @@ -39,7 +38,7 @@ def test_ethernet_channelgroup(self):
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'
Expand All @@ -48,7 +47,7 @@ def test_cnos_ethernet_lacp(self):
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'
Expand All @@ -57,7 +56,7 @@ def test_cnos_ethernet_duplex(self):
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'
Expand All @@ -66,7 +65,7 @@ def test_cnos_ethernet_mtu(self):
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'})
Expand All @@ -77,7 +76,7 @@ def test_cnos_ethernet_spanningtree(self):
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)
Expand Down
13 changes: 6 additions & 7 deletions test/units/modules/network/cnos/test_cnos_portchannel.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,14 @@ def setUp(self):
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')]

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'
Expand All @@ -39,7 +38,7 @@ def test_portchannel_channelgroup(self):
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'
Expand All @@ -48,7 +47,7 @@ def test_cnos_portchannel_lacp(self):
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'
Expand All @@ -57,7 +56,7 @@ def test_cnos_portchannel_duplex(self):
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'
Expand All @@ -66,7 +65,7 @@ def test_cnos_portchannel_mtu(self):
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'})
Expand All @@ -77,7 +76,7 @@ def test_cnos_portchannel_spanningtree(self):
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)
Expand Down
7 changes: 3 additions & 4 deletions test/units/modules/network/cnos/test_cnos_vlag.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,23 +22,22 @@ def setUp(self):
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')]

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)

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'
Expand All @@ -47,7 +46,7 @@ def test_cnos_vlag_instance(self):
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'
Expand Down
5 changes: 2 additions & 3 deletions test/units/modules/network/cnos/test_cnos_vlan.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,14 @@ def setUp(self):
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')]

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'
Expand All @@ -39,7 +38,7 @@ def test_cnos_vlan_create(self):
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'
Expand Down
17 changes: 15 additions & 2 deletions test/units/modules/storage/netapp/test_netapp_e_ldap.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
# (c) 2018, NetApp Inc.
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)

import os
import shutil
import tempfile

from ansible.modules.storage.netapp.netapp_e_ldap import Ldap
from units.modules.utils import ModuleTestCase, set_module_args, AnsibleFailJson, AnsibleExitJson

Expand All @@ -15,11 +19,20 @@ class LdapTest(ModuleTestCase):
'api_url': 'http://localhost',
'ssid': '1',
'state': 'absent',
'log_path': './debug.log'

}
REQ_FUNC = 'ansible.modules.storage.netapp.netapp_e_ldap.request'

def setUp(self):
super(LdapTest, self).setUp()

self.temp_dir = tempfile.mkdtemp('ansible-test_netapp_e_ldap-')
self.REQUIRED_PARAMS['log_path'] = os.path.join(self.temp_dir, 'debug.log')

def tearDown(self):
super(LdapTest, self).tearDown()

shutil.rmtree(self.temp_dir)

def _make_ldap_instance(self):
self._set_args()
ldap = Ldap()
Expand Down