Merge "Unbreak start instance and fixes bug 905270"
This commit is contained in:
@@ -1358,6 +1358,15 @@ class ComputeAPITestCase(BaseTestCase):
|
|||||||
'properties': {'kernel_id': 1, 'ramdisk_id': 1},
|
'properties': {'kernel_id': 1, 'ramdisk_id': 1},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
def _run_instance(self):
|
||||||
|
instance = self._create_fake_instance()
|
||||||
|
instance_uuid = instance['uuid']
|
||||||
|
self.compute.run_instance(self.context, instance_uuid)
|
||||||
|
|
||||||
|
instance = db.instance_get_by_uuid(self.context, instance_uuid)
|
||||||
|
self.assertEqual(instance['task_state'], None)
|
||||||
|
return instance, instance_uuid
|
||||||
|
|
||||||
def test_create_with_too_little_ram(self):
|
def test_create_with_too_little_ram(self):
|
||||||
"""Test an instance type with too little memory"""
|
"""Test an instance type with too little memory"""
|
||||||
|
|
||||||
@@ -1554,13 +1563,45 @@ class ComputeAPITestCase(BaseTestCase):
|
|||||||
|
|
||||||
db.instance_destroy(self.context, instance['id'])
|
db.instance_destroy(self.context, instance['id'])
|
||||||
|
|
||||||
def test_delete(self):
|
def test_start_shutdown(self):
|
||||||
|
def check_state(instance_uuid, power_state_, vm_state_, task_state_):
|
||||||
|
instance = db.instance_get_by_uuid(self.context, instance_uuid)
|
||||||
|
self.assertEqual(instance['power_state'], power_state_)
|
||||||
|
self.assertEqual(instance['vm_state'], vm_state_)
|
||||||
|
self.assertEqual(instance['task_state'], task_state_)
|
||||||
|
|
||||||
|
def start_check_state(instance_uuid,
|
||||||
|
power_state_, vm_state_, task_state_):
|
||||||
|
instance = db.instance_get_by_uuid(self.context, instance_uuid)
|
||||||
|
self.compute_api.start(self.context, instance)
|
||||||
|
check_state(instance_uuid, power_state_, vm_state_, task_state_)
|
||||||
|
|
||||||
instance = self._create_fake_instance()
|
instance = self._create_fake_instance()
|
||||||
instance_uuid = instance['uuid']
|
instance_uuid = instance['uuid']
|
||||||
self.compute.run_instance(self.context, instance_uuid)
|
self.compute.run_instance(self.context, instance_uuid)
|
||||||
|
|
||||||
instance = db.instance_get_by_uuid(self.context, instance_uuid)
|
check_state(instance_uuid, power_state.RUNNING, vm_states.ACTIVE, None)
|
||||||
self.assertEqual(instance['task_state'], None)
|
|
||||||
|
# NOTE(yamahata): emulate compute.manager._sync_power_state() that
|
||||||
|
# the instance is shutdown by itself
|
||||||
|
db.instance_update(self.context, instance_uuid,
|
||||||
|
{'power_state': power_state.NOSTATE,
|
||||||
|
'vm_state': vm_states.SHUTOFF})
|
||||||
|
check_state(instance_uuid, power_state.NOSTATE, vm_states.SHUTOFF,
|
||||||
|
None)
|
||||||
|
|
||||||
|
start_check_state(instance_uuid,
|
||||||
|
power_state.NOSTATE, vm_states.SHUTOFF, None)
|
||||||
|
|
||||||
|
db.instance_update(self.context, instance_uuid,
|
||||||
|
{'shutdown_terminate': False})
|
||||||
|
start_check_state(instance_uuid, power_state.NOSTATE,
|
||||||
|
vm_states.STOPPED, task_states.STARTING)
|
||||||
|
|
||||||
|
db.instance_destroy(self.context, instance['id'])
|
||||||
|
|
||||||
|
def test_delete(self):
|
||||||
|
instance, instance_uuid = self._run_instance()
|
||||||
|
|
||||||
self.compute_api.delete(self.context, instance)
|
self.compute_api.delete(self.context, instance)
|
||||||
|
|
||||||
@@ -1569,14 +1610,21 @@ class ComputeAPITestCase(BaseTestCase):
|
|||||||
|
|
||||||
db.instance_destroy(self.context, instance['id'])
|
db.instance_destroy(self.context, instance['id'])
|
||||||
|
|
||||||
def test_delete_soft(self):
|
def test_delete_fail(self):
|
||||||
instance = self._create_fake_instance()
|
instance, instance_uuid = self._run_instance()
|
||||||
instance_uuid = instance['uuid']
|
|
||||||
self.compute.run_instance(self.context, instance['uuid'])
|
instance = db.instance_update(self.context, instance_uuid,
|
||||||
|
{'disable_terminate': True})
|
||||||
|
self.compute_api.delete(self.context, instance)
|
||||||
|
|
||||||
instance = db.instance_get_by_uuid(self.context, instance_uuid)
|
instance = db.instance_get_by_uuid(self.context, instance_uuid)
|
||||||
self.assertEqual(instance['task_state'], None)
|
self.assertEqual(instance['task_state'], None)
|
||||||
|
|
||||||
|
db.instance_destroy(self.context, instance['id'])
|
||||||
|
|
||||||
|
def test_delete_soft(self):
|
||||||
|
instance, instance_uuid = self._run_instance()
|
||||||
|
|
||||||
self.compute_api.soft_delete(self.context, instance)
|
self.compute_api.soft_delete(self.context, instance)
|
||||||
|
|
||||||
instance = db.instance_get_by_uuid(self.context, instance_uuid)
|
instance = db.instance_get_by_uuid(self.context, instance_uuid)
|
||||||
@@ -1584,6 +1632,18 @@ class ComputeAPITestCase(BaseTestCase):
|
|||||||
|
|
||||||
db.instance_destroy(self.context, instance['id'])
|
db.instance_destroy(self.context, instance['id'])
|
||||||
|
|
||||||
|
def test_delete_soft_fail(self):
|
||||||
|
instance, instance_uuid = self._run_instance()
|
||||||
|
|
||||||
|
instance = db.instance_update(self.context, instance_uuid,
|
||||||
|
{'disable_terminate': True})
|
||||||
|
self.compute_api.soft_delete(self.context, instance)
|
||||||
|
|
||||||
|
instance = db.instance_get_by_uuid(self.context, instance_uuid)
|
||||||
|
self.assertEqual(instance['task_state'], None)
|
||||||
|
|
||||||
|
db.instance_destroy(self.context, instance['id'])
|
||||||
|
|
||||||
def test_force_delete(self):
|
def test_force_delete(self):
|
||||||
"""Ensure instance can be deleted after a soft delete"""
|
"""Ensure instance can be deleted after a soft delete"""
|
||||||
instance = self._create_fake_instance()
|
instance = self._create_fake_instance()
|
||||||
|
|||||||
Reference in New Issue
Block a user