Browse Source

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
changes/21/416921/1
Steve Baker 7 years ago
committed by Thomas Herve
parent
commit
e533f66122
  1. 11
      hot/software-config/elements/heat-config/bin/heat-config-notify
  2. 31
      tests/software_config/test_heat_config_notify.py

11
hot/software-config/elements/heat-config/bin/heat-config-notify

@ -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:

31
tests/software_config/test_heat_config_notify.py

@ -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

Loading…
Cancel
Save