Merge "Apply nova flavor constraint for resources"

This commit is contained in:
Jenkins
2014-12-03 11:48:58 +00:00
committed by Gerrit Code Review
14 changed files with 67 additions and 21 deletions

View File

@@ -61,7 +61,10 @@ class LaunchConfiguration(resource.Resource):
INSTANCE_TYPE: properties.Schema(
properties.Schema.STRING,
_('Nova instance type (flavor).'),
required=True
required=True,
constraints=[
constraints.CustomConstraint('nova.flavor')
]
),
KEY_NAME: properties.Schema(
properties.Schema.STRING,

View File

@@ -178,7 +178,10 @@ class Instance(resource.Resource):
properties.Schema.STRING,
_('Nova instance type (flavor).'),
required=True,
update_allowed=True
update_allowed=True,
constraints=[
constraints.CustomConstraint('nova.flavor')
]
),
KEY_NAME: properties.Schema(
properties.Schema.STRING,

View File

@@ -149,7 +149,10 @@ class Server(stack_user.StackUser):
properties.Schema.STRING,
_('The ID or name of the flavor to boot onto.'),
required=True,
update_allowed=True
update_allowed=True,
constraints=[
constraints.CustomConstraint('nova.flavor')
]
),
FLAVOR_UPDATE_POLICY: properties.Schema(
properties.Schema.STRING,

View File

@@ -52,6 +52,7 @@ class TestAutoScalingGroupValidation(common.HeatTestCase):
stack = utils.parse_stack(t, params=inline_templates.as_params)
self.stub_ImageConstraint_validate()
self.stub_FlavorConstraint_validate()
self.m.ReplayAll()
self.assertRaises(exception.NotSupported,
self.validate_scaling_group, t,
@@ -68,6 +69,7 @@ class TestAutoScalingGroupValidation(common.HeatTestCase):
stack = utils.parse_stack(t, params=inline_templates.as_params)
self.stub_ImageConstraint_validate()
self.stub_FlavorConstraint_validate()
self.m.ReplayAll()
e = self.assertRaises(exception.StackValidationFailed,
@@ -87,6 +89,7 @@ class TestAutoScalingGroupValidation(common.HeatTestCase):
stack = utils.parse_stack(t, params=inline_templates.as_params)
self.stub_ImageConstraint_validate()
self.stub_FlavorConstraint_validate()
self.m.ReplayAll()
e = self.assertRaises(exception.StackValidationFailed,
@@ -106,7 +109,7 @@ class TestAutoScalingGroupValidation(common.HeatTestCase):
stack = utils.parse_stack(t, params=inline_templates.as_params)
self.stub_ImageConstraint_validate()
self.stub_FlavorConstraint_validate()
self.m.ReplayAll()
e = self.assertRaises(exception.StackValidationFailed,
self.validate_scaling_group, t,
@@ -125,6 +128,7 @@ class TestAutoScalingGroupValidation(common.HeatTestCase):
stack = utils.parse_stack(t, params=inline_templates.as_params)
self.stub_ImageConstraint_validate()
self.stub_FlavorConstraint_validate()
self.m.ReplayAll()
e = self.assertRaises(exception.StackValidationFailed,

View File

@@ -157,3 +157,8 @@ class HeatTestCase(testscenarios.WithScenarios,
for x in range(num):
glance.ImageConstraint.validate(
mox.IgnoreArg(), mox.IgnoreArg()).AndReturn(True)
def stub_FlavorConstraint_validate(self):
self.m.StubOutWithMock(nova.FlavorConstraint, 'validate')
nova.FlavorConstraint.validate(
mox.IgnoreArg(), mox.IgnoreArg()).MultipleTimes().AndReturn(True)

View File

@@ -112,6 +112,7 @@ class AutoScalingTest(common.HeatTestCase):
self.m.StubOutWithMock(instance.Instance, 'handle_create')
self.m.StubOutWithMock(instance.Instance, 'check_create_complete')
self.stub_ImageConstraint_validate()
self.stub_FlavorConstraint_validate()
if with_error:
instance.Instance.handle_create().AndRaise(
exception.Error(with_error))
@@ -128,6 +129,7 @@ class AutoScalingTest(common.HeatTestCase):
self.m.StubOutWithMock(server.Server, 'check_create_complete')
self.m.StubOutWithMock(server.Server, 'validate')
self.stub_ImageConstraint_validate()
self.stub_FlavorConstraint_validate()
server_test = object()
for x in range(num):
server.Server.handle_create().AndReturn(server_test)
@@ -466,6 +468,7 @@ class AutoScalingTest(common.HeatTestCase):
self.m.StubOutWithMock(instance.Instance, 'check_create_complete')
instance.Instance.handle_create().AndRaise(Exception)
self.stub_ImageConstraint_validate()
self.stub_FlavorConstraint_validate()
self.m.ReplayAll()
@@ -748,6 +751,7 @@ class AutoScalingTest(common.HeatTestCase):
stack = utils.parse_stack(t, params=self.params)
rsrc = stack['LaunchConfig']
self.stub_ImageConstraint_validate()
self.stub_FlavorConstraint_validate()
self.assertIsNone(rsrc.validate())
scheduler.TaskRunner(rsrc.create)()
self.assertEqual((rsrc.CREATE, rsrc.COMPLETE), rsrc.state)
@@ -772,6 +776,7 @@ class AutoScalingTest(common.HeatTestCase):
stack = utils.parse_stack(t, params=self.params)
self.stub_ImageConstraint_validate()
self.stub_FlavorConstraint_validate()
self.m.ReplayAll()
e = self.assertRaises(exception.StackValidationFailed,
@@ -792,6 +797,7 @@ class AutoScalingTest(common.HeatTestCase):
stack = utils.parse_stack(t, params=self.params)
self.stub_ImageConstraint_validate()
self.stub_FlavorConstraint_validate()
self.m.ReplayAll()
e = self.assertRaises(exception.StackValidationFailed,

View File

@@ -319,6 +319,7 @@ class AutoScalingGroupTest(common.HeatTestCase):
stack = utils.parse_stack(tmpl)
self.stub_ImageConstraint_validate()
self.stub_KeypairConstraint_validate()
self.stub_FlavorConstraint_validate()
self.m.ReplayAll()
stack.validate()
@@ -331,6 +332,7 @@ class AutoScalingGroupTest(common.HeatTestCase):
stack = utils.parse_stack(tmpl)
self.stub_ImageConstraint_validate()
self.stub_KeypairConstraint_validate()
self.stub_FlavorConstraint_validate()
self.m.ReplayAll()
stack.validate()
@@ -353,6 +355,7 @@ class AutoScalingGroupTest(common.HeatTestCase):
stack = utils.parse_stack(tmpl)
self.stub_ImageConstraint_validate()
self.stub_KeypairConstraint_validate()
self.stub_FlavorConstraint_validate()
self.m.ReplayAll()
stack.validate()
@@ -370,6 +373,7 @@ class AutoScalingGroupTest(common.HeatTestCase):
def test_parse_with_bad_update_policy(self):
self.stub_ImageConstraint_validate()
self.stub_KeypairConstraint_validate()
self.stub_FlavorConstraint_validate()
self.m.ReplayAll()
tmpl = template_format.parse(asg_tmpl_with_bad_updt_policy)
stack = utils.parse_stack(tmpl)
@@ -380,6 +384,7 @@ class AutoScalingGroupTest(common.HeatTestCase):
def test_parse_with_bad_pausetime_in_update_policy(self):
self.stub_ImageConstraint_validate()
self.stub_KeypairConstraint_validate()
self.stub_FlavorConstraint_validate()
self.m.ReplayAll()
tmpl = template_format.parse(asg_tmpl_with_default_updt_policy)
group = tmpl['Resources']['WebServerGroup']
@@ -451,6 +456,7 @@ class AutoScalingGroupTest(common.HeatTestCase):
self.stub_KeypairConstraint_validate()
self.stub_ImageConstraint_validate()
self.stub_FlavorConstraint_validate()
self.m.ReplayAll()
stack.validate()
@@ -461,6 +467,7 @@ class AutoScalingGroupTest(common.HeatTestCase):
size = int(stack['WebServerGroup'].properties['MinSize'])
self._stub_grp_create(size)
self.stub_ImageConstraint_validate()
self.stub_FlavorConstraint_validate()
self.m.ReplayAll()
stack.create()
self.m.VerifyAll()
@@ -518,6 +525,7 @@ class AutoScalingGroupTest(common.HeatTestCase):
self.stub_wallclock()
self.stub_ImageConstraint_validate()
self.stub_KeypairConstraint_validate()
self.stub_FlavorConstraint_validate()
self.m.ReplayAll()
stack.validate()
@@ -718,6 +726,7 @@ class AutoScalingGroupTest(common.HeatTestCase):
stack = utils.parse_stack(tmpl)
self.stub_ImageConstraint_validate()
self.stub_KeypairConstraint_validate()
self.stub_FlavorConstraint_validate()
self.m.ReplayAll()
stack.validate()
@@ -728,6 +737,7 @@ class AutoScalingGroupTest(common.HeatTestCase):
size = int(stack['WebServerGroup'].properties['MinSize'])
self._stub_grp_create(size)
self.stub_ImageConstraint_validate()
self.stub_FlavorConstraint_validate()
self.m.ReplayAll()
stack.create()
self.m.VerifyAll()
@@ -782,6 +792,7 @@ class AutoScalingGroupTest(common.HeatTestCase):
size = int(stack['WebServerGroup'].properties['MinSize'])
self._stub_grp_create(size)
self.stub_ImageConstraint_validate()
self.stub_FlavorConstraint_validate()
self.m.ReplayAll()
stack.create()
self.m.VerifyAll()
@@ -825,6 +836,7 @@ class AutoScalingGroupTest(common.HeatTestCase):
self.stub_KeypairConstraint_validate()
self.stub_ImageConstraint_validate()
self.stub_FlavorConstraint_validate()
self.m.ReplayAll()
stack.update(updated_stack)
self.m.VerifyAll()

View File

@@ -78,6 +78,7 @@ class InstanceGroupTest(common.HeatTestCase):
parser.Stack.validate()
self.stub_KeypairConstraint_validate()
self.stub_ImageConstraint_validate()
self.stub_FlavorConstraint_validate()
self.m.StubOutWithMock(instance_class, 'handle_create')
self.m.StubOutWithMock(instance_class, 'check_create_complete')
@@ -163,6 +164,7 @@ class InstanceGroupTest(common.HeatTestCase):
stack = utils.parse_stack(t)
self.stub_ImageConstraint_validate()
self.stub_KeypairConstraint_validate()
self.stub_FlavorConstraint_validate()
self.m.ReplayAll()
@@ -180,6 +182,7 @@ class InstanceGroupTest(common.HeatTestCase):
self.stub_KeypairConstraint_validate()
self.stub_ImageConstraint_validate()
self.stub_FlavorConstraint_validate()
self.m.ReplayAll()
@@ -241,6 +244,7 @@ class InstanceGroupTest(common.HeatTestCase):
parser.Stack.validate()
self.stub_ImageConstraint_validate()
self.stub_KeypairConstraint_validate()
self.stub_FlavorConstraint_validate()
self.m.StubOutWithMock(instance.Instance, 'handle_create')
instance.Instance.handle_create().AndRaise(Exception)
@@ -284,6 +288,7 @@ class InstanceGroupTest(common.HeatTestCase):
parser.Stack.validate()
self.stub_ImageConstraint_validate()
self.stub_KeypairConstraint_validate()
self.stub_FlavorConstraint_validate()
self.m.StubOutWithMock(instance.Instance, 'handle_create')
instance.Instance.handle_create().AndRaise(Exception)

View File

@@ -166,6 +166,7 @@ class InstanceGroupTest(common.HeatTestCase):
parser.Stack.validate().MultipleTimes()
self.stub_ImageConstraint_validate()
self.stub_KeypairConstraint_validate()
self.stub_FlavorConstraint_validate()
def _stub_grp_create(self, capacity):
"""
@@ -239,6 +240,7 @@ class InstanceGroupTest(common.HeatTestCase):
stack = utils.parse_stack(tmpl)
self.stub_ImageConstraint_validate()
self.stub_KeypairConstraint_validate()
self.stub_FlavorConstraint_validate()
self.m.ReplayAll()
stack.validate()
@@ -251,6 +253,7 @@ class InstanceGroupTest(common.HeatTestCase):
stack = utils.parse_stack(tmpl)
self.stub_ImageConstraint_validate()
self.stub_KeypairConstraint_validate()
self.stub_FlavorConstraint_validate()
self.m.ReplayAll()
stack.validate()
@@ -271,6 +274,7 @@ class InstanceGroupTest(common.HeatTestCase):
stack = utils.parse_stack(tmpl)
self.stub_ImageConstraint_validate()
self.stub_KeypairConstraint_validate()
self.stub_FlavorConstraint_validate()
self.m.ReplayAll()
stack.validate()
@@ -364,6 +368,7 @@ class InstanceGroupTest(common.HeatTestCase):
stack = utils.parse_stack(tmpl)
self.stub_KeypairConstraint_validate()
self.stub_ImageConstraint_validate()
self.stub_FlavorConstraint_validate()
self.m.ReplayAll()
stack.validate()
@@ -691,6 +696,7 @@ class InstanceGroupTest(common.HeatTestCase):
self.stub_KeypairConstraint_validate()
self.stub_ImageConstraint_validate()
self.stub_FlavorConstraint_validate()
self.m.ReplayAll()
stack.update(updated_stack)
self.assertEqual(('UPDATE', 'FAILED'), stack.state)

View File

@@ -164,6 +164,7 @@ class MetadataRefreshTest(common.HeatTestCase):
self.stub_ImageConstraint_validate()
self.stub_KeypairConstraint_validate()
self.stub_FlavorConstraint_validate()
self.m.StubOutWithMock(instance.Instance, 'handle_create')
self.m.StubOutWithMock(instance.Instance, 'check_create_complete')
@@ -227,6 +228,7 @@ class WaitCondMetadataUpdateTest(common.HeatTestCase):
self.stub_ImageConstraint_validate()
self.stub_KeypairConstraint_validate()
self.stub_FlavorConstraint_validate()
self.m.StubOutWithMock(instance.Instance, 'handle_create')
self.m.StubOutWithMock(instance.Instance, 'check_create_complete')
@@ -319,6 +321,7 @@ class MetadataRefreshTestServer(common.HeatTestCase):
self.stub_ImageConstraint_validate()
self.stub_KeypairConstraint_validate()
self.stub_FlavorConstraint_validate()
self.m.StubOutWithMock(server.Server, 'handle_create')
self.m.StubOutWithMock(server.Server, 'check_create_complete')

View File

@@ -20,7 +20,6 @@ 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.clients.os import nova
from heat.engine import environment
from heat.engine import parser
@@ -129,7 +128,6 @@ class AutoScalingTest(common.HeatTestCase):
self.m.StubOutWithMock(instance.Instance, 'handle_create')
self.m.StubOutWithMock(instance.Instance, 'check_create_complete')
self.m.StubOutWithMock(glance.ImageConstraint, "validate")
def test_lb(self):
@@ -255,10 +253,8 @@ class AutoScalingTest(common.HeatTestCase):
.AndReturn(False)
instance.Instance.check_create_complete(mox.IgnoreArg())\
.AndReturn(True)
glance.ImageConstraint.validate(
mox.IgnoreArg(), mox.IgnoreArg()).MultipleTimes().AndReturn(True)
self.stub_ImageConstraint_validate()
self.stub_FlavorConstraint_validate()
nova.NovaClientPlugin.server_to_ipaddress(
mox.IgnoreArg()).AndReturn('1.2.3.4')

View File

@@ -168,6 +168,7 @@ class ScaleNotificationTest(common.HeatTestCase):
self.m_validate = self.patchobject(parser.Stack, 'validate')
self.patchobject(nova.KeypairConstraint, 'validate')
self.patchobject(glance.ImageConstraint, 'validate')
self.patchobject(nova.FlavorConstraint, 'validate')
self.patchobject(instance.Instance, 'handle_create')\
.return_value = True
self.patchobject(instance.Instance, 'check_create_complete')\

View File

@@ -977,10 +977,9 @@ class ServersTest(common.HeatTestCase):
resource_defns = templ.resource_definitions(stack)
server = servers.Server('server_validate_test',
resource_defns['WebServer'], stack)
self.stub_ImageConstraint_validate()
self.stub_FlavorConstraint_validate()
self.m.StubOutWithMock(glance.ImageConstraint, "validate")
glance.ImageConstraint.validate(
mox.IgnoreArg(), mox.IgnoreArg()).MultipleTimes().AndReturn(True)
self.m.ReplayAll()
self.assertIsNone(server.validate())
@@ -1365,7 +1364,7 @@ class ServersTest(common.HeatTestCase):
resource_defns['WebServer'], stack)
update_template = copy.deepcopy(server.t)
update_template['Properties']['flavor'] = 'm1.smigish'
update_template['Properties']['flavor'] = 'm1.small'
updater = scheduler.TaskRunner(server.update, update_template)
self.assertRaises(resource.UpdateReplace, updater)
@@ -1386,7 +1385,7 @@ class ServersTest(common.HeatTestCase):
# the update then the updated policy is followed for a flavor
# update
update_template['Properties']['flavor_update_policy'] = 'REPLACE'
update_template['Properties']['flavor'] = 'm1.smigish'
update_template['Properties']['flavor'] = 'm1.small'
updater = scheduler.TaskRunner(server.update, update_template)
self.assertRaises(resource.UpdateReplace, updater)
@@ -1402,9 +1401,8 @@ class ServersTest(common.HeatTestCase):
image_id = self.getUniqueString()
self.m.StubOutWithMock(nova.NovaClientPlugin, '_create')
nova.NovaClientPlugin._create().AndReturn(self.fc)
self.m.StubOutWithMock(glance.ImageConstraint, "validate")
glance.ImageConstraint.validate(
mox.IgnoreArg(), mox.IgnoreArg()).MultipleTimes().AndReturn(True)
self.stub_ImageConstraint_validate()
self.m.ReplayAll()
update_template = copy.deepcopy(server.t)
@@ -1512,9 +1510,7 @@ class ServersTest(common.HeatTestCase):
server = self._create_test_server(return_server,
'update_prop')
self.m.StubOutWithMock(glance.ImageConstraint, "validate")
glance.ImageConstraint.validate(
mox.IgnoreArg(), mox.IgnoreArg()).MultipleTimes().AndReturn(True)
self.stub_ImageConstraint_validate()
self.m.ReplayAll()
update_template = copy.deepcopy(server.t)

View File

@@ -206,6 +206,7 @@ class ServerTagsTest(common.HeatTestCase):
new_metadata).AndReturn(None)
self.stub_ImageConstraint_validate()
self.stub_KeypairConstraint_validate()
self.stub_FlavorConstraint_validate()
self.m.ReplayAll()
update_template = copy.deepcopy(instance.t)
update_template['Properties']['Tags'] = new_tags
@@ -227,6 +228,7 @@ class ServerTagsTest(common.HeatTestCase):
conf = stack['Config']
self.stub_KeypairConstraint_validate()
self.stub_ImageConstraint_validate()
self.stub_FlavorConstraint_validate()
self.m.ReplayAll()
self.assertIsNone(conf.validate())
scheduler.TaskRunner(conf.create)()
@@ -278,6 +280,7 @@ class ServerTagsTest(common.HeatTestCase):
conf = stack['Config']
self.stub_ImageConstraint_validate()
self.stub_KeypairConstraint_validate()
self.stub_FlavorConstraint_validate()
self.m.ReplayAll()
self.assertIsNone(conf.validate())