summaryrefslogtreecommitdiffstats
path: root/nova/tests
diff options
context:
space:
mode:
authorJenkins <jenkins@review.openstack.org>2011-12-15 19:07:35 +0000
committerGerrit Code Review <review@openstack.org>2011-12-15 19:07:35 +0000
commitcce41ac10df9aa978e1202f5947d698cd30d9d62 (patch)
tree72f70e914bbfa5cd9bcd03625a798c977b3db1f1 /nova/tests
parent8eeb132f80acdf3f05edd5594bce54dde5fb789c (diff)
parent0d71f29583c68c2488d5917f3fdaa7b7011186a1 (diff)
Merge "Expose Asynchronous Fault entity in the OSAPI"
Diffstat (limited to 'nova/tests')
-rw-r--r--nova/tests/api/openstack/v2/test_servers.py167
-rw-r--r--nova/tests/test_compute.py27
-rw-r--r--nova/tests/test_db_api.py56
3 files changed, 225 insertions, 25 deletions
diff --git a/nova/tests/api/openstack/v2/test_servers.py b/nova/tests/api/openstack/v2/test_servers.py
index 243438ca5..23621fd7f 100644
--- a/nova/tests/api/openstack/v2/test_servers.py
+++ b/nova/tests/api/openstack/v2/test_servers.py
@@ -2447,6 +2447,158 @@ class ServersViewBuilderTest(test.TestCase):
output = self.view_builder.show(self.request, self.instance)
self.assertDictMatch(output, expected_server)
+ def test_build_server_detail_with_fault(self):
+ self.instance['vm_state'] = vm_states.ERROR
+ self.instance['fault'] = {
+ 'code': 404,
+ 'instance_uuid': self.uuid,
+ 'message': "HTTPNotFound",
+ 'details': "Stock details for test",
+ 'created_at': datetime.datetime(2010, 10, 10, 12, 0, 0),
+ }
+
+ image_bookmark = "http://localhost/fake/images/5"
+ flavor_bookmark = "http://localhost/fake/flavors/1"
+ self_link = "http://localhost/v2/fake/servers/%s" % self.uuid
+ bookmark_link = "http://localhost/fake/servers/%s" % self.uuid
+ expected_server = {
+ "server": {
+ "id": self.uuid,
+ "user_id": "fake",
+ "tenant_id": "fake",
+ "updated": "2010-11-11T11:00:00Z",
+ "created": "2010-10-10T12:00:00Z",
+ "name": "test_server",
+ "status": "ERROR",
+ "accessIPv4": "",
+ "accessIPv6": "",
+ "hostId": '',
+ "key_name": '',
+ "image": {
+ "id": "5",
+ "links": [
+ {
+ "rel": "bookmark",
+ "href": image_bookmark,
+ },
+ ],
+ },
+ "flavor": {
+ "id": "1",
+ "links": [
+ {
+ "rel": "bookmark",
+ "href": flavor_bookmark,
+ },
+ ],
+ },
+ "addresses": {
+ 'private': [
+ {'version': 4, 'addr': '172.19.0.1'}
+ ],
+ 'public': [
+ {'version': 6, 'addr': 'b33f::fdee:ddff:fecc:bbaa'},
+ {'version': 4, 'addr': '192.168.0.3'},
+ ],
+ },
+ "metadata": {},
+ "config_drive": None,
+ "links": [
+ {
+ "rel": "self",
+ "href": self_link,
+ },
+ {
+ "rel": "bookmark",
+ "href": bookmark_link,
+ },
+ ],
+ "fault": {
+ "code": 404,
+ "created": "2010-10-10T12:00:00Z",
+ "message": "HTTPNotFound",
+ "details": "Stock details for test",
+ },
+ }
+ }
+
+ output = self.view_builder.show(self.request, self.instance)
+ self.assertDictMatch(output, expected_server)
+
+ def test_build_server_detail_with_fault_but_active(self):
+ self.instance['vm_state'] = vm_states.ACTIVE
+ self.instance['progress'] = 100
+ self.instance['fault'] = {
+ 'code': 404,
+ 'instance_uuid': self.uuid,
+ 'message': "HTTPNotFound",
+ 'details': "Stock details for test",
+ 'created_at': datetime.datetime(2010, 10, 10, 12, 0, 0),
+ }
+
+ image_bookmark = "http://localhost/fake/images/5"
+ flavor_bookmark = "http://localhost/fake/flavors/1"
+ self_link = "http://localhost/v2/fake/servers/%s" % self.uuid
+ bookmark_link = "http://localhost/fake/servers/%s" % self.uuid
+ expected_server = {
+ "server": {
+ "id": self.uuid,
+ "user_id": "fake",
+ "tenant_id": "fake",
+ "updated": "2010-11-11T11:00:00Z",
+ "created": "2010-10-10T12:00:00Z",
+ "progress": 100,
+ "name": "test_server",
+ "status": "ACTIVE",
+ "accessIPv4": "",
+ "accessIPv6": "",
+ "hostId": '',
+ "key_name": '',
+ "image": {
+ "id": "5",
+ "links": [
+ {
+ "rel": "bookmark",
+ "href": image_bookmark,
+ },
+ ],
+ },
+ "flavor": {
+ "id": "1",
+ "links": [
+ {
+ "rel": "bookmark",
+ "href": flavor_bookmark,
+ },
+ ],
+ },
+ "addresses": {
+ 'private': [
+ {'version': 4, 'addr': '172.19.0.1'}
+ ],
+ 'public': [
+ {'version': 6, 'addr': 'b33f::fdee:ddff:fecc:bbaa'},
+ {'version': 4, 'addr': '192.168.0.3'},
+ ],
+ },
+ "metadata": {},
+ "config_drive": None,
+ "links": [
+ {
+ "rel": "self",
+ "href": self_link,
+ },
+ {
+ "rel": "bookmark",
+ "href": bookmark_link,
+ },
+ ],
+ }
+ }
+
+ output = self.view_builder.show(self.request, self.instance)
+ self.assertDictMatch(output, expected_server)
+
def test_build_server_detail_active_status(self):
#set the power state of the instance to running
self.instance['vm_state'] = vm_states.ACTIVE
@@ -3457,6 +3609,12 @@ class ServerXMLSerializationTest(test.TestCase):
'rel': 'bookmark',
},
],
+ "fault": {
+ "code": 500,
+ "created": self.TIMESTAMP,
+ "message": "Error Message",
+ "details": "Fault details",
+ }
}
}
@@ -3517,6 +3675,15 @@ class ServerXMLSerializationTest(test.TestCase):
self.assertEqual(str(ip_elem.get('addr')),
str(ip['addr']))
+ fault_root = root.find('{0}fault'.format(NS))
+ fault_dict = server_dict['fault']
+ self.assertEqual(fault_root.get("code"), str(fault_dict["code"]))
+ self.assertEqual(fault_root.get("created"), fault_dict["created"])
+ msg_elem = fault_root.find('{0}message'.format(NS))
+ self.assertEqual(msg_elem.text, fault_dict["message"])
+ det_elem = fault_root.find('{0}details'.format(NS))
+ self.assertEqual(det_elem.text, fault_dict["details"])
+
def test_action(self):
serializer = servers.ServerXMLSerializer()
diff --git a/nova/tests/test_compute.py b/nova/tests/test_compute.py
index 883ee0173..b70f444e9 100644
--- a/nova/tests/test_compute.py
+++ b/nova/tests/test_compute.py
@@ -20,6 +20,7 @@
Tests For Compute
"""
from copy import copy
+import datetime
from webob import exc
import mox
@@ -2262,6 +2263,32 @@ class ComputeAPITestCase(BaseTestCase):
db.instance_destroy(_context, instance['uuid'])
+ def test_get_instance_faults(self):
+ """Get an instances latest fault"""
+ instance = self._create_fake_instance()
+
+ fault_fixture = {
+ 'code': 404,
+ 'instance_uuid': instance['uuid'],
+ 'message': "HTTPNotFound",
+ 'details': "Stock details for test",
+ 'created_at': datetime.datetime(2010, 10, 10, 12, 0, 0),
+ }
+
+ def return_fault(_ctxt, instance_uuids):
+ return dict.fromkeys(instance_uuids, [fault_fixture])
+
+ self.stubs.Set(nova.db,
+ 'instance_fault_get_by_instance_uuids',
+ return_fault)
+
+ _context = context.get_admin_context()
+ output = self.compute_api.get_instance_faults(_context, [instance])
+ expected = {instance['uuid']: [fault_fixture]}
+ self.assertEqual(output, expected)
+
+ db.instance_destroy(_context, instance['uuid'])
+
@staticmethod
def _parse_db_block_device_mapping(bdm_ref):
attr_list = ('delete_on_termination', 'device_name', 'no_device',
diff --git a/nova/tests/test_db_api.py b/nova/tests/test_db_api.py
index 36b5eced4..314a9f276 100644
--- a/nova/tests/test_db_api.py
+++ b/nova/tests/test_db_api.py
@@ -209,58 +209,64 @@ class DbApiTestCase(test.TestCase):
db.instance_fault_create(ctxt, fault_values)
# Retrieve the fault to ensure it was successfully added
- instance_fault = db.instance_fault_get_by_instance(ctxt, uuid)
- self.assertEqual(404, instance_fault['code'])
+ faults = db.instance_fault_get_by_instance_uuids(ctxt, [uuid])
+ self.assertEqual(404, faults[uuid][0]['code'])
def test_instance_fault_get_by_instance(self):
""" ensure we can retrieve an instance fault by instance UUID """
ctxt = context.get_admin_context()
+ instance1 = db.instance_create(ctxt, {})
+ instance2 = db.instance_create(ctxt, {})
+ uuids = [instance1['uuid'], instance2['uuid']]
# Create faults
- uuid = str(utils.gen_uuid())
fault_values = {
'message': 'message',
'details': 'detail',
- 'instance_uuid': uuid,
+ 'instance_uuid': uuids[0],
'code': 404,
}
- db.instance_fault_create(ctxt, fault_values)
+ fault1 = db.instance_fault_create(ctxt, fault_values)
- uuid2 = str(utils.gen_uuid())
fault_values = {
'message': 'message',
'details': 'detail',
- 'instance_uuid': uuid2,
+ 'instance_uuid': uuids[0],
'code': 500,
}
- db.instance_fault_create(ctxt, fault_values)
-
- # Retrieve the fault to ensure it was successfully added
- instance_fault = db.instance_fault_get_by_instance(ctxt, uuid2)
- self.assertEqual(500, instance_fault['code'])
-
- def test_instance_fault_get_by_instance_first_fault(self):
- """Instance_fault_get_by_instance should return the latest fault """
- ctxt = context.get_admin_context()
+ fault2 = db.instance_fault_create(ctxt, fault_values)
- # Create faults
- uuid = str(utils.gen_uuid())
fault_values = {
'message': 'message',
'details': 'detail',
- 'instance_uuid': uuid,
+ 'instance_uuid': uuids[1],
'code': 404,
}
- db.instance_fault_create(ctxt, fault_values)
+ fault3 = db.instance_fault_create(ctxt, fault_values)
fault_values = {
'message': 'message',
'details': 'detail',
- 'instance_uuid': uuid,
+ 'instance_uuid': uuids[1],
'code': 500,
}
- db.instance_fault_create(ctxt, fault_values)
+ fault4 = db.instance_fault_create(ctxt, fault_values)
- # Retrieve the fault to ensure it was successfully added
- instance_fault = db.instance_fault_get_by_instance(ctxt, uuid)
- self.assertEqual(500, instance_fault['code'])
+ instance_faults = db.instance_fault_get_by_instance_uuids(ctxt, uuids)
+
+ expected = {
+ uuids[0]: [fault2, fault1],
+ uuids[1]: [fault4, fault3],
+ }
+
+ self.assertEqual(instance_faults, expected)
+
+ def test_instance_faults_get_by_instance_uuids_no_faults(self):
+ """None should be returned when no faults exist"""
+ ctxt = context.get_admin_context()
+ instance1 = db.instance_create(ctxt, {})
+ instance2 = db.instance_create(ctxt, {})
+ uuids = [instance1['uuid'], instance2['uuid']]
+ instance_faults = db.instance_fault_get_by_instance_uuids(ctxt, uuids)
+ expected = {uuids[0]: [], uuids[1]: []}
+ self.assertEqual(expected, instance_faults)