Move glance_utils functions to glance client plugin
The glance client plugin is a more obvious home for this sort of function, and this change makes mocking of these functions much easier since a mocked client is no longer needed. To access the methods defined in the client plugin the method Resource.client_plugin has been added. When all clients are contributed by plugins then method Resource.client will call Resource.client_plugin. glance_utils can be deleted since it was only added at the beginning of the Juno cycle. The image constraint has also been moved to the glance plugin. Change-Id: Id31ccd605411ca034addc67d8aadf7cea0904bfd
This commit is contained in:
parent
ec35f074cc
commit
956632844a
@ -16,7 +16,6 @@ import copy
|
|||||||
from heat.common import exception
|
from heat.common import exception
|
||||||
from heat.engine import attributes
|
from heat.engine import attributes
|
||||||
from heat.engine import properties
|
from heat.engine import properties
|
||||||
from heat.engine.resources import glance_utils
|
|
||||||
from heat.engine.resources import nova_utils
|
from heat.engine.resources import nova_utils
|
||||||
from heat.engine.resources import server
|
from heat.engine.resources import server
|
||||||
from heat.openstack.common.gettextutils import _
|
from heat.openstack.common.gettextutils import _
|
||||||
@ -114,7 +113,7 @@ class CloudServer(server.Server):
|
|||||||
"""Return the server's image ID."""
|
"""Return the server's image ID."""
|
||||||
image = self.properties.get(self.IMAGE)
|
image = self.properties.get(self.IMAGE)
|
||||||
if image and self._image is None:
|
if image and self._image is None:
|
||||||
self._image = glance_utils.get_image_id(self.glance(), image)
|
self._image = self.client_plugin('glance').get_image_id(image)
|
||||||
return self._image
|
return self._image
|
||||||
|
|
||||||
def _config_drive(self):
|
def _config_drive(self):
|
||||||
|
@ -21,7 +21,6 @@ from heat.engine.clients.os import nova
|
|||||||
from heat.engine import environment
|
from heat.engine import environment
|
||||||
from heat.engine import parser
|
from heat.engine import parser
|
||||||
from heat.engine import resource
|
from heat.engine import resource
|
||||||
from heat.engine.resources import glance_utils
|
|
||||||
from heat.engine import scheduler
|
from heat.engine import scheduler
|
||||||
from heat.openstack.common import uuidutils
|
from heat.openstack.common import uuidutils
|
||||||
from heat.tests.common import HeatTestCase
|
from heat.tests.common import HeatTestCase
|
||||||
@ -68,12 +67,8 @@ class CloudServersTest(HeatTestCase):
|
|||||||
cloud_server.CloudServer)
|
cloud_server.CloudServer)
|
||||||
|
|
||||||
def _mock_get_image_id_success(self, imageId_input, imageId):
|
def _mock_get_image_id_success(self, imageId_input, imageId):
|
||||||
g_cli_mock = self.m.CreateMockAnything()
|
self.m.StubOutWithMock(glance.GlanceClientPlugin, 'get_image_id')
|
||||||
self.m.StubOutWithMock(glance.GlanceClientPlugin, '_create')
|
glance.GlanceClientPlugin.get_image_id(imageId_input).MultipleTimes().\
|
||||||
glance.GlanceClientPlugin._create().MultipleTimes().AndReturn(
|
|
||||||
g_cli_mock)
|
|
||||||
self.m.StubOutWithMock(glance_utils, 'get_image_id')
|
|
||||||
glance_utils.get_image_id(g_cli_mock, imageId_input).MultipleTimes().\
|
|
||||||
AndReturn(imageId)
|
AndReturn(imageId)
|
||||||
|
|
||||||
def _stub_server_validate(self, server, imageId_input, image_id):
|
def _stub_server_validate(self, server, imageId_input, image_id):
|
||||||
|
@ -12,8 +12,16 @@
|
|||||||
# under the License.
|
# under the License.
|
||||||
|
|
||||||
from glanceclient import client as gc
|
from glanceclient import client as gc
|
||||||
|
from glanceclient import exc
|
||||||
|
|
||||||
|
from heat.common import exception
|
||||||
from heat.engine.clients import client_plugin
|
from heat.engine.clients import client_plugin
|
||||||
|
from heat.engine import constraints
|
||||||
|
from heat.openstack.common.gettextutils import _
|
||||||
|
from heat.openstack.common import log as logging
|
||||||
|
from heat.openstack.common import uuidutils
|
||||||
|
|
||||||
|
LOG = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
|
||||||
class GlanceClientPlugin(client_plugin.ClientPlugin):
|
class GlanceClientPlugin(client_plugin.ClientPlugin):
|
||||||
@ -37,3 +45,57 @@ class GlanceClientPlugin(client_plugin.ClientPlugin):
|
|||||||
}
|
}
|
||||||
|
|
||||||
return gc.Client('1', endpoint, **args)
|
return gc.Client('1', endpoint, **args)
|
||||||
|
|
||||||
|
def get_image_id(self, image_identifier):
|
||||||
|
'''
|
||||||
|
Return an id for the specified image name or identifier.
|
||||||
|
|
||||||
|
:param image_identifier: image name or a UUID-like identifier
|
||||||
|
:returns: the id of the requested :image_identifier:
|
||||||
|
:raises: exception.ImageNotFound,
|
||||||
|
exception.PhysicalResourceNameAmbiguity
|
||||||
|
'''
|
||||||
|
if uuidutils.is_uuid_like(image_identifier):
|
||||||
|
try:
|
||||||
|
image_id = self.client().images.get(image_identifier).id
|
||||||
|
except exc.HTTPNotFound:
|
||||||
|
image_id = self.get_image_id_by_name(image_identifier)
|
||||||
|
else:
|
||||||
|
image_id = self.get_image_id_by_name(image_identifier)
|
||||||
|
return image_id
|
||||||
|
|
||||||
|
def get_image_id_by_name(self, image_identifier):
|
||||||
|
'''
|
||||||
|
Return an id for the specified image name.
|
||||||
|
|
||||||
|
:param image_identifier: image name
|
||||||
|
:returns: the id of the requested :image_identifier:
|
||||||
|
:raises: exception.ImageNotFound,
|
||||||
|
exception.PhysicalResourceNameAmbiguity
|
||||||
|
'''
|
||||||
|
try:
|
||||||
|
filters = {'name': image_identifier}
|
||||||
|
image_list = list(self.client().images.list(filters=filters))
|
||||||
|
except exc.ClientException as ex:
|
||||||
|
raise exception.Error(
|
||||||
|
_("Error retrieving image list from glance: %s") % ex)
|
||||||
|
num_matches = len(image_list)
|
||||||
|
if num_matches == 0:
|
||||||
|
LOG.info(_("Image %s was not found in glance") %
|
||||||
|
image_identifier)
|
||||||
|
raise exception.ImageNotFound(image_name=image_identifier)
|
||||||
|
elif num_matches > 1:
|
||||||
|
LOG.info(_("Multiple images %s were found in glance with name") %
|
||||||
|
image_identifier)
|
||||||
|
raise exception.PhysicalResourceNameAmbiguity(
|
||||||
|
name=image_identifier)
|
||||||
|
else:
|
||||||
|
return image_list[0].id
|
||||||
|
|
||||||
|
|
||||||
|
class ImageConstraint(constraints.BaseCustomConstraint):
|
||||||
|
|
||||||
|
expected_exceptions = (exception.ImageNotFound,)
|
||||||
|
|
||||||
|
def validate_with_client(self, client, value):
|
||||||
|
client.client_plugin('glance').get_image_id(value)
|
||||||
|
@ -344,6 +344,11 @@ class Resource(object):
|
|||||||
assert client_name, "Must specify client name"
|
assert client_name, "Must specify client name"
|
||||||
return self.stack.clients.client(client_name)
|
return self.stack.clients.client(client_name)
|
||||||
|
|
||||||
|
def client_plugin(self, name=None):
|
||||||
|
client_name = name or self.default_client_name
|
||||||
|
assert client_name, "Must specify client name"
|
||||||
|
return self.stack.clients.client_plugin(client_name)
|
||||||
|
|
||||||
def keystone(self):
|
def keystone(self):
|
||||||
return self.client('keystone')
|
return self.client('keystone')
|
||||||
|
|
||||||
|
@ -1,69 +0,0 @@
|
|||||||
#
|
|
||||||
# Licensed under the Apache License, Version 2.0 (the "License"); you may
|
|
||||||
# not use this file except in compliance with the License. You may obtain
|
|
||||||
# a copy of the License at
|
|
||||||
#
|
|
||||||
# http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
#
|
|
||||||
# Unless required by applicable law or agreed to in writing, software
|
|
||||||
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
|
||||||
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
|
||||||
# License for the specific language governing permissions and limitations
|
|
||||||
# under the License.
|
|
||||||
"""Utilities for Resources that use the OpenStack Glance API."""
|
|
||||||
|
|
||||||
from glanceclient import exc as glance_exceptions
|
|
||||||
|
|
||||||
from heat.common import exception
|
|
||||||
from heat.openstack.common.gettextutils import _
|
|
||||||
from heat.openstack.common import log as logging
|
|
||||||
from heat.openstack.common import uuidutils
|
|
||||||
|
|
||||||
logger = logging.getLogger(__name__)
|
|
||||||
|
|
||||||
|
|
||||||
def get_image_id(glance_client, image_identifier):
|
|
||||||
'''
|
|
||||||
Return an id for the specified image name or identifier.
|
|
||||||
|
|
||||||
:param glance_client: the glance client to use
|
|
||||||
:param image_identifier: image name or a UUID-like identifier
|
|
||||||
:returns: the id of the requested :image_identifier:
|
|
||||||
:raises: exception.ImageNotFound, exception.PhysicalResourceNameAmbiguity
|
|
||||||
'''
|
|
||||||
if uuidutils.is_uuid_like(image_identifier):
|
|
||||||
try:
|
|
||||||
image_id = glance_client.images.get(image_identifier).id
|
|
||||||
except glance_exceptions.NotFound:
|
|
||||||
image_id = get_image_id_by_name(glance_client, image_identifier)
|
|
||||||
else:
|
|
||||||
image_id = get_image_id_by_name(glance_client, image_identifier)
|
|
||||||
return image_id
|
|
||||||
|
|
||||||
|
|
||||||
def get_image_id_by_name(glance_client, image_identifier):
|
|
||||||
'''
|
|
||||||
Return an id for the specified image name or identifier.
|
|
||||||
|
|
||||||
:param glance_client: the glance client to use
|
|
||||||
:param image_identifier: image name or a UUID-like identifier
|
|
||||||
:returns: the id of the requested :image_identifier:
|
|
||||||
:raises: exception.ImageNotFound, exception.PhysicalResourceNameAmbiguity
|
|
||||||
'''
|
|
||||||
try:
|
|
||||||
filters = {'name': image_identifier}
|
|
||||||
image_list = list(glance_client.images.list(filters=filters))
|
|
||||||
except glance_exceptions.ClientException as ex:
|
|
||||||
raise exception.Error(
|
|
||||||
_("Error retrieving image list from glance: %s") % ex)
|
|
||||||
num_matches = len(image_list)
|
|
||||||
if num_matches == 0:
|
|
||||||
logger.info(_("Image %s was not found in glance") %
|
|
||||||
image_identifier)
|
|
||||||
raise exception.ImageNotFound(image_name=image_identifier)
|
|
||||||
elif num_matches > 1:
|
|
||||||
logger.info(_("Multiple images %s were found in glance with name")
|
|
||||||
% image_identifier)
|
|
||||||
raise exception.PhysicalResourceNameAmbiguity(name=image_identifier)
|
|
||||||
else:
|
|
||||||
return image_list[0].id
|
|
@ -1,25 +0,0 @@
|
|||||||
#
|
|
||||||
# Licensed under the Apache License, Version 2.0 (the "License"); you may
|
|
||||||
# not use this file except in compliance with the License. You may obtain
|
|
||||||
# a copy of the License at
|
|
||||||
#
|
|
||||||
# http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
#
|
|
||||||
# Unless required by applicable law or agreed to in writing, software
|
|
||||||
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
|
||||||
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
|
||||||
# License for the specific language governing permissions and limitations
|
|
||||||
# under the License.
|
|
||||||
|
|
||||||
from heat.common import exception
|
|
||||||
from heat.engine import constraints
|
|
||||||
from heat.engine.resources import glance_utils
|
|
||||||
|
|
||||||
|
|
||||||
class ImageConstraint(constraints.BaseCustomConstraint):
|
|
||||||
|
|
||||||
expected_exceptions = (exception.ImageNotFound,)
|
|
||||||
|
|
||||||
def validate_with_client(self, client, value):
|
|
||||||
glance_client = client.client('glance')
|
|
||||||
glance_utils.get_image_id(glance_client, value)
|
|
@ -21,7 +21,6 @@ from heat.engine import attributes
|
|||||||
from heat.engine import constraints
|
from heat.engine import constraints
|
||||||
from heat.engine import properties
|
from heat.engine import properties
|
||||||
from heat.engine import resource
|
from heat.engine import resource
|
||||||
from heat.engine.resources import glance_utils
|
|
||||||
from heat.engine.resources.network_interface import NetworkInterface
|
from heat.engine.resources.network_interface import NetworkInterface
|
||||||
from heat.engine.resources.neutron import neutron
|
from heat.engine.resources.neutron import neutron
|
||||||
from heat.engine.resources import nova_utils
|
from heat.engine.resources import nova_utils
|
||||||
@ -439,7 +438,7 @@ class Instance(resource.Resource):
|
|||||||
|
|
||||||
image_name = self.properties[self.IMAGE_ID]
|
image_name = self.properties[self.IMAGE_ID]
|
||||||
|
|
||||||
image_id = glance_utils.get_image_id(self.glance(), image_name)
|
image_id = self.client_plugin('glance').get_image_id(image_name)
|
||||||
|
|
||||||
flavor_id = nova_utils.get_flavor_id(self.nova(), flavor)
|
flavor_id = nova_utils.get_flavor_id(self.nova(), flavor)
|
||||||
|
|
||||||
|
@ -22,7 +22,6 @@ from heat.engine import attributes
|
|||||||
from heat.engine import constraints
|
from heat.engine import constraints
|
||||||
from heat.engine import properties
|
from heat.engine import properties
|
||||||
from heat.engine import resource
|
from heat.engine import resource
|
||||||
from heat.engine.resources import glance_utils
|
|
||||||
from heat.engine.resources.neutron import subnet
|
from heat.engine.resources.neutron import subnet
|
||||||
from heat.engine.resources import nova_utils
|
from heat.engine.resources import nova_utils
|
||||||
from heat.engine.resources.software_config import software_config as sc
|
from heat.engine.resources.software_config import software_config as sc
|
||||||
@ -484,7 +483,7 @@ class Server(stack_user.StackUser):
|
|||||||
|
|
||||||
image = self.properties.get(self.IMAGE)
|
image = self.properties.get(self.IMAGE)
|
||||||
if image:
|
if image:
|
||||||
image = glance_utils.get_image_id(self.glance(), image)
|
image = self.client_plugin('glance').get_image_id(image)
|
||||||
|
|
||||||
flavor_id = nova_utils.get_flavor_id(self.nova(), flavor)
|
flavor_id = nova_utils.get_flavor_id(self.nova(), flavor)
|
||||||
|
|
||||||
@ -747,7 +746,7 @@ class Server(stack_user.StackUser):
|
|||||||
if image_update_policy == 'REPLACE':
|
if image_update_policy == 'REPLACE':
|
||||||
raise resource.UpdateReplace(self.name)
|
raise resource.UpdateReplace(self.name)
|
||||||
image = prop_diff[self.IMAGE]
|
image = prop_diff[self.IMAGE]
|
||||||
image_id = glance_utils.get_image_id(self.glance(), image)
|
image_id = self.client_plugin('glance').get_image_id(image)
|
||||||
if not server:
|
if not server:
|
||||||
server = self.nova().servers.get(self.resource_id)
|
server = self.nova().servers.get(self.resource_id)
|
||||||
preserve_ephemeral = (
|
preserve_ephemeral = (
|
||||||
|
@ -21,7 +21,6 @@ from heat.engine import attributes
|
|||||||
from heat.engine import constraints
|
from heat.engine import constraints
|
||||||
from heat.engine import properties
|
from heat.engine import properties
|
||||||
from heat.engine import resource
|
from heat.engine import resource
|
||||||
from heat.engine.resources import glance_utils
|
|
||||||
from heat.engine import scheduler
|
from heat.engine import scheduler
|
||||||
from heat.engine import support
|
from heat.engine import support
|
||||||
from heat.openstack.common import log as logging
|
from heat.openstack.common import log as logging
|
||||||
@ -644,8 +643,8 @@ class CinderVolume(Volume):
|
|||||||
'availability_zone': self.properties[self.AVAILABILITY_ZONE]
|
'availability_zone': self.properties[self.AVAILABILITY_ZONE]
|
||||||
}
|
}
|
||||||
if self.properties.get(self.IMAGE):
|
if self.properties.get(self.IMAGE):
|
||||||
arguments['imageRef'] = glance_utils.get_image_id(
|
arguments['imageRef'] = self.client_plugin('glance').get_image_id(
|
||||||
self.glance(), self.properties[self.IMAGE])
|
self.properties[self.IMAGE])
|
||||||
elif self.properties.get(self.IMAGE_REF):
|
elif self.properties.get(self.IMAGE_REF):
|
||||||
arguments['imageRef'] = self.properties[self.IMAGE_REF]
|
arguments['imageRef'] = self.properties[self.IMAGE_REF]
|
||||||
|
|
||||||
|
@ -21,11 +21,11 @@ from oslo.config import cfg
|
|||||||
from heat.common import exception
|
from heat.common import exception
|
||||||
from heat.common import short_id
|
from heat.common import short_id
|
||||||
from heat.common import template_format
|
from heat.common import template_format
|
||||||
|
from heat.engine.clients.os import glance
|
||||||
from heat.engine.notification import autoscaling as notification
|
from heat.engine.notification import autoscaling as notification
|
||||||
from heat.engine import parser
|
from heat.engine import parser
|
||||||
from heat.engine import resource
|
from heat.engine import resource
|
||||||
from heat.engine.resources import autoscaling as asc
|
from heat.engine.resources import autoscaling as asc
|
||||||
from heat.engine.resources import image
|
|
||||||
from heat.engine.resources import instance
|
from heat.engine.resources import instance
|
||||||
from heat.engine.resources import loadbalancer
|
from heat.engine.resources import loadbalancer
|
||||||
from heat.engine.resources.neutron import loadbalancer as neutron_lb
|
from heat.engine.resources.neutron import loadbalancer as neutron_lb
|
||||||
@ -151,8 +151,8 @@ class AutoScalingTest(HeatTestCase):
|
|||||||
def _stub_create(self, num, with_error=None):
|
def _stub_create(self, num, with_error=None):
|
||||||
self.m.StubOutWithMock(instance.Instance, 'handle_create')
|
self.m.StubOutWithMock(instance.Instance, 'handle_create')
|
||||||
self.m.StubOutWithMock(instance.Instance, 'check_create_complete')
|
self.m.StubOutWithMock(instance.Instance, 'check_create_complete')
|
||||||
self.m.StubOutWithMock(image.ImageConstraint, "validate")
|
self.m.StubOutWithMock(glance.ImageConstraint, "validate")
|
||||||
image.ImageConstraint.validate(
|
glance.ImageConstraint.validate(
|
||||||
mox.IgnoreArg(), mox.IgnoreArg()).MultipleTimes().AndReturn(True)
|
mox.IgnoreArg(), mox.IgnoreArg()).MultipleTimes().AndReturn(True)
|
||||||
if with_error:
|
if with_error:
|
||||||
instance.Instance.handle_create().AndRaise(
|
instance.Instance.handle_create().AndRaise(
|
||||||
@ -166,9 +166,9 @@ class AutoScalingTest(HeatTestCase):
|
|||||||
cookie).MultipleTimes().AndReturn(True)
|
cookie).MultipleTimes().AndReturn(True)
|
||||||
|
|
||||||
def _stub_image_validate(self, num=1):
|
def _stub_image_validate(self, num=1):
|
||||||
self.m.StubOutWithMock(image.ImageConstraint, "validate")
|
self.m.StubOutWithMock(glance.ImageConstraint, "validate")
|
||||||
for x in range(num):
|
for x in range(num):
|
||||||
image.ImageConstraint.validate(
|
glance.ImageConstraint.validate(
|
||||||
mox.IgnoreArg(), mox.IgnoreArg()).AndReturn(True)
|
mox.IgnoreArg(), mox.IgnoreArg()).AndReturn(True)
|
||||||
|
|
||||||
def _stub_delete(self, num):
|
def _stub_delete(self, num):
|
||||||
@ -553,8 +553,8 @@ class AutoScalingTest(HeatTestCase):
|
|||||||
self.m.StubOutWithMock(instance.Instance, 'handle_create')
|
self.m.StubOutWithMock(instance.Instance, 'handle_create')
|
||||||
self.m.StubOutWithMock(instance.Instance, 'check_create_complete')
|
self.m.StubOutWithMock(instance.Instance, 'check_create_complete')
|
||||||
instance.Instance.handle_create().AndRaise(Exception)
|
instance.Instance.handle_create().AndRaise(Exception)
|
||||||
self.m.StubOutWithMock(image.ImageConstraint, "validate")
|
self.m.StubOutWithMock(glance.ImageConstraint, "validate")
|
||||||
image.ImageConstraint.validate(
|
glance.ImageConstraint.validate(
|
||||||
mox.IgnoreArg(), mox.IgnoreArg()).MultipleTimes().AndReturn(True)
|
mox.IgnoreArg(), mox.IgnoreArg()).MultipleTimes().AndReturn(True)
|
||||||
|
|
||||||
self.m.ReplayAll()
|
self.m.ReplayAll()
|
||||||
|
@ -25,7 +25,6 @@ from heat.engine.clients.os import nova
|
|||||||
from heat.engine import function
|
from heat.engine import function
|
||||||
from heat.engine.notification import stack as notification
|
from heat.engine.notification import stack as notification
|
||||||
from heat.engine import parser
|
from heat.engine import parser
|
||||||
from heat.engine.resources import glance_utils
|
|
||||||
from heat.engine.resources import instance
|
from heat.engine.resources import instance
|
||||||
from heat.engine.resources import loadbalancer as lb
|
from heat.engine.resources import loadbalancer as lb
|
||||||
from heat.engine.resources import wait_condition as wc
|
from heat.engine.resources import wait_condition as wc
|
||||||
@ -212,13 +211,8 @@ class AutoScalingGroupTest(HeatTestCase):
|
|||||||
'http://127.0.0.1:8000/v1/waitcondition')
|
'http://127.0.0.1:8000/v1/waitcondition')
|
||||||
|
|
||||||
def _mock_get_image_id_success(self, imageId_input, imageId,
|
def _mock_get_image_id_success(self, imageId_input, imageId,
|
||||||
update_image=None, mock_create=True):
|
update_image=None):
|
||||||
g_cli_mock = self.m.CreateMockAnything()
|
self.m.StubOutWithMock(glance.GlanceClientPlugin, 'get_image_id')
|
||||||
if mock_create:
|
|
||||||
self.m.StubOutWithMock(glance.GlanceClientPlugin, '_create')
|
|
||||||
glance.GlanceClientPlugin._create().AndReturn(
|
|
||||||
g_cli_mock)
|
|
||||||
self.m.StubOutWithMock(glance_utils, 'get_image_id')
|
|
||||||
|
|
||||||
# If update_image is None (create case), validation for initial image
|
# If update_image is None (create case), validation for initial image
|
||||||
# imageId_input will be invoked multiple times (for each server).
|
# imageId_input will be invoked multiple times (for each server).
|
||||||
@ -226,10 +220,10 @@ class AutoScalingGroupTest(HeatTestCase):
|
|||||||
# values and new property values will be done, but the order is not
|
# values and new property values will be done, but the order is not
|
||||||
# deterministic. Therefore, using mox.IgnoreArg() for the update case.
|
# deterministic. Therefore, using mox.IgnoreArg() for the update case.
|
||||||
if update_image is None:
|
if update_image is None:
|
||||||
glance_utils.get_image_id(g_cli_mock, imageId_input).\
|
glance.GlanceClientPlugin.get_image_id(imageId_input).\
|
||||||
MultipleTimes().AndReturn(imageId)
|
MultipleTimes().AndReturn(imageId)
|
||||||
else:
|
else:
|
||||||
glance_utils.get_image_id(g_cli_mock, mox.IgnoreArg()).\
|
glance.GlanceClientPlugin.get_image_id(mox.IgnoreArg()).\
|
||||||
MultipleTimes().AndReturn(imageId)
|
MultipleTimes().AndReturn(imageId)
|
||||||
|
|
||||||
def _stub_validate(self):
|
def _stub_validate(self):
|
||||||
@ -509,8 +503,7 @@ class AutoScalingGroupTest(HeatTestCase):
|
|||||||
num_reloads_expected_on_updt)
|
num_reloads_expected_on_updt)
|
||||||
self.stub_wallclock()
|
self.stub_wallclock()
|
||||||
self._mock_get_image_id_success('F20-x86_64-cfntools', 'image_id',
|
self._mock_get_image_id_success('F20-x86_64-cfntools', 'image_id',
|
||||||
update_image=update_image_id,
|
update_image=update_image_id)
|
||||||
mock_create=False)
|
|
||||||
|
|
||||||
stack.validate()
|
stack.validate()
|
||||||
self.m.ReplayAll()
|
self.m.ReplayAll()
|
||||||
|
@ -39,7 +39,6 @@ from heat.engine import environment
|
|||||||
from heat.engine import parser
|
from heat.engine import parser
|
||||||
from heat.engine.properties import Properties
|
from heat.engine.properties import Properties
|
||||||
from heat.engine import resource as res
|
from heat.engine import resource as res
|
||||||
from heat.engine.resources import glance_utils
|
|
||||||
from heat.engine.resources import instance as instances
|
from heat.engine.resources import instance as instances
|
||||||
from heat.engine.resources import nova_utils
|
from heat.engine.resources import nova_utils
|
||||||
from heat.engine import service
|
from heat.engine import service
|
||||||
@ -204,12 +203,8 @@ def setup_keystone_mocks(mocks, stack):
|
|||||||
|
|
||||||
def setup_mock_for_image_constraint(mocks, imageId_input,
|
def setup_mock_for_image_constraint(mocks, imageId_input,
|
||||||
imageId_output=744):
|
imageId_output=744):
|
||||||
g_cli_mock = mocks.CreateMockAnything()
|
mocks.StubOutWithMock(glance.GlanceClientPlugin, 'get_image_id')
|
||||||
mocks.StubOutWithMock(glance.GlanceClientPlugin, '_create')
|
glance.GlanceClientPlugin.get_image_id(imageId_input).\
|
||||||
glance.GlanceClientPlugin._create().AndReturn(
|
|
||||||
g_cli_mock)
|
|
||||||
mocks.StubOutWithMock(glance_utils, 'get_image_id')
|
|
||||||
glance_utils.get_image_id(g_cli_mock, imageId_input).\
|
|
||||||
MultipleTimes().AndReturn(imageId_output)
|
MultipleTimes().AndReturn(imageId_output)
|
||||||
|
|
||||||
|
|
||||||
|
@ -10,26 +10,29 @@
|
|||||||
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||||
# License for the specific language governing permissions and limitations
|
# License for the specific language governing permissions and limitations
|
||||||
# under the License.
|
# under the License.
|
||||||
"""Tests for :module:'heat.engine.resources.glance_utils'."""
|
|
||||||
|
|
||||||
import uuid
|
import uuid
|
||||||
|
|
||||||
from glanceclient import exc as glance_exceptions
|
from glanceclient import exc as glance_exceptions
|
||||||
|
|
||||||
from heat.common import exception
|
from heat.common import exception
|
||||||
from heat.engine.resources import glance_utils
|
|
||||||
from heat.tests.common import HeatTestCase
|
from heat.tests.common import HeatTestCase
|
||||||
|
from heat.tests import utils
|
||||||
|
|
||||||
|
|
||||||
class GlanceUtilsTests(HeatTestCase):
|
class GlanceUtilsTests(HeatTestCase):
|
||||||
"""
|
"""
|
||||||
Basic tests for the helper methods in
|
Basic tests for the helper methods in
|
||||||
:module:'heat.engine.resources.glance_utils'.
|
:module:'heat.engine.resources.clients.os.glance'.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
super(GlanceUtilsTests, self).setUp()
|
super(GlanceUtilsTests, self).setUp()
|
||||||
self.glance_client = self.m.CreateMockAnything()
|
self.glance_client = self.m.CreateMockAnything()
|
||||||
|
con = utils.dummy_context()
|
||||||
|
c = con.clients
|
||||||
|
self.glance_plugin = c.client_plugin('glance')
|
||||||
|
self.glance_plugin._client = self.glance_client
|
||||||
|
|
||||||
def test_get_image_id(self):
|
def test_get_image_id(self):
|
||||||
"""Tests the get_image_id function."""
|
"""Tests the get_image_id function."""
|
||||||
@ -45,12 +48,10 @@ class GlanceUtilsTests(HeatTestCase):
|
|||||||
filters = {'name': 'noimage'}
|
filters = {'name': 'noimage'}
|
||||||
self.glance_client.images.list(filters=filters).AndReturn([])
|
self.glance_client.images.list(filters=filters).AndReturn([])
|
||||||
self.m.ReplayAll()
|
self.m.ReplayAll()
|
||||||
self.assertEqual(img_id, glance_utils.get_image_id(
|
self.assertEqual(img_id, self.glance_plugin.get_image_id(img_id))
|
||||||
self.glance_client, img_id))
|
self.assertEqual(img_id, self.glance_plugin.get_image_id(img_name))
|
||||||
self.assertEqual(img_id, glance_utils.get_image_id(
|
self.assertRaises(exception.ImageNotFound,
|
||||||
self.glance_client, img_name))
|
self.glance_plugin.get_image_id, 'noimage')
|
||||||
self.assertRaises(exception.ImageNotFound, glance_utils.get_image_id,
|
|
||||||
self.glance_client, 'noimage')
|
|
||||||
self.m.VerifyAll()
|
self.m.VerifyAll()
|
||||||
|
|
||||||
def test_get_image_id_by_name_in_uuid(self):
|
def test_get_image_id_by_name_in_uuid(self):
|
||||||
@ -62,14 +63,13 @@ class GlanceUtilsTests(HeatTestCase):
|
|||||||
my_image.name = img_name
|
my_image.name = img_name
|
||||||
self.glance_client.images = self.m.CreateMockAnything()
|
self.glance_client.images = self.m.CreateMockAnything()
|
||||||
self.glance_client.images.get(img_name).AndRaise(
|
self.glance_client.images.get(img_name).AndRaise(
|
||||||
glance_exceptions.NotFound(404))
|
glance_exceptions.HTTPNotFound())
|
||||||
filters = {'name': img_name}
|
filters = {'name': img_name}
|
||||||
self.glance_client.images.list(filters=filters).MultipleTimes().\
|
self.glance_client.images.list(filters=filters).MultipleTimes().\
|
||||||
AndReturn([my_image])
|
AndReturn([my_image])
|
||||||
self.m.ReplayAll()
|
self.m.ReplayAll()
|
||||||
|
|
||||||
self.assertEqual(img_id, glance_utils.get_image_id(self.glance_client,
|
self.assertEqual(img_id, self.glance_plugin.get_image_id(img_name))
|
||||||
img_name))
|
|
||||||
self.m.VerifyAll()
|
self.m.VerifyAll()
|
||||||
|
|
||||||
def test_get_image_id_glance_exception(self):
|
def test_get_image_id_glance_exception(self):
|
||||||
@ -84,8 +84,8 @@ class GlanceUtilsTests(HeatTestCase):
|
|||||||
|
|
||||||
expected_error = "Error retrieving image list from glance: Error"
|
expected_error = "Error retrieving image list from glance: Error"
|
||||||
e = self.assertRaises(exception.Error,
|
e = self.assertRaises(exception.Error,
|
||||||
glance_utils.get_image_id_by_name,
|
self.glance_plugin.get_image_id_by_name,
|
||||||
self.glance_client, img_name)
|
img_name)
|
||||||
self.assertEqual(expected_error, str(e))
|
self.assertEqual(expected_error, str(e))
|
||||||
self.m.VerifyAll()
|
self.m.VerifyAll()
|
||||||
|
|
||||||
@ -96,15 +96,14 @@ class GlanceUtilsTests(HeatTestCase):
|
|||||||
my_image.name = img_name
|
my_image.name = img_name
|
||||||
self.glance_client.images = self.m.CreateMockAnything()
|
self.glance_client.images = self.m.CreateMockAnything()
|
||||||
self.glance_client.images.get(img_name).AndRaise(
|
self.glance_client.images.get(img_name).AndRaise(
|
||||||
glance_exceptions.NotFound(404))
|
glance_exceptions.HTTPNotFound())
|
||||||
filters = {'name': img_name}
|
filters = {'name': img_name}
|
||||||
self.glance_client.images.list(filters=filters).MultipleTimes().\
|
self.glance_client.images.list(filters=filters).MultipleTimes().\
|
||||||
AndReturn([])
|
AndReturn([])
|
||||||
self.m.ReplayAll()
|
self.m.ReplayAll()
|
||||||
|
|
||||||
self.assertRaises(exception.ImageNotFound,
|
self.assertRaises(exception.ImageNotFound,
|
||||||
glance_utils.get_image_id,
|
self.glance_plugin.get_image_id, img_name)
|
||||||
self.glance_client, img_name)
|
|
||||||
self.m.VerifyAll()
|
self.m.VerifyAll()
|
||||||
|
|
||||||
def test_get_image_id_name_ambiguity(self):
|
def test_get_image_id_name_ambiguity(self):
|
||||||
@ -120,6 +119,5 @@ class GlanceUtilsTests(HeatTestCase):
|
|||||||
AndReturn(image_list)
|
AndReturn(image_list)
|
||||||
self.m.ReplayAll()
|
self.m.ReplayAll()
|
||||||
self.assertRaises(exception.PhysicalResourceNameAmbiguity,
|
self.assertRaises(exception.PhysicalResourceNameAmbiguity,
|
||||||
glance_utils.get_image_id,
|
self.glance_plugin.get_image_id, img_name)
|
||||||
self.glance_client, img_name)
|
|
||||||
self.m.VerifyAll()
|
self.m.VerifyAll()
|
@ -13,28 +13,26 @@
|
|||||||
import mock
|
import mock
|
||||||
|
|
||||||
from heat.common import exception
|
from heat.common import exception
|
||||||
from heat.engine import clients
|
from heat.engine.clients.os import glance
|
||||||
from heat.engine.resources import glance_utils
|
|
||||||
from heat.engine.resources import image
|
|
||||||
from heat.tests.common import HeatTestCase
|
from heat.tests.common import HeatTestCase
|
||||||
from heat.tests import utils
|
from heat.tests import utils
|
||||||
|
|
||||||
|
|
||||||
class ImageConstraintTest(HeatTestCase):
|
class ImageConstraintTest(HeatTestCase):
|
||||||
|
|
||||||
@mock.patch.object(glance_utils, 'get_image_id')
|
def setUp(self):
|
||||||
def test_validation(self, mock_get_image):
|
super(ImageConstraintTest, self).setUp()
|
||||||
ctx = utils.dummy_context()
|
self.ctx = utils.dummy_context()
|
||||||
with mock.patch.object(clients, "OpenStackClients"):
|
self.mock_get_image = mock.Mock()
|
||||||
constraint = image.ImageConstraint()
|
self.ctx.clients.client_plugin(
|
||||||
mock_get_image.return_value = "id1"
|
'glance').get_image_id = self.mock_get_image
|
||||||
self.assertTrue(constraint.validate("foo", ctx))
|
self.constraint = glance.ImageConstraint()
|
||||||
|
|
||||||
@mock.patch.object(glance_utils, 'get_image_id')
|
def test_validation(self):
|
||||||
def test_validation_error(self, mock_get_image):
|
self.mock_get_image.return_value = "id1"
|
||||||
ctx = utils.dummy_context()
|
self.assertTrue(self.constraint.validate("foo", self.ctx))
|
||||||
with mock.patch.object(clients, "OpenStackClients"):
|
|
||||||
constraint = image.ImageConstraint()
|
def test_validation_error(self):
|
||||||
mock_get_image.side_effect = exception.ImageNotFound(
|
self.mock_get_image.side_effect = exception.ImageNotFound(
|
||||||
image_name='bar')
|
image_name='bar')
|
||||||
self.assertFalse(constraint.validate("bar", ctx))
|
self.assertFalse(self.constraint.validate("bar", self.ctx))
|
||||||
|
@ -25,8 +25,6 @@ from heat.engine.clients.os import nova
|
|||||||
from heat.engine import environment
|
from heat.engine import environment
|
||||||
from heat.engine import parser
|
from heat.engine import parser
|
||||||
from heat.engine import resource
|
from heat.engine import resource
|
||||||
from heat.engine.resources import glance_utils
|
|
||||||
from heat.engine.resources import image
|
|
||||||
from heat.engine.resources import instance as instances
|
from heat.engine.resources import instance as instances
|
||||||
from heat.engine.resources import network_interface
|
from heat.engine.resources import network_interface
|
||||||
from heat.engine.resources import nova_utils
|
from heat.engine.resources import nova_utils
|
||||||
@ -80,21 +78,13 @@ class InstancesTest(HeatTestCase):
|
|||||||
return (template, stack)
|
return (template, stack)
|
||||||
|
|
||||||
def _mock_get_image_id_success(self, imageId_input, imageId):
|
def _mock_get_image_id_success(self, imageId_input, imageId):
|
||||||
g_cli_mock = self.m.CreateMockAnything()
|
self.m.StubOutWithMock(glance.GlanceClientPlugin, 'get_image_id')
|
||||||
self.m.StubOutWithMock(glance.GlanceClientPlugin, '_create')
|
glance.GlanceClientPlugin.get_image_id(
|
||||||
glance.GlanceClientPlugin._create().AndReturn(
|
imageId_input).MultipleTimes().AndReturn(imageId)
|
||||||
g_cli_mock)
|
|
||||||
self.m.StubOutWithMock(glance_utils, 'get_image_id')
|
|
||||||
glance_utils.get_image_id(g_cli_mock, imageId_input).MultipleTimes().\
|
|
||||||
AndReturn(imageId)
|
|
||||||
|
|
||||||
def _mock_get_image_id_fail(self, image_id, exp):
|
def _mock_get_image_id_fail(self, image_id, exp):
|
||||||
g_cli_mock = self.m.CreateMockAnything()
|
self.m.StubOutWithMock(glance.GlanceClientPlugin, 'get_image_id')
|
||||||
self.m.StubOutWithMock(glance.GlanceClientPlugin, '_create')
|
glance.GlanceClientPlugin.get_image_id(image_id).AndRaise(exp)
|
||||||
glance.GlanceClientPlugin._create().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 _get_test_template(self, stack_name, image_id=None):
|
def _get_test_template(self, stack_name, image_id=None):
|
||||||
(tmpl, stack) = self._setup_test_stack(stack_name)
|
(tmpl, stack) = self._setup_test_stack(stack_name)
|
||||||
@ -712,8 +702,8 @@ class InstancesTest(HeatTestCase):
|
|||||||
instance = self._create_test_instance(return_server,
|
instance = self._create_test_instance(return_server,
|
||||||
'in_update2')
|
'in_update2')
|
||||||
|
|
||||||
self.m.StubOutWithMock(image.ImageConstraint, "validate")
|
self.m.StubOutWithMock(glance.ImageConstraint, "validate")
|
||||||
image.ImageConstraint.validate(
|
glance.ImageConstraint.validate(
|
||||||
mox.IgnoreArg(), mox.IgnoreArg()).MultipleTimes().AndReturn(True)
|
mox.IgnoreArg(), mox.IgnoreArg()).MultipleTimes().AndReturn(True)
|
||||||
self.m.ReplayAll()
|
self.m.ReplayAll()
|
||||||
|
|
||||||
|
@ -17,10 +17,10 @@ import mox
|
|||||||
|
|
||||||
from heat.common import exception
|
from heat.common import exception
|
||||||
from heat.common import template_format
|
from heat.common import template_format
|
||||||
|
from heat.engine.clients.os import glance
|
||||||
from heat.engine import parser
|
from heat.engine import parser
|
||||||
from heat.engine import resource
|
from heat.engine import resource
|
||||||
from heat.engine import resources
|
from heat.engine import resources
|
||||||
from heat.engine.resources import image
|
|
||||||
from heat.engine.resources import instance
|
from heat.engine.resources import instance
|
||||||
from heat.engine.resources import nova_keypair
|
from heat.engine.resources import nova_keypair
|
||||||
from heat.engine import rsrc_defn
|
from heat.engine import rsrc_defn
|
||||||
@ -75,8 +75,8 @@ class InstanceGroupTest(HeatTestCase):
|
|||||||
self.m.StubOutWithMock(nova_keypair.KeypairConstraint, 'validate')
|
self.m.StubOutWithMock(nova_keypair.KeypairConstraint, 'validate')
|
||||||
nova_keypair.KeypairConstraint.validate(
|
nova_keypair.KeypairConstraint.validate(
|
||||||
mox.IgnoreArg(), mox.IgnoreArg()).MultipleTimes().AndReturn(True)
|
mox.IgnoreArg(), mox.IgnoreArg()).MultipleTimes().AndReturn(True)
|
||||||
self.m.StubOutWithMock(image.ImageConstraint, 'validate')
|
self.m.StubOutWithMock(glance.ImageConstraint, 'validate')
|
||||||
image.ImageConstraint.validate(
|
glance.ImageConstraint.validate(
|
||||||
mox.IgnoreArg(), mox.IgnoreArg()).MultipleTimes().AndReturn(True)
|
mox.IgnoreArg(), mox.IgnoreArg()).MultipleTimes().AndReturn(True)
|
||||||
|
|
||||||
self.m.StubOutWithMock(instance_class, 'handle_create')
|
self.m.StubOutWithMock(instance_class, 'handle_create')
|
||||||
@ -165,8 +165,8 @@ class InstanceGroupTest(HeatTestCase):
|
|||||||
self.m.StubOutWithMock(nova_keypair.KeypairConstraint, 'validate')
|
self.m.StubOutWithMock(nova_keypair.KeypairConstraint, 'validate')
|
||||||
nova_keypair.KeypairConstraint.validate(
|
nova_keypair.KeypairConstraint.validate(
|
||||||
mox.IgnoreArg(), mox.IgnoreArg()).MultipleTimes().AndReturn(True)
|
mox.IgnoreArg(), mox.IgnoreArg()).MultipleTimes().AndReturn(True)
|
||||||
self.m.StubOutWithMock(image.ImageConstraint, 'validate')
|
self.m.StubOutWithMock(glance.ImageConstraint, 'validate')
|
||||||
image.ImageConstraint.validate(
|
glance.ImageConstraint.validate(
|
||||||
mox.IgnoreArg(), mox.IgnoreArg()).MultipleTimes().AndReturn(True)
|
mox.IgnoreArg(), mox.IgnoreArg()).MultipleTimes().AndReturn(True)
|
||||||
|
|
||||||
self.m.ReplayAll()
|
self.m.ReplayAll()
|
||||||
@ -230,8 +230,8 @@ class InstanceGroupTest(HeatTestCase):
|
|||||||
self.m.StubOutWithMock(nova_keypair.KeypairConstraint, 'validate')
|
self.m.StubOutWithMock(nova_keypair.KeypairConstraint, 'validate')
|
||||||
nova_keypair.KeypairConstraint.validate(
|
nova_keypair.KeypairConstraint.validate(
|
||||||
mox.IgnoreArg(), mox.IgnoreArg()).MultipleTimes().AndReturn(True)
|
mox.IgnoreArg(), mox.IgnoreArg()).MultipleTimes().AndReturn(True)
|
||||||
self.m.StubOutWithMock(image.ImageConstraint, 'validate')
|
self.m.StubOutWithMock(glance.ImageConstraint, 'validate')
|
||||||
image.ImageConstraint.validate(
|
glance.ImageConstraint.validate(
|
||||||
mox.IgnoreArg(), mox.IgnoreArg()).MultipleTimes().AndReturn(True)
|
mox.IgnoreArg(), mox.IgnoreArg()).MultipleTimes().AndReturn(True)
|
||||||
self.m.StubOutWithMock(instance.Instance, 'handle_create')
|
self.m.StubOutWithMock(instance.Instance, 'handle_create')
|
||||||
instance.Instance.handle_create().AndRaise(Exception)
|
instance.Instance.handle_create().AndRaise(Exception)
|
||||||
@ -277,8 +277,8 @@ class InstanceGroupTest(HeatTestCase):
|
|||||||
self.m.StubOutWithMock(nova_keypair.KeypairConstraint, 'validate')
|
self.m.StubOutWithMock(nova_keypair.KeypairConstraint, 'validate')
|
||||||
nova_keypair.KeypairConstraint.validate(
|
nova_keypair.KeypairConstraint.validate(
|
||||||
mox.IgnoreArg(), mox.IgnoreArg()).MultipleTimes().AndReturn(True)
|
mox.IgnoreArg(), mox.IgnoreArg()).MultipleTimes().AndReturn(True)
|
||||||
self.m.StubOutWithMock(image.ImageConstraint, 'validate')
|
self.m.StubOutWithMock(glance.ImageConstraint, 'validate')
|
||||||
image.ImageConstraint.validate(
|
glance.ImageConstraint.validate(
|
||||||
mox.IgnoreArg(), mox.IgnoreArg()).MultipleTimes().AndReturn(True)
|
mox.IgnoreArg(), mox.IgnoreArg()).MultipleTimes().AndReturn(True)
|
||||||
self.m.StubOutWithMock(instance.Instance, 'handle_create')
|
self.m.StubOutWithMock(instance.Instance, 'handle_create')
|
||||||
instance.Instance.handle_create().AndRaise(Exception)
|
instance.Instance.handle_create().AndRaise(Exception)
|
||||||
|
@ -19,10 +19,10 @@ from testtools.matchers import MatchesRegex
|
|||||||
|
|
||||||
from heat.common import exception
|
from heat.common import exception
|
||||||
from heat.common import template_format
|
from heat.common import template_format
|
||||||
|
from heat.engine.clients.os import glance
|
||||||
from heat.engine.clients.os import nova
|
from heat.engine.clients.os import nova
|
||||||
from heat.engine import function
|
from heat.engine import function
|
||||||
from heat.engine import parser
|
from heat.engine import parser
|
||||||
from heat.engine.resources import image
|
|
||||||
from heat.engine.resources import instance
|
from heat.engine.resources import instance
|
||||||
from heat.engine.resources import nova_keypair
|
from heat.engine.resources import nova_keypair
|
||||||
from heat.tests.common import HeatTestCase
|
from heat.tests.common import HeatTestCase
|
||||||
@ -169,8 +169,8 @@ class InstanceGroupTest(HeatTestCase):
|
|||||||
self.m.StubOutWithMock(nova_keypair.KeypairConstraint, 'validate')
|
self.m.StubOutWithMock(nova_keypair.KeypairConstraint, 'validate')
|
||||||
nova_keypair.KeypairConstraint.validate(
|
nova_keypair.KeypairConstraint.validate(
|
||||||
mox.IgnoreArg(), mox.IgnoreArg()).MultipleTimes().AndReturn(True)
|
mox.IgnoreArg(), mox.IgnoreArg()).MultipleTimes().AndReturn(True)
|
||||||
self.m.StubOutWithMock(image.ImageConstraint, 'validate')
|
self.m.StubOutWithMock(glance.ImageConstraint, 'validate')
|
||||||
image.ImageConstraint.validate(
|
glance.ImageConstraint.validate(
|
||||||
mox.IgnoreArg(), mox.IgnoreArg()).MultipleTimes().AndReturn(True)
|
mox.IgnoreArg(), mox.IgnoreArg()).MultipleTimes().AndReturn(True)
|
||||||
|
|
||||||
def _stub_grp_create(self, capacity):
|
def _stub_grp_create(self, capacity):
|
||||||
|
@ -18,7 +18,6 @@ from heat.engine.clients.os import glance
|
|||||||
from heat.engine.clients.os import nova
|
from heat.engine.clients.os import nova
|
||||||
from heat.engine import environment
|
from heat.engine import environment
|
||||||
from heat.engine import parser
|
from heat.engine import parser
|
||||||
from heat.engine.resources import glance_utils
|
|
||||||
from heat.engine.resources import instance as instances
|
from heat.engine.resources import instance as instances
|
||||||
from heat.engine.resources import network_interface as network_interfaces
|
from heat.engine.resources import network_interface as network_interfaces
|
||||||
from heat.engine.resources import nova_utils
|
from heat.engine.resources import nova_utils
|
||||||
@ -152,13 +151,9 @@ class instancesTest(HeatTestCase):
|
|||||||
self.fc = fakes.FakeClient()
|
self.fc = fakes.FakeClient()
|
||||||
|
|
||||||
def _mock_get_image_id_success(self, imageId_input, imageId):
|
def _mock_get_image_id_success(self, imageId_input, imageId):
|
||||||
g_cli_mock = self.m.CreateMockAnything()
|
self.m.StubOutWithMock(glance.GlanceClientPlugin, 'get_image_id')
|
||||||
self.m.StubOutWithMock(glance.GlanceClientPlugin, '_create')
|
glance.GlanceClientPlugin.get_image_id(
|
||||||
glance.GlanceClientPlugin._create().AndReturn(
|
imageId_input).MultipleTimes().AndReturn(imageId)
|
||||||
g_cli_mock)
|
|
||||||
self.m.StubOutWithMock(glance_utils, 'get_image_id')
|
|
||||||
glance_utils.get_image_id(g_cli_mock, imageId_input).MultipleTimes().\
|
|
||||||
AndReturn(imageId)
|
|
||||||
|
|
||||||
def _create_test_instance(self, return_server, name):
|
def _create_test_instance(self, return_server, name):
|
||||||
stack_name = '%s_s' % name
|
stack_name = '%s_s' % name
|
||||||
|
@ -23,7 +23,6 @@ from heat.common import template_format
|
|||||||
from heat.engine.clients.os import glance
|
from heat.engine.clients.os import glance
|
||||||
from heat.engine.clients.os import nova
|
from heat.engine.clients.os import nova
|
||||||
from heat.engine import resource
|
from heat.engine import resource
|
||||||
from heat.engine.resources import glance_utils
|
|
||||||
from heat.engine.resources import instance
|
from heat.engine.resources import instance
|
||||||
from heat.engine.resources import loadbalancer as lb
|
from heat.engine.resources import loadbalancer as lb
|
||||||
from heat.engine.resources import wait_condition as wc
|
from heat.engine.resources import wait_condition as wc
|
||||||
@ -124,12 +123,8 @@ class LoadBalancerTest(HeatTestCase):
|
|||||||
return rsrc
|
return rsrc
|
||||||
|
|
||||||
def _mock_get_image_id_success(self, imageId_input, imageId):
|
def _mock_get_image_id_success(self, imageId_input, imageId):
|
||||||
g_cli_mock = self.m.CreateMockAnything()
|
self.m.StubOutWithMock(glance.GlanceClientPlugin, 'get_image_id')
|
||||||
self.m.StubOutWithMock(glance.GlanceClientPlugin, '_create')
|
glance.GlanceClientPlugin.get_image_id(imageId_input).\
|
||||||
glance.GlanceClientPlugin._create().AndReturn(
|
|
||||||
g_cli_mock)
|
|
||||||
self.m.StubOutWithMock(glance_utils, 'get_image_id')
|
|
||||||
glance_utils.get_image_id(g_cli_mock, imageId_input).\
|
|
||||||
MultipleTimes().AndReturn(imageId)
|
MultipleTimes().AndReturn(imageId)
|
||||||
|
|
||||||
def _create_stubs(self, key_name='test', stub_meta=True):
|
def _create_stubs(self, key_name='test', stub_meta=True):
|
||||||
|
@ -18,9 +18,9 @@ from oslo.config import cfg
|
|||||||
|
|
||||||
from heat.common import identifier
|
from heat.common import identifier
|
||||||
from heat.common import template_format
|
from heat.common import template_format
|
||||||
|
from heat.engine.clients.os import glance
|
||||||
from heat.engine import environment
|
from heat.engine import environment
|
||||||
from heat.engine import parser
|
from heat.engine import parser
|
||||||
from heat.engine.resources import image
|
|
||||||
from heat.engine.resources import instance
|
from heat.engine.resources import instance
|
||||||
from heat.engine.resources import nova_keypair
|
from heat.engine.resources import nova_keypair
|
||||||
from heat.engine.resources import server
|
from heat.engine.resources import server
|
||||||
@ -168,8 +168,8 @@ class MetadataRefreshTest(HeatTestCase):
|
|||||||
self.m.StubOutWithMock(nova_keypair.KeypairConstraint, 'validate')
|
self.m.StubOutWithMock(nova_keypair.KeypairConstraint, 'validate')
|
||||||
nova_keypair.KeypairConstraint.validate(
|
nova_keypair.KeypairConstraint.validate(
|
||||||
mox.IgnoreArg(), mox.IgnoreArg()).MultipleTimes().AndReturn(True)
|
mox.IgnoreArg(), mox.IgnoreArg()).MultipleTimes().AndReturn(True)
|
||||||
self.m.StubOutWithMock(image.ImageConstraint, 'validate')
|
self.m.StubOutWithMock(glance.ImageConstraint, 'validate')
|
||||||
image.ImageConstraint.validate(
|
glance.ImageConstraint.validate(
|
||||||
mox.IgnoreArg(), mox.IgnoreArg()).MultipleTimes().AndReturn(True)
|
mox.IgnoreArg(), mox.IgnoreArg()).MultipleTimes().AndReturn(True)
|
||||||
|
|
||||||
self.m.StubOutWithMock(instance.Instance, 'handle_create')
|
self.m.StubOutWithMock(instance.Instance, 'handle_create')
|
||||||
@ -237,8 +237,8 @@ class WaitCondMetadataUpdateTest(HeatTestCase):
|
|||||||
self.m.StubOutWithMock(nova_keypair.KeypairConstraint, 'validate')
|
self.m.StubOutWithMock(nova_keypair.KeypairConstraint, 'validate')
|
||||||
nova_keypair.KeypairConstraint.validate(
|
nova_keypair.KeypairConstraint.validate(
|
||||||
mox.IgnoreArg(), mox.IgnoreArg()).MultipleTimes().AndReturn(True)
|
mox.IgnoreArg(), mox.IgnoreArg()).MultipleTimes().AndReturn(True)
|
||||||
self.m.StubOutWithMock(image.ImageConstraint, 'validate')
|
self.m.StubOutWithMock(glance.ImageConstraint, 'validate')
|
||||||
image.ImageConstraint.validate(
|
glance.ImageConstraint.validate(
|
||||||
mox.IgnoreArg(), mox.IgnoreArg()).MultipleTimes().AndReturn(True)
|
mox.IgnoreArg(), mox.IgnoreArg()).MultipleTimes().AndReturn(True)
|
||||||
|
|
||||||
self.m.StubOutWithMock(instance.Instance, 'handle_create')
|
self.m.StubOutWithMock(instance.Instance, 'handle_create')
|
||||||
@ -333,8 +333,8 @@ class MetadataRefreshTestServer(HeatTestCase):
|
|||||||
self.m.StubOutWithMock(nova_keypair.KeypairConstraint, 'validate')
|
self.m.StubOutWithMock(nova_keypair.KeypairConstraint, 'validate')
|
||||||
nova_keypair.KeypairConstraint.validate(
|
nova_keypair.KeypairConstraint.validate(
|
||||||
mox.IgnoreArg(), mox.IgnoreArg()).MultipleTimes().AndReturn(True)
|
mox.IgnoreArg(), mox.IgnoreArg()).MultipleTimes().AndReturn(True)
|
||||||
self.m.StubOutWithMock(image.ImageConstraint, 'validate')
|
self.m.StubOutWithMock(glance.ImageConstraint, 'validate')
|
||||||
image.ImageConstraint.validate(
|
glance.ImageConstraint.validate(
|
||||||
mox.IgnoreArg(), mox.IgnoreArg()).MultipleTimes().AndReturn(True)
|
mox.IgnoreArg(), mox.IgnoreArg()).MultipleTimes().AndReturn(True)
|
||||||
|
|
||||||
self.m.StubOutWithMock(server.Server, 'handle_create')
|
self.m.StubOutWithMock(server.Server, 'handle_create')
|
||||||
|
@ -20,9 +20,9 @@ from oslo.config import cfg
|
|||||||
|
|
||||||
from heat.common import template_format
|
from heat.common import template_format
|
||||||
from heat.db import api as db_api
|
from heat.db import api as db_api
|
||||||
|
from heat.engine.clients.os import glance
|
||||||
from heat.engine import environment
|
from heat.engine import environment
|
||||||
from heat.engine import parser
|
from heat.engine import parser
|
||||||
from heat.engine.resources import image
|
|
||||||
from heat.engine.resources import instance
|
from heat.engine.resources import instance
|
||||||
from heat.engine.resources import nova_utils
|
from heat.engine.resources import nova_utils
|
||||||
from heat.engine import template
|
from heat.engine import template
|
||||||
@ -129,7 +129,7 @@ class AutoScalingTest(HeatTestCase):
|
|||||||
|
|
||||||
self.m.StubOutWithMock(instance.Instance, 'handle_create')
|
self.m.StubOutWithMock(instance.Instance, 'handle_create')
|
||||||
self.m.StubOutWithMock(instance.Instance, 'check_create_complete')
|
self.m.StubOutWithMock(instance.Instance, 'check_create_complete')
|
||||||
self.m.StubOutWithMock(image.ImageConstraint, "validate")
|
self.m.StubOutWithMock(glance.ImageConstraint, "validate")
|
||||||
|
|
||||||
def test_lb(self):
|
def test_lb(self):
|
||||||
|
|
||||||
@ -278,7 +278,7 @@ class AutoScalingTest(HeatTestCase):
|
|||||||
instance.Instance.check_create_complete(mox.IgnoreArg())\
|
instance.Instance.check_create_complete(mox.IgnoreArg())\
|
||||||
.AndReturn(True)
|
.AndReturn(True)
|
||||||
|
|
||||||
image.ImageConstraint.validate(
|
glance.ImageConstraint.validate(
|
||||||
mox.IgnoreArg(), mox.IgnoreArg()).MultipleTimes().AndReturn(True)
|
mox.IgnoreArg(), mox.IgnoreArg()).MultipleTimes().AndReturn(True)
|
||||||
|
|
||||||
nova_utils.server_to_ipaddress(
|
nova_utils.server_to_ipaddress(
|
||||||
|
@ -14,7 +14,6 @@
|
|||||||
from heat.common import template_format
|
from heat.common import template_format
|
||||||
from heat.engine.clients.os import glance
|
from heat.engine.clients.os import glance
|
||||||
from heat.engine.clients.os import nova
|
from heat.engine.clients.os import nova
|
||||||
from heat.engine.resources import glance_utils
|
|
||||||
from heat.engine.resources import instance as instances
|
from heat.engine.resources import instance as instances
|
||||||
from heat.engine.resources import nova_utils
|
from heat.engine.resources import nova_utils
|
||||||
from heat.engine import scheduler
|
from heat.engine import scheduler
|
||||||
@ -62,13 +61,9 @@ class nokeyTest(HeatTestCase):
|
|||||||
|
|
||||||
self.m.StubOutWithMock(nova.NovaClientPlugin, '_create')
|
self.m.StubOutWithMock(nova.NovaClientPlugin, '_create')
|
||||||
nova.NovaClientPlugin._create().AndReturn(self.fc)
|
nova.NovaClientPlugin._create().AndReturn(self.fc)
|
||||||
g_cli_mock = self.m.CreateMockAnything()
|
self.m.StubOutWithMock(glance.GlanceClientPlugin, 'get_image_id')
|
||||||
self.m.StubOutWithMock(glance.GlanceClientPlugin, '_create')
|
glance.GlanceClientPlugin.get_image_id(
|
||||||
glance.GlanceClientPlugin._create().AndReturn(
|
'CentOS 5.2').MultipleTimes().AndReturn(1)
|
||||||
g_cli_mock)
|
|
||||||
self.m.StubOutWithMock(glance_utils, 'get_image_id')
|
|
||||||
glance_utils.get_image_id(g_cli_mock, 'CentOS 5.2').MultipleTimes().\
|
|
||||||
AndReturn(1)
|
|
||||||
|
|
||||||
# need to resolve the template functions
|
# need to resolve the template functions
|
||||||
server_userdata = nova_utils.build_userdata(
|
server_userdata = nova_utils.build_userdata(
|
||||||
|
@ -15,12 +15,12 @@ import mock
|
|||||||
|
|
||||||
from heat.common import exception
|
from heat.common import exception
|
||||||
from heat.common import template_format
|
from heat.common import template_format
|
||||||
|
from heat.engine.clients.os import glance
|
||||||
from heat.engine import environment
|
from heat.engine import environment
|
||||||
from heat.engine import parser
|
from heat.engine import parser
|
||||||
from heat.engine import resource
|
from heat.engine import resource
|
||||||
# imports for mocking
|
# imports for mocking
|
||||||
from heat.engine.resources import autoscaling
|
from heat.engine.resources import autoscaling
|
||||||
from heat.engine.resources import image
|
|
||||||
from heat.engine.resources import instance
|
from heat.engine.resources import instance
|
||||||
from heat.engine.resources import loadbalancer
|
from heat.engine.resources import loadbalancer
|
||||||
from heat.engine.resources import nova_keypair
|
from heat.engine.resources import nova_keypair
|
||||||
@ -167,7 +167,7 @@ class ScaleNotificationTest(common.HeatTestCase):
|
|||||||
def mock_stack_except_for_group(self):
|
def mock_stack_except_for_group(self):
|
||||||
self.m_validate = self.patchobject(parser.Stack, 'validate')
|
self.m_validate = self.patchobject(parser.Stack, 'validate')
|
||||||
self.patchobject(nova_keypair.KeypairConstraint, 'validate')
|
self.patchobject(nova_keypair.KeypairConstraint, 'validate')
|
||||||
self.patchobject(image.ImageConstraint, 'validate')
|
self.patchobject(glance.ImageConstraint, 'validate')
|
||||||
self.patchobject(instance.Instance, 'handle_create')\
|
self.patchobject(instance.Instance, 'handle_create')\
|
||||||
.return_value = True
|
.return_value = True
|
||||||
self.patchobject(instance.Instance, 'check_create_complete')\
|
self.patchobject(instance.Instance, 'check_create_complete')\
|
||||||
|
@ -26,8 +26,6 @@ from heat.engine.clients.os import nova
|
|||||||
from heat.engine import environment
|
from heat.engine import environment
|
||||||
from heat.engine import parser
|
from heat.engine import parser
|
||||||
from heat.engine import resource
|
from heat.engine import resource
|
||||||
from heat.engine.resources import glance_utils
|
|
||||||
from heat.engine.resources import image
|
|
||||||
from heat.engine.resources import nova_utils
|
from heat.engine.resources import nova_utils
|
||||||
from heat.engine.resources import server as servers
|
from heat.engine.resources import server as servers
|
||||||
from heat.engine.resources.software_config import software_config as sc
|
from heat.engine.resources.software_config import software_config as sc
|
||||||
@ -162,28 +160,18 @@ class ServersTest(HeatTestCase):
|
|||||||
return fake_interface(port, mac, ip)
|
return fake_interface(port, mac, ip)
|
||||||
|
|
||||||
def _mock_get_image_id_success(self, imageId_input, imageId,
|
def _mock_get_image_id_success(self, imageId_input, imageId,
|
||||||
server_rebuild=False,
|
server_rebuild=False):
|
||||||
mock_create=True):
|
self.m.StubOutWithMock(glance.GlanceClientPlugin, 'get_image_id')
|
||||||
g_cli_mock = self.m.CreateMockAnything()
|
glance.GlanceClientPlugin.get_image_id(
|
||||||
if mock_create:
|
imageId_input).MultipleTimes().AndReturn(imageId)
|
||||||
self.m.StubOutWithMock(glance.GlanceClientPlugin, '_create')
|
|
||||||
glance.GlanceClientPlugin._create().AndReturn(
|
|
||||||
g_cli_mock)
|
|
||||||
self.m.StubOutWithMock(glance_utils, 'get_image_id')
|
|
||||||
glance_utils.get_image_id(g_cli_mock, imageId_input).MultipleTimes().\
|
|
||||||
AndReturn(imageId)
|
|
||||||
|
|
||||||
if server_rebuild:
|
if server_rebuild:
|
||||||
glance_utils.get_image_id(g_cli_mock, 'F17-x86_64-gold').\
|
glance.GlanceClientPlugin.get_image_id('F17-x86_64-gold').\
|
||||||
MultipleTimes().AndReturn(744)
|
MultipleTimes().AndReturn(744)
|
||||||
|
|
||||||
def _mock_get_image_id_fail(self, image_id, exp):
|
def _mock_get_image_id_fail(self, image_id, exp):
|
||||||
g_cli_mock = self.m.CreateMockAnything()
|
self.m.StubOutWithMock(glance.GlanceClientPlugin, 'get_image_id')
|
||||||
self.m.StubOutWithMock(glance.GlanceClientPlugin, '_create')
|
glance.GlanceClientPlugin.get_image_id(image_id).AndRaise(exp)
|
||||||
glance.GlanceClientPlugin._create().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):
|
def _mock_get_keypair_success(self, keypair_input, keypair):
|
||||||
n_cli_mock = self.m.CreateMockAnything()
|
n_cli_mock = self.m.CreateMockAnything()
|
||||||
@ -835,8 +823,8 @@ class ServersTest(HeatTestCase):
|
|||||||
|
|
||||||
self.m.StubOutWithMock(nova.NovaClientPlugin, '_create')
|
self.m.StubOutWithMock(nova.NovaClientPlugin, '_create')
|
||||||
nova.NovaClientPlugin._create().AndReturn(self.fc)
|
nova.NovaClientPlugin._create().AndReturn(self.fc)
|
||||||
self.m.StubOutWithMock(image.ImageConstraint, "validate")
|
self.m.StubOutWithMock(glance.ImageConstraint, "validate")
|
||||||
image.ImageConstraint.validate(
|
glance.ImageConstraint.validate(
|
||||||
mox.IgnoreArg(), mox.IgnoreArg()).MultipleTimes().AndReturn(True)
|
mox.IgnoreArg(), mox.IgnoreArg()).MultipleTimes().AndReturn(True)
|
||||||
self.m.ReplayAll()
|
self.m.ReplayAll()
|
||||||
self.m.ReplayAll()
|
self.m.ReplayAll()
|
||||||
@ -1063,7 +1051,7 @@ class ServersTest(HeatTestCase):
|
|||||||
self.m.StubOutWithMock(self.fc.servers, 'set_meta')
|
self.m.StubOutWithMock(self.fc.servers, 'set_meta')
|
||||||
self.fc.servers.set_meta(new_return_server,
|
self.fc.servers.set_meta(new_return_server,
|
||||||
new_meta).AndReturn(None)
|
new_meta).AndReturn(None)
|
||||||
self._mock_get_image_id_success('CentOS 5.2', 1, mock_create=False)
|
self._mock_get_image_id_success('CentOS 5.2', 1)
|
||||||
self.m.ReplayAll()
|
self.m.ReplayAll()
|
||||||
update_template = copy.deepcopy(server.t)
|
update_template = copy.deepcopy(server.t)
|
||||||
update_template['Properties']['metadata'] = new_meta
|
update_template['Properties']['metadata'] = new_meta
|
||||||
@ -1213,8 +1201,8 @@ class ServersTest(HeatTestCase):
|
|||||||
image_id = self.getUniqueString()
|
image_id = self.getUniqueString()
|
||||||
self.m.StubOutWithMock(nova.NovaClientPlugin, '_create')
|
self.m.StubOutWithMock(nova.NovaClientPlugin, '_create')
|
||||||
nova.NovaClientPlugin._create().AndReturn(self.fc)
|
nova.NovaClientPlugin._create().AndReturn(self.fc)
|
||||||
self.m.StubOutWithMock(image.ImageConstraint, "validate")
|
self.m.StubOutWithMock(glance.ImageConstraint, "validate")
|
||||||
image.ImageConstraint.validate(
|
glance.ImageConstraint.validate(
|
||||||
mox.IgnoreArg(), mox.IgnoreArg()).MultipleTimes().AndReturn(True)
|
mox.IgnoreArg(), mox.IgnoreArg()).MultipleTimes().AndReturn(True)
|
||||||
self.m.ReplayAll()
|
self.m.ReplayAll()
|
||||||
|
|
||||||
@ -1323,8 +1311,8 @@ class ServersTest(HeatTestCase):
|
|||||||
server = self._create_test_server(return_server,
|
server = self._create_test_server(return_server,
|
||||||
'update_prop')
|
'update_prop')
|
||||||
|
|
||||||
self.m.StubOutWithMock(image.ImageConstraint, "validate")
|
self.m.StubOutWithMock(glance.ImageConstraint, "validate")
|
||||||
image.ImageConstraint.validate(
|
glance.ImageConstraint.validate(
|
||||||
mox.IgnoreArg(), mox.IgnoreArg()).MultipleTimes().AndReturn(True)
|
mox.IgnoreArg(), mox.IgnoreArg()).MultipleTimes().AndReturn(True)
|
||||||
self.m.ReplayAll()
|
self.m.ReplayAll()
|
||||||
|
|
||||||
@ -2451,12 +2439,12 @@ class ServersTest(HeatTestCase):
|
|||||||
def test_server_properties_validation_create_and_update(self):
|
def test_server_properties_validation_create_and_update(self):
|
||||||
return_server = self.fc.servers.list()[1]
|
return_server = self.fc.servers.list()[1]
|
||||||
|
|
||||||
self.m.StubOutWithMock(image.ImageConstraint, "validate")
|
self.m.StubOutWithMock(glance.ImageConstraint, "validate")
|
||||||
# verify that validate gets invoked exactly once for create
|
# verify that validate gets invoked exactly once for create
|
||||||
image.ImageConstraint.validate(
|
glance.ImageConstraint.validate(
|
||||||
'CentOS 5.2', mox.IgnoreArg()).AndReturn(True)
|
'CentOS 5.2', mox.IgnoreArg()).AndReturn(True)
|
||||||
# verify that validate gets invoked exactly once for update
|
# verify that validate gets invoked exactly once for update
|
||||||
image.ImageConstraint.validate(
|
glance.ImageConstraint.validate(
|
||||||
'Update Image', mox.IgnoreArg()).AndReturn(True)
|
'Update Image', mox.IgnoreArg()).AndReturn(True)
|
||||||
self.m.ReplayAll()
|
self.m.ReplayAll()
|
||||||
|
|
||||||
@ -2476,13 +2464,13 @@ class ServersTest(HeatTestCase):
|
|||||||
def test_server_properties_validation_create_and_update_fail(self):
|
def test_server_properties_validation_create_and_update_fail(self):
|
||||||
return_server = self.fc.servers.list()[1]
|
return_server = self.fc.servers.list()[1]
|
||||||
|
|
||||||
self.m.StubOutWithMock(image.ImageConstraint, "validate")
|
self.m.StubOutWithMock(glance.ImageConstraint, "validate")
|
||||||
# verify that validate gets invoked exactly once for create
|
# verify that validate gets invoked exactly once for create
|
||||||
image.ImageConstraint.validate(
|
glance.ImageConstraint.validate(
|
||||||
'CentOS 5.2', mox.IgnoreArg()).AndReturn(True)
|
'CentOS 5.2', mox.IgnoreArg()).AndReturn(True)
|
||||||
# verify that validate gets invoked exactly once for update
|
# verify that validate gets invoked exactly once for update
|
||||||
ex = exception.ImageNotFound(image_name='Update Image')
|
ex = exception.ImageNotFound(image_name='Update Image')
|
||||||
image.ImageConstraint.validate('Update Image',
|
glance.ImageConstraint.validate('Update Image',
|
||||||
mox.IgnoreArg()).AndRaise(ex)
|
mox.IgnoreArg()).AndRaise(ex)
|
||||||
self.m.ReplayAll()
|
self.m.ReplayAll()
|
||||||
|
|
||||||
|
@ -21,7 +21,6 @@ from heat.engine.clients.os import glance
|
|||||||
from heat.engine.clients.os import nova
|
from heat.engine.clients.os import nova
|
||||||
from heat.engine import environment
|
from heat.engine import environment
|
||||||
from heat.engine import parser
|
from heat.engine import parser
|
||||||
from heat.engine.resources import glance_utils
|
|
||||||
from heat.engine.resources import instance as instances
|
from heat.engine.resources import instance as instances
|
||||||
from heat.engine.resources import nova_utils
|
from heat.engine.resources import nova_utils
|
||||||
from heat.engine import scheduler
|
from heat.engine import scheduler
|
||||||
@ -131,16 +130,10 @@ class ServerTagsTest(HeatTestCase):
|
|||||||
super(ServerTagsTest, self).setUp()
|
super(ServerTagsTest, self).setUp()
|
||||||
self.fc = fakes.FakeClient()
|
self.fc = fakes.FakeClient()
|
||||||
|
|
||||||
def _mock_get_image_id_success(self, imageId_input, imageId,
|
def _mock_get_image_id_success(self, imageId_input, imageId):
|
||||||
mock_create=True):
|
self.m.StubOutWithMock(glance.GlanceClientPlugin, 'get_image_id')
|
||||||
g_cli_mock = self.m.CreateMockAnything()
|
glance.GlanceClientPlugin.get_image_id(
|
||||||
if mock_create:
|
imageId_input).MultipleTimes().AndReturn(imageId)
|
||||||
self.m.StubOutWithMock(glance.GlanceClientPlugin, '_create')
|
|
||||||
glance.GlanceClientPlugin._create().AndReturn(
|
|
||||||
g_cli_mock)
|
|
||||||
self.m.StubOutWithMock(glance_utils, 'get_image_id')
|
|
||||||
glance_utils.get_image_id(g_cli_mock, imageId_input).MultipleTimes().\
|
|
||||||
AndReturn(imageId)
|
|
||||||
|
|
||||||
def _setup_test_instance(self, intags=None, nova_tags=None):
|
def _setup_test_instance(self, intags=None, nova_tags=None):
|
||||||
stack_name = 'tag_test'
|
stack_name = 'tag_test'
|
||||||
@ -210,7 +203,7 @@ class ServerTagsTest(HeatTestCase):
|
|||||||
self.m.StubOutWithMock(self.fc.servers, 'set_meta')
|
self.m.StubOutWithMock(self.fc.servers, 'set_meta')
|
||||||
self.fc.servers.set_meta(self.fc.servers.list()[1],
|
self.fc.servers.set_meta(self.fc.servers.list()[1],
|
||||||
new_metadata).AndReturn(None)
|
new_metadata).AndReturn(None)
|
||||||
self._mock_get_image_id_success('CentOS 5.2', 1, False)
|
self._mock_get_image_id_success('CentOS 5.2', 1)
|
||||||
self.m.ReplayAll()
|
self.m.ReplayAll()
|
||||||
update_template = copy.deepcopy(instance.t)
|
update_template = copy.deepcopy(instance.t)
|
||||||
update_template['Properties']['Tags'] = new_tags
|
update_template['Properties']['Tags'] = new_tags
|
||||||
|
@ -30,7 +30,6 @@ from heat.engine.clients.os import nova
|
|||||||
from heat.engine import environment
|
from heat.engine import environment
|
||||||
from heat.engine import parser
|
from heat.engine import parser
|
||||||
from heat.engine.resource import Resource
|
from heat.engine.resource import Resource
|
||||||
from heat.engine.resources import glance_utils
|
|
||||||
from heat.engine.resources import instance as instances
|
from heat.engine.resources import instance as instances
|
||||||
from heat.engine import scheduler
|
from heat.engine import scheduler
|
||||||
from heat.openstack.common import timeutils
|
from heat.openstack.common import timeutils
|
||||||
@ -96,13 +95,9 @@ class SqlAlchemyTest(HeatTestCase):
|
|||||||
super(SqlAlchemyTest, self).tearDown()
|
super(SqlAlchemyTest, self).tearDown()
|
||||||
|
|
||||||
def _mock_get_image_id_success(self, imageId_input, imageId):
|
def _mock_get_image_id_success(self, imageId_input, imageId):
|
||||||
g_cli_mock = self.m.CreateMockAnything()
|
self.m.StubOutWithMock(glance.GlanceClientPlugin, 'get_image_id')
|
||||||
self.m.StubOutWithMock(glance.GlanceClientPlugin, '_create')
|
glance.GlanceClientPlugin.get_image_id(
|
||||||
glance.GlanceClientPlugin._create().AndReturn(
|
imageId_input).MultipleTimes().AndReturn(imageId)
|
||||||
g_cli_mock)
|
|
||||||
self.m.StubOutWithMock(glance_utils, 'get_image_id')
|
|
||||||
glance_utils.get_image_id(g_cli_mock, imageId_input).MultipleTimes().\
|
|
||||||
AndReturn(imageId)
|
|
||||||
|
|
||||||
def _setup_test_stack(self, stack_name, stack_id=None, owner_id=None,
|
def _setup_test_stack(self, stack_name, stack_id=None, owner_id=None,
|
||||||
stack_user_project_id=None):
|
stack_user_project_id=None):
|
||||||
|
@ -22,7 +22,6 @@ from heat.engine import environment
|
|||||||
from heat.engine.hot.template import HOTemplate
|
from heat.engine.hot.template import HOTemplate
|
||||||
from heat.engine import parser
|
from heat.engine import parser
|
||||||
from heat.engine import resources
|
from heat.engine import resources
|
||||||
from heat.engine.resources import glance_utils
|
|
||||||
from heat.engine import service
|
from heat.engine import service
|
||||||
from heat.tests.common import HeatTestCase
|
from heat.tests.common import HeatTestCase
|
||||||
from heat.tests import utils
|
from heat.tests import utils
|
||||||
@ -817,21 +816,13 @@ class validateTest(HeatTestCase):
|
|||||||
self.addCleanup(self.mock_warnings.stop)
|
self.addCleanup(self.mock_warnings.stop)
|
||||||
|
|
||||||
def _mock_get_image_id_success(self, imageId_input, imageId):
|
def _mock_get_image_id_success(self, imageId_input, imageId):
|
||||||
g_cli_mock = self.m.CreateMockAnything()
|
self.m.StubOutWithMock(glance.GlanceClientPlugin, 'get_image_id')
|
||||||
self.m.StubOutWithMock(glance.GlanceClientPlugin, '_create')
|
glance.GlanceClientPlugin.get_image_id(
|
||||||
glance.GlanceClientPlugin._create().AndReturn(
|
imageId_input).MultipleTimes().AndReturn(imageId)
|
||||||
g_cli_mock)
|
|
||||||
self.m.StubOutWithMock(glance_utils, 'get_image_id')
|
|
||||||
glance_utils.get_image_id(g_cli_mock, imageId_input).MultipleTimes().\
|
|
||||||
AndReturn(imageId)
|
|
||||||
|
|
||||||
def _mock_get_image_id_fail(self, image_id, exp):
|
def _mock_get_image_id_fail(self, image_id, exp):
|
||||||
g_cli_mock = self.m.CreateMockAnything()
|
self.m.StubOutWithMock(glance.GlanceClientPlugin, 'get_image_id')
|
||||||
self.m.StubOutWithMock(glance.GlanceClientPlugin, '_create')
|
glance.GlanceClientPlugin.get_image_id(image_id).AndRaise(exp)
|
||||||
glance.GlanceClientPlugin._create().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 test_validate_volumeattach_valid(self):
|
def test_validate_volumeattach_valid(self):
|
||||||
t = template_format.parse(test_template_volumeattach % 'vdq')
|
t = template_format.parse(test_template_volumeattach % 'vdq')
|
||||||
|
@ -24,8 +24,6 @@ from heat.common import template_format
|
|||||||
from heat.engine.clients.os import cinder
|
from heat.engine.clients.os import cinder
|
||||||
from heat.engine.clients.os import glance
|
from heat.engine.clients.os import glance
|
||||||
from heat.engine.clients.os import nova
|
from heat.engine.clients.os import nova
|
||||||
from heat.engine.resources import glance_utils
|
|
||||||
from heat.engine.resources import image
|
|
||||||
from heat.engine.resources import instance
|
from heat.engine.resources import instance
|
||||||
from heat.engine.resources import volume as vol
|
from heat.engine.resources import volume as vol
|
||||||
from heat.engine import rsrc_defn
|
from heat.engine import rsrc_defn
|
||||||
@ -215,12 +213,12 @@ class VolumeTest(HeatTestCase):
|
|||||||
self.m.StubOutWithMock(instance.Instance, 'check_create_complete')
|
self.m.StubOutWithMock(instance.Instance, 'check_create_complete')
|
||||||
self.m.StubOutWithMock(vol.VolumeAttachment, 'handle_create')
|
self.m.StubOutWithMock(vol.VolumeAttachment, 'handle_create')
|
||||||
self.m.StubOutWithMock(vol.VolumeAttachment, 'check_create_complete')
|
self.m.StubOutWithMock(vol.VolumeAttachment, 'check_create_complete')
|
||||||
self.m.StubOutWithMock(image.ImageConstraint, "validate")
|
self.m.StubOutWithMock(glance.ImageConstraint, "validate")
|
||||||
instance.Instance.handle_create().AndReturn(None)
|
instance.Instance.handle_create().AndReturn(None)
|
||||||
instance.Instance.check_create_complete(None).AndReturn(True)
|
instance.Instance.check_create_complete(None).AndReturn(True)
|
||||||
cinder.CinderClientPlugin._create().AndReturn(
|
cinder.CinderClientPlugin._create().AndReturn(
|
||||||
self.cinder_fc)
|
self.cinder_fc)
|
||||||
image.ImageConstraint.validate(
|
glance.ImageConstraint.validate(
|
||||||
mox.IgnoreArg(), mox.IgnoreArg()).MultipleTimes().AndReturn(True)
|
mox.IgnoreArg(), mox.IgnoreArg()).MultipleTimes().AndReturn(True)
|
||||||
vol_name = utils.PhysName(stack_name, 'DataVolume')
|
vol_name = utils.PhysName(stack_name, 'DataVolume')
|
||||||
self.cinder_fc.volumes.create(
|
self.cinder_fc.volumes.create(
|
||||||
@ -885,13 +883,9 @@ class VolumeTest(HeatTestCase):
|
|||||||
image_id = '46988116-6703-4623-9dbc-2bc6d284021b'
|
image_id = '46988116-6703-4623-9dbc-2bc6d284021b'
|
||||||
cinder.CinderClientPlugin._create().AndReturn(
|
cinder.CinderClientPlugin._create().AndReturn(
|
||||||
self.cinder_fc)
|
self.cinder_fc)
|
||||||
g_cli_mock = self.m.CreateMockAnything()
|
self.m.StubOutWithMock(glance.GlanceClientPlugin, 'get_image_id')
|
||||||
self.m.StubOutWithMock(glance.GlanceClientPlugin, '_create')
|
glance.GlanceClientPlugin.get_image_id(
|
||||||
glance.GlanceClientPlugin._create().AndReturn(
|
image_id).MultipleTimes().AndReturn(image_id)
|
||||||
g_cli_mock)
|
|
||||||
self.m.StubOutWithMock(glance_utils, 'get_image_id')
|
|
||||||
glance_utils.get_image_id(g_cli_mock, image_id).MultipleTimes().\
|
|
||||||
AndReturn(image_id)
|
|
||||||
|
|
||||||
self.cinder_fc.volumes.create(
|
self.cinder_fc.volumes.create(
|
||||||
size=1, availability_zone='nova',
|
size=1, availability_zone='nova',
|
||||||
|
@ -51,7 +51,7 @@ heat.clients =
|
|||||||
heat.constraints =
|
heat.constraints =
|
||||||
nova.flavor = heat.engine.resources.server:FlavorConstraint
|
nova.flavor = heat.engine.resources.server:FlavorConstraint
|
||||||
neutron.network = heat.engine.clients.os.neutron:NetworkConstraint
|
neutron.network = heat.engine.clients.os.neutron:NetworkConstraint
|
||||||
glance.image = heat.engine.resources.image:ImageConstraint
|
glance.image = heat.engine.clients.os.glance:ImageConstraint
|
||||||
iso_8601 = heat.engine.resources.iso_8601:ISO8601Constraint
|
iso_8601 = heat.engine.resources.iso_8601:ISO8601Constraint
|
||||||
nova.keypair = heat.engine.resources.nova_keypair:KeypairConstraint
|
nova.keypair = heat.engine.resources.nova_keypair:KeypairConstraint
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user