blob: 9285da253123e57f61cd6693800acce6dbfac9a7 [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
Andrea Frittolicd368412017-08-14 21:37:56 +010016from tempest.common import utils
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
Sean Dague782f6772015-11-11 11:26:45 -050021
22CONF = config.CONF
23
Sean Dague782f6772015-11-11 11:26:45 -050024
25class TestServerMultinode(manager.ScenarioTest):
Ken'ichi Ohmichic4e4f1c2015-11-17 08:16:12 +000026 """This is a set of tests specific to multinode testing."""
Sean Dague782f6772015-11-11 11:26:45 -050027 credentials = ['primary', 'admin']
28
Sean Dague9b115182015-11-13 09:20:22 -050029 @classmethod
Jordan Pittier619763a2016-01-07 19:26:35 +010030 def skip_checks(cls):
31 super(TestServerMultinode, cls).skip_checks()
32
33 if CONF.compute.min_compute_nodes < 2:
34 raise cls.skipException(
35 "Less than 2 compute nodes, skipping multinode tests.")
36
Ken'ichi Ohmichic85a9512017-01-27 18:34:24 -080037 @decorators.idempotent_id('9cecbe35-b9d4-48da-a37e-7ce70aa43d30')
Ghanshyam Manne2183ca2023-02-10 19:31:52 -060038 @decorators.attr(type=['smoke', 'multinode'])
Andrea Frittolicd368412017-08-14 21:37:56 +010039 @utils.services('compute', 'network')
Sean Dague782f6772015-11-11 11:26:45 -050040 def test_schedule_to_all_nodes(self):
zhufl83889922016-08-18 15:09:47 +080041 available_zone = \
Jordan Pittier8160d312017-04-18 11:52:23 +020042 self.os_admin.availability_zone_client.list_availability_zones(
zhufl83889922016-08-18 15:09:47 +080043 detail=True)['availabilityZoneInfo']
44 hosts = []
45 for zone in available_zone:
46 if zone['zoneState']['available']:
47 for host in zone['hosts']:
48 if 'nova-compute' in zone['hosts'][host] and \
49 zone['hosts'][host]['nova-compute']['available']:
50 hosts.append({'zone': zone['zoneName'],
51 'host_name': host})
Sean Dague782f6772015-11-11 11:26:45 -050052
53 # ensure we have at least as many compute hosts as we expect
54 if len(hosts) < CONF.compute.min_compute_nodes:
55 raise exceptions.InvalidConfiguration(
56 "Host list %s is shorter than min_compute_nodes. "
57 "Did a compute worker not boot correctly?" % hosts)
58
59 # create 1 compute for each node, up to the min_compute_nodes
60 # threshold (so that things don't get crazy if you have 1000
61 # compute nodes but set min to 3).
62 servers = []
63
64 for host in hosts[:CONF.compute.min_compute_nodes]:
Sean Dague782f6772015-11-11 11:26:45 -050065 # by getting to active state here, this means this has
66 # landed on the host in question.
jeremy.zhang0343be52017-05-25 21:29:57 +080067 # in order to use the availability_zone:host scheduler hint,
68 # admin client is need here.
lanoux5fc14522015-09-21 08:17:35 +000069 inst = self.create_server(
jeremy.zhang0343be52017-05-25 21:29:57 +080070 clients=self.os_admin,
zhufl13c9c892017-02-10 12:04:07 +080071 availability_zone='%(zone)s:%(host_name)s' % host)
jeremy.zhang0343be52017-05-25 21:29:57 +080072 server = self.os_admin.servers_client.show_server(
73 inst['id'])['server']
zhuflb935f9a2017-02-10 15:36:42 +080074 # ensure server is located on the requested host
75 self.assertEqual(host['host_name'], server['OS-EXT-SRV-ATTR:host'])
Sean Dague782f6772015-11-11 11:26:45 -050076 servers.append(server)
77
78 # make sure we really have the number of servers we think we should
79 self.assertEqual(
80 len(servers), CONF.compute.min_compute_nodes,
81 "Incorrect number of servers built %s" % servers)
82
83 # ensure that every server ended up on a different host
84 host_ids = [x['hostId'] for x in servers]
85 self.assertEqual(
86 len(set(host_ids)), len(servers),
87 "Incorrect number of distinct host_ids scheduled to %s" % servers)