blob: d9bff090898a65c734bf8b07abbcb388e05c1aa0 [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
Sean Dague782f6772015-11-11 11:26:45 -050017from tempest import config
Ken'ichi Ohmichic85a9512017-01-27 18:34:24 -080018from tempest.lib import decorators
Matthew Treinish4217a702016-10-07 17:27:11 -040019from tempest.lib import exceptions
Sean Dague782f6772015-11-11 11:26:45 -050020from tempest.scenario import manager
21from tempest import test
22
23CONF = config.CONF
24
Sean Dague782f6772015-11-11 11:26:45 -050025
26class TestServerMultinode(manager.ScenarioTest):
Ken'ichi Ohmichic4e4f1c2015-11-17 08:16:12 +000027 """This is a set of tests specific to multinode testing."""
Sean Dague782f6772015-11-11 11:26:45 -050028 credentials = ['primary', 'admin']
29
Sean Dague9b115182015-11-13 09:20:22 -050030 @classmethod
Jordan Pittier619763a2016-01-07 19:26:35 +010031 def skip_checks(cls):
32 super(TestServerMultinode, cls).skip_checks()
33
34 if CONF.compute.min_compute_nodes < 2:
35 raise cls.skipException(
36 "Less than 2 compute nodes, skipping multinode tests.")
37
38 @classmethod
Sean Dague9b115182015-11-13 09:20:22 -050039 def setup_clients(cls):
40 super(TestServerMultinode, cls).setup_clients()
41 # Use admin client by default
42 cls.manager = cls.admin_manager
43 # this is needed so that we can use the availability_zone:host
44 # scheduler hint, which is admin_only by default
45 cls.servers_client = cls.admin_manager.servers_client
Sean Dague9b115182015-11-13 09:20:22 -050046
Ken'ichi Ohmichic85a9512017-01-27 18:34:24 -080047 @decorators.idempotent_id('9cecbe35-b9d4-48da-a37e-7ce70aa43d30')
Jordan Pittier3b46d272017-04-12 16:17:28 +020048 @decorators.attr(type='smoke')
Sean Dague782f6772015-11-11 11:26:45 -050049 @test.services('compute', 'network')
50 def test_schedule_to_all_nodes(self):
zhufl83889922016-08-18 15:09:47 +080051 available_zone = \
Jordan Pittier8160d312017-04-18 11:52:23 +020052 self.os_admin.availability_zone_client.list_availability_zones(
zhufl83889922016-08-18 15:09:47 +080053 detail=True)['availabilityZoneInfo']
54 hosts = []
55 for zone in available_zone:
56 if zone['zoneState']['available']:
57 for host in zone['hosts']:
58 if 'nova-compute' in zone['hosts'][host] and \
59 zone['hosts'][host]['nova-compute']['available']:
60 hosts.append({'zone': zone['zoneName'],
61 'host_name': host})
Sean Dague782f6772015-11-11 11:26:45 -050062
63 # ensure we have at least as many compute hosts as we expect
64 if len(hosts) < CONF.compute.min_compute_nodes:
65 raise exceptions.InvalidConfiguration(
66 "Host list %s is shorter than min_compute_nodes. "
67 "Did a compute worker not boot correctly?" % hosts)
68
69 # create 1 compute for each node, up to the min_compute_nodes
70 # threshold (so that things don't get crazy if you have 1000
71 # compute nodes but set min to 3).
72 servers = []
73
74 for host in hosts[:CONF.compute.min_compute_nodes]:
Sean Dague782f6772015-11-11 11:26:45 -050075 # by getting to active state here, this means this has
76 # landed on the host in question.
lanoux5fc14522015-09-21 08:17:35 +000077 inst = self.create_server(
zhufl13c9c892017-02-10 12:04:07 +080078 availability_zone='%(zone)s:%(host_name)s' % host)
Sean Dague782f6772015-11-11 11:26:45 -050079 server = self.servers_client.show_server(inst['id'])['server']
zhuflb935f9a2017-02-10 15:36:42 +080080 # ensure server is located on the requested host
81 self.assertEqual(host['host_name'], server['OS-EXT-SRV-ATTR:host'])
Sean Dague782f6772015-11-11 11:26:45 -050082 servers.append(server)
83
84 # make sure we really have the number of servers we think we should
85 self.assertEqual(
86 len(servers), CONF.compute.min_compute_nodes,
87 "Incorrect number of servers built %s" % servers)
88
89 # ensure that every server ended up on a different host
90 host_ids = [x['hostId'] for x in servers]
91 self.assertEqual(
92 len(set(host_ids)), len(servers),
93 "Incorrect number of distinct host_ids scheduled to %s" % servers)