Add preparation for asynchronous instance faults
Add InstanceFault model Migration for new instance_faults table Functions to add and get instance faults A single example of how faults should be added Change-Id: I439e2419240de24a728045046153451eb8a0d267
This commit is contained in:
@@ -21,6 +21,7 @@ Tests For Compute
|
|||||||
"""
|
"""
|
||||||
|
|
||||||
from copy import copy
|
from copy import copy
|
||||||
|
from webob import exc
|
||||||
|
|
||||||
import mox
|
import mox
|
||||||
|
|
||||||
@@ -1063,6 +1064,60 @@ class ComputeTestCase(BaseTestCase):
|
|||||||
self.assertEqual(len(instances), 1)
|
self.assertEqual(len(instances), 1)
|
||||||
self.assertEqual(power_state.NOSTATE, instances[0]['power_state'])
|
self.assertEqual(power_state.NOSTATE, instances[0]['power_state'])
|
||||||
|
|
||||||
|
def test_add_instance_fault(self):
|
||||||
|
instance_uuid = str(utils.gen_uuid())
|
||||||
|
|
||||||
|
def fake_db_fault_create(ctxt, values):
|
||||||
|
expected = {
|
||||||
|
'code': 404,
|
||||||
|
'message': 'HTTPNotFound',
|
||||||
|
'details': 'Error Details',
|
||||||
|
'instance_uuid': instance_uuid,
|
||||||
|
}
|
||||||
|
self.assertEquals(expected, values)
|
||||||
|
|
||||||
|
self.stubs.Set(nova.db, 'instance_fault_create', fake_db_fault_create)
|
||||||
|
|
||||||
|
ctxt = context.get_admin_context()
|
||||||
|
self.compute.add_instance_fault(ctxt, instance_uuid, 404,
|
||||||
|
'HTTPNotFound', 'Error Details')
|
||||||
|
|
||||||
|
def test_add_instance_fault_error(self):
|
||||||
|
instance_uuid = str(utils.gen_uuid())
|
||||||
|
|
||||||
|
def fake_db_fault_create(ctxt, values):
|
||||||
|
expected = {
|
||||||
|
'code': 500,
|
||||||
|
'message': 'NotImplementedError',
|
||||||
|
'details': '',
|
||||||
|
'instance_uuid': instance_uuid,
|
||||||
|
}
|
||||||
|
self.assertEquals(expected, values)
|
||||||
|
|
||||||
|
self.stubs.Set(nova.db, 'instance_fault_create', fake_db_fault_create)
|
||||||
|
|
||||||
|
ctxt = context.get_admin_context()
|
||||||
|
self.compute.add_instance_fault_from_exc(ctxt, instance_uuid,
|
||||||
|
NotImplementedError())
|
||||||
|
|
||||||
|
def test_add_instance_fault_http_exception(self):
|
||||||
|
instance_uuid = str(utils.gen_uuid())
|
||||||
|
|
||||||
|
def fake_db_fault_create(ctxt, values):
|
||||||
|
expected = {
|
||||||
|
'code': 404,
|
||||||
|
'message': 'HTTPNotFound',
|
||||||
|
'details': 'Error Details',
|
||||||
|
'instance_uuid': instance_uuid,
|
||||||
|
}
|
||||||
|
self.assertEquals(expected, values)
|
||||||
|
|
||||||
|
self.stubs.Set(nova.db, 'instance_fault_create', fake_db_fault_create)
|
||||||
|
|
||||||
|
ctxt = context.get_admin_context()
|
||||||
|
self.compute.add_instance_fault_from_exc(ctxt, instance_uuid,
|
||||||
|
exc.HTTPNotFound("Error Details"))
|
||||||
|
|
||||||
|
|
||||||
class ComputeAPITestCase(BaseTestCase):
|
class ComputeAPITestCase(BaseTestCase):
|
||||||
|
|
||||||
|
|||||||
@@ -24,6 +24,7 @@ from nova import test
|
|||||||
from nova import context
|
from nova import context
|
||||||
from nova import db
|
from nova import db
|
||||||
from nova import flags
|
from nova import flags
|
||||||
|
from nova import utils
|
||||||
|
|
||||||
FLAGS = flags.FLAGS
|
FLAGS = flags.FLAGS
|
||||||
|
|
||||||
@@ -192,3 +193,74 @@ class DbApiTestCase(test.TestCase):
|
|||||||
# Retrieve the metadata to ensure it was successfully updated
|
# Retrieve the metadata to ensure it was successfully updated
|
||||||
instance_meta = db.instance_metadata_get(ctxt, instance.id)
|
instance_meta = db.instance_metadata_get(ctxt, instance.id)
|
||||||
self.assertEqual('bar', instance_meta['host'])
|
self.assertEqual('bar', instance_meta['host'])
|
||||||
|
|
||||||
|
def test_instance_fault_create(self):
|
||||||
|
"""Ensure we can create an instance fault"""
|
||||||
|
ctxt = context.get_admin_context()
|
||||||
|
uuid = str(utils.gen_uuid())
|
||||||
|
|
||||||
|
# Create a fault
|
||||||
|
fault_values = {
|
||||||
|
'message': 'message',
|
||||||
|
'details': 'detail',
|
||||||
|
'instance_uuid': uuid,
|
||||||
|
'code': 404,
|
||||||
|
}
|
||||||
|
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'])
|
||||||
|
|
||||||
|
def test_instance_fault_get_by_instance(self):
|
||||||
|
""" ensure we can retrieve an instance fault by instance UUID """
|
||||||
|
ctxt = context.get_admin_context()
|
||||||
|
|
||||||
|
# Create faults
|
||||||
|
uuid = str(utils.gen_uuid())
|
||||||
|
fault_values = {
|
||||||
|
'message': 'message',
|
||||||
|
'details': 'detail',
|
||||||
|
'instance_uuid': uuid,
|
||||||
|
'code': 404,
|
||||||
|
}
|
||||||
|
db.instance_fault_create(ctxt, fault_values)
|
||||||
|
|
||||||
|
uuid2 = str(utils.gen_uuid())
|
||||||
|
fault_values = {
|
||||||
|
'message': 'message',
|
||||||
|
'details': 'detail',
|
||||||
|
'instance_uuid': uuid2,
|
||||||
|
'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()
|
||||||
|
|
||||||
|
# Create faults
|
||||||
|
uuid = str(utils.gen_uuid())
|
||||||
|
fault_values = {
|
||||||
|
'message': 'message',
|
||||||
|
'details': 'detail',
|
||||||
|
'instance_uuid': uuid,
|
||||||
|
'code': 404,
|
||||||
|
}
|
||||||
|
db.instance_fault_create(ctxt, fault_values)
|
||||||
|
|
||||||
|
fault_values = {
|
||||||
|
'message': 'message',
|
||||||
|
'details': 'detail',
|
||||||
|
'instance_uuid': uuid,
|
||||||
|
'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, uuid)
|
||||||
|
self.assertEqual(500, instance_fault['code'])
|
||||||
|
|||||||
Reference in New Issue
Block a user