diff options
Diffstat (limited to 'functest/tests')
-rw-r--r-- | functest/tests/unit/ci/test_prepare_env.py | 8 | ||||
-rw-r--r-- | functest/tests/unit/openstack/snaps/test_snaps.py | 169 | ||||
-rw-r--r-- | functest/tests/unit/utils/test_openstack_clean.py | 16 | ||||
-rw-r--r-- | functest/tests/unit/utils/test_openstack_snapshot.py | 16 | ||||
-rw-r--r-- | functest/tests/unit/utils/test_openstack_utils.py | 24 |
5 files changed, 192 insertions, 41 deletions
diff --git a/functest/tests/unit/ci/test_prepare_env.py b/functest/tests/unit/ci/test_prepare_env.py index f3e15a01..69abd643 100644 --- a/functest/tests/unit/ci/test_prepare_env.py +++ b/functest/tests/unit/ci/test_prepare_env.py @@ -424,7 +424,6 @@ class PrepareEnvTesting(unittest.TestCase): mock_logger_info.assert_any_call("Functest environment" " is installed.") - @mock.patch('functest.ci.prepare_env.print_deployment_info') @mock.patch('functest.ci.prepare_env.check_environment') @mock.patch('functest.ci.prepare_env.create_flavor') @mock.patch('functest.ci.prepare_env.install_tempest') @@ -433,21 +432,19 @@ class PrepareEnvTesting(unittest.TestCase): @mock.patch('functest.ci.prepare_env.update_config_file') @mock.patch('functest.ci.prepare_env.source_rc_file') @mock.patch('functest.ci.prepare_env.create_directories') - @mock.patch('functest.ci.prepare_env.get_deployment_handler') @mock.patch('functest.ci.prepare_env.check_env_variables') @mock.patch('functest.ci.prepare_env.logger.info') - def test_main_start(self, mock_logger_info, mock_env_var, mock_dep_handler, + def test_main_start(self, mock_logger_info, mock_env_var, mock_create_dir, mock_source_rc, mock_update_config, mock_verify_depl, mock_install_rally, mock_install_temp, mock_create_flavor, - mock_check_env, mock_print_info): + mock_check_env): with mock.patch("__builtin__.open", mock.mock_open()) as m: args = {'action': 'start'} self.assertEqual(prepare_env.main(**args), 0) mock_logger_info.assert_any_call("######### Preparing Functest " "environment #########\n") self.assertTrue(mock_env_var.called) - self.assertTrue(mock_dep_handler.called) self.assertTrue(mock_create_dir.called) self.assertTrue(mock_source_rc.called) self.assertTrue(mock_update_config.called) @@ -458,7 +455,6 @@ class PrepareEnvTesting(unittest.TestCase): m.assert_called_once_with( CONST.__getattribute__('env_active'), "w") self.assertTrue(mock_check_env.called) - self.assertTrue(mock_print_info.called) @mock.patch('functest.ci.prepare_env.check_environment') def test_main_check(self, mock_check_env): diff --git a/functest/tests/unit/openstack/snaps/test_snaps.py b/functest/tests/unit/openstack/snaps/test_snaps.py index 9cfcc0a6..7cf53b39 100644 --- a/functest/tests/unit/openstack/snaps/test_snaps.py +++ b/functest/tests/unit/openstack/snaps/test_snaps.py @@ -1,5 +1,3 @@ -#!/usr/bin/env python - # Copyright (c) 2017 Cable Television Laboratories, Inc. and others. # # All rights reserved. This program and the accompanying materials @@ -9,12 +7,14 @@ # http://www.apache.org/licenses/LICENSE-2.0 import mock +import os import unittest from snaps.openstack.os_credentials import OSCreds from functest.core.testcase import TestCase -from functest.opnfv_tests.openstack.snaps import connection_check +from functest.opnfv_tests.openstack.snaps import (connection_check, api_check, + health_check, smoke) class ConnectionCheckTesting(unittest.TestCase): @@ -31,10 +31,8 @@ class ConnectionCheckTesting(unittest.TestCase): self.connection_check = connection_check.ConnectionCheck( os_creds=self.os_creds, ext_net_name='foo') - @mock.patch('functest.opnfv_tests.openstack.snaps.connection_check.' - 'ConnectionCheck') @mock.patch('snaps.test_suite_builder.add_openstack_client_tests') - def test_run_success(self, mock_test, add_os_client_tests): + def test_run_success(self, add_os_client_tests): result = mock.MagicMock(name='unittest.TextTestResult') result.testsRun = 100 result.failures = [] @@ -44,10 +42,8 @@ class ConnectionCheckTesting(unittest.TestCase): self.assertEquals(TestCase.EX_OK, self.connection_check.is_successful()) - @mock.patch('functest.opnfv_tests.openstack.snaps.connection_check.' - 'ConnectionCheck') @mock.patch('snaps.test_suite_builder.add_openstack_client_tests') - def test_run_1_of_100_failures(self, mock_test, add_os_client_tests): + def test_run_1_of_100_failures(self, add_os_client_tests): result = mock.MagicMock(name='unittest.TextTestResult') result.testsRun = 100 result.failures = ['foo'] @@ -57,11 +53,8 @@ class ConnectionCheckTesting(unittest.TestCase): self.assertEquals(TestCase.EX_TESTCASE_FAILED, self.connection_check.is_successful()) - @mock.patch('functest.opnfv_tests.openstack.snaps.connection_check.' - 'ConnectionCheck') @mock.patch('snaps.test_suite_builder.add_openstack_client_tests') - def test_run_1_of_100_failures_within_criteria(self, mock_test, - add_os_client_tests): + def test_run_1_of_100_failures_within_criteria(self, add_os_client_tests): self.connection_check.criteria = 90 result = mock.MagicMock(name='unittest.TextTestResult') result.testsRun = 100 @@ -71,3 +64,153 @@ class ConnectionCheckTesting(unittest.TestCase): self.assertEquals(TestCase.EX_OK, self.connection_check.run()) self.assertEquals(TestCase.EX_OK, self.connection_check.is_successful()) + + +class APICheckTesting(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.api_check = api_check.ApiCheck( + os_creds=self.os_creds, ext_net_name='foo') + + @mock.patch('snaps.test_suite_builder.add_openstack_api_tests') + def test_run_success(self, add_tests): + result = mock.MagicMock(name='unittest.TextTestResult') + result.testsRun = 100 + result.failures = [] + result.errors = [] + with mock.patch('unittest.TextTestRunner.run', return_value=result): + self.assertEquals(TestCase.EX_OK, self.api_check.run()) + self.assertEquals(TestCase.EX_OK, + self.api_check.is_successful()) + + @mock.patch('snaps.test_suite_builder.add_openstack_api_tests') + def test_run_1_of_100_failures(self, add_tests): + result = mock.MagicMock(name='unittest.TextTestResult') + result.testsRun = 100 + result.failures = ['foo'] + result.errors = [] + with mock.patch('unittest.TextTestRunner.run', return_value=result): + self.assertEquals(TestCase.EX_OK, self.api_check.run()) + self.assertEquals(TestCase.EX_TESTCASE_FAILED, + self.api_check.is_successful()) + + @mock.patch('snaps.test_suite_builder.add_openstack_api_tests') + def test_run_1_of_100_failures_within_criteria(self, add_tests): + self.api_check.criteria = 90 + result = mock.MagicMock(name='unittest.TextTestResult') + result.testsRun = 100 + result.failures = ['foo'] + result.errors = [] + with mock.patch('unittest.TextTestRunner.run', return_value=result): + self.assertEquals(TestCase.EX_OK, self.api_check.run()) + self.assertEquals(TestCase.EX_OK, + self.api_check.is_successful()) + + +class HealthCheckTesting(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.health_check = health_check.HealthCheck( + os_creds=self.os_creds, ext_net_name='foo') + + @mock.patch('snaps.test_suite_builder.add_openstack_client_tests') + def test_run_success(self, add_tests): + result = mock.MagicMock(name='unittest.TextTestResult') + result.testsRun = 100 + result.failures = [] + result.errors = [] + with mock.patch('unittest.TextTestRunner.run', return_value=result): + self.assertEquals(TestCase.EX_OK, self.health_check.run()) + self.assertEquals(TestCase.EX_OK, + self.health_check.is_successful()) + + @mock.patch('snaps.test_suite_builder.add_openstack_client_tests') + def test_run_1_of_100_failures(self, add_tests): + result = mock.MagicMock(name='unittest.TextTestResult') + result.testsRun = 100 + result.failures = ['foo'] + result.errors = [] + with mock.patch('unittest.TextTestRunner.run', return_value=result): + self.assertEquals(TestCase.EX_OK, self.health_check.run()) + self.assertEquals(TestCase.EX_TESTCASE_FAILED, + self.health_check.is_successful()) + + @mock.patch('snaps.test_suite_builder.add_openstack_client_tests') + def test_run_1_of_100_failures_within_criteria(self, add_tests): + self.health_check.criteria = 90 + result = mock.MagicMock(name='unittest.TextTestResult') + result.testsRun = 100 + result.failures = ['foo'] + result.errors = [] + with mock.patch('unittest.TextTestRunner.run', return_value=result): + self.assertEquals(TestCase.EX_OK, self.health_check.run()) + self.assertEquals(TestCase.EX_OK, + self.health_check.is_successful()) + + +class SmokeTesting(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.smoke = smoke.SnapsSmoke( + os_creds=self.os_creds, ext_net_name='foo') + + @mock.patch('snaps.test_suite_builder.add_openstack_integration_tests') + @mock.patch('os.path.join', return_value=os.getcwd()) + def test_run_success(self, add_tests, cwd): + result = mock.MagicMock(name='unittest.TextTestResult') + result.testsRun = 100 + result.failures = [] + result.errors = [] + with mock.patch('unittest.TextTestRunner.run', return_value=result): + self.assertEquals(TestCase.EX_OK, self.smoke.run()) + self.assertEquals(TestCase.EX_OK, + self.smoke.is_successful()) + + @mock.patch('snaps.test_suite_builder.add_openstack_integration_tests') + @mock.patch('os.path.join', return_value=os.getcwd()) + def test_run_1_of_100_failures(self, add_tests, cwd): + result = mock.MagicMock(name='unittest.TextTestResult') + result.testsRun = 100 + result.failures = ['foo'] + result.errors = [] + with mock.patch('unittest.TextTestRunner.run', return_value=result): + self.assertEquals(TestCase.EX_OK, self.smoke.run()) + self.assertEquals(TestCase.EX_TESTCASE_FAILED, + self.smoke.is_successful()) + + @mock.patch('snaps.test_suite_builder.add_openstack_integration_tests') + @mock.patch('os.path.join', return_value=os.getcwd()) + def test_run_1_of_100_failures_within_criteria(self, add_tests, cwd): + self.smoke.criteria = 90 + result = mock.MagicMock(name='unittest.TextTestResult') + result.testsRun = 100 + result.failures = ['foo'] + result.errors = [] + with mock.patch('unittest.TextTestRunner.run', return_value=result): + self.assertEquals(TestCase.EX_OK, self.smoke.run()) + self.assertEquals(TestCase.EX_OK, + self.smoke.is_successful()) diff --git a/functest/tests/unit/utils/test_openstack_clean.py b/functest/tests/unit/utils/test_openstack_clean.py index fe7b50d4..6ae7faa4 100644 --- a/functest/tests/unit/utils/test_openstack_clean.py +++ b/functest/tests/unit/utils/test_openstack_clean.py @@ -61,6 +61,8 @@ class OSCleanTesting(unittest.TestCase): {'id': 'id2', 'name': 'name2', 'ip': 'ip2', 'router:external': False, 'external_gateway_info': None}] + self.floatingips_list = [{'id': 'id1', 'floating_ip_address': 'ip1'}, + {'id': 'id2', 'floating_ip_address': 'ip2'}] self.routers = [mock.Mock()] self.ports = [mock.Mock()] @@ -254,7 +256,8 @@ class OSCleanTesting(unittest.TestCase): @mock.patch('functest.utils.openstack_clean.logger.debug') def test_remove_floatingips(self, mock_logger_debug): with mock.patch('functest.utils.openstack_clean.os_utils' - '.get_floating_ips', return_value=self.test_list): + '.get_floating_ips', + return_value=self.floatingips_list): openstack_clean.remove_floatingips(self.client, self.update_list) mock_logger_debug.assert_any_call("Removing floating IPs...") mock_logger_debug.assert_any_call(" > this is a default " @@ -272,9 +275,10 @@ class OSCleanTesting(unittest.TestCase): @mock.patch('functest.utils.openstack_clean.logger.debug') def test_remove_floatingips_delete_success(self, mock_logger_debug): with mock.patch('functest.utils.openstack_clean.os_utils' - '.get_floating_ips', return_value=self.test_list), \ + '.get_floating_ips', + return_value=self.floatingips_list), \ mock.patch('functest.utils.openstack_clean.os_utils' - '.delete_volume', return_value=True): + '.delete_floating_ip', return_value=True): openstack_clean.remove_floatingips(self.client, self.remove_list) mock_logger_debug.assert_any_call("Removing floating IPs...") mock_logger_debug.assert_any_call(" > Done!") @@ -287,7 +291,8 @@ class OSCleanTesting(unittest.TestCase): def test_remove_floatingips_delete_failed(self, mock_logger_debug, mock_logger_error): with mock.patch('functest.utils.openstack_clean.os_utils' - '.get_floating_ips', return_value=self.test_list), \ + '.get_floating_ips', + return_value=self.floatingips_list), \ mock.patch('functest.utils.openstack_clean.os_utils' '.delete_floating_ip', return_value=False): openstack_clean.remove_floatingips(self.client, self.remove_list) @@ -672,6 +677,7 @@ class OSCleanTesting(unittest.TestCase): RegexMatch(" Removing " "\s*\S+...")) + @mock.patch('functest.utils.openstack_clean.os_utils.get_glance_client') @mock.patch('functest.utils.openstack_clean.os_utils.get_cinder_client') @mock.patch('functest.utils.openstack_clean.os_utils' '.get_keystone_client') @@ -684,7 +690,7 @@ class OSCleanTesting(unittest.TestCase): @mock.patch('functest.utils.openstack_clean.logger.debug') def test_main_default(self, mock_logger_debug, mock_logger_info, mock_creds, mock_nova, mock_neutron, - mock_keystone, mock_cinder): + mock_keystone, mock_cinder, mock_glance): with mock.patch('functest.utils.openstack_clean.remove_instances') \ as mock_remove_instances, \ diff --git a/functest/tests/unit/utils/test_openstack_snapshot.py b/functest/tests/unit/utils/test_openstack_snapshot.py index d3f93994..33e74609 100644 --- a/functest/tests/unit/utils/test_openstack_snapshot.py +++ b/functest/tests/unit/utils/test_openstack_snapshot.py @@ -12,7 +12,7 @@ import unittest from functest.utils import openstack_snapshot -class OSTackerTesting(unittest.TestCase): +class OSSnapshotTesting(unittest.TestCase): def _get_instance(self, key): mock_obj = mock.Mock() @@ -26,6 +26,8 @@ class OSTackerTesting(unittest.TestCase): self.test_list = [self._get_instance(1), self._get_instance(2)] self.update_list = {'id1': 'name1', 'id2': 'name2'} self.update_floatingips = {'id1': 'ip1', 'id2': 'ip2'} + self.floatingips_list = [{'id': 'id1', 'floating_ip_address': 'ip1'}, + {'id': 'id2', 'floating_ip_address': 'ip2'}] self.test_dict_list = [{'id': 'id1', 'name': 'name1', 'ip': 'ip1'}, {'id': 'id2', 'name': 'name2', 'ip': 'ip2'}] @@ -138,8 +140,9 @@ class OSTackerTesting(unittest.TestCase): @mock.patch('functest.utils.openstack_snapshot.logger.debug') def test_get_floatingips(self, mock_logger_debug): with mock.patch('functest.utils.openstack_snapshot.os_utils' - '.get_floating_ips', return_value=self.test_list): - resp = openstack_snapshot.get_floatinips(self.client) + '.get_floating_ips', + return_value=self.floatingips_list): + resp = openstack_snapshot.get_floatingips(self.client) mock_logger_debug.assert_called_once_with("Getting Floating " "IPs...") self.assertDictEqual(resp, {'floatingips': @@ -149,7 +152,7 @@ class OSTackerTesting(unittest.TestCase): def test_get_floatingips_missing_floatingips(self, mock_logger_debug): with mock.patch('functest.utils.openstack_snapshot.os_utils' '.get_floating_ips', return_value=[]): - resp = openstack_snapshot.get_floatinips(self.client) + resp = openstack_snapshot.get_floatingips(self.client) mock_logger_debug.assert_called_once_with("Getting Floating " "IPs...") self.assertDictEqual(resp, {'floatingips': {}}) @@ -186,6 +189,7 @@ class OSTackerTesting(unittest.TestCase): mock_logger_debug.assert_called_once_with("Getting tenants...") self.assertDictEqual(resp, {'tenants': {}}) + @mock.patch('functest.utils.openstack_clean.os_utils.get_glance_client') @mock.patch('functest.utils.openstack_snapshot.os_utils.get_cinder_client') @mock.patch('functest.utils.openstack_snapshot.os_utils' '.get_keystone_client') @@ -197,7 +201,7 @@ class OSTackerTesting(unittest.TestCase): @mock.patch('functest.utils.openstack_snapshot.logger.debug') def test_main_default(self, mock_logger_debug, mock_logger_info, mock_creds, mock_nova, mock_neutron, - mock_keystone, mock_cinder): + mock_keystone, mock_cinder, mock_glance): with mock.patch('functest.utils.openstack_snapshot.get_instances', return_value=self.update_list), \ mock.patch('functest.utils.openstack_snapshot.get_images', @@ -212,7 +216,7 @@ class OSTackerTesting(unittest.TestCase): return_value=self.update_list), \ mock.patch('functest.utils.openstack_snapshot.get_security_groups', return_value=self.update_list), \ - mock.patch('functest.utils.openstack_snapshot.get_floatinips', + mock.patch('functest.utils.openstack_snapshot.get_floatingips', return_value=self.update_floatingips), \ mock.patch('functest.utils.openstack_snapshot.get_users', return_value=self.update_list), \ diff --git a/functest/tests/unit/utils/test_openstack_utils.py b/functest/tests/unit/utils/test_openstack_utils.py index 0f06b1e1..74b49aaa 100644 --- a/functest/tests/unit/utils/test_openstack_utils.py +++ b/functest/tests/unit/utils/test_openstack_utils.py @@ -27,7 +27,8 @@ class OSUtilsTesting(unittest.TestCase): 'OS_PROJECT_NAME': os_prefix + 'project_name', 'OS_ENDPOINT_TYPE': os_prefix + 'endpoint_type', 'OS_REGION_NAME': os_prefix + 'region_name', - 'OS_CACERT': os_prefix + 'https_cacert'} + 'OS_CACERT': os_prefix + 'https_cacert', + 'OS_INSECURE': os_prefix + 'https_insecure'} def _get_os_env_vars(self): return {'username': 'test_username', 'password': 'test_password', @@ -37,7 +38,8 @@ class OSUtilsTesting(unittest.TestCase): 'project_name': 'test_project_name', 'endpoint_type': 'test_endpoint_type', 'region_name': 'test_region_name', - 'https_cacert': 'test_https_cacert'} + 'https_cacert': 'test_https_cacert', + 'https_insecure': 'test_https_insecure'} def setUp(self): self.env_vars = ['OS_AUTH_URL', 'OS_USERNAME', 'OS_PASSWORD'] @@ -75,9 +77,8 @@ class OSUtilsTesting(unittest.TestCase): self.availability_zone = mock_obj mock_obj = mock.Mock() - attrs = {'id': 'floating_id', - 'zoneName': 'test_floating_ip', - 'status': 'ok'} + attrs = {'floating_network_id': 'floating_id', + 'floating_ip_address': 'test_floating_ip'} mock_obj.configure_mock(**attrs) self.floating_ip = mock_obj @@ -113,8 +114,6 @@ class OSUtilsTesting(unittest.TestCase): 'aggregates.delete.return_value': mock.Mock(), 'availability_zones.list.return_value': [self.availability_zone], - 'floating_ips.list.return_value': [self.floating_ip], - 'floating_ips.delete.return_value': mock.Mock(), 'hypervisors.list.return_value': [self.hypervisor], 'create.return_value': mock.Mock(), 'add_security_group.return_value': mock.Mock(), @@ -271,7 +270,10 @@ class OSUtilsTesting(unittest.TestCase): 'create_security_group.return_value': {'security_group': self.sec_group}, 'update_quota.return_value': mock.Mock(), - 'delete_security_group.return_value': mock.Mock() + 'delete_security_group.return_value': mock.Mock(), + 'list_floatingips.return_value': {'floatingips': + [self.floating_ip]}, + 'delete_floatingip.return_value': mock.Mock(), } self.neutron_client.configure_mock(**attrs) @@ -721,7 +723,7 @@ class OSUtilsTesting(unittest.TestCase): def test_get_floating_ips_default(self): self.assertEqual(openstack_utils. - get_floating_ips(self.nova_client), + get_floating_ips(self.neutron_client), [self.floating_ip]) @mock.patch('functest.utils.openstack_utils.logger.error') @@ -867,7 +869,7 @@ class OSUtilsTesting(unittest.TestCase): def test_delete_floating_ip_default(self): self.assertTrue(openstack_utils. - delete_floating_ip(self.nova_client, + delete_floating_ip(self.neutron_client, 'floating_ip_id')) @mock.patch('functest.utils.openstack_utils.logger.error') @@ -1472,7 +1474,7 @@ class OSUtilsTesting(unittest.TestCase): def test_get_images_default(self): self.assertEqual(openstack_utils. - get_images(self.nova_client), + get_images(self.glance_client), [self.image]) @mock.patch('functest.utils.openstack_utils.logger.error') |