fix missing host when unshelving
An instance has the hostname of the host on which it is running.
The hostname is deleted when shelving. However, the hostname is not
recreated when unshelving.
This patch sets the hostname when unshelving.
Change-Id: I2e431718198321c46b9335e6fb7ab7be3943fab6
Closes-Bug: #1237868
(cherry picked from commit 9532e4ed96
)
This commit is contained in:
parent
bcdc813194
commit
298f052f1f
@ -3454,7 +3454,10 @@ class ComputeManager(manager.SchedulerDependentManager):
|
||||
|
||||
def _unshelve_instance(self, context, instance, image):
|
||||
self._notify_about_instance_usage(context, instance, 'unshelve.start')
|
||||
compute_info = self._get_compute_info(context, self.host)
|
||||
instance.task_state = task_states.SPAWNING
|
||||
instance.node = compute_info['hypervisor_hostname']
|
||||
instance.host = self.host
|
||||
instance.save()
|
||||
|
||||
network_info = self._get_instance_nw_info(context, instance)
|
||||
|
@ -148,11 +148,14 @@ class ShelveComputeManagerTestCase(test_compute.BaseTestCase):
|
||||
sys_meta['shelved_at'] = timeutils.strtime(at=cur_time)
|
||||
sys_meta['shelved_image_id'] = image['id']
|
||||
sys_meta['shelved_host'] = host
|
||||
hypervisor_hostname = 'fake_hypervisor_hostname'
|
||||
fake_compute_info = {'hypervisor_hostname': hypervisor_hostname}
|
||||
|
||||
self.mox.StubOutWithMock(self.compute, '_notify_about_instance_usage')
|
||||
self.mox.StubOutWithMock(self.compute, '_prep_block_device')
|
||||
self.mox.StubOutWithMock(self.compute.driver, 'spawn')
|
||||
self.mox.StubOutWithMock(self.compute, '_get_power_state')
|
||||
self.mox.StubOutWithMock(self.compute, '_get_compute_info')
|
||||
self.mox.StubOutWithMock(db, 'instance_update_and_get_original')
|
||||
|
||||
self.deleted_image_id = None
|
||||
@ -165,8 +168,12 @@ class ShelveComputeManagerTestCase(test_compute.BaseTestCase):
|
||||
|
||||
self.compute._notify_about_instance_usage(self.context, instance,
|
||||
'unshelve.start')
|
||||
self.compute._get_compute_info(mox.IgnoreArg(),
|
||||
mox.IgnoreArg()).AndReturn(
|
||||
fake_compute_info)
|
||||
db.instance_update_and_get_original(self.context, instance['uuid'],
|
||||
{'task_state': task_states.SPAWNING},
|
||||
{'task_state': task_states.SPAWNING, 'host': host,
|
||||
'node': hypervisor_hostname},
|
||||
update_cells=False,
|
||||
columns_to_join=['metadata', 'system_metadata'],
|
||||
).AndReturn((db_instance, db_instance))
|
||||
@ -197,6 +204,7 @@ class ShelveComputeManagerTestCase(test_compute.BaseTestCase):
|
||||
self.compute.unshelve_instance(self.context, instance,
|
||||
image=image)
|
||||
self.assertEqual(image['id'], self.deleted_image_id)
|
||||
self.assertEqual(instance.host, self.compute.host)
|
||||
|
||||
self.mox.VerifyAll()
|
||||
self.mox.UnsetStubs()
|
||||
@ -219,17 +227,24 @@ class ShelveComputeManagerTestCase(test_compute.BaseTestCase):
|
||||
sys_meta['shelved_at'] = timeutils.strtime(at=cur_time)
|
||||
sys_meta['shelved_image_id'] = None
|
||||
sys_meta['shelved_host'] = host
|
||||
hypervisor_hostname = 'fake_hypervisor_hostname'
|
||||
fake_compute_info = {'hypervisor_hostname': hypervisor_hostname}
|
||||
|
||||
self.mox.StubOutWithMock(self.compute, '_notify_about_instance_usage')
|
||||
self.mox.StubOutWithMock(self.compute, '_prep_block_device')
|
||||
self.mox.StubOutWithMock(self.compute.driver, 'spawn')
|
||||
self.mox.StubOutWithMock(self.compute, '_get_power_state')
|
||||
self.mox.StubOutWithMock(self.compute, '_get_compute_info')
|
||||
self.mox.StubOutWithMock(db, 'instance_update_and_get_original')
|
||||
|
||||
self.compute._notify_about_instance_usage(self.context, instance,
|
||||
'unshelve.start')
|
||||
self.compute._get_compute_info(mox.IgnoreArg(),
|
||||
mox.IgnoreArg()).AndReturn(
|
||||
fake_compute_info)
|
||||
db.instance_update_and_get_original(self.context, instance['uuid'],
|
||||
{'task_state': task_states.SPAWNING},
|
||||
{'task_state': task_states.SPAWNING, 'host': host,
|
||||
'node': hypervisor_hostname},
|
||||
update_cells=False,
|
||||
columns_to_join=['metadata', 'system_metadata']
|
||||
).AndReturn((db_instance, db_instance))
|
||||
|
Loading…
Reference in New Issue
Block a user