summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorZuul <zuul@review.openstack.org>2018-05-20 22:06:18 +0000
committerGerrit Code Review <review@openstack.org>2018-05-20 22:06:18 +0000
commitaa7714cf48f2653b4d0a3cb5aa104d4b4f41ed52 (patch)
treec6d3e907d373c22d52ba62f9464f1dc9ea5a6201
parente776cadb3876e7107c35ad7645e9ceec1af2030c (diff)
parentffbf5918c650e8499de206b73f050d5e8580b04e (diff)
Merge "Skip placement on rebuild in same host" into stable/pikestable/pike
-rw-r--r--nova/scheduler/manager.py3
-rw-r--r--nova/tests/fixtures.py4
-rw-r--r--nova/tests/functional/test_servers.py12
-rw-r--r--nova/tests/unit/scheduler/test_scheduler.py16
4 files changed, 34 insertions, 1 deletions
diff --git a/nova/scheduler/manager.py b/nova/scheduler/manager.py
index 0db7ddb..55d6d6e 100644
--- a/nova/scheduler/manager.py
+++ b/nova/scheduler/manager.py
@@ -119,8 +119,9 @@ class SchedulerManager(manager.Manager):
119 request_spec, 119 request_spec,
120 filter_properties) 120 filter_properties)
121 resources = utils.resources_from_request_spec(spec_obj) 121 resources = utils.resources_from_request_spec(spec_obj)
122 is_rebuild = utils.request_is_rebuild(spec_obj)
122 alloc_reqs_by_rp_uuid, provider_summaries = None, None 123 alloc_reqs_by_rp_uuid, provider_summaries = None, None
123 if self.driver.USES_ALLOCATION_CANDIDATES: 124 if self.driver.USES_ALLOCATION_CANDIDATES and not is_rebuild:
124 res = self.placement_client.get_allocation_candidates(resources) 125 res = self.placement_client.get_allocation_candidates(resources)
125 if res is None: 126 if res is None:
126 # We have to handle the case that we failed to connect to the 127 # We have to handle the case that we failed to connect to the
diff --git a/nova/tests/fixtures.py b/nova/tests/fixtures.py
index 5d1626f..c6da937 100644
--- a/nova/tests/fixtures.py
+++ b/nova/tests/fixtures.py
@@ -1446,6 +1446,10 @@ class PlacementApiClient(object):
1446 def get(self, url): 1446 def get(self, url):
1447 return client.APIResponse(self.fixture._fake_get(None, url)) 1447 return client.APIResponse(self.fixture._fake_get(None, url))
1448 1448
1449 def put(self, url, body, **kwargs):
1450 return client.APIResponse(
1451 self.fixture._fake_put(None, url, body, **kwargs))
1452
1449 1453
1450class PlacementFixture(fixtures.Fixture): 1454class PlacementFixture(fixtures.Fixture):
1451 """A fixture to placement operations. 1455 """A fixture to placement operations.
diff --git a/nova/tests/functional/test_servers.py b/nova/tests/functional/test_servers.py
index 7b09df7..f149c4c 100644
--- a/nova/tests/functional/test_servers.py
+++ b/nova/tests/functional/test_servers.py
@@ -1186,6 +1186,15 @@ class ServerRebuildTestCase(integrated_helpers._IntegratedTestBase,
1186 return self.placement_api.get( 1186 return self.placement_api.get(
1187 '/allocations/%s' % server_uuid).body['allocations'] 1187 '/allocations/%s' % server_uuid).body['allocations']
1188 1188
1189 def _set_provider_inventory(rp_uuid, resource_class, inventory):
1190 # Get the resource provider generation for the inventory update.
1191 rp = self.placement_api.get(
1192 '/resource_providers/%s' % rp_uuid).body
1193 inventory['resource_provider_generation'] = rp['generation']
1194 return self.placement_api.put(
1195 '/resource_providers/%s/inventories/%s' %
1196 (rp_uuid, resource_class), inventory).body
1197
1189 def assertFlavorMatchesAllocation(flavor, allocation): 1198 def assertFlavorMatchesAllocation(flavor, allocation):
1190 self.assertEqual(flavor['vcpus'], allocation['VCPU']) 1199 self.assertEqual(flavor['vcpus'], allocation['VCPU'])
1191 self.assertEqual(flavor['ram'], allocation['MEMORY_MB']) 1200 self.assertEqual(flavor['ram'], allocation['MEMORY_MB'])
@@ -1213,6 +1222,9 @@ class ServerRebuildTestCase(integrated_helpers._IntegratedTestBase,
1213 1222
1214 flavor = self.api.api_get('/flavors/1').body['flavor'] 1223 flavor = self.api.api_get('/flavors/1').body['flavor']
1215 1224
1225 # make the compute node full and ensure rebuild still succeed
1226 _set_provider_inventory(rp_uuid, "VCPU", {"total": 1})
1227
1216 # There should be usage for the server on the compute node now. 1228 # There should be usage for the server on the compute node now.
1217 rp_usages = _get_provider_usages(rp_uuid) 1229 rp_usages = _get_provider_usages(rp_uuid)
1218 assertFlavorMatchesAllocation(flavor, rp_usages) 1230 assertFlavorMatchesAllocation(flavor, rp_usages)
diff --git a/nova/tests/unit/scheduler/test_scheduler.py b/nova/tests/unit/scheduler/test_scheduler.py
index d61cf56..fe54516 100644
--- a/nova/tests/unit/scheduler/test_scheduler.py
+++ b/nova/tests/unit/scheduler/test_scheduler.py
@@ -171,6 +171,22 @@ class SchedulerManagerTestCase(test.NoDBTestCase):
171 @mock.patch('nova.scheduler.utils.resources_from_request_spec') 171 @mock.patch('nova.scheduler.utils.resources_from_request_spec')
172 @mock.patch('nova.scheduler.client.report.SchedulerReportClient.' 172 @mock.patch('nova.scheduler.client.report.SchedulerReportClient.'
173 'get_allocation_candidates') 173 'get_allocation_candidates')
174 def test_select_destination_is_rebuild(self, mock_get_ac, mock_rfrs):
175 fake_spec = objects.RequestSpec(
176 scheduler_hints={'_nova_check_type': ['rebuild']})
177 fake_spec.instance_uuid = uuids.instance
178 with mock.patch.object(self.manager.driver, 'select_destinations'
179 ) as select_destinations:
180 self.manager.select_destinations(self.context, spec_obj=fake_spec,
181 instance_uuids=[fake_spec.instance_uuid])
182 select_destinations.assert_called_once_with(
183 self.context, fake_spec,
184 [fake_spec.instance_uuid], None, None)
185 mock_get_ac.assert_not_called()
186
187 @mock.patch('nova.scheduler.utils.resources_from_request_spec')
188 @mock.patch('nova.scheduler.client.report.SchedulerReportClient.'
189 'get_allocation_candidates')
174 def test_select_destination_with_4_3_client(self, mock_get_ac, mock_rfrs): 190 def test_select_destination_with_4_3_client(self, mock_get_ac, mock_rfrs):
175 fake_spec = objects.RequestSpec() 191 fake_spec = objects.RequestSpec()
176 place_res = (fakes.ALLOC_REQS, mock.sentinel.p_sums) 192 place_res = (fakes.ALLOC_REQS, mock.sentinel.p_sums)