resource-list --nested-depth stack_name column

For resource-list --nested-depth an extra column parent_resource
is added to the result. This has the following issues:
- parent_resource values cannot be used as the stack argument to
  resource-show
- templates with more than one ResourceGroup will have more than one
  parent_resource called "0", so there is no way of inferring the actual
  parent, and it is not possible to guess the correct parent resource
- parent_resource is inconsistent with event-list --nested-depth, which
  adds a stack_name column that doesn't have the above disadvantages.

This change replaces the parent_resource column with a stack_name
column for resource-list --nested-depth.

Change-Id: I6b4bc306db48e08931ff294bcbefeb6bbb195663
Closes-bug: #1467332
This commit is contained in:
Steve Baker
2015-06-22 12:16:17 +12:00
parent 5d5256a0c8
commit 1f7c44517d
4 changed files with 34 additions and 3 deletions

View File

@@ -175,3 +175,20 @@ class ResourceManagerTest(testtools.TestCase):
manager = self._base_test(expect, key)
manager.signal(**fields)
self.m.VerifyAll()
class ResourceStackNameTest(testtools.TestCase):
def test_stack_name(self):
resource = resources.Resource(None, {"links": [{
"href": "http://heat.example.com:8004/foo/12/resources/foobar",
"rel": "self"
}, {
"href": "http://heat.example.com:8004/foo/12",
"rel": "stack"
}]})
self.assertEqual('foo', resource.stack_name)
def test_stack_name_no_links(self):
resource = resources.Resource(None, {})
self.assertIsNone(resource.stack_name)

View File

@@ -2848,7 +2848,13 @@ class ShellTestResources(ShellBase):
self.register_keystone_auth_fixture()
resp_dict = {"resources": [{
"resource_name": "foobar",
"parent_resource": "my_parent_resource",
"links": [{
"href": "http://heat.example.com:8004/foo/12/resources/foobar",
"rel": "self"
}, {
"href": "http://heat.example.com:8004/foo/12",
"rel": "stack"
}],
}]}
resp = fakes.FakeHTTPResponse(
200,
@@ -2867,7 +2873,7 @@ class ShellTestResources(ShellBase):
required = [
'resource_name', 'foobar',
'parent_resource', 'my_parent_resource',
'stack_name', 'foo',
]
for field in required:
self.assertRegexpMatches(resource_list_text, field)

View File

@@ -36,6 +36,14 @@ class Resource(base.Resource):
def data(self, **kwargs):
return self.manager.data(self, **kwargs)
@property
def stack_name(self):
if not hasattr(self, 'links'):
return
for l in self.links:
if l['rel'] == 'stack':
return l['href'].split('/')[-2]
class ResourceManager(stacks.StackChildManager):
resource_class = Resource

View File

@@ -750,7 +750,7 @@ def do_resource_list(hc, args):
fields.insert(0, 'resource_name')
if args.nested_depth:
fields.append('parent_resource')
fields.append('stack_name')
utils.print_list(resources, fields, sortby_index=4)