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):
|
class TestPolicyTypeList(TestPolicyType):
|
||||||
expected_columns = ['name']
|
expected_columns = ['name', 'version', 'support_status']
|
||||||
list_response = [
|
list_response = [
|
||||||
sdk_policy_type.PolicyType(name='BBB', schema={'foo': 'bar'}),
|
sdk_policy_type.PolicyType(
|
||||||
sdk_policy_type.PolicyType(name='AAA', schema={'foo': 'bar'}),
|
name='BBB', schema={'foo': 'bar'},
|
||||||
sdk_policy_type.PolicyType(name='CCC', 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 = [
|
expected_rows = [
|
||||||
['AAA'],
|
('AAA', '1.0', 'DEPRECATED since 2016.01'),
|
||||||
['BBB'],
|
('BBB', '1.0', 'SUPPORTED since 2016.10')
|
||||||
['CCC']
|
|
||||||
]
|
]
|
||||||
|
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
|
@ -89,7 +89,9 @@ class ShellTest(testtools.TestCase):
|
|||||||
mock_type.name = "fake_type"
|
mock_type.name = "fake_type"
|
||||||
types = [mock_type]
|
types = [mock_type]
|
||||||
service.profile_types.return_value = types
|
service.profile_types.return_value = types
|
||||||
|
|
||||||
sh.do_profile_type_list(service)
|
sh.do_profile_type_list(service)
|
||||||
|
|
||||||
mock_print.assert_called_once_with(
|
mock_print.assert_called_once_with(
|
||||||
mock.ANY,
|
mock.ANY,
|
||||||
['name', 'version', 'support_status'],
|
['name', 'version', 'support_status'],
|
||||||
@ -361,10 +363,27 @@ class ShellTest(testtools.TestCase):
|
|||||||
def test_do_policy_type_list(self, mock_print):
|
def test_do_policy_type_list(self, mock_print):
|
||||||
service = mock.Mock()
|
service = mock.Mock()
|
||||||
args = 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
|
service.policy_types.return_value = types
|
||||||
|
|
||||||
sh.do_policy_type_list(service, args)
|
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')
|
@mock.patch.object(utils, 'format_output')
|
||||||
def test_do_policy_type_show(self, mock_format):
|
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)
|
self.log.debug("take_action(%s)", parsed_args)
|
||||||
senlin_client = self.app.client_manager.clustering
|
senlin_client = self.app.client_manager.clustering
|
||||||
types = senlin_client.policy_types()
|
types = senlin_client.policy_types()
|
||||||
columns = ['name']
|
columns = ['name', 'version', 'support_status']
|
||||||
rows = sorted([t.name] for t in types)
|
results = []
|
||||||
return columns, rows
|
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):
|
class PolicyTypeShow(format_utils.YamlFormat):
|
||||||
|
@ -304,8 +304,25 @@ def do_policy_type_list(service, args):
|
|||||||
"""List the available policy types."""
|
"""List the available policy types."""
|
||||||
show_deprecated('senlin policy-type-list',
|
show_deprecated('senlin policy-type-list',
|
||||||
'openstack cluster 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()
|
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>',
|
@utils.arg('type_name', metavar='<TYPE_NAME>',
|
||||||
|
Loading…
Reference in New Issue
Block a user