Add compute instance ID and volume ID to trove show output

The Compute ID (server_id) and Volume ID (volume_id)
associated with a trove instance are useful information
for an administrator. This commit add these fields to the
trove show output. They will only be visible to users
with admin rights.

Change-Id: I4a39b59ae610803f5aaf849f2e20ebb6e4ea1565
Closes-Bug: 1633581
This commit is contained in:
Simon Chang 2016-10-14 14:40:17 -04:00
parent 731ca1bdfd
commit 17ba7bc92e
8 changed files with 48 additions and 10 deletions

View File

@ -1,5 +1,5 @@
HTTP/1.1 200 OK HTTP/1.1 200 OK
Content-Type: application/json Content-Type: application/json
Content-Length: 1556 Content-Length: 1676
Date: Mon, 18 Mar 2013 19:09:17 GMT Date: Mon, 18 Mar 2013 19:09:17 GMT

View File

@ -56,6 +56,7 @@
"status": "ACTIVE", "status": "ACTIVE",
"tenant_id": "3000" "tenant_id": "3000"
}, },
"server_id": "44b277eb-39be-4921-be31-3d61b43651d7",
"service_status": "ACTIVE", "service_status": "ACTIVE",
"status": "ACTIVE", "status": "ACTIVE",
"task_description": "No tasks for the instance.", "task_description": "No tasks for the instance.",
@ -75,6 +76,7 @@
"status": "in-use", "status": "in-use",
"total": 4.0, "total": 4.0,
"used": 0.16 "used": 0.16
} },
"volume_id": "VOL_44b277eb-39be-4921-be31-3d61b43651d7"
} }
} }

View File

@ -1,5 +1,5 @@
HTTP/1.1 200 OK HTTP/1.1 200 OK
Content-Type: application/json Content-Type: application/json
Content-Length: 1105 Content-Length: 1225
Date: Mon, 18 Mar 2013 19:09:17 GMT Date: Mon, 18 Mar 2013 19:09:17 GMT

View File

@ -45,6 +45,7 @@
"status": "ACTIVE", "status": "ACTIVE",
"tenant_id": "3000" "tenant_id": "3000"
}, },
"server_id": "44b277eb-39be-4921-be31-3d61b43651d7",
"service_status": "ACTIVE", "service_status": "ACTIVE",
"status": "ACTIVE", "status": "ACTIVE",
"task_description": "No tasks for the instance.", "task_description": "No tasks for the instance.",
@ -52,7 +53,8 @@
"updated": "2014-10-30T12:30:00", "updated": "2014-10-30T12:30:00",
"volume": { "volume": {
"size": 4 "size": 4
} },
"volume_id": "VOL_44b277eb-39be-4921-be31-3d61b43651d7"
} }
] ]
} }

View File

@ -0,0 +1,4 @@
---
other:
- Add Compute ID (server_id) and Volume ID (volume_id)
to trove show output for admin users. Bug #1633581

View File

@ -16,6 +16,7 @@
from oslo_log import log as logging from oslo_log import log as logging
from trove.common.views import create_links from trove.common.views import create_links
from trove.common import wsgi
from trove.instance import models from trove.instance import models
LOG = logging.getLogger(__name__) LOG = logging.getLogger(__name__)
@ -27,6 +28,7 @@ class InstanceView(object):
def __init__(self, instance, req=None): def __init__(self, instance, req=None):
self.instance = instance self.instance = instance
self.req = req self.req = req
self.context = req.environ[wsgi.CONTEXT_KEY]
def data(self): def data(self):
instance_dict = { instance_dict = {
@ -122,6 +124,10 @@ class InstanceDetailView(InstanceView):
if self.instance.shard_id: if self.instance.shard_id:
result['instance']['shard_id'] = self.instance.shard_id result['instance']['shard_id'] = self.instance.shard_id
if self.context.is_admin:
result['instance']['server_id'] = self.instance.server_id
result['instance']['volume_id'] = self.instance.volume_id
return result return result
def _build_fault_info(self): def _build_fault_info(self):

View File

@ -127,6 +127,10 @@ class ClusterInstanceDetailViewTest(trove_testtools.TestCase):
self.instance.get_visible_ip_addresses = lambda: ["1.2.3.4"] self.instance.get_visible_ip_addresses = lambda: ["1.2.3.4"]
self.instance.slave_of_id = None self.instance.slave_of_id = None
self.instance.slaves = None self.instance.slaves = None
self.context = trove_testtools.TroveTestContext(self)
self.req = Mock()
self.req.environ = Mock()
self.req.environ.__getitem__ = Mock(return_value=self.context)
def tearDown(self): def tearDown(self):
super(ClusterInstanceDetailViewTest, self).tearDown() super(ClusterInstanceDetailViewTest, self).tearDown()
@ -135,7 +139,7 @@ class ClusterInstanceDetailViewTest(trove_testtools.TestCase):
@patch.object(ClusterInstanceDetailView, '_build_flavor_links') @patch.object(ClusterInstanceDetailView, '_build_flavor_links')
@patch.object(ClusterInstanceDetailView, '_build_configuration_info') @patch.object(ClusterInstanceDetailView, '_build_configuration_info')
def test_data(self, *args): def test_data(self, *args):
view = ClusterInstanceDetailView(self.instance, Mock()) view = ClusterInstanceDetailView(self.instance, self.req)
result = view.data() result = view.data()
self.assertEqual(self.instance.created, result['instance']['created']) self.assertEqual(self.instance.created, result['instance']['created'])
self.assertEqual(self.instance.updated, result['instance']['updated']) self.assertEqual(self.instance.updated, result['instance']['updated'])
@ -150,7 +154,7 @@ class ClusterInstanceDetailViewTest(trove_testtools.TestCase):
@patch.object(ClusterInstanceDetailView, '_build_configuration_info') @patch.object(ClusterInstanceDetailView, '_build_configuration_info')
def test_data_ip(self, *args): def test_data_ip(self, *args):
self.instance.hostname = None self.instance.hostname = None
view = ClusterInstanceDetailView(self.instance, Mock()) view = ClusterInstanceDetailView(self.instance, self.req)
result = view.data() result = view.data()
self.assertEqual(self.instance.created, result['instance']['created']) self.assertEqual(self.instance.created, result['instance']['created'])
self.assertEqual(self.instance.updated, result['instance']['updated']) self.assertEqual(self.instance.updated, result['instance']['updated'])

View File

@ -63,6 +63,8 @@ class InstanceDetailViewTest(trove_testtools.TestCase):
self.instance.slave_of_id = None self.instance.slave_of_id = None
self.instance.slaves = [] self.instance.slaves = []
self.instance.locality = 'affinity' self.instance.locality = 'affinity'
self.instance.server_id = 'server_abc'
self.instance.volume_id = 'volume_abc'
self.fault_message = 'Error' self.fault_message = 'Error'
self.fault_details = 'details' self.fault_details = 'details'
self.fault_date = 'now' self.fault_date = 'now'
@ -70,6 +72,10 @@ class InstanceDetailViewTest(trove_testtools.TestCase):
self.instance.fault.message = self.fault_message self.instance.fault.message = self.fault_message
self.instance.fault.details = self.fault_details self.instance.fault.details = self.fault_details
self.instance.fault.updated = self.fault_date self.instance.fault.updated = self.fault_date
self.context = trove_testtools.TroveTestContext(self)
self.req = Mock()
self.req.environ = Mock()
self.req.environ.__getitem__ = Mock(return_value=self.context)
def tearDown(self): def tearDown(self):
super(InstanceDetailViewTest, self).tearDown() super(InstanceDetailViewTest, self).tearDown()
@ -78,7 +84,7 @@ class InstanceDetailViewTest(trove_testtools.TestCase):
InstanceDetailView._build_configuration_info = self.build_config_method InstanceDetailView._build_configuration_info = self.build_config_method
def test_data_hostname(self): def test_data_hostname(self):
view = InstanceDetailView(self.instance, Mock()) view = InstanceDetailView(self.instance, self.req)
result = view.data() result = view.data()
self.assertEqual(self.instance.created, result['instance']['created']) self.assertEqual(self.instance.created, result['instance']['created'])
self.assertEqual(self.instance.updated, result['instance']['updated']) self.assertEqual(self.instance.updated, result['instance']['updated'])
@ -90,7 +96,7 @@ class InstanceDetailViewTest(trove_testtools.TestCase):
def test_data_ip(self): def test_data_ip(self):
self.instance.hostname = None self.instance.hostname = None
view = InstanceDetailView(self.instance, Mock()) view = InstanceDetailView(self.instance, self.req)
result = view.data() result = view.data()
self.assertEqual(self.instance.created, result['instance']['created']) self.assertEqual(self.instance.created, result['instance']['created'])
self.assertEqual(self.instance.updated, result['instance']['updated']) self.assertEqual(self.instance.updated, result['instance']['updated'])
@ -101,13 +107,13 @@ class InstanceDetailViewTest(trove_testtools.TestCase):
def test_locality(self): def test_locality(self):
self.instance.hostname = None self.instance.hostname = None
view = InstanceDetailView(self.instance, Mock()) view = InstanceDetailView(self.instance, self.req)
result = view.data() result = view.data()
self.assertEqual(self.instance.locality, self.assertEqual(self.instance.locality,
result['instance']['locality']) result['instance']['locality'])
def test_fault(self): def test_fault(self):
view = InstanceDetailView(self.instance, Mock()) view = InstanceDetailView(self.instance, self.req)
result = view.data() result = view.data()
self.assertEqual(self.fault_message, self.assertEqual(self.fault_message,
result['instance']['fault']['message']) result['instance']['fault']['message'])
@ -115,3 +121,17 @@ class InstanceDetailViewTest(trove_testtools.TestCase):
result['instance']['fault']['details']) result['instance']['fault']['details'])
self.assertEqual(self.fault_date, self.assertEqual(self.fault_date,
result['instance']['fault']['created']) result['instance']['fault']['created'])
def test_admin_view(self):
self.context.is_admin = True
view = InstanceDetailView(self.instance, self.req)
result = view.data()
self.assertIn('server_id', result['instance'])
self.assertIn('volume_id', result['instance'])
def test_non_admin_view(self):
self.context.is_admin = False
view = InstanceDetailView(self.instance, self.req)
result = view.data()
self.assertNotIn('server_id', result['instance'])
self.assertNotIn('volume_id', result['instance'])