From f57900ad20d21aac5cb91aed87edc121f9008115 Mon Sep 17 00:00:00 2001 From: Sean Mooney Date: Tue, 21 Jun 2022 12:04:20 +0100 Subject: [PATCH] add repoducer test for bug 1890244 This change adds a test to simulate validating a instnace group policy where the group has been deleted but is still referenced in the scheduler hint. Change-Id: I803e6286a773d9e53639ab0cd449fc72bb3be613 Related-Bug: #1890244 (cherry picked from commit 84a84f7f2fff58cf6254d6267af0ca5cee64c53b) --- nova/tests/unit/compute/test_compute_mgr.py | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/nova/tests/unit/compute/test_compute_mgr.py b/nova/tests/unit/compute/test_compute_mgr.py index 1b0469b8e65..c6be4b49562 100644 --- a/nova/tests/unit/compute/test_compute_mgr.py +++ b/nova/tests/unit/compute/test_compute_mgr.py @@ -7615,6 +7615,24 @@ def test_validate_instance_group_policy_handles_hint_list(self, mock_get): instance, hints) mock_get.assert_called_once_with(self.context, uuids.group_hint) + @mock.patch('nova.objects.InstanceGroup.get_by_hint') + def test_validate_instance_group_policy_deleted_group(self, mock_get): + """Tests that _validate_instance_group_policy handles the case + where the scheduler hint has a group but that group has been deleted. + This tests is a reproducer for bug: #1890244 + """ + instance = objects.Instance(uuid=uuids.instance) + hints = {'group': [uuids.group_hint]} + mock_get.side_effect = exception.InstanceGroupNotFound( + group_uuid=uuids.group_hint + ) + # FIXME(sean-k-mooney): this should not leak the exception + self.assertRaises( + exception.InstanceGroupNotFound, + self.compute._validate_instance_group_policy, self.context, + instance, hints) + mock_get.assert_called_once_with(self.context, uuids.group_hint) + @mock.patch('nova.objects.InstanceGroup.get_by_uuid') @mock.patch('nova.objects.InstanceList.get_uuids_by_host') @mock.patch('nova.objects.InstanceGroup.get_by_hint')