heat-config-notify support deploy_signal_verb

The URL for deploy_signal_id is called with POST by default, however some
signals need to be called with PUT (specifically signals backed by swift
objects).

This change uses the value of deploy_signal_verb for POST or PUT, using
POST by default.

Change-Id: I8c83fa34cad9b1e91abcfc7e26e04b21cdc9bde4
Partial-Blueprint: software-config-swift-signal
This commit is contained in:
Steve Baker 2015-02-18 11:27:55 +13:00
parent 8d0d4deb1d
commit f27ef03211
2 changed files with 39 additions and 3 deletions

View File

@ -69,10 +69,15 @@ def main(argv=sys.argv, stdin=sys.stdin):
if 'deploy_signal_id' in iv:
sigurl = iv.get('deploy_signal_id')
sigverb = iv.get('deploy_signal_verb', 'POST')
signal_data = json.dumps(signal_data)
log.debug('Signalling to %s' % sigurl)
r = requests.post(sigurl, data=signal_data,
headers={'content-type': None})
log.debug('Signaling to %s via %s' % (sigurl, sigverb))
if sigverb == 'PUT':
r = requests.put(sigurl, data=signal_data,
headers={'content-type': None})
else:
r = requests.post(sigurl, data=signal_data,
headers={'content-type': None})
log.debug('Response %s ' % r)
if 'deploy_auth_url' in iv:

View File

@ -34,6 +34,19 @@ class HeatConfigNotifyTest(common.RunScriptTest):
'config': 'five'
}
data_signal_id_put = {
'id': '5555',
'group': 'script',
'inputs': [{
'name': 'deploy_signal_id',
'value': 'mock://192.0.2.3/foo'
}, {
'name': 'deploy_signal_verb',
'value': 'PUT'
}],
'config': 'five'
}
data_heat_signal = {
'id': '5555',
'group': 'script',
@ -107,6 +120,24 @@ class HeatConfigNotifyTest(common.RunScriptTest):
data=signal_data,
headers={'content-type': None})
def test_notify_signal_id_put(self):
requests = mock.MagicMock()
hcn.requests = requests
requests.post.return_value = '[200]'
signal_data = json.dumps({'foo': 'bar'})
stdin = cStringIO.StringIO(signal_data)
with self.write_config_file(self.data_signal_id_put) as config_file:
self.assertEqual(
0, hcn.main(['heat-config-notify', config_file.name], stdin))
requests.put.assert_called_once_with(
'mock://192.0.2.3/foo',
data=signal_data,
headers={'content-type': None})
def test_notify_signal_id_empty_data(self):
requests = mock.MagicMock()
hcn.requests = requests