2020from oslo_log import log as logging
2121
2222import nova
23+ from nova .compute import manager
2324from nova .conf import neutron as neutron_conf
2425from nova import context as nova_context
2526from nova import objects
@@ -972,6 +973,7 @@ def test_resize_dedicated_policy_race_on_dest_bug_1953359(self):
972973 # migrate the first instance from compute1 to compute2 but stop
973974 # migrating at the start of finish_resize. Then start a racing periodic
974975 # update_available_resources.
976+ orig_finish_resize = manager .ComputeManager .finish_resize
975977
976978 def fake_finish_resize (* args , ** kwargs ):
977979 # start a racing update_available_resource periodic
@@ -980,34 +982,60 @@ def fake_finish_resize(*args, **kwargs):
980982 # as the resource_tracker will use the source node numa_topology
981983 # and that does not fit to the dest node as pcpu 0 in the dest
982984 # is already occupied.
985+ log = self .stdlog .logger .output
986+ # The resize_claim correctly calculates that the instance should be
987+ # pinned to pcpu id 1 instead of 0
988+ self .assertIn (
989+ 'Computed NUMA topology CPU pinning: usable pCPUs: [[1]], '
990+ 'vCPUs mapping: [(0, 1)]' ,
991+ log ,
992+ )
993+ # But the periodic fails as it tries to apply the source topology
994+ # on the dest. This is bug 1953359.
995+ log = self .stdlog .logger .output
996+ self .assertIn ('Error updating resources for node compute2' , log )
997+ self .assertIn (
998+ 'nova.exception.CPUPinningInvalid: CPU set to pin [0] must be '
999+ 'a subset of free CPU set [1]' ,
1000+ log ,
1001+ )
1002+
1003+ # now let the resize finishes
1004+ return orig_finish_resize (* args , ** kwargs )
9831005
9841006 # TODO(stephenfin): The mock of 'migrate_disk_and_power_off' should
9851007 # probably be less...dumb
9861008 with mock .patch ('nova.virt.libvirt.driver.LibvirtDriver'
9871009 '.migrate_disk_and_power_off' , return_value = '{}' ):
9881010 with mock .patch (
989- 'nova.compute.manager.ComputeManager.finish_resize'
990- ) as mock_finish_resize :
991- mock_finish_resize . side_effect = fake_finish_resize
1011+ 'nova.compute.manager.ComputeManager.finish_resize' ,
1012+ new = fake_finish_resize ,
1013+ ):
9921014 post = {'migrate' : None }
1015+ # this is expected to succeed but logs are emitted
1016+ # from the racing periodic task. See fake_finish_resize
1017+ # for the asserts
9931018 self .admin_api .post_server_action (server ['id' ], post )
9941019
995- log = self .stdlog .logger .output
996- # The resize_claim correctly calculates that the inst1 should be pinned
997- # to pcpu id 1 instead of 0
998- self .assertIn (
999- 'Computed NUMA topology CPU pinning: usable pCPUs: [[1]], '
1000- 'vCPUs mapping: [(0, 1)]' ,
1001- log ,
1020+ server = self ._wait_for_state_change (server , 'VERIFY_RESIZE' )
1021+
1022+ # as the periodic job raced and failed during the resize if we revert
1023+ # the instance now then it tries to unpin its cpus from the dest host
1024+ # but those was never pinned as the periodic failed. So the unpinning
1025+ # will fail too.
1026+ post = {'revertResize' : {}}
1027+ ex = self .assertRaises (
1028+ client .OpenStackApiException ,
1029+ self .admin_api .post_server_action , server ['id' ], post
10021030 )
1003- # But the periodic fails as it tries to apply the source topology on
1004- # the dest. This is bug 1953359.
1005- log = self .stdlog . logger . output
1006- self .assertIn ( 'Error updating resources for node compute2 ' , log )
1031+ # This is still bug 1953359.
1032+ self . assertEqual ( 500 , ex . response . status_code )
1033+ server = self .api . get_server ( server [ 'id' ])
1034+ self .assertEqual ( 'ERROR ' , server [ 'status' ] )
10071035 self .assertIn (
1008- 'nova.exception.CPUPinningInvalid : CPU set to pin [0 ] must be '
1009- 'a subset of free CPU set [1 ]' ,
1010- log ,
1036+ 'nova.exception.CPUUnpinningInvalid : CPU set to unpin [1 ] must be '
1037+ 'a subset of pinned CPU set [0 ]' ,
1038+ self . stdlog . logger . output ,
10111039 )
10121040
10131041
0 commit comments