blob: f21ff4fdd48d1a9ba6a6c5374d2e28d6e3f8a2bc [file] [log] [blame]
Sean Dague782f6772015-11-11 11:26:45 -05001# Copyright 2012 OpenStack Foundation
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
17from oslo_log import log as logging
18
19from tempest import config
20from tempest import exceptions
21from tempest.scenario import manager
22from tempest import test
23
24CONF = config.CONF
25
26LOG = logging.getLogger(__name__)
27
28
29class TestServerMultinode(manager.ScenarioTest):
Ken'ichi Ohmichic4e4f1c2015-11-17 08:16:12 +000030 """This is a set of tests specific to multinode testing."""
Sean Dague782f6772015-11-11 11:26:45 -050031 credentials = ['primary', 'admin']
32
Sean Dague9b115182015-11-13 09:20:22 -050033 @classmethod
Jordan Pittier619763a2016-01-07 19:26:35 +010034 def skip_checks(cls):
35 super(TestServerMultinode, cls).skip_checks()
36
37 if CONF.compute.min_compute_nodes < 2:
38 raise cls.skipException(
39 "Less than 2 compute nodes, skipping multinode tests.")
40
41 @classmethod
Sean Dague9b115182015-11-13 09:20:22 -050042 def setup_clients(cls):
43 super(TestServerMultinode, cls).setup_clients()
44 # Use admin client by default
45 cls.manager = cls.admin_manager
46 # this is needed so that we can use the availability_zone:host
47 # scheduler hint, which is admin_only by default
48 cls.servers_client = cls.admin_manager.servers_client
49 super(TestServerMultinode, cls).resource_setup()
50
Sean Dague782f6772015-11-11 11:26:45 -050051 @test.idempotent_id('9cecbe35-b9d4-48da-a37e-7ce70aa43d30')
52 @test.attr(type='smoke')
53 @test.services('compute', 'network')
54 def test_schedule_to_all_nodes(self):
Sean Dague9b115182015-11-13 09:20:22 -050055 host_client = self.manager.hosts_client
Sean Dague782f6772015-11-11 11:26:45 -050056 hosts = host_client.list_hosts()['hosts']
57 hosts = [x for x in hosts if x['service'] == 'compute']
58
59 # ensure we have at least as many compute hosts as we expect
60 if len(hosts) < CONF.compute.min_compute_nodes:
61 raise exceptions.InvalidConfiguration(
62 "Host list %s is shorter than min_compute_nodes. "
63 "Did a compute worker not boot correctly?" % hosts)
64
65 # create 1 compute for each node, up to the min_compute_nodes
66 # threshold (so that things don't get crazy if you have 1000
67 # compute nodes but set min to 3).
68 servers = []
69
70 for host in hosts[:CONF.compute.min_compute_nodes]:
Sean Dague782f6772015-11-11 11:26:45 -050071 # by getting to active state here, this means this has
72 # landed on the host in question.
lanoux5fc14522015-09-21 08:17:35 +000073 inst = self.create_server(
74 availability_zone='%(zone)s:%(host_name)s' % host,
75 wait_until='ACTIVE')
Sean Dague782f6772015-11-11 11:26:45 -050076 server = self.servers_client.show_server(inst['id'])['server']
77 servers.append(server)
78
79 # make sure we really have the number of servers we think we should
80 self.assertEqual(
81 len(servers), CONF.compute.min_compute_nodes,
82 "Incorrect number of servers built %s" % servers)
83
84 # ensure that every server ended up on a different host
85 host_ids = [x['hostId'] for x in servers]
86 self.assertEqual(
87 len(set(host_ids)), len(servers),
88 "Incorrect number of distinct host_ids scheduled to %s" % servers)