blob: 5513f4d0e35b0cd419ce3f9675418287f63c831c [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
Ghanshyam Mannb3da2e12023-02-03 13:20:48 -060089 @decorators.attr(type='slow')
Ken'ichi Ohmichic85a9512017-01-27 18:34:24 -080090 @decorators.idempotent_id('bdbb5441-9204-419d-a225-b4fdbfb1a1a8')
Andrea Frittolicd368412017-08-14 21:37:56 +010091 @utils.services('compute', 'volume', 'image', 'network')
Masayuki Igawa73d9f3a2013-05-24 10:30:01 +090092 def test_minimum_basic_scenario(self):
Benny Kopilovd4d49b02021-08-10 18:54:01 +030093 """This is a basic minimum scenario with multiple components
94
95 Steps:
96 1. Create image
97 2. Create keypair
98 3. Boot instance with keypair and get list of instances
99 4. Create volume and show list of volumes
100 5. Attach volume to instance and getlist of volumes
101 6. Add IP to instance
102 7. Create and add security group to instance
103 8. Check SSH connection to instance
104 9. Reboot instance
105 10. Check SSH connection to instance after reboot
106 """
Soniya Vyasbe8d5102020-08-17 17:23:30 +0530107 image = self.image_create()
Jordan Pittier7cf64762015-10-14 15:01:12 +0200108 keypair = self.create_keypair()
JordanP3fe2dc32014-11-17 13:06:01 +0100109
zhufl13c9c892017-02-10 12:04:07 +0800110 server = self.create_server(image_id=image, key_name=keypair['name'])
Jordan Pittier93dffb72016-09-16 15:12:31 +0200111 servers = self.servers_client.list_servers()['servers']
Jordan Pittier7cf64762015-10-14 15:01:12 +0200112 self.assertIn(server['id'], [x['id'] for x in servers])
JordanP3fe2dc32014-11-17 13:06:01 +0100113
Jordan Pittier7cf64762015-10-14 15:01:12 +0200114 self.nova_show(server)
115
Jordan Pittierbbb17122016-01-26 17:10:55 +0100116 volume = self.create_volume()
117 volumes = self.volumes_client.list_volumes()['volumes']
Jordan Pittier7cf64762015-10-14 15:01:12 +0200118 self.assertIn(volume['id'], [x['id'] for x in volumes])
119
120 self.cinder_show(volume)
121
122 volume = self.nova_volume_attach(server, volume)
123 self.addCleanup(self.nova_volume_detach, server, volume)
124 self.cinder_show(volume)
125
zhufl1bdc3e72018-01-10 14:10:47 +0800126 floating_ip = None
Matt Riedemann8ca50562016-08-16 14:46:01 -0400127 server = self.servers_client.show_server(server['id'])['server']
zhufl1bdc3e72018-01-10 14:10:47 +0800128 if (CONF.network_feature_enabled.floating_ips and
Benny Kopilovd4d49b02021-08-10 18:54:01 +0300129 CONF.network.floating_network_name):
Ghanshyam Mann64281392021-03-24 18:48:38 -0500130 fip = self.create_floating_ip(server)
131 floating_ip = self.associate_floating_ip(
132 fip, server)
Artom Lifshitz8a959ea2021-09-27 12:09:12 -0400133 waiters.wait_for_server_floating_ip(self.servers_client,
134 server, floating_ip)
Ghanshyam Mann64281392021-03-24 18:48:38 -0500135 ssh_ip = floating_ip['floating_ip_address']
zhufl1bdc3e72018-01-10 14:10:47 +0800136 else:
137 ssh_ip = self.get_server_ip(server)
Matt Riedemann8ca50562016-08-16 14:46:01 -0400138
Jordan Pittier7cf64762015-10-14 15:01:12 +0200139 self.create_and_add_security_group_to_server(server)
140
Alexander Gubanova5ab12e2015-11-17 18:18:46 +0200141 # check that we can SSH to the server before reboot
Jordan Pittier7cf64762015-10-14 15:01:12 +0200142 self.linux_client = self.get_remote_client(
zhufl1bdc3e72018-01-10 14:10:47 +0800143 ssh_ip, private_key=keypair['private_key'],
zhuflf52c7592017-05-25 13:55:24 +0800144 server=server)
Alexander Gubanova5ab12e2015-11-17 18:18:46 +0200145
Jordan Pittier7cf64762015-10-14 15:01:12 +0200146 self.nova_reboot(server)
147
Alexander Gubanova5ab12e2015-11-17 18:18:46 +0200148 # check that we can SSH to the server after reboot
149 # (both connections are part of the scenario)
Jordan Pittier7cf64762015-10-14 15:01:12 +0200150 self.linux_client = self.get_remote_client(
zhufl1bdc3e72018-01-10 14:10:47 +0800151 ssh_ip, private_key=keypair['private_key'],
zhuflf52c7592017-05-25 13:55:24 +0800152 server=server)
Alexander Gubanova5ab12e2015-11-17 18:18:46 +0200153
Evgeny Antyshev4894a912016-11-21 12:17:18 +0000154 self.check_disks()
Matt Riedemann8ca50562016-08-16 14:46:01 -0400155
zhufl1bdc3e72018-01-10 14:10:47 +0800156 if floating_ip:
157 # delete the floating IP, this should refresh the server addresses
Ghanshyam Mann64281392021-03-24 18:48:38 -0500158 self.disassociate_floating_ip(floating_ip)
Artom Lifshitz8a959ea2021-09-27 12:09:12 -0400159 waiters.wait_for_server_floating_ip(
160 self.servers_client, server, floating_ip,
161 wait_for_disassociate=True)
Benny Kopilovd4d49b02021-08-10 18:54:01 +0300162
Ghanshyam Mannb3da2e12023-02-03 13:20:48 -0600163 @decorators.attr(type='slow')
Benny Kopilovd4d49b02021-08-10 18:54:01 +0300164 @decorators.idempotent_id('a8fd48ec-1d01-4895-b932-02321661ec1e')
165 @testtools.skipUnless(CONF.volume_feature_enabled.snapshot,
166 "Cinder volume snapshots are disabled")
167 @utils.services('compute', 'volume', 'image', 'network')
168 def test_minimum_basic_instance_hard_reboot_after_vol_snap_deletion(self):
169 """Test compute hard reboot after volume snapshot deleted
170
171 Steps:
172 1. Create image
173 2. Create keypair
174 3. Boot instance with keypair and get list of instances
175 4. Create volume and show list of volumes
176 5. Attach volume to instance and getlist of volumes
177 6. Create a snapshot from volume
178 7. Add IP to instance
179 8. Create and add security group to instance
180 9. Check SSH connection to instance
181 10. Write data timestamp to the attached volume
182 11. Delete volume snapshot before reboot instance
183 12. Reboot instance (HARD)
184 13. Check SSH connection to instance after reboot
185 14. Verify attached disk data timestamp post instance reboot
186 """
187 image = self.image_create()
188 keypair = self.create_keypair()
189
190 server = self.create_server(image_id=image, key_name=keypair['name'])
191 servers = self.servers_client.list_servers()['servers']
192 self.assertIn(server['id'], [x['id'] for x in servers])
193
194 self.nova_show(server)
195
196 volume = self.create_volume()
197 volumes = self.volumes_client.list_volumes()['volumes']
198 self.assertIn(volume['id'], [x['id'] for x in volumes])
199
200 self.cinder_show(volume)
201
202 volume = self.nova_volume_attach(server, volume)
203 self.addCleanup(self.nova_volume_detach, server, volume)
204 snapshot = self.create_volume_snapshot(volume['id'], force=True)
205 self.cinder_show(volume)
206
207 floating_ip = None
208 server = self.servers_client.show_server(server['id'])['server']
209 if (CONF.network_feature_enabled.floating_ips and
210 CONF.network.floating_network_name):
211 fip = self.create_floating_ip(server)
212 floating_ip = self.associate_floating_ip(
213 fip, server)
Artom Lifshitz3f7c50c2022-07-12 12:03:15 -0400214 waiters.wait_for_server_floating_ip(self.servers_client, server,
215 floating_ip)
Benny Kopilovd4d49b02021-08-10 18:54:01 +0300216 ssh_ip = floating_ip['floating_ip_address']
217 else:
218 ssh_ip = self.get_server_ip(server)
219
220 self.create_and_add_security_group_to_server(server)
221
222 # check that we can SSH to the server before reboot
223 self.linux_client = self.get_remote_client(
224 ssh_ip, private_key=keypair['private_key'],
225 server=server)
226
227 # write data to the volume before reboot instance
228 timestamp_before = self.create_timestamp(
229 ssh_ip, private_key=keypair['private_key'], server=server)
230 # delete the snapshot before rebooting the instance
231 self.snapshots_client.delete_snapshot(snapshot['id'])
232 self.snapshots_client.wait_for_resource_deletion(snapshot['id'])
233 self.nova_reboot(server, hard=True)
234
235 # check that we can SSH to the server after reboot
236 # (both connections are part of the scenario)
237 self.linux_client = self.get_remote_client(
238 ssh_ip, private_key=keypair['private_key'],
239 server=server)
240
241 self.check_disks()
242 timestamp_after = self.get_timestamp(
243 ssh_ip, private_key=keypair['private_key'], server=server)
244 self.assertEqual(timestamp_before, timestamp_after)
245 if floating_ip:
246 # delete the floating IP, this should refresh the server addresses
247 self.disassociate_floating_ip(floating_ip)
248 waiters.wait_for_server_floating_ip(
249 self.servers_client, server, floating_ip,
250 wait_for_disassociate=True)