Native WaitConditionHandle move to common curl_cli
Move to a common curl_cli attribute, which can be used for both success (default) and failure (by passing appropriate status data, and optionally reason). This should allow a slightly more flexible interface than the current success/failure attributes, while still remaining simple, and enabling simpler portability between this and the alternative Swift signal implementation. Note this breaks compatibility with the attributes we just recently merged, but I'm assuming since it's so recent nobody is using it yet. The example template at https://review.openstack.org/#/c/106424/ has been updated to reflect the new interface. Change-Id: Iac09aaa60ef5c1de27c9eeca7c65eca41c06907e blueprint: native-waitcondition
This commit is contained in:
parent
b5f498654c
commit
7e742a4f91
@ -99,13 +99,11 @@ class HeatWaitConditionHandle(BaseWaitConditionHandle):
|
|||||||
ATTRIBUTES = (
|
ATTRIBUTES = (
|
||||||
TOKEN,
|
TOKEN,
|
||||||
ENDPOINT,
|
ENDPOINT,
|
||||||
CURL_CLI_SUCCESS,
|
CURL_CLI,
|
||||||
CURL_CLI_FAILURE,
|
|
||||||
) = (
|
) = (
|
||||||
'token',
|
'token',
|
||||||
'endpoint',
|
'endpoint',
|
||||||
'curl_cli_success',
|
'curl_cli',
|
||||||
'curl_cli_failure',
|
|
||||||
)
|
)
|
||||||
|
|
||||||
attributes_schema = {
|
attributes_schema = {
|
||||||
@ -117,14 +115,13 @@ class HeatWaitConditionHandle(BaseWaitConditionHandle):
|
|||||||
_('Endpoint/url which can be used for signalling handle'),
|
_('Endpoint/url which can be used for signalling handle'),
|
||||||
cache_mode=attributes.Schema.CACHE_NONE
|
cache_mode=attributes.Schema.CACHE_NONE
|
||||||
),
|
),
|
||||||
CURL_CLI_SUCCESS: attributes.Schema(
|
CURL_CLI: attributes.Schema(
|
||||||
_('Convenience attribute, provides curl CLI command '
|
_('Convenience attribute, provides curl CLI command '
|
||||||
'which can be used for signalling handle completion'),
|
'prefix, which can be used for signalling handle completion or '
|
||||||
cache_mode=attributes.Schema.CACHE_NONE
|
'failure. You can signal success by adding '
|
||||||
),
|
'--data-binary \'{"status": "SUCCESS"}\' '
|
||||||
CURL_CLI_FAILURE: attributes.Schema(
|
', or signal failure by adding '
|
||||||
_('Convenience attribute, provides curl CLI command '
|
'--data-binary \'{"status": "FAILURE"}\''),
|
||||||
'which can be used for signalling handle failure'),
|
|
||||||
cache_mode=attributes.Schema.CACHE_NONE
|
cache_mode=attributes.Schema.CACHE_NONE
|
||||||
),
|
),
|
||||||
}
|
}
|
||||||
@ -167,7 +164,7 @@ class HeatWaitConditionHandle(BaseWaitConditionHandle):
|
|||||||
return self.data().get('token')
|
return self.data().get('token')
|
||||||
elif key == self.ENDPOINT:
|
elif key == self.ENDPOINT:
|
||||||
return self.data().get('endpoint')
|
return self.data().get('endpoint')
|
||||||
elif key == self.CURL_CLI_SUCCESS:
|
elif key == self.CURL_CLI:
|
||||||
# Construct curl command for template-author convenience
|
# Construct curl command for template-author convenience
|
||||||
return ('curl -i -X POST '
|
return ('curl -i -X POST '
|
||||||
'-H \'X-Auth-Token: %(token)s\' '
|
'-H \'X-Auth-Token: %(token)s\' '
|
||||||
@ -176,16 +173,6 @@ class HeatWaitConditionHandle(BaseWaitConditionHandle):
|
|||||||
'%(endpoint)s' %
|
'%(endpoint)s' %
|
||||||
dict(token=self.data().get('token'),
|
dict(token=self.data().get('token'),
|
||||||
endpoint=self.data().get('endpoint')))
|
endpoint=self.data().get('endpoint')))
|
||||||
elif key == self.CURL_CLI_FAILURE:
|
|
||||||
return ('curl -i -X POST '
|
|
||||||
'--data-binary \'{"status": "%(status)s"}\' '
|
|
||||||
'-H \'X-Auth-Token: %(token)s\' '
|
|
||||||
'-H \'Content-Type: application/json\' '
|
|
||||||
'-H \'Accept: application/json\' '
|
|
||||||
'%(endpoint)s' %
|
|
||||||
dict(status=self.STATUS_FAILURE,
|
|
||||||
token=self.data().get('token'),
|
|
||||||
endpoint=self.data().get('endpoint')))
|
|
||||||
|
|
||||||
def handle_signal(self, details=None):
|
def handle_signal(self, details=None):
|
||||||
'''
|
'''
|
||||||
|
@ -1006,7 +1006,7 @@ class HeatWaitConditionTest(HeatTestCase):
|
|||||||
self.assertEqual(expected, handle.FnGetAtt('endpoint'))
|
self.assertEqual(expected, handle.FnGetAtt('endpoint'))
|
||||||
self.m.VerifyAll()
|
self.m.VerifyAll()
|
||||||
|
|
||||||
def test_getatt_curl_cli_success(self):
|
def test_getatt_curl_cli(self):
|
||||||
self.m.StubOutWithMock(heat_plugin.HeatClientPlugin, 'get_heat_url')
|
self.m.StubOutWithMock(heat_plugin.HeatClientPlugin, 'get_heat_url')
|
||||||
heat_plugin.HeatClientPlugin.get_heat_url().AndReturn(
|
heat_plugin.HeatClientPlugin.get_heat_url().AndReturn(
|
||||||
'foo/%s' % self.tenant_id)
|
'foo/%s' % self.tenant_id)
|
||||||
@ -1017,21 +1017,5 @@ class HeatWaitConditionTest(HeatTestCase):
|
|||||||
"-H 'Accept: application/json' "
|
"-H 'Accept: application/json' "
|
||||||
"foo/aprojectid/stacks/test_stack/%s/resources/wait_handle"
|
"foo/aprojectid/stacks/test_stack/%s/resources/wait_handle"
|
||||||
"/signal" % self.stack_id)
|
"/signal" % self.stack_id)
|
||||||
self.assertEqual(expected, handle.FnGetAtt('curl_cli_success'))
|
self.assertEqual(expected, handle.FnGetAtt('curl_cli'))
|
||||||
self.m.VerifyAll()
|
|
||||||
|
|
||||||
def test_getatt_curl_cli_failure(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()
|
|
||||||
handle = self._create_heat_handle()
|
|
||||||
expected = ("curl -i -X POST "
|
|
||||||
"--data-binary '{\"status\": \"FAILURE\"}' "
|
|
||||||
"-H 'X-Auth-Token: adomainusertoken' "
|
|
||||||
"-H 'Content-Type: application/json' "
|
|
||||||
"-H 'Accept: application/json' "
|
|
||||||
"foo/aprojectid/stacks/test_stack/%s/resources/wait_handle"
|
|
||||||
"/signal" % self.stack_id)
|
|
||||||
self.assertEqual(expected, handle.FnGetAtt('curl_cli_failure'))
|
|
||||||
self.m.VerifyAll()
|
self.m.VerifyAll()
|
||||||
|
Loading…
Reference in New Issue
Block a user