@@ -677,6 +677,30 @@ def test_unshelve_with_resource_request_update_raises(
677
677
self .context , self .compute .reportclient , [],
678
678
{uuids .port_1 : [uuids .rp1 ]})
679
679
680
+ def test_unshelve_spawn_fails_cleanup_instance_image_ref (self ):
681
+ """Tests error handling when a instance fails to unshelve and makes
682
+ sure to revert instance.image_ref to the initial value instead of
683
+ keeping the one of shelved image
684
+ https://bugs.launchpad.net/nova/+bug/1934094
685
+ """
686
+ instance = self ._create_fake_instance_obj ()
687
+ # TODO(pslestang) to uncomment when bug 1934094 is fixed
688
+ # initial_image_ref = instance.image_ref
689
+
690
+ fake_spec = objects .RequestSpec ()
691
+ shelved_image = {'id' : uuids .image_id }
692
+
693
+ with mock .patch .object (self .compute .driver , 'spawn' ,
694
+ side_effect = test .TestingException ('Spawn Failed' )):
695
+ self .assertRaises (test .TestingException ,
696
+ self .compute .unshelve_instance , self .context , instance ,
697
+ image = shelved_image , filter_properties = {},
698
+ node = 'fake-node' , request_spec = fake_spec , accel_uuids = [])
699
+ # FIXME(pslestang) Until bug 1934094 is fixed
700
+ # The instance.image_ref is set to shelved_image.id but should be
701
+ # equal to initial_image_ref
702
+ self .assertEqual (instance .image_ref , shelved_image ['id' ])
703
+
680
704
@mock .patch .object (objects .InstanceList , 'get_by_filters' )
681
705
def test_shelved_poll_none_offloaded (self , mock_get_by_filters ):
682
706
# Test instances are not offloaded when shelved_offload_time is -1
0 commit comments