Sean Dague | 782f677 | 2015-11-11 11:26:45 -0500 | [diff] [blame] | 1 | # 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 Frittoli | cd36841 | 2017-08-14 21:37:56 +0100 | [diff] [blame] | 16 | from tempest.common import utils |
Sean Dague | 782f677 | 2015-11-11 11:26:45 -0500 | [diff] [blame] | 17 | from tempest import config |
Ken'ichi Ohmichi | c85a951 | 2017-01-27 18:34:24 -0800 | [diff] [blame] | 18 | from tempest.lib import decorators |
Matthew Treinish | 4217a70 | 2016-10-07 17:27:11 -0400 | [diff] [blame] | 19 | from tempest.lib import exceptions |
Sean Dague | 782f677 | 2015-11-11 11:26:45 -0500 | [diff] [blame] | 20 | from tempest.scenario import manager |
Sean Dague | 782f677 | 2015-11-11 11:26:45 -0500 | [diff] [blame] | 21 | |
| 22 | CONF = config.CONF |
| 23 | |
Sean Dague | 782f677 | 2015-11-11 11:26:45 -0500 | [diff] [blame] | 24 | |
| 25 | class TestServerMultinode(manager.ScenarioTest): |
Ken'ichi Ohmichi | c4e4f1c | 2015-11-17 08:16:12 +0000 | [diff] [blame] | 26 | """This is a set of tests specific to multinode testing.""" |
Sean Dague | 782f677 | 2015-11-11 11:26:45 -0500 | [diff] [blame] | 27 | credentials = ['primary', 'admin'] |
| 28 | |
Sean Dague | 9b11518 | 2015-11-13 09:20:22 -0500 | [diff] [blame] | 29 | @classmethod |
Jordan Pittier | 619763a | 2016-01-07 19:26:35 +0100 | [diff] [blame] | 30 | 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 Ohmichi | c85a951 | 2017-01-27 18:34:24 -0800 | [diff] [blame] | 37 | @decorators.idempotent_id('9cecbe35-b9d4-48da-a37e-7ce70aa43d30') |
Ghanshyam Mann | e2183ca | 2023-02-10 19:31:52 -0600 | [diff] [blame] | 38 | @decorators.attr(type=['smoke', 'multinode']) |
Andrea Frittoli | cd36841 | 2017-08-14 21:37:56 +0100 | [diff] [blame] | 39 | @utils.services('compute', 'network') |
Sean Dague | 782f677 | 2015-11-11 11:26:45 -0500 | [diff] [blame] | 40 | def test_schedule_to_all_nodes(self): |
zhufl | 8388992 | 2016-08-18 15:09:47 +0800 | [diff] [blame] | 41 | available_zone = \ |
Jordan Pittier | 8160d31 | 2017-04-18 11:52:23 +0200 | [diff] [blame] | 42 | self.os_admin.availability_zone_client.list_availability_zones( |
zhufl | 8388992 | 2016-08-18 15:09:47 +0800 | [diff] [blame] | 43 | 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 Dague | 782f677 | 2015-11-11 11:26:45 -0500 | [diff] [blame] | 52 | |
| 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 Dague | 782f677 | 2015-11-11 11:26:45 -0500 | [diff] [blame] | 65 | # by getting to active state here, this means this has |
| 66 | # landed on the host in question. |
jeremy.zhang | 0343be5 | 2017-05-25 21:29:57 +0800 | [diff] [blame] | 67 | # in order to use the availability_zone:host scheduler hint, |
| 68 | # admin client is need here. |
lanoux | 5fc1452 | 2015-09-21 08:17:35 +0000 | [diff] [blame] | 69 | inst = self.create_server( |
jeremy.zhang | 0343be5 | 2017-05-25 21:29:57 +0800 | [diff] [blame] | 70 | clients=self.os_admin, |
zhufl | 13c9c89 | 2017-02-10 12:04:07 +0800 | [diff] [blame] | 71 | availability_zone='%(zone)s:%(host_name)s' % host) |
jeremy.zhang | 0343be5 | 2017-05-25 21:29:57 +0800 | [diff] [blame] | 72 | server = self.os_admin.servers_client.show_server( |
| 73 | inst['id'])['server'] |
zhufl | b935f9a | 2017-02-10 15:36:42 +0800 | [diff] [blame] | 74 | # ensure server is located on the requested host |
| 75 | self.assertEqual(host['host_name'], server['OS-EXT-SRV-ATTR:host']) |
Sean Dague | 782f677 | 2015-11-11 11:26:45 -0500 | [diff] [blame] | 76 | 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) |