Skip to content

Commit b1de451

Browse files
Zuulopenstack-gerrit
authored andcommitted
Merge "unit test: do not fill rp mapping for failed re-schedule"
2 parents c34b783 + 8a1ea45 commit b1de451

File tree

1 file changed

+72
-0
lines changed

1 file changed

+72
-0
lines changed

nova/tests/unit/conductor/tasks/test_migrate.py

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
# under the License.
1212

1313
import mock
14+
from oslo_serialization import jsonutils
1415
from oslo_utils.fixture import uuidsentinel as uuids
1516

1617
from nova.compute import rpcapi as compute_rpcapi
@@ -220,6 +221,77 @@ def set_migration_uuid(*a, **k):
220221
mock_get_resources.assert_called_once_with(
221222
self.context, self.instance.uuid)
222223

224+
@mock.patch.object(scheduler_utils, 'fill_provider_mapping')
225+
@mock.patch.object(scheduler_utils, 'claim_resources')
226+
@mock.patch.object(context.RequestContext, 'elevated')
227+
def test_execute_reschedule(
228+
self, mock_elevated, mock_claim, mock_fill_provider_mapping):
229+
report_client = report.SchedulerReportClient()
230+
# setup task for re-schedule
231+
alloc_req = {
232+
"allocations": {
233+
uuids.host1: {
234+
"resources": {
235+
"VCPU": 1,
236+
"MEMORY_MB": 1024,
237+
"DISK_GB": 100}}}}
238+
alternate_selection = objects.Selection(
239+
service_host="host1",
240+
nodename="node1",
241+
cell_uuid=uuids.cell1,
242+
allocation_request=jsonutils.dumps(alloc_req),
243+
allocation_request_version='1.19')
244+
task = migrate.MigrationTask(
245+
self.context, self.instance, self.flavor, self.request_spec,
246+
self.clean_shutdown, compute_rpcapi.ComputeAPI(),
247+
query.SchedulerQueryClient(), report_client,
248+
host_list=[alternate_selection], network_api=self.mock_network_api)
249+
mock_claim.return_value = True
250+
251+
actual_selection = task._reschedule()
252+
253+
self.assertIs(alternate_selection, actual_selection)
254+
mock_claim.assert_called_once_with(
255+
mock_elevated.return_value, report_client, self.request_spec,
256+
self.instance.uuid, alloc_req, '1.19')
257+
mock_fill_provider_mapping.assert_called_once_with(
258+
self.context, report_client, self.request_spec,
259+
alternate_selection)
260+
261+
@mock.patch.object(scheduler_utils, 'fill_provider_mapping')
262+
@mock.patch.object(scheduler_utils, 'claim_resources')
263+
@mock.patch.object(context.RequestContext, 'elevated')
264+
def test_execute_reschedule_claim_fails_no_more_alternate(
265+
self, mock_elevated, mock_claim, mock_fill_provider_mapping):
266+
report_client = report.SchedulerReportClient()
267+
# set up the task for re-schedule
268+
alloc_req = {
269+
"allocations": {
270+
uuids.host1: {
271+
"resources": {
272+
"VCPU": 1,
273+
"MEMORY_MB": 1024,
274+
"DISK_GB": 100}}}}
275+
alternate_selection = objects.Selection(
276+
service_host="host1",
277+
nodename="node1",
278+
cell_uuid=uuids.cell1,
279+
allocation_request=jsonutils.dumps(alloc_req),
280+
allocation_request_version='1.19')
281+
task = migrate.MigrationTask(
282+
self.context, self.instance, self.flavor, self.request_spec,
283+
self.clean_shutdown, compute_rpcapi.ComputeAPI(),
284+
query.SchedulerQueryClient(), report_client,
285+
host_list=[alternate_selection], network_api=self.mock_network_api)
286+
mock_claim.return_value = False
287+
288+
self.assertRaises(exception.MaxRetriesExceeded, task._reschedule)
289+
290+
mock_claim.assert_called_once_with(
291+
mock_elevated.return_value, report_client, self.request_spec,
292+
self.instance.uuid, alloc_req, '1.19')
293+
mock_fill_provider_mapping.assert_not_called()
294+
223295

224296
class MigrationTaskAllocationUtils(test.NoDBTestCase):
225297
@mock.patch('nova.objects.ComputeNode.get_by_host_and_nodename')

0 commit comments

Comments
 (0)