blob: 90e1bc562f6d7413bfb978a6408c8947bd1a41d1 [file] [log] [blame]
Masayuki Igawa73d9f3a2013-05-24 10:30:01 +09001# Copyright 2013 NEC Corporation
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
Benny Kopilovd4d49b02021-08-10 18:54:01 +030016import testtools
17
Andrea Frittoli247058f2014-07-16 16:09:22 +010018from tempest.common import custom_matchers
Andrea Frittolicd368412017-08-14 21:37:56 +010019from tempest.common import utils
Ken'ichi Ohmichi0eb153c2015-07-13 02:18:25 +000020from tempest.common import waiters
Matthew Treinish6c072292014-01-29 19:15:52 +000021from tempest import config
Jordan Pittier35a63752016-08-30 13:09:12 +020022from tempest.lib.common.utils import test_utils
Ken'ichi Ohmichic85a9512017-01-27 18:34:24 -080023from tempest.lib import decorators
guo yunxian7383a6f2016-12-05 18:56:51 +080024from tempest.lib import exceptions
Masayuki Igawa73d9f3a2013-05-24 10:30:01 +090025from tempest.scenario import manager
26
Matthew Treinish6c072292014-01-29 19:15:52 +000027CONF = config.CONF
Masayuki Igawa73d9f3a2013-05-24 10:30:01 +090028
Masayuki Igawa73d9f3a2013-05-24 10:30:01 +090029
Andrea Frittoli247058f2014-07-16 16:09:22 +010030class TestMinimumBasicScenario(manager.ScenarioTest):
Masayuki Igawa73d9f3a2013-05-24 10:30:01 +090031
Ken'ichi Ohmichic4e4f1c2015-11-17 08:16:12 +000032 """This is a basic minimum scenario test.
Masayuki Igawa73d9f3a2013-05-24 10:30:01 +090033
Benny Kopilovd4d49b02021-08-10 18:54:01 +030034 These tests below:
Masayuki Igawa73d9f3a2013-05-24 10:30:01 +090035 * across the multiple components
36 * as a regular user
37 * with and without optional parameters
38 * check command outputs
Masayuki Igawa73d9f3a2013-05-24 10:30:01 +090039 """
afazekas40fcb9b2019-03-08 11:25:11 +010040
Jordan Pittier7cf64762015-10-14 15:01:12 +020041 def nova_show(self, server):
42 got_server = (self.servers_client.show_server(server['id'])
ghanshyam0f825252015-08-25 16:02:50 +090043 ['server'])
Jordan Pittier5d367152015-08-19 12:03:49 +020044 excluded_keys = ['OS-EXT-AZ:availability_zone']
45 # Exclude these keys because of LP:#1486475
46 excluded_keys.extend(['OS-EXT-STS:power_state', 'updated'])
Andrea Frittoli247058f2014-07-16 16:09:22 +010047 self.assertThat(
Jordan Pittier7cf64762015-10-14 15:01:12 +020048 server, custom_matchers.MatchesDictExceptForKeys(
Jordan Pittier5d367152015-08-19 12:03:49 +020049 got_server, excluded_keys=excluded_keys))
Masayuki Igawa73d9f3a2013-05-24 10:30:01 +090050
Jordan Pittier7cf64762015-10-14 15:01:12 +020051 def cinder_show(self, volume):
52 got_volume = self.volumes_client.show_volume(volume['id'])['volume']
Matt Riedemann3ec41c22019-10-15 11:39:32 -040053 # Exclude updated_at because of bug 1838202.
54 excluded_keys = ['updated_at']
55 self.assertThat(
56 volume, custom_matchers.MatchesDictExceptForKeys(
57 got_volume, excluded_keys=excluded_keys))
Masayuki Igawa73d9f3a2013-05-24 10:30:01 +090058
Benny Kopilovd4d49b02021-08-10 18:54:01 +030059 def nova_reboot(self, server, hard=False):
60 self.servers_client.reboot_server(server['id'],
61 type="HARD" if hard else "SOFT")
Masayuki Igawa8bf68672016-01-15 14:43:10 +090062 waiters.wait_for_server_status(self.servers_client,
63 server['id'], 'ACTIVE')
Masayuki Igawa73d9f3a2013-05-24 10:30:01 +090064
Evgeny Antyshev4894a912016-11-21 12:17:18 +000065 def check_disks(self):
Andrea Frittoli247058f2014-07-16 16:09:22 +010066 # NOTE(andreaf) The device name may be different on different guest OS
Evgeny Antyshev4894a912016-11-21 12:17:18 +000067 disks = self.linux_client.get_disks()
68 self.assertEqual(1, disks.count(CONF.compute.volume_device_name))
Masayuki Igawa73d9f3a2013-05-24 10:30:01 +090069
Jordan Pittier7cf64762015-10-14 15:01:12 +020070 def create_and_add_security_group_to_server(self, server):
Soniya Vyas582c1702021-02-22 18:26:17 +053071 secgroup = self.create_security_group()
Jordan Pittier7cf64762015-10-14 15:01:12 +020072 self.servers_client.add_security_group(server['id'],
Ken'ichi Ohmichie6349f32015-12-09 06:47:54 +000073 name=secgroup['name'])
Andrea Frittoli247058f2014-07-16 16:09:22 +010074 self.addCleanup(self.servers_client.remove_security_group,
Ken'ichi Ohmichi36b714c2015-12-09 08:12:47 +000075 server['id'], name=secgroup['name'])
Grishkin0f1e11c2014-05-04 20:44:52 +040076
Clark Boylanff31bcc2014-11-04 13:44:04 -080077 def wait_for_secgroup_add():
Jordan Pittier7cf64762015-10-14 15:01:12 +020078 body = (self.servers_client.show_server(server['id'])
ghanshyam0f825252015-08-25 16:02:50 +090079 ['server'])
Clark Boylanff31bcc2014-11-04 13:44:04 -080080 return {'name': secgroup['name']} in body['security_groups']
81
Jordan Pittier35a63752016-08-30 13:09:12 +020082 if not test_utils.call_until_true(wait_for_secgroup_add,
83 CONF.compute.build_timeout,
84 CONF.compute.build_interval):
Clark Boylanff31bcc2014-11-04 13:44:04 -080085 msg = ('Timed out waiting for adding security group %s to server '
Jordan Pittier7cf64762015-10-14 15:01:12 +020086 '%s' % (secgroup['id'], server['id']))
Clark Boylanff31bcc2014-11-04 13:44:04 -080087 raise exceptions.TimeoutException(msg)
88
Ken'ichi Ohmichic85a9512017-01-27 18:34:24 -080089 @decorators.idempotent_id('bdbb5441-9204-419d-a225-b4fdbfb1a1a8')
Andrea Frittolicd368412017-08-14 21:37:56 +010090 @utils.services('compute', 'volume', 'image', 'network')
Masayuki Igawa73d9f3a2013-05-24 10:30:01 +090091 def test_minimum_basic_scenario(self):
Benny Kopilovd4d49b02021-08-10 18:54:01 +030092 """This is a basic minimum scenario with multiple components
93
94 Steps:
95 1. Create image
96 2. Create keypair
97 3. Boot instance with keypair and get list of instances
98 4. Create volume and show list of volumes
99 5. Attach volume to instance and getlist of volumes
100 6. Add IP to instance
101 7. Create and add security group to instance
102 8. Check SSH connection to instance
103 9. Reboot instance
104 10. Check SSH connection to instance after reboot
105 """
Soniya Vyasbe8d5102020-08-17 17:23:30 +0530106 image = self.image_create()
Jordan Pittier7cf64762015-10-14 15:01:12 +0200107 keypair = self.create_keypair()
JordanP3fe2dc32014-11-17 13:06:01 +0100108
zhufl13c9c892017-02-10 12:04:07 +0800109 server = self.create_server(image_id=image, key_name=keypair['name'])
Jordan Pittier93dffb72016-09-16 15:12:31 +0200110 servers = self.servers_client.list_servers()['servers']
Jordan Pittier7cf64762015-10-14 15:01:12 +0200111 self.assertIn(server['id'], [x['id'] for x in servers])
JordanP3fe2dc32014-11-17 13:06:01 +0100112
Jordan Pittier7cf64762015-10-14 15:01:12 +0200113 self.nova_show(server)
114
Jordan Pittierbbb17122016-01-26 17:10:55 +0100115 volume = self.create_volume()
116 volumes = self.volumes_client.list_volumes()['volumes']
Jordan Pittier7cf64762015-10-14 15:01:12 +0200117 self.assertIn(volume['id'], [x['id'] for x in volumes])
118
119 self.cinder_show(volume)
120
121 volume = self.nova_volume_attach(server, volume)
122 self.addCleanup(self.nova_volume_detach, server, volume)
123 self.cinder_show(volume)
124
zhufl1bdc3e72018-01-10 14:10:47 +0800125 floating_ip = None
Matt Riedemann8ca50562016-08-16 14:46:01 -0400126 server = self.servers_client.show_server(server['id'])['server']
zhufl1bdc3e72018-01-10 14:10:47 +0800127 if (CONF.network_feature_enabled.floating_ips and
Benny Kopilovd4d49b02021-08-10 18:54:01 +0300128 CONF.network.floating_network_name):
Ghanshyam Mann64281392021-03-24 18:48:38 -0500129 fip = self.create_floating_ip(server)
130 floating_ip = self.associate_floating_ip(
131 fip, server)
Artom Lifshitz8a959ea2021-09-27 12:09:12 -0400132 waiters.wait_for_server_floating_ip(self.servers_client,
133 server, floating_ip)
Ghanshyam Mann64281392021-03-24 18:48:38 -0500134 ssh_ip = floating_ip['floating_ip_address']
zhufl1bdc3e72018-01-10 14:10:47 +0800135 else:
136 ssh_ip = self.get_server_ip(server)
Matt Riedemann8ca50562016-08-16 14:46:01 -0400137
Jordan Pittier7cf64762015-10-14 15:01:12 +0200138 self.create_and_add_security_group_to_server(server)
139
Alexander Gubanova5ab12e2015-11-17 18:18:46 +0200140 # check that we can SSH to the server before reboot
Jordan Pittier7cf64762015-10-14 15:01:12 +0200141 self.linux_client = self.get_remote_client(
zhufl1bdc3e72018-01-10 14:10:47 +0800142 ssh_ip, private_key=keypair['private_key'],
zhuflf52c7592017-05-25 13:55:24 +0800143 server=server)
Alexander Gubanova5ab12e2015-11-17 18:18:46 +0200144
Jordan Pittier7cf64762015-10-14 15:01:12 +0200145 self.nova_reboot(server)
146
Alexander Gubanova5ab12e2015-11-17 18:18:46 +0200147 # check that we can SSH to the server after reboot
148 # (both connections are part of the scenario)
Jordan Pittier7cf64762015-10-14 15:01:12 +0200149 self.linux_client = self.get_remote_client(
zhufl1bdc3e72018-01-10 14:10:47 +0800150 ssh_ip, private_key=keypair['private_key'],
zhuflf52c7592017-05-25 13:55:24 +0800151 server=server)
Alexander Gubanova5ab12e2015-11-17 18:18:46 +0200152
Evgeny Antyshev4894a912016-11-21 12:17:18 +0000153 self.check_disks()
Matt Riedemann8ca50562016-08-16 14:46:01 -0400154
zhufl1bdc3e72018-01-10 14:10:47 +0800155 if floating_ip:
156 # delete the floating IP, this should refresh the server addresses
Ghanshyam Mann64281392021-03-24 18:48:38 -0500157 self.disassociate_floating_ip(floating_ip)
Artom Lifshitz8a959ea2021-09-27 12:09:12 -0400158 waiters.wait_for_server_floating_ip(
159 self.servers_client, server, floating_ip,
160 wait_for_disassociate=True)
Benny Kopilovd4d49b02021-08-10 18:54:01 +0300161
Benny Kopilovd4d49b02021-08-10 18:54:01 +0300162 @decorators.idempotent_id('a8fd48ec-1d01-4895-b932-02321661ec1e')
163 @testtools.skipUnless(CONF.volume_feature_enabled.snapshot,
164 "Cinder volume snapshots are disabled")
165 @utils.services('compute', 'volume', 'image', 'network')
166 def test_minimum_basic_instance_hard_reboot_after_vol_snap_deletion(self):
167 """Test compute hard reboot after volume snapshot deleted
168
169 Steps:
170 1. Create image
171 2. Create keypair
172 3. Boot instance with keypair and get list of instances
173 4. Create volume and show list of volumes
174 5. Attach volume to instance and getlist of volumes
175 6. Create a snapshot from volume
176 7. Add IP to instance
177 8. Create and add security group to instance
178 9. Check SSH connection to instance
179 10. Write data timestamp to the attached volume
180 11. Delete volume snapshot before reboot instance
181 12. Reboot instance (HARD)
182 13. Check SSH connection to instance after reboot
183 14. Verify attached disk data timestamp post instance reboot
184 """
185 image = self.image_create()
186 keypair = self.create_keypair()
187
188 server = self.create_server(image_id=image, key_name=keypair['name'])
189 servers = self.servers_client.list_servers()['servers']
190 self.assertIn(server['id'], [x['id'] for x in servers])
191
192 self.nova_show(server)
193
194 volume = self.create_volume()
195 volumes = self.volumes_client.list_volumes()['volumes']
196 self.assertIn(volume['id'], [x['id'] for x in volumes])
197
198 self.cinder_show(volume)
199
200 volume = self.nova_volume_attach(server, volume)
201 self.addCleanup(self.nova_volume_detach, server, volume)
202 snapshot = self.create_volume_snapshot(volume['id'], force=True)
203 self.cinder_show(volume)
204
205 floating_ip = None
206 server = self.servers_client.show_server(server['id'])['server']
207 if (CONF.network_feature_enabled.floating_ips and
208 CONF.network.floating_network_name):
209 fip = self.create_floating_ip(server)
210 floating_ip = self.associate_floating_ip(
211 fip, server)
Artom Lifshitz3f7c50c2022-07-12 12:03:15 -0400212 waiters.wait_for_server_floating_ip(self.servers_client, server,
213 floating_ip)
Benny Kopilovd4d49b02021-08-10 18:54:01 +0300214 ssh_ip = floating_ip['floating_ip_address']
215 else:
216 ssh_ip = self.get_server_ip(server)
217
218 self.create_and_add_security_group_to_server(server)
219
220 # check that we can SSH to the server before reboot
221 self.linux_client = self.get_remote_client(
222 ssh_ip, private_key=keypair['private_key'],
223 server=server)
224
225 # write data to the volume before reboot instance
226 timestamp_before = self.create_timestamp(
227 ssh_ip, private_key=keypair['private_key'], server=server)
228 # delete the snapshot before rebooting the instance
229 self.snapshots_client.delete_snapshot(snapshot['id'])
230 self.snapshots_client.wait_for_resource_deletion(snapshot['id'])
231 self.nova_reboot(server, hard=True)
232
233 # check that we can SSH to the server after reboot
234 # (both connections are part of the scenario)
235 self.linux_client = self.get_remote_client(
236 ssh_ip, private_key=keypair['private_key'],
237 server=server)
238
239 self.check_disks()
240 timestamp_after = self.get_timestamp(
241 ssh_ip, private_key=keypair['private_key'], server=server)
242 self.assertEqual(timestamp_before, timestamp_after)
243 if floating_ip:
244 # delete the floating IP, this should refresh the server addresses
245 self.disassociate_floating_ip(floating_ip)
246 waiters.wait_for_server_floating_ip(
247 self.servers_client, server, floating_ip,
248 wait_for_disassociate=True)