Show server_id for listing instance by admin
Story: 2008420 Task: 41361 Change-Id: I4dd67cf9aa9a13a520e69872d2752d22f19e63cf
This commit is contained in:
parent
6aac8ded86
commit
b02459fb1d
@ -24,38 +24,44 @@ from troveclient.osc.v1 import base
|
||||
from troveclient import utils as trove_utils
|
||||
|
||||
|
||||
def set_attributes_for_print(instances):
|
||||
def get_instances_info(instances):
|
||||
instances_info = []
|
||||
|
||||
for instance in instances:
|
||||
# To avoid invoking GET request to trove.
|
||||
instance_info = instance.to_dict()
|
||||
|
||||
setattr(instance, 'flavor_id', instance.flavor['id'])
|
||||
instance_info['flavor_id'] = instance.flavor['id']
|
||||
|
||||
instance_info['size'] = '-'
|
||||
if 'volume' in instance_info:
|
||||
setattr(instance, 'size', instance.volume['size'])
|
||||
else:
|
||||
setattr(instance, 'size', '-')
|
||||
instance_info['size'] = instance_info['volume']['size']
|
||||
|
||||
setattr(instance, 'role', '')
|
||||
instance_info['role'] = ''
|
||||
if 'replica_of' in instance_info:
|
||||
setattr(instance, 'role', 'replica')
|
||||
instance_info['role'] = 'replica'
|
||||
if 'replicas' in instance_info:
|
||||
setattr(instance, 'role', 'primary')
|
||||
instance_info['role'] = 'primary'
|
||||
|
||||
if 'datastore' in instance_info:
|
||||
if instance.datastore.get('version'):
|
||||
setattr(instance, 'datastore_version',
|
||||
instance.datastore['version'])
|
||||
setattr(instance, 'datastore', instance.datastore['type'])
|
||||
instance_info['datastore_version'] = instance.\
|
||||
datastore['version']
|
||||
instance_info['datastore'] = instance.datastore['type']
|
||||
|
||||
if 'access' in instance_info:
|
||||
setattr(instance, "public",
|
||||
instance_info["access"].get("is_public", False))
|
||||
instance_info['public'] = instance_info["access"].get(
|
||||
"is_public", False)
|
||||
|
||||
if 'addresses' not in instance_info:
|
||||
setattr(instance, 'addresses', '')
|
||||
instance_info['addresses'] = ''
|
||||
|
||||
return instances
|
||||
if 'server' in instance_info:
|
||||
instance_info['server_id'] = instance_info['server'].get('id')
|
||||
|
||||
instances_info.append(instance_info)
|
||||
|
||||
return instances_info
|
||||
|
||||
|
||||
def set_attributes_for_print_detail(instance):
|
||||
@ -101,7 +107,7 @@ class ListDatabaseInstances(command.Lister):
|
||||
_description = _("List database instances")
|
||||
columns = ['ID', 'Name', 'Datastore', 'Datastore Version', 'Status',
|
||||
'Public', 'Addresses', 'Flavor ID', 'Size', 'Role']
|
||||
admin_columns = columns + ["Tenant ID"]
|
||||
admin_columns = columns + ["Server ID", "Tenant ID"]
|
||||
|
||||
def get_parser(self, prog_name):
|
||||
parser = super(ListDatabaseInstances, self).get_parser(prog_name)
|
||||
@ -164,9 +170,9 @@ class ListDatabaseInstances(command.Lister):
|
||||
**extra_params
|
||||
)
|
||||
if instances:
|
||||
instances = set_attributes_for_print(instances)
|
||||
instances = [osc_utils.get_item_properties(i, cols)
|
||||
for i in instances]
|
||||
instances_info = get_instances_info(instances)
|
||||
instances = [osc_utils.get_dict_properties(info, cols)
|
||||
for info in instances_info]
|
||||
|
||||
return cols, instances
|
||||
|
||||
|
@ -197,8 +197,7 @@ class FakeHTTPClient(base_client.HTTPClient):
|
||||
},
|
||||
"tenant_id": "fake_tenant_id",
|
||||
"access": {"is_public": False, "allowed_cidrs": []}
|
||||
},
|
||||
|
||||
}
|
||||
]
|
||||
}
|
||||
)
|
||||
|
@ -41,10 +41,33 @@ class TestInstanceList(TestInstances):
|
||||
def setUp(self):
|
||||
super(TestInstanceList, self).setUp()
|
||||
self.cmd = database_instances.ListDatabaseInstances(self.app, None)
|
||||
self.data = self.fake_instances.get_instances()
|
||||
|
||||
def test_instance_list_defaults(self):
|
||||
self.instance_client.list.return_value = common.Paginated(self.data)
|
||||
instance_id = self.random_uuid()
|
||||
name = self.random_name('test-list')
|
||||
tenant_id = self.random_uuid()
|
||||
insts = [
|
||||
{
|
||||
"id": instance_id,
|
||||
"name": name,
|
||||
"status": "ACTIVE",
|
||||
"addresses": [
|
||||
{"type": "private", "address": "10.0.0.13"}
|
||||
],
|
||||
"volume": {"size": 2},
|
||||
"flavor": {"id": "02"},
|
||||
"region": "regionOne",
|
||||
"datastore": {
|
||||
"version": "5.6", "type": "mysql",
|
||||
"version_number": "5.7.29"
|
||||
},
|
||||
"tenant_id": tenant_id,
|
||||
"replica_of": self.random_uuid(),
|
||||
"access": {"is_public": False, "allowed_cidrs": []},
|
||||
}
|
||||
]
|
||||
self.instance_client.list.return_value = common.Paginated(
|
||||
[instances.Instance(mock.MagicMock(), inst) for inst in insts])
|
||||
|
||||
parsed_args = self.check_parser(self.cmd, [], [])
|
||||
columns, data = self.cmd.take_action(parsed_args)
|
||||
@ -56,21 +79,45 @@ class TestInstanceList(TestInstances):
|
||||
)
|
||||
|
||||
values = [
|
||||
('1234', 'test-member-1', 'mysql', '5.6', 'ACTIVE', False,
|
||||
(instance_id, name, 'mysql', '5.6', 'ACTIVE', False,
|
||||
[{"type": "private", "address": "10.0.0.13"}],
|
||||
'02', 2, 'replica'),
|
||||
('5678', 'test-member-2', 'mysql', '5.6', 'ACTIVE', False,
|
||||
[{"type": "private", "address": "10.0.0.14"}],
|
||||
'2', 2, '')
|
||||
]
|
||||
self.assertEqual(values, data)
|
||||
|
||||
def test_instance_list_all_projects(self):
|
||||
self.mgmt_client.list.return_value = common.Paginated(self.data)
|
||||
instance_id = self.random_uuid()
|
||||
name = self.random_name('test-list')
|
||||
tenant_id = self.random_uuid()
|
||||
server_id = self.random_uuid()
|
||||
insts = [
|
||||
{
|
||||
"id": instance_id,
|
||||
"name": name,
|
||||
"status": "ACTIVE",
|
||||
"addresses": [
|
||||
{"type": "private", "address": "10.0.0.13"}
|
||||
],
|
||||
"volume": {"size": 2},
|
||||
"flavor": {"id": "02"},
|
||||
"region": "regionOne",
|
||||
"datastore": {
|
||||
"version": "5.6", "type": "mysql",
|
||||
"version_number": "5.7.29"
|
||||
},
|
||||
"tenant_id": tenant_id,
|
||||
"access": {"is_public": False, "allowed_cidrs": []},
|
||||
'server': {
|
||||
'id': server_id
|
||||
}
|
||||
}
|
||||
]
|
||||
self.mgmt_client.list.return_value = common.Paginated(
|
||||
[instances.Instance(mock.MagicMock(), inst) for inst in insts])
|
||||
|
||||
parsed_args = self.check_parser(self.cmd, ["--all-projects"],
|
||||
[("all_projects", True)])
|
||||
columns, instances = self.cmd.take_action(parsed_args)
|
||||
columns, data = self.cmd.take_action(parsed_args)
|
||||
|
||||
self.mgmt_client.list.assert_called_once_with(**self.defaults)
|
||||
self.assertEqual(
|
||||
@ -79,28 +126,62 @@ class TestInstanceList(TestInstances):
|
||||
)
|
||||
|
||||
expected_instances = [
|
||||
('1234', 'test-member-1', 'mysql', '5.6',
|
||||
'ACTIVE', False, [{"type": "private", "address": "10.0.0.13"}],
|
||||
'02', 2, 'replica', 'fake_tenant_id'),
|
||||
('5678', 'test-member-2', 'mysql', '5.6',
|
||||
'ACTIVE', False, [{"type": "private", "address": "10.0.0.14"}],
|
||||
'2', 2, '', 'fake_tenant_id')
|
||||
(instance_id, name, 'mysql', '5.6', 'ACTIVE', False,
|
||||
[{"type": "private", "address": "10.0.0.13"}],
|
||||
'02', 2, '', server_id, tenant_id),
|
||||
]
|
||||
self.assertEqual(expected_instances, instances)
|
||||
self.assertEqual(expected_instances, data)
|
||||
|
||||
def test_instance_list_for_project(self):
|
||||
self.mgmt_client.list.return_value = common.Paginated(self.data)
|
||||
instance_id = self.random_uuid()
|
||||
name = self.random_name('test-list')
|
||||
tenant_id = self.random_uuid()
|
||||
server_id = self.random_uuid()
|
||||
insts = [
|
||||
{
|
||||
"id": instance_id,
|
||||
"name": name,
|
||||
"status": "ACTIVE",
|
||||
"addresses": [
|
||||
{"type": "private", "address": "10.0.0.13"}
|
||||
],
|
||||
"volume": {"size": 2},
|
||||
"flavor": {"id": "02"},
|
||||
"region": "regionOne",
|
||||
"datastore": {
|
||||
"version": "5.6", "type": "mysql",
|
||||
"version_number": "5.7.29"
|
||||
},
|
||||
"tenant_id": tenant_id,
|
||||
"access": {"is_public": False, "allowed_cidrs": []},
|
||||
'server': {
|
||||
'id': server_id
|
||||
}
|
||||
}
|
||||
]
|
||||
self.mgmt_client.list.return_value = common.Paginated(
|
||||
[instances.Instance(mock.MagicMock(), inst) for inst in insts])
|
||||
|
||||
project_id = self.random_uuid()
|
||||
parsed_args = self.check_parser(self.cmd, ["--project-id", project_id],
|
||||
[("project_id", project_id)])
|
||||
self.cmd.take_action(parsed_args)
|
||||
parsed_args = self.check_parser(self.cmd, ["--project-id", tenant_id],
|
||||
[("project_id", tenant_id)])
|
||||
columns, data = self.cmd.take_action(parsed_args)
|
||||
|
||||
self.assertEqual(
|
||||
database_instances.ListDatabaseInstances.admin_columns,
|
||||
columns
|
||||
)
|
||||
expected_instances = [
|
||||
(instance_id, name, 'mysql', '5.6', 'ACTIVE', False,
|
||||
[{"type": "private", "address": "10.0.0.13"}],
|
||||
'02', 2, '', server_id, tenant_id),
|
||||
]
|
||||
self.assertEqual(expected_instances, data)
|
||||
|
||||
expected_params = {
|
||||
'include_clustered': False,
|
||||
'limit': None,
|
||||
'marker': None,
|
||||
'project_id': project_id
|
||||
'project_id': tenant_id
|
||||
}
|
||||
self.mgmt_client.list.assert_called_once_with(**expected_params)
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user