summaryrefslogtreecommitdiff
path: root/nova/tests/unit/cmd/test_manage.py
diff options
context:
space:
mode:
authorStephen Finucane <stephenfin@redhat.com>2021-07-29 14:53:51 +0100
committerTakashi Kajinami <tkajinam@redhat.com>2021-08-10 11:08:57 +0900
commit4cf4af7ff4742cf67d2621560ba296e030d25676 (patch)
tree11c9b15a9e3458157e7804cb737a9f9c9cb8090c /nova/tests/unit/cmd/test_manage.py
parent1d3373dcf0a05d4a2c5b51fc1b74d41ec1bb1175 (diff)
downloadnova-4cf4af7ff4742cf67d2621560ba296e030d25676.tar.gz
tests: Add test for bug #1936278
Ensure we're building the correct URL to talk to placement. Change-Id: I2152ee77ba522b3925a6777e7f32a9943b76aa49 Related-Bug: #1936278 Signed-off-by: Stephen Finucane <stephenfin@redhat.com>
Diffstat (limited to 'nova/tests/unit/cmd/test_manage.py')
-rw-r--r--nova/tests/unit/cmd/test_manage.py56
1 files changed, 52 insertions, 4 deletions
diff --git a/nova/tests/unit/cmd/test_manage.py b/nova/tests/unit/cmd/test_manage.py
index a42980871b..9ab2d4c0c6 100644
--- a/nova/tests/unit/cmd/test_manage.py
+++ b/nova/tests/unit/cmd/test_manage.py
@@ -2887,11 +2887,54 @@ class TestNovaManagePlacement(test.NoDBTestCase):
neutron.update_port.assert_called_once_with(
uuidsentinel.port_id, body=expected_update_body)
- def test_audit_with_wrong_provider_uuid(self):
+ @mock.patch.object(manage.PlacementCommands,
+ '_check_orphaned_allocations_for_provider')
+ @mock.patch('nova.scheduler.client.report.SchedulerReportClient.get')
+ def test_audit_with_provider_uuid(
+ self, get_resource_providers, check_orphaned_allocs,
+ ):
+ rps = [
+ {
+ "generation": 1,
+ "uuid": uuidsentinel.rp1,
+ "links": None,
+ "name": "rp1",
+ "parent_provider_uuid": None,
+ "root_provider_uuid": uuidsentinel.rp1,
+ },
+ ]
+ get_resource_providers.return_value = fake_requests.FakeResponse(
+ 200, content=jsonutils.dumps({"resource_providers": rps}))
+
+ # we found one orphaned allocation per RP and we had no faults
+ check_orphaned_allocs.side_effect = ((1, 0),)
+
+ ret = self.cli.audit(
+ verbose=True, delete=False,
+ provider_uuid=uuidsentinel.fake_uuid)
+
+ # We found orphaned allocations but we left them
+ self.assertEqual(3, ret)
+
+ get_resource_providers.assert_called_once_with(
+ f'/resource_providers?uuid={uuidsentinel.fake_uuid}',
+ global_request_id=mock.ANY,
+ version='1.14')
+
+ # Only the specified RP is checked
+ check_orphaned_allocs.assert_has_calls([
+ mock.call(mock.ANY, mock.ANY, mock.ANY, rps[0], False),
+ ])
+
+ output = self.output.getvalue()
+ self.assertIn('Processed 1 allocation', output)
+
+ def test_audit_with_invalid_provider_uuid(self):
with mock.patch.object(
- self.cli, '_get_resource_provider',
- side_effect=exception.ResourceProviderNotFound(
- name_or_uuid=uuidsentinel.fake_uuid)):
+ self.cli, '_get_resource_provider',
+ side_effect=exception.ResourceProviderNotFound(
+ name_or_uuid=uuidsentinel.fake_uuid),
+ ):
ret = self.cli.audit(
provider_uuid=uuidsentinel.fake_uuid)
self.assertEqual(127, ret)
@@ -2947,6 +2990,11 @@ class TestNovaManagePlacement(test.NoDBTestCase):
expected_ret = 0
self.assertEqual(expected_ret, ret)
+ get_resource_providers.assert_called_once_with(
+ '/resource_providers',
+ global_request_id=mock.ANY,
+ version='1.14')
+
call1 = mock.call(mock.ANY, mock.ANY, mock.ANY, rps[0], delete)
call2 = mock.call(mock.ANY, mock.ANY, mock.ANY, rps[1], delete)
if errors: