summaryrefslogtreecommitdiff
path: root/nova/tests/functional/regressions/test_bug_1823370.py
blob: 60a8e0053b51e510abc548a7fc6f16fde4ea60a9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
# 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.tests import fixtures as nova_fixtures
from nova.tests.functional import integrated_helpers


class MultiCellEvacuateTestCase(integrated_helpers._IntegratedTestBase,
                                integrated_helpers.InstanceHelperMixin):
    """Recreate test for bug 1823370 which was introduced in Pike.

    When evacuating a server, the request to the scheduler should be restricted
    to the cell in which the instance is already running since cross-cell
    evacuate is not supported, at least not yet. This test creates two cells
    with two compute hosts in one cell and another compute host in the other
    cell. A server is created in the cell with two hosts and then evacuated
    which should land it on the other host in that cell, not the other cell
    with only one host. The scheduling behavior is controlled via the custom
    HostNameWeigher.
    """
    # Set variables used in the parent class.
    NUMBER_OF_CELLS = 2
    REQUIRES_LOCKING = False
    ADMIN_API = True
    USE_NEUTRON = True
    _image_ref_parameter = 'imageRef'
    _flavor_ref_parameter = 'flavorRef'
    api_major_version = 'v2.1'
    microversion = '2.11'  # Need at least 2.11 for the force-down API

    def setUp(self):
        # Register a custom weigher for predictable scheduling results.
        self.useFixture(nova_fixtures.HostNameWeigherFixture())
        super(MultiCellEvacuateTestCase, self).setUp()

    def _setup_compute_service(self):
        """Start three compute services, two in cell1 and one in cell2.

        host1: cell1 (highest weight)
        host2: cell2 (medium weight)
        host3: cell1 (lowest weight)
        """
        host_to_cell = {'host1': 'cell1', 'host2': 'cell2', 'host3': 'cell1'}
        for host, cell in host_to_cell.items():
            svc = self.start_service('compute', host=host, cell=cell)
            # Set an attribute so we can access this service later.
            setattr(self, host, svc)

    def test_evacuate_multi_cell(self):
        # Create a server which should land on host1 since it has the highest
        # weight.
        server = self._build_server(self.api.get_flavors()[0]['id'])
        server = self.api.post_server({'server': server})
        server = self._wait_for_state_change(self.api, server, 'ACTIVE')
        self.assertEqual('host1', server['OS-EXT-SRV-ATTR:host'])

        # Disable the host on which the server is now running.
        self.host1.stop()
        self.api.force_down_service('host1', 'nova-compute', forced_down=True)

        # Now evacuate the server which should send it to host3 since it is
        # in the same cell as host1, even though host2 in cell2 is weighed
        # higher than host3.
        req = {'evacuate': {'onSharedStorage': False}}
        self.api.post_server_action(server['id'], req)
        self._wait_for_migration_status(server, ['done'])
        server = self._wait_for_state_change(self.api, server, 'ACTIVE')
        # FIXME(mriedem): This is bug 1823370 where conductor does not restrict
        # the RequestSpec to the origin cell before calling the scheduler to
        # pick a new host so the host (host2) in the other cell (cell2) is
        # incorrectly picked.
        self.assertEqual('host2', server['OS-EXT-SRV-ATTR:host'])