blob: 5a9611f8f62eafebe779a41ba321acccc9915229 [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
39 3) Mount the volume, 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
96 # Create volume from snapshot, attach it to instance and check file
97 # and contents for snap1
98 volume_snap_1 = self.create_volume(snapshot_id=snapshot1['id'])
Rajat Dhasmana638f2302021-05-12 06:23:45 -040099 volume_device_name, __ = self._attach_and_get_volume_device_name(
Rajat Dhasmanad9e59252021-05-11 16:03:47 -0400100 server, volume_snap_1, instance_ip, self.keypair['private_key'])
101 count_snap_1, md5_file_1 = self.get_md5_from_file(
102 server, instance_ip, 'file1', dev_name=volume_device_name)
103 # Detach the volume
104 self.nova_volume_detach(server, volume_snap_1)
Rajat Dhasmana21d63a32020-01-14 17:41:22 +0000105
106 self.assertEqual(count_snap_1, 1)
107 self.assertEqual(file1_md5, md5_file_1)
108
Rajat Dhasmanad9e59252021-05-11 16:03:47 -0400109 # Create volume from snapshot, attach it to instance and check file
110 # and contents for snap2
111 volume_snap_2 = self.create_volume(snapshot_id=snapshot2['id'])
Rajat Dhasmana638f2302021-05-12 06:23:45 -0400112 volume_device_name, __ = self._attach_and_get_volume_device_name(
Rajat Dhasmanad9e59252021-05-11 16:03:47 -0400113 server, volume_snap_2, instance_ip, self.keypair['private_key'])
114 count_snap_2, md5_file_2 = self.get_md5_from_file(
115 server, instance_ip, 'file2', dev_name=volume_device_name)
116 # Detach the volume
117 self.nova_volume_detach(server, volume_snap_2)
Rajat Dhasmana21d63a32020-01-14 17:41:22 +0000118
119 self.assertEqual(count_snap_2, 2)
120 self.assertEqual(file2_md5, md5_file_2)
121
Rajat Dhasmanad9e59252021-05-11 16:03:47 -0400122 # Create volume from snapshot, attach it to instance and check file
123 # and contents for snap3
124 volume_snap_3 = self.create_volume(snapshot_id=snapshot3['id'])
Rajat Dhasmana638f2302021-05-12 06:23:45 -0400125 volume_device_name, __ = self._attach_and_get_volume_device_name(
Rajat Dhasmanad9e59252021-05-11 16:03:47 -0400126 server, volume_snap_3, instance_ip, self.keypair['private_key'])
127 count_snap_3, md5_file_3 = self.get_md5_from_file(
128 server, instance_ip, 'file3', dev_name=volume_device_name)
129 # Detach the volume
130 self.nova_volume_detach(server, volume_snap_3)
Rajat Dhasmana21d63a32020-01-14 17:41:22 +0000131
132 self.assertEqual(count_snap_3, 3)
133 self.assertEqual(file3_md5, md5_file_3)