From 4023d3f82abf440d3151bad732de7e51e042dbdd Mon Sep 17 00:00:00 2001 From: Bence Romsics Date: Mon, 14 Aug 2023 13:03:13 +0200 Subject: [PATCH] Reproduce bug #2025480 in a functional test Written by gibi, I just cleaned it up. NOTE(elod.illes): test_bug_2025480.py needed to be edited as refactoring patch I456f685f480b8de71014cf232a8f08c731605ad8 was only introduced to Xena and we don't want to backport that. Change-Id: I8386a846b3685b8d03c59334ccfb2efbd4afe427 Co-Authored-By: Balazs Gibizer Related-Bug: #2025480 (cherry picked from commit 62300d4885549368f874b3e07b756017ff96c659) (cherry picked from commit 477ff2667d7ecd218fa5163d86d2719979dcdcd3) (cherry picked from commit 23c190a35839b396418d3e98af1e67587f9e9296) (cherry picked from commit 7422642dd6e222959470b73dc6ba2450a792b9c7) (cherry picked from commit fc02bdf830054268df814adc269443e470972719) (cherry picked from commit e078152e786fdb4be16672d01fd7ce1ec6357530) --- .../regressions/test_bug_2025480.py | 82 +++++++++++++++++++ 1 file changed, 82 insertions(+) create mode 100644 nova/tests/functional/regressions/test_bug_2025480.py diff --git a/nova/tests/functional/regressions/test_bug_2025480.py b/nova/tests/functional/regressions/test_bug_2025480.py new file mode 100644 index 00000000000..45b201ce45e --- /dev/null +++ b/nova/tests/functional/regressions/test_bug_2025480.py @@ -0,0 +1,82 @@ +# Licensed under the Apache License, Version 2.0 (the "License"); you may +# not use this file except in compliance with the License. You may obtain +# a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +# License for the specific language governing permissions and limitations +# under the License. +from unittest import mock + +from nova import context +from nova.objects import compute_node +from nova import test +from nova.tests import fixtures as nova_fixtures +from nova.tests.functional import fixtures as func_fixtures +from nova.tests.functional import integrated_helpers +from nova.tests.unit import fake_notifier + + +class UnshelveUpdateAvailableResourcesPeriodicRace( + test.TestCase, integrated_helpers.InstanceHelperMixin): + def setUp(self): + super(UnshelveUpdateAvailableResourcesPeriodicRace, self).setUp() + + placement = func_fixtures.PlacementFixture() + self.useFixture(placement) + self.placement = placement.api + self.neutron = nova_fixtures.NeutronFixture(self) + self.useFixture(self.neutron) + self.useFixture(nova_fixtures.GlanceFixture(self)) + # Start nova services. + self.api = self.useFixture(nova_fixtures.OSAPIFixture( + api_version='v2.1')).admin_api + self.api.microversion = 'latest' + fake_notifier.stub_notifier(self) + self.addCleanup(fake_notifier.reset) + + self.start_service('conductor') + self.start_service('scheduler') + + def test_unshelve_spawning_update_available_resources(self): + compute = self._start_compute('compute1') + + server = self._create_server( + networks=[{'port': self.neutron.port_1['id']}]) + + node = compute_node.ComputeNode.get_by_nodename( + context.get_admin_context(), 'compute1') + self.assertEqual(1, node.vcpus_used) + + # with default config shelve means immediate offload as well + req = { + 'shelve': {} + } + self.api.post_server_action(server['id'], req) + self._wait_for_server_parameter( + server, {'status': 'SHELVED_OFFLOADED', + 'OS-EXT-SRV-ATTR:host': None}) + + node = compute_node.ComputeNode.get_by_nodename( + context.get_admin_context(), 'compute1') + self.assertEqual(0, node.vcpus_used) + + def fake_spawn(*args, **kwargs): + self._run_periodics() + + with mock.patch.object( + compute.driver, 'spawn', side_effect=fake_spawn): + req = {'unshelve': None} + self.api.post_server_action(server['id'], req) + fake_notifier.wait_for_versioned_notifications( + 'instance.unshelve.start') + self._wait_for_state_change(server, 'ACTIVE') + + node = compute_node.ComputeNode.get_by_nodename( + context.get_admin_context(), 'compute1') + # This is the bug, the instance should have resources claimed + # self.assertEqual(1, node.vcpus_used) + self.assertEqual(0, node.vcpus_used)