diff options
Diffstat (limited to 'functest')
-rw-r--r-- | functest/ci/config_functest.yaml | 8 | ||||
-rw-r--r-- | functest/ci/prepare_env.py | 2 | ||||
-rw-r--r-- | functest/opnfv_tests/openstack/tempest/conf_utils.py | 51 | ||||
-rw-r--r-- | functest/opnfv_tests/openstack/tempest/tempest.py | 7 | ||||
-rw-r--r-- | functest/opnfv_tests/openstack/vping/vping_base.py | 27 | ||||
-rw-r--r-- | functest/opnfv_tests/vnf/ims/cloudify_ims.py | 8 | ||||
-rw-r--r-- | functest/opnfv_tests/vnf/ims/orchestra_clearwaterims.py | 12 | ||||
-rw-r--r-- | functest/opnfv_tests/vnf/ims/orchestra_openims.py | 11 | ||||
-rw-r--r-- | functest/tests/unit/openstack/tempest/test_conf_utils.py | 82 |
9 files changed, 171 insertions, 37 deletions
diff --git a/functest/ci/config_functest.yaml b/functest/ci/config_functest.yaml index b3fc397f..37e518e6 100644 --- a/functest/ci/config_functest.yaml +++ b/functest/ci/config_functest.yaml @@ -69,6 +69,9 @@ vping: vm_name_2: opnfv-vping-2 image_name: functest-vping private_net_name: vping-net + # network_type: vlan + # physical_network: physnet2 + # segmentation_id: 2366 private_subnet_name: vping-subnet private_subnet_cidr: 192.168.130.0/24 router_name: vping-router @@ -96,6 +99,11 @@ odl_sfc: tempest: deployment_name: opnfv-tempest + identity: + tenant_name: tempest + tenant_description: Tenant for Tempest test suite + user_name: tempest + user_password: Tempest123! validation: ssh_timeout: 130 object_storage: diff --git a/functest/ci/prepare_env.py b/functest/ci/prepare_env.py index c40e3266..9ed585f3 100644 --- a/functest/ci/prepare_env.py +++ b/functest/ci/prepare_env.py @@ -33,7 +33,7 @@ actions = ['start', 'check'] logger = logging.getLogger('functest.ci.prepare_env') handler = None # set the architecture to default -pod_arch = None +pod_arch = os.getenv("HOST_ARCH", None) arch_filter = ['aarch64'] CONFIG_FUNCTEST_PATH = pkg_resources.resource_filename( diff --git a/functest/opnfv_tests/openstack/tempest/conf_utils.py b/functest/opnfv_tests/openstack/tempest/conf_utils.py index fd3785b9..8574b0de 100644 --- a/functest/opnfv_tests/openstack/tempest/conf_utils.py +++ b/functest/opnfv_tests/openstack/tempest/conf_utils.py @@ -41,6 +41,9 @@ REFSTACK_RESULTS_DIR = os.path.join(CONST.__getattribute__('dir_results'), 'refstack') TEMPEST_CONF_YAML = pkg_resources.resource_filename( 'functest', 'opnfv_tests/openstack/tempest/custom_tests/tempest_conf.yaml') +TEST_ACCOUNTS_FILE = pkg_resources.resource_filename( + 'functest', + 'opnfv_tests/openstack/tempest/custom_tests/test_accounts.yaml') CI_INSTALLER_TYPE = CONST.__getattribute__('INSTALLER_TYPE') CI_INSTALLER_IP = CONST.__getattribute__('INSTALLER_IP') @@ -117,6 +120,30 @@ def create_tempest_resources(use_custom_images=False, return img_flavor_dict +def create_tenant_user(): + keystone_client = os_utils.get_keystone_client() + + logger.debug("Creating tenant and user for Tempest suite") + tenant_id = os_utils.create_tenant( + keystone_client, + CONST.__getattribute__('tempest_identity_tenant_name'), + CONST.__getattribute__('tempest_identity_tenant_description')) + if not tenant_id: + logger.error("Failed to create %s tenant" + % CONST.__getattribute__('tempest_identity_tenant_name')) + + user_id = os_utils.create_user( + keystone_client, + CONST.__getattribute__('tempest_identity_user_name'), + CONST.__getattribute__('tempest_identity_user_password'), + None, tenant_id) + if not user_id: + logger.error("Failed to create %s user" % + CONST.__getattribute__('tempest_identity_user_name')) + + return tenant_id + + def get_verifier_id(): """ Returns verifer id for current Tempest @@ -228,6 +255,8 @@ def configure_tempest_defcore(deployment_dir, img_flavor_dict): config.set('DEFAULT', 'log_file', '{}/tempest.log'.format(deployment_dir)) config.set('oslo_concurrency', 'lock_path', '{}/lock_files'.format(deployment_dir)) + generate_test_accounts_file() + config.set('auth', 'test_accounts_file', TEST_ACCOUNTS_FILE) config.set('scenario', 'img_dir', '{}'.format(deployment_dir)) config.set('scenario', 'img_file', 'tempest-image') config.set('compute', 'image_ref', img_flavor_dict.get("image_id")) @@ -246,6 +275,28 @@ def configure_tempest_defcore(deployment_dir, img_flavor_dict): shutil.copyfile(conf_file, confpath) +def generate_test_accounts_file(): + """ + Add needed tenant and user params into test_accounts.yaml + """ + + logger.debug("Add needed params into test_accounts.yaml...") + tenant_id = create_tenant_user() + accounts_list = [ + { + 'tenant_name': + CONST.__getattribute__('tempest_identity_tenant_name'), + 'tenant_id': str(tenant_id), + 'username': CONST.__getattribute__('tempest_identity_user_name'), + 'password': + CONST.__getattribute__('tempest_identity_user_password') + } + ] + + with open(TEST_ACCOUNTS_FILE, "w") as f: + yaml.dump(accounts_list, f, default_flow_style=False) + + def configure_tempest_update_params(tempest_conf_file, IMAGE_ID=None, FLAVOR_ID=None): """ diff --git a/functest/opnfv_tests/openstack/tempest/tempest.py b/functest/opnfv_tests/openstack/tempest/tempest.py index 003d4ea4..f783f01f 100644 --- a/functest/opnfv_tests/openstack/tempest/tempest.py +++ b/functest/opnfv_tests/openstack/tempest/tempest.py @@ -184,9 +184,12 @@ class TempestCommon(testcase.OSGCTestCase): try: self.result = 100 * int(num_success) / int(num_executed) except ZeroDivisionError: - logger.error("No test has been executed") self.result = 0 - return + if int(num_tests) > 0: + logger.info("All tests have been skipped") + else: + logger.error("No test has been executed") + return with open(os.path.join(conf_utils.TEMPEST_RESULTS_DIR, "tempest.log"), 'r') as logfile: diff --git a/functest/opnfv_tests/openstack/vping/vping_base.py b/functest/opnfv_tests/openstack/vping/vping_base.py index 74fbce1b..f3e0cfe3 100644 --- a/functest/opnfv_tests/openstack/vping/vping_base.py +++ b/functest/opnfv_tests/openstack/vping/vping_base.py @@ -102,14 +102,33 @@ class VPingBase(testcase.TestCase): 'vping_private_subnet_name') + self.guid private_subnet_cidr = CONST.__getattribute__( 'vping_private_subnet_cidr') + + vping_network_type = None + vping_physical_network = None + vping_segmentation_id = None + + if (hasattr(CONST, 'network_type')): + vping_network_type = CONST.__getattribute__( + 'vping_network_type') + if (hasattr(CONST, 'physical_network')): + vping_physical_network = CONST.__getattribute__( + 'vping_physical_network') + if (hasattr(CONST, 'segmentation_id')): + vping_segmentation_id = CONST.__getattribute__( + 'vping_segmentation_id') + self.logger.info( "Creating network with name: '%s'" % private_net_name) self.network_creator = deploy_utils.create_network( self.os_creds, - NetworkSettings(name=private_net_name, - subnet_settings=[SubnetSettings( - name=private_subnet_name, - cidr=private_subnet_cidr)])) + NetworkSettings( + name=private_net_name, + network_type=vping_network_type, + physical_network=vping_physical_network, + segmentation_id=vping_segmentation_id, + subnet_settings=[SubnetSettings( + name=private_subnet_name, + cidr=private_subnet_cidr)])) self.creators.append(self.network_creator) self.logger.info( diff --git a/functest/opnfv_tests/vnf/ims/cloudify_ims.py b/functest/opnfv_tests/vnf/ims/cloudify_ims.py index 8f6fcec8..b07eaee2 100644 --- a/functest/opnfv_tests/vnf/ims/cloudify_ims.py +++ b/functest/opnfv_tests/vnf/ims/cloudify_ims.py @@ -110,15 +110,15 @@ class CloudifyIms(clearwater_ims_base.ClearwaterOnBoardingBase): # needs some images self.__logger.info("Upload some OS images if it doesn't exist") - for image_name, image_url in self.images.iteritems(): - self.__logger.info("image: %s, url: %s", image_name, image_url) - if image_url and image_name: + for image_name, image_file in self.images.iteritems(): + self.__logger.info("image: %s, file: %s", image_name, image_file) + if image_file and image_name: image_creator = OpenStackImage( self.snaps_creds, ImageSettings(name=image_name, image_user='cloud', img_format='qcow2', - url=image_url)) + image_file=image_file)) image_creator.create() # self.created_object.append(image_creator) diff --git a/functest/opnfv_tests/vnf/ims/orchestra_clearwaterims.py b/functest/opnfv_tests/vnf/ims/orchestra_clearwaterims.py index 9e14711c..a5405996 100644 --- a/functest/opnfv_tests/vnf/ims/orchestra_clearwaterims.py +++ b/functest/opnfv_tests/vnf/ims/orchestra_clearwaterims.py @@ -195,9 +195,7 @@ class ClearwaterImsVnf(vnf.VnfOnBoarding): if not os.path.exists(self.data_dir): os.makedirs(self.data_dir) - self.images = get_config( - "tenant_images.%s" % - self.case_name, config_file) + self.images = get_config("tenant_images.orchestrator", config_file) self.images.update( get_config( "tenant_images.%s" % @@ -228,15 +226,15 @@ class ClearwaterImsVnf(vnf.VnfOnBoarding): def prepare_images(self): """Upload images if they doen't exist yet""" self.logger.info("Upload images if they doen't exist yet") - for image_name, image_url in self.images.iteritems(): - self.logger.info("image: %s, url: %s", image_name, image_url) - if image_url and image_name: + for image_name, image_file in self.images.iteritems(): + self.logger.info("image: %s, file: %s", image_name, image_file) + if image_file and image_name: image = OpenStackImage( self.snaps_creds, ImageSettings(name=image_name, image_user='cloud', img_format='qcow2', - url=image_url)) + image_file=image_file)) image.create() # self.created_resources.append(image); diff --git a/functest/opnfv_tests/vnf/ims/orchestra_openims.py b/functest/opnfv_tests/vnf/ims/orchestra_openims.py index f9a81f22..f8acada4 100644 --- a/functest/opnfv_tests/vnf/ims/orchestra_openims.py +++ b/functest/opnfv_tests/vnf/ims/orchestra_openims.py @@ -195,8 +195,7 @@ class OpenImsVnf(vnf.VnfOnBoarding): if not os.path.exists(self.data_dir): os.makedirs(self.data_dir) - self.images = get_config("tenant_images.%s" % - self.case_name, config_file) + self.images = get_config("tenant_images.orchestrator", config_file) self.images.update(get_config("tenant_images.%s" % self.case_name, config_file)) self.snaps_creds = None @@ -224,15 +223,15 @@ class OpenImsVnf(vnf.VnfOnBoarding): def prepare_images(self): """Upload images if they doen't exist yet""" self.logger.info("Upload images if they doen't exist yet") - for image_name, image_url in self.images.iteritems(): - self.logger.info("image: %s, url: %s", image_name, image_url) - if image_url and image_name: + for image_name, image_file in self.images.iteritems(): + self.logger.info("image: %s, file: %s", image_name, image_file) + if image_file and image_name: image = OpenStackImage( self.snaps_creds, ImageSettings(name=image_name, image_user='cloud', img_format='qcow2', - url=image_url)) + image_file=image_file)) image.create() # self.created_resources.append(image); diff --git a/functest/tests/unit/openstack/tempest/test_conf_utils.py b/functest/tests/unit/openstack/tempest/test_conf_utils.py index bbfcc57d..e2937a18 100644 --- a/functest/tests/unit/openstack/tempest/test_conf_utils.py +++ b/functest/tests/unit/openstack/tempest/test_conf_utils.py @@ -18,11 +18,8 @@ class OSTempestConfUtilsTesting(unittest.TestCase): def test_create_tempest_resources_missing_network_dic(self): with mock.patch('functest.opnfv_tests.openstack.tempest.conf_utils.' - 'os_utils.get_keystone_client', - return_value=mock.Mock()), \ - mock.patch('functest.opnfv_tests.openstack.tempest.conf_utils.' - 'os_utils.create_shared_network_full', - return_value=None), \ + 'os_utils.create_shared_network_full', + return_value=None), \ self.assertRaises(Exception) as context: conf_utils.create_tempest_resources() msg = 'Failed to create private network' @@ -30,12 +27,9 @@ class OSTempestConfUtilsTesting(unittest.TestCase): def test_create_tempest_resources_missing_image(self): with mock.patch('functest.opnfv_tests.openstack.tempest.conf_utils.' - 'os_utils.get_keystone_client', + 'os_utils.create_shared_network_full', return_value=mock.Mock()), \ mock.patch('functest.opnfv_tests.openstack.tempest.conf_utils.' - 'os_utils.create_shared_network_full', - return_value=mock.Mock()), \ - mock.patch('functest.opnfv_tests.openstack.tempest.conf_utils.' 'os_utils.get_or_create_image', return_value=(mock.Mock(), None)), \ self.assertRaises(Exception) as context: @@ -52,12 +46,9 @@ class OSTempestConfUtilsTesting(unittest.TestCase): def test_create_tempest_resources_missing_flavor(self): with mock.patch('functest.opnfv_tests.openstack.tempest.conf_utils.' - 'os_utils.get_keystone_client', + 'os_utils.create_shared_network_full', return_value=mock.Mock()), \ mock.patch('functest.opnfv_tests.openstack.tempest.conf_utils.' - 'os_utils.create_shared_network_full', - return_value=mock.Mock()), \ - mock.patch('functest.opnfv_tests.openstack.tempest.conf_utils.' 'os_utils.get_or_create_image', return_value=(mock.Mock(), 'image_id')), \ mock.patch('functest.opnfv_tests.openstack.tempest.conf_utils.' @@ -76,6 +67,58 @@ class OSTempestConfUtilsTesting(unittest.TestCase): msg = 'Failed to create flavor' self.assertTrue(msg in context) + @mock.patch('functest.opnfv_tests.openstack.tempest.conf_utils.' + 'logger.error') + def create_tenant_user_and_tenant_ok(self, mock_logger_error): + with mock.patch('functest.opnfv_tests.openstack.tempest.conf_utils.' + 'os_utils.get_keystone_client', + return_value=mock.Mock()), \ + mock.patch('functest.opnfv_tests.openstack.tempest.conf_utils.' + 'os_utils.create_tenant', + return_value='test_tenant_id'): + conf_utils.create_tenant_user() + mock_logger_error.assert_not_called() + + @mock.patch('functest.opnfv_tests.openstack.tempest.conf_utils.' + 'logger.error') + def create_tenant_user_and_user_ok(self, mock_logger_error): + with mock.patch('functest.opnfv_tests.openstack.tempest.conf_utils.' + 'os_utils.get_keystone_client', + return_value=mock.Mock()), \ + mock.patch('functest.opnfv_tests.openstack.tempest.conf_utils.' + 'os_utils.create_user', + return_value='test_user_id'): + conf_utils.create_tenant_user() + mock_logger_error.assert_not_called() + + @mock.patch('functest.opnfv_tests.openstack.tempest.conf_utils.' + 'logger.error') + def create_tenant_user_and_tenant_failed(self, mock_logger_error): + with mock.patch('functest.opnfv_tests.openstack.tempest.conf_utils.' + 'os_utils.get_keystone_client', + return_value=mock.Mock()), \ + mock.patch('functest.opnfv_tests.openstack.tempest.conf_utils.' + 'os_utils.create_tenant', + return_value=None): + conf_utils.create_tenant_user() + msg = ("Failed to create %s tenant" + % CONST.__getattribute__('tempest_identity_tenant_name')) + mock_logger_error.assert_any_call(msg) + + @mock.patch('functest.opnfv_tests.openstack.tempest.conf_utils.' + 'logger.error') + def create_tenant_user_and_user_failed(self, mock_logger_error): + with mock.patch('functest.opnfv_tests.openstack.tempest.conf_utils.' + 'os_utils.get_keystone_client', + return_value=mock.Mock()), \ + mock.patch('functest.opnfv_tests.openstack.tempest.conf_utils.' + 'os_utils.create_user', + return_value=None): + conf_utils.create_tenant_user() + msg = ("Failed to create %s user" + % CONST.__getattribute__('tempest_identity_user_name')) + mock_logger_error.assert_any_call(msg) + def test_get_verifier_id_missing_verifier(self): CONST.__setattr__('tempest_deployment_name', 'test_deploy_name') with mock.patch('functest.opnfv_tests.openstack.tempest.' @@ -206,6 +249,8 @@ class OSTempestConfUtilsTesting(unittest.TestCase): 'write') as mwrite, \ mock.patch('__builtin__.open', mock.mock_open()), \ mock.patch('functest.opnfv_tests.openstack.tempest.' + 'conf_utils.generate_test_accounts_file'), \ + mock.patch('functest.opnfv_tests.openstack.tempest.' 'conf_utils.shutil.copyfile'): conf_utils.configure_tempest_defcore('test_dep_dir', img_flavor_dict) @@ -218,6 +263,17 @@ class OSTempestConfUtilsTesting(unittest.TestCase): self.assertTrue(mread.called) self.assertTrue(mwrite.called) + def test_generate_test_accounts_file_default(self): + with mock.patch('functest.opnfv_tests.openstack.tempest.conf_utils.' + 'create_tenant_user', + return_value='test_tenant_id') as mock_create, \ + mock.patch("__builtin__.open", mock.mock_open()), \ + mock.patch('functest.opnfv_tests.openstack.tempest.conf_utils.' + 'yaml.dump') as mock_dump: + conf_utils.generate_test_accounts_file() + self.assertTrue(mock_create.called) + self.assertTrue(mock_dump.called) + def _test_missing_param(self, params, image_id, flavor_id): with mock.patch('functest.opnfv_tests.openstack.tempest.' 'conf_utils.ConfigParser.RawConfigParser.' |