Oleksii Zhurba | 7f3941b | 2018-03-27 14:38:42 -0500 | [diff] [blame] | 1 | |
| 2 | |
| 3 | import testtools |
| 4 | @test.attr(type='full') |
| 5 | @test.services('compute', 'network') |
| 6 | @testtools.skipUnless(CONF.compute_feature_enabled.live_migration, |
| 7 | 'Live migration must be enabled in tempest.conf') |
| 8 | def test_live_migrate_to_all_nodes(self): |
| 9 | # collect all active hosts in all az |
| 10 | if not CONF.compute_feature_enabled.live_migration: |
| 11 | raise cls.skipException( |
| 12 | "Live migration is disabled") |
| 13 | available_zone = \ |
| 14 | self.os_adm.availability_zone_client.list_availability_zones( |
| 15 | detail=True)['availabilityZoneInfo'] |
| 16 | hosts = [] |
| 17 | for zone in available_zone: |
| 18 | if zone['zoneState']['available']: |
| 19 | for host in zone['hosts']: |
| 20 | if 'nova-compute' in zone['hosts'][host] and \ |
| 21 | zone['hosts'][host]['nova-compute']['available']: |
| 22 | hosts.append({'zone': zone['zoneName'], |
| 23 | 'host_name': host}) |
| 24 | |
| 25 | # ensure we have at least as many compute hosts as we expect |
| 26 | if len(hosts) < CONF.compute.min_compute_nodes: |
| 27 | raise exceptions.InvalidConfiguration( |
| 28 | "Host list %s is shorter than min_compute_nodes. " |
| 29 | "Did a compute worker not boot correctly?" % hosts) |
| 30 | |
| 31 | # Create 1 VM |
| 32 | servers = [] |
| 33 | first_last_host = hosts[0] |
| 34 | inst = self.create_server( |
| 35 | availability_zone='%(zone)s:%(host_name)s' % hosts[0], |
| 36 | wait_until='ACTIVE') |
| 37 | server = self.servers_client.show_server(inst['id'])['server'] |
| 38 | # ensure server is located on the requested host |
| 39 | self.assertEqual(hosts[0]['host_name'], server['OS-EXT-SRV-ATTR:host']) |
| 40 | hosts.remove(first_last_host) |
| 41 | hosts.append(first_last_host) |
| 42 | |
| 43 | # Live migrate to every host |
| 44 | for host in hosts[:CONF.compute.min_compute_nodes]: |
| 45 | self.servers_client.live_migrate_server(server_id=inst["id"],host=host['host_name'],block_migration=CONF.compute_feature_enabled.block_migration_for_live_migration,disk_over_commit=False) |
| 46 | waiters.wait_for_server_status(self.servers_client, inst["id"], 'ACTIVE') |
| 47 | server = self.servers_client.show_server(inst['id'])['server'] |
| 48 | # ensure server is located on the requested host |
| 49 | self.assertEqual(host['host_name'], server['OS-EXT-SRV-ATTR:host']) |
| 50 | |
| 51 | |
| 52 | from tempest.lib.common.utils import test_utils |
| 53 | class TestServerSshAllComputes(manager.NetworkScenarioTest): |
| 54 | credentials = ['primary', 'admin'] |
| 55 | |
| 56 | |
| 57 | @classmethod |
| 58 | def setup_clients(cls): |
| 59 | super(TestServerSshAllComputes, cls).setup_clients() |
| 60 | # Use admin client by default |
| 61 | cls.manager = cls.admin_manager |
| 62 | # this is needed so that we can use the availability_zone:host |
| 63 | # scheduler hint, which is admin_only by default |
| 64 | cls.servers_client = cls.admin_manager.servers_client |
| 65 | |
| 66 | @test.attr(type='full') |
| 67 | @test.services('compute', 'network') |
| 68 | def test_ssh_to_all_nodes(self): |
| 69 | available_zone = \ |
| 70 | self.os_adm.availability_zone_client.list_availability_zones( |
| 71 | detail=True)['availabilityZoneInfo'] |
| 72 | hosts = [] |
| 73 | for zone in available_zone: |
| 74 | if zone['zoneState']['available']: |
| 75 | for host in zone['hosts']: |
| 76 | if 'nova-compute' in zone['hosts'][host] and \ |
| 77 | zone['hosts'][host]['nova-compute']['available']: |
| 78 | hosts.append({'zone': zone['zoneName'], |
| 79 | 'host_name': host}) |
| 80 | |
| 81 | # ensure we have at least as many compute hosts as we expect |
| 82 | if len(hosts) < CONF.compute.min_compute_nodes: |
| 83 | raise exceptions.InvalidConfiguration( |
| 84 | "Host list %s is shorter than min_compute_nodes. " |
| 85 | "Did a compute worker not boot correctly?" % hosts) |
| 86 | |
| 87 | servers = [] |
| 88 | |
| 89 | # prepare key pair and sec group |
| 90 | keypair = self.os_adm.keypairs_client.create_keypair(name="tempest-live") |
| 91 | secgroup = self._create_security_group(security_groups_client=self.os_adm.security_groups_client, security_group_rules_client=self.os_adm.security_group_rules_client, tenant_id=self.os_adm.security_groups_client.tenant_id) |
| 92 | |
| 93 | # create 1 compute for each node, up to the min_compute_nodes |
| 94 | # threshold (so that things don't get crazy if you have 1000 |
| 95 | # compute nodes but set min to 3). |
| 96 | |
| 97 | for host in hosts[:CONF.compute.min_compute_nodes]: |
| 98 | inst = self.create_server( |
| 99 | availability_zone='%(zone)s:%(host_name)s' % host, |
| 100 | key_name=keypair['keypair']['name']) |
| 101 | server = self.os_adm.servers_client.show_server(inst['id'])['server'] |
| 102 | # TODO we may create server with sec group instead of adding it |
| 103 | self.os_adm.servers_client.add_security_group(server['id'], |
| 104 | name=secgroup['name']) |
| 105 | |
| 106 | # ensure server is located on the requested host |
| 107 | self.assertEqual(host['host_name'], server['OS-EXT-SRV-ATTR:host']) |
| 108 | # TODO maybe check validate = True? |
| 109 | if CONF.network.public_network_id: |
| 110 | # Check VM via ssh |
| 111 | floating_ip = self.os_adm.compute_floating_ips_client.create_floating_ip(pool=CONF.network.floating_network_name)['floating_ip'] |
| 112 | self.addCleanup(test_utils.call_and_ignore_notfound_exc, |
| 113 | self.os_adm.compute_floating_ips_client.delete_floating_ip, |
| 114 | floating_ip['id']) |
| 115 | self.os_adm.compute_floating_ips_client.associate_floating_ip_to_server(floating_ip['ip'], inst['id']) |
| 116 | |
| 117 | # TODO maybe add this |
| 118 | # "Failed to find floating IP '%s' in server addresses: %s" % |
| 119 | # (floating_ip['ip'], server['addresses'])) |
| 120 | |
| 121 | # check that we can SSH to the server |
| 122 | self.linux_client = self.get_remote_client( |
| 123 | floating_ip['ip'], private_key=keypair['keypair']['private_key']) |
| 124 | |
| 125 | servers.append(server) |
| 126 | |
| 127 | # make sure we really have the number of servers we think we should |
| 128 | self.assertEqual( |
| 129 | len(servers), CONF.compute.min_compute_nodes, |
| 130 | "Incorrect number of servers built %s" % servers) |
| 131 | |
| 132 | # ensure that every server ended up on a different host |
| 133 | host_ids = [x['hostId'] for x in servers] |
| 134 | self.assertEqual( |
| 135 | len(set(host_ids)), len(servers), |
| 136 | "Incorrect number of distinct host_ids scheduled to %s" % servers) |
| 137 | self.os_adm.keypairs_client.delete_keypair(keypair['keypair']['name']) |