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