class RallyBase(testcase.TestCase):
"""Base class form Rally testcases implementation."""
+ # pylint: disable=too-many-instance-attributes
TESTS = ['authenticate', 'glance', 'ceilometer', 'cinder', 'heat',
'keystone', 'neutron', 'nova', 'quotas', 'vm', 'all']
GLANCE_IMAGE_NAME = CONST.__getattribute__('openstack_image_name')
self.compute_cnt = 0
def _build_task_args(self, test_file_name):
+ """Build arguments for the Rally task."""
task_args = {'service_list': [test_file_name]}
task_args['image_name'] = self.image_name
task_args['flavor_name'] = self.flavor_name
return task_args
def _prepare_test_list(self, test_name):
+ """Build the list of test cases to be executed."""
test_yaml_file_name = 'opnfv-{}.yaml'.format(test_name)
scenario_file_name = os.path.join(self.RALLY_SCENARIO_DIR,
test_yaml_file_name)
in_it(installer_type, installers)):
tests = item['tests']
black_tests.extend(tests)
- except Exception:
+ except Exception: # pylint: disable=broad-except
LOGGER.debug("Scenario exclusion not applied.")
return black_tests
# match if regex pattern is set and found in the needle
if pattern and re.search(pattern, needle) is not None:
return True
- else:
- return False
+
+ return False
def excl_func(self):
"""Exclude functionalities."""
LOGGER.info('Test scenario: "{}" Failed.'.format(test_name) + "\n")
def _append_summary(self, json_raw, test_name):
+ """Update statistics summary info."""
nb_tests = 0
nb_success = 0
overall_duration = 0.0
self.summary.append(scenario_summary)
def _prepare_env(self):
+ """Create resources needed by test scenarios."""
LOGGER.debug('Validating the test name...')
if self.test_name not in self.TESTS:
raise Exception("Test name '%s' is invalid" % self.test_name)
segmentation_id=rally_segmentation_id,
subnet_settings=[SubnetConfig(
name=subnet_name,
- cidr=self.RALLY_PRIVATE_SUBNET_CIDR)
- ]))
+ cidr=self.RALLY_PRIVATE_SUBNET_CIDR)]))
if network_creator is None:
raise Exception("Failed to create private network")
self.priv_net_id = network_creator.get_network().id
self.creators.append(flavor_alt_creator)
def _run_tests(self):
+ """Execute tests."""
if self.test_name == 'all':
for test in self.TESTS:
if test == 'all' or test == 'vm':
self._run_task(self.test_name)
def _generate_report(self):
+ """Generate test execution summary report."""
total_duration = 0.0
total_nb_tests = 0
total_nb_success = 0
self.details = payload
def _clean_up(self):
+ """Cleanup all OpenStack objects. Should be called on completion."""
for creator in reversed(self.creators):
try:
creator.clean()
- except Exception as e:
- LOGGER.error('Unexpected error cleaning - %s', e)
+ except Exception as exc: # pylint: disable=broad-except
+ LOGGER.error('Unexpected error cleaning - %s', exc)
@energy.enable_recording
def run(self, **kwargs):
# which accompanies this distribution, and is available at
# http://www.apache.org/licenses/LICENSE-2.0
-# pylint: disable=missing-docstring
+# pylint: disable=missing-docstring,protected-access,invalid-name
import json
import logging
class OSRallyTesting(unittest.TestCase):
+ # pylint: disable=too-many-public-methods
def setUp(self):
os_creds = OSCreds(
username='user', password='pass',
auth_url='http://foo.com:5000/v3', project_name='bar')
with mock.patch('functest.opnfv_tests.openstack.snaps.snaps_utils.'
- 'get_credentials', return_value=os_creds) as m:
+ 'get_credentials',
+ return_value=os_creds) as mock_get_creds:
self.rally_base = rally.RallyBase()
- self.assertTrue(m.called)
+ self.assertTrue(mock_get_creds.called)
def test_build_task_args_missing_floating_network(self):
CONST.__setattr__('OS_AUTH_URL', None)
@mock.patch('functest.opnfv_tests.openstack.rally.rally.subprocess.Popen')
@mock.patch('functest.opnfv_tests.openstack.rally.rally.LOGGER.error')
def test_run_task_taskid_missing(self, mock_logger_error, *args):
+ # pylint: disable=unused-argument
self.rally_base._run_task('test_name')
text = 'Failed to retrieve task_id, validating task...'
mock_logger_error.assert_any_call(text)
@mock.patch('functest.opnfv_tests.openstack.rally.rally.LOGGER.error')
def test_run_task_default(self, mock_logger_error, mock_logger_info,
*args):
+ # pylint: disable=unused-argument
self.rally_base._run_task('test_name')
text = 'Test scenario: "test_name" OK.\n'
mock_logger_info.assert_any_call(text)
@mock.patch('snaps.openstack.utils.deploy_utils.create_network')
@mock.patch('snaps.openstack.utils.deploy_utils.create_router',
return_value=None)
- def test_prepare_env_router_creation_failed(
- self, mock_create_router, mock_create_net, mock_get_img,
- mock_get_net, mock_get_comp_cnt):
+ def test_prepare_env_router_creation_failed(self, *args):
self.rally_base.TESTS = ['test1', 'test2']
self.rally_base.test_name = 'test1'
with self.assertRaises(Exception):
self.rally_base._prepare_env()
- mock_create_net.assert_called()
- mock_get_img.assert_called()
- mock_get_net.assert_called()
- mock_create_router.assert_called()
- mock_get_comp_cnt.assert_called()
+ for func in args:
+ func.assert_called()
@mock.patch('functest.opnfv_tests.openstack.snaps.snaps_utils.'
'get_active_compute_cnt')
@mock.patch('snaps.openstack.utils.deploy_utils.create_router')
@mock.patch('snaps.openstack.create_flavor.OpenStackFlavor.create',
return_value=None)
- def test_prepare_env_flavor_creation_failed(
- self, mock_create_flavor, mock_create_router, mock_create_net,
- mock_get_img, mock_get_net, mock_get_comp_cnt):
+ def test_prepare_env_flavor_creation_failed(self, mock_create_flavor,
+ *args):
self.rally_base.TESTS = ['test1', 'test2']
self.rally_base.test_name = 'test1'
with self.assertRaises(Exception):
self.rally_base._prepare_env()
- mock_create_net.assert_called()
- mock_get_img.assert_called()
- mock_get_net.assert_called()
- mock_create_router.assert_called()
- mock_get_comp_cnt.assert_called()
+ for func in args:
+ func.assert_called()
mock_create_flavor.assert_called_once()
@mock.patch('functest.opnfv_tests.openstack.snaps.snaps_utils.'
@mock.patch('snaps.openstack.utils.deploy_utils.create_router')
@mock.patch('snaps.openstack.create_flavor.OpenStackFlavor.create',
side_effect=[mock.Mock, None])
- def test_prepare_env_flavor_alt_creation_failed(
- self, mock_create_flavor, mock_create_router, mock_create_net,
- mock_get_img, mock_get_net, mock_get_comp_cnt):
+ def test_prepare_env_flavor_alt_creation_failed(self, mock_create_flavor,
+ *args):
self.rally_base.TESTS = ['test1', 'test2']
self.rally_base.test_name = 'test1'
with self.assertRaises(Exception):
self.rally_base._prepare_env()
- mock_create_net.assert_called()
- mock_get_img.assert_called()
- mock_get_net.assert_called()
- mock_create_router.assert_called()
- mock_get_comp_cnt.assert_called()
+ for func in args:
+ func.assert_called()
self.assertEqual(mock_create_flavor.call_count, 2)
@mock.patch('functest.opnfv_tests.openstack.rally.rally.RallyBase.'
'_clean_up')
def test_run_default(self, *args):
self.assertEqual(self.rally_base.run(), testcase.TestCase.EX_OK)
- map(lambda m: m.assert_called(), args)
+ for func in args:
+ func.assert_called()
@mock.patch('functest.opnfv_tests.openstack.tempest.conf_utils.'
'create_rally_deployment', side_effect=Exception)
self.assertEqual(self.rally_base.run(), testcase.TestCase.EX_RUN_ERROR)
mock_create_rally_dep.assert_called()
- @mock.patch('functest.opnfv_tests.openstack.rally.rally.RallyBase.'
- '_prepare_env', side_effect=Exception)
@mock.patch('functest.opnfv_tests.openstack.tempest.conf_utils.'
'create_rally_deployment', return_value=mock.Mock())
- def test_run_exception_prepare_env(self, mock_create_rally_dep,
- mock_prep_env):
+ @mock.patch('functest.opnfv_tests.openstack.rally.rally.RallyBase.'
+ '_prepare_env', side_effect=Exception)
+ def test_run_exception_prepare_env(self, mock_prep_env, *args):
+ # pylint: disable=unused-argument
self.assertEqual(self.rally_base.run(), testcase.TestCase.EX_RUN_ERROR)
mock_prep_env.assert_called()