Print support status while listing policy types
This adds the output of support status when listing policy types. Change-Id: Id1ac701e06257a13d19b6773a87b438d5864ea46
This commit is contained in:
parent
f9fa670aaf
commit
fc00ae7d5e
@ -27,16 +27,24 @@ class TestPolicyType(fakes.TestClusteringv1):
|
||||
|
||||
|
||||
class TestPolicyTypeList(TestPolicyType):
|
||||
expected_columns = ['name']
|
||||
expected_columns = ['name', 'version', 'support_status']
|
||||
list_response = [
|
||||
sdk_policy_type.PolicyType(name='BBB', schema={'foo': 'bar'}),
|
||||
sdk_policy_type.PolicyType(name='AAA', schema={'foo': 'bar'}),
|
||||
sdk_policy_type.PolicyType(name='CCC', schema={'foo': 'bar'}),
|
||||
sdk_policy_type.PolicyType(
|
||||
name='BBB', schema={'foo': 'bar'},
|
||||
support_status={
|
||||
"1.0": [{"status": "SUPPORTED", "since": "2016.10"}]
|
||||
}
|
||||
),
|
||||
sdk_policy_type.PolicyType(
|
||||
name='AAA', schema={'foo': 'bar'},
|
||||
support_status={
|
||||
"1.0": [{"status": "DEPRECATED", "since": "2016.01"}]
|
||||
}
|
||||
),
|
||||
]
|
||||
expected_rows = [
|
||||
['AAA'],
|
||||
['BBB'],
|
||||
['CCC']
|
||||
('AAA', '1.0', 'DEPRECATED since 2016.01'),
|
||||
('BBB', '1.0', 'SUPPORTED since 2016.10')
|
||||
]
|
||||
|
||||
def setUp(self):
|
||||
|
@ -89,7 +89,9 @@ class ShellTest(testtools.TestCase):
|
||||
mock_type.name = "fake_type"
|
||||
types = [mock_type]
|
||||
service.profile_types.return_value = types
|
||||
|
||||
sh.do_profile_type_list(service)
|
||||
|
||||
mock_print.assert_called_once_with(
|
||||
mock.ANY,
|
||||
['name', 'version', 'support_status'],
|
||||
@ -361,10 +363,27 @@ class ShellTest(testtools.TestCase):
|
||||
def test_do_policy_type_list(self, mock_print):
|
||||
service = mock.Mock()
|
||||
args = mock.Mock()
|
||||
types = mock.Mock()
|
||||
mock_type = mock.Mock(
|
||||
support_status={
|
||||
"1.0": [
|
||||
{
|
||||
"status": "SUPPORTED",
|
||||
"since": "2016.10"
|
||||
}
|
||||
]
|
||||
}
|
||||
)
|
||||
mock_type.name = "fake_type"
|
||||
types = [mock_type]
|
||||
service.policy_types.return_value = types
|
||||
|
||||
sh.do_policy_type_list(service, args)
|
||||
mock_print.assert_called_once_with(types, ['name'], sortby_index=0)
|
||||
|
||||
mock_print.assert_called_once_with(
|
||||
mock.ANY,
|
||||
['name', 'version', 'support_status'],
|
||||
sortby_index=0)
|
||||
self.assertTrue(service.policy_types.called)
|
||||
|
||||
@mock.patch.object(utils, 'format_output')
|
||||
def test_do_policy_type_show(self, mock_format):
|
||||
|
@ -35,9 +35,18 @@ class PolicyTypeList(command.Lister):
|
||||
self.log.debug("take_action(%s)", parsed_args)
|
||||
senlin_client = self.app.client_manager.clustering
|
||||
types = senlin_client.policy_types()
|
||||
columns = ['name']
|
||||
rows = sorted([t.name] for t in types)
|
||||
return columns, rows
|
||||
columns = ['name', 'version', 'support_status']
|
||||
results = []
|
||||
for t in types:
|
||||
for v in t.support_status.keys():
|
||||
st_list = '\n'.join([
|
||||
' since '.join((item['status'], item['since']))
|
||||
for item in t.support_status[v]
|
||||
])
|
||||
|
||||
results.append((t.name, v, st_list))
|
||||
|
||||
return columns, sorted(results)
|
||||
|
||||
|
||||
class PolicyTypeShow(format_utils.YamlFormat):
|
||||
|
@ -304,8 +304,25 @@ def do_policy_type_list(service, args):
|
||||
"""List the available policy types."""
|
||||
show_deprecated('senlin policy-type-list',
|
||||
'openstack cluster policy type list')
|
||||
|
||||
class _PolicyType(object):
|
||||
|
||||
def __init__(self, name, version, status):
|
||||
self.name = name
|
||||
self.version = version
|
||||
self.support_status = status
|
||||
|
||||
fields = ['name', 'version', 'support_status']
|
||||
types = service.policy_types()
|
||||
utils.print_list(types, ['name'], sortby_index=0)
|
||||
|
||||
results = []
|
||||
for t in types:
|
||||
for v in t.support_status.keys():
|
||||
ss = '\n'.join([' since '.join((item['status'], item['since']))
|
||||
for item in t.support_status[v]])
|
||||
results.append(_PolicyType(t.name, v, ss))
|
||||
|
||||
utils.print_list(results, fields, sortby_index=0)
|
||||
|
||||
|
||||
@utils.arg('type_name', metavar='<TYPE_NAME>',
|
||||
|
Loading…
Reference in New Issue
Block a user