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 | |
| 16 | |
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 |
| 21 | from tempest import test |
| 22 | |
| 23 | CONF = config.CONF |
| 24 | |
Sean Dague | 782f677 | 2015-11-11 11:26:45 -0500 | [diff] [blame] | 25 | |
| 26 | class TestServerMultinode(manager.ScenarioTest): |
Ken'ichi Ohmichi | c4e4f1c | 2015-11-17 08:16:12 +0000 | [diff] [blame] | 27 | """This is a set of tests specific to multinode testing.""" |
Sean Dague | 782f677 | 2015-11-11 11:26:45 -0500 | [diff] [blame] | 28 | credentials = ['primary', 'admin'] |
| 29 | |
Sean Dague | 9b11518 | 2015-11-13 09:20:22 -0500 | [diff] [blame] | 30 | @classmethod |
Jordan Pittier | 619763a | 2016-01-07 19:26:35 +0100 | [diff] [blame] | 31 | 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 Dague | 9b11518 | 2015-11-13 09:20:22 -0500 | [diff] [blame] | 39 | 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 Dague | 9b11518 | 2015-11-13 09:20:22 -0500 | [diff] [blame] | 46 | |
Ken'ichi Ohmichi | c85a951 | 2017-01-27 18:34:24 -0800 | [diff] [blame] | 47 | @decorators.idempotent_id('9cecbe35-b9d4-48da-a37e-7ce70aa43d30') |
Jordan Pittier | 3b46d27 | 2017-04-12 16:17:28 +0200 | [diff] [blame] | 48 | @decorators.attr(type='smoke') |
Sean Dague | 782f677 | 2015-11-11 11:26:45 -0500 | [diff] [blame] | 49 | @test.services('compute', 'network') |
| 50 | def test_schedule_to_all_nodes(self): |
zhufl | 8388992 | 2016-08-18 15:09:47 +0800 | [diff] [blame] | 51 | available_zone = \ |
Jordan Pittier | 8160d31 | 2017-04-18 11:52:23 +0200 | [diff] [blame] | 52 | self.os_admin.availability_zone_client.list_availability_zones( |
zhufl | 8388992 | 2016-08-18 15:09:47 +0800 | [diff] [blame] | 53 | 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 Dague | 782f677 | 2015-11-11 11:26:45 -0500 | [diff] [blame] | 62 | |
| 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 Dague | 782f677 | 2015-11-11 11:26:45 -0500 | [diff] [blame] | 75 | # by getting to active state here, this means this has |
| 76 | # landed on the host in question. |
lanoux | 5fc1452 | 2015-09-21 08:17:35 +0000 | [diff] [blame] | 77 | inst = self.create_server( |
zhufl | 13c9c89 | 2017-02-10 12:04:07 +0800 | [diff] [blame] | 78 | availability_zone='%(zone)s:%(host_name)s' % host) |
Sean Dague | 782f677 | 2015-11-11 11:26:45 -0500 | [diff] [blame] | 79 | server = self.servers_client.show_server(inst['id'])['server'] |
zhufl | b935f9a | 2017-02-10 15:36:42 +0800 | [diff] [blame] | 80 | # ensure server is located on the requested host |
| 81 | self.assertEqual(host['host_name'], server['OS-EXT-SRV-ATTR:host']) |
Sean Dague | 782f677 | 2015-11-11 11:26:45 -0500 | [diff] [blame] | 82 | 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) |