Merge "Remove mox from test_waitcondition"
This commit is contained in:
commit
c37bc8ca25
@ -15,7 +15,6 @@ import datetime
|
||||
import uuid
|
||||
|
||||
import mock
|
||||
import mox
|
||||
from oslo_serialization import jsonutils as json
|
||||
from oslo_utils import timeutils
|
||||
import six
|
||||
@ -163,27 +162,20 @@ class HeatWaitConditionTest(common.HeatTestCase):
|
||||
if stub:
|
||||
id = identifier.ResourceIdentifier('test_tenant', stack.name,
|
||||
stack.id, '', 'wait_handle')
|
||||
self.m.StubOutWithMock(h_wch.HeatWaitConditionHandle,
|
||||
'identifier')
|
||||
h_wch.HeatWaitConditionHandle.identifier(
|
||||
).MultipleTimes().AndReturn(id)
|
||||
self.patchobject(h_wch.HeatWaitConditionHandle, 'identifier',
|
||||
return_value=id)
|
||||
|
||||
if stub_status:
|
||||
self.m.StubOutWithMock(h_wch.HeatWaitConditionHandle,
|
||||
'get_status')
|
||||
self.patchobject(h_wch.HeatWaitConditionHandle, 'get_status')
|
||||
|
||||
return stack
|
||||
|
||||
def test_post_complete_to_handle(self):
|
||||
self.stack = self.create_stack()
|
||||
h_wch.HeatWaitConditionHandle.get_status().AndReturn(['SUCCESS'])
|
||||
h_wch.HeatWaitConditionHandle.get_status().AndReturn(['SUCCESS',
|
||||
'SUCCESS'])
|
||||
h_wch.HeatWaitConditionHandle.get_status().AndReturn(['SUCCESS',
|
||||
'SUCCESS',
|
||||
'SUCCESS'])
|
||||
|
||||
self.m.ReplayAll()
|
||||
mock_get_status = h_wch.HeatWaitConditionHandle.get_status
|
||||
mock_get_status.side_effect = ([['SUCCESS'],
|
||||
['SUCCESS', 'SUCCESS'],
|
||||
['SUCCESS', 'SUCCESS', 'SUCCESS']])
|
||||
|
||||
self.stack.create()
|
||||
|
||||
@ -194,18 +186,14 @@ class HeatWaitConditionTest(common.HeatTestCase):
|
||||
r = resource_objects.Resource.get_by_name_and_stack(
|
||||
self.stack.context, 'wait_handle', self.stack.id)
|
||||
self.assertEqual('wait_handle', r.name)
|
||||
self.m.VerifyAll()
|
||||
self.assertEqual(3, mock_get_status.call_count)
|
||||
|
||||
def test_post_failed_to_handle(self):
|
||||
self.stack = self.create_stack()
|
||||
h_wch.HeatWaitConditionHandle.get_status().AndReturn(['SUCCESS'])
|
||||
h_wch.HeatWaitConditionHandle.get_status().AndReturn(['SUCCESS',
|
||||
'SUCCESS'])
|
||||
h_wch.HeatWaitConditionHandle.get_status().AndReturn(['SUCCESS',
|
||||
'SUCCESS',
|
||||
'FAILURE'])
|
||||
|
||||
self.m.ReplayAll()
|
||||
mock_get_status = h_wch.HeatWaitConditionHandle.get_status
|
||||
mock_get_status.side_effect = ([['SUCCESS'],
|
||||
['SUCCESS', 'SUCCESS'],
|
||||
['SUCCESS', 'SUCCESS', 'FAILURE']])
|
||||
|
||||
self.stack.create()
|
||||
|
||||
@ -218,11 +206,10 @@ class HeatWaitConditionTest(common.HeatTestCase):
|
||||
r = resource_objects.Resource.get_by_name_and_stack(
|
||||
self.stack.context, 'wait_handle', self.stack.id)
|
||||
self.assertEqual('wait_handle', r.name)
|
||||
self.m.VerifyAll()
|
||||
self.assertEqual(3, mock_get_status.call_count)
|
||||
|
||||
def _test_wait_handle_invalid(self, tmpl, handle_name):
|
||||
self.stack = self.create_stack(template=tmpl)
|
||||
self.m.ReplayAll()
|
||||
self.stack.create()
|
||||
rsrc = self.stack['wait_condition']
|
||||
self.assertEqual((rsrc.CREATE, rsrc.FAILED), rsrc.state)
|
||||
@ -243,8 +230,7 @@ class HeatWaitConditionTest(common.HeatTestCase):
|
||||
self.stack = self.create_stack()
|
||||
|
||||
# Avoid the stack create exercising the timeout code at the same time
|
||||
self.m.StubOutWithMock(self.stack, 'timeout_secs')
|
||||
self.stack.timeout_secs().MultipleTimes().AndReturn(None)
|
||||
self.stack.timeout_secs = mock.Mock(return_value=None)
|
||||
|
||||
now = timeutils.utcnow()
|
||||
periods = [0, 0.001, 0.1, 4.1, 5.1]
|
||||
@ -256,8 +242,6 @@ class HeatWaitConditionTest(common.HeatTestCase):
|
||||
h_wch.HeatWaitConditionHandle.get_status(
|
||||
).MultipleTimes().AndReturn([])
|
||||
|
||||
self.m.ReplayAll()
|
||||
|
||||
self.stack.create()
|
||||
|
||||
rsrc = self.stack['wait_condition']
|
||||
@ -266,14 +250,12 @@ class HeatWaitConditionTest(common.HeatTestCase):
|
||||
reason = rsrc.status_reason
|
||||
self.assertTrue(reason.startswith('WaitConditionTimeout:'))
|
||||
|
||||
self.m.VerifyAll()
|
||||
|
||||
def _create_heat_wc_and_handle(self):
|
||||
self.stack = self.create_stack(
|
||||
template=test_template_heat_waitcondition)
|
||||
h_wch.HeatWaitConditionHandle.get_status().AndReturn(['SUCCESS'])
|
||||
mock_get_status = h_wch.HeatWaitConditionHandle.get_status
|
||||
mock_get_status.side_effect = ([['SUCCESS']])
|
||||
|
||||
self.m.ReplayAll()
|
||||
self.stack.create()
|
||||
|
||||
rsrc = self.stack['wait_condition']
|
||||
@ -284,10 +266,10 @@ class HeatWaitConditionTest(common.HeatTestCase):
|
||||
|
||||
handle = self.stack['wait_handle']
|
||||
self.assertEqual((handle.CREATE, handle.COMPLETE), handle.state)
|
||||
return (rsrc, handle)
|
||||
return (rsrc, handle, mock_get_status)
|
||||
|
||||
def test_data(self):
|
||||
rsrc, handle = self._create_heat_wc_and_handle()
|
||||
rsrc, handle, mock_get_status = self._create_heat_wc_and_handle()
|
||||
test_metadata = {'data': 'foo', 'reason': 'bar',
|
||||
'status': 'SUCCESS', 'id': '123'}
|
||||
ret = handle.handle_signal(details=test_metadata)
|
||||
@ -302,10 +284,10 @@ class HeatWaitConditionTest(common.HeatTestCase):
|
||||
self.assertEqual(json.loads(u'{"123": "foo", "456": "dog"}'),
|
||||
json.loads(wc_att))
|
||||
self.assertEqual('status:SUCCESS reason:cat', ret)
|
||||
self.m.VerifyAll()
|
||||
mock_get_status.assert_called_once()
|
||||
|
||||
def test_data_noid(self):
|
||||
rsrc, handle = self._create_heat_wc_and_handle()
|
||||
rsrc, handle, mock_get_status = self._create_heat_wc_and_handle()
|
||||
test_metadata = {'data': 'foo', 'reason': 'bar',
|
||||
'status': 'SUCCESS'}
|
||||
ret = handle.handle_signal(details=test_metadata)
|
||||
@ -320,10 +302,10 @@ class HeatWaitConditionTest(common.HeatTestCase):
|
||||
self.assertEqual(json.loads(u'{"1": "foo", "2": "dog"}'),
|
||||
json.loads(wc_att))
|
||||
self.assertEqual('status:SUCCESS reason:cat', ret)
|
||||
self.m.VerifyAll()
|
||||
mock_get_status.assert_called_once()
|
||||
|
||||
def test_data_nodata(self):
|
||||
rsrc, handle = self._create_heat_wc_and_handle()
|
||||
rsrc, handle, mock_get_status = self._create_heat_wc_and_handle()
|
||||
ret = handle.handle_signal()
|
||||
expected = 'status:SUCCESS reason:Signal 1 received'
|
||||
self.assertEqual(expected, ret)
|
||||
@ -334,10 +316,10 @@ class HeatWaitConditionTest(common.HeatTestCase):
|
||||
wc_att = rsrc.FnGetAtt('data')
|
||||
self.assertEqual(json.loads(u'{"1": null, "2": null}'),
|
||||
json.loads(wc_att))
|
||||
self.m.VerifyAll()
|
||||
mock_get_status.assert_called_once()
|
||||
|
||||
def test_data_partial_complete(self):
|
||||
rsrc, handle = self._create_heat_wc_and_handle()
|
||||
rsrc, handle, mock_get_status = self._create_heat_wc_and_handle()
|
||||
test_metadata = {'status': 'SUCCESS'}
|
||||
ret = handle.handle_signal(details=test_metadata)
|
||||
expected = 'status:SUCCESS reason:Signal 1 received'
|
||||
@ -352,13 +334,12 @@ class HeatWaitConditionTest(common.HeatTestCase):
|
||||
wc_att = rsrc.FnGetAtt('data')
|
||||
self.assertEqual(json.loads(u'{"1": null, "2": null}'),
|
||||
json.loads(wc_att))
|
||||
self.m.VerifyAll()
|
||||
mock_get_status.assert_called_once()
|
||||
|
||||
def _create_heat_handle(self,
|
||||
template=test_template_heat_waithandle_token):
|
||||
self.stack = self.create_stack(template=template, stub_status=False)
|
||||
|
||||
self.m.ReplayAll()
|
||||
self.stack.create()
|
||||
|
||||
handle = self.stack['wait_handle']
|
||||
@ -377,7 +358,6 @@ class HeatWaitConditionTest(common.HeatTestCase):
|
||||
md_expected = {'1': {'data': None, 'reason': 'Signal 1 received',
|
||||
'status': 'SUCCESS'}}
|
||||
self.assertEqual(md_expected, handle.metadata_get())
|
||||
self.m.VerifyAll()
|
||||
|
||||
def test_get_status_partial_complete(self):
|
||||
handle = self._create_heat_handle()
|
||||
@ -390,8 +370,6 @@ class HeatWaitConditionTest(common.HeatTestCase):
|
||||
'status': 'SUCCESS'}}
|
||||
self.assertEqual(md_expected, handle.metadata_get())
|
||||
|
||||
self.m.VerifyAll()
|
||||
|
||||
def test_get_status_failure(self):
|
||||
handle = self._create_heat_handle()
|
||||
test_metadata = {'status': 'FAILURE'}
|
||||
@ -403,33 +381,24 @@ class HeatWaitConditionTest(common.HeatTestCase):
|
||||
'status': 'FAILURE'}}
|
||||
self.assertEqual(md_expected, handle.metadata_get())
|
||||
|
||||
self.m.VerifyAll()
|
||||
|
||||
def test_getatt_token(self):
|
||||
handle = self._create_heat_handle()
|
||||
self.assertEqual('adomainusertoken', handle.FnGetAtt('token'))
|
||||
self.m.VerifyAll()
|
||||
|
||||
def test_getatt_endpoint(self):
|
||||
self.m.StubOutWithMock(heat_plugin.HeatClientPlugin, 'get_heat_url')
|
||||
heat_plugin.HeatClientPlugin.get_heat_url().AndReturn(
|
||||
'foo/%s' % self.tenant_id)
|
||||
self.m.ReplayAll()
|
||||
self.patchobject(heat_plugin.HeatClientPlugin, 'get_heat_url',
|
||||
return_value='foo/%s' % self.tenant_id)
|
||||
handle = self._create_heat_handle()
|
||||
expected = ('foo/aprojectid/stacks/test_stack/%s/resources/'
|
||||
'wait_handle/signal'
|
||||
% self.stack_id)
|
||||
self.assertEqual(expected, handle.FnGetAtt('endpoint'))
|
||||
self.m.VerifyAll()
|
||||
|
||||
def test_getatt_curl_cli(self):
|
||||
self.m.StubOutWithMock(heat_plugin.HeatClientPlugin, 'get_heat_url')
|
||||
heat_plugin.HeatClientPlugin.get_heat_url().AndReturn(
|
||||
'foo/%s' % self.tenant_id)
|
||||
self.m.StubOutWithMock(
|
||||
heat_plugin.HeatClientPlugin, 'get_insecure_option')
|
||||
heat_plugin.HeatClientPlugin.get_insecure_option().AndReturn(False)
|
||||
self.m.ReplayAll()
|
||||
self.patchobject(heat_plugin.HeatClientPlugin, 'get_heat_url',
|
||||
return_value='foo/%s' % self.tenant_id)
|
||||
self.patchobject(heat_plugin.HeatClientPlugin, 'get_insecure_option',
|
||||
return_value=False)
|
||||
handle = self._create_heat_handle()
|
||||
expected = ("curl -i -X POST -H 'X-Auth-Token: adomainusertoken' "
|
||||
"-H 'Content-Type: application/json' "
|
||||
@ -437,16 +406,12 @@ class HeatWaitConditionTest(common.HeatTestCase):
|
||||
"foo/aprojectid/stacks/test_stack/%s/resources/wait_handle"
|
||||
"/signal" % self.stack_id)
|
||||
self.assertEqual(expected, handle.FnGetAtt('curl_cli'))
|
||||
self.m.VerifyAll()
|
||||
|
||||
def test_getatt_curl_cli_insecure_true(self):
|
||||
self.m.StubOutWithMock(heat_plugin.HeatClientPlugin, 'get_heat_url')
|
||||
heat_plugin.HeatClientPlugin.get_heat_url().AndReturn(
|
||||
'foo/%s' % self.tenant_id)
|
||||
self.m.StubOutWithMock(
|
||||
heat_plugin.HeatClientPlugin, 'get_insecure_option')
|
||||
heat_plugin.HeatClientPlugin.get_insecure_option().AndReturn(True)
|
||||
self.m.ReplayAll()
|
||||
self.patchobject(heat_plugin.HeatClientPlugin, 'get_heat_url',
|
||||
return_value='foo/%s' % self.tenant_id)
|
||||
self.patchobject(heat_plugin.HeatClientPlugin, 'get_insecure_option',
|
||||
return_value=True)
|
||||
handle = self._create_heat_handle()
|
||||
expected = (
|
||||
"curl --insecure -i -X POST -H 'X-Auth-Token: adomainusertoken' "
|
||||
@ -455,7 +420,6 @@ class HeatWaitConditionTest(common.HeatTestCase):
|
||||
"foo/aprojectid/stacks/test_stack/%s/resources/wait_handle"
|
||||
"/signal" % self.stack_id)
|
||||
self.assertEqual(expected, handle.FnGetAtt('curl_cli'))
|
||||
self.m.VerifyAll()
|
||||
|
||||
def test_getatt_signal_heat(self):
|
||||
handle = self._create_heat_handle(
|
||||
@ -472,9 +436,6 @@ class HeatWaitConditionTest(common.HeatTestCase):
|
||||
self.assertIn('domain_id', signal)
|
||||
|
||||
def test_getatt_signal_swift(self):
|
||||
self.m.StubOutWithMock(swift_plugin.SwiftClientPlugin, 'get_temp_url')
|
||||
self.m.StubOutWithMock(swift_plugin.SwiftClientPlugin, 'client')
|
||||
|
||||
class mock_swift(object):
|
||||
@staticmethod
|
||||
def put_container(container, **kwargs):
|
||||
@ -484,15 +445,11 @@ class HeatWaitConditionTest(common.HeatTestCase):
|
||||
def put_object(container, object, contents, **kwargs):
|
||||
pass
|
||||
|
||||
swift_plugin.SwiftClientPlugin.client().AndReturn(mock_swift)
|
||||
swift_plugin.SwiftClientPlugin.client().AndReturn(mock_swift)
|
||||
swift_plugin.SwiftClientPlugin.client().AndReturn(mock_swift)
|
||||
swift_plugin.SwiftClientPlugin.get_temp_url(mox.IgnoreArg(),
|
||||
mox.IgnoreArg(),
|
||||
mox.IgnoreArg()
|
||||
).AndReturn('foo')
|
||||
|
||||
self.m.ReplayAll()
|
||||
mock_tempurl = self.patchobject(swift_plugin.SwiftClientPlugin,
|
||||
'get_temp_url',
|
||||
return_value='foo')
|
||||
self.patchobject(swift_plugin.SwiftClientPlugin, 'client',
|
||||
return_value=mock_swift)
|
||||
|
||||
handle = self._create_heat_handle(
|
||||
template=test_template_heat_waithandle_swift)
|
||||
@ -501,6 +458,7 @@ class HeatWaitConditionTest(common.HeatTestCase):
|
||||
self.assertIsNone(handle.FnGetAtt('curl_cli'))
|
||||
signal = json.loads(handle.FnGetAtt('signal'))
|
||||
self.assertIn('alarm_url', signal)
|
||||
mock_tempurl.assert_called_once()
|
||||
|
||||
@mock.patch('zaqarclient.queues.v2.queues.Queue.signed_url')
|
||||
def test_getatt_signal_zaqar(self, mock_signed_url):
|
||||
@ -528,7 +486,6 @@ class HeatWaitConditionTest(common.HeatTestCase):
|
||||
def test_create_update_updatehandle(self):
|
||||
self.stack = self.create_stack(
|
||||
template=test_template_update_waithandle, stub_status=False)
|
||||
self.m.ReplayAll()
|
||||
self.stack.create()
|
||||
|
||||
handle = self.stack['update_wait_handle']
|
||||
|
Loading…
Reference in New Issue
Block a user