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 | |
| 17 | from oslo_log import log as logging |
| 18 | |
| 19 | from tempest import config |
| 20 | from tempest import exceptions |
| 21 | from tempest.scenario import manager |
| 22 | from tempest import test |
| 23 | |
| 24 | CONF = config.CONF |
| 25 | |
| 26 | LOG = logging.getLogger(__name__) |
| 27 | |
| 28 | |
| 29 | class TestServerMultinode(manager.ScenarioTest): |
Ken'ichi Ohmichi | c4e4f1c | 2015-11-17 08:16:12 +0000 | [diff] [blame] | 30 | """This is a set of tests specific to multinode testing.""" |
Sean Dague | 782f677 | 2015-11-11 11:26:45 -0500 | [diff] [blame] | 31 | credentials = ['primary', 'admin'] |
| 32 | |
Sean Dague | 9b11518 | 2015-11-13 09:20:22 -0500 | [diff] [blame] | 33 | @classmethod |
Jordan Pittier | 619763a | 2016-01-07 19:26:35 +0100 | [diff] [blame] | 34 | def skip_checks(cls): |
| 35 | super(TestServerMultinode, cls).skip_checks() |
| 36 | |
| 37 | if CONF.compute.min_compute_nodes < 2: |
| 38 | raise cls.skipException( |
| 39 | "Less than 2 compute nodes, skipping multinode tests.") |
| 40 | |
| 41 | @classmethod |
Sean Dague | 9b11518 | 2015-11-13 09:20:22 -0500 | [diff] [blame] | 42 | def setup_clients(cls): |
| 43 | super(TestServerMultinode, cls).setup_clients() |
| 44 | # Use admin client by default |
| 45 | cls.manager = cls.admin_manager |
| 46 | # this is needed so that we can use the availability_zone:host |
| 47 | # scheduler hint, which is admin_only by default |
| 48 | cls.servers_client = cls.admin_manager.servers_client |
| 49 | super(TestServerMultinode, cls).resource_setup() |
| 50 | |
Sean Dague | 782f677 | 2015-11-11 11:26:45 -0500 | [diff] [blame] | 51 | @test.idempotent_id('9cecbe35-b9d4-48da-a37e-7ce70aa43d30') |
| 52 | @test.attr(type='smoke') |
| 53 | @test.services('compute', 'network') |
| 54 | def test_schedule_to_all_nodes(self): |
Sean Dague | 9b11518 | 2015-11-13 09:20:22 -0500 | [diff] [blame] | 55 | host_client = self.manager.hosts_client |
Sean Dague | 782f677 | 2015-11-11 11:26:45 -0500 | [diff] [blame] | 56 | hosts = host_client.list_hosts()['hosts'] |
| 57 | hosts = [x for x in hosts if x['service'] == 'compute'] |
| 58 | |
| 59 | # ensure we have at least as many compute hosts as we expect |
| 60 | if len(hosts) < CONF.compute.min_compute_nodes: |
| 61 | raise exceptions.InvalidConfiguration( |
| 62 | "Host list %s is shorter than min_compute_nodes. " |
| 63 | "Did a compute worker not boot correctly?" % hosts) |
| 64 | |
| 65 | # create 1 compute for each node, up to the min_compute_nodes |
| 66 | # threshold (so that things don't get crazy if you have 1000 |
| 67 | # compute nodes but set min to 3). |
| 68 | servers = [] |
| 69 | |
| 70 | for host in hosts[:CONF.compute.min_compute_nodes]: |
Sean Dague | 782f677 | 2015-11-11 11:26:45 -0500 | [diff] [blame] | 71 | # by getting to active state here, this means this has |
| 72 | # landed on the host in question. |
lanoux | 5fc1452 | 2015-09-21 08:17:35 +0000 | [diff] [blame] | 73 | inst = self.create_server( |
| 74 | availability_zone='%(zone)s:%(host_name)s' % host, |
| 75 | wait_until='ACTIVE') |
Sean Dague | 782f677 | 2015-11-11 11:26:45 -0500 | [diff] [blame] | 76 | server = self.servers_client.show_server(inst['id'])['server'] |
| 77 | servers.append(server) |
| 78 | |
| 79 | # make sure we really have the number of servers we think we should |
| 80 | self.assertEqual( |
| 81 | len(servers), CONF.compute.min_compute_nodes, |
| 82 | "Incorrect number of servers built %s" % servers) |
| 83 | |
| 84 | # ensure that every server ended up on a different host |
| 85 | host_ids = [x['hostId'] for x in servers] |
| 86 | self.assertEqual( |
| 87 | len(set(host_ids)), len(servers), |
| 88 | "Incorrect number of distinct host_ids scheduled to %s" % servers) |