blob: f376954f99a1cf67e5f03e3a68d292abd4391fe1 [file] [log] [blame]
Rajat Dhasmana21d63a32020-01-14 17:41:22 +00001# Copyright 2020 Red Hat, Inc.
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
Rajat Dhasmana21d63a32020-01-14 17:41:22 +000016from tempest.common import utils
17from tempest.lib import decorators
18
Luigi Toscano3c5c8a22021-02-23 10:24:01 +010019from cinder_tempest_plugin.scenario import manager
20
Rajat Dhasmana21d63a32020-01-14 17:41:22 +000021
22class SnapshotDataIntegrityTests(manager.ScenarioTest):
23
24 def setUp(self):
25 super(SnapshotDataIntegrityTests, self).setUp()
Dan Smith51c56f22023-04-27 15:49:10 -070026 self.validation_resources = self.get_test_validation_resources(
27 self.os_primary)
28 # NOTE(danms): If validation is enabled, we will have a keypair to use,
29 # otherwise we need to create our own.
30 if 'keypair' in self.validation_resources:
31 self.keypair = self.validation_resources['keypair']
32 else:
33 self.keypair = self.create_keypair()
Rajat Dhasmana638f2302021-05-12 06:23:45 -040034 self.security_group = self.create_security_group()
Rajat Dhasmanad9e59252021-05-11 16:03:47 -040035
Rajat Dhasmana21d63a32020-01-14 17:41:22 +000036 @decorators.idempotent_id('ff10644e-5a70-4a9f-9801-8204bb81fb61')
37 @utils.services('compute', 'volume', 'image', 'network')
38 def test_snapshot_data_integrity(self):
39 """This test checks the data integrity after creating and restoring
40
41 snapshots. The procedure is as follows:
42
Rajat Dhasmanad9e59252021-05-11 16:03:47 -040043 1) Create an instance with ephemeral disk
44 2) Create a volume, attach it to the instance and create a filesystem
45 on it and mount it
whoami-rajat027295a2021-12-12 12:31:59 -050046 3) Create a file and write data into it, Unmount it
Rajat Dhasmana21d63a32020-01-14 17:41:22 +000047 4) create snapshot
48 5) repeat 3 and 4 two more times (simply creating 3 snapshots)
49
Rajat Dhasmanad9e59252021-05-11 16:03:47 -040050 Now create volume from the snapshots one by one, attach it to the
51 instance and check the number of files and file content at each
Rajat Dhasmana21d63a32020-01-14 17:41:22 +000052 point when snapshot was created.
53 """
54
Rajat Dhasmanad9e59252021-05-11 16:03:47 -040055 # Create an instance
56 server = self.create_server(
57 key_name=self.keypair['name'],
Dan Smith51c56f22023-04-27 15:49:10 -070058 validatable=True,
59 validation_resources=self.validation_resources,
60 wait_until='SSHABLE',
Rajat Dhasmanad9e59252021-05-11 16:03:47 -040061 security_groups=[{'name': self.security_group['name']}])
Rajat Dhasmana21d63a32020-01-14 17:41:22 +000062
Rajat Dhasmanad9e59252021-05-11 16:03:47 -040063 # Create an empty volume
64 volume = self.create_volume()
Rajat Dhasmana21d63a32020-01-14 17:41:22 +000065
66 instance_ip = self.get_server_ip(server)
67
Rajat Dhasmanad9e59252021-05-11 16:03:47 -040068 # Attach volume to instance and find it's device name (eg: /dev/vdb)
Rajat Dhasmana638f2302021-05-12 06:23:45 -040069 volume_device_name, __ = self._attach_and_get_volume_device_name(
Rajat Dhasmanad9e59252021-05-11 16:03:47 -040070 server, volume, instance_ip, self.keypair['private_key'])
71
72 # Create filesystem on the volume
73 self._make_fs(instance_ip, self.keypair['private_key'], server,
74 volume_device_name)
75
Rajat Dhasmana21d63a32020-01-14 17:41:22 +000076 # Write data to volume
77 file1_md5 = self.create_md5_new_file(
Rajat Dhasmanad9e59252021-05-11 16:03:47 -040078 instance_ip, dev_name=volume_device_name, filename="file1",
Rajat Dhasmana21d63a32020-01-14 17:41:22 +000079 private_key=self.keypair['private_key'],
80 server=instance_ip)
81
82 # Create first snapshot
83 snapshot1 = self.create_volume_snapshot(volume['id'], force=True)
84
85 # Write data to volume
86 file2_md5 = self.create_md5_new_file(
Rajat Dhasmanad9e59252021-05-11 16:03:47 -040087 instance_ip, dev_name=volume_device_name, filename="file2",
Rajat Dhasmana21d63a32020-01-14 17:41:22 +000088 private_key=self.keypair['private_key'],
89 server=instance_ip)
90
91 # Create second snapshot
92 snapshot2 = self.create_volume_snapshot(volume['id'], force=True)
93
94 # Write data to volume
95 file3_md5 = self.create_md5_new_file(
Rajat Dhasmanad9e59252021-05-11 16:03:47 -040096 instance_ip, dev_name=volume_device_name, filename="file3",
Rajat Dhasmana21d63a32020-01-14 17:41:22 +000097 private_key=self.keypair['private_key'],
98 server=instance_ip)
99
100 # Create third snapshot
101 snapshot3 = self.create_volume_snapshot(volume['id'], force=True)
102
Rajat Dhasmanad9e59252021-05-11 16:03:47 -0400103 # Detach the volume
104 self.nova_volume_detach(server, volume)
105
whoami-rajat027295a2021-12-12 12:31:59 -0500106 snap_map = {1: snapshot1, 2: snapshot2, 3: snapshot3}
107 file_map = {1: file1_md5, 2: file2_md5, 3: file3_md5}
Rajat Dhasmana21d63a32020-01-14 17:41:22 +0000108
whoami-rajat027295a2021-12-12 12:31:59 -0500109 # Loop over 3 times to check the data integrity of all 3 snapshots
110 for i in range(1, 4):
111 # Create volume from snapshot, attach it to instance and check file
112 # and contents for snap
113 volume_snap = self.create_volume(snapshot_id=snap_map[i]['id'])
114 volume_device_name, __ = self._attach_and_get_volume_device_name(
115 server, volume_snap, instance_ip, self.keypair['private_key'])
116 count_snap, md5_file = self.get_md5_from_file(
117 server, instance_ip, 'file' + str(i),
118 dev_name=volume_device_name)
119 # Detach the volume
120 self.nova_volume_detach(server, volume_snap)
Rajat Dhasmana21d63a32020-01-14 17:41:22 +0000121
whoami-rajat027295a2021-12-12 12:31:59 -0500122 self.assertEqual(count_snap, i)
123 self.assertEqual(file_map[i], md5_file)