Skip to content

Commit 4023d3f

Browse files
rubasovgibizer
authored andcommitted
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 <[email protected]> Related-Bug: #2025480 (cherry picked from commit 62300d4) (cherry picked from commit 477ff26) (cherry picked from commit 23c190a) (cherry picked from commit 7422642) (cherry picked from commit fc02bdf) (cherry picked from commit e078152)
1 parent bff6da2 commit 4023d3f

File tree

1 file changed

+82
-0
lines changed

1 file changed

+82
-0
lines changed
Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
# Licensed under the Apache License, Version 2.0 (the "License"); you may
2+
# not use this file except in compliance with the License. You may obtain
3+
# a copy of the License at
4+
#
5+
# http://www.apache.org/licenses/LICENSE-2.0
6+
#
7+
# Unless required by applicable law or agreed to in writing, software
8+
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
9+
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
10+
# License for the specific language governing permissions and limitations
11+
# under the License.
12+
from unittest import mock
13+
14+
from nova import context
15+
from nova.objects import compute_node
16+
from nova import test
17+
from nova.tests import fixtures as nova_fixtures
18+
from nova.tests.functional import fixtures as func_fixtures
19+
from nova.tests.functional import integrated_helpers
20+
from nova.tests.unit import fake_notifier
21+
22+
23+
class UnshelveUpdateAvailableResourcesPeriodicRace(
24+
test.TestCase, integrated_helpers.InstanceHelperMixin):
25+
def setUp(self):
26+
super(UnshelveUpdateAvailableResourcesPeriodicRace, self).setUp()
27+
28+
placement = func_fixtures.PlacementFixture()
29+
self.useFixture(placement)
30+
self.placement = placement.api
31+
self.neutron = nova_fixtures.NeutronFixture(self)
32+
self.useFixture(self.neutron)
33+
self.useFixture(nova_fixtures.GlanceFixture(self))
34+
# Start nova services.
35+
self.api = self.useFixture(nova_fixtures.OSAPIFixture(
36+
api_version='v2.1')).admin_api
37+
self.api.microversion = 'latest'
38+
fake_notifier.stub_notifier(self)
39+
self.addCleanup(fake_notifier.reset)
40+
41+
self.start_service('conductor')
42+
self.start_service('scheduler')
43+
44+
def test_unshelve_spawning_update_available_resources(self):
45+
compute = self._start_compute('compute1')
46+
47+
server = self._create_server(
48+
networks=[{'port': self.neutron.port_1['id']}])
49+
50+
node = compute_node.ComputeNode.get_by_nodename(
51+
context.get_admin_context(), 'compute1')
52+
self.assertEqual(1, node.vcpus_used)
53+
54+
# with default config shelve means immediate offload as well
55+
req = {
56+
'shelve': {}
57+
}
58+
self.api.post_server_action(server['id'], req)
59+
self._wait_for_server_parameter(
60+
server, {'status': 'SHELVED_OFFLOADED',
61+
'OS-EXT-SRV-ATTR:host': None})
62+
63+
node = compute_node.ComputeNode.get_by_nodename(
64+
context.get_admin_context(), 'compute1')
65+
self.assertEqual(0, node.vcpus_used)
66+
67+
def fake_spawn(*args, **kwargs):
68+
self._run_periodics()
69+
70+
with mock.patch.object(
71+
compute.driver, 'spawn', side_effect=fake_spawn):
72+
req = {'unshelve': None}
73+
self.api.post_server_action(server['id'], req)
74+
fake_notifier.wait_for_versioned_notifications(
75+
'instance.unshelve.start')
76+
self._wait_for_state_change(server, 'ACTIVE')
77+
78+
node = compute_node.ComputeNode.get_by_nodename(
79+
context.get_admin_context(), 'compute1')
80+
# This is the bug, the instance should have resources claimed
81+
# self.assertEqual(1, node.vcpus_used)
82+
self.assertEqual(0, node.vcpus_used)

0 commit comments

Comments
 (0)