Test for the nova diagnostics API
Add tests for nova API 'servers/{server_id}/diagnostics'
Change-Id: If631472081d16fe8c0b37575eb157a7b13d6fba4
This commit is contained in:
@@ -35,8 +35,11 @@ class ServersAdminTestJSON(base.BaseComputeAdminTest):
|
|||||||
cls.client = cls.os_adm.servers_client
|
cls.client = cls.os_adm.servers_client
|
||||||
cls.flavors_client = cls.os_adm.flavors_client
|
cls.flavors_client = cls.os_adm.flavors_client
|
||||||
|
|
||||||
cls.admin_client = cls._get_identity_admin_client()
|
cls.non_adm_client = cls.servers_client
|
||||||
tenant = cls.admin_client.get_tenant_by_name(
|
cls.flavors_client = cls.os_adm.flavors_client
|
||||||
|
|
||||||
|
cls.identity_client = cls._get_identity_admin_client()
|
||||||
|
tenant = cls.identity_client.get_tenant_by_name(
|
||||||
cls.client.tenant_name)
|
cls.client.tenant_name)
|
||||||
cls.tenant_id = tenant['id']
|
cls.tenant_id = tenant['id']
|
||||||
|
|
||||||
@@ -158,6 +161,24 @@ class ServersAdminTestJSON(base.BaseComputeAdminTest):
|
|||||||
self.assertRaises(exceptions.NotFound,
|
self.assertRaises(exceptions.NotFound,
|
||||||
self.client.reset_state, '999')
|
self.client.reset_state, '999')
|
||||||
|
|
||||||
|
@attr(type='gate')
|
||||||
|
def test_get_server_diagnostics_by_admin(self):
|
||||||
|
# Retrieve server diagnostics by admin user
|
||||||
|
resp, diagnostic = self.client.get_server_diagnostics(self.s1_id)
|
||||||
|
self.assertEqual(200, resp.status)
|
||||||
|
basic_attrs = ['rx_packets', 'rx_errors', 'rx_drop',
|
||||||
|
'tx_packets', 'tx_errors', 'tx_drop',
|
||||||
|
'read_req', 'write_req', 'cpu', 'memory']
|
||||||
|
for key in basic_attrs:
|
||||||
|
self.assertIn(key, str(diagnostic.keys()))
|
||||||
|
|
||||||
|
@attr(type=['negative', 'gate'])
|
||||||
|
def test_get_server_diagnostics_by_non_admin(self):
|
||||||
|
# Non-admin user can not view server diagnostics according to policy
|
||||||
|
self.assertRaises(exceptions.Unauthorized,
|
||||||
|
self.non_adm_client.get_server_diagnostics,
|
||||||
|
self.s1_id)
|
||||||
|
|
||||||
|
|
||||||
class ServersAdminTestXML(ServersAdminTestJSON):
|
class ServersAdminTestXML(ServersAdminTestJSON):
|
||||||
_interface = 'xml'
|
_interface = 'xml'
|
||||||
|
|||||||
@@ -366,6 +366,11 @@ class ServersClientJSON(RestClient):
|
|||||||
"""Unrescue the provided server."""
|
"""Unrescue the provided server."""
|
||||||
return self.action(server_id, 'unrescue', None)
|
return self.action(server_id, 'unrescue', None)
|
||||||
|
|
||||||
|
def get_server_diagnostics(self, server_id):
|
||||||
|
"""Get the usage data for a server."""
|
||||||
|
resp, body = self.get("servers/%s/diagnostics" % str(server_id))
|
||||||
|
return resp, json.loads(body)
|
||||||
|
|
||||||
def list_instance_actions(self, server_id):
|
def list_instance_actions(self, server_id):
|
||||||
"""List the provided server action."""
|
"""List the provided server action."""
|
||||||
resp, body = self.get("servers/%s/os-instance-actions" %
|
resp, body = self.get("servers/%s/os-instance-actions" %
|
||||||
|
|||||||
@@ -575,6 +575,13 @@ class ServersClientXML(RestClientXML):
|
|||||||
(server_id, volume_id), headers)
|
(server_id, volume_id), headers)
|
||||||
return resp, body
|
return resp, body
|
||||||
|
|
||||||
|
def get_server_diagnostics(self, server_id):
|
||||||
|
"""Get the usage data for a server."""
|
||||||
|
resp, body = self.get("servers/%s/diagnostics" % server_id,
|
||||||
|
self.headers)
|
||||||
|
body = xml_to_json(etree.fromstring(body))
|
||||||
|
return resp, body
|
||||||
|
|
||||||
def list_instance_actions(self, server_id):
|
def list_instance_actions(self, server_id):
|
||||||
"""List the provided server action."""
|
"""List the provided server action."""
|
||||||
resp, body = self.get("servers/%s/os-instance-actions" % server_id,
|
resp, body = self.get("servers/%s/os-instance-actions" % server_id,
|
||||||
|
|||||||
Reference in New Issue
Block a user