blob: ef78b4abced059aacdd5c7776899b2f7d97c2f81 [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):
30
31 """
32 This is a set of tests specific to multinode testing.
33
34 """
35 credentials = ['primary', 'admin']
36
Sean Dague9b115182015-11-13 09:20:22 -050037 @classmethod
38 def setup_clients(cls):
39 super(TestServerMultinode, cls).setup_clients()
40 # Use admin client by default
41 cls.manager = cls.admin_manager
42 # this is needed so that we can use the availability_zone:host
43 # scheduler hint, which is admin_only by default
44 cls.servers_client = cls.admin_manager.servers_client
45 super(TestServerMultinode, cls).resource_setup()
46
Sean Dague782f6772015-11-11 11:26:45 -050047 @test.idempotent_id('9cecbe35-b9d4-48da-a37e-7ce70aa43d30')
48 @test.attr(type='smoke')
49 @test.services('compute', 'network')
50 def test_schedule_to_all_nodes(self):
Sean Dague9b115182015-11-13 09:20:22 -050051 host_client = self.manager.hosts_client
Sean Dague782f6772015-11-11 11:26:45 -050052 hosts = host_client.list_hosts()['hosts']
53 hosts = [x for x in hosts if x['service'] == 'compute']
54
55 # ensure we have at least as many compute hosts as we expect
56 if len(hosts) < CONF.compute.min_compute_nodes:
57 raise exceptions.InvalidConfiguration(
58 "Host list %s is shorter than min_compute_nodes. "
59 "Did a compute worker not boot correctly?" % hosts)
60
61 # create 1 compute for each node, up to the min_compute_nodes
62 # threshold (so that things don't get crazy if you have 1000
63 # compute nodes but set min to 3).
64 servers = []
65
66 for host in hosts[:CONF.compute.min_compute_nodes]:
67 create_kwargs = {
Sean Dague9b115182015-11-13 09:20:22 -050068 'availability_zone': '%(zone)s:%(host_name)s' % host
Sean Dague782f6772015-11-11 11:26:45 -050069 }
70
71 # by getting to active state here, this means this has
72 # landed on the host in question.
73 inst = self.create_server(image=CONF.compute.image_ref,
74 flavor=CONF.compute.flavor_ref,
75 create_kwargs=create_kwargs)
76 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)