diff --git a/contrib/barbican/barbican/clients.py b/contrib/barbican/barbican/clients.py index 07a267d74..ee811f7ce 100644 --- a/contrib/barbican/barbican/clients.py +++ b/contrib/barbican/barbican/clients.py @@ -24,15 +24,7 @@ except ImportError: class Clients(heat_clients.OpenStackClients): - def __init__(self, context): - super(Clients, self).__init__(context) - self._barbican = None - - def barbican(self): - if self._barbican: - return self._barbican - - keystone_client = self.keystone().client + def _barbican(self): + keystone_client = self.client('keystone').client auth_plugin = auth.KeystoneAuthV2(keystone=keystone_client) - self._barbican = barbican_client.Client(auth_plugin=auth_plugin) - return self._barbican + return barbican_client.Client(auth_plugin=auth_plugin) diff --git a/contrib/barbican/barbican/resources/order.py b/contrib/barbican/barbican/resources/order.py index 6dfecb624..f60883028 100644 --- a/contrib/barbican/barbican/resources/order.py +++ b/contrib/barbican/barbican/resources/order.py @@ -106,14 +106,17 @@ class Order(resource.Resource): super(Order, self).__init__(name, json_snippet, stack) self.clients = clients.Clients(self.context) + def barbican(self): + return self.clients.client('barbican') + def handle_create(self): info = dict(self.properties) - order_ref = self.clients.barbican().orders.create(**info) + order_ref = self.barbican().orders.create(**info) self.resource_id_set(order_ref) return order_ref def check_create_complete(self, order_href): - order = self.clients.barbican().orders.get(order_href) + order = self.barbican().orders.get(order_href) if order.status == 'ERROR': reason = order.error_reason @@ -129,7 +132,7 @@ class Order(resource.Resource): return try: - self.clients.barbican().orders.delete(self.resource_id) + self.barbican().orders.delete(self.resource_id) self.resource_id_set(None) except clients.barbican_client.HTTPClientError as exc: # This is the only exception the client raises @@ -141,7 +144,7 @@ class Order(resource.Resource): def _resolve_attribute(self, name): try: - order = self.clients.barbican().orders.get(self.resource_id) + order = self.barbican().orders.get(self.resource_id) except clients.barbican_client.HTTPClientError as exc: LOG.warn(_("Order '%(name)s' not found: %(exc)s") % {'name': self.resource_id, 'exc': str(exc)}) diff --git a/contrib/barbican/barbican/resources/secret.py b/contrib/barbican/barbican/resources/secret.py index acc05930a..d140be3f7 100644 --- a/contrib/barbican/barbican/resources/secret.py +++ b/contrib/barbican/barbican/resources/secret.py @@ -109,6 +109,9 @@ class Secret(resource.Resource): super(Secret, self).__init__(name, json_snippet, stack) self.clients = clients.Clients(self.context) + def barbican(self): + return self.clients.client('barbican') + def validate(self): super(Secret, self).validate() self._validate_payload() @@ -125,7 +128,7 @@ class Secret(resource.Resource): def handle_create(self): info = dict(self.properties) - secret_ref = self.clients.barbican().secrets.store(**info) + secret_ref = self.barbican().secrets.store(**info) self.resource_id_set(secret_ref) return secret_ref @@ -134,7 +137,7 @@ class Secret(resource.Resource): return try: - self.clients.barbican().secrets.delete(self.resource_id) + self.barbican().secrets.delete(self.resource_id) self.resource_id_set(None) except clients.barbican_client.HTTPClientError as exc: # This is the only exception the client raises @@ -147,10 +150,10 @@ class Secret(resource.Resource): def _resolve_attribute(self, name): try: if name == self.DECRYPTED_PAYLOAD: - return self.clients.barbican().secrets.decrypt( + return self.barbican().secrets.decrypt( self.resource_id) - secret = self.clients.barbican().secrets.get(self.resource_id) + secret = self.barbican().secrets.get(self.resource_id) if name == self.STATUS: return secret.status except clients.barbican_client.HTTPClientError as e: diff --git a/contrib/barbican/barbican/tests/test_clients.py b/contrib/barbican/barbican/tests/test_clients.py index e6ddb79e3..9a4fd5561 100644 --- a/contrib/barbican/barbican/tests/test_clients.py +++ b/contrib/barbican/barbican/tests/test_clients.py @@ -33,12 +33,12 @@ class TestClient(HeatTestCase): mock_barbican_client, mock_heat_clients): mock_ks = mock.Mock() - self.clients.keystone = mock.Mock() - self.clients.keystone.return_value.client = mock_ks + self.clients._keystone = mock.Mock() + self.clients._keystone.return_value.client = mock_ks mock_plugin = mock.Mock() mock_auth.KeystoneAuthV2.return_value = mock_plugin - self.clients.barbican() + self.clients.client('barbican') mock_auth.KeystoneAuthV2.assert_called_once_with(keystone=mock_ks) mock_barbican_client.Client.assert_called_once_with(auth_plugin= mock_plugin) diff --git a/contrib/barbican/barbican/tests/test_order.py b/contrib/barbican/barbican/tests/test_order.py index 62adb3788..1442125b2 100644 --- a/contrib/barbican/barbican/tests/test_order.py +++ b/contrib/barbican/barbican/tests/test_order.py @@ -52,9 +52,9 @@ class TestOrder(HeatTestCase): self.props = tmpl['resources']['order']['properties'] self._register_resources() - self.patcher_client = mock.patch.object(order.clients, 'Clients') + self.patcher_client = mock.patch.object(order.Order, 'barbican') mock_client = self.patcher_client.start() - self.barbican = mock_client.return_value.barbican.return_value + self.barbican = mock_client.return_value def tearDown(self): super(TestOrder, self).tearDown() diff --git a/contrib/barbican/barbican/tests/test_secret.py b/contrib/barbican/barbican/tests/test_secret.py index 5bec9ddf2..7d5da4818 100644 --- a/contrib/barbican/barbican/tests/test_secret.py +++ b/contrib/barbican/barbican/tests/test_secret.py @@ -42,9 +42,9 @@ class TestSecret(HeatTestCase): utils.setup_dummy_db() self.ctx = utils.dummy_context() - self.patcher_client = mock.patch.object(secret.clients, 'Clients') + self.patcher_client = mock.patch.object(secret.Secret, 'barbican') mock_client = self.patcher_client.start() - self.barbican = mock_client.return_value.barbican.return_value + self.barbican = mock_client.return_value self._register_resources() self.stack = utils.parse_stack(template_format.parse(stack_template)) @@ -86,7 +86,7 @@ class TestSecret(HeatTestCase): def test_attributes_handles_exceptions(self): secret.clients.barbican_client.HTTPClientError = Exception some_error = secret.clients.barbican_client.HTTPClientError('boom') - secret.clients.Clients().barbican.side_effect = some_error + secret.Secret.barbican.side_effect = some_error self.assertEqual('', self.res.FnGetAtt('status')) diff --git a/contrib/marconi/marconi/clients.py b/contrib/marconi/marconi/clients.py index f93ba0b4d..2ecc700d6 100644 --- a/contrib/marconi/marconi/clients.py +++ b/contrib/marconi/marconi/clients.py @@ -26,15 +26,7 @@ except ImportError: class Clients(clients.OpenStackClients): - """Convenience class to create and cache client instances.""" - - def __init__(self, context): - super(Clients, self).__init__(context) - self._marconi = None - - def marconi(self, service_type="queuing"): - if self._marconi: - return self._marconi + def _marconi(self, service_type="queuing"): con = self.context if self.auth_token is None: @@ -52,6 +44,4 @@ class Clients(clients.OpenStackClients): conf = {'auth_opts': auth_opts} endpoint = self.url_for(service_type=service_type) - self._marconi = marconiclient.Client(url=endpoint, conf=conf) - - return self._marconi + return marconiclient.Client(url=endpoint, conf=conf) diff --git a/contrib/marconi/marconi/resources/queue.py b/contrib/marconi/marconi/resources/queue.py index aef98ca93..285d44ebc 100644 --- a/contrib/marconi/marconi/resources/queue.py +++ b/contrib/marconi/marconi/resources/queue.py @@ -70,7 +70,7 @@ class MarconiQueue(resource.Resource): self.clients = clients.Clients(self.context) def marconi(self): - return self.clients.marconi() + return self.clients.client('marconi') def physical_resource_name(self): return self.properties[self.NAME] diff --git a/contrib/rackspace/rackspace/tests/test_rackspace_cloud_server.py b/contrib/rackspace/rackspace/tests/test_rackspace_cloud_server.py index 307d5c0b6..ed1f539c9 100644 --- a/contrib/rackspace/rackspace/tests/test_rackspace_cloud_server.py +++ b/contrib/rackspace/rackspace/tests/test_rackspace_cloud_server.py @@ -68,8 +68,8 @@ class CloudServersTest(HeatTestCase): def _mock_get_image_id_success(self, imageId_input, imageId): g_cli_mock = self.m.CreateMockAnything() - self.m.StubOutWithMock(clients.OpenStackClients, 'glance') - clients.OpenStackClients.glance().MultipleTimes().AndReturn( + self.m.StubOutWithMock(clients.OpenStackClients, '_glance') + clients.OpenStackClients._glance().MultipleTimes().AndReturn( g_cli_mock) self.m.StubOutWithMock(glance_utils, 'get_image_id') glance_utils.get_image_id(g_cli_mock, imageId_input).MultipleTimes().\ @@ -79,8 +79,8 @@ class CloudServersTest(HeatTestCase): # stub nova validate self.m.StubOutWithMock(server, 'nova') server.nova().MultipleTimes().AndReturn(self.fc) - self.m.StubOutWithMock(clients.OpenStackClients, 'nova') - clients.OpenStackClients.nova().MultipleTimes().AndReturn(self.fc) + self.m.StubOutWithMock(clients.OpenStackClients, '_nova') + clients.OpenStackClients._nova().MultipleTimes().AndReturn(self.fc) # stub glance image validate self._mock_get_image_id_success(imageId_input, image_id) @@ -324,7 +324,7 @@ class CloudServersTest(HeatTestCase): self.assertEqual('Error: Unknown Managed Cloud automation status: FOO', str(exc)) - @mock.patch.object(clients.OpenStackClients, 'nova') + @mock.patch.object(clients.OpenStackClients, '_nova') @mock.patch.object(resource.Resource, 'data_set') def test_create_store_admin_pass_resource_data(self, mock_data_set, @@ -348,7 +348,7 @@ class CloudServersTest(HeatTestCase): 'autogenerated', redact=True) self.assertIn(expected_call, mock_data_set.call_args_list) - @mock.patch.object(clients.OpenStackClients, 'nova') + @mock.patch.object(clients.OpenStackClients, '_nova') @mock.patch.object(resource.Resource, 'data_set') def test_create_save_admin_pass_is_false(self, mock_data_set, @@ -372,7 +372,7 @@ class CloudServersTest(HeatTestCase): mock.ANY, mock.ANY) self.assertNotIn(expected_call, mock_data_set.call_args_list) - @mock.patch.object(clients.OpenStackClients, 'nova') + @mock.patch.object(clients.OpenStackClients, '_nova') @mock.patch.object(resource.Resource, 'data_set') def test_create_save_admin_pass_defaults_to_false(self, mock_data_set, @@ -396,7 +396,7 @@ class CloudServersTest(HeatTestCase): mock.ANY, mock.ANY) self.assertNotIn(expected_call, mock_data_set.call_args_list) - @mock.patch.object(clients.OpenStackClients, 'nova') + @mock.patch.object(clients.OpenStackClients, '_nova') @mock.patch.object(resource.Resource, 'data_set') def test_create_without_adminPass_attribute(self, mock_data_set, @@ -440,7 +440,7 @@ class CloudServersTest(HeatTestCase): resource_defns['WebServer'], stack) self.assertEqual('foo', server.FnGetAtt('admin_pass')) - @mock.patch.object(clients.OpenStackClients, 'nova') + @mock.patch.object(clients.OpenStackClients, '_nova') def _test_server_config_drive(self, user_data, config_drive, result, mock_nova): return_server = self.fc.servers.list()[1] diff --git a/heat/engine/clients.py b/heat/engine/clients.py index b3b848323..801752c09 100644 --- a/heat/engine/clients.py +++ b/heat/engine/clients.py @@ -21,6 +21,7 @@ from novaclient import shell as novashell from oslo.config import cfg from swiftclient import client as swiftclient from troveclient import client as troveclient +import warnings from heat.common import heat_keystoneclient as hkc from heat.openstack.common.gettextutils import _ @@ -48,28 +49,40 @@ class OpenStackClients(object): self.context = context self._clients = {} + def client(self, name): + if name in self._clients: + return self._clients[name] + method_name = '_%s' % name + if callable(getattr(self, method_name, None)): + client = getattr(self, method_name)() + self._clients[name] = client + return client + @property def auth_token(self): # Always use the auth_token from the keystone() client, as # this may be refreshed if the context contains credentials # which allow reissuing of a new token before the context # auth_token expiry (e.g trust_id or username/password) - return self.keystone().auth_token + return self.client('keystone').auth_token def keystone(self): - if 'keystone' in self._clients: - return self._clients['keystone'] + warnings.warn('keystone() is deprecated. ' + 'Replace with calls to client("keystone")') + return self.client('keystone') - self._clients['keystone'] = hkc.KeystoneClient(self.context) - return self._clients['keystone'] + def _keystone(self): + return hkc.KeystoneClient(self.context) def url_for(self, **kwargs): - return self.keystone().url_for(**kwargs) + return self.client('keystone').url_for(**kwargs) def nova(self): - if 'nova' in self._clients: - return self._clients['nova'] + warnings.warn('nova() is deprecated. ' + 'Replace with calls to client("nova")') + return self.client('nova') + def _nova(self): con = self.context computeshell = novashell.OpenStackComputeShell() extensions = computeshell._discover_extensions("1.1") @@ -96,12 +109,14 @@ class OpenStackClients(object): client.client.auth_token = self.auth_token client.client.management_url = management_url - self._clients['nova'] = client return client def swift(self): - if 'swift' in self._clients: - return self._clients['swift'] + warnings.warn('swift() is deprecated. ' + 'Replace with calls to client("swift")') + return self.client('swift') + + def _swift(self): con = self.context endpoint_type = self._get_client_option('swift', 'endpoint_type') @@ -118,12 +133,14 @@ class OpenStackClients(object): 'cacert': self._get_client_option('swift', 'ca_file'), 'insecure': self._get_client_option('swift', 'insecure') } - self._clients['swift'] = swiftclient.Connection(**args) - return self._clients['swift'] + return swiftclient.Connection(**args) def glance(self): - if 'glance' in self._clients: - return self._clients['glance'] + warnings.warn('glance() is deprecated. ' + 'Replace with calls to client("glance")') + return self.client('glance') + + def _glance(self): con = self.context endpoint_type = self._get_client_option('glance', 'endpoint_type') @@ -141,12 +158,14 @@ class OpenStackClients(object): 'insecure': self._get_client_option('glance', 'insecure') } - self._clients['glance'] = glanceclient.Client('1', endpoint, **args) - return self._clients['glance'] + return glanceclient.Client('1', endpoint, **args) def neutron(self): - if 'neutron' in self._clients: - return self._clients['neutron'] + warnings.warn('neutron() is deprecated. ' + 'Replace with calls to client("neutron")') + return self.client('neutron') + + def _neutron(self): con = self.context if self.auth_token is None: @@ -165,13 +184,14 @@ class OpenStackClients(object): 'insecure': self._get_client_option('neutron', 'insecure') } - self._clients['neutron'] = neutronclient.Client(**args) - - return self._clients['neutron'] + return neutronclient.Client(**args) def cinder(self): - if 'cinder' in self._clients: - return self._clients['cinder'] + warnings.warn('cinder() is deprecated. ' + 'Replace with calls to client("cinder")') + return self.client('cinder') + + def _cinder(self): con = self.context endpoint_type = self._get_client_option('cinder', 'endpoint_type') @@ -186,22 +206,25 @@ class OpenStackClients(object): 'insecure': self._get_client_option('cinder', 'insecure') } - self._clients['cinder'] = cinderclient.Client('1', **args) + client = cinderclient.Client('1', **args) management_url = self.url_for(service_type='volume', endpoint_type=endpoint_type) - self._clients['cinder'].client.auth_token = self.auth_token - self._clients['cinder'].client.management_url = management_url + client.client.auth_token = self.auth_token + client.client.management_url = management_url - return self._clients['cinder'] + return client - def trove(self, service_type="database"): - if 'trove' in self._clients: - return self._clients['trove'] + def trove(self): + warnings.warn('trove() is deprecated. ' + 'Replace with calls to client("trove")') + return self.client('trove') + + def _trove(self): con = self.context endpoint_type = self._get_client_option('trove', 'endpoint_type') args = { - 'service_type': service_type, + 'service_type': 'database', 'auth_url': con.auth_url, 'proxy_token': con.auth_token, 'username': None, @@ -211,17 +234,20 @@ class OpenStackClients(object): 'endpoint_type': endpoint_type } - self._clients['trove'] = troveclient.Client('1.0', **args) - management_url = self.url_for(service_type=service_type, + client = troveclient.Client('1.0', **args) + management_url = self.url_for(service_type='database', endpoint_type=endpoint_type) - self._clients['trove'].client.auth_token = con.auth_token - self._clients['trove'].client.management_url = management_url + client.client.auth_token = con.auth_token + client.client.management_url = management_url - return self._clients['trove'] + return client def ceilometer(self): - if 'ceilometer' in self._clients: - return self._clients['ceilometer'] + warnings.warn('ceilometer() is deprecated. ' + 'Replace with calls to client("ceilometer")') + return self.client('ceilometer') + + def _ceilometer(self): con = self.context endpoint_type = self._get_client_option('ceilometer', 'endpoint_type') @@ -239,10 +265,7 @@ class OpenStackClients(object): 'insecure': self._get_client_option('ceilometer', 'insecure') } - client = ceilometerclient.Client('2', endpoint, **args) - - self._clients['ceilometer'] = client - return self._clients['ceilometer'] + return ceilometerclient.Client('2', endpoint, **args) def _get_client_option(self, client, option): try: @@ -262,8 +285,11 @@ class OpenStackClients(object): return heat_url def heat(self): - if 'heat' in self._clients: - return self._clients['heat'] + warnings.warn('heat() is deprecated. ' + 'Replace with calls to client("heat")') + return self.client('heat') + + def _heat(self): con = self.context endpoint_type = self._get_client_option('heat', 'endpoint_type') @@ -282,9 +308,7 @@ class OpenStackClients(object): if not endpoint: endpoint = self.url_for(service_type='orchestration', endpoint_type=endpoint_type) - self._clients['heat'] = heatclient.Client('1', endpoint, **args) - - return self._clients['heat'] + return heatclient.Client('1', endpoint, **args) class ClientBackend(object): diff --git a/heat/engine/parser.py b/heat/engine/parser.py index a60865084..f28e312c1 100644 --- a/heat/engine/parser.py +++ b/heat/engine/parser.py @@ -277,7 +277,8 @@ class Stack(collections.Mapping): # Create a context containing a trust_id and trustor_user_id # if trusts are enabled if cfg.CONF.deferred_auth_method == 'trusts': - trust_ctx = self.clients.keystone().create_trust_context() + keystone = self.clients.client('keystone') + trust_ctx = keystone.create_trust_context() new_creds = db_api.user_creds_create(trust_ctx) else: new_creds = db_api.user_creds_create(self.context) @@ -771,7 +772,8 @@ class Stack(collections.Mapping): trust_id = user_creds.get('trust_id') if trust_id: try: - self.clients.keystone().delete_trust(trust_id) + self.clients.client('keystone').delete_trust( + trust_id) except Exception as ex: LOG.exception(ex) stack_status = self.FAILED @@ -796,7 +798,8 @@ class Stack(collections.Mapping): # If the stack has a domain project, delete it if self.stack_user_project_id: try: - self.clients.keystone().delete_stack_domain_project( + keystone = self.clients.client('keystone') + keystone.delete_stack_domain_project( project_id=self.stack_user_project_id) except Exception as ex: LOG.exception(ex) @@ -897,10 +900,11 @@ class Stack(collections.Mapping): # restart the whole stack def get_availability_zones(self): + nova = self.clients.client('nova') if self._zones is None: self._zones = [ zone.zoneName for zone in - self.clients.nova().availability_zones.list(detailed=False)] + nova.availability_zones.list(detailed=False)] return self._zones def set_stack_user_project_id(self, project_id): diff --git a/heat/engine/resource.py b/heat/engine/resource.py index e2e6a48f9..257435bb0 100644 --- a/heat/engine/resource.py +++ b/heat/engine/resource.py @@ -93,6 +93,9 @@ class Resource(object): support_status = support.SupportStatus() + # Default name to use for calls to self.client() + default_client_name = None + def __new__(cls, name, definition, stack): '''Create a new Resource of the appropriate class for its type.''' @@ -336,32 +339,37 @@ class Resource(object): return list( [r.name for r in self.stack.dependencies.required_by(self)]) + def client(self, name=None): + client_name = name or self.default_client_name + assert client_name, "Must specify client name" + return self.stack.clients.client(client_name) + def keystone(self): - return self.stack.clients.keystone() + return self.client('keystone') def nova(self): - return self.stack.clients.nova() + return self.client('nova') def swift(self): - return self.stack.clients.swift() + return self.client('swift') def neutron(self): - return self.stack.clients.neutron() + return self.client('neutron') def cinder(self): - return self.stack.clients.cinder() + return self.client('cinder') def trove(self): - return self.stack.clients.trove() + return self.client('trove') def ceilometer(self): - return self.stack.clients.ceilometer() + return self.client('ceilometer') def heat(self): - return self.stack.clients.heat() + return self.client('heat') def glance(self): - return self.stack.clients.glance() + return self.client('glance') def _do_action(self, action, pre_func=None, resource_data=None): ''' diff --git a/heat/engine/resources/image.py b/heat/engine/resources/image.py index a804057ab..fa069d088 100644 --- a/heat/engine/resources/image.py +++ b/heat/engine/resources/image.py @@ -21,7 +21,7 @@ class ImageConstraint(constraints.BaseCustomConstraint): expected_exceptions = (exception.ImageNotFound,) def validate_with_client(self, client, value): - glance_client = client.glance() + glance_client = client.client('glance') glance_utils.get_image_id(glance_client, value) diff --git a/heat/engine/resources/neutron/net.py b/heat/engine/resources/neutron/net.py index 3b4220c59..74a7a64d2 100644 --- a/heat/engine/resources/neutron/net.py +++ b/heat/engine/resources/neutron/net.py @@ -189,7 +189,7 @@ class NetworkConstraint(constraints.BaseCustomConstraint): expected_exceptions = (neutron_exp.NeutronClientException,) def validate_with_client(self, client, value): - neutron_client = client.neutron() + neutron_client = client.client('neutron') neutronV20.find_resourceid_by_name_or_id( neutron_client, 'network', value) diff --git a/heat/engine/resources/nova_keypair.py b/heat/engine/resources/nova_keypair.py index b1bd24950..c92c8ac5b 100644 --- a/heat/engine/resources/nova_keypair.py +++ b/heat/engine/resources/nova_keypair.py @@ -138,7 +138,7 @@ class KeypairConstraint(constraints.BaseCustomConstraint): # Don't validate empty key, which can happen when you use a KeyPair # resource return True - nova_client = client.nova() + nova_client = client.client('nova') nova_utils.get_keypair(nova_client, value) diff --git a/heat/engine/resources/server.py b/heat/engine/resources/server.py index 8d006410c..579c1f3ab 100644 --- a/heat/engine/resources/server.py +++ b/heat/engine/resources/server.py @@ -1051,7 +1051,7 @@ class FlavorConstraint(constraints.BaseCustomConstraint): expected_exceptions = (exception.FlavorMissing,) def validate_with_client(self, client, value): - nova_client = client.nova() + nova_client = client.client('nova') nova_utils.get_flavor_id(nova_client, value) diff --git a/heat/engine/resources/volume.py b/heat/engine/resources/volume.py index c63873744..49f1a4fb4 100644 --- a/heat/engine/resources/volume.py +++ b/heat/engine/resources/volume.py @@ -250,7 +250,7 @@ class VolumeExtendTask(object): def __call__(self): LOG.debug(str(self)) - cinder = self.clients.cinder().volumes + cinder = self.clients.client('cinder').volumes vol = cinder.get(self.volume_id) try: @@ -307,14 +307,14 @@ class VolumeAttachTask(object): """Return a co-routine which runs the task.""" LOG.debug(str(self)) - va = self.clients.nova().volumes.create_server_volume( + va = self.clients.client('nova').volumes.create_server_volume( server_id=self.server_id, volume_id=self.volume_id, device=self.device) self.attachment_id = va.id yield - vol = self.clients.cinder().volumes.get(self.volume_id) + vol = self.clients.client('cinder').volumes.get(self.volume_id) while vol.status == 'available' or vol.status == 'attaching': LOG.debug('%(name)s - volume status: %(status)s' % {'name': str(self), 'status': vol.status}) @@ -354,13 +354,13 @@ class VolumeDetachTask(object): """Return a co-routine which runs the task.""" LOG.debug(str(self)) - server_api = self.clients.nova().volumes + server_api = self.clients.client('nova').volumes # get reference to the volume while it is attached try: nova_vol = server_api.get_server_volume(self.server_id, self.attachment_id) - vol = self.clients.cinder().volumes.get(nova_vol.id) + vol = self.clients.client('cinder').volumes.get(nova_vol.id) except (clients.cinderclient.exceptions.NotFound, clients.novaclient.exceptions.BadRequest, clients.novaclient.exceptions.NotFound): diff --git a/heat/tests/common.py b/heat/tests/common.py index 083e9db0a..ad3f0832c 100644 --- a/heat/tests/common.py +++ b/heat/tests/common.py @@ -115,7 +115,7 @@ class HeatTestCase(testscenarios.WithScenarios, return mockfixture.mock def stub_keystoneclient(self, **kwargs): - client = self.patchobject(clients.OpenStackClients, "keystone") + client = self.patchobject(clients.OpenStackClients, "_keystone") fkc = fakes.FakeKeystoneClient(**kwargs) client.return_value = fkc return fkc diff --git a/heat/tests/test_autoscaling_update_policy.py b/heat/tests/test_autoscaling_update_policy.py index fc2028f2c..934ef3deb 100644 --- a/heat/tests/test_autoscaling_update_policy.py +++ b/heat/tests/test_autoscaling_update_policy.py @@ -213,8 +213,8 @@ class AutoScalingGroupTest(HeatTestCase): def _mock_get_image_id_success(self, imageId_input, imageId, update_image=None): g_cli_mock = self.m.CreateMockAnything() - self.m.StubOutWithMock(clients.OpenStackClients, 'glance') - clients.OpenStackClients.glance().MultipleTimes().AndReturn( + self.m.StubOutWithMock(clients.OpenStackClients, '_glance') + clients.OpenStackClients._glance().MultipleTimes().AndReturn( g_cli_mock) self.m.StubOutWithMock(glance_utils, 'get_image_id') @@ -253,7 +253,7 @@ class AutoScalingGroupTest(HeatTestCase): """ self._stub_validate() - self.m.StubOutWithMock(clients.OpenStackClients, 'nova') + self.m.StubOutWithMock(clients.OpenStackClients, '_nova') self.m.StubOutWithMock(instance.Instance, 'handle_create') self.m.StubOutWithMock(instance.Instance, 'check_create_complete') @@ -262,7 +262,7 @@ class AutoScalingGroupTest(HeatTestCase): cookie = object() - clients.OpenStackClients.nova().MultipleTimes().AndReturn(self.fc) + clients.OpenStackClients._nova().MultipleTimes().AndReturn(self.fc) # for load balancer setup if setup_lb: self._stub_lb_create() @@ -289,13 +289,13 @@ class AutoScalingGroupTest(HeatTestCase): notification.send(mox.IgnoreArg()).MultipleTimes().AndReturn(None) # for instances in the group - self.m.StubOutWithMock(clients.OpenStackClients, 'nova') + self.m.StubOutWithMock(clients.OpenStackClients, '_nova') self.m.StubOutWithMock(instance.Instance, 'handle_create') self.m.StubOutWithMock(instance.Instance, 'check_create_complete') self.m.StubOutWithMock(instance.Instance, 'destroy') if num_reloads_expected_on_updt > 1: - clients.OpenStackClients.nova().MultipleTimes().AndReturn(self.fc) + clients.OpenStackClients._nova().MultipleTimes().AndReturn(self.fc) cookie = object() for i in range(num_creates_expected_on_updt): diff --git a/heat/tests/test_ceilometer_alarm.py b/heat/tests/test_ceilometer_alarm.py index 3772ef2fe..5489a1374 100644 --- a/heat/tests/test_ceilometer_alarm.py +++ b/heat/tests/test_ceilometer_alarm.py @@ -356,10 +356,10 @@ class CombinationAlarmTest(HeatTestCase): def setUp(self): super(CombinationAlarmTest, self).setUp() self.fc = FakeCeilometerClient() - self.m.StubOutWithMock(clients.OpenStackClients, 'ceilometer') + self.m.StubOutWithMock(clients.OpenStackClients, '_ceilometer') def create_alarm(self): - clients.OpenStackClients.ceilometer().MultipleTimes().AndReturn( + clients.OpenStackClients._ceilometer().AndReturn( self.fc) self.m.StubOutWithMock(self.fc.alarms, 'create') self.fc.alarms.create( diff --git a/heat/tests/test_clients.py b/heat/tests/test_clients.py index 6591f55b1..424d0c1f5 100644 --- a/heat/tests/test_clients.py +++ b/heat/tests/test_clients.py @@ -52,11 +52,11 @@ class ClientsTest(HeatTestCase): obj._get_heat_url.return_value = None obj.url_for = mock.Mock(name="url_for") obj.url_for.return_value = "url_from_keystone" - obj.heat() + obj.client('heat') self.assertEqual('url_from_keystone', mock_call.call_args[0][1]) obj._get_heat_url.return_value = "url_from_config" del(obj._clients['heat']) - obj.heat() + obj.client('heat') self.assertEqual('url_from_config', mock_call.call_args[0][1]) @mock.patch.object(heatclient, 'Client') @@ -71,8 +71,8 @@ class ClientsTest(HeatTestCase): obj._get_heat_url.return_value = None obj.url_for = mock.Mock(name="url_for") obj.url_for.return_value = "url_from_keystone" - self.assertIsNotNone(obj.heat()) - self.assertEqual('anewtoken', obj.keystone().auth_token) + self.assertIsNotNone(obj.client('heat')) + self.assertEqual('anewtoken', obj.client('keystone').auth_token) @mock.patch.object(heatclient, 'Client') def test_clients_heat_cached(self, mock_call): @@ -87,8 +87,8 @@ class ClientsTest(HeatTestCase): obj.url_for = mock.Mock(name="url_for") obj.url_for.return_value = "url_from_keystone" obj._heat = None - heat = obj.heat() - heat_cached = obj.heat() + heat = obj.client('heat') + heat_cached = obj.client('heat') self.assertEqual(heat, heat_cached) def test_clients_auth_token_update(self): @@ -100,7 +100,7 @@ class ClientsTest(HeatTestCase): con.password = 'verysecret' con.auth_token = None obj = clients.Clients(con) - self.assertIsNotNone(obj.heat()) + self.assertIsNotNone(obj.client('heat')) self.assertEqual('token1', obj.auth_token) fkc.auth_token = 'token2' self.assertEqual('token2', obj.auth_token) diff --git a/heat/tests/test_engine_service.py b/heat/tests/test_engine_service.py index 500eb7cb4..41836df5f 100644 --- a/heat/tests/test_engine_service.py +++ b/heat/tests/test_engine_service.py @@ -196,15 +196,15 @@ def get_stack(stack_name, ctx, template): def setup_keystone_mocks(mocks, stack): fkc = test_fakes.FakeKeystoneClient() - mocks.StubOutWithMock(stack.clients, 'keystone') - stack.clients.keystone().MultipleTimes().AndReturn(fkc) + mocks.StubOutWithMock(stack.clients, '_keystone') + stack.clients._keystone().MultipleTimes().AndReturn(fkc) def setup_mock_for_image_constraint(mocks, imageId_input, imageId_output=744): g_cli_mock = mocks.CreateMockAnything() - mocks.StubOutWithMock(clients.OpenStackClients, 'glance') - clients.OpenStackClients.glance().MultipleTimes().AndReturn( + mocks.StubOutWithMock(clients.OpenStackClients, '_glance') + clients.OpenStackClients._glance().MultipleTimes().AndReturn( g_cli_mock) mocks.StubOutWithMock(glance_utils, 'get_image_id') glance_utils.get_image_id(g_cli_mock, imageId_input).\ @@ -215,8 +215,8 @@ def setup_mocks(mocks, stack, mock_image_constraint=True): fc = fakes.FakeClient() mocks.StubOutWithMock(instances.Instance, 'nova') instances.Instance.nova().MultipleTimes().AndReturn(fc) - mocks.StubOutWithMock(clients.OpenStackClients, 'nova') - clients.OpenStackClients.nova().MultipleTimes().AndReturn(fc) + mocks.StubOutWithMock(clients.OpenStackClients, '_nova') + clients.OpenStackClients._nova().MultipleTimes().AndReturn(fc) instance = stack['WebServer'] if mock_image_constraint: setup_mock_for_image_constraint(mocks, diff --git a/heat/tests/test_instance.py b/heat/tests/test_instance.py index 76d29f32b..645608e98 100644 --- a/heat/tests/test_instance.py +++ b/heat/tests/test_instance.py @@ -80,8 +80,8 @@ class InstancesTest(HeatTestCase): def _mock_get_image_id_success(self, imageId_input, imageId): g_cli_mock = self.m.CreateMockAnything() - self.m.StubOutWithMock(clients.OpenStackClients, 'glance') - clients.OpenStackClients.glance().MultipleTimes().AndReturn( + self.m.StubOutWithMock(clients.OpenStackClients, '_glance') + clients.OpenStackClients._glance().MultipleTimes().AndReturn( g_cli_mock) self.m.StubOutWithMock(glance_utils, 'get_image_id') glance_utils.get_image_id(g_cli_mock, imageId_input).MultipleTimes().\ @@ -89,8 +89,8 @@ class InstancesTest(HeatTestCase): def _mock_get_image_id_fail(self, image_id, exp): g_cli_mock = self.m.CreateMockAnything() - self.m.StubOutWithMock(clients.OpenStackClients, 'glance') - clients.OpenStackClients.glance().MultipleTimes().AndReturn( + self.m.StubOutWithMock(clients.OpenStackClients, '_glance') + clients.OpenStackClients._glance().MultipleTimes().AndReturn( g_cli_mock) self.m.StubOutWithMock(glance_utils, 'get_image_id') glance_utils.get_image_id(g_cli_mock, image_id).AndRaise(exp) @@ -116,8 +116,8 @@ class InstancesTest(HeatTestCase): self.m.StubOutWithMock(instance, 'nova') instance.nova().MultipleTimes().AndReturn(self.fc) - self.m.StubOutWithMock(clients.OpenStackClients, 'nova') - clients.OpenStackClients.nova().MultipleTimes().AndReturn(self.fc) + self.m.StubOutWithMock(clients.OpenStackClients, '_nova') + clients.OpenStackClients._nova().MultipleTimes().AndReturn(self.fc) if stub_create: self.m.StubOutWithMock(self.fc.servers, 'create') @@ -314,8 +314,8 @@ class InstancesTest(HeatTestCase): instance = instances.Instance('instance_create_image', resource_defns['WebServer'], stack) - self.m.StubOutWithMock(clients.OpenStackClients, 'nova') - clients.OpenStackClients.nova().MultipleTimes().AndReturn(self.fc) + self.m.StubOutWithMock(clients.OpenStackClients, '_nova') + clients.OpenStackClients._nova().MultipleTimes().AndReturn(self.fc) self._mock_get_image_id_success('1', 1) self.m.ReplayAll() diff --git a/heat/tests/test_instance_network.py b/heat/tests/test_instance_network.py index a918fa8da..436298562 100644 --- a/heat/tests/test_instance_network.py +++ b/heat/tests/test_instance_network.py @@ -152,8 +152,8 @@ class instancesTest(HeatTestCase): def _mock_get_image_id_success(self, imageId_input, imageId): g_cli_mock = self.m.CreateMockAnything() - self.m.StubOutWithMock(clients.OpenStackClients, 'glance') - clients.OpenStackClients.glance().MultipleTimes().AndReturn( + self.m.StubOutWithMock(clients.OpenStackClients, '_glance') + clients.OpenStackClients._glance().MultipleTimes().AndReturn( g_cli_mock) self.m.StubOutWithMock(glance_utils, 'get_image_id') glance_utils.get_image_id(g_cli_mock, imageId_input).MultipleTimes().\ @@ -177,8 +177,8 @@ class instancesTest(HeatTestCase): self.m.StubOutWithMock(instance, 'nova') instance.nova().MultipleTimes().AndReturn(self.fc) - self.m.StubOutWithMock(clients.OpenStackClients, 'nova') - clients.OpenStackClients.nova().MultipleTimes().AndReturn(self.fc) + self.m.StubOutWithMock(clients.OpenStackClients, '_nova') + clients.OpenStackClients._nova().MultipleTimes().AndReturn(self.fc) self._mock_get_image_id_success(image_id, 1) @@ -237,8 +237,8 @@ class instancesTest(HeatTestCase): self.m.StubOutWithMock(instance, 'nova') instance.nova().MultipleTimes().AndReturn(self.fc) - self.m.StubOutWithMock(clients.OpenStackClients, 'nova') - clients.OpenStackClients.nova().MultipleTimes().AndReturn(self.fc) + self.m.StubOutWithMock(clients.OpenStackClients, '_nova') + clients.OpenStackClients._nova().MultipleTimes().AndReturn(self.fc) # need to resolve the template functions server_userdata = nova_utils.build_userdata( diff --git a/heat/tests/test_loadbalancer.py b/heat/tests/test_loadbalancer.py index b977e8afd..e735b2e18 100644 --- a/heat/tests/test_loadbalancer.py +++ b/heat/tests/test_loadbalancer.py @@ -104,7 +104,7 @@ class LoadBalancerTest(HeatTestCase): def setUp(self): super(LoadBalancerTest, self).setUp() self.fc = fakes.FakeClient() - self.m.StubOutWithMock(clients.OpenStackClients, 'nova') + self.m.StubOutWithMock(clients.OpenStackClients, '_nova') self.m.StubOutWithMock(self.fc.servers, 'create') self.m.StubOutWithMock(resource.Resource, 'metadata_set') self.stub_keystoneclient(username='test_stack.CfnLBUser') @@ -124,8 +124,8 @@ class LoadBalancerTest(HeatTestCase): def _mock_get_image_id_success(self, imageId_input, imageId): g_cli_mock = self.m.CreateMockAnything() - self.m.StubOutWithMock(clients.OpenStackClients, 'glance') - clients.OpenStackClients.glance().MultipleTimes().AndReturn( + self.m.StubOutWithMock(clients.OpenStackClients, '_glance') + clients.OpenStackClients._glance().MultipleTimes().AndReturn( g_cli_mock) self.m.StubOutWithMock(glance_utils, 'get_image_id') glance_utils.get_image_id(g_cli_mock, imageId_input).\ @@ -136,7 +136,7 @@ class LoadBalancerTest(HeatTestCase): utils.PhysName('test_stack', 'LoadBalancer'), 'LB_instance', limit=instance.Instance.physical_resource_name_limit) - clients.OpenStackClients.nova().MultipleTimes().AndReturn(self.fc) + clients.OpenStackClients._nova().MultipleTimes().AndReturn(self.fc) self.fc.servers.create( flavor=2, image=746, key_name=key_name, meta=None, nics=None, name=server_name, diff --git a/heat/tests/test_neutron.py b/heat/tests/test_neutron.py index 5337dd7f3..f8c3e427e 100644 --- a/heat/tests/test_neutron.py +++ b/heat/tests/test_neutron.py @@ -2384,8 +2384,8 @@ class NeutronPortTest(HeatTestCase): class NetworkConstraintTest(HeatTestCase): def test_validate(self): - self.m.StubOutWithMock(clients.OpenStackClients, 'neutron') - clients.OpenStackClients.neutron().MultipleTimes().AndReturn(None) + self.m.StubOutWithMock(clients.OpenStackClients, '_neutron') + clients.OpenStackClients._neutron().MultipleTimes().AndReturn(None) self.m.StubOutWithMock(net.neutronV20, 'find_resourceid_by_name_or_id') net.neutronV20.find_resourceid_by_name_or_id( None, 'network', 'foo' diff --git a/heat/tests/test_neutron_loadbalancer.py b/heat/tests/test_neutron_loadbalancer.py index 92f7e4584..911cb5f26 100644 --- a/heat/tests/test_neutron_loadbalancer.py +++ b/heat/tests/test_neutron_loadbalancer.py @@ -955,10 +955,10 @@ class LoadBalancerTest(HeatTestCase): self.m.StubOutWithMock(neutronclient.Client, 'create_member') self.m.StubOutWithMock(neutronclient.Client, 'delete_member') self.stub_keystoneclient() - self.m.StubOutWithMock(clients.OpenStackClients, 'nova') + self.m.StubOutWithMock(clients.OpenStackClients, '_nova') def create_load_balancer(self): - clients.OpenStackClients.nova().MultipleTimes().AndReturn(self.fc) + clients.OpenStackClients._nova().AndReturn(self.fc) neutronclient.Client.create_member({ 'member': { 'pool_id': 'pool123', 'protocol_port': 8080, diff --git a/heat/tests/test_neutron_security_group.py b/heat/tests/test_neutron_security_group.py index ebe5a3fed..12518b34a 100644 --- a/heat/tests/test_neutron_security_group.py +++ b/heat/tests/test_neutron_security_group.py @@ -18,7 +18,6 @@ from novaclient.v1_1 import security_groups as nova_sg from heat.common import exception from heat.common import template_format -from heat.engine import clients from heat.engine import parser from heat.engine import scheduler from heat.tests.common import HeatTestCase @@ -86,7 +85,6 @@ Resources: def setUp(self): super(SecurityGroupTest, self).setUp() self.fc = fakes.FakeClient() - self.m.StubOutWithMock(clients.OpenStackClients, 'nova') self.stub_keystoneclient() self.m.StubOutWithMock(nova_sgr.SecurityGroupRuleManager, 'create') self.m.StubOutWithMock(nova_sgr.SecurityGroupRuleManager, 'delete') diff --git a/heat/tests/test_nokey.py b/heat/tests/test_nokey.py index f72dc60a0..2a97acf84 100644 --- a/heat/tests/test_nokey.py +++ b/heat/tests/test_nokey.py @@ -62,8 +62,8 @@ class nokeyTest(HeatTestCase): self.m.StubOutWithMock(instance, 'nova') instance.nova().MultipleTimes().AndReturn(self.fc) g_cli_mock = self.m.CreateMockAnything() - self.m.StubOutWithMock(clients.OpenStackClients, 'glance') - clients.OpenStackClients.glance().MultipleTimes().AndReturn( + self.m.StubOutWithMock(clients.OpenStackClients, '_glance') + clients.OpenStackClients._glance().MultipleTimes().AndReturn( g_cli_mock) self.m.StubOutWithMock(glance_utils, 'get_image_id') glance_utils.get_image_id(g_cli_mock, 'CentOS 5.2').MultipleTimes().\ diff --git a/heat/tests/test_nova_floatingip.py b/heat/tests/test_nova_floatingip.py index e47b3995a..b3f9c69b3 100644 --- a/heat/tests/test_nova_floatingip.py +++ b/heat/tests/test_nova_floatingip.py @@ -63,7 +63,7 @@ class NovaFloatingIPTest(HeatTestCase): super(NovaFloatingIPTest, self).setUp() self.novaclient = novaclient.Client('user', 'pass', 'project', 'uri') - self.m.StubOutWithMock(clients.OpenStackClients, 'nova') + self.m.StubOutWithMock(clients.OpenStackClients, '_nova') self.m.StubOutWithMock(self.novaclient.floating_ips, 'create') self.m.StubOutWithMock(self.novaclient.floating_ips, 'get') self.m.StubOutWithMock(self.novaclient.floating_ips, 'delete') @@ -79,7 +79,7 @@ class NovaFloatingIPTest(HeatTestCase): return mock def prepare_floating_ip(self): - clients.OpenStackClients.nova().AndReturn(self.novaclient) + clients.OpenStackClients._nova().AndReturn(self.novaclient) self.novaclient.floating_ips.create(pool='public').AndReturn( self._make_obj(**{ 'id': '1', @@ -95,7 +95,7 @@ class NovaFloatingIPTest(HeatTestCase): return NovaFloatingIp('MyFloatingIP', floating_ip, stack) def prepare_floating_ip_assoc(self): - clients.OpenStackClients.nova().MultipleTimes().AndReturn( + clients.OpenStackClients._nova().AndReturn( self.novaclient) self.novaclient.servers.get('67dc62f9-efde-4c8b-94af-013e00f5dc57') self.novaclient.floating_ips.get('1').AndReturn( @@ -132,7 +132,6 @@ class NovaFloatingIPTest(HeatTestCase): rsrc = self.prepare_floating_ip() rsrc.validate() - clients.OpenStackClients.nova().AndReturn(self.novaclient) self.novaclient.floating_ips.delete('1') self.m.ReplayAll() diff --git a/heat/tests/test_nova_keypair.py b/heat/tests/test_nova_keypair.py index b6da92037..7c8204a5d 100644 --- a/heat/tests/test_nova_keypair.py +++ b/heat/tests/test_nova_keypair.py @@ -152,8 +152,8 @@ class KeypairConstraintTest(HeatTestCase): def test_validation(self): client = fakes.FakeClient() - self.m.StubOutWithMock(clients.OpenStackClients, 'nova') - clients.OpenStackClients.nova().MultipleTimes().AndReturn(client) + self.m.StubOutWithMock(clients.OpenStackClients, '_nova') + clients.OpenStackClients._nova().MultipleTimes().AndReturn(client) client.keypairs = self.m.CreateMockAnything() key = collections.namedtuple("Key", ["name"]) diff --git a/heat/tests/test_parser.py b/heat/tests/test_parser.py index 6742427c8..a16ef5759 100644 --- a/heat/tests/test_parser.py +++ b/heat/tests/test_parser.py @@ -466,9 +466,9 @@ Mappings: snippet = {"Fn::GetAZs": ""} stack = parser.Stack(self.ctx, 'test_stack', parser.Template(empty_template)) - self.m.StubOutWithMock(clients.OpenStackClients, 'nova') + self.m.StubOutWithMock(clients.OpenStackClients, '_nova') fc = fakes.FakeClient() - clients.OpenStackClients.nova().MultipleTimes().AndReturn(fc) + clients.OpenStackClients._nova().MultipleTimes().AndReturn(fc) self.m.ReplayAll() self.assertEqual(["nova1"], self.resolve(snippet, tmpl, stack)) @@ -1346,8 +1346,8 @@ class StackTest(HeatTestCase): def delete_trust(self, trust_id): raise Exception("Shouldn't delete") - self.m.StubOutWithMock(clients.OpenStackClients, 'keystone') - clients.OpenStackClients.keystone().MultipleTimes().AndReturn( + self.m.StubOutWithMock(clients.OpenStackClients, '_keystone') + clients.OpenStackClients._keystone().MultipleTimes().AndReturn( FakeKeystoneClientFail()) self.m.ReplayAll() @@ -1372,8 +1372,8 @@ class StackTest(HeatTestCase): def delete_trust(self, trust_id): raise kc_exceptions.Forbidden("Denied!") - self.m.StubOutWithMock(clients.OpenStackClients, 'keystone') - clients.OpenStackClients.keystone().MultipleTimes().AndReturn( + self.m.StubOutWithMock(clients.OpenStackClients, '_keystone') + clients.OpenStackClients._keystone().MultipleTimes().AndReturn( FakeKeystoneClientFail()) self.m.ReplayAll() @@ -2959,8 +2959,8 @@ class StackTest(HeatTestCase): """ cfg.CONF.set_override('deferred_auth_method', 'trusts') - self.m.StubOutWithMock(clients.OpenStackClients, 'keystone') - clients.OpenStackClients.keystone().MultipleTimes().AndReturn( + self.m.StubOutWithMock(clients.OpenStackClients, '_keystone') + clients.OpenStackClients._keystone().MultipleTimes().AndReturn( FakeKeystoneClient()) self.m.ReplayAll() @@ -3118,8 +3118,9 @@ class StackTest(HeatTestCase): def delete_stack_domain_project(self, project_id): raise kc_exceptions.Forbidden("Denied!") - self.m.StubOutWithMock(clients.OpenStackClients, 'keystone') - clients.OpenStackClients.keystone().AndReturn(FakeKeystoneClientFail()) + self.m.StubOutWithMock(clients.OpenStackClients, '_keystone') + clients.OpenStackClients._keystone().AndReturn( + FakeKeystoneClientFail()) self.m.ReplayAll() self.stack = parser.Stack(self.ctx, 'user_project_init', @@ -3245,8 +3246,8 @@ class StackTest(HeatTestCase): # Mock objects so the query for flavors in server.FlavorConstraint # works for stack creation fc = fakes.FakeClient() - self.m.StubOutWithMock(clients.OpenStackClients, 'nova') - clients.OpenStackClients.nova().MultipleTimes().AndReturn(fc) + self.m.StubOutWithMock(clients.OpenStackClients, '_nova') + clients.OpenStackClients._nova().MultipleTimes().AndReturn(fc) fc.flavors = self.m.CreateMockAnything() flavor = collections.namedtuple("Flavor", ["id", "name"]) diff --git a/heat/tests/test_security_group.py b/heat/tests/test_security_group.py index c5f6db8ed..7f6ee50b8 100644 --- a/heat/tests/test_security_group.py +++ b/heat/tests/test_security_group.py @@ -127,7 +127,7 @@ Resources: def setUp(self): super(SecurityGroupTest, self).setUp() self.fc = fakes.FakeClient() - self.m.StubOutWithMock(clients.OpenStackClients, 'nova') + self.m.StubOutWithMock(clients.OpenStackClients, '_nova') self.stub_keystoneclient() self.m.StubOutWithMock(nova_sgr.SecurityGroupRuleManager, 'create') self.m.StubOutWithMock(nova_sgr.SecurityGroupRuleManager, 'delete') @@ -165,14 +165,13 @@ Resources: def test_security_group_nova(self): #create script - clients.OpenStackClients.nova().AndReturn(self.fc) + clients.OpenStackClients._nova().AndReturn(self.fc) nova_sg.SecurityGroupManager.list().AndReturn([NovaSG( id=1, name='test', description='FAKE_SECURITY_GROUP', rules=[], )]) - clients.OpenStackClients.nova().AndReturn(self.fc) sg_name = utils.PhysName('test_stack', 'the_sg') nova_sg.SecurityGroupManager.create( sg_name, @@ -182,7 +181,6 @@ Resources: description='HTTP and SSH access', rules=[])) - clients.OpenStackClients.nova().AndReturn(self.fc) nova_sgr.SecurityGroupRuleManager.create( 2, 'tcp', '22', '22', '0.0.0.0/0', None).AndReturn(None) nova_sgr.SecurityGroupRuleManager.create( @@ -193,7 +191,6 @@ Resources: 2, 'icmp', None, None, None, '1').AndReturn(None) # delete script - clients.OpenStackClients.nova().AndReturn(self.fc) nova_sg.SecurityGroupManager.get(2).AndReturn(NovaSG( id=2, name=sg_name, @@ -242,15 +239,10 @@ Resources: 'id': 133 }] )) - clients.OpenStackClients.nova().AndReturn(self.fc) nova_sgr.SecurityGroupRuleManager.delete(130).AndReturn(None) - clients.OpenStackClients.nova().AndReturn(self.fc) nova_sgr.SecurityGroupRuleManager.delete(131).AndReturn(None) - clients.OpenStackClients.nova().AndReturn(self.fc) nova_sgr.SecurityGroupRuleManager.delete(132).AndReturn(None) - clients.OpenStackClients.nova().AndReturn(self.fc) nova_sgr.SecurityGroupRuleManager.delete(133).AndReturn(None) - clients.OpenStackClients.nova().AndReturn(self.fc) nova_sg.SecurityGroupManager.delete(2).AndReturn(None) self.m.ReplayAll() @@ -265,14 +257,13 @@ Resources: def test_security_group_nova_bad_source_group(self): #create script - clients.OpenStackClients.nova().AndReturn(self.fc) + clients.OpenStackClients._nova().AndReturn(self.fc) nova_sg.SecurityGroupManager.list().AndReturn([NovaSG( id=1, name='test', description='FAKE_SECURITY_GROUP', rules=[], )]) - clients.OpenStackClients.nova().AndReturn(self.fc) sg_name = utils.PhysName('test_stack', 'the_sg') nova_sg.SecurityGroupManager.create( sg_name, @@ -282,14 +273,12 @@ Resources: description='HTTP and SSH access', rules=[])) - clients.OpenStackClients.nova().AndReturn(self.fc) nova_sgr.SecurityGroupRuleManager.create( 2, 'tcp', '22', '22', '0.0.0.0/0', None).AndReturn(None) nova_sgr.SecurityGroupRuleManager.create( 2, 'tcp', '80', '80', '0.0.0.0/0', None).AndReturn(None) # delete script - clients.OpenStackClients.nova().AndReturn(self.fc) nova_sg.SecurityGroupManager.get(2).AndReturn(NovaSG( id=2, name=sg_name, @@ -316,11 +305,8 @@ Resources: 'id': 131 }] )) - clients.OpenStackClients.nova().AndReturn(self.fc) nova_sgr.SecurityGroupRuleManager.delete(130).AndReturn(None) - clients.OpenStackClients.nova().AndReturn(self.fc) nova_sgr.SecurityGroupRuleManager.delete(131).AndReturn(None) - clients.OpenStackClients.nova().AndReturn(self.fc) nova_sg.SecurityGroupManager.delete(2).AndReturn(None) self.m.ReplayAll() @@ -335,7 +321,7 @@ Resources: def test_security_group_nova_exception(self): #create script - clients.OpenStackClients.nova().AndReturn(self.fc) + clients.OpenStackClients._nova().AndReturn(self.fc) sg_name = utils.PhysName('test_stack', 'the_sg') nova_sg.SecurityGroupManager.list().AndReturn([ NovaSG( @@ -352,7 +338,6 @@ Resources: ) ]) - clients.OpenStackClients.nova().AndReturn(self.fc) nova_sgr.SecurityGroupRuleManager.create( 2, 'tcp', '22', '22', '0.0.0.0/0', None).AndRaise( clients.novaclient.exceptions.BadRequest( @@ -371,7 +356,6 @@ Resources: 400, 'Rule already exists')) # delete script - clients.OpenStackClients.nova().AndReturn(self.fc) nova_sg.SecurityGroupManager.get(2).AndReturn(NovaSG( id=2, name=sg_name, @@ -420,22 +404,16 @@ Resources: 'id': 133 }] )) - clients.OpenStackClients.nova().AndReturn(self.fc) nova_sgr.SecurityGroupRuleManager.delete(130).AndRaise( clients.novaclient.exceptions.NotFound('goneburger')) - clients.OpenStackClients.nova().AndReturn(self.fc) nova_sgr.SecurityGroupRuleManager.delete(131).AndRaise( clients.novaclient.exceptions.NotFound('goneburger')) - clients.OpenStackClients.nova().AndReturn(self.fc) nova_sgr.SecurityGroupRuleManager.delete(132).AndRaise( clients.novaclient.exceptions.NotFound('goneburger')) - clients.OpenStackClients.nova().AndReturn(self.fc) nova_sgr.SecurityGroupRuleManager.delete(133).AndRaise( clients.novaclient.exceptions.NotFound('goneburger')) - clients.OpenStackClients.nova().AndReturn(self.fc) nova_sg.SecurityGroupManager.delete(2).AndReturn(None) - clients.OpenStackClients.nova().AndReturn(self.fc) nova_sg.SecurityGroupManager.get(2).AndRaise( clients.novaclient.exceptions.NotFound('goneburger')) diff --git a/heat/tests/test_server.py b/heat/tests/test_server.py index e4c6a4880..0189243e2 100644 --- a/heat/tests/test_server.py +++ b/heat/tests/test_server.py @@ -126,8 +126,8 @@ class ServersTest(HeatTestCase): self.m.StubOutWithMock(server, 'nova') server.nova().MultipleTimes().AndReturn(self.fc) - self.m.StubOutWithMock(clients.OpenStackClients, 'nova') - clients.OpenStackClients.nova().MultipleTimes().AndReturn(self.fc) + self.m.StubOutWithMock(clients.OpenStackClients, '_nova') + clients.OpenStackClients._nova().MultipleTimes().AndReturn(self.fc) if stub_create: self.m.StubOutWithMock(self.fc.servers, 'create') @@ -165,8 +165,8 @@ class ServersTest(HeatTestCase): def _mock_get_image_id_success(self, imageId_input, imageId, server_rebuild=False): g_cli_mock = self.m.CreateMockAnything() - self.m.StubOutWithMock(clients.OpenStackClients, 'glance') - clients.OpenStackClients.glance().MultipleTimes().AndReturn( + self.m.StubOutWithMock(clients.OpenStackClients, '_glance') + clients.OpenStackClients._glance().MultipleTimes().AndReturn( g_cli_mock) self.m.StubOutWithMock(glance_utils, 'get_image_id') glance_utils.get_image_id(g_cli_mock, imageId_input).MultipleTimes().\ @@ -178,16 +178,16 @@ class ServersTest(HeatTestCase): def _mock_get_image_id_fail(self, image_id, exp): g_cli_mock = self.m.CreateMockAnything() - self.m.StubOutWithMock(clients.OpenStackClients, 'glance') - clients.OpenStackClients.glance().MultipleTimes().AndReturn( + self.m.StubOutWithMock(clients.OpenStackClients, '_glance') + clients.OpenStackClients._glance().MultipleTimes().AndReturn( g_cli_mock) self.m.StubOutWithMock(glance_utils, 'get_image_id') glance_utils.get_image_id(g_cli_mock, image_id).AndRaise(exp) def _mock_get_keypair_success(self, keypair_input, keypair): n_cli_mock = self.m.CreateMockAnything() - self.m.StubOutWithMock(clients.OpenStackClients, 'nova') - clients.OpenStackClients.nova().MultipleTimes().AndReturn( + self.m.StubOutWithMock(clients.OpenStackClients, '_nova') + clients.OpenStackClients._nova().MultipleTimes().AndReturn( n_cli_mock) self.m.StubOutWithMock(nova_utils, 'get_keypair') nova_utils.get_keypair(n_cli_mock, keypair_input).MultipleTimes().\ @@ -196,8 +196,8 @@ class ServersTest(HeatTestCase): def _server_validate_mock(self, server): self.m.StubOutWithMock(server, 'nova') server.nova().MultipleTimes().AndReturn(self.fc) - self.m.StubOutWithMock(clients.OpenStackClients, 'nova') - clients.OpenStackClients.nova().MultipleTimes().AndReturn(self.fc) + self.m.StubOutWithMock(clients.OpenStackClients, '_nova') + clients.OpenStackClients._nova().MultipleTimes().AndReturn(self.fc) self._mock_get_image_id_success('F17-x86_64-gold', 'image_id') def test_server_create(self): @@ -278,8 +278,8 @@ class ServersTest(HeatTestCase): self.m.StubOutWithMock(server, 'nova') server.nova().MultipleTimes().AndReturn(self.fc) - self.m.StubOutWithMock(clients.OpenStackClients, 'nova') - clients.OpenStackClients.nova().MultipleTimes().AndReturn(self.fc) + self.m.StubOutWithMock(clients.OpenStackClients, '_nova') + clients.OpenStackClients._nova().MultipleTimes().AndReturn(self.fc) self._mock_get_image_id_success('F17-x86_64-gold', image_id) self.m.ReplayAll() @@ -457,8 +457,8 @@ class ServersTest(HeatTestCase): self.m.StubOutWithMock(server, 'nova') server.nova().MultipleTimes().AndReturn(self.fc) - self.m.StubOutWithMock(clients.OpenStackClients, 'nova') - clients.OpenStackClients.nova().MultipleTimes().AndReturn(self.fc) + self.m.StubOutWithMock(clients.OpenStackClients, '_nova') + clients.OpenStackClients._nova().MultipleTimes().AndReturn(self.fc) self._mock_get_image_id_success('F17-x86_64-gold', 744) self.m.StubOutWithMock(self.fc.servers, 'create') @@ -500,8 +500,8 @@ class ServersTest(HeatTestCase): 'wordpress from config') server.nova().MultipleTimes().AndReturn(self.fc) - self.m.StubOutWithMock(clients.OpenStackClients, 'nova') - clients.OpenStackClients.nova().MultipleTimes().AndReturn(self.fc) + self.m.StubOutWithMock(clients.OpenStackClients, '_nova') + clients.OpenStackClients._nova().MultipleTimes().AndReturn(self.fc) self._mock_get_image_id_success('F17-x86_64-gold', 744) self.m.StubOutWithMock(self.fc.servers, 'create') @@ -543,8 +543,8 @@ class ServersTest(HeatTestCase): software_config_id=sc_id)) server.nova().MultipleTimes().AndReturn(self.fc) - self.m.StubOutWithMock(clients.OpenStackClients, 'nova') - clients.OpenStackClients.nova().MultipleTimes().AndReturn(self.fc) + self.m.StubOutWithMock(clients.OpenStackClients, '_nova') + clients.OpenStackClients._nova().MultipleTimes().AndReturn(self.fc) self._mock_get_image_id_success('F17-x86_64-gold', 744) self.m.StubOutWithMock(self.fc.servers, 'create') @@ -580,8 +580,8 @@ class ServersTest(HeatTestCase): self.m.StubOutWithMock(server, 'heat') server.nova().MultipleTimes().AndReturn(self.fc) - self.m.StubOutWithMock(clients.OpenStackClients, 'nova') - clients.OpenStackClients.nova().MultipleTimes().AndReturn(self.fc) + self.m.StubOutWithMock(clients.OpenStackClients, '_nova') + clients.OpenStackClients._nova().MultipleTimes().AndReturn(self.fc) self._mock_get_image_id_success('F17-x86_64-gold', 744) self.m.StubOutWithMock(self.fc.servers, 'create') @@ -644,8 +644,8 @@ class ServersTest(HeatTestCase): self.m.StubOutWithMock(server, 'nova') server.nova().MultipleTimes().AndReturn(self.fc) - self.m.StubOutWithMock(clients.OpenStackClients, 'nova') - clients.OpenStackClients.nova().MultipleTimes().AndReturn(self.fc) + self.m.StubOutWithMock(clients.OpenStackClients, '_nova') + clients.OpenStackClients._nova().MultipleTimes().AndReturn(self.fc) self._mock_get_image_id_success('F17-x86_64-gold', 744) self.m.StubOutWithMock(self.fc.servers, 'create') @@ -693,7 +693,7 @@ class ServersTest(HeatTestCase): self.m.VerifyAll() - @mock.patch.object(clients.OpenStackClients, 'nova') + @mock.patch.object(clients.OpenStackClients, '_nova') def test_server_create_default_admin_pass(self, mock_nova): return_server = self.fc.servers.list()[1] return_server.adminPass = 'autogenerated' @@ -719,7 +719,7 @@ class ServersTest(HeatTestCase): disk_config=None, reservation_id=None, files={}, admin_pass=None) - @mock.patch.object(clients.OpenStackClients, 'nova') + @mock.patch.object(clients.OpenStackClients, '_nova') def test_server_create_custom_admin_pass(self, mock_nova): return_server = self.fc.servers.list()[1] return_server.adminPass = 'foo' @@ -764,8 +764,8 @@ class ServersTest(HeatTestCase): server = servers.Server('server_create_image', resource_defns['WebServer'], stack) - self.m.StubOutWithMock(clients.OpenStackClients, 'nova') - clients.OpenStackClients.nova().MultipleTimes().AndReturn(self.fc) + self.m.StubOutWithMock(clients.OpenStackClients, '_nova') + clients.OpenStackClients._nova().MultipleTimes().AndReturn(self.fc) self._mock_get_image_id_success('1', 1) self.m.ReplayAll() @@ -795,8 +795,8 @@ class ServersTest(HeatTestCase): if mock_nova: self.m.StubOutWithMock(server, 'nova') server.nova().MultipleTimes().AndReturn(self.fc) - self.m.StubOutWithMock(clients.OpenStackClients, 'nova') - clients.OpenStackClients.nova().MultipleTimes().AndReturn(self.fc) + self.m.StubOutWithMock(clients.OpenStackClients, '_nova') + clients.OpenStackClients._nova().MultipleTimes().AndReturn(self.fc) self.m.ReplayAll() return server @@ -869,8 +869,8 @@ class ServersTest(HeatTestCase): server = servers.Server('WebServer', resource_defns['WebServer'], stack) - self.m.StubOutWithMock(clients.OpenStackClients, 'nova') - clients.OpenStackClients.nova().MultipleTimes().AndReturn(self.fc) + self.m.StubOutWithMock(clients.OpenStackClients, '_nova') + clients.OpenStackClients._nova().MultipleTimes().AndReturn(self.fc) self.m.ReplayAll() error = self.assertRaises(exception.StackValidationFailed, @@ -895,8 +895,8 @@ class ServersTest(HeatTestCase): server = servers.Server('server_validate_with_networks', resource_defns['WebServer'], stack) - self.m.StubOutWithMock(clients.OpenStackClients, 'nova') - clients.OpenStackClients.nova().MultipleTimes().AndReturn(self.fc) + self.m.StubOutWithMock(clients.OpenStackClients, '_nova') + clients.OpenStackClients._nova().MultipleTimes().AndReturn(self.fc) self._mock_get_image_id_success('F17-x86_64-gold', 'image_id') self.m.ReplayAll() @@ -928,8 +928,8 @@ class ServersTest(HeatTestCase): self.m.StubOutWithMock(server, 'nova') server.nova().MultipleTimes().AndReturn(self.fc) - self.m.StubOutWithMock(clients.OpenStackClients, 'nova') - clients.OpenStackClients.nova().MultipleTimes().AndReturn(self.fc) + self.m.StubOutWithMock(clients.OpenStackClients, '_nova') + clients.OpenStackClients._nova().MultipleTimes().AndReturn(self.fc) self._mock_get_image_id_success('F17-x86_64-gold', 'image_id') self.m.ReplayAll() @@ -1068,8 +1068,8 @@ class ServersTest(HeatTestCase): # part two change the metadata (test removing the old key) self.m.StubOutWithMock(server, 'nova') server.nova().MultipleTimes().AndReturn(self.fc) - self.m.StubOutWithMock(clients.OpenStackClients, 'nova') - clients.OpenStackClients.nova().MultipleTimes().AndReturn(self.fc) + self.m.StubOutWithMock(clients.OpenStackClients, '_nova') + clients.OpenStackClients._nova().MultipleTimes().AndReturn(self.fc) self.m.ReplayAll() new_meta = {'new_key': 'yeah'} @@ -1182,8 +1182,8 @@ class ServersTest(HeatTestCase): def test_server_update_server_flavor_replace(self): stack_name = 'update_flvrep' (tmpl, stack) = self._setup_test_stack(stack_name) - self.m.StubOutWithMock(clients.OpenStackClients, 'nova') - clients.OpenStackClients.nova().MultipleTimes().AndReturn(self.fc) + self.m.StubOutWithMock(clients.OpenStackClients, '_nova') + clients.OpenStackClients._nova().MultipleTimes().AndReturn(self.fc) self._mock_get_image_id_success('F17-x86_64-gold', 'image_id') self.m.ReplayAll() @@ -1201,8 +1201,8 @@ class ServersTest(HeatTestCase): def test_server_update_server_flavor_policy_update(self): stack_name = 'update_flvpol' (tmpl, stack) = self._setup_test_stack(stack_name) - self.m.StubOutWithMock(clients.OpenStackClients, 'nova') - clients.OpenStackClients.nova().MultipleTimes().AndReturn(self.fc) + self.m.StubOutWithMock(clients.OpenStackClients, '_nova') + clients.OpenStackClients._nova().MultipleTimes().AndReturn(self.fc) self._mock_get_image_id_success('F17-x86_64-gold', 'image_id') self.m.ReplayAll() @@ -1229,8 +1229,8 @@ class ServersTest(HeatTestCase): server = servers.Server('server_update_image_replace', resource_defns['WebServer'], stack) image_id = self.getUniqueString() - self.m.StubOutWithMock(clients.OpenStackClients, 'nova') - clients.OpenStackClients.nova().MultipleTimes().AndReturn(self.fc) + self.m.StubOutWithMock(clients.OpenStackClients, '_nova') + clients.OpenStackClients._nova().MultipleTimes().AndReturn(self.fc) self.m.StubOutWithMock(image.ImageConstraint, "validate") image.ImageConstraint.validate( mox.IgnoreArg(), mox.IgnoreArg()).MultipleTimes().AndReturn(True) @@ -1762,8 +1762,8 @@ class ServersTest(HeatTestCase): resource_defns = tmpl.resource_definitions(stack) server = servers.Server('server_create_image_err', resource_defns['WebServer'], stack) - self.m.StubOutWithMock(clients.OpenStackClients, 'nova') - clients.OpenStackClients.nova().MultipleTimes().AndReturn(self.fc) + self.m.StubOutWithMock(clients.OpenStackClients, '_nova') + clients.OpenStackClients._nova().MultipleTimes().AndReturn(self.fc) self._mock_get_image_id_success('F17-x86_64-gold', 'image_id') self.m.ReplayAll() @@ -1781,8 +1781,8 @@ class ServersTest(HeatTestCase): resource_defns = tmpl.resource_definitions(stack) server = servers.Server('server_create_image_err', resource_defns['WebServer'], stack) - self.m.StubOutWithMock(clients.OpenStackClients, 'nova') - clients.OpenStackClients.nova().MultipleTimes().AndReturn(self.fc) + self.m.StubOutWithMock(clients.OpenStackClients, '_nova') + clients.OpenStackClients._nova().MultipleTimes().AndReturn(self.fc) self._mock_get_image_id_success('F17-x86_64-gold', 'image_id') self.m.ReplayAll() @@ -1805,8 +1805,8 @@ class ServersTest(HeatTestCase): resource_defns = tmpl.resource_definitions(stack) server = servers.Server('server_create_image_err', resource_defns['WebServer'], stack) - self.m.StubOutWithMock(clients.OpenStackClients, 'nova') - clients.OpenStackClients.nova().MultipleTimes().AndReturn(self.fc) + self.m.StubOutWithMock(clients.OpenStackClients, '_nova') + clients.OpenStackClients._nova().MultipleTimes().AndReturn(self.fc) self.m.ReplayAll() ex = self.assertRaises(exception.StackValidationFailed, @@ -1834,8 +1834,8 @@ class ServersTest(HeatTestCase): self.m.StubOutWithMock(server, 'nova') server.nova().MultipleTimes().AndReturn(self.fc) - self.m.StubOutWithMock(clients.OpenStackClients, 'nova') - clients.OpenStackClients.nova().MultipleTimes().AndReturn(self.fc) + self.m.StubOutWithMock(clients.OpenStackClients, '_nova') + clients.OpenStackClients._nova().MultipleTimes().AndReturn(self.fc) self._mock_get_image_id_success('F17-x86_64-gold', 'image_id') self.m.ReplayAll() @@ -1861,8 +1861,8 @@ class ServersTest(HeatTestCase): self.m.StubOutWithMock(server, 'nova') server.nova().MultipleTimes().AndReturn(self.fc) - self.m.StubOutWithMock(clients.OpenStackClients, 'nova') - clients.OpenStackClients.nova().MultipleTimes().AndReturn(self.fc) + self.m.StubOutWithMock(clients.OpenStackClients, '_nova') + clients.OpenStackClients._nova().MultipleTimes().AndReturn(self.fc) self._mock_get_image_id_success('F17-x86_64-gold', 'image_id') self.m.ReplayAll() self.assertIsNone(server.validate()) @@ -1888,8 +1888,8 @@ class ServersTest(HeatTestCase): self.m.StubOutWithMock(server, 'nova') server.nova().MultipleTimes().AndReturn(self.fc) - self.m.StubOutWithMock(clients.OpenStackClients, 'nova') - clients.OpenStackClients.nova().MultipleTimes().AndReturn(self.fc) + self.m.StubOutWithMock(clients.OpenStackClients, '_nova') + clients.OpenStackClients._nova().MultipleTimes().AndReturn(self.fc) self._mock_get_image_id_success('F17-x86_64-gold', 'image_id') self.m.ReplayAll() @@ -1918,8 +1918,8 @@ class ServersTest(HeatTestCase): self.m.StubOutWithMock(server, 'nova') server.nova().MultipleTimes().AndReturn(self.fc) - self.m.StubOutWithMock(clients.OpenStackClients, 'nova') - clients.OpenStackClients.nova().MultipleTimes().AndReturn(self.fc) + self.m.StubOutWithMock(clients.OpenStackClients, '_nova') + clients.OpenStackClients._nova().MultipleTimes().AndReturn(self.fc) self._mock_get_image_id_success('F17-x86_64-gold', 'image_id') self.m.ReplayAll() @@ -1941,8 +1941,8 @@ class ServersTest(HeatTestCase): self.m.StubOutWithMock(server, 'nova') server.nova().MultipleTimes().AndReturn(self.fc) - self.m.StubOutWithMock(clients.OpenStackClients, 'nova') - clients.OpenStackClients.nova().MultipleTimes().AndReturn(self.fc) + self.m.StubOutWithMock(clients.OpenStackClients, '_nova') + clients.OpenStackClients._nova().MultipleTimes().AndReturn(self.fc) self._mock_get_image_id_success('F17-x86_64-gold', 'image_id') self.m.ReplayAll() @@ -1964,8 +1964,8 @@ class ServersTest(HeatTestCase): self.m.StubOutWithMock(server, 'nova') server.nova().MultipleTimes().AndReturn(self.fc) - self.m.StubOutWithMock(clients.OpenStackClients, 'nova') - clients.OpenStackClients.nova().MultipleTimes().AndReturn(self.fc) + self.m.StubOutWithMock(clients.OpenStackClients, '_nova') + clients.OpenStackClients._nova().MultipleTimes().AndReturn(self.fc) self._mock_get_image_id_success('F17-x86_64-gold', 'image_id') self.m.ReplayAll() @@ -2032,8 +2032,8 @@ class ServersTest(HeatTestCase): admin_pass=None).AndReturn(return_server) self.m.StubOutWithMock(server, 'nova') server.nova().MultipleTimes().AndReturn(self.fc) - self.m.StubOutWithMock(clients.OpenStackClients, 'nova') - clients.OpenStackClients.nova().MultipleTimes().AndReturn(self.fc) + self.m.StubOutWithMock(clients.OpenStackClients, '_nova') + clients.OpenStackClients._nova().MultipleTimes().AndReturn(self.fc) self._mock_get_image_id_success('F17-x86_64-gold', image_id) self.m.StubOutWithMock(nova_utils, 'build_userdata') nova_utils.build_userdata(server, @@ -2536,8 +2536,8 @@ class FlavorConstraintTest(HeatTestCase): def test_validate(self): client = fakes.FakeClient() self.stub_keystoneclient() - self.m.StubOutWithMock(clients.OpenStackClients, 'nova') - clients.OpenStackClients.nova().MultipleTimes().AndReturn(client) + self.m.StubOutWithMock(clients.OpenStackClients, '_nova') + clients.OpenStackClients._nova().MultipleTimes().AndReturn(client) client.flavors = self.m.CreateMockAnything() flavor = collections.namedtuple("Flavor", ["id", "name"]) diff --git a/heat/tests/test_server_tags.py b/heat/tests/test_server_tags.py index ea774a10f..6e80c9efd 100644 --- a/heat/tests/test_server_tags.py +++ b/heat/tests/test_server_tags.py @@ -132,8 +132,8 @@ class ServerTagsTest(HeatTestCase): def _mock_get_image_id_success(self, imageId_input, imageId): g_cli_mock = self.m.CreateMockAnything() - self.m.StubOutWithMock(clients.OpenStackClients, 'glance') - clients.OpenStackClients.glance().MultipleTimes().AndReturn( + self.m.StubOutWithMock(clients.OpenStackClients, '_glance') + clients.OpenStackClients._glance().MultipleTimes().AndReturn( g_cli_mock) self.m.StubOutWithMock(glance_utils, 'get_image_id') glance_utils.get_image_id(g_cli_mock, imageId_input).MultipleTimes().\ @@ -154,8 +154,8 @@ class ServerTagsTest(HeatTestCase): self.m.StubOutWithMock(instance, 'nova') instance.nova().MultipleTimes().AndReturn(self.fc) - self.m.StubOutWithMock(clients.OpenStackClients, 'nova') - clients.OpenStackClients.nova().MultipleTimes().AndReturn(self.fc) + self.m.StubOutWithMock(clients.OpenStackClients, '_nova') + clients.OpenStackClients._nova().MultipleTimes().AndReturn(self.fc) self._mock_get_image_id_success('CentOS 5.2', 1) # need to resolve the template functions server_userdata = nova_utils.build_userdata( @@ -208,8 +208,8 @@ class ServerTagsTest(HeatTestCase): self.m.StubOutWithMock(instance, 'nova') instance.nova().MultipleTimes().AndReturn(self.fc) - self.m.StubOutWithMock(clients.OpenStackClients, 'nova') - clients.OpenStackClients.nova().MultipleTimes().AndReturn(self.fc) + self.m.StubOutWithMock(clients.OpenStackClients, '_nova') + clients.OpenStackClients._nova().MultipleTimes().AndReturn(self.fc) self.m.StubOutWithMock(self.fc.servers, 'set_meta') self.fc.servers.set_meta(self.fc.servers.list()[1], new_metadata).AndReturn(None) @@ -244,8 +244,8 @@ class ServerTagsTest(HeatTestCase): self.m.StubOutWithMock(instances.Instance, 'nova') instances.Instance.nova().MultipleTimes().AndReturn(self.fc) - self.m.StubOutWithMock(clients.OpenStackClients, 'nova') - clients.OpenStackClients.nova().MultipleTimes().AndReturn(self.fc) + self.m.StubOutWithMock(clients.OpenStackClients, '_nova') + clients.OpenStackClients._nova().MultipleTimes().AndReturn(self.fc) self._mock_get_image_id_success('CentOS 5.2', 1) # need to resolve the template functions self.m.StubOutWithMock(self.fc.servers, 'create') @@ -295,8 +295,8 @@ class ServerTagsTest(HeatTestCase): self.m.StubOutWithMock(instances.Instance, 'nova') instances.Instance.nova().MultipleTimes().AndReturn(self.fc) - self.m.StubOutWithMock(clients.OpenStackClients, 'nova') - clients.OpenStackClients.nova().MultipleTimes().AndReturn(self.fc) + self.m.StubOutWithMock(clients.OpenStackClients, '_nova') + clients.OpenStackClients._nova().MultipleTimes().AndReturn(self.fc) self._mock_get_image_id_success('CentOS 5.2', 1) # need to resolve the template functions self.m.StubOutWithMock(self.fc.servers, 'create') diff --git a/heat/tests/test_signal.py b/heat/tests/test_signal.py index 8fcf33ccb..ad7324a87 100644 --- a/heat/tests/test_signal.py +++ b/heat/tests/test_signal.py @@ -216,8 +216,8 @@ class SignalTest(HeatTestCase): def delete_stack_user(self, name): raise kc_exceptions.NotFound() - self.m.StubOutWithMock(clients.OpenStackClients, 'keystone') - clients.OpenStackClients.keystone().MultipleTimes().AndReturn( + self.m.StubOutWithMock(clients.OpenStackClients, '_keystone') + clients.OpenStackClients._keystone().AndReturn( FakeKeystoneClientFail()) self.m.ReplayAll() @@ -313,8 +313,8 @@ class SignalTest(HeatTestCase): # test isolated from keystoneclient. The unset stubs is done so that we # do not have to mock out all of the deleting that the # stack_delete_after decorator will do during cleanup. - self.m.StubOutWithMock(self.stack.clients, 'keystone') - self.stack.clients.keystone().AndReturn(self.fc) + self.m.StubOutWithMock(self.stack.clients, '_keystone') + self.stack.clients._keystone().AndReturn(self.fc) self.m.ReplayAll() diff --git a/heat/tests/test_sqlalchemy_api.py b/heat/tests/test_sqlalchemy_api.py index efc936a55..ee6f29aec 100644 --- a/heat/tests/test_sqlalchemy_api.py +++ b/heat/tests/test_sqlalchemy_api.py @@ -97,8 +97,8 @@ class SqlAlchemyTest(HeatTestCase): def _mock_get_image_id_success(self, imageId_input, imageId): g_cli_mock = self.m.CreateMockAnything() - self.m.StubOutWithMock(clients.OpenStackClients, 'glance') - clients.OpenStackClients.glance().MultipleTimes().AndReturn( + self.m.StubOutWithMock(clients.OpenStackClients, '_glance') + clients.OpenStackClients._glance().MultipleTimes().AndReturn( g_cli_mock) self.m.StubOutWithMock(glance_utils, 'get_image_id') glance_utils.get_image_id(g_cli_mock, imageId_input).MultipleTimes().\ @@ -121,8 +121,8 @@ class SqlAlchemyTest(HeatTestCase): fc = fakes.FakeClient() mocks.StubOutWithMock(instances.Instance, 'nova') instances.Instance.nova().MultipleTimes().AndReturn(fc) - self.m.StubOutWithMock(clients.OpenStackClients, 'nova') - clients.OpenStackClients.nova().MultipleTimes().AndReturn(self.fc) + self.m.StubOutWithMock(clients.OpenStackClients, '_nova') + clients.OpenStackClients._nova().MultipleTimes().AndReturn(self.fc) self._mock_get_image_id_success('F17-x86_64-gold', 744) mocks.StubOutWithMock(fc.servers, 'create') diff --git a/heat/tests/test_validate.py b/heat/tests/test_validate.py index f00e97975..b33b339b3 100644 --- a/heat/tests/test_validate.py +++ b/heat/tests/test_validate.py @@ -819,8 +819,8 @@ class validateTest(HeatTestCase): def _mock_get_image_id_success(self, imageId_input, imageId): g_cli_mock = self.m.CreateMockAnything() - self.m.StubOutWithMock(clients.OpenStackClients, 'glance') - clients.OpenStackClients.glance().MultipleTimes().AndReturn( + self.m.StubOutWithMock(clients.OpenStackClients, '_glance') + clients.OpenStackClients._glance().MultipleTimes().AndReturn( g_cli_mock) self.m.StubOutWithMock(glance_utils, 'get_image_id') glance_utils.get_image_id(g_cli_mock, imageId_input).MultipleTimes().\ @@ -828,8 +828,8 @@ class validateTest(HeatTestCase): def _mock_get_image_id_fail(self, image_id, exp): g_cli_mock = self.m.CreateMockAnything() - self.m.StubOutWithMock(clients.OpenStackClients, 'glance') - clients.OpenStackClients.glance().MultipleTimes().AndReturn( + self.m.StubOutWithMock(clients.OpenStackClients, '_glance') + clients.OpenStackClients._glance().MultipleTimes().AndReturn( g_cli_mock) self.m.StubOutWithMock(glance_utils, 'get_image_id') glance_utils.get_image_id(g_cli_mock, image_id).AndRaise(exp) @@ -1267,8 +1267,8 @@ class validateTest(HeatTestCase): self._mock_get_image_id_success('image_name', 'image_id') - self.m.StubOutWithMock(clients.OpenStackClients, 'nova') - clients.OpenStackClients.nova().MultipleTimes().AndReturn(self.fc) + self.m.StubOutWithMock(clients.OpenStackClients, '_nova') + clients.OpenStackClients._nova().MultipleTimes().AndReturn(self.fc) self.m.ReplayAll() resource = stack['Instance'] @@ -1284,8 +1284,8 @@ class validateTest(HeatTestCase): self._mock_get_image_id_success('image_name', 'image_id') - self.m.StubOutWithMock(clients.OpenStackClients, 'nova') - clients.OpenStackClients.nova().MultipleTimes().AndReturn(self.fc) + self.m.StubOutWithMock(clients.OpenStackClients, '_nova') + clients.OpenStackClients._nova().MultipleTimes().AndReturn(self.fc) self.m.ReplayAll() resource = stack['Instance'] @@ -1301,8 +1301,8 @@ class validateTest(HeatTestCase): self.m.StubOutWithMock(self.gc.images, 'list') self.gc.images.list().AndRaise( g_exc.ClientException(500)) - self.m.StubOutWithMock(clients.OpenStackClients, 'glance') - clients.OpenStackClients.glance().MultipleTimes().AndReturn(self.gc) + self.m.StubOutWithMock(clients.OpenStackClients, '_glance') + clients.OpenStackClients._glance().MultipleTimes().AndReturn(self.gc) self.m.ReplayAll() self.assertRaises(exception.StackValidationFailed, stack.validate) diff --git a/heat/tests/test_volume.py b/heat/tests/test_volume.py index b4d697938..89303b0f1 100644 --- a/heat/tests/test_volume.py +++ b/heat/tests/test_volume.py @@ -100,8 +100,8 @@ class VolumeTest(HeatTestCase): super(VolumeTest, self).setUp() self.fc = fakes.FakeClient() self.cinder_fc = cinderclient.Client('username', 'password') - self.m.StubOutWithMock(clients.OpenStackClients, 'cinder') - self.m.StubOutWithMock(clients.OpenStackClients, 'nova') + self.m.StubOutWithMock(clients.OpenStackClients, '_cinder') + self.m.StubOutWithMock(clients.OpenStackClients, '_nova') self.m.StubOutWithMock(self.cinder_fc.volumes, 'create') self.m.StubOutWithMock(self.cinder_fc.volumes, 'get') self.m.StubOutWithMock(self.cinder_fc.volumes, 'delete') @@ -144,7 +144,7 @@ class VolumeTest(HeatTestCase): return rsrc def _mock_create_volume(self, fv, stack_name, size=1): - clients.OpenStackClients.cinder().MultipleTimes().AndReturn( + clients.OpenStackClients._cinder().MultipleTimes().AndReturn( self.cinder_fc) vol_name = utils.PhysName(stack_name, 'DataVolume') self.cinder_fc.volumes.create( @@ -168,7 +168,7 @@ class VolumeTest(HeatTestCase): device=u'/dev/vdc', update=False): if not update: - clients.OpenStackClients.nova().MultipleTimes().AndReturn(self.fc) + clients.OpenStackClients._nova().MultipleTimes().AndReturn(self.fc) self.fc.volumes.create_server_volume( device=device, server_id=server, volume_id=volume).AndReturn(fva) self.cinder_fc.volumes.get(volume).AndReturn(fva) @@ -211,7 +211,7 @@ class VolumeTest(HeatTestCase): stack_name = 'test_volume_stack' # create script - clients.OpenStackClients.nova().MultipleTimes().AndReturn(self.fc) + clients.OpenStackClients._nova().MultipleTimes().AndReturn(self.fc) self.m.StubOutWithMock(instance.Instance, 'handle_create') self.m.StubOutWithMock(instance.Instance, 'check_create_complete') self.m.StubOutWithMock(vol.VolumeAttachment, 'handle_create') @@ -219,7 +219,7 @@ class VolumeTest(HeatTestCase): self.m.StubOutWithMock(image.ImageConstraint, "validate") instance.Instance.handle_create().AndReturn(None) instance.Instance.check_create_complete(None).AndReturn(True) - clients.OpenStackClients.cinder().MultipleTimes().AndReturn( + clients.OpenStackClients._cinder().MultipleTimes().AndReturn( self.cinder_fc) image.ImageConstraint.validate( mox.IgnoreArg(), mox.IgnoreArg()).MultipleTimes().AndReturn(True) @@ -764,7 +764,7 @@ class VolumeTest(HeatTestCase): fvbr = FakeBackupRestore('vol-123') # create script - clients.OpenStackClients.cinder().MultipleTimes().AndReturn( + clients.OpenStackClients._cinder().MultipleTimes().AndReturn( self.cinder_fc) self.m.StubOutWithMock(self.cinder_fc.restores, 'restore') self.cinder_fc.restores.restore('backup-123').AndReturn(fvbr) @@ -793,7 +793,7 @@ class VolumeTest(HeatTestCase): fvbr = FakeBackupRestore('vol-123') # create script - clients.OpenStackClients.cinder().MultipleTimes().AndReturn( + clients.OpenStackClients._cinder().MultipleTimes().AndReturn( self.cinder_fc) self.m.StubOutWithMock(self.cinder_fc.restores, 'restore') self.cinder_fc.restores.restore('backup-123').AndReturn(fvbr) @@ -824,7 +824,7 @@ class VolumeTest(HeatTestCase): fv = FakeVolume('creating', 'available') stack_name = 'test_volume_stack' - clients.OpenStackClients.cinder().MultipleTimes().AndReturn( + clients.OpenStackClients._cinder().MultipleTimes().AndReturn( self.cinder_fc) self.cinder_fc.volumes.create( size=1, availability_zone='nova', @@ -896,11 +896,11 @@ class VolumeTest(HeatTestCase): fv = FakeVolumeWithStateTransition('downloading', 'available') stack_name = 'test_volume_stack' image_id = '46988116-6703-4623-9dbc-2bc6d284021b' - clients.OpenStackClients.cinder().MultipleTimes().AndReturn( + clients.OpenStackClients._cinder().MultipleTimes().AndReturn( self.cinder_fc) g_cli_mock = self.m.CreateMockAnything() - self.m.StubOutWithMock(clients.OpenStackClients, 'glance') - clients.OpenStackClients.glance().MultipleTimes().AndReturn( + self.m.StubOutWithMock(clients.OpenStackClients, '_glance') + clients.OpenStackClients._glance().MultipleTimes().AndReturn( g_cli_mock) self.m.StubOutWithMock(glance_utils, 'get_image_id') glance_utils.get_image_id(g_cli_mock, image_id).MultipleTimes().\ @@ -939,7 +939,7 @@ class VolumeTest(HeatTestCase): fv = FakeVolume('creating', 'available') stack_name = 'test_volume_stack' - clients.OpenStackClients.cinder().MultipleTimes().AndReturn( + clients.OpenStackClients._cinder().MultipleTimes().AndReturn( self.cinder_fc) vol_name = utils.PhysName(stack_name, 'DataVolume') self.cinder_fc.volumes.create( @@ -976,7 +976,7 @@ class VolumeTest(HeatTestCase): created_at='2013-02-25T02:40:21.000000') stack_name = 'test_volume_stack' - clients.OpenStackClients.cinder().MultipleTimes().AndReturn( + clients.OpenStackClients._cinder().MultipleTimes().AndReturn( self.cinder_fc) vol_name = utils.PhysName(stack_name, 'DataVolume') self.cinder_fc.volumes.create( @@ -1263,7 +1263,7 @@ class VolumeTest(HeatTestCase): fvbr = FakeBackupRestore('vol-123') # create script - clients.OpenStackClients.cinder().MultipleTimes().AndReturn( + clients.OpenStackClients._cinder().MultipleTimes().AndReturn( self.cinder_fc) self.m.StubOutWithMock(self.cinder_fc.restores, 'restore') self.cinder_fc.restores.restore('backup-123').AndReturn(fvbr) @@ -1311,7 +1311,7 @@ class VolumeTest(HeatTestCase): 'display_description': update_description } - clients.OpenStackClients.cinder().MultipleTimes().AndReturn( + clients.OpenStackClients._cinder().MultipleTimes().AndReturn( self.cinder_fc) self.cinder_fc.volumes.create( availability_zone=None,