Merge "Use mock in test_validate.py"
This commit is contained in:
commit
32fcda12bf
|
@ -21,7 +21,6 @@ from heat.common.i18n import _
|
||||||
from heat.common import template_format
|
from heat.common import template_format
|
||||||
from heat.common import urlfetch
|
from heat.common import urlfetch
|
||||||
from heat.engine.clients.os import glance
|
from heat.engine.clients.os import glance
|
||||||
from heat.engine.clients.os import nova
|
|
||||||
from heat.engine import environment
|
from heat.engine import environment
|
||||||
from heat.engine.hot import template as hot_tmpl
|
from heat.engine.hot import template as hot_tmpl
|
||||||
from heat.engine import resources
|
from heat.engine import resources
|
||||||
|
@ -915,17 +914,13 @@ class ValidateTest(common.HeatTestCase):
|
||||||
self.addCleanup(self.mock_isa.stop)
|
self.addCleanup(self.mock_isa.stop)
|
||||||
self.engine = service.EngineService('a', 't')
|
self.engine = service.EngineService('a', 't')
|
||||||
|
|
||||||
def _mock_get_image_id_success(self, imageId_input, imageId):
|
def _mock_get_image_id_success(self, imageId):
|
||||||
self.m.StubOutWithMock(glance.GlanceClientPlugin,
|
self.patchobject(glance.GlanceClientPlugin, 'find_image_by_name_or_id',
|
||||||
'find_image_by_name_or_id')
|
return_value=imageId)
|
||||||
glance.GlanceClientPlugin.find_image_by_name_or_id(
|
|
||||||
imageId_input).MultipleTimes().AndReturn(imageId)
|
|
||||||
|
|
||||||
def _mock_get_image_id_fail(self, image_id, exp):
|
def _mock_get_image_id_fail(self, exp):
|
||||||
self.m.StubOutWithMock(glance.GlanceClientPlugin,
|
self.patchobject(glance.GlanceClientPlugin, 'find_image_by_name_or_id',
|
||||||
'find_image_by_name_or_id')
|
side_effect=exp)
|
||||||
glance.GlanceClientPlugin.find_image_by_name_or_id(
|
|
||||||
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')
|
||||||
|
@ -1338,11 +1333,9 @@ class ValidateTest(common.HeatTestCase):
|
||||||
|
|
||||||
self.stub_FlavorConstraint_validate()
|
self.stub_FlavorConstraint_validate()
|
||||||
self.stub_ImageConstraint_validate()
|
self.stub_ImageConstraint_validate()
|
||||||
self.m.ReplayAll()
|
|
||||||
|
|
||||||
resource = stack['Instance']
|
resource = stack['Instance']
|
||||||
self.assertRaises(exception.StackValidationFailed, resource.validate)
|
self.assertRaises(exception.StackValidationFailed, resource.validate)
|
||||||
self.m.VerifyAll()
|
|
||||||
|
|
||||||
def test_unregistered_image(self):
|
def test_unregistered_image(self):
|
||||||
t = template_format.parse(test_template_image)
|
t = template_format.parse(test_template_image)
|
||||||
|
@ -1352,19 +1345,15 @@ class ValidateTest(common.HeatTestCase):
|
||||||
|
|
||||||
stack = parser.Stack(self.ctx, 'test_stack', template)
|
stack = parser.Stack(self.ctx, 'test_stack', template)
|
||||||
|
|
||||||
self._mock_get_image_id_fail('image_name',
|
self._mock_get_image_id_fail(exception.EntityNotFound(
|
||||||
exception.EntityNotFound(
|
entity='Image',
|
||||||
entity='Image',
|
name='image_name'))
|
||||||
name='image_name'))
|
|
||||||
self.stub_KeypairConstraint_validate()
|
self.stub_KeypairConstraint_validate()
|
||||||
self.stub_FlavorConstraint_validate()
|
self.stub_FlavorConstraint_validate()
|
||||||
self.m.ReplayAll()
|
|
||||||
|
|
||||||
resource = stack['Instance']
|
resource = stack['Instance']
|
||||||
self.assertRaises(exception.StackValidationFailed, resource.validate)
|
self.assertRaises(exception.StackValidationFailed, resource.validate)
|
||||||
|
|
||||||
self.m.VerifyAll()
|
|
||||||
|
|
||||||
def test_duplicated_image(self):
|
def test_duplicated_image(self):
|
||||||
t = template_format.parse(test_template_image)
|
t = template_format.parse(test_template_image)
|
||||||
template = tmpl.Template(t,
|
template = tmpl.Template(t,
|
||||||
|
@ -1373,66 +1362,56 @@ class ValidateTest(common.HeatTestCase):
|
||||||
|
|
||||||
stack = parser.Stack(self.ctx, 'test_stack', template)
|
stack = parser.Stack(self.ctx, 'test_stack', template)
|
||||||
|
|
||||||
self._mock_get_image_id_fail('image_name',
|
self._mock_get_image_id_fail(exception.PhysicalResourceNameAmbiguity(
|
||||||
exception.PhysicalResourceNameAmbiguity(
|
name='image_name'))
|
||||||
name='image_name'))
|
|
||||||
|
|
||||||
self.stub_KeypairConstraint_validate()
|
self.stub_KeypairConstraint_validate()
|
||||||
self.stub_FlavorConstraint_validate()
|
self.stub_FlavorConstraint_validate()
|
||||||
self.m.ReplayAll()
|
|
||||||
|
|
||||||
resource = stack['Instance']
|
resource = stack['Instance']
|
||||||
self.assertRaises(exception.StackValidationFailed,
|
self.assertRaises(exception.StackValidationFailed,
|
||||||
resource.validate)
|
resource.validate)
|
||||||
|
|
||||||
self.m.VerifyAll()
|
@mock.patch('heat.engine.clients.os.nova.NovaClientPlugin._create')
|
||||||
|
def test_invalid_security_groups_with_nics(self, mock_create):
|
||||||
def test_invalid_security_groups_with_nics(self):
|
|
||||||
t = template_format.parse(test_template_invalid_secgroups)
|
t = template_format.parse(test_template_invalid_secgroups)
|
||||||
template = tmpl.Template(t,
|
template = tmpl.Template(t,
|
||||||
env=environment.Environment(
|
env=environment.Environment(
|
||||||
{'KeyName': 'test'}))
|
{'KeyName': 'test'}))
|
||||||
stack = parser.Stack(self.ctx, 'test_stack', template)
|
stack = parser.Stack(self.ctx, 'test_stack', template)
|
||||||
|
|
||||||
self._mock_get_image_id_success('image_name', 'image_id')
|
self._mock_get_image_id_success('image_id')
|
||||||
|
|
||||||
self.m.StubOutWithMock(nova.NovaClientPlugin, '_create')
|
mock_create.return_value = self.fc
|
||||||
nova.NovaClientPlugin._create().AndReturn(self.fc)
|
|
||||||
self.m.ReplayAll()
|
|
||||||
|
|
||||||
resource = stack['Instance']
|
resource = stack['Instance']
|
||||||
self.assertRaises(exception.ResourcePropertyConflict,
|
self.assertRaises(exception.ResourcePropertyConflict,
|
||||||
resource.validate)
|
resource.validate)
|
||||||
self.m.VerifyAll()
|
|
||||||
|
|
||||||
def test_invalid_security_group_ids_with_nics(self):
|
@mock.patch('heat.engine.clients.os.nova.NovaClientPlugin._create')
|
||||||
|
def test_invalid_security_group_ids_with_nics(self, mock_create):
|
||||||
t = template_format.parse(test_template_invalid_secgroupids)
|
t = template_format.parse(test_template_invalid_secgroupids)
|
||||||
template = tmpl.Template(
|
template = tmpl.Template(
|
||||||
t, env=environment.Environment({'KeyName': 'test'}))
|
t, env=environment.Environment({'KeyName': 'test'}))
|
||||||
stack = parser.Stack(self.ctx, 'test_stack', template)
|
stack = parser.Stack(self.ctx, 'test_stack', template)
|
||||||
|
|
||||||
self._mock_get_image_id_success('image_name', 'image_id')
|
self._mock_get_image_id_success('image_id')
|
||||||
|
|
||||||
self.m.StubOutWithMock(nova.NovaClientPlugin, '_create')
|
mock_create.return_value = self.fc
|
||||||
nova.NovaClientPlugin._create().AndReturn(self.fc)
|
|
||||||
self.m.ReplayAll()
|
|
||||||
|
|
||||||
resource = stack['Instance']
|
resource = stack['Instance']
|
||||||
self.assertRaises(exception.ResourcePropertyConflict,
|
self.assertRaises(exception.ResourcePropertyConflict,
|
||||||
resource.validate)
|
resource.validate)
|
||||||
self.m.VerifyAll()
|
|
||||||
|
|
||||||
def test_client_exception_from_glance_client(self):
|
@mock.patch('heat.engine.clients.os.glance.GlanceClientPlugin.client')
|
||||||
|
def test_client_exception_from_glance_client(self, mock_client):
|
||||||
t = template_format.parse(test_template_glance_client_exception)
|
t = template_format.parse(test_template_glance_client_exception)
|
||||||
template = tmpl.Template(t)
|
template = tmpl.Template(t)
|
||||||
stack = parser.Stack(self.ctx, 'test_stack', template)
|
stack = parser.Stack(self.ctx, 'test_stack', template)
|
||||||
self.m.StubOutWithMock(glance.GlanceClientPlugin, 'client')
|
mock_client.return_value = self.gc
|
||||||
glance.GlanceClientPlugin.client().AndReturn(self.gc)
|
|
||||||
self.stub_FlavorConstraint_validate()
|
self.stub_FlavorConstraint_validate()
|
||||||
self.m.ReplayAll()
|
|
||||||
|
|
||||||
self.assertRaises(exception.StackValidationFailed, stack.validate)
|
self.assertRaises(exception.StackValidationFailed, stack.validate)
|
||||||
self.m.VerifyAll()
|
|
||||||
|
|
||||||
def test_validate_unique_logical_name(self):
|
def test_validate_unique_logical_name(self):
|
||||||
t = template_format.parse(test_template_unique_logical_name)
|
t = template_format.parse(test_template_unique_logical_name)
|
||||||
|
|
Loading…
Reference in New Issue