21
21
from oslo_log import log as logging
22
22
23
23
import nova
24
+ from nova .compute import manager
24
25
from nova .conf import neutron as neutron_conf
25
26
from nova import context as nova_context
26
27
from nova import objects
@@ -862,6 +863,7 @@ def test_resize_dedicated_policy_race_on_dest_bug_1953359(self):
862
863
# migrate the first instance from compute1 to compute2 but stop
863
864
# migrating at the start of finish_resize. Then start a racing periodic
864
865
# update_available_resources.
866
+ orig_finish_resize = manager .ComputeManager .finish_resize
865
867
866
868
def fake_finish_resize (* args , ** kwargs ):
867
869
# start a racing update_available_resource periodic
@@ -870,34 +872,60 @@ def fake_finish_resize(*args, **kwargs):
870
872
# as the resource_tracker will use the source node numa_topology
871
873
# and that does not fit to the dest node as pcpu 0 in the dest
872
874
# is already occupied.
875
+ log = self .stdlog .logger .output
876
+ # The resize_claim correctly calculates that the instance should be
877
+ # pinned to pcpu id 1 instead of 0
878
+ self .assertIn (
879
+ 'Computed NUMA topology CPU pinning: usable pCPUs: [[1]], '
880
+ 'vCPUs mapping: [(0, 1)]' ,
881
+ log ,
882
+ )
883
+ # But the periodic fails as it tries to apply the source topology
884
+ # on the dest. This is bug 1953359.
885
+ log = self .stdlog .logger .output
886
+ self .assertIn ('Error updating resources for node compute2' , log )
887
+ self .assertIn (
888
+ 'nova.exception.CPUPinningInvalid: CPU set to pin [0] must be '
889
+ 'a subset of free CPU set [1]' ,
890
+ log ,
891
+ )
892
+
893
+ # now let the resize finishes
894
+ return orig_finish_resize (* args , ** kwargs )
873
895
874
896
# TODO(stephenfin): The mock of 'migrate_disk_and_power_off' should
875
897
# probably be less...dumb
876
898
with mock .patch ('nova.virt.libvirt.driver.LibvirtDriver'
877
899
'.migrate_disk_and_power_off' , return_value = '{}' ):
878
900
with mock .patch (
879
- 'nova.compute.manager.ComputeManager.finish_resize'
880
- ) as mock_finish_resize :
881
- mock_finish_resize . side_effect = fake_finish_resize
901
+ 'nova.compute.manager.ComputeManager.finish_resize' ,
902
+ new = fake_finish_resize ,
903
+ ):
882
904
post = {'migrate' : None }
905
+ # this is expected to succeed but logs are emitted
906
+ # from the racing periodic task. See fake_finish_resize
907
+ # for the asserts
883
908
self .admin_api .post_server_action (server ['id' ], post )
884
909
885
- log = self .stdlog .logger .output
886
- # The resize_claim correctly calculates that the inst1 should be pinned
887
- # to pcpu id 1 instead of 0
888
- self .assertIn (
889
- 'Computed NUMA topology CPU pinning: usable pCPUs: [[1]], '
890
- 'vCPUs mapping: [(0, 1)]' ,
891
- log ,
910
+ server = self ._wait_for_state_change (server , 'VERIFY_RESIZE' )
911
+
912
+ # as the periodic job raced and failed during the resize if we revert
913
+ # the instance now then it tries to unpin its cpus from the dest host
914
+ # but those was never pinned as the periodic failed. So the unpinning
915
+ # will fail too.
916
+ post = {'revertResize' : {}}
917
+ ex = self .assertRaises (
918
+ client .OpenStackApiException ,
919
+ self .admin_api .post_server_action , server ['id' ], post
892
920
)
893
- # But the periodic fails as it tries to apply the source topology on
894
- # the dest. This is bug 1953359.
895
- log = self .stdlog . logger . output
896
- self .assertIn ( 'Error updating resources for node compute2 ' , log )
921
+ # This is still bug 1953359.
922
+ self . assertEqual ( 500 , ex . response . status_code )
923
+ server = self .api . get_server ( server [ 'id' ])
924
+ self .assertEqual ( 'ERROR ' , server [ 'status' ] )
897
925
self .assertIn (
898
- 'nova.exception.CPUPinningInvalid : CPU set to pin [0 ] must be '
899
- 'a subset of free CPU set [1 ]' ,
900
- log ,
926
+ 'nova.exception.CPUUnpinningInvalid : CPU set to unpin [1 ] must be '
927
+ 'a subset of pinned CPU set [0 ]' ,
928
+ self . stdlog . logger . output ,
901
929
)
902
930
903
931
0 commit comments