Rajat Dhasmana | 21d63a3 | 2020-01-14 17:41:22 +0000 | [diff] [blame] | 1 | # 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 Dhasmana | 21d63a3 | 2020-01-14 17:41:22 +0000 | [diff] [blame] | 16 | from tempest.common import utils |
| 17 | from tempest.lib import decorators |
| 18 | |
Luigi Toscano | 3c5c8a2 | 2021-02-23 10:24:01 +0100 | [diff] [blame] | 19 | from cinder_tempest_plugin.scenario import manager |
| 20 | |
Rajat Dhasmana | 21d63a3 | 2020-01-14 17:41:22 +0000 | [diff] [blame] | 21 | |
| 22 | class SnapshotDataIntegrityTests(manager.ScenarioTest): |
| 23 | |
| 24 | def setUp(self): |
| 25 | super(SnapshotDataIntegrityTests, self).setUp() |
| 26 | self.keypair = self.create_keypair() |
Rajat Dhasmana | 638f230 | 2021-05-12 06:23:45 -0400 | [diff] [blame] | 27 | self.security_group = self.create_security_group() |
Rajat Dhasmana | d9e5925 | 2021-05-11 16:03:47 -0400 | [diff] [blame] | 28 | |
Rajat Dhasmana | 21d63a3 | 2020-01-14 17:41:22 +0000 | [diff] [blame] | 29 | @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 Dhasmana | d9e5925 | 2021-05-11 16:03:47 -0400 | [diff] [blame] | 36 | 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-rajat | 027295a | 2021-12-12 12:31:59 -0500 | [diff] [blame] | 39 | 3) Create a file and write data into it, Unmount it |
Rajat Dhasmana | 21d63a3 | 2020-01-14 17:41:22 +0000 | [diff] [blame] | 40 | 4) create snapshot |
| 41 | 5) repeat 3 and 4 two more times (simply creating 3 snapshots) |
| 42 | |
Rajat Dhasmana | d9e5925 | 2021-05-11 16:03:47 -0400 | [diff] [blame] | 43 | 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 Dhasmana | 21d63a3 | 2020-01-14 17:41:22 +0000 | [diff] [blame] | 45 | point when snapshot was created. |
| 46 | """ |
| 47 | |
Rajat Dhasmana | d9e5925 | 2021-05-11 16:03:47 -0400 | [diff] [blame] | 48 | # Create an instance |
| 49 | server = self.create_server( |
| 50 | key_name=self.keypair['name'], |
| 51 | security_groups=[{'name': self.security_group['name']}]) |
Rajat Dhasmana | 21d63a3 | 2020-01-14 17:41:22 +0000 | [diff] [blame] | 52 | |
Rajat Dhasmana | d9e5925 | 2021-05-11 16:03:47 -0400 | [diff] [blame] | 53 | # Create an empty volume |
| 54 | volume = self.create_volume() |
Rajat Dhasmana | 21d63a3 | 2020-01-14 17:41:22 +0000 | [diff] [blame] | 55 | |
| 56 | instance_ip = self.get_server_ip(server) |
| 57 | |
Rajat Dhasmana | d9e5925 | 2021-05-11 16:03:47 -0400 | [diff] [blame] | 58 | # Attach volume to instance and find it's device name (eg: /dev/vdb) |
Rajat Dhasmana | 638f230 | 2021-05-12 06:23:45 -0400 | [diff] [blame] | 59 | volume_device_name, __ = self._attach_and_get_volume_device_name( |
Rajat Dhasmana | d9e5925 | 2021-05-11 16:03:47 -0400 | [diff] [blame] | 60 | 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 Dhasmana | 21d63a3 | 2020-01-14 17:41:22 +0000 | [diff] [blame] | 66 | # Write data to volume |
| 67 | file1_md5 = self.create_md5_new_file( |
Rajat Dhasmana | d9e5925 | 2021-05-11 16:03:47 -0400 | [diff] [blame] | 68 | instance_ip, dev_name=volume_device_name, filename="file1", |
Rajat Dhasmana | 21d63a3 | 2020-01-14 17:41:22 +0000 | [diff] [blame] | 69 | 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 Dhasmana | d9e5925 | 2021-05-11 16:03:47 -0400 | [diff] [blame] | 77 | instance_ip, dev_name=volume_device_name, filename="file2", |
Rajat Dhasmana | 21d63a3 | 2020-01-14 17:41:22 +0000 | [diff] [blame] | 78 | 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 Dhasmana | d9e5925 | 2021-05-11 16:03:47 -0400 | [diff] [blame] | 86 | instance_ip, dev_name=volume_device_name, filename="file3", |
Rajat Dhasmana | 21d63a3 | 2020-01-14 17:41:22 +0000 | [diff] [blame] | 87 | 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 Dhasmana | d9e5925 | 2021-05-11 16:03:47 -0400 | [diff] [blame] | 93 | # Detach the volume |
| 94 | self.nova_volume_detach(server, volume) |
| 95 | |
whoami-rajat | 027295a | 2021-12-12 12:31:59 -0500 | [diff] [blame] | 96 | snap_map = {1: snapshot1, 2: snapshot2, 3: snapshot3} |
| 97 | file_map = {1: file1_md5, 2: file2_md5, 3: file3_md5} |
Rajat Dhasmana | 21d63a3 | 2020-01-14 17:41:22 +0000 | [diff] [blame] | 98 | |
whoami-rajat | 027295a | 2021-12-12 12:31:59 -0500 | [diff] [blame] | 99 | # 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 Dhasmana | 21d63a3 | 2020-01-14 17:41:22 +0000 | [diff] [blame] | 111 | |
whoami-rajat | 027295a | 2021-12-12 12:31:59 -0500 | [diff] [blame] | 112 | self.assertEqual(count_snap, i) |
| 113 | self.assertEqual(file_map[i], md5_file) |