diff --git a/senlinclient/tests/unit/v1/test_policy_type.py b/senlinclient/tests/unit/v1/test_policy_type.py index 3064469..378c59e 100644 --- a/senlinclient/tests/unit/v1/test_policy_type.py +++ b/senlinclient/tests/unit/v1/test_policy_type.py @@ -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): diff --git a/senlinclient/tests/unit/v1/test_shell.py b/senlinclient/tests/unit/v1/test_shell.py index a730f62..af0c057 100644 --- a/senlinclient/tests/unit/v1/test_shell.py +++ b/senlinclient/tests/unit/v1/test_shell.py @@ -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): diff --git a/senlinclient/v1/policy_type.py b/senlinclient/v1/policy_type.py index d6ad86f..5d55bbc 100644 --- a/senlinclient/v1/policy_type.py +++ b/senlinclient/v1/policy_type.py @@ -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): diff --git a/senlinclient/v1/shell.py b/senlinclient/v1/shell.py index 8645c1a..0c2fe39 100644 --- a/senlinclient/v1/shell.py +++ b/senlinclient/v1/shell.py @@ -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='',