blob: e060b0f85504f2c661c71097520d21ff6b90db3a [file] [log] [blame]
Yuiko Takadaebcf6af2013-07-09 05:10:55 +00001# 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
Adam Gandelmanfbc95ac2014-06-19 17:33:43 -070016import testtools
Sean Daguefe8a6092013-07-27 08:15:55 -040017
Andrea Frittolicd368412017-08-14 21:37:56 +010018from tempest.common import utils
Ghanshyam Mann51c0f9a2023-07-21 14:09:40 -050019from tempest.common import waiters
Matthew Treinish6c072292014-01-29 19:15:52 +000020from tempest import config
Jordan Pittier35a63752016-08-30 13:09:12 +020021from tempest.lib.common.utils import test_utils
Andrea Frittoli (andreaf)db9672e2016-02-23 14:07:24 -050022from tempest.lib import decorators
23from tempest.lib import exceptions as lib_exc
Yuiko Takadaebcf6af2013-07-09 05:10:55 +000024from tempest.scenario import manager
Yuiko Takadaebcf6af2013-07-09 05:10:55 +000025
Matthew Treinish6c072292014-01-29 19:15:52 +000026CONF = config.CONF
Yuiko Takadaebcf6af2013-07-09 05:10:55 +000027
28
Andrea Frittolic0651b22014-09-17 16:34:01 +010029class TestStampPattern(manager.ScenarioTest):
Ken'ichi Ohmichic4e4f1c2015-11-17 08:16:12 +000030 """The test suite for both snapshoting and attaching of volume
31
Yuiko Takadaebcf6af2013-07-09 05:10:55 +000032 This test is for snapshotting an instance/volume and attaching the volume
33 created from snapshot to the instance booted from snapshot.
34 The following is the scenario outline:
35 1. Boot an instance "instance1"
36 2. Create a volume "volume1"
37 3. Attach volume1 to instance1
38 4. Create a filesystem on volume1
39 5. Mount volume1
40 6. Create a file which timestamp is written in volume1
41 7. Unmount volume1
42 8. Detach volume1 from instance1
43 9. Get a snapshot "snapshot_from_volume" of volume1
44 10. Get a snapshot "snapshot_from_instance" of instance1
45 11. Boot an instance "instance2" from snapshot_from_instance
46 12. Create a volume "volume2" from snapshot_from_volume
47 13. Attach volume2 to instance2
48 14. Check the existence of a file which created at 6. in volume2
49 """
50
JordanPbce55532014-03-19 12:10:32 +010051 @classmethod
Emily Hugenbruch5e2d2a22015-02-25 21:35:45 +000052 def skip_checks(cls):
53 super(TestStampPattern, cls).skip_checks()
Ghanshyam Mann2803b572023-08-04 12:11:59 -070054 if not CONF.service_available.cinder:
55 raise cls.skipException("Cinder is not available")
JordanPbce55532014-03-19 12:10:32 +010056 if not CONF.volume_feature_enabled.snapshot:
57 raise cls.skipException("Cinder volume snapshots are disabled")
58
Paras Babbar4b45f9e2019-12-11 16:51:57 -050059 def _attached_volume_name(
60 self, disks_list_before_attach, ip_address, private_key):
Sean Dague20e98612016-01-06 14:33:28 -050061 ssh = self.get_remote_client(ip_address, private_key=private_key)
Attila Fazekas70431ba2013-07-26 18:47:37 +020062
Paras Babbar4b45f9e2019-12-11 16:51:57 -050063 def _wait_for_volume_available_on_system():
64 disks_list_after_attach = ssh.list_disks()
65 return len(disks_list_after_attach) > len(disks_list_before_attach)
Attila Fazekas70431ba2013-07-26 18:47:37 +020066
Paras Babbar4b45f9e2019-12-11 16:51:57 -050067 if not test_utils.call_until_true(_wait_for_volume_available_on_system,
Jordan Pittier35a63752016-08-30 13:09:12 +020068 CONF.compute.build_timeout,
69 CONF.compute.build_interval):
guo yunxianebb15f22016-11-01 21:03:35 +080070 raise lib_exc.TimeoutException
Attila Fazekas70431ba2013-07-26 18:47:37 +020071
Paras Babbar4b45f9e2019-12-11 16:51:57 -050072 disks_list_after_attach = ssh.list_disks()
73 volume_name = [item for item in disks_list_after_attach
74 if item not in disks_list_before_attach][0]
75 return volume_name
76
Jordan Pittier3b46d272017-04-12 16:17:28 +020077 @decorators.attr(type='slow')
Ken'ichi Ohmichic85a9512017-01-27 18:34:24 -080078 @decorators.idempotent_id('10fd234a-515c-41e5-b092-8323060598c5')
Adam Gandelmanfbc95ac2014-06-19 17:33:43 -070079 @testtools.skipUnless(CONF.compute_feature_enabled.snapshot,
80 'Snapshotting is not available.')
zhufl6b7040a2017-01-18 16:38:34 +080081 @testtools.skipUnless(CONF.network.public_network_id,
82 'The public_network_id option must be specified.')
Andrea Frittolicd368412017-08-14 21:37:56 +010083 @utils.services('compute', 'network', 'volume', 'image')
Yuiko Takadaebcf6af2013-07-09 05:10:55 +000084 def test_stamp_pattern(self):
Takashi NATSUME6d5a2b42015-09-08 11:27:49 +090085 # prepare for booting an instance
Matt Riedemannfd5657d2015-09-30 14:47:07 -070086 keypair = self.create_keypair()
Soniya Vyas582c1702021-02-22 18:26:17 +053087 security_group = self.create_security_group()
Yuiko Takadaebcf6af2013-07-09 05:10:55 +000088
89 # boot an instance and create a timestamp file in it
Ghanshyam Mann51c0f9a2023-07-21 14:09:40 -050090 volume = self.create_volume(wait_until=None)
lanoux5fc14522015-09-21 08:17:35 +000091 server = self.create_server(
lanoux5fc14522015-09-21 08:17:35 +000092 key_name=keypair['name'],
zhufl96c36cf2017-02-10 09:51:57 +080093 security_groups=[{'name': security_group['name']}])
Yuiko Takadaebcf6af2013-07-09 05:10:55 +000094
95 # create and add floating IP to server1
Sean Dague20e98612016-01-06 14:33:28 -050096 ip_for_server = self.get_server_ip(server)
Yuiko Takadaebcf6af2013-07-09 05:10:55 +000097
Attila Fazekasba184262018-11-04 13:54:30 +010098 # Make sure the machine ssh-able before attaching the volume
Paras Babbar4b45f9e2019-12-11 16:51:57 -050099 linux_client = self.get_remote_client(
100 ip_for_server, private_key=keypair['private_key'],
101 server=server)
102 disks_list_before_attach = linux_client.list_disks()
Ghanshyam Mann51c0f9a2023-07-21 14:09:40 -0500103 waiters.wait_for_volume_resource_status(self.volumes_client,
104 volume['id'], 'available')
105 # The volume retrieved on creation has a non-up-to-date status.
106 # Retrieval after it becomes active ensures correct details.
107 volume = self.volumes_client.show_volume(volume['id'])['volume']
108
Jordan Pittierbbb17122016-01-26 17:10:55 +0100109 self.nova_volume_attach(server, volume)
Paras Babbar4b45f9e2019-12-11 16:51:57 -0500110 volume_device_name = self._attached_volume_name(
111 disks_list_before_attach, ip_for_server, keypair['private_key'])
112
Alexander Gubanovabd154c2015-09-23 23:24:06 +0300113 timestamp = self.create_timestamp(ip_for_server,
Paras Babbar4b45f9e2019-12-11 16:51:57 -0500114 volume_device_name,
Slawek Kaplonski79d8b0f2018-07-30 22:43:41 +0200115 private_key=keypair['private_key'],
116 server=server)
Jordan Pittierbbb17122016-01-26 17:10:55 +0100117 self.nova_volume_detach(server, volume)
Yuiko Takadaebcf6af2013-07-09 05:10:55 +0000118
119 # snapshot the volume
lkuchlan73ed1f32017-07-06 16:22:12 +0300120 volume_snapshot = self.create_volume_snapshot(volume['id'])
Yuiko Takadaebcf6af2013-07-09 05:10:55 +0000121
122 # snapshot the instance
Ken'ichi Ohmichia4912232013-08-26 14:03:25 +0900123 snapshot_image = self.create_server_snapshot(server=server)
Yuiko Takadaebcf6af2013-07-09 05:10:55 +0000124
125 # create second volume from the snapshot(volume2)
Jordan Pittierbbb17122016-01-26 17:10:55 +0100126 volume_from_snapshot = self.create_volume(
Ghanshyam Mann51c0f9a2023-07-21 14:09:40 -0500127 snapshot_id=volume_snapshot['id'], wait_until=None)
Yuiko Takadaebcf6af2013-07-09 05:10:55 +0000128
129 # boot second instance from the snapshot(instance2)
lanoux5fc14522015-09-21 08:17:35 +0000130 server_from_snapshot = self.create_server(
131 image_id=snapshot_image['id'],
132 key_name=keypair['name'],
zhufl96c36cf2017-02-10 09:51:57 +0800133 security_groups=[{'name': security_group['name']}])
Yuiko Takadaebcf6af2013-07-09 05:10:55 +0000134
135 # create and add floating IP to server_from_snapshot
Sean Dague20e98612016-01-06 14:33:28 -0500136 ip_for_snapshot = self.get_server_ip(server_from_snapshot)
Yuiko Takadaebcf6af2013-07-09 05:10:55 +0000137
Attila Fazekasba184262018-11-04 13:54:30 +0100138 # Make sure the machine ssh-able before attaching the volume
139 # Just a live machine is responding
Rajesh Tailora85bdb42024-04-02 12:01:53 +0530140 # for device attach/detach as expected
Paras Babbar4b45f9e2019-12-11 16:51:57 -0500141 linux_client = self.get_remote_client(
142 ip_for_snapshot, private_key=keypair['private_key'],
143 server=server_from_snapshot)
144 disks_list_before_attach = linux_client.list_disks()
Attila Fazekasba184262018-11-04 13:54:30 +0100145
Yuiko Takadaebcf6af2013-07-09 05:10:55 +0000146 # attach volume2 to instance2
Ghanshyam Mann51c0f9a2023-07-21 14:09:40 -0500147 waiters.wait_for_volume_resource_status(self.volumes_client,
148 volume_from_snapshot['id'],
149 'available')
150 # The volume retrieved on creation has a non-up-to-date status.
151 # Retrieval after it becomes active ensures correct details.
152 volume_from_snapshot = self.volumes_client.show_volume(
153 volume_from_snapshot['id'])['volume']
154
Jordan Pittierbbb17122016-01-26 17:10:55 +0100155 self.nova_volume_attach(server_from_snapshot, volume_from_snapshot)
Paras Babbar4b45f9e2019-12-11 16:51:57 -0500156 volume_device_name = self._attached_volume_name(
157 disks_list_before_attach, ip_for_snapshot, keypair['private_key'])
Yuiko Takadaebcf6af2013-07-09 05:10:55 +0000158
159 # check the existence of the timestamp file in the volume2
Alexander Gubanovabd154c2015-09-23 23:24:06 +0300160 timestamp2 = self.get_timestamp(ip_for_snapshot,
Paras Babbar4b45f9e2019-12-11 16:51:57 -0500161 volume_device_name,
Slawek Kaplonski79d8b0f2018-07-30 22:43:41 +0200162 private_key=keypair['private_key'],
163 server=server_from_snapshot)
Alexander Gubanovabd154c2015-09-23 23:24:06 +0300164 self.assertEqual(timestamp, timestamp2)