summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThomas Herve <therve@redhat.com>2017-03-28 15:19:00 +0200
committerThomas Herve <therve@redhat.com>2017-03-29 15:23:47 +0000
commit56b497539877ca9e0e83ce6dad5a7f862efc7a63 (patch)
treefe83dd7ef859dafa7a40b77436248b75f173aae2
parenta198d7a53b1f1d635a2763b36686921de47f3091 (diff)
downloadpython-heatclient-56b497539877ca9e0e83ce6dad5a7f862efc7a63.tar.gz
Build event stack_name from links1.8.1
When retrieving events from nested stacks, we used to do a query per stack and thus get the stack that way. We changed it to do only one API call, but didn't fix the way the stack name was set. We need to use the event links to retrieve the stack name, instead of the root stack. Closes-Bug: #1676896 Change-Id: I09ab1cc2c6aaab02036b124b1dfa561dd6132083 (cherry picked from commit 954e475a6a0a12432ec325d7579460fabcf3f40a)
-rw-r--r--heatclient/common/event_utils.py12
-rw-r--r--heatclient/tests/unit/test_event_utils.py5
2 files changed, 14 insertions, 3 deletions
diff --git a/heatclient/common/event_utils.py b/heatclient/common/event_utils.py
index df000f7..8551b56 100644
--- a/heatclient/common/event_utils.py
+++ b/heatclient/common/event_utils.py
@@ -151,6 +151,15 @@ def _get_nested_events(hc, nested_depth, stack_id, event_args):
return nested_events
+def _get_stack_name_from_links(event):
+ links = dict((l.get('rel'),
+ l.get('href')) for l in getattr(event, 'links', []))
+ href = links.get('stack')
+ if not href:
+ return
+ return href.split('/stacks/', 1)[-1].split('/')[0]
+
+
def _get_stack_events(hc, stack_id, event_args):
event_args['stack_id'] = stack_id
try:
@@ -160,9 +169,10 @@ def _get_stack_events(hc, stack_id, event_args):
# just use the message that the server sent us.
raise exc.CommandError(str(ex))
else:
+ stack_name = stack_id.split("/")[0]
# Show which stack the event comes from (for nested events)
for e in events:
- e.stack_name = stack_id.split("/")[0]
+ e.stack_name = _get_stack_name_from_links(e) or stack_name
return events
diff --git a/heatclient/tests/unit/test_event_utils.py b/heatclient/tests/unit/test_event_utils.py
index a9e8912..b080e00 100644
--- a/heatclient/tests/unit/test_event_utils.py
+++ b/heatclient/tests/unit/test_event_utils.py
@@ -47,8 +47,9 @@ class ShellTestEventUtils(testtools.TestCase):
@staticmethod
def _mock_event(event_id, resource_id,
resource_status='CREATE_COMPLETE'):
- ev_info = {"links": [{"href": "http://heat/foo", "rel": "self"},
- {"href": "http://heat/stacks/a", "rel": "stack"}],
+ ev_info = {"links": [
+ {"href": "http://heat/foo", "rel": "self"},
+ {"href": "http://heat/stacks/astack", "rel": "stack"}],
"logical_resource_id": resource_id,
"physical_resource_id": resource_id,
"resource_name": resource_id,