aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJuha Kosonen <juha.kosonen@nokia.com>2018-02-13 14:08:58 +0200
committerJuha Kosonen <juha.kosonen@nokia.com>2018-02-13 14:08:58 +0200
commit2f67e870b37683f01ac738a39f3f6859506dd0a7 (patch)
tree78afea9bdc43ca89eff6b8b99ccd1f6844392d00
parentb1522c34d95f9bb48fc9cfca91f281da2f958953 (diff)
Enhance variable manipulation in rally
- utilize env vars directly via os module - use getattr to read CONST JIRA: FUNCTEST-931 Change-Id: I893a91331e26846f8effe2d3d58522950bd096fd Signed-off-by: Juha Kosonen <juha.kosonen@nokia.com>
-rw-r--r--functest/opnfv_tests/openstack/rally/rally.py58
-rw-r--r--functest/tests/unit/openstack/rally/test_rally.py17
2 files changed, 30 insertions, 45 deletions
diff --git a/functest/opnfv_tests/openstack/rally/rally.py b/functest/opnfv_tests/openstack/rally/rally.py
index 2fd7d7f67..2632fd398 100644
--- a/functest/opnfv_tests/openstack/rally/rally.py
+++ b/functest/opnfv_tests/openstack/rally/rally.py
@@ -47,24 +47,20 @@ class RallyBase(testcase.TestCase):
# 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')
- GLANCE_IMAGE_FILENAME = CONST.__getattribute__('openstack_image_file_name')
- GLANCE_IMAGE_PATH = os.path.join(
- CONST.__getattribute__('dir_functest_images'),
- GLANCE_IMAGE_FILENAME)
- GLANCE_IMAGE_FORMAT = CONST.__getattribute__('openstack_image_disk_format')
- GLANCE_IMAGE_USERNAME = CONST.__getattribute__('openstack_image_username')
- GLANCE_IMAGE_EXTRA_PROPERTIES = {}
- if hasattr(CONST, 'openstack_extra_properties'):
- GLANCE_IMAGE_EXTRA_PROPERTIES = CONST.__getattribute__(
- 'openstack_extra_properties')
- FLAVOR_NAME = CONST.__getattribute__('rally_flavor_name')
- FLAVOR_ALT_NAME = CONST.__getattribute__('rally_flavor_alt_name')
- FLAVOR_EXTRA_SPECS = None
+ GLANCE_IMAGE_NAME = getattr(CONST, 'openstack_image_name')
+ GLANCE_IMAGE_FILENAME = getattr(CONST, 'openstack_image_file_name')
+ GLANCE_IMAGE_PATH = os.path.join(getattr(CONST, 'dir_functest_images'),
+ GLANCE_IMAGE_FILENAME)
+ GLANCE_IMAGE_FORMAT = getattr(CONST, 'openstack_image_disk_format')
+ GLANCE_IMAGE_USERNAME = getattr(CONST, 'openstack_image_username')
+ GLANCE_IMAGE_EXTRA_PROPERTIES = getattr(CONST,
+ 'openstack_extra_properties', {})
+ FLAVOR_NAME = getattr(CONST, 'rally_flavor_name')
+ FLAVOR_ALT_NAME = getattr(CONST, 'rally_flavor_alt_name')
FLAVOR_RAM = 512
FLAVOR_RAM_ALT = 1024
- if hasattr(CONST, 'flavor_extra_specs'):
- FLAVOR_EXTRA_SPECS = CONST.__getattribute__('flavor_extra_specs')
+ FLAVOR_EXTRA_SPECS = getattr(CONST, 'flavor_extra_specs', None)
+ if FLAVOR_EXTRA_SPECS:
FLAVOR_RAM = 1024
FLAVOR_RAM_ALT = 2048
@@ -80,14 +76,14 @@ class RallyBase(testcase.TestCase):
TENANTS_AMOUNT = 3
ITERATIONS_AMOUNT = 10
CONCURRENCY = 4
- RESULTS_DIR = os.path.join(CONST.__getattribute__('dir_results'), 'rally')
+ RESULTS_DIR = os.path.join(getattr(CONST, 'dir_results'), 'rally')
BLACKLIST_FILE = os.path.join(RALLY_DIR, "blacklist.txt")
TEMP_DIR = os.path.join(RALLY_DIR, "var")
- RALLY_PRIVATE_NET_NAME = CONST.__getattribute__('rally_network_name')
- RALLY_PRIVATE_SUBNET_NAME = CONST.__getattribute__('rally_subnet_name')
- RALLY_PRIVATE_SUBNET_CIDR = CONST.__getattribute__('rally_subnet_cidr')
- RALLY_ROUTER_NAME = CONST.__getattribute__('rally_router_name')
+ RALLY_PRIVATE_NET_NAME = getattr(CONST, 'rally_network_name')
+ RALLY_PRIVATE_SUBNET_NAME = getattr(CONST, 'rally_subnet_name')
+ RALLY_PRIVATE_SUBNET_CIDR = getattr(CONST, 'rally_subnet_cidr')
+ RALLY_ROUTER_NAME = getattr(CONST, 'rally_router_name')
def __init__(self, **kwargs):
"""Initialize RallyBase object."""
@@ -222,8 +218,8 @@ class RallyBase(testcase.TestCase):
with open(RallyBase.BLACKLIST_FILE, 'r') as black_list_file:
black_list_yaml = yaml.safe_load(black_list_file)
- installer_type = CONST.__getattribute__('INSTALLER_TYPE')
- deploy_scenario = CONST.__getattribute__('DEPLOY_SCENARIO')
+ installer_type = os.getenv('INSTALLER_TYPE', None)
+ deploy_scenario = os.getenv('DEPLOY_SCENARIO', None)
if (bool(installer_type) and bool(deploy_scenario) and
'scenario' in black_list_yaml.keys()):
for item in black_list_yaml['scenario']:
@@ -454,19 +450,9 @@ class RallyBase(testcase.TestCase):
LOGGER.debug("Creating network '%s'...", network_name)
- rally_network_type = None
- rally_physical_network = None
- rally_segmentation_id = None
-
- if hasattr(CONST, 'rally_network_type'):
- rally_network_type = CONST.__getattribute__(
- 'rally_network_type')
- if hasattr(CONST, 'rally_physical_network'):
- rally_physical_network = CONST.__getattribute__(
- 'rally_physical_network')
- if hasattr(CONST, 'rally_segmentation_id'):
- rally_segmentation_id = CONST.__getattribute__(
- 'rally_segmentation_id')
+ rally_network_type = getattr(CONST, 'rally_network_type', None)
+ rally_physical_network = getattr(CONST, 'rally_physical_network', None)
+ rally_segmentation_id = getattr(CONST, 'rally_segmentation_id', None)
network_creator = deploy_utils.create_network(
self.os_creds, NetworkConfig(
diff --git a/functest/tests/unit/openstack/rally/test_rally.py b/functest/tests/unit/openstack/rally/test_rally.py
index 08ca7e395..9cc6bf53d 100644
--- a/functest/tests/unit/openstack/rally/test_rally.py
+++ b/functest/tests/unit/openstack/rally/test_rally.py
@@ -16,7 +16,6 @@ import mock
from functest.core import testcase
from functest.opnfv_tests.openstack.rally import rally
-from functest.utils.constants import CONST
from snaps.openstack.os_credentials import OSCreds
@@ -34,13 +33,13 @@ class OSRallyTesting(unittest.TestCase):
self.assertTrue(mock_get_creds.called)
def test_build_task_args_missing_floating_network(self):
- CONST.__setattr__('OS_AUTH_URL', None)
+ os.environ['OS_AUTH_URL'] = ''
self.rally_base.ext_net_name = ''
task_args = self.rally_base._build_task_args('test_file_name')
self.assertEqual(task_args['floating_network'], '')
def test_build_task_args_missing_net_id(self):
- CONST.__setattr__('OS_AUTH_URL', None)
+ os.environ['OS_AUTH_URL'] = ''
self.rally_base.priv_net_id = ''
task_args = self.rally_base._build_task_args('test_file_name')
self.assertEqual(task_args['netid'], '')
@@ -121,8 +120,8 @@ class OSRallyTesting(unittest.TestCase):
'installers': ['test_installer'],
'tests': ['other_test']}]})
def test_excl_scenario_default(self, mock_func):
- CONST.__setattr__('INSTALLER_TYPE', 'test_installer')
- CONST.__setattr__('DEPLOY_SCENARIO', 'test_scenario')
+ os.environ['INSTALLER_TYPE'] = 'test_installer'
+ os.environ['DEPLOY_SCENARIO'] = 'test_scenario'
self.assertEqual(self.rally_base.excl_scenario(), ['test'])
mock_func.assert_called()
@@ -148,8 +147,8 @@ class OSRallyTesting(unittest.TestCase):
'installers': ['test_installer'],
'tests': ['test0b']}]})
def test_excl_scenario_regex(self, mock_func):
- CONST.__setattr__('INSTALLER_TYPE', 'test_installer')
- CONST.__setattr__('DEPLOY_SCENARIO', 'os-ctrlT-featT-modeT')
+ os.environ['INSTALLER_TYPE'] = 'test_installer'
+ os.environ['DEPLOY_SCENARIO'] = 'os-ctrlT-featT-modeT'
self.assertEqual(self.rally_base.excl_scenario(),
['test1', 'test2', 'test3', 'test4'])
mock_func.assert_called()
@@ -166,8 +165,8 @@ class OSRallyTesting(unittest.TestCase):
@mock.patch('functest.opnfv_tests.openstack.rally.rally.RallyBase.'
'_migration_supported', return_value=False)
def test_excl_func_default(self, mock_func, mock_yaml_load):
- CONST.__setattr__('INSTALLER_TYPE', 'test_installer')
- CONST.__setattr__('DEPLOY_SCENARIO', 'test_scenario')
+ os.environ['INSTALLER_TYPE'] = 'test_installer'
+ os.environ['DEPLOY_SCENARIO'] = 'test_scenario'
self.assertEqual(self.rally_base.excl_func(), ['test'])
mock_func.assert_called()
mock_yaml_load.assert_called()