Merge "Support status output for profile type list"
This commit is contained in:
commit
c47aad60ae
senlinclient
@ -27,7 +27,7 @@ def create_connection(prof=None, user_agent=None, **kwargs):
|
||||
if region_name:
|
||||
prof.set_region('clustering', region_name)
|
||||
|
||||
prof.set_api_version('clustering', '1.2')
|
||||
prof.set_api_version('clustering', '1.5')
|
||||
try:
|
||||
conn = connection.Connection(profile=prof, user_agent=user_agent,
|
||||
**kwargs)
|
||||
|
@ -144,9 +144,9 @@ def _print_list(objs, fields, formatters=None, sortby_index=0,
|
||||
pt.add_row(row)
|
||||
|
||||
if six.PY3:
|
||||
print(encodeutils.safe_encode(pt.get_string(**kwargs)).decode())
|
||||
return encodeutils.safe_encode(pt.get_string(**kwargs)).decode()
|
||||
else:
|
||||
print(encodeutils.safe_encode(pt.get_string(**kwargs)))
|
||||
return encodeutils.safe_encode(pt.get_string(**kwargs))
|
||||
|
||||
|
||||
def print_list(objs, fields, formatters=None, sortby_index=0,
|
||||
@ -157,10 +157,11 @@ def print_list(objs, fields, formatters=None, sortby_index=0,
|
||||
objs = []
|
||||
|
||||
try:
|
||||
_print_list(objs, fields, formatters=formatters,
|
||||
sortby_index=sortby_index,
|
||||
mixed_case_fields=mixed_case_fields,
|
||||
field_labels=field_labels)
|
||||
res = _print_list(objs, fields, formatters=formatters,
|
||||
sortby_index=sortby_index,
|
||||
mixed_case_fields=mixed_case_fields,
|
||||
field_labels=field_labels)
|
||||
print(res)
|
||||
except Exception as ex:
|
||||
exc.parse_exception(ex)
|
||||
|
||||
|
@ -23,7 +23,7 @@ LOG = logging.getLogger(__name__)
|
||||
DEFAULT_CLUSTERING_API_VERSION = '1'
|
||||
API_VERSION_OPTION = 'os_clustering_api_version'
|
||||
API_NAME = 'clustering'
|
||||
CURRENT_API_VERSION = '1.2'
|
||||
CURRENT_API_VERSION = '1.5'
|
||||
|
||||
|
||||
def make_client(instance):
|
||||
|
@ -27,16 +27,24 @@ class TestProfileType(fakes.TestClusteringv1):
|
||||
|
||||
|
||||
class TestProfileTypeList(TestProfileType):
|
||||
expected_columns = ['name']
|
||||
expected_columns = ['name', 'version', 'support_status']
|
||||
list_response = [
|
||||
sdk_profile_type.ProfileType(name='BBB', schema={'foo': 'bar'}),
|
||||
sdk_profile_type.ProfileType(name='AAA', schema={'foo': 'bar'}),
|
||||
sdk_profile_type.ProfileType(name='CCC', schema={'foo': 'bar'}),
|
||||
sdk_profile_type.ProfileType(
|
||||
name='BBB', schema={'foo': 'bar'},
|
||||
support_status={
|
||||
"1.0": [{"status": "SUPPORTED", "since": "2016.10"}]
|
||||
}
|
||||
),
|
||||
sdk_profile_type.ProfileType(
|
||||
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):
|
||||
|
@ -76,10 +76,24 @@ class ShellTest(testtools.TestCase):
|
||||
@mock.patch.object(utils, 'print_list')
|
||||
def test_do_profile_type_list(self, mock_print):
|
||||
service = 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.profile_types.return_value = types
|
||||
sh.do_profile_type_list(service)
|
||||
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.profile_types.called)
|
||||
|
||||
@mock.patch.object(utils, 'format_output')
|
||||
|
@ -17,6 +17,7 @@ import logging
|
||||
from openstack import exceptions as sdk_exc
|
||||
from osc_lib.command import command
|
||||
from osc_lib import exceptions as exc
|
||||
|
||||
from senlinclient.common import format_utils
|
||||
from senlinclient.common.i18n import _
|
||||
|
||||
@ -34,9 +35,19 @@ class ProfileTypeList(command.Lister):
|
||||
self.log.debug("take_action(%s)", parsed_args)
|
||||
senlin_client = self.app.client_manager.clustering
|
||||
types = senlin_client.profile_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 ProfileTypeShow(format_utils.YamlFormat):
|
||||
|
@ -48,13 +48,28 @@ def do_build_info(service, args=None):
|
||||
|
||||
# PROFILE TYPES
|
||||
|
||||
|
||||
def do_profile_type_list(service, args=None):
|
||||
"""List the available profile types."""
|
||||
show_deprecated('senlin profile-type-list',
|
||||
'openstack cluster profile type list')
|
||||
|
||||
class _ProfileType(object):
|
||||
|
||||
def __init__(self, name, version, status):
|
||||
self.name = name
|
||||
self.version = version
|
||||
self.support_status = status
|
||||
|
||||
fields = ['name', 'version', 'support_status']
|
||||
types = service.profile_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(_ProfileType(t.name, v, ss))
|
||||
|
||||
utils.print_list(results, fields, sortby_index=0)
|
||||
|
||||
|
||||
@utils.arg('type_name', metavar='<TYPE_NAME>',
|
||||
|
Loading…
x
Reference in New Issue
Block a user