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 = (
|
||||
TOKEN,
|
||||
ENDPOINT,
|
||||
CURL_CLI_SUCCESS,
|
||||
CURL_CLI_FAILURE,
|
||||
CURL_CLI,
|
||||
) = (
|
||||
'token',
|
||||
'endpoint',
|
||||
'curl_cli_success',
|
||||
'curl_cli_failure',
|
||||
'curl_cli',
|
||||
)
|
||||
|
||||
attributes_schema = {
|
||||
@ -117,14 +115,13 @@ class HeatWaitConditionHandle(BaseWaitConditionHandle):
|
||||
_('Endpoint/url which can be used for signalling handle'),
|
||||
cache_mode=attributes.Schema.CACHE_NONE
|
||||
),
|
||||
CURL_CLI_SUCCESS: attributes.Schema(
|
||||
CURL_CLI: attributes.Schema(
|
||||
_('Convenience attribute, provides curl CLI command '
|
||||
'which can be used for signalling handle completion'),
|
||||
cache_mode=attributes.Schema.CACHE_NONE
|
||||
),
|
||||
CURL_CLI_FAILURE: attributes.Schema(
|
||||
_('Convenience attribute, provides curl CLI command '
|
||||
'which can be used for signalling handle failure'),
|
||||
'prefix, which can be used for signalling handle completion or '
|
||||
'failure. You can signal success by adding '
|
||||
'--data-binary \'{"status": "SUCCESS"}\' '
|
||||
', or signal failure by adding '
|
||||
'--data-binary \'{"status": "FAILURE"}\''),
|
||||
cache_mode=attributes.Schema.CACHE_NONE
|
||||
),
|
||||
}
|
||||
@ -167,7 +164,7 @@ class HeatWaitConditionHandle(BaseWaitConditionHandle):
|
||||
return self.data().get('token')
|
||||
elif key == self.ENDPOINT:
|
||||
return self.data().get('endpoint')
|
||||
elif key == self.CURL_CLI_SUCCESS:
|
||||
elif key == self.CURL_CLI:
|
||||
# Construct curl command for template-author convenience
|
||||
return ('curl -i -X POST '
|
||||
'-H \'X-Auth-Token: %(token)s\' '
|
||||
@ -176,16 +173,6 @@ class HeatWaitConditionHandle(BaseWaitConditionHandle):
|
||||
'%(endpoint)s' %
|
||||
dict(token=self.data().get('token'),
|
||||
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):
|
||||
'''
|
||||
|
@ -1006,7 +1006,7 @@ class HeatWaitConditionTest(HeatTestCase):
|
||||
self.assertEqual(expected, handle.FnGetAtt('endpoint'))
|
||||
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')
|
||||
heat_plugin.HeatClientPlugin.get_heat_url().AndReturn(
|
||||
'foo/%s' % self.tenant_id)
|
||||
@ -1017,21 +1017,5 @@ class HeatWaitConditionTest(HeatTestCase):
|
||||
"-H 'Accept: application/json' "
|
||||
"foo/aprojectid/stacks/test_stack/%s/resources/wait_handle"
|
||||
"/signal" % self.stack_id)
|
||||
self.assertEqual(expected, handle.FnGetAtt('curl_cli_success'))
|
||||
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.assertEqual(expected, handle.FnGetAtt('curl_cli'))
|
||||
self.m.VerifyAll()
|
||||
|
Loading…
Reference in New Issue
Block a user