Remove unnecessary API call for listing instances
Change-Id: Ibd6a1ce15abc12524f49f4091acb38d6841a8476
This commit is contained in:
@@ -27,26 +27,23 @@ from troveclient import utils as trove_utils
|
||||
|
||||
def set_attributes_for_print(instances):
|
||||
for instance in instances:
|
||||
# To avoid invoking GET request to trove.
|
||||
instance_info = instance.to_dict()
|
||||
|
||||
setattr(instance, 'flavor_id', instance.flavor['id'])
|
||||
|
||||
if hasattr(instance, 'volume'):
|
||||
if 'volume' in instance_info:
|
||||
setattr(instance, 'size', instance.volume['size'])
|
||||
else:
|
||||
setattr(instance, 'size', '-')
|
||||
|
||||
if hasattr(instance, 'ip'):
|
||||
addresses = ', '.join(instance.ip)
|
||||
setattr(instance, 'addresses', addresses)
|
||||
|
||||
# If 'replica_of' not in instance, the client will invoke a GET
|
||||
# instance request to API.
|
||||
if hasattr(instance, 'replica_of'):
|
||||
setattr(instance, 'role', '')
|
||||
if 'replica_of' in instance_info:
|
||||
setattr(instance, 'role', 'replica')
|
||||
|
||||
if hasattr(instance, 'replicas'):
|
||||
if 'replicas' in instance_info:
|
||||
setattr(instance, 'role', 'master')
|
||||
|
||||
if hasattr(instance, 'datastore'):
|
||||
if 'datastore' in instance_info:
|
||||
if instance.datastore.get('version'):
|
||||
setattr(instance, 'datastore_version',
|
||||
instance.datastore['version'])
|
||||
|
@@ -167,7 +167,9 @@ class FakeHTTPClient(base_client.HTTPClient):
|
||||
"id": "1234",
|
||||
"name": "test-member-1",
|
||||
"status": "ACTIVE",
|
||||
"ip": ["10.0.0.13"],
|
||||
"addresses": [
|
||||
{"type": "private", "address": "10.0.0.13"}
|
||||
],
|
||||
"volume": {"size": 2},
|
||||
"flavor": {"id": "02"},
|
||||
"region": "regionOne",
|
||||
@@ -179,7 +181,9 @@ class FakeHTTPClient(base_client.HTTPClient):
|
||||
"id": "5678",
|
||||
"name": "test-member-2",
|
||||
"status": "ACTIVE",
|
||||
"ip": ["10.0.0.14"],
|
||||
"addresses": [
|
||||
{"type": "private", "address": "10.0.0.14"}
|
||||
],
|
||||
"volume": {"size": 2},
|
||||
"flavor": {"id": "2"},
|
||||
"region": "regionOne",
|
||||
|
@@ -55,9 +55,11 @@ class TestInstanceList(TestInstances):
|
||||
)
|
||||
|
||||
values = [
|
||||
('1234', 'test-member-1', 'mysql', '5.6', 'ACTIVE', '10.0.0.13',
|
||||
('1234', 'test-member-1', 'mysql', '5.6', 'ACTIVE',
|
||||
[{"type": "private", "address": "10.0.0.13"}],
|
||||
'02', 2, 'regionOne', 'replica'),
|
||||
('5678', 'test-member-2', 'mysql', '5.6', 'ACTIVE', '10.0.0.14',
|
||||
('5678', 'test-member-2', 'mysql', '5.6', 'ACTIVE',
|
||||
[{"type": "private", "address": "10.0.0.14"}],
|
||||
'2', 2, 'regionOne', '')
|
||||
]
|
||||
self.assertEqual(values, data)
|
||||
@@ -77,15 +79,18 @@ class TestInstanceList(TestInstances):
|
||||
|
||||
expected_instances = [
|
||||
('1234', 'test-member-1', 'fake_tenant_id', 'mysql', '5.6',
|
||||
'ACTIVE', '10.0.0.13', '02', 2, 'replica'),
|
||||
'ACTIVE', [{"type": "private", "address": "10.0.0.13"}], '02', 2,
|
||||
'replica'),
|
||||
('5678', 'test-member-2', 'fake_tenant_id', 'mysql', '5.6',
|
||||
'ACTIVE', '10.0.0.14', '2', 2, '')
|
||||
'ACTIVE', [{"type": "private", "address": "10.0.0.14"}], '2', 2,
|
||||
'')
|
||||
]
|
||||
self.assertEqual(expected_instances, instances)
|
||||
|
||||
|
||||
class TestInstanceShow(TestInstances):
|
||||
values = ('mysql', '5.6', '02', '1234', '10.0.0.13', 'test-member-1',
|
||||
values = ([{'address': '10.0.0.13', 'type': 'private'}], 'mysql', '5.6',
|
||||
'02', '1234', 'test-member-1',
|
||||
'regionOne', 'fake_master_id', 'ACTIVE', 'fake_tenant_id', 2)
|
||||
|
||||
def setUp(self):
|
||||
@@ -94,11 +99,11 @@ class TestInstanceShow(TestInstances):
|
||||
self.data = self.fake_instances.get_instances_1234()
|
||||
self.instance_client.get.return_value = self.data
|
||||
self.columns = (
|
||||
'addresses',
|
||||
'datastore',
|
||||
'datastore_version',
|
||||
'flavor',
|
||||
'id',
|
||||
'ip',
|
||||
'name',
|
||||
'region',
|
||||
'replica_of',
|
||||
|
Reference in New Issue
Block a user