aboutsummaryrefslogtreecommitdiffstats
path: root/functest/tests
diff options
context:
space:
mode:
Diffstat (limited to 'functest/tests')
-rw-r--r--functest/tests/unit/ci/test_prepare_env.py6
-rw-r--r--functest/tests/unit/cli/commands/test_cli_os.py4
-rw-r--r--functest/tests/unit/odl/test_odl.py48
-rw-r--r--functest/tests/unit/openstack/refstack_client/test_refstack_client.py22
-rw-r--r--functest/tests/unit/openstack/vping/test_vping.py157
-rw-r--r--functest/tests/unit/utils/test_openstack_utils.py53
6 files changed, 189 insertions, 101 deletions
diff --git a/functest/tests/unit/ci/test_prepare_env.py b/functest/tests/unit/ci/test_prepare_env.py
index 69abd643..7d4b5fb2 100644
--- a/functest/tests/unit/ci/test_prepare_env.py
+++ b/functest/tests/unit/ci/test_prepare_env.py
@@ -441,7 +441,7 @@ class PrepareEnvTesting(unittest.TestCase):
mock_check_env):
with mock.patch("__builtin__.open", mock.mock_open()) as m:
args = {'action': 'start'}
- self.assertEqual(prepare_env.main(**args), 0)
+ self.assertEqual(prepare_env.prepare_env(**args), 0)
mock_logger_info.assert_any_call("######### Preparing Functest "
"environment #########\n")
self.assertTrue(mock_env_var.called)
@@ -459,13 +459,13 @@ class PrepareEnvTesting(unittest.TestCase):
@mock.patch('functest.ci.prepare_env.check_environment')
def test_main_check(self, mock_check_env):
args = {'action': 'check'}
- self.assertEqual(prepare_env.main(**args), 0)
+ self.assertEqual(prepare_env.prepare_env(**args), 0)
self.assertTrue(mock_check_env.called)
@mock.patch('functest.ci.prepare_env.logger.error')
def test_main_no_arg(self, mock_logger_error):
args = {'action': 'not_valid'}
- self.assertEqual(prepare_env.main(**args), -1)
+ self.assertEqual(prepare_env.prepare_env(**args), -1)
mock_logger_error.assert_called_once_with('Argument not valid.')
diff --git a/functest/tests/unit/cli/commands/test_cli_os.py b/functest/tests/unit/cli/commands/test_cli_os.py
index 50ebe4b5..a3d930de 100644
--- a/functest/tests/unit/cli/commands/test_cli_os.py
+++ b/functest/tests/unit/cli/commands/test_cli_os.py
@@ -8,7 +8,6 @@
#
import logging
-import pkg_resources
import unittest
import os
@@ -65,8 +64,7 @@ class CliOpenStackTesting(unittest.TestCase):
with mock.patch.object(self.cli_os, 'ping_endpoint'):
self.cli_os.check()
mock_ftutils_execute.assert_called_once_with(
- "sh %s" % pkg_resources.resource_filename(
- 'functest', 'ci/check_os.sh'), verbose=False)
+ "check_os.sh", verbose=False)
@mock.patch('functest.cli.commands.cli_os.os.path.isfile',
return_value=False)
diff --git a/functest/tests/unit/odl/test_odl.py b/functest/tests/unit/odl/test_odl.py
index 60adf211..070a8d2e 100644
--- a/functest/tests/unit/odl/test_odl.py
+++ b/functest/tests/unit/odl/test_odl.py
@@ -202,10 +202,10 @@ class ODLRobotTesting(ODLTesting):
class ODLMainTesting(ODLTesting):
- """The class testing ODLTests.main()."""
+ """The class testing ODLTests.run_suites()."""
# pylint: disable=missing-docstring
- def _get_main_kwargs(self, key=None):
+ def _get_run_suites_kwargs(self, key=None):
kwargs = {'odlusername': self._odl_username,
'odlpassword': self._odl_password,
'neutronip': self._neutron_ip,
@@ -220,9 +220,9 @@ class ODLMainTesting(ODLTesting):
del kwargs[key]
return kwargs
- def _test_main(self, status, *args):
- kwargs = self._get_main_kwargs()
- self.assertEqual(self.test.main(**kwargs), status)
+ def _test_run_suites(self, status, *args):
+ kwargs = self._get_run_suites_kwargs()
+ self.assertEqual(self.test.run_suites(**kwargs), status)
if len(args) > 0:
args[0].assert_called_once_with(
odl.ODLTests.res_dir)
@@ -249,8 +249,8 @@ class ODLMainTesting(ODLTesting):
os.path.join(odl.ODLTests.res_dir, 'stdout.txt'))
def _test_no_keyword(self, key):
- kwargs = self._get_main_kwargs(key)
- self.assertEqual(self.test.main(**kwargs),
+ kwargs = self._get_run_suites_kwargs(key)
+ self.assertEqual(self.test.run_suites(**kwargs),
testcase.TestCase.EX_RUN_ERROR)
def test_no_odlusername(self):
@@ -286,7 +286,7 @@ class ODLMainTesting(ODLTesting):
def test_set_vars_ko(self):
with mock.patch.object(self.test, 'set_robotframework_vars',
return_value=False) as mock_object:
- self._test_main(testcase.TestCase.EX_RUN_ERROR)
+ self._test_run_suites(testcase.TestCase.EX_RUN_ERROR)
mock_object.assert_called_once_with(
self._odl_username, self._odl_password)
@@ -295,15 +295,15 @@ class ODLMainTesting(ODLTesting):
with mock.patch.object(self.test, 'set_robotframework_vars',
return_value=True), \
self.assertRaises(Exception):
- self._test_main(testcase.TestCase.EX_RUN_ERROR,
- mock_method)
+ self._test_run_suites(testcase.TestCase.EX_RUN_ERROR,
+ mock_method)
@mock.patch('os.makedirs', side_effect=OSError)
def test_makedirs_oserror(self, mock_method):
with mock.patch.object(self.test, 'set_robotframework_vars',
return_value=True):
- self._test_main(testcase.TestCase.EX_RUN_ERROR,
- mock_method)
+ self._test_run_suites(testcase.TestCase.EX_RUN_ERROR,
+ mock_method)
@mock.patch('robot.run', side_effect=RobotError)
@mock.patch('os.makedirs')
@@ -311,7 +311,7 @@ class ODLMainTesting(ODLTesting):
with mock.patch.object(self.test, 'set_robotframework_vars',
return_value=True), \
self.assertRaises(RobotError):
- self._test_main(testcase.TestCase.EX_RUN_ERROR, *args)
+ self._test_run_suites(testcase.TestCase.EX_RUN_ERROR, *args)
@mock.patch('robot.run')
@mock.patch('os.makedirs')
@@ -320,7 +320,7 @@ class ODLMainTesting(ODLTesting):
return_value=True), \
mock.patch.object(self.test, 'parse_results',
side_effect=RobotError):
- self._test_main(testcase.TestCase.EX_RUN_ERROR, *args)
+ self._test_run_suites(testcase.TestCase.EX_RUN_ERROR, *args)
@mock.patch('robot.run')
@mock.patch('os.makedirs')
@@ -328,7 +328,7 @@ class ODLMainTesting(ODLTesting):
with mock.patch.object(self.test, 'set_robotframework_vars',
return_value=True), \
mock.patch.object(self.test, 'parse_results'):
- self._test_main(testcase.TestCase.EX_OK, *args)
+ self._test_run_suites(testcase.TestCase.EX_OK, *args)
@mock.patch('robot.run')
@mock.patch('os.makedirs', side_effect=OSError(errno.EEXIST, ''))
@@ -336,7 +336,7 @@ class ODLMainTesting(ODLTesting):
with mock.patch.object(self.test, 'set_robotframework_vars',
return_value=True), \
mock.patch.object(self.test, 'parse_results'):
- self._test_main(testcase.TestCase.EX_OK, *args)
+ self._test_run_suites(testcase.TestCase.EX_OK, *args)
@mock.patch('robot.run', return_value=1)
@mock.patch('os.makedirs')
@@ -344,7 +344,7 @@ class ODLMainTesting(ODLTesting):
with mock.patch.object(self.test, 'set_robotframework_vars',
return_value=True), \
mock.patch.object(self.test, 'parse_results'):
- self._test_main(testcase.TestCase.EX_OK, *args)
+ self._test_run_suites(testcase.TestCase.EX_OK, *args)
class ODLRunTesting(ODLTesting):
@@ -371,11 +371,11 @@ class ODLRunTesting(ODLTesting):
return_value="http://{}:9696".format(
ODLTesting._neutron_ip)):
if exception:
- self.test.main = mock.Mock(side_effect=exception)
+ self.test.run_suites = mock.Mock(side_effect=exception)
else:
- self.test.main = mock.Mock(return_value=status)
+ self.test.run_suites = mock.Mock(return_value=status)
self.assertEqual(self.test.run(), status)
- self.test.main.assert_called_once_with(
+ self.test.run_suites.assert_called_once_with(
odl.ODLTests.default_suites,
neutronip=self._neutron_ip,
odlip=odlip, odlpassword=self._odl_password,
@@ -394,9 +394,9 @@ class ODLRunTesting(ODLTesting):
with mock.patch('functest.utils.openstack_utils.get_endpoint',
return_value="http://{}:9696".format(
ODLTesting._neutron_ip)):
- self.test.main = mock.Mock(return_value=status)
+ self.test.run_suites = mock.Mock(return_value=status)
self.assertEqual(self.test.run(suites=suites), status)
- self.test.main.assert_called_once_with(
+ self.test.run_suites.assert_called_once_with(
suites,
neutronip=self._neutron_ip,
odlip=odlip, odlpassword=self._odl_password,
@@ -424,13 +424,13 @@ class ODLRunTesting(ODLTesting):
def test_no_os_tenant_name(self):
self._test_no_env_var("OS_TENANT_NAME")
- def test_main_false(self):
+ def test_run_suites_false(self):
os.environ["SDN_CONTROLLER_IP"] = self._sdn_controller_ip
self._test_run(testcase.TestCase.EX_RUN_ERROR,
odlip=self._sdn_controller_ip,
odlwebport=self._odl_webport)
- def test_main_exc(self):
+ def test_run_suites_exc(self):
with self.assertRaises(Exception):
os.environ["SDN_CONTROLLER_IP"] = self._sdn_controller_ip
self._test_run(status=testcase.TestCase.EX_RUN_ERROR,
diff --git a/functest/tests/unit/openstack/refstack_client/test_refstack_client.py b/functest/tests/unit/openstack/refstack_client/test_refstack_client.py
index 3a121245..f92d2806 100644
--- a/functest/tests/unit/openstack/refstack_client/test_refstack_client.py
+++ b/functest/tests/unit/openstack/refstack_client/test_refstack_client.py
@@ -1,5 +1,6 @@
#!/usr/bin/env python
-
+# Copyright (c) 2017 Huawei Technologies Co.,Ltd and others.
+# matthew.lijun@huawei.com wangwulin@huawei.com
# All rights reserved. This program and the accompanying materials
# are made available under the terms of the Apache License, Version 2.0
# which accompanies this distribution, and is available at
@@ -12,7 +13,6 @@ import unittest
from functest.core import testcase
from functest.opnfv_tests.openstack.refstack_client import refstack_client
-from functest.utils.constants import CONST
class OSRefstackClientTesting(unittest.TestCase):
@@ -28,27 +28,13 @@ class OSRefstackClientTesting(unittest.TestCase):
'testlist': self._testlist}
self.refstackclient = refstack_client.RefstackClient()
- def test_source_venv(self):
- with mock.patch('functest.opnfv_tests.openstack.refstack_client.'
- 'refstack_client.ft_utils.execute_command') as m:
- cmd = ("cd {0};"
- ". .venv/bin/activate;"
- "cd -;"
- .format(CONST.__getattribute__('dir_refstack_client')))
- self.refstackclient.source_venv()
- m.assert_any_call(cmd)
-
def test_run_defcore(self):
config = 'tempest.conf'
testlist = 'testlist'
with mock.patch('functest.opnfv_tests.openstack.refstack_client.'
'refstack_client.ft_utils.execute_command') as m:
- cmd = ("cd {0};"
- "./refstack-client test -c {1} -v --test-list {2};"
- "cd -;"
- .format(CONST.__getattribute__('dir_refstack_client'),
- config,
- testlist))
+ cmd = ("refstack-client test -c {0} -v --test-list {1}"
+ .format(config, testlist))
self.refstackclient.run_defcore(config, testlist)
m.assert_any_call(cmd)
diff --git a/functest/tests/unit/openstack/vping/test_vping.py b/functest/tests/unit/openstack/vping/test_vping.py
new file mode 100644
index 00000000..b229c351
--- /dev/null
+++ b/functest/tests/unit/openstack/vping/test_vping.py
@@ -0,0 +1,157 @@
+# Copyright (c) 2017 Cable Television Laboratories, Inc. and others.
+#
+# All rights reserved. This program and the accompanying materials
+# are made available under the terms of the Apache License, Version 2.0
+# which accompanies this distribution, and is available at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+
+import unittest
+
+import mock
+
+from snaps.openstack.create_image import OpenStackImage
+from snaps.openstack.create_instance import OpenStackVmInstance, \
+ VmInstanceSettings
+from snaps.openstack.create_keypairs import OpenStackKeypair, KeypairSettings
+from snaps.openstack.create_network import OpenStackNetwork, NetworkSettings, \
+ SubnetSettings, PortSettings
+from snaps.openstack.create_router import OpenStackRouter, RouterSettings
+from snaps.openstack.create_security_group import OpenStackSecurityGroup, \
+ SecurityGroupSettings
+from snaps.openstack.os_credentials import OSCreds
+
+from functest.core.testcase import TestCase
+from functest.opnfv_tests.openstack.vping import vping_userdata, vping_ssh
+
+
+class VPingUserdataTesting(unittest.TestCase):
+ """
+ Ensures the VPingUserdata class can run in Functest. This test does not
+ actually connect with an OpenStack pod.
+ """
+
+ def setUp(self):
+ self.os_creds = OSCreds(
+ username='user', password='pass',
+ auth_url='http://foo.com:5000/v3', project_name='bar')
+
+ self.vping_userdata = vping_userdata.VPingUserdata(
+ os_creds=self.os_creds)
+
+ @mock.patch('snaps.openstack.utils.deploy_utils.create_vm_instance')
+ @mock.patch('functest.opnfv_tests.openstack.vping.vping_base.os.'
+ 'path.exists', return_value=True)
+ @mock.patch('snaps.openstack.create_flavor.OpenStackFlavor.create',
+ return_value=None)
+ @mock.patch('snaps.openstack.create_instance.OpenStackVmInstance.'
+ 'get_port_ip', return_value='10.0.0.1')
+ @mock.patch('snaps.openstack.create_instance.OpenStackVmInstance.'
+ 'vm_active', return_value=True)
+ def test_vping_userdata(self, deploy_vm, path_exists, create_flavor,
+ get_port_ip, vm_active):
+ os_vm_inst = mock.MagicMock(name='get_console_output')
+ os_vm_inst.get_console_output.return_value = 'vPing OK'
+ with mock.patch('snaps.openstack.utils.deploy_utils.create_image',
+ return_value=OpenStackImage(self.os_creds, None)), \
+ mock.patch('snaps.openstack.utils.deploy_utils.create_network',
+ return_value=OpenStackNetwork(
+ self.os_creds, NetworkSettings(name='foo'))), \
+ mock.patch('snaps.openstack.utils.deploy_utils.'
+ 'create_vm_instance',
+ return_value=OpenStackVmInstance(
+ self.os_creds,
+ VmInstanceSettings(
+ name='foo', flavor='bar',
+ port_settings=[PortSettings(
+ name='foo', network_name='bar')]),
+ None)), \
+ mock.patch('snaps.openstack.create_instance.'
+ 'OpenStackVmInstance.get_os_vm_server_obj',
+ return_value=os_vm_inst):
+ self.assertEquals(TestCase.EX_OK, self.vping_userdata.run())
+
+
+class VPingSSHTesting(unittest.TestCase):
+ """
+ Ensures the VPingUserdata class can run in Functest. This test does not
+ actually connect with an OpenStack pod.
+ """
+
+ def setUp(self):
+ self.os_creds = OSCreds(
+ username='user', password='pass',
+ auth_url='http://foo.com:5000/v3', project_name='bar')
+
+ self.vping_ssh = vping_ssh.VPingSSH(
+ os_creds=self.os_creds)
+
+ @mock.patch('snaps.openstack.utils.deploy_utils.create_vm_instance')
+ @mock.patch('functest.opnfv_tests.openstack.vping.vping_base.os.'
+ 'path.exists', return_value=True)
+ @mock.patch('snaps.openstack.create_flavor.OpenStackFlavor.create',
+ return_value=None)
+ @mock.patch('snaps.openstack.create_instance.OpenStackVmInstance.'
+ 'get_port_ip', return_value='10.0.0.1')
+ @mock.patch('snaps.openstack.create_instance.OpenStackVmInstance.'
+ 'vm_active', return_value=True)
+ @mock.patch('snaps.openstack.create_instance.OpenStackVmInstance.'
+ 'vm_ssh_active', return_value=True)
+ @mock.patch('snaps.openstack.create_instance.OpenStackVmInstance.'
+ 'ssh_client', return_value=True)
+ @mock.patch('scp.SCPClient')
+ @mock.patch('functest.opnfv_tests.openstack.vping.vping_ssh.'
+ 'VPingSSH._transfer_ping_script', return_value=True)
+ @mock.patch('functest.opnfv_tests.openstack.vping.vping_ssh.'
+ 'VPingSSH._do_vping_ssh', return_value=TestCase.EX_OK)
+ @mock.patch('functest.opnfv_tests.openstack.snaps.snaps_utils.'
+ 'get_ext_net_name', return_value='foo')
+ def test_vping_ssh(self, create_vm, path_exists,
+ flavor_create, get_port_ip, vm_active, ssh_active,
+ ssh_client, scp_client, trans_script, do_vping_ssh,
+ ext_net_name):
+ os_vm_inst = mock.MagicMock(name='get_console_output')
+ os_vm_inst.get_console_output.return_value = 'vPing OK'
+ ssh_client = mock.MagicMock(name='get_transport')
+ ssh_client.get_transport.return_value = None
+ scp_client = mock.MagicMock(name='put')
+ scp_client.put.return_value = None
+
+ with mock.patch('snaps.openstack.utils.deploy_utils.create_image',
+ return_value=OpenStackImage(self.os_creds, None)), \
+ mock.patch('snaps.openstack.utils.deploy_utils.create_network',
+ return_value=OpenStackNetwork(
+ self.os_creds,
+ NetworkSettings(
+ name='foo',
+ subnet_settings=[
+ SubnetSettings(
+ name='bar',
+ cidr='10.0.0.1/24')]))), \
+ mock.patch('snaps.openstack.utils.deploy_utils.'
+ 'create_vm_instance',
+ return_value=OpenStackVmInstance(
+ self.os_creds,
+ VmInstanceSettings(
+ name='foo', flavor='bar',
+ port_settings=[PortSettings(
+ name='foo', network_name='bar')]),
+ None)), \
+ mock.patch('snaps.openstack.utils.deploy_utils.create_keypair',
+ return_value=OpenStackKeypair(
+ self.os_creds, KeypairSettings(name='foo'))), \
+ mock.patch('snaps.openstack.utils.deploy_utils.create_router',
+ return_value=OpenStackRouter(
+ self.os_creds, RouterSettings(name='foo'))), \
+ mock.patch('snaps.openstack.utils.deploy_utils.'
+ 'create_security_group',
+ return_value=OpenStackSecurityGroup(
+ self.os_creds,
+ SecurityGroupSettings(name='foo'))), \
+ mock.patch('snaps.openstack.create_instance.'
+ 'OpenStackVmInstance.'
+ 'get_vm_inst', return_value=os_vm_inst), \
+ mock.patch('snaps.openstack.create_instance.'
+ 'OpenStackVmInstance.'
+ 'ssh_client', return_value=ssh_client):
+ self.assertEquals(TestCase.EX_OK, self.vping_ssh.run())
diff --git a/functest/tests/unit/utils/test_openstack_utils.py b/functest/tests/unit/utils/test_openstack_utils.py
index 74b49aaa..828fb3d4 100644
--- a/functest/tests/unit/utils/test_openstack_utils.py
+++ b/functest/tests/unit/utils/test_openstack_utils.py
@@ -255,12 +255,6 @@ class OSUtilsTesting(unittest.TestCase):
'delete_port.return_value': mock.Mock(),
'remove_interface_router.return_value': mock.Mock(),
'remove_gateway_router.return_value': mock.Mock(),
- 'create_bgpvpn.return_value': self.mock_return,
- 'create_network_association.return_value': self.mock_return,
- 'create_router_association.return_value': self.mock_return,
- 'update_bgpvpn.return_value': self.mock_return,
- 'delete_bgpvpn.return_value': self.mock_return,
- 'show_bgpvpn.return_value': self.mock_return,
'list_security_groups.return_value': {'security_groups':
[self.sec_group]},
'list_security_group_rules.'
@@ -1212,53 +1206,6 @@ class OSUtilsTesting(unittest.TestCase):
'router_id'))
self.assertTrue(mock_logger_error.called)
- def test_create_bgpvpn(self):
- self.assertEqual(openstack_utils.
- create_bgpvpn(self.neutron_client),
- self.mock_return)
-
- def test_create_network_association(self):
- self.assertEqual(openstack_utils.
- create_network_association(self.neutron_client,
- 'bgpvpn_id',
- 'network_id'),
- self.mock_return)
-
- def test_create_router_association(self):
- self.assertEqual(openstack_utils.
- create_router_association(self.neutron_client,
- 'bgpvpn_id',
- 'router_id'),
- self.mock_return)
-
- def test_update_bgpvpn(self):
- self.assertEqual(openstack_utils.
- update_bgpvpn(self.neutron_client,
- 'bgpvpn_id'),
- self.mock_return)
-
- def test_delete_bgpvpn(self):
- self.assertEqual(openstack_utils.
- delete_bgpvpn(self.neutron_client,
- 'bgpvpn_id'),
- self.mock_return)
-
- def test_get_bgpvpn(self):
- self.assertEqual(openstack_utils.
- get_bgpvpn(self.neutron_client,
- 'bgpvpn_id'),
- self.mock_return)
-
- def test_get_bgpvpn_routers(self):
- with mock.patch('functest.utils.openstack_utils.'
- 'get_bgpvpn',
- return_value={'bgpvpn':
- {'routers': [self.router]}}):
- self.assertEqual(openstack_utils.
- get_bgpvpn_routers(self.neutron_client,
- 'bgpvpn_id'),
- [self.router])
-
def test_get_security_groups_default(self):
self.assertEqual(openstack_utils.
get_security_groups(self.neutron_client),