|
| 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