diff options
author | spisarski <s.pisarski@cablelabs.com> | 2018-05-24 11:08:06 -0600 |
---|---|---|
committer | spisarski <s.pisarski@cablelabs.com> | 2018-05-24 11:08:06 -0600 |
commit | 8a60bedb302428719b81172cd65c0718ccb43041 (patch) | |
tree | 171d132fcdb28a2414aa69730a7680d0b39c1a0c | |
parent | f5ff39bd0b32c5d3c31bc21cb1f560161c559894 (diff) |
Added ability for integration tests to define additional
existing users to a project.
Change-Id: I91be434dcd7b580f3bfd69e3a97b9a9a13ee4676
Signed-off-by: spisarski <s.pisarski@cablelabs.com>
-rw-r--r-- | snaps/openstack/tests/create_instance_tests.py | 30 | ||||
-rw-r--r-- | snaps/openstack/tests/os_source_file_test.py | 14 |
2 files changed, 40 insertions, 4 deletions
diff --git a/snaps/openstack/tests/create_instance_tests.py b/snaps/openstack/tests/create_instance_tests.py index bdd6d50..a45654f 100644 --- a/snaps/openstack/tests/create_instance_tests.py +++ b/snaps/openstack/tests/create_instance_tests.py @@ -44,6 +44,7 @@ from snaps.openstack.create_network import OpenStackNetwork from snaps.openstack.create_router import OpenStackRouter from snaps.openstack.create_security_group import OpenStackSecurityGroup from snaps.openstack.create_volume import OpenStackVolume +from snaps.openstack.os_credentials import OSCreds from snaps.openstack.tests import openstack_tests, validation_utils from snaps.openstack.tests.os_source_file_test import ( OSIntegrationTestCase, OSComponentTestCase) @@ -694,6 +695,7 @@ class CreateInstanceSingleNetworkTests(OSIntegrationTestCase): Instantiates the CreateImage object that is responsible for downloading and creating an OS image file within OpenStack """ + self.proj_users = ['admin'] super(self.__class__, self).__start__() self.nova = nova_utils.nova_client(self.os_creds, self.os_session) @@ -1055,10 +1057,36 @@ class CreateInstanceSingleNetworkTests(OSIntegrationTestCase): self.assertTrue(inst_creator.vm_active(block=True)) + vm_os_creds = OSCreds( + auth_url=self.admin_os_creds.auth_url, + username=self.admin_os_creds.username, + password=self.admin_os_creds.password, + project_name=self.os_creds.project_name, + identity_api_version=self.os_creds.identity_api_version) derived_inst_creator = create_instance.generate_creator( - self.os_creds, vm_inst, self.image_creator.image_settings, + vm_os_creds, vm_inst, self.image_creator.image_settings, self.os_creds.project_name, self.keypair_creator.keypair_settings) + # Tests to ensure that a instance can be returned with an invalid + # image config object and admin credentials (when the 'admin' user has + # been added to the project) as this should not matter unless one + # needs to access the machine via ssh and its floating IP + + # Invalid ImageConfig + derived_foo_image_creator = create_instance.generate_creator( + vm_os_creds, vm_inst, ImageConfig( + name='foo', image_user='bar', format='qcow2', + image_file='foo/bar'), + vm_os_creds.project_name) + self.assertIsNotNone(derived_foo_image_creator) + self.assertTrue(derived_foo_image_creator.vm_active()) + + # None ImageConfig + derived_none_image_creator = create_instance.generate_creator( + vm_os_creds, vm_inst, None, vm_os_creds.project_name) + self.assertIsNotNone(derived_none_image_creator) + self.assertTrue(derived_none_image_creator.vm_active()) + derived_inst_creator.add_floating_ip(FloatingIpConfig( name=self.floating_ip_name, port_name=self.port_1_name, router_name=self.pub_net_config.router_settings.name)) diff --git a/snaps/openstack/tests/os_source_file_test.py b/snaps/openstack/tests/os_source_file_test.py index 7e70ed0..c632e02 100644 --- a/snaps/openstack/tests/os_source_file_test.py +++ b/snaps/openstack/tests/os_source_file_test.py @@ -77,8 +77,9 @@ 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, - flavor_metadata, image_metadata, log_level)) + suite.addTest(testcase_klass( + name, os_creds, ext_net_name, flavor_metadata, image_metadata, + log_level)) return suite def __clean__(self): @@ -123,6 +124,7 @@ class OSIntegrationTestCase(OSComponentTestCase): self.use_keystone = use_keystone self.keystone = None self.user_roles = None + self.proj_users = None @staticmethod def parameterize(testcase_klass, os_creds, ext_net_name, @@ -170,7 +172,7 @@ class OSIntegrationTestCase(OSComponentTestCase): # Set by implementing class for setting the user's roles roles = dict() - if self.user_roles: + if self.user_roles and isinstance(self.user_roles, list): for user_role in self.user_roles: roles[user_role] = project_name @@ -187,6 +189,12 @@ class OSIntegrationTestCase(OSComponentTestCase): # add user to project self.project_creator.assoc_user(self.user_creator.get_user()) + if self.proj_users and isinstance(self.proj_users, list): + for user_name in self.proj_users: + user = keystone_utils.get_user(self.keystone, user_name) + if user: + self.project_creator.assoc_user(user) + def __clean__(self): """ Cleans up test user and project. |