Skip to content

Commit 23c190a

Browse files
rubasovgibizer
andcommitted
Reproduce bug #2025480 in a functional test
Written by gibi, I just cleaned it up. Change-Id: I8386a846b3685b8d03c59334ccfb2efbd4afe427 Co-Authored-By: Balazs Gibizer <[email protected]> Related-Bug: #2025480 (cherry picked from commit 62300d4) (cherry picked from commit 477ff26)
1 parent 7583267 commit 23c190a

File tree

1 file changed

+87
-0
lines changed

1 file changed

+87
-0
lines changed
Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
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+
21+
22+
class UnshelveUpdateAvailableResourcesPeriodicRace(
23+
test.TestCase, integrated_helpers.InstanceHelperMixin):
24+
def setUp(self):
25+
super(UnshelveUpdateAvailableResourcesPeriodicRace, self).setUp()
26+
27+
placement = func_fixtures.PlacementFixture()
28+
self.useFixture(placement)
29+
self.placement = placement.api
30+
self.neutron = nova_fixtures.NeutronFixture(self)
31+
self.useFixture(self.neutron)
32+
self.useFixture(nova_fixtures.GlanceFixture(self))
33+
# Start nova services.
34+
self.api = self.useFixture(nova_fixtures.OSAPIFixture(
35+
api_version='v2.1')).admin_api
36+
self.api.microversion = 'latest'
37+
self.notifier = self.useFixture(
38+
nova_fixtures.NotificationFixture(self))
39+
40+
self.start_service('conductor')
41+
self.start_service('scheduler')
42+
43+
def test_unshelve_spawning_update_available_resources(self):
44+
compute = self._start_compute('compute1')
45+
46+
server = self._create_server(
47+
networks=[{'port': self.neutron.port_1['id']}])
48+
49+
node = compute_node.ComputeNode.get_by_nodename(
50+
context.get_admin_context(), 'compute1')
51+
self.assertEqual(1, node.vcpus_used)
52+
53+
# with default config shelve means immediate offload as well
54+
req = {
55+
'shelve': {}
56+
}
57+
self.api.post_server_action(server['id'], req)
58+
self._wait_for_server_parameter(
59+
server, {'status': 'SHELVED_OFFLOADED',
60+
'OS-EXT-SRV-ATTR:host': None})
61+
62+
node = compute_node.ComputeNode.get_by_nodename(
63+
context.get_admin_context(), 'compute1')
64+
self.assertEqual(0, node.vcpus_used)
65+
66+
def fake_spawn(*args, **kwargs):
67+
self._run_periodics()
68+
69+
with mock.patch.object(
70+
compute.driver, 'spawn', side_effect=fake_spawn):
71+
req = {'unshelve': None}
72+
self.api.post_server_action(server['id'], req)
73+
self.notifier.wait_for_versioned_notifications(
74+
'instance.unshelve.start')
75+
self._wait_for_server_parameter(
76+
server,
77+
{
78+
'status': 'ACTIVE',
79+
'OS-EXT-STS:task_state': None,
80+
'OS-EXT-SRV-ATTR:host': 'compute1',
81+
})
82+
83+
node = compute_node.ComputeNode.get_by_nodename(
84+
context.get_admin_context(), 'compute1')
85+
# This is the bug, the instance should have resources claimed
86+
# self.assertEqual(1, node.vcpus_used)
87+
self.assertEqual(0, node.vcpus_used)

0 commit comments

Comments
 (0)