Fix flavor-show problems with UUID

flavor-show fails if the flavor's ID is in the form of UUID
and user specified its name.
The change in troveclient/v1/shell.py#L92-L95 is from Sushil Kumar.

Closes-Bug: #1467383
Change-Id: Ie838796191a06193a59499da59fae79b9d9f060f
This commit is contained in:
Masaki Matsushita 2015-06-22 13:55:49 +09:00
parent 0702365088
commit 29d0703de1
5 changed files with 21 additions and 4 deletions

View File

@ -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": [
{

View File

@ -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')

View File

@ -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'

View File

@ -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 "<Flavor: %s>" % self.name

View File

@ -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)