blob: 99e10571d07742904503840044d0e0cd35777c46 [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()
26 self.keypair = self.create_keypair()
Rajat Dhasmana638f2302021-05-12 06:23:45 -040027 self.security_group = self.create_security_group()
Rajat Dhasmanad9e59252021-05-11 16:03:47 -040028
Rajat Dhasmana21d63a32020-01-14 17:41:22 +000029 @decorators.idempotent_id('ff10644e-5a70-4a9f-9801-8204bb81fb61')
30 @utils.services('compute', 'volume', 'image', 'network')
31 def test_snapshot_data_integrity(self):
32 """This test checks the data integrity after creating and restoring
33
34 snapshots. The procedure is as follows:
35
Rajat Dhasmanad9e59252021-05-11 16:03:47 -040036 1) Create an instance with ephemeral disk
37 2) Create a volume, attach it to the instance and create a filesystem
38 on it and mount it
whoami-rajat027295a2021-12-12 12:31:59 -050039 3) Create a file and write data into it, Unmount it
Rajat Dhasmana21d63a32020-01-14 17:41:22 +000040 4) create snapshot
41 5) repeat 3 and 4 two more times (simply creating 3 snapshots)
42
Rajat Dhasmanad9e59252021-05-11 16:03:47 -040043 Now create volume from the snapshots one by one, attach it to the
44 instance and check the number of files and file content at each
Rajat Dhasmana21d63a32020-01-14 17:41:22 +000045 point when snapshot was created.
46 """
47
Rajat Dhasmanad9e59252021-05-11 16:03:47 -040048 # Create an instance
49 server = self.create_server(
50 key_name=self.keypair['name'],
51 security_groups=[{'name': self.security_group['name']}])
Rajat Dhasmana21d63a32020-01-14 17:41:22 +000052
Rajat Dhasmanad9e59252021-05-11 16:03:47 -040053 # Create an empty volume
54 volume = self.create_volume()
Rajat Dhasmana21d63a32020-01-14 17:41:22 +000055
56 instance_ip = self.get_server_ip(server)
57
Rajat Dhasmanad9e59252021-05-11 16:03:47 -040058 # Attach volume to instance and find it's device name (eg: /dev/vdb)
Rajat Dhasmana638f2302021-05-12 06:23:45 -040059 volume_device_name, __ = self._attach_and_get_volume_device_name(
Rajat Dhasmanad9e59252021-05-11 16:03:47 -040060 server, volume, instance_ip, self.keypair['private_key'])
61
62 # Create filesystem on the volume
63 self._make_fs(instance_ip, self.keypair['private_key'], server,
64 volume_device_name)
65
Rajat Dhasmana21d63a32020-01-14 17:41:22 +000066 # Write data to volume
67 file1_md5 = self.create_md5_new_file(
Rajat Dhasmanad9e59252021-05-11 16:03:47 -040068 instance_ip, dev_name=volume_device_name, filename="file1",
Rajat Dhasmana21d63a32020-01-14 17:41:22 +000069 private_key=self.keypair['private_key'],
70 server=instance_ip)
71
72 # Create first snapshot
73 snapshot1 = self.create_volume_snapshot(volume['id'], force=True)
74
75 # Write data to volume
76 file2_md5 = self.create_md5_new_file(
Rajat Dhasmanad9e59252021-05-11 16:03:47 -040077 instance_ip, dev_name=volume_device_name, filename="file2",
Rajat Dhasmana21d63a32020-01-14 17:41:22 +000078 private_key=self.keypair['private_key'],
79 server=instance_ip)
80
81 # Create second snapshot
82 snapshot2 = self.create_volume_snapshot(volume['id'], force=True)
83
84 # Write data to volume
85 file3_md5 = self.create_md5_new_file(
Rajat Dhasmanad9e59252021-05-11 16:03:47 -040086 instance_ip, dev_name=volume_device_name, filename="file3",
Rajat Dhasmana21d63a32020-01-14 17:41:22 +000087 private_key=self.keypair['private_key'],
88 server=instance_ip)
89
90 # Create third snapshot
91 snapshot3 = self.create_volume_snapshot(volume['id'], force=True)
92
Rajat Dhasmanad9e59252021-05-11 16:03:47 -040093 # Detach the volume
94 self.nova_volume_detach(server, volume)
95
whoami-rajat027295a2021-12-12 12:31:59 -050096 snap_map = {1: snapshot1, 2: snapshot2, 3: snapshot3}
97 file_map = {1: file1_md5, 2: file2_md5, 3: file3_md5}
Rajat Dhasmana21d63a32020-01-14 17:41:22 +000098
whoami-rajat027295a2021-12-12 12:31:59 -050099 # Loop over 3 times to check the data integrity of all 3 snapshots
100 for i in range(1, 4):
101 # Create volume from snapshot, attach it to instance and check file
102 # and contents for snap
103 volume_snap = self.create_volume(snapshot_id=snap_map[i]['id'])
104 volume_device_name, __ = self._attach_and_get_volume_device_name(
105 server, volume_snap, instance_ip, self.keypair['private_key'])
106 count_snap, md5_file = self.get_md5_from_file(
107 server, instance_ip, 'file' + str(i),
108 dev_name=volume_device_name)
109 # Detach the volume
110 self.nova_volume_detach(server, volume_snap)
Rajat Dhasmana21d63a32020-01-14 17:41:22 +0000111
whoami-rajat027295a2021-12-12 12:31:59 -0500112 self.assertEqual(count_snap, i)
113 self.assertEqual(file_map[i], md5_file)