diff --git a/troveclient/tests/fakes.py b/troveclient/tests/fakes.py index 2fe389c3..67f7b04a 100644 --- a/troveclient/tests/fakes.py +++ b/troveclient/tests/fakes.py @@ -192,7 +192,12 @@ class FakeHTTPClient(base_client.HTTPClient): "str_id": "3", "ram": 4096, "id": 3, - "name": "m1.medium"}]}) + "name": "m1.medium"}, + { + "str_id": "7d0d16e5-875f-4198-b6da-90ab2d3e899e", + "ram": 8192, + "id": None, + "name": "m1.uuid"}]}) def get_datastores_mysql_versions_some_version_id_flavors(self, **kw): return self.get_flavors() @@ -201,6 +206,10 @@ class FakeHTTPClient(base_client.HTTPClient): r = {'flavor': self.get_flavors()[2]['flavors'][0]} return (200, {}, r) + def get_flavors_m1_uuid(self, **kw): + r = {'flavor': self.get_flavors()[2]['flavors'][4]} + return (200, {}, r) + def get_clusters(self, **kw): return (200, {}, {"clusters": [ { diff --git a/troveclient/tests/test_v1_shell.py b/troveclient/tests/test_v1_shell.py index 5c377bb9..a5874683 100644 --- a/troveclient/tests/test_v1_shell.py +++ b/troveclient/tests/test_v1_shell.py @@ -132,6 +132,10 @@ class ShellTest(utils.TestCase): self.run_command('flavor-show 1') self.assert_called('GET', '/flavors/1') + def test_flavor_show_uuid(self): + self.run_command('flavor-show m1.uuid') + self.assert_called('GET', '/flavors/m1.uuid') + def test_cluster_list(self): self.run_command('cluster-list') self.assert_called('GET', '/clusters') diff --git a/troveclient/utils.py b/troveclient/utils.py index 8f1e1f60..c685ea2b 100644 --- a/troveclient/utils.py +++ b/troveclient/utils.py @@ -178,7 +178,7 @@ def print_list(objs, fields, formatters={}, order_by=None, obj_is_dict=False, data = obj.get(field, '') else: data = getattr(obj, field, '') - row.append(data) + row.append(str(data)) # set the alignment to right-aligned if it's a numeric if set_align and hasattr(data, '__int__'): align[labels[field]] = 'r' diff --git a/troveclient/v1/flavors.py b/troveclient/v1/flavors.py index 64238abb..7b1d72fa 100644 --- a/troveclient/v1/flavors.py +++ b/troveclient/v1/flavors.py @@ -20,6 +20,11 @@ from troveclient import base class Flavor(base.Resource): """A Flavor is an Instance type, specifying other things, like RAM size.""" + def __init__(self, manager, info, loaded=False): + super(Flavor, self).__init__(manager, info, loaded) + if self.id is None and self.str_id is not None: + self.id = self.str_id + def __repr__(self): return "" % self.name diff --git a/troveclient/v1/shell.py b/troveclient/v1/shell.py index 5737f050..f8ab1b79 100644 --- a/troveclient/v1/shell.py +++ b/troveclient/v1/shell.py @@ -90,8 +90,7 @@ def _print_object(obj): # Fallback to str_id for flavors, where necessary if hasattr(obj, 'str_id'): - if hasattr(obj, 'id') and not obj.id: - obj._info['id'] = obj.str_id + obj._info['id'] = obj.id del(obj._info['str_id']) utils.print_dict(obj._info)