blob: 7e0e41cbcb67f58887f0b663e18e152ef1e6c67a [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
34 def setup_clients(cls):
35 super(TestServerMultinode, cls).setup_clients()
36 # Use admin client by default
37 cls.manager = cls.admin_manager
38 # this is needed so that we can use the availability_zone:host
39 # scheduler hint, which is admin_only by default
40 cls.servers_client = cls.admin_manager.servers_client
41 super(TestServerMultinode, cls).resource_setup()
42
Sean Dague782f6772015-11-11 11:26:45 -050043 @test.idempotent_id('9cecbe35-b9d4-48da-a37e-7ce70aa43d30')
44 @test.attr(type='smoke')
45 @test.services('compute', 'network')
46 def test_schedule_to_all_nodes(self):
Sean Dague9b115182015-11-13 09:20:22 -050047 host_client = self.manager.hosts_client
Sean Dague782f6772015-11-11 11:26:45 -050048 hosts = host_client.list_hosts()['hosts']
49 hosts = [x for x in hosts if x['service'] == 'compute']
50
51 # ensure we have at least as many compute hosts as we expect
52 if len(hosts) < CONF.compute.min_compute_nodes:
53 raise exceptions.InvalidConfiguration(
54 "Host list %s is shorter than min_compute_nodes. "
55 "Did a compute worker not boot correctly?" % hosts)
56
57 # create 1 compute for each node, up to the min_compute_nodes
58 # threshold (so that things don't get crazy if you have 1000
59 # compute nodes but set min to 3).
60 servers = []
61
62 for host in hosts[:CONF.compute.min_compute_nodes]:
Sean Dague782f6772015-11-11 11:26:45 -050063 # by getting to active state here, this means this has
64 # landed on the host in question.
lanoux5fc14522015-09-21 08:17:35 +000065 inst = self.create_server(
66 availability_zone='%(zone)s:%(host_name)s' % host,
67 wait_until='ACTIVE')
Sean Dague782f6772015-11-11 11:26:45 -050068 server = self.servers_client.show_server(inst['id'])['server']
69 servers.append(server)
70
71 # make sure we really have the number of servers we think we should
72 self.assertEqual(
73 len(servers), CONF.compute.min_compute_nodes,
74 "Incorrect number of servers built %s" % servers)
75
76 # ensure that every server ended up on a different host
77 host_ids = [x['hostId'] for x in servers]
78 self.assertEqual(
79 len(set(host_ids)), len(servers),
80 "Incorrect number of distinct host_ids scheduled to %s" % servers)