blob: 543be3182ca9d741fda9b3113096f25448b658ad [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
Ken'ichi Ohmichic85a9512017-01-27 18:34:24 -080022from tempest.lib import decorators
Masayuki Igawa73d9f3a2013-05-24 10:30:01 +090023from tempest.scenario import manager
24
Matthew Treinish6c072292014-01-29 19:15:52 +000025CONF = config.CONF
Masayuki Igawa73d9f3a2013-05-24 10:30:01 +090026
Masayuki Igawa73d9f3a2013-05-24 10:30:01 +090027
Andrea Frittoli247058f2014-07-16 16:09:22 +010028class TestMinimumBasicScenario(manager.ScenarioTest):
Masayuki Igawa73d9f3a2013-05-24 10:30:01 +090029
Ken'ichi Ohmichic4e4f1c2015-11-17 08:16:12 +000030 """This is a basic minimum scenario test.
Masayuki Igawa73d9f3a2013-05-24 10:30:01 +090031
Benny Kopilovd4d49b02021-08-10 18:54:01 +030032 These tests below:
Masayuki Igawa73d9f3a2013-05-24 10:30:01 +090033 * across the multiple components
34 * as a regular user
35 * with and without optional parameters
36 * check command outputs
Masayuki Igawa73d9f3a2013-05-24 10:30:01 +090037 """
afazekas40fcb9b2019-03-08 11:25:11 +010038
Ghanshyam Mann2803b572023-08-04 12:11:59 -070039 @classmethod
40 def skip_checks(cls):
41 super(TestMinimumBasicScenario, cls).skip_checks()
42 if not CONF.service_available.cinder:
43 raise cls.skipException("Cinder is not available")
44
Jordan Pittier7cf64762015-10-14 15:01:12 +020045 def nova_show(self, server):
46 got_server = (self.servers_client.show_server(server['id'])
ghanshyam0f825252015-08-25 16:02:50 +090047 ['server'])
Jordan Pittier5d367152015-08-19 12:03:49 +020048 excluded_keys = ['OS-EXT-AZ:availability_zone']
49 # Exclude these keys because of LP:#1486475
50 excluded_keys.extend(['OS-EXT-STS:power_state', 'updated'])
Andrea Frittoli247058f2014-07-16 16:09:22 +010051 self.assertThat(
Jordan Pittier7cf64762015-10-14 15:01:12 +020052 server, custom_matchers.MatchesDictExceptForKeys(
Jordan Pittier5d367152015-08-19 12:03:49 +020053 got_server, excluded_keys=excluded_keys))
Masayuki Igawa73d9f3a2013-05-24 10:30:01 +090054
Jordan Pittier7cf64762015-10-14 15:01:12 +020055 def cinder_show(self, volume):
56 got_volume = self.volumes_client.show_volume(volume['id'])['volume']
Matt Riedemann3ec41c22019-10-15 11:39:32 -040057 # Exclude updated_at because of bug 1838202.
58 excluded_keys = ['updated_at']
59 self.assertThat(
60 volume, custom_matchers.MatchesDictExceptForKeys(
61 got_volume, excluded_keys=excluded_keys))
Masayuki Igawa73d9f3a2013-05-24 10:30:01 +090062
Benny Kopilovd4d49b02021-08-10 18:54:01 +030063 def nova_reboot(self, server, hard=False):
64 self.servers_client.reboot_server(server['id'],
65 type="HARD" if hard else "SOFT")
Masayuki Igawa8bf68672016-01-15 14:43:10 +090066 waiters.wait_for_server_status(self.servers_client,
67 server['id'], 'ACTIVE')
Masayuki Igawa73d9f3a2013-05-24 10:30:01 +090068
Evgeny Antyshev4894a912016-11-21 12:17:18 +000069 def check_disks(self):
Andrea Frittoli247058f2014-07-16 16:09:22 +010070 # NOTE(andreaf) The device name may be different on different guest OS
Evgeny Antyshev4894a912016-11-21 12:17:18 +000071 disks = self.linux_client.get_disks()
72 self.assertEqual(1, disks.count(CONF.compute.volume_device_name))
Masayuki Igawa73d9f3a2013-05-24 10:30:01 +090073
Ghanshyam Mannb3da2e12023-02-03 13:20:48 -060074 @decorators.attr(type='slow')
Ken'ichi Ohmichic85a9512017-01-27 18:34:24 -080075 @decorators.idempotent_id('bdbb5441-9204-419d-a225-b4fdbfb1a1a8')
Andrea Frittolicd368412017-08-14 21:37:56 +010076 @utils.services('compute', 'volume', 'image', 'network')
Masayuki Igawa73d9f3a2013-05-24 10:30:01 +090077 def test_minimum_basic_scenario(self):
Benny Kopilovd4d49b02021-08-10 18:54:01 +030078 """This is a basic minimum scenario with multiple components
79
80 Steps:
81 1. Create image
82 2. Create keypair
83 3. Boot instance with keypair and get list of instances
84 4. Create volume and show list of volumes
85 5. Attach volume to instance and getlist of volumes
86 6. Add IP to instance
87 7. Create and add security group to instance
88 8. Check SSH connection to instance
89 9. Reboot instance
90 10. Check SSH connection to instance after reboot
91 """
Soniya Vyasbe8d5102020-08-17 17:23:30 +053092 image = self.image_create()
Jordan Pittier7cf64762015-10-14 15:01:12 +020093 keypair = self.create_keypair()
JordanP3fe2dc32014-11-17 13:06:01 +010094
zhufl13c9c892017-02-10 12:04:07 +080095 server = self.create_server(image_id=image, key_name=keypair['name'])
Jordan Pittier93dffb72016-09-16 15:12:31 +020096 servers = self.servers_client.list_servers()['servers']
Jordan Pittier7cf64762015-10-14 15:01:12 +020097 self.assertIn(server['id'], [x['id'] for x in servers])
JordanP3fe2dc32014-11-17 13:06:01 +010098
Jordan Pittier7cf64762015-10-14 15:01:12 +020099 self.nova_show(server)
100
Jordan Pittierbbb17122016-01-26 17:10:55 +0100101 volume = self.create_volume()
102 volumes = self.volumes_client.list_volumes()['volumes']
Jordan Pittier7cf64762015-10-14 15:01:12 +0200103 self.assertIn(volume['id'], [x['id'] for x in volumes])
104
105 self.cinder_show(volume)
106
107 volume = self.nova_volume_attach(server, volume)
108 self.addCleanup(self.nova_volume_detach, server, volume)
109 self.cinder_show(volume)
110
zhufl1bdc3e72018-01-10 14:10:47 +0800111 floating_ip = None
Matt Riedemann8ca50562016-08-16 14:46:01 -0400112 server = self.servers_client.show_server(server['id'])['server']
zhufl1bdc3e72018-01-10 14:10:47 +0800113 if (CONF.network_feature_enabled.floating_ips and
Benny Kopilovd4d49b02021-08-10 18:54:01 +0300114 CONF.network.floating_network_name):
Ghanshyam Mann64281392021-03-24 18:48:38 -0500115 fip = self.create_floating_ip(server)
116 floating_ip = self.associate_floating_ip(
117 fip, server)
Artom Lifshitz8a959ea2021-09-27 12:09:12 -0400118 waiters.wait_for_server_floating_ip(self.servers_client,
119 server, floating_ip)
Ghanshyam Mann64281392021-03-24 18:48:38 -0500120 ssh_ip = floating_ip['floating_ip_address']
zhufl1bdc3e72018-01-10 14:10:47 +0800121 else:
122 ssh_ip = self.get_server_ip(server)
Matt Riedemann8ca50562016-08-16 14:46:01 -0400123
Jordan Pittier7cf64762015-10-14 15:01:12 +0200124 self.create_and_add_security_group_to_server(server)
125
Alexander Gubanova5ab12e2015-11-17 18:18:46 +0200126 # check that we can SSH to the server before reboot
Jordan Pittier7cf64762015-10-14 15:01:12 +0200127 self.linux_client = self.get_remote_client(
zhufl1bdc3e72018-01-10 14:10:47 +0800128 ssh_ip, private_key=keypair['private_key'],
zhuflf52c7592017-05-25 13:55:24 +0800129 server=server)
Alexander Gubanova5ab12e2015-11-17 18:18:46 +0200130
Jordan Pittier7cf64762015-10-14 15:01:12 +0200131 self.nova_reboot(server)
132
Alexander Gubanova5ab12e2015-11-17 18:18:46 +0200133 # check that we can SSH to the server after reboot
134 # (both connections are part of the scenario)
Jordan Pittier7cf64762015-10-14 15:01:12 +0200135 self.linux_client = self.get_remote_client(
zhufl1bdc3e72018-01-10 14:10:47 +0800136 ssh_ip, private_key=keypair['private_key'],
zhuflf52c7592017-05-25 13:55:24 +0800137 server=server)
Alexander Gubanova5ab12e2015-11-17 18:18:46 +0200138
Evgeny Antyshev4894a912016-11-21 12:17:18 +0000139 self.check_disks()
Matt Riedemann8ca50562016-08-16 14:46:01 -0400140
zhufl1bdc3e72018-01-10 14:10:47 +0800141 if floating_ip:
142 # delete the floating IP, this should refresh the server addresses
Ghanshyam Mann64281392021-03-24 18:48:38 -0500143 self.disassociate_floating_ip(floating_ip)
Artom Lifshitz8a959ea2021-09-27 12:09:12 -0400144 waiters.wait_for_server_floating_ip(
145 self.servers_client, server, floating_ip,
146 wait_for_disassociate=True)
Benny Kopilovd4d49b02021-08-10 18:54:01 +0300147
Ghanshyam Mannb3da2e12023-02-03 13:20:48 -0600148 @decorators.attr(type='slow')
Benny Kopilovd4d49b02021-08-10 18:54:01 +0300149 @decorators.idempotent_id('a8fd48ec-1d01-4895-b932-02321661ec1e')
150 @testtools.skipUnless(CONF.volume_feature_enabled.snapshot,
151 "Cinder volume snapshots are disabled")
152 @utils.services('compute', 'volume', 'image', 'network')
153 def test_minimum_basic_instance_hard_reboot_after_vol_snap_deletion(self):
154 """Test compute hard reboot after volume snapshot deleted
155
156 Steps:
157 1. Create image
158 2. Create keypair
159 3. Boot instance with keypair and get list of instances
160 4. Create volume and show list of volumes
161 5. Attach volume to instance and getlist of volumes
162 6. Create a snapshot from volume
163 7. Add IP to instance
164 8. Create and add security group to instance
165 9. Check SSH connection to instance
166 10. Write data timestamp to the attached volume
167 11. Delete volume snapshot before reboot instance
168 12. Reboot instance (HARD)
169 13. Check SSH connection to instance after reboot
170 14. Verify attached disk data timestamp post instance reboot
171 """
172 image = self.image_create()
173 keypair = self.create_keypair()
174
175 server = self.create_server(image_id=image, key_name=keypair['name'])
176 servers = self.servers_client.list_servers()['servers']
177 self.assertIn(server['id'], [x['id'] for x in servers])
178
179 self.nova_show(server)
180
181 volume = self.create_volume()
182 volumes = self.volumes_client.list_volumes()['volumes']
183 self.assertIn(volume['id'], [x['id'] for x in volumes])
184
185 self.cinder_show(volume)
186
187 volume = self.nova_volume_attach(server, volume)
188 self.addCleanup(self.nova_volume_detach, server, volume)
189 snapshot = self.create_volume_snapshot(volume['id'], force=True)
190 self.cinder_show(volume)
191
192 floating_ip = None
193 server = self.servers_client.show_server(server['id'])['server']
194 if (CONF.network_feature_enabled.floating_ips and
195 CONF.network.floating_network_name):
196 fip = self.create_floating_ip(server)
197 floating_ip = self.associate_floating_ip(
198 fip, server)
Artom Lifshitz3f7c50c2022-07-12 12:03:15 -0400199 waiters.wait_for_server_floating_ip(self.servers_client, server,
200 floating_ip)
Benny Kopilovd4d49b02021-08-10 18:54:01 +0300201 ssh_ip = floating_ip['floating_ip_address']
202 else:
203 ssh_ip = self.get_server_ip(server)
204
205 self.create_and_add_security_group_to_server(server)
206
207 # check that we can SSH to the server before reboot
208 self.linux_client = self.get_remote_client(
209 ssh_ip, private_key=keypair['private_key'],
210 server=server)
211
212 # write data to the volume before reboot instance
213 timestamp_before = self.create_timestamp(
214 ssh_ip, private_key=keypair['private_key'], server=server)
215 # delete the snapshot before rebooting the instance
216 self.snapshots_client.delete_snapshot(snapshot['id'])
217 self.snapshots_client.wait_for_resource_deletion(snapshot['id'])
218 self.nova_reboot(server, hard=True)
219
220 # check that we can SSH to the server after reboot
221 # (both connections are part of the scenario)
222 self.linux_client = self.get_remote_client(
223 ssh_ip, private_key=keypair['private_key'],
224 server=server)
225
226 self.check_disks()
227 timestamp_after = self.get_timestamp(
228 ssh_ip, private_key=keypair['private_key'], server=server)
229 self.assertEqual(timestamp_before, timestamp_after)
230 if floating_ip:
231 # delete the floating IP, this should refresh the server addresses
232 self.disassociate_floating_ip(floating_ip)
233 waiters.wait_for_server_floating_ip(
234 self.servers_client, server, floating_ip,
235 wait_for_disassociate=True)