diff options
author | 2017-07-07 15:26:24 -0600 | |
---|---|---|
committer | 2017-07-11 08:10:28 -0600 | |
commit | 9881e7e312b1927d9be52ae02dccc5f9df3982df (patch) | |
tree | 167feaba570b4e29368260d82284bd398564c71d /snaps/openstack/tests/os_source_file_test.py | |
parent | 5f3fe6856f07bd1289bac532264eccf6cba68d77 (diff) |
Added ability to add a user to a role.
This functionality was requested as the SNAPS-OO integration tests
currently have the ability to run these tests in custom projects with
custom users and certain OpenStack installations are not allowing
some of the integration tests functions unless the new user has been
added to the 'admin' role.
Change-Id: I255cfa089a14bbcb434a6cd33b2a1dfae66206b5
Signed-off-by: spisarski <s.pisarski@cablelabs.com>
Diffstat (limited to 'snaps/openstack/tests/os_source_file_test.py')
-rw-r--r-- | snaps/openstack/tests/os_source_file_test.py | 97 |
1 files changed, 59 insertions, 38 deletions
diff --git a/snaps/openstack/tests/os_source_file_test.py b/snaps/openstack/tests/os_source_file_test.py index 4b421e8..01aa88a 100644 --- a/snaps/openstack/tests/os_source_file_test.py +++ b/snaps/openstack/tests/os_source_file_test.py @@ -24,23 +24,23 @@ from snaps.openstack.tests import openstack_tests from snaps.openstack.utils import deploy_utils, keystone_utils -dev_os_env_file = pkg_resources.resource_filename('snaps.openstack.tests.conf', 'os_env.yaml') - -# !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! -# To run these tests from an IDE, the CWD must be set to the snaps directory of this project -# !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! +dev_os_env_file = pkg_resources.resource_filename( + 'snaps.openstack.tests.conf', 'os_env.yaml') class OSComponentTestCase(unittest.TestCase): - def __init__(self, method_name='runTest', os_creds=None, ext_net_name=None, image_metadata=None, - log_level=logging.DEBUG): + def __init__(self, method_name='runTest', os_creds=None, ext_net_name=None, + image_metadata=None, log_level=logging.DEBUG): """ Super for test classes requiring a connection to OpenStack :param method_name: default 'runTest' - :param os_creds: the OSCreds object, when null it searches for the file {cwd}/openstack/tests/conf/os_env.yaml - :param ext_net_name: the name of the external network that is used for creating routers for floating IPs - :param image_metadata: ability to override images being used in the tests (see examples/image-metadata) + :param os_creds: the OSCreds object, when null it searches for the file + in the package snaps.openstack.tests.conf.os_env.yaml + :param ext_net_name: the name of the external network that is used for + creating routers for floating IPs + :param image_metadata: ability to override images being used in the + tests (see examples/image-metadata) :param log_level: the logging level of your test run (default DEBUG) """ super(OSComponentTestCase, self).__init__(method_name) @@ -50,7 +50,8 @@ class OSComponentTestCase(unittest.TestCase): if os_creds: self.os_creds = os_creds else: - self.os_creds = openstack_tests.get_credentials(dev_os_env_file=dev_os_env_file) + self.os_creds = openstack_tests.get_credentials( + dev_os_env_file=dev_os_env_file) self.ext_net_name = ext_net_name @@ -61,7 +62,8 @@ class OSComponentTestCase(unittest.TestCase): self.image_metadata = image_metadata @staticmethod - def parameterize(testcase_klass, os_creds, ext_net_name, image_metadata=None, log_level=logging.DEBUG): + def parameterize(testcase_klass, os_creds, ext_net_name, + image_metadata=None, log_level=logging.DEBUG): """ Create a suite containing all tests taken from the given subclass, passing them the parameter 'param'. """ @@ -69,37 +71,46 @@ class OSComponentTestCase(unittest.TestCase): test_names = test_loader.getTestCaseNames(testcase_klass) suite = unittest.TestSuite() for name in test_names: - suite.addTest(testcase_klass(name, os_creds, ext_net_name, image_metadata, log_level)) + suite.addTest(testcase_klass(name, os_creds, ext_net_name, + image_metadata, log_level)) return suite class OSIntegrationTestCase(OSComponentTestCase): - def __init__(self, method_name='runTest', os_creds=None, ext_net_name=None, use_keystone=False, - flavor_metadata=None, image_metadata=None, log_level=logging.DEBUG): + def __init__(self, method_name='runTest', os_creds=None, ext_net_name=None, + use_keystone=False, flavor_metadata=None, image_metadata=None, + log_level=logging.DEBUG): """ Super for integration tests requiring a connection to OpenStack :param method_name: default 'runTest' - :param os_creds: the OSCreds object, when null it searches for the file {cwd}/openstack/tests/conf/os_env.yaml - :param ext_net_name: the name of the external network that is used for creating routers for floating IPs - :param use_keystone: when true, these tests will create a new user/project under which to run the test - :param image_metadata: dict() containing the URLs for the disk, kernel, and ramdisk images when multi-part - images are required. - image_metadata={'disk_url': 'http://download.cirros-cloud.net/0.3.4/cirros-0.3.4-x86_64-disk.img', - 'kernel_url': 'http://download.cirros-cloud.net/0.3.4/cirros-0.3.4-x86_64-kernel', - 'ramdisk_url': 'http://download.cirros-cloud.net/0.3.4/cirros-0.3.4-x86_64-initramfs'}) - :param flavor_metadata: dict() to be sent directly into the Nova client generally used for page sizes + :param os_creds: the OSCreds object, when null it searches for the file + in the package snaps.openstack.tests.conf.os_env.yaml + :param ext_net_name: the name of the external network that is used for + creating routers for floating IPs + :param use_keystone: when true, these tests will create a new + user/project under which to run the test + :param image_metadata: dict() containing the URLs for the disk, kernel, + and ramdisk images when multi-part images are + required. See below for a simple example + image_metadata={'disk_url': '{URI}/cirros-0.3.4-x86_64-disk.img', + 'kernel_url': '{URI}/cirros-0.3.4-x86_64-kernel', + 'ramdisk_url': '{URI}/cirros-0.3.4-x86_64-initramfs'}) + :param flavor_metadata: dict() to be sent directly into the Nova client + generally used for page sizes :param log_level: the logging level of your test run (default DEBUG) """ - super(OSIntegrationTestCase, self).__init__(method_name=method_name, os_creds=os_creds, - ext_net_name=ext_net_name, image_metadata=image_metadata, - log_level=log_level) + super(OSIntegrationTestCase, self).__init__( + method_name=method_name, os_creds=os_creds, + ext_net_name=ext_net_name, image_metadata=image_metadata, + log_level=log_level) self.use_keystone = use_keystone self.keystone = None self.flavor_metadata = flavor_metadata @staticmethod - def parameterize(testcase_klass, os_creds, ext_net_name, use_keystone=False, flavor_metadata=None, + def parameterize(testcase_klass, os_creds, ext_net_name, + use_keystone=False, flavor_metadata=None, image_metadata=None, log_level=logging.DEBUG): """ Create a suite containing all tests taken from the given @@ -109,17 +120,20 @@ class OSIntegrationTestCase(OSComponentTestCase): test_names = test_loader.getTestCaseNames(testcase_klass) suite = unittest.TestSuite() for name in test_names: - suite.addTest(testcase_klass(name, os_creds, ext_net_name, use_keystone, flavor_metadata, image_metadata, - log_level)) + suite.addTest(testcase_klass(name, os_creds, ext_net_name, + use_keystone, flavor_metadata, + image_metadata, log_level)) return suite """ - Super for test classes that should be run within their own project/tenant as they can run for quite some time + Super for test classes that should be run within their own project/tenant + as they can run for quite some time """ def __start__(self): """ - Creates a project and user to be leveraged by subclass test methods. If implementing class uses this method, - it must call __clean__() else you will be left with unwanted users and tenants + Creates a project and user to be leveraged by subclass test methods. If + implementing class uses this method, it must call __clean__() else you + will be left with unwanted users and tenants """ self.project_creator = None self.user_creator = None @@ -130,11 +144,17 @@ class OSIntegrationTestCase(OSComponentTestCase): self.keystone = keystone_utils.keystone_client(self.os_creds) guid = self.__class__.__name__ + '-' + str(uuid.uuid4())[:-19] project_name = guid + '-proj' - self.project_creator = deploy_utils.create_project(self.admin_os_creds, ProjectSettings(name=project_name)) + self.project_creator = deploy_utils.create_project( + self.admin_os_creds, ProjectSettings(name=project_name)) self.user_creator = deploy_utils.create_user( - self.admin_os_creds, UserSettings(name=guid + '-user', password=guid, project_name=project_name)) - self.os_creds = self.user_creator.get_os_creds(self.project_creator.project_settings.name) + self.admin_os_creds, UserSettings( + name=guid + '-user', password=guid, + project_name=project_name, roles={ + 'admin': self.project_creator.project_settings.name})) + + self.os_creds = self.user_creator.get_os_creds( + self.project_creator.project_settings.name) # add user to project self.project_creator.assoc_user(self.user_creator.get_user()) @@ -142,8 +162,9 @@ class OSIntegrationTestCase(OSComponentTestCase): def __clean__(self): """ Cleans up test user and project. - Must be called at the end of child classes tearDown() if __start__() is called during setUp() else these - objects will persist after the test is run + Must be called at the end of child classes tearDown() if __start__() is + called during setUp() else these objects will persist after the test is + run """ if self.role: keystone_utils.delete_role(self.keystone, self.role) |