Merge "Deprecate direct access to clients methods"

This commit is contained in:
Jenkins 2014-07-03 10:37:37 +00:00 committed by Gerrit Code Review
commit 706f7289fa
39 changed files with 319 additions and 319 deletions

View File

@ -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)

View File

@ -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)})

View File

@ -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:

View File

@ -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)

View File

@ -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()

View File

@ -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'))

View File

@ -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)

View File

@ -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]

View File

@ -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]

View File

@ -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):

View File

@ -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):

View File

@ -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):
'''

View File

@ -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)

View File

@ -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)

View File

@ -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)

View File

@ -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)

View File

@ -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):

View File

@ -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

View File

@ -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):

View File

@ -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(

View File

@ -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)

View File

@ -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,

View File

@ -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()

View File

@ -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(

View File

@ -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,

View File

@ -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'

View File

@ -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,

View File

@ -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')

View File

@ -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().\

View File

@ -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()

View File

@ -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"])

View File

@ -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"])

View File

@ -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'))

View File

@ -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"])

View File

@ -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')

View File

@ -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()

View File

@ -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')

View File

@ -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)

View File

@ -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,