Skip to content

Commit

Permalink
add regression test case for bug 1978983
Browse files Browse the repository at this point in the history
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)
(cherry picked from commit 6bd0bf0)
(cherry picked from commit 1e0af92)
  • Loading branch information
Amit Uniyal committed Aug 19, 2022
1 parent 2f7f4cc commit b57b0ee
Show file tree
Hide file tree
Showing 2 changed files with 82 additions and 2 deletions.
6 changes: 4 additions & 2 deletions nova/tests/functional/integrated_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -556,9 +556,11 @@ def _start_server(self, server):
self.api.post_server_action(server['id'], {'os-start': None})
return self._wait_for_state_change(server, 'ACTIVE')

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


class PlacementHelperMixin:
Expand Down
78 changes: 78 additions & 0 deletions nova/tests/functional/regressions/test_bug_1978983.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
# Copyright 2022 Red Hat, Inc.
# All Rights Reserved.
#
# 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 nova import test
from nova.tests import fixtures as nova_fixtures
from nova.tests.functional.api import client
from nova.tests.functional import fixtures as func_fixtures
from nova.tests.functional import integrated_helpers


class EvacuateServerWithTaskState(
test.TestCase, integrated_helpers.InstanceHelperMixin,
):
"""Regression test for bug 1978983
If instance task state is powering-off or not None
instance should be allowed to evacuate.
"""

def setUp(self):
super().setUp()
# Stub out external dependencies.
self.useFixture(nova_fixtures.NeutronFixture(self))
self.useFixture(nova_fixtures.GlanceFixture(self))
self.useFixture(func_fixtures.PlacementFixture())
self.useFixture(nova_fixtures.HostNameWeigherFixture())

# Start nova controller services.
self.start_service('conductor')
self.start_service('scheduler')

api_fixture = self.useFixture(nova_fixtures.OSAPIFixture(
api_version='v2.1'))
self.api = api_fixture.admin_api

self.src = self._start_compute(host='host1')
self.dest = self._start_compute(host='host2')

def test_evacuate_instance(self):
"""Evacuating a server
"""
server = self._create_server(networks=[])

self.api.microversion = 'latest'
server = self._wait_for_state_change(server, 'ACTIVE')
self.assertEqual('host1', server['OS-EXT-SRV-ATTR:host'])

# stop host1 compute service
self.src.stop()

# poweroff instance
self._stop_server(server, wait_for_stop=False)
server = self._wait_for_server_parameter(
server, {'OS-EXT-STS:task_state': 'powering-off'})

# FIXME(auniyal): As compute service is down in source node
# instance is stuck at powering-off, evacuation fails with
# msg: Cannot 'evacuate' instance <instance-id> while it is in
# task_state powering-off (HTTP 409)

ex = self.assertRaises(
client.OpenStackApiException,
self._evacuate_server,
server,
expected_host=self.dest.host)
self.assertEqual(409, ex.response.status_code)

0 comments on commit b57b0ee

Please sign in to comment.