Merge "Move glance_utils functions to glance client plugin"

This commit is contained in:
Jenkins 2014-07-24 13:56:18 +00:00 committed by Gerrit Code Review
commit 96b8a3f078
29 changed files with 201 additions and 317 deletions

View File

@ -16,7 +16,6 @@ import copy
from heat.common import exception
from heat.engine import attributes
from heat.engine import properties
from heat.engine.resources import glance_utils
from heat.engine.resources import nova_utils
from heat.engine.resources import server
from heat.openstack.common.gettextutils import _
@ -114,7 +113,7 @@ class CloudServer(server.Server):
"""Return the server's image ID."""
image = self.properties.get(self.IMAGE)
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
def _config_drive(self):

View File

@ -21,7 +21,6 @@ from heat.engine.clients.os import nova
from heat.engine import environment
from heat.engine import parser
from heat.engine import resource
from heat.engine.resources import glance_utils
from heat.engine import scheduler
from heat.openstack.common import uuidutils
from heat.tests.common import HeatTestCase
@ -68,12 +67,8 @@ class CloudServersTest(HeatTestCase):
cloud_server.CloudServer)
def _mock_get_image_id_success(self, imageId_input, imageId):
g_cli_mock = self.m.CreateMockAnything()
self.m.StubOutWithMock(glance.GlanceClientPlugin, '_create')
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().\
self.m.StubOutWithMock(glance.GlanceClientPlugin, 'get_image_id')
glance.GlanceClientPlugin.get_image_id(imageId_input).MultipleTimes().\
AndReturn(imageId)
def _stub_server_validate(self, server, imageId_input, image_id):

View File

@ -12,8 +12,16 @@
# under the License.
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 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):
@ -37,3 +45,57 @@ class GlanceClientPlugin(client_plugin.ClientPlugin):
}
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)

View File

@ -344,6 +344,11 @@ class Resource(object):
assert client_name, "Must specify 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):
return self.client('keystone')

View File

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

View File

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

View File

@ -21,7 +21,6 @@ from heat.engine import attributes
from heat.engine import constraints
from heat.engine import properties
from heat.engine import resource
from heat.engine.resources import glance_utils
from heat.engine.resources.network_interface import NetworkInterface
from heat.engine.resources.neutron import neutron
from heat.engine.resources import nova_utils
@ -439,7 +438,7 @@ class Instance(resource.Resource):
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)

View File

@ -22,7 +22,6 @@ from heat.engine import attributes
from heat.engine import constraints
from heat.engine import properties
from heat.engine import resource
from heat.engine.resources import glance_utils
from heat.engine.resources.neutron import subnet
from heat.engine.resources import nova_utils
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)
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)
@ -747,7 +746,7 @@ class Server(stack_user.StackUser):
if image_update_policy == 'REPLACE':
raise resource.UpdateReplace(self.name)
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:
server = self.nova().servers.get(self.resource_id)
preserve_ephemeral = (

View File

@ -21,7 +21,6 @@ from heat.engine import attributes
from heat.engine import constraints
from heat.engine import properties
from heat.engine import resource
from heat.engine.resources import glance_utils
from heat.engine import scheduler
from heat.engine import support
from heat.openstack.common import log as logging
@ -644,8 +643,8 @@ class CinderVolume(Volume):
'availability_zone': self.properties[self.AVAILABILITY_ZONE]
}
if self.properties.get(self.IMAGE):
arguments['imageRef'] = glance_utils.get_image_id(
self.glance(), self.properties[self.IMAGE])
arguments['imageRef'] = self.client_plugin('glance').get_image_id(
self.properties[self.IMAGE])
elif self.properties.get(self.IMAGE_REF):
arguments['imageRef'] = self.properties[self.IMAGE_REF]

View File

@ -21,11 +21,11 @@ from oslo.config import cfg
from heat.common import exception
from heat.common import short_id
from heat.common import template_format
from heat.engine.clients.os import glance
from heat.engine.notification import autoscaling as notification
from heat.engine import parser
from heat.engine import resource
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 loadbalancer
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):
self.m.StubOutWithMock(instance.Instance, 'handle_create')
self.m.StubOutWithMock(instance.Instance, 'check_create_complete')
self.m.StubOutWithMock(image.ImageConstraint, "validate")
image.ImageConstraint.validate(
self.m.StubOutWithMock(glance.ImageConstraint, "validate")
glance.ImageConstraint.validate(
mox.IgnoreArg(), mox.IgnoreArg()).MultipleTimes().AndReturn(True)
if with_error:
instance.Instance.handle_create().AndRaise(
@ -166,9 +166,9 @@ class AutoScalingTest(HeatTestCase):
cookie).MultipleTimes().AndReturn(True)
def _stub_image_validate(self, num=1):
self.m.StubOutWithMock(image.ImageConstraint, "validate")
self.m.StubOutWithMock(glance.ImageConstraint, "validate")
for x in range(num):
image.ImageConstraint.validate(
glance.ImageConstraint.validate(
mox.IgnoreArg(), mox.IgnoreArg()).AndReturn(True)
def _stub_delete(self, num):
@ -553,8 +553,8 @@ class AutoScalingTest(HeatTestCase):
self.m.StubOutWithMock(instance.Instance, 'handle_create')
self.m.StubOutWithMock(instance.Instance, 'check_create_complete')
instance.Instance.handle_create().AndRaise(Exception)
self.m.StubOutWithMock(image.ImageConstraint, "validate")
image.ImageConstraint.validate(
self.m.StubOutWithMock(glance.ImageConstraint, "validate")
glance.ImageConstraint.validate(
mox.IgnoreArg(), mox.IgnoreArg()).MultipleTimes().AndReturn(True)
self.m.ReplayAll()

View File

@ -25,7 +25,6 @@ from heat.engine.clients.os import nova
from heat.engine import function
from heat.engine.notification import stack as notification
from heat.engine import parser
from heat.engine.resources import glance_utils
from heat.engine.resources import instance
from heat.engine.resources import loadbalancer as lb
from heat.engine.resources import wait_condition as wc
@ -212,13 +211,8 @@ class AutoScalingGroupTest(HeatTestCase):
'http://127.0.0.1:8000/v1/waitcondition')
def _mock_get_image_id_success(self, imageId_input, imageId,
update_image=None, mock_create=True):
g_cli_mock = self.m.CreateMockAnything()
if mock_create:
self.m.StubOutWithMock(glance.GlanceClientPlugin, '_create')
glance.GlanceClientPlugin._create().AndReturn(
g_cli_mock)
self.m.StubOutWithMock(glance_utils, 'get_image_id')
update_image=None):
self.m.StubOutWithMock(glance.GlanceClientPlugin, 'get_image_id')
# If update_image is None (create case), validation for initial image
# 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
# deterministic. Therefore, using mox.IgnoreArg() for the update case.
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)
else:
glance_utils.get_image_id(g_cli_mock, mox.IgnoreArg()).\
glance.GlanceClientPlugin.get_image_id(mox.IgnoreArg()).\
MultipleTimes().AndReturn(imageId)
def _stub_validate(self):
@ -509,8 +503,7 @@ class AutoScalingGroupTest(HeatTestCase):
num_reloads_expected_on_updt)
self.stub_wallclock()
self._mock_get_image_id_success('F20-x86_64-cfntools', 'image_id',
update_image=update_image_id,
mock_create=False)
update_image=update_image_id)
stack.validate()
self.m.ReplayAll()

View File

@ -39,7 +39,6 @@ from heat.engine import environment
from heat.engine import parser
from heat.engine.properties import Properties
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 nova_utils
from heat.engine import service
@ -204,12 +203,8 @@ def setup_keystone_mocks(mocks, stack):
def setup_mock_for_image_constraint(mocks, imageId_input,
imageId_output=744):
g_cli_mock = mocks.CreateMockAnything()
mocks.StubOutWithMock(glance.GlanceClientPlugin, '_create')
glance.GlanceClientPlugin._create().AndReturn(
g_cli_mock)
mocks.StubOutWithMock(glance_utils, 'get_image_id')
glance_utils.get_image_id(g_cli_mock, imageId_input).\
mocks.StubOutWithMock(glance.GlanceClientPlugin, 'get_image_id')
glance.GlanceClientPlugin.get_image_id(imageId_input).\
MultipleTimes().AndReturn(imageId_output)

View File

@ -10,26 +10,29 @@
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
"""Tests for :module:'heat.engine.resources.glance_utils'."""
import uuid
from glanceclient import exc as glance_exceptions
from heat.common import exception
from heat.engine.resources import glance_utils
from heat.tests.common import HeatTestCase
from heat.tests import utils
class GlanceUtilsTests(HeatTestCase):
"""
Basic tests for the helper methods in
:module:'heat.engine.resources.glance_utils'.
:module:'heat.engine.resources.clients.os.glance'.
"""
def setUp(self):
super(GlanceUtilsTests, self).setUp()
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):
"""Tests the get_image_id function."""
@ -45,12 +48,10 @@ class GlanceUtilsTests(HeatTestCase):
filters = {'name': 'noimage'}
self.glance_client.images.list(filters=filters).AndReturn([])
self.m.ReplayAll()
self.assertEqual(img_id, glance_utils.get_image_id(
self.glance_client, img_id))
self.assertEqual(img_id, glance_utils.get_image_id(
self.glance_client, img_name))
self.assertRaises(exception.ImageNotFound, glance_utils.get_image_id,
self.glance_client, 'noimage')
self.assertEqual(img_id, self.glance_plugin.get_image_id(img_id))
self.assertEqual(img_id, self.glance_plugin.get_image_id(img_name))
self.assertRaises(exception.ImageNotFound,
self.glance_plugin.get_image_id, 'noimage')
self.m.VerifyAll()
def test_get_image_id_by_name_in_uuid(self):
@ -62,14 +63,13 @@ class GlanceUtilsTests(HeatTestCase):
my_image.name = img_name
self.glance_client.images = self.m.CreateMockAnything()
self.glance_client.images.get(img_name).AndRaise(
glance_exceptions.NotFound(404))
glance_exceptions.HTTPNotFound())
filters = {'name': img_name}
self.glance_client.images.list(filters=filters).MultipleTimes().\
AndReturn([my_image])
self.m.ReplayAll()
self.assertEqual(img_id, glance_utils.get_image_id(self.glance_client,
img_name))
self.assertEqual(img_id, self.glance_plugin.get_image_id(img_name))
self.m.VerifyAll()
def test_get_image_id_glance_exception(self):
@ -84,8 +84,8 @@ class GlanceUtilsTests(HeatTestCase):
expected_error = "Error retrieving image list from glance: Error"
e = self.assertRaises(exception.Error,
glance_utils.get_image_id_by_name,
self.glance_client, img_name)
self.glance_plugin.get_image_id_by_name,
img_name)
self.assertEqual(expected_error, str(e))
self.m.VerifyAll()
@ -96,15 +96,14 @@ class GlanceUtilsTests(HeatTestCase):
my_image.name = img_name
self.glance_client.images = self.m.CreateMockAnything()
self.glance_client.images.get(img_name).AndRaise(
glance_exceptions.NotFound(404))
glance_exceptions.HTTPNotFound())
filters = {'name': img_name}
self.glance_client.images.list(filters=filters).MultipleTimes().\
AndReturn([])
self.m.ReplayAll()
self.assertRaises(exception.ImageNotFound,
glance_utils.get_image_id,
self.glance_client, img_name)
self.glance_plugin.get_image_id, img_name)
self.m.VerifyAll()
def test_get_image_id_name_ambiguity(self):
@ -120,6 +119,5 @@ class GlanceUtilsTests(HeatTestCase):
AndReturn(image_list)
self.m.ReplayAll()
self.assertRaises(exception.PhysicalResourceNameAmbiguity,
glance_utils.get_image_id,
self.glance_client, img_name)
self.glance_plugin.get_image_id, img_name)
self.m.VerifyAll()

View File

@ -13,28 +13,26 @@
import mock
from heat.common import exception
from heat.engine import clients
from heat.engine.resources import glance_utils
from heat.engine.resources import image
from heat.engine.clients.os import glance
from heat.tests.common import HeatTestCase
from heat.tests import utils
class ImageConstraintTest(HeatTestCase):
@mock.patch.object(glance_utils, 'get_image_id')
def test_validation(self, mock_get_image):
ctx = utils.dummy_context()
with mock.patch.object(clients, "OpenStackClients"):
constraint = image.ImageConstraint()
mock_get_image.return_value = "id1"
self.assertTrue(constraint.validate("foo", ctx))
def setUp(self):
super(ImageConstraintTest, self).setUp()
self.ctx = utils.dummy_context()
self.mock_get_image = mock.Mock()
self.ctx.clients.client_plugin(
'glance').get_image_id = self.mock_get_image
self.constraint = glance.ImageConstraint()
@mock.patch.object(glance_utils, 'get_image_id')
def test_validation_error(self, mock_get_image):
ctx = utils.dummy_context()
with mock.patch.object(clients, "OpenStackClients"):
constraint = image.ImageConstraint()
mock_get_image.side_effect = exception.ImageNotFound(
def test_validation(self):
self.mock_get_image.return_value = "id1"
self.assertTrue(self.constraint.validate("foo", self.ctx))
def test_validation_error(self):
self.mock_get_image.side_effect = exception.ImageNotFound(
image_name='bar')
self.assertFalse(constraint.validate("bar", ctx))
self.assertFalse(self.constraint.validate("bar", self.ctx))

View File

@ -25,8 +25,6 @@ from heat.engine.clients.os import nova
from heat.engine import environment
from heat.engine import parser
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 network_interface
from heat.engine.resources import nova_utils
@ -80,21 +78,13 @@ class InstancesTest(HeatTestCase):
return (template, stack)
def _mock_get_image_id_success(self, imageId_input, imageId):
g_cli_mock = self.m.CreateMockAnything()
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)
self.m.StubOutWithMock(glance.GlanceClientPlugin, 'get_image_id')
glance.GlanceClientPlugin.get_image_id(
imageId_input).MultipleTimes().AndReturn(imageId)
def _mock_get_image_id_fail(self, image_id, exp):
g_cli_mock = self.m.CreateMockAnything()
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, image_id).AndRaise(exp)
self.m.StubOutWithMock(glance.GlanceClientPlugin, 'get_image_id')
glance.GlanceClientPlugin.get_image_id(image_id).AndRaise(exp)
def _get_test_template(self, stack_name, image_id=None):
(tmpl, stack) = self._setup_test_stack(stack_name)
@ -712,8 +702,8 @@ class InstancesTest(HeatTestCase):
instance = self._create_test_instance(return_server,
'in_update2')
self.m.StubOutWithMock(image.ImageConstraint, "validate")
image.ImageConstraint.validate(
self.m.StubOutWithMock(glance.ImageConstraint, "validate")
glance.ImageConstraint.validate(
mox.IgnoreArg(), mox.IgnoreArg()).MultipleTimes().AndReturn(True)
self.m.ReplayAll()

View File

@ -17,10 +17,10 @@ import mox
from heat.common import exception
from heat.common import template_format
from heat.engine.clients.os import glance
from heat.engine import parser
from heat.engine import resource
from heat.engine import resources
from heat.engine.resources import image
from heat.engine.resources import instance
from heat.engine.resources import nova_keypair
from heat.engine import rsrc_defn
@ -75,8 +75,8 @@ class InstanceGroupTest(HeatTestCase):
self.m.StubOutWithMock(nova_keypair.KeypairConstraint, 'validate')
nova_keypair.KeypairConstraint.validate(
mox.IgnoreArg(), mox.IgnoreArg()).MultipleTimes().AndReturn(True)
self.m.StubOutWithMock(image.ImageConstraint, 'validate')
image.ImageConstraint.validate(
self.m.StubOutWithMock(glance.ImageConstraint, 'validate')
glance.ImageConstraint.validate(
mox.IgnoreArg(), mox.IgnoreArg()).MultipleTimes().AndReturn(True)
self.m.StubOutWithMock(instance_class, 'handle_create')
@ -165,8 +165,8 @@ class InstanceGroupTest(HeatTestCase):
self.m.StubOutWithMock(nova_keypair.KeypairConstraint, 'validate')
nova_keypair.KeypairConstraint.validate(
mox.IgnoreArg(), mox.IgnoreArg()).MultipleTimes().AndReturn(True)
self.m.StubOutWithMock(image.ImageConstraint, 'validate')
image.ImageConstraint.validate(
self.m.StubOutWithMock(glance.ImageConstraint, 'validate')
glance.ImageConstraint.validate(
mox.IgnoreArg(), mox.IgnoreArg()).MultipleTimes().AndReturn(True)
self.m.ReplayAll()
@ -230,8 +230,8 @@ class InstanceGroupTest(HeatTestCase):
self.m.StubOutWithMock(nova_keypair.KeypairConstraint, 'validate')
nova_keypair.KeypairConstraint.validate(
mox.IgnoreArg(), mox.IgnoreArg()).MultipleTimes().AndReturn(True)
self.m.StubOutWithMock(image.ImageConstraint, 'validate')
image.ImageConstraint.validate(
self.m.StubOutWithMock(glance.ImageConstraint, 'validate')
glance.ImageConstraint.validate(
mox.IgnoreArg(), mox.IgnoreArg()).MultipleTimes().AndReturn(True)
self.m.StubOutWithMock(instance.Instance, 'handle_create')
instance.Instance.handle_create().AndRaise(Exception)
@ -277,8 +277,8 @@ class InstanceGroupTest(HeatTestCase):
self.m.StubOutWithMock(nova_keypair.KeypairConstraint, 'validate')
nova_keypair.KeypairConstraint.validate(
mox.IgnoreArg(), mox.IgnoreArg()).MultipleTimes().AndReturn(True)
self.m.StubOutWithMock(image.ImageConstraint, 'validate')
image.ImageConstraint.validate(
self.m.StubOutWithMock(glance.ImageConstraint, 'validate')
glance.ImageConstraint.validate(
mox.IgnoreArg(), mox.IgnoreArg()).MultipleTimes().AndReturn(True)
self.m.StubOutWithMock(instance.Instance, 'handle_create')
instance.Instance.handle_create().AndRaise(Exception)

View File

@ -19,10 +19,10 @@ from testtools.matchers import MatchesRegex
from heat.common import exception
from heat.common import template_format
from heat.engine.clients.os import glance
from heat.engine.clients.os import nova
from heat.engine import function
from heat.engine import parser
from heat.engine.resources import image
from heat.engine.resources import instance
from heat.engine.resources import nova_keypair
from heat.tests.common import HeatTestCase
@ -169,8 +169,8 @@ class InstanceGroupTest(HeatTestCase):
self.m.StubOutWithMock(nova_keypair.KeypairConstraint, 'validate')
nova_keypair.KeypairConstraint.validate(
mox.IgnoreArg(), mox.IgnoreArg()).MultipleTimes().AndReturn(True)
self.m.StubOutWithMock(image.ImageConstraint, 'validate')
image.ImageConstraint.validate(
self.m.StubOutWithMock(glance.ImageConstraint, 'validate')
glance.ImageConstraint.validate(
mox.IgnoreArg(), mox.IgnoreArg()).MultipleTimes().AndReturn(True)
def _stub_grp_create(self, capacity):

View File

@ -18,7 +18,6 @@ from heat.engine.clients.os import glance
from heat.engine.clients.os import nova
from heat.engine import environment
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 network_interface as network_interfaces
from heat.engine.resources import nova_utils
@ -152,13 +151,9 @@ class instancesTest(HeatTestCase):
self.fc = fakes.FakeClient()
def _mock_get_image_id_success(self, imageId_input, imageId):
g_cli_mock = self.m.CreateMockAnything()
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)
self.m.StubOutWithMock(glance.GlanceClientPlugin, 'get_image_id')
glance.GlanceClientPlugin.get_image_id(
imageId_input).MultipleTimes().AndReturn(imageId)
def _create_test_instance(self, return_server, name):
stack_name = '%s_s' % name

View File

@ -23,7 +23,6 @@ from heat.common import template_format
from heat.engine.clients.os import glance
from heat.engine.clients.os import nova
from heat.engine import resource
from heat.engine.resources import glance_utils
from heat.engine.resources import instance
from heat.engine.resources import loadbalancer as lb
from heat.engine.resources import wait_condition as wc
@ -124,12 +123,8 @@ class LoadBalancerTest(HeatTestCase):
return rsrc
def _mock_get_image_id_success(self, imageId_input, imageId):
g_cli_mock = self.m.CreateMockAnything()
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).\
self.m.StubOutWithMock(glance.GlanceClientPlugin, 'get_image_id')
glance.GlanceClientPlugin.get_image_id(imageId_input).\
MultipleTimes().AndReturn(imageId)
def _create_stubs(self, key_name='test', stub_meta=True):

View File

@ -18,9 +18,9 @@ from oslo.config import cfg
from heat.common import identifier
from heat.common import template_format
from heat.engine.clients.os import glance
from heat.engine import environment
from heat.engine import parser
from heat.engine.resources import image
from heat.engine.resources import instance
from heat.engine.resources import nova_keypair
from heat.engine.resources import server
@ -168,8 +168,8 @@ class MetadataRefreshTest(HeatTestCase):
self.m.StubOutWithMock(nova_keypair.KeypairConstraint, 'validate')
nova_keypair.KeypairConstraint.validate(
mox.IgnoreArg(), mox.IgnoreArg()).MultipleTimes().AndReturn(True)
self.m.StubOutWithMock(image.ImageConstraint, 'validate')
image.ImageConstraint.validate(
self.m.StubOutWithMock(glance.ImageConstraint, 'validate')
glance.ImageConstraint.validate(
mox.IgnoreArg(), mox.IgnoreArg()).MultipleTimes().AndReturn(True)
self.m.StubOutWithMock(instance.Instance, 'handle_create')
@ -237,8 +237,8 @@ class WaitCondMetadataUpdateTest(HeatTestCase):
self.m.StubOutWithMock(nova_keypair.KeypairConstraint, 'validate')
nova_keypair.KeypairConstraint.validate(
mox.IgnoreArg(), mox.IgnoreArg()).MultipleTimes().AndReturn(True)
self.m.StubOutWithMock(image.ImageConstraint, 'validate')
image.ImageConstraint.validate(
self.m.StubOutWithMock(glance.ImageConstraint, 'validate')
glance.ImageConstraint.validate(
mox.IgnoreArg(), mox.IgnoreArg()).MultipleTimes().AndReturn(True)
self.m.StubOutWithMock(instance.Instance, 'handle_create')
@ -333,8 +333,8 @@ class MetadataRefreshTestServer(HeatTestCase):
self.m.StubOutWithMock(nova_keypair.KeypairConstraint, 'validate')
nova_keypair.KeypairConstraint.validate(
mox.IgnoreArg(), mox.IgnoreArg()).MultipleTimes().AndReturn(True)
self.m.StubOutWithMock(image.ImageConstraint, 'validate')
image.ImageConstraint.validate(
self.m.StubOutWithMock(glance.ImageConstraint, 'validate')
glance.ImageConstraint.validate(
mox.IgnoreArg(), mox.IgnoreArg()).MultipleTimes().AndReturn(True)
self.m.StubOutWithMock(server.Server, 'handle_create')

View File

@ -20,9 +20,9 @@ from oslo.config import cfg
from heat.common import template_format
from heat.db import api as db_api
from heat.engine.clients.os import glance
from heat.engine import environment
from heat.engine import parser
from heat.engine.resources import image
from heat.engine.resources import instance
from heat.engine.resources import nova_utils
from heat.engine import template
@ -129,7 +129,7 @@ class AutoScalingTest(HeatTestCase):
self.m.StubOutWithMock(instance.Instance, 'handle_create')
self.m.StubOutWithMock(instance.Instance, 'check_create_complete')
self.m.StubOutWithMock(image.ImageConstraint, "validate")
self.m.StubOutWithMock(glance.ImageConstraint, "validate")
def test_lb(self):
@ -278,7 +278,7 @@ class AutoScalingTest(HeatTestCase):
instance.Instance.check_create_complete(mox.IgnoreArg())\
.AndReturn(True)
image.ImageConstraint.validate(
glance.ImageConstraint.validate(
mox.IgnoreArg(), mox.IgnoreArg()).MultipleTimes().AndReturn(True)
nova_utils.server_to_ipaddress(

View File

@ -14,7 +14,6 @@
from heat.common import template_format
from heat.engine.clients.os import glance
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 nova_utils
from heat.engine import scheduler
@ -62,13 +61,9 @@ class nokeyTest(HeatTestCase):
self.m.StubOutWithMock(nova.NovaClientPlugin, '_create')
nova.NovaClientPlugin._create().AndReturn(self.fc)
g_cli_mock = self.m.CreateMockAnything()
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, 'CentOS 5.2').MultipleTimes().\
AndReturn(1)
self.m.StubOutWithMock(glance.GlanceClientPlugin, 'get_image_id')
glance.GlanceClientPlugin.get_image_id(
'CentOS 5.2').MultipleTimes().AndReturn(1)
# need to resolve the template functions
server_userdata = nova_utils.build_userdata(

View File

@ -15,12 +15,12 @@ import mock
from heat.common import exception
from heat.common import template_format
from heat.engine.clients.os import glance
from heat.engine import environment
from heat.engine import parser
from heat.engine import resource
# imports for mocking
from heat.engine.resources import autoscaling
from heat.engine.resources import image
from heat.engine.resources import instance
from heat.engine.resources import loadbalancer
from heat.engine.resources import nova_keypair
@ -167,7 +167,7 @@ class ScaleNotificationTest(common.HeatTestCase):
def mock_stack_except_for_group(self):
self.m_validate = self.patchobject(parser.Stack, 'validate')
self.patchobject(nova_keypair.KeypairConstraint, 'validate')
self.patchobject(image.ImageConstraint, 'validate')
self.patchobject(glance.ImageConstraint, 'validate')
self.patchobject(instance.Instance, 'handle_create')\
.return_value = True
self.patchobject(instance.Instance, 'check_create_complete')\

View File

@ -26,8 +26,6 @@ from heat.engine.clients.os import nova
from heat.engine import environment
from heat.engine import parser
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 server as servers
from heat.engine.resources.software_config import software_config as sc
@ -162,28 +160,18 @@ class ServersTest(HeatTestCase):
return fake_interface(port, mac, ip)
def _mock_get_image_id_success(self, imageId_input, imageId,
server_rebuild=False,
mock_create=True):
g_cli_mock = self.m.CreateMockAnything()
if mock_create:
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)
server_rebuild=False):
self.m.StubOutWithMock(glance.GlanceClientPlugin, 'get_image_id')
glance.GlanceClientPlugin.get_image_id(
imageId_input).MultipleTimes().AndReturn(imageId)
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)
def _mock_get_image_id_fail(self, image_id, exp):
g_cli_mock = self.m.CreateMockAnything()
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, image_id).AndRaise(exp)
self.m.StubOutWithMock(glance.GlanceClientPlugin, 'get_image_id')
glance.GlanceClientPlugin.get_image_id(image_id).AndRaise(exp)
def _mock_get_keypair_success(self, keypair_input, keypair):
n_cli_mock = self.m.CreateMockAnything()
@ -835,8 +823,8 @@ class ServersTest(HeatTestCase):
self.m.StubOutWithMock(nova.NovaClientPlugin, '_create')
nova.NovaClientPlugin._create().AndReturn(self.fc)
self.m.StubOutWithMock(image.ImageConstraint, "validate")
image.ImageConstraint.validate(
self.m.StubOutWithMock(glance.ImageConstraint, "validate")
glance.ImageConstraint.validate(
mox.IgnoreArg(), mox.IgnoreArg()).MultipleTimes().AndReturn(True)
self.m.ReplayAll()
self.m.ReplayAll()
@ -1090,7 +1078,7 @@ class ServersTest(HeatTestCase):
self.m.StubOutWithMock(self.fc.servers, 'set_meta')
self.fc.servers.set_meta(new_return_server,
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()
update_template = copy.deepcopy(server.t)
update_template['Properties']['metadata'] = new_meta
@ -1240,8 +1228,8 @@ class ServersTest(HeatTestCase):
image_id = self.getUniqueString()
self.m.StubOutWithMock(nova.NovaClientPlugin, '_create')
nova.NovaClientPlugin._create().AndReturn(self.fc)
self.m.StubOutWithMock(image.ImageConstraint, "validate")
image.ImageConstraint.validate(
self.m.StubOutWithMock(glance.ImageConstraint, "validate")
glance.ImageConstraint.validate(
mox.IgnoreArg(), mox.IgnoreArg()).MultipleTimes().AndReturn(True)
self.m.ReplayAll()
@ -1350,8 +1338,8 @@ class ServersTest(HeatTestCase):
server = self._create_test_server(return_server,
'update_prop')
self.m.StubOutWithMock(image.ImageConstraint, "validate")
image.ImageConstraint.validate(
self.m.StubOutWithMock(glance.ImageConstraint, "validate")
glance.ImageConstraint.validate(
mox.IgnoreArg(), mox.IgnoreArg()).MultipleTimes().AndReturn(True)
self.m.ReplayAll()
@ -2478,12 +2466,12 @@ class ServersTest(HeatTestCase):
def test_server_properties_validation_create_and_update(self):
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
image.ImageConstraint.validate(
glance.ImageConstraint.validate(
'CentOS 5.2', mox.IgnoreArg()).AndReturn(True)
# verify that validate gets invoked exactly once for update
image.ImageConstraint.validate(
glance.ImageConstraint.validate(
'Update Image', mox.IgnoreArg()).AndReturn(True)
self.m.ReplayAll()
@ -2503,13 +2491,13 @@ class ServersTest(HeatTestCase):
def test_server_properties_validation_create_and_update_fail(self):
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
image.ImageConstraint.validate(
glance.ImageConstraint.validate(
'CentOS 5.2', mox.IgnoreArg()).AndReturn(True)
# verify that validate gets invoked exactly once for update
ex = exception.ImageNotFound(image_name='Update Image')
image.ImageConstraint.validate('Update Image',
glance.ImageConstraint.validate('Update Image',
mox.IgnoreArg()).AndRaise(ex)
self.m.ReplayAll()

View File

@ -21,7 +21,6 @@ from heat.engine.clients.os import glance
from heat.engine.clients.os import nova
from heat.engine import environment
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 nova_utils
from heat.engine import scheduler
@ -131,16 +130,10 @@ class ServerTagsTest(HeatTestCase):
super(ServerTagsTest, self).setUp()
self.fc = fakes.FakeClient()
def _mock_get_image_id_success(self, imageId_input, imageId,
mock_create=True):
g_cli_mock = self.m.CreateMockAnything()
if mock_create:
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 _mock_get_image_id_success(self, imageId_input, imageId):
self.m.StubOutWithMock(glance.GlanceClientPlugin, 'get_image_id')
glance.GlanceClientPlugin.get_image_id(
imageId_input).MultipleTimes().AndReturn(imageId)
def _setup_test_instance(self, intags=None, nova_tags=None):
stack_name = 'tag_test'
@ -210,7 +203,7 @@ class ServerTagsTest(HeatTestCase):
self.m.StubOutWithMock(self.fc.servers, 'set_meta')
self.fc.servers.set_meta(self.fc.servers.list()[1],
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()
update_template = copy.deepcopy(instance.t)
update_template['Properties']['Tags'] = new_tags

View File

@ -30,7 +30,6 @@ from heat.engine.clients.os import nova
from heat.engine import environment
from heat.engine import parser
from heat.engine.resource import Resource
from heat.engine.resources import glance_utils
from heat.engine.resources import instance as instances
from heat.engine import scheduler
from heat.openstack.common import timeutils
@ -96,13 +95,9 @@ class SqlAlchemyTest(HeatTestCase):
super(SqlAlchemyTest, self).tearDown()
def _mock_get_image_id_success(self, imageId_input, imageId):
g_cli_mock = self.m.CreateMockAnything()
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)
self.m.StubOutWithMock(glance.GlanceClientPlugin, 'get_image_id')
glance.GlanceClientPlugin.get_image_id(
imageId_input).MultipleTimes().AndReturn(imageId)
def _setup_test_stack(self, stack_name, stack_id=None, owner_id=None,
stack_user_project_id=None):

View File

@ -22,7 +22,6 @@ from heat.engine import environment
from heat.engine.hot.template import HOTemplate
from heat.engine import parser
from heat.engine import resources
from heat.engine.resources import glance_utils
from heat.engine import service
from heat.tests.common import HeatTestCase
from heat.tests import utils
@ -817,21 +816,13 @@ class validateTest(HeatTestCase):
self.addCleanup(self.mock_warnings.stop)
def _mock_get_image_id_success(self, imageId_input, imageId):
g_cli_mock = self.m.CreateMockAnything()
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)
self.m.StubOutWithMock(glance.GlanceClientPlugin, 'get_image_id')
glance.GlanceClientPlugin.get_image_id(
imageId_input).MultipleTimes().AndReturn(imageId)
def _mock_get_image_id_fail(self, image_id, exp):
g_cli_mock = self.m.CreateMockAnything()
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, image_id).AndRaise(exp)
self.m.StubOutWithMock(glance.GlanceClientPlugin, 'get_image_id')
glance.GlanceClientPlugin.get_image_id(image_id).AndRaise(exp)
def test_validate_volumeattach_valid(self):
t = template_format.parse(test_template_volumeattach % 'vdq')

View File

@ -24,8 +24,6 @@ from heat.common import template_format
from heat.engine.clients.os import cinder
from heat.engine.clients.os import glance
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 volume as vol
from heat.engine import rsrc_defn
@ -215,12 +213,12 @@ class VolumeTest(HeatTestCase):
self.m.StubOutWithMock(instance.Instance, 'check_create_complete')
self.m.StubOutWithMock(vol.VolumeAttachment, 'handle_create')
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.check_create_complete(None).AndReturn(True)
cinder.CinderClientPlugin._create().AndReturn(
self.cinder_fc)
image.ImageConstraint.validate(
glance.ImageConstraint.validate(
mox.IgnoreArg(), mox.IgnoreArg()).MultipleTimes().AndReturn(True)
vol_name = utils.PhysName(stack_name, 'DataVolume')
self.cinder_fc.volumes.create(
@ -885,13 +883,9 @@ class VolumeTest(HeatTestCase):
image_id = '46988116-6703-4623-9dbc-2bc6d284021b'
cinder.CinderClientPlugin._create().AndReturn(
self.cinder_fc)
g_cli_mock = self.m.CreateMockAnything()
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, image_id).MultipleTimes().\
AndReturn(image_id)
self.m.StubOutWithMock(glance.GlanceClientPlugin, 'get_image_id')
glance.GlanceClientPlugin.get_image_id(
image_id).MultipleTimes().AndReturn(image_id)
self.cinder_fc.volumes.create(
size=1, availability_zone='nova',

View File

@ -51,7 +51,7 @@ heat.clients =
heat.constraints =
nova.flavor = heat.engine.resources.server:FlavorConstraint
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
nova.keypair = heat.engine.resources.nova_keypair:KeypairConstraint