From b8b14d27a2ece042553a82b82fb0a3a7f3896fdf Mon Sep 17 00:00:00 2001 From: spisarski Date: Tue, 25 Jul 2017 14:40:09 -0600 Subject: Added region support. Added region_name attribute to OSCreds Added region_name to neutron, nova, glance, heat, and keystone client retrieval Fixed false positive heat connection test. JIRA: SNAPS-50 & SNAPS-146 Change-Id: If3471ed7a2bdd0e6bfc281455c996386d031235d Signed-off-by: spisarski --- snaps/openstack/utils/glance_utils.py | 3 +- snaps/openstack/utils/heat_utils.py | 3 +- snaps/openstack/utils/keystone_utils.py | 4 ++- snaps/openstack/utils/neutron_utils.py | 3 +- snaps/openstack/utils/nova_utils.py | 3 +- snaps/openstack/utils/tests/heat_utils_tests.py | 39 ++++++++++++++++--------- 6 files changed, 37 insertions(+), 18 deletions(-) (limited to 'snaps/openstack/utils') diff --git a/snaps/openstack/utils/glance_utils.py b/snaps/openstack/utils/glance_utils.py index 8479be3..49bfe95 100644 --- a/snaps/openstack/utils/glance_utils.py +++ b/snaps/openstack/utils/glance_utils.py @@ -40,7 +40,8 @@ def glance_client(os_creds): :return: the glance client """ return Client(version=os_creds.image_api_version, - session=keystone_utils.keystone_session(os_creds)) + session=keystone_utils.keystone_session(os_creds), + region_name=os_creds.region_name) def get_image(glance, image_name=None): diff --git a/snaps/openstack/utils/heat_utils.py b/snaps/openstack/utils/heat_utils.py index a631b35..ae367a0 100644 --- a/snaps/openstack/utils/heat_utils.py +++ b/snaps/openstack/utils/heat_utils.py @@ -37,7 +37,8 @@ def heat_client(os_creds): """ logger.debug('Retrieving Nova Client') return Client(os_creds.heat_api_version, - session=keystone_utils.keystone_session(os_creds)) + session=keystone_utils.keystone_session(os_creds), + region_name=os_creds.region_name) def get_stack_by_name(heat_cli, stack_name): diff --git a/snaps/openstack/utils/keystone_utils.py b/snaps/openstack/utils/keystone_utils.py index 4eda4e4..8446df0 100644 --- a/snaps/openstack/utils/keystone_utils.py +++ b/snaps/openstack/utils/keystone_utils.py @@ -83,7 +83,9 @@ def keystone_client(os_creds): """ return Client( version=os_creds.identity_api_version, - session=keystone_session(os_creds), interface=os_creds.interface) + session=keystone_session(os_creds), + interface=os_creds.interface, + region_name=os_creds.region_name) def get_endpoint(os_creds, service_type, interface='public'): diff --git a/snaps/openstack/utils/neutron_utils.py b/snaps/openstack/utils/neutron_utils.py index d93faa0..bf8cb08 100644 --- a/snaps/openstack/utils/neutron_utils.py +++ b/snaps/openstack/utils/neutron_utils.py @@ -40,7 +40,8 @@ def neutron_client(os_creds): :return: the client object """ return Client(api_version=os_creds.network_api_version, - session=keystone_utils.keystone_session(os_creds)) + session=keystone_utils.keystone_session(os_creds), + region_name=os_creds.region_name) def create_network(neutron, os_creds, network_settings): diff --git a/snaps/openstack/utils/nova_utils.py b/snaps/openstack/utils/nova_utils.py index 70b1e7b..ab434f1 100644 --- a/snaps/openstack/utils/nova_utils.py +++ b/snaps/openstack/utils/nova_utils.py @@ -45,7 +45,8 @@ def nova_client(os_creds): """ logger.debug('Retrieving Nova Client') return Client(os_creds.compute_api_version, - session=keystone_utils.keystone_session(os_creds)) + session=keystone_utils.keystone_session(os_creds), + region_name=os_creds.region_name) def create_server(nova, neutron, glance, instance_settings, image_settings, diff --git a/snaps/openstack/utils/tests/heat_utils_tests.py b/snaps/openstack/utils/tests/heat_utils_tests.py index 2ef0c68..dda1111 100644 --- a/snaps/openstack/utils/tests/heat_utils_tests.py +++ b/snaps/openstack/utils/tests/heat_utils_tests.py @@ -44,7 +44,9 @@ class HeatSmokeTests(OSComponentTestCase): heat = heat_utils.heat_client(self.os_creds) # This should not throw an exception - heat.stacks.list() + stacks = heat.stacks.list() + for stack in stacks: + print stack def test_nova_connect_fail(self): """ @@ -52,13 +54,17 @@ class HeatSmokeTests(OSComponentTestCase): """ from snaps.openstack.os_credentials import OSCreds - nova = heat_utils.heat_client( - OSCreds(username='user', password='pass', auth_url=self.os_creds.auth_url, - project_name=self.os_creds.project_name, proxy_settings=self.os_creds.proxy_settings)) + heat = heat_utils.heat_client( + OSCreds(username='user', password='pass', + auth_url=self.os_creds.auth_url, + project_name=self.os_creds.project_name, + proxy_settings=self.os_creds.proxy_settings)) + stacks = heat.stacks.list() # This should throw an exception with self.assertRaises(Exception): - nova.flavors.list() + for stack in stacks: + print stack class HeatUtilsCreateStackTests(OSComponentTestCase): @@ -68,15 +74,16 @@ class HeatUtilsCreateStackTests(OSComponentTestCase): def setUp(self): """ - Instantiates the CreateImage object that is responsible for downloading and creating an OS image file - within OpenStack + Instantiates the CreateImage object that is responsible for downloading + and creating an OS image file within OpenStack """ guid = self.__class__.__name__ + '-' + str(uuid.uuid4()) stack_name = self.__class__.__name__ + '-' + str(guid) + '-stack' self.image_creator = OpenStackImage( self.os_creds, openstack_tests.cirros_image_settings( - name=self.__class__.__name__ + '-' + str(guid) + '-image', image_metadata=self.image_metadata)) + name=self.__class__.__name__ + '-' + str(guid) + '-image', + image_metadata=self.image_metadata)) self.image_creator.create() # Create Flavor @@ -89,7 +96,9 @@ class HeatUtilsCreateStackTests(OSComponentTestCase): 'flavor_name': self.flavor_creator.flavor_settings.name} heat_tmplt_path = pkg_resources.resource_filename( 'snaps.openstack.tests.heat', 'test_heat_template.yaml') - self.stack_settings = StackSettings(name=stack_name, template_path=heat_tmplt_path, env_values=env_values) + self.stack_settings = StackSettings( + name=stack_name, template_path=heat_tmplt_path, + env_values=env_values) self.stack = None self.heat_client = heat_utils.heat_client(self.os_creds) @@ -119,12 +128,15 @@ class HeatUtilsCreateStackTests(OSComponentTestCase): """ Tests the creation of an OpenStack keypair that does not exist. """ - self.stack = heat_utils.create_stack(self.heat_client, self.stack_settings) + self.stack = heat_utils.create_stack(self.heat_client, + self.stack_settings) - stack_query_1 = heat_utils.get_stack_by_name(self.heat_client, self.stack_settings.name) + stack_query_1 = heat_utils.get_stack_by_name(self.heat_client, + self.stack_settings.name) self.assertEqual(self.stack.id, stack_query_1.id) - stack_query_2 = heat_utils.get_stack_by_id(self.heat_client, self.stack.id) + stack_query_2 = heat_utils.get_stack_by_id(self.heat_client, + self.stack.id) self.assertEqual(self.stack.id, stack_query_2.id) outputs = heat_utils.get_stack_outputs(self.heat_client, self.stack.id) @@ -135,7 +147,8 @@ class HeatUtilsCreateStackTests(OSComponentTestCase): is_active = False while time.time() < end_time: - status = heat_utils.get_stack_status(self.heat_client, self.stack.id) + status = heat_utils.get_stack_status(self.heat_client, + self.stack.id) if status == create_stack.STATUS_CREATE_COMPLETE: is_active = True break -- cgit 1.2.3-korg