|
| 1 | +# Copyright 2017 Ericsson |
| 2 | +# |
| 3 | +# Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | +# you may not use this file except in compliance with the License. |
| 5 | +# You may obtain a copy of the License at |
| 6 | +# |
| 7 | +# http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | +# |
| 9 | +# Unless required by applicable law or agreed to in writing, software |
| 10 | +# distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | +# See the License for the specific language governing permissions and |
| 13 | +# limitations under the License. |
| 14 | + |
| 15 | +from nova import context |
| 16 | +from nova import objects |
| 17 | +from nova import test |
| 18 | +from nova.tests import fixtures as nova_fixtures |
| 19 | +from nova.tests.functional import fixtures as func_fixtures |
| 20 | +from nova.tests.functional import integrated_helpers |
| 21 | + |
| 22 | + |
| 23 | +class IgnoreDeletedServerGroupsTest( |
| 24 | + test.TestCase, integrated_helpers.InstanceHelperMixin, |
| 25 | +): |
| 26 | + """Regression test for bug 1890244 |
| 27 | +
|
| 28 | + If instance are created as member of server groups it |
| 29 | + should be possibel to evacuate them if the server groups are |
| 30 | + deleted prior to the host failure. |
| 31 | + """ |
| 32 | + |
| 33 | + def setUp(self): |
| 34 | + super().setUp() |
| 35 | + # Stub out external dependencies. |
| 36 | + self.useFixture(nova_fixtures.NeutronFixture(self)) |
| 37 | + self.useFixture(nova_fixtures.GlanceFixture(self)) |
| 38 | + self.useFixture(func_fixtures.PlacementFixture()) |
| 39 | + # Start nova controller services. |
| 40 | + api_fixture = self.useFixture(nova_fixtures.OSAPIFixture( |
| 41 | + api_version='v2.1')) |
| 42 | + self.api = api_fixture.admin_api |
| 43 | + self.start_service('conductor') |
| 44 | + # Use a custom weigher to make sure that we have a predictable |
| 45 | + # scheduling sort order. |
| 46 | + self.useFixture(nova_fixtures.HostNameWeigherFixture()) |
| 47 | + self.start_service('scheduler') |
| 48 | + # Start two computes, one where the server will be created and another |
| 49 | + # where we'll evacuate it to. |
| 50 | + self.src = self._start_compute('host1') |
| 51 | + self.dest = self._start_compute('host2') |
| 52 | + self.notifier = self.useFixture( |
| 53 | + nova_fixtures.NotificationFixture(self) |
| 54 | + ) |
| 55 | + |
| 56 | + def test_evacuate_after_group_delete(self): |
| 57 | + # Create an anti-affinity group for the server. |
| 58 | + body = { |
| 59 | + 'server_group': { |
| 60 | + 'name': 'test-group', |
| 61 | + 'policies': ['anti-affinity'] |
| 62 | + } |
| 63 | + } |
| 64 | + group_id = self.api.api_post( |
| 65 | + '/os-server-groups', body).body['server_group']['id'] |
| 66 | + |
| 67 | + # Create a server in the group which should land on host1 due to our |
| 68 | + # custom weigher. |
| 69 | + body = {'server': self._build_server()} |
| 70 | + body['os:scheduler_hints'] = {'group': group_id} |
| 71 | + server = self.api.post_server(body) |
| 72 | + server = self._wait_for_state_change(server, 'ACTIVE') |
| 73 | + self.assertEqual('host1', server['OS-EXT-SRV-ATTR:host']) |
| 74 | + |
| 75 | + # Down the source compute to enable the evacuation |
| 76 | + self.api.microversion = '2.11' # Cap for the force-down call. |
| 77 | + self.api.force_down_service('host1', 'nova-compute', True) |
| 78 | + self.api.microversion = 'latest' |
| 79 | + self.src.stop() |
| 80 | + |
| 81 | + # assert the server currently has a server group |
| 82 | + reqspec = objects.RequestSpec.get_by_instance_uuid( |
| 83 | + context.get_admin_context(), server['id']) |
| 84 | + self.assertIsNotNone(reqspec.instance_group) |
| 85 | + self.assertIn('group', reqspec.scheduler_hints) |
| 86 | + # then delete it so that we need to clean it up on evac |
| 87 | + self.api.api_delete(f'/os-server-groups/{group_id}') |
| 88 | + |
| 89 | + # Initiate evacuation |
| 90 | + server = self._evacuate_server( |
| 91 | + server, expected_host='host2', expected_migration_status='done' |
| 92 | + ) |
| 93 | + reqspec = objects.RequestSpec.get_by_instance_uuid( |
| 94 | + context.get_admin_context(), server['id']) |
| 95 | + self.assertIsNone(reqspec.instance_group) |
| 96 | + self.assertNotIn('group', reqspec.scheduler_hints) |
0 commit comments