Skip to content

Commit 6bd0bf0

Browse files
committed
add regression test case for bug 1978983
This change add a repoducer test for evacuating a vm in the powering-off state Related-Bug: #1978983 Change-Id: I5540df6c7497956219c06cff6f15b51c2c8bc299 (cherry picked from commit 5904c7f)
1 parent fed81f6 commit 6bd0bf0

File tree

2 files changed

+82
-2
lines changed

2 files changed

+82
-2
lines changed

nova/tests/functional/integrated_helpers.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -606,9 +606,11 @@ def _start_server(self, server):
606606
self.api.post_server_action(server['id'], {'os-start': None})
607607
return self._wait_for_state_change(server, 'ACTIVE')
608608

609-
def _stop_server(self, server):
609+
def _stop_server(self, server, wait_for_stop=True):
610610
self.api.post_server_action(server['id'], {'os-stop': None})
611-
return self._wait_for_state_change(server, 'SHUTOFF')
611+
if wait_for_stop:
612+
return self._wait_for_state_change(server, 'SHUTOFF')
613+
return server
612614

613615

614616
class PlacementHelperMixin:
Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
# Copyright 2022 Red Hat, Inc.
2+
# All Rights Reserved.
3+
#
4+
# Licensed under the Apache License, Version 2.0 (the "License"); you may
5+
# not use this file except in compliance with the License. You may obtain
6+
# a copy of the License at
7+
#
8+
# http://www.apache.org/licenses/LICENSE-2.0
9+
#
10+
# Unless required by applicable law or agreed to in writing, software
11+
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12+
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13+
# License for the specific language governing permissions and limitations
14+
# under the License.
15+
16+
17+
from nova import test
18+
from nova.tests import fixtures as nova_fixtures
19+
from nova.tests.functional.api import client
20+
from nova.tests.functional import fixtures as func_fixtures
21+
from nova.tests.functional import integrated_helpers
22+
23+
24+
class EvacuateServerWithTaskState(
25+
test.TestCase, integrated_helpers.InstanceHelperMixin,
26+
):
27+
"""Regression test for bug 1978983
28+
If instance task state is powering-off or not None
29+
instance should be allowed to evacuate.
30+
"""
31+
32+
def setUp(self):
33+
super().setUp()
34+
# Stub out external dependencies.
35+
self.useFixture(nova_fixtures.NeutronFixture(self))
36+
self.useFixture(nova_fixtures.GlanceFixture(self))
37+
self.useFixture(func_fixtures.PlacementFixture())
38+
self.useFixture(nova_fixtures.HostNameWeigherFixture())
39+
40+
# Start nova controller services.
41+
self.start_service('conductor')
42+
self.start_service('scheduler')
43+
44+
api_fixture = self.useFixture(nova_fixtures.OSAPIFixture(
45+
api_version='v2.1'))
46+
self.api = api_fixture.admin_api
47+
48+
self.src = self._start_compute(host='host1')
49+
self.dest = self._start_compute(host='host2')
50+
51+
def test_evacuate_instance(self):
52+
"""Evacuating a server
53+
"""
54+
server = self._create_server(networks=[])
55+
56+
self.api.microversion = 'latest'
57+
server = self._wait_for_state_change(server, 'ACTIVE')
58+
self.assertEqual('host1', server['OS-EXT-SRV-ATTR:host'])
59+
60+
# stop host1 compute service
61+
self.src.stop()
62+
63+
# poweroff instance
64+
self._stop_server(server, wait_for_stop=False)
65+
server = self._wait_for_server_parameter(
66+
server, {'OS-EXT-STS:task_state': 'powering-off'})
67+
68+
# FIXME(auniyal): As compute service is down in source node
69+
# instance is stuck at powering-off, evacuation fails with
70+
# msg: Cannot 'evacuate' instance <instance-id> while it is in
71+
# task_state powering-off (HTTP 409)
72+
73+
ex = self.assertRaises(
74+
client.OpenStackApiException,
75+
self._evacuate_server,
76+
server,
77+
expected_host=self.dest.host)
78+
self.assertEqual(409, ex.response.status_code)

0 commit comments

Comments
 (0)