Codebase list cinder-tempest-plugin / 027295a
Improvements in snapshot data integrity tests This patch addresses the comments in the snapshot data integrity tests[1]. [1] https://review.opendev.org/c/openstack/cinder-tempest-plugin/+/790899 Change-Id: Icef31c07cf2a4e8c822a288edfc4463d592668ff whoami-rajat 4 years ago
2 changed file(s) with 44 addition(s) and 64 deletion(s). Raw diff Collapse all Expand all
1212 # License for the specific language governing permissions and limitations
1313 # under the License.
1414
15 import contextlib
16
1517 from oslo_log import log
1618
1719 from tempest.common import waiters
5456 if item not in disks_list_before_attach][0]
5557 return volume_name
5658
57 def _get_file_md5(self, ip_address, filename, dev_name=None,
58 mount_path='/mnt', private_key=None, server=None):
59
60 ssh_client = self.get_remote_client(ip_address,
61 private_key=private_key,
62 server=server)
59 @contextlib.contextmanager
60 def mount_dev_path(self, ssh_client, dev_name, mount_path):
6361 if dev_name is not None:
6462 ssh_client.exec_command('sudo mount /dev/%s %s' % (dev_name,
6563 mount_path))
66
67 md5_sum = ssh_client.exec_command(
68 'sudo md5sum %s/%s|cut -c 1-32' % (mount_path, filename))
69 if dev_name is not None:
64 yield
7065 ssh_client.exec_command('sudo umount %s' % mount_path)
66 else:
67 yield
68
69 def _get_file_md5(self, ip_address, filename, dev_name=None,
70 mount_path='/mnt', private_key=None, server=None):
71
72 ssh_client = self.get_remote_client(ip_address,
73 private_key=private_key,
74 server=server)
75 with self.mount_dev_path(ssh_client, dev_name, mount_path):
76 md5_sum = ssh_client.exec_command(
77 'sudo md5sum %s/%s|cut -c 1-32' % (mount_path, filename))
7178 return md5_sum
7279
7380 def _count_files(self, ip_address, dev_name=None, mount_path='/mnt',
7582 ssh_client = self.get_remote_client(ip_address,
7683 private_key=private_key,
7784 server=server)
78 if dev_name is not None:
79 ssh_client.exec_command('sudo mount /dev/%s %s' % (dev_name,
80 mount_path))
81 count = ssh_client.exec_command('sudo ls -l %s | wc -l' % mount_path)
82 if dev_name is not None:
83 ssh_client.exec_command('sudo umount %s' % mount_path)
85 with self.mount_dev_path(ssh_client, dev_name, mount_path):
86 count = ssh_client.exec_command(
87 'sudo ls -l %s | wc -l' % mount_path)
8488 # We subtract 2 from the count since `wc -l` also includes the count
8589 # of new line character and while creating the filesystem, a
8690 # lost+found folder is also created
99103 private_key=private_key,
100104 server=server)
101105
102 if dev_name is not None:
103 ssh_client.exec_command('sudo mount /dev/%s %s' % (dev_name,
104 mount_path))
105 ssh_client.exec_command(
106 'sudo dd bs=1024 count=100 if=/dev/urandom of=/%s/%s' %
107 (mount_path, filename))
108 md5 = ssh_client.exec_command(
109 'sudo md5sum -b %s/%s|cut -c 1-32' % (mount_path, filename))
110 ssh_client.exec_command('sudo sync')
111 if dev_name is not None:
112 ssh_client.exec_command('sudo umount %s' % mount_path)
106 with self.mount_dev_path(ssh_client, dev_name, mount_path):
107 ssh_client.exec_command(
108 'sudo dd bs=1024 count=100 if=/dev/urandom of=/%s/%s' %
109 (mount_path, filename))
110 md5 = ssh_client.exec_command(
111 'sudo md5sum -b %s/%s|cut -c 1-32' % (mount_path, filename))
112 ssh_client.exec_command('sudo sync')
113113 return md5
114114
115115 def get_md5_from_file(self, instance, instance_ip, filename,
3535 1) Create an instance with ephemeral disk
3636 2) Create a volume, attach it to the instance and create a filesystem
3737 on it and mount it
38 3) Mount the volume, create a file and write data into it, Unmount it
38 3) Create a file and write data into it, Unmount it
3939 4) create snapshot
4040 5) repeat 3 and 4 two more times (simply creating 3 snapshots)
4141
9292 # Detach the volume
9393 self.nova_volume_detach(server, volume)
9494
95 # Create volume from snapshot, attach it to instance and check file
96 # and contents for snap1
97 volume_snap_1 = self.create_volume(snapshot_id=snapshot1['id'])
98 volume_device_name, __ = self._attach_and_get_volume_device_name(
99 server, volume_snap_1, instance_ip, self.keypair['private_key'])
100 count_snap_1, md5_file_1 = self.get_md5_from_file(
101 server, instance_ip, 'file1', dev_name=volume_device_name)
102 # Detach the volume
103 self.nova_volume_detach(server, volume_snap_1)
95 snap_map = {1: snapshot1, 2: snapshot2, 3: snapshot3}
96 file_map = {1: file1_md5, 2: file2_md5, 3: file3_md5}
10497
105 self.assertEqual(count_snap_1, 1)
106 self.assertEqual(file1_md5, md5_file_1)
98 # Loop over 3 times to check the data integrity of all 3 snapshots
99 for i in range(1, 4):
100 # Create volume from snapshot, attach it to instance and check file
101 # and contents for snap
102 volume_snap = self.create_volume(snapshot_id=snap_map[i]['id'])
103 volume_device_name, __ = self._attach_and_get_volume_device_name(
104 server, volume_snap, instance_ip, self.keypair['private_key'])
105 count_snap, md5_file = self.get_md5_from_file(
106 server, instance_ip, 'file' + str(i),
107 dev_name=volume_device_name)
108 # Detach the volume
109 self.nova_volume_detach(server, volume_snap)
107110
108 # Create volume from snapshot, attach it to instance and check file
109 # and contents for snap2
110 volume_snap_2 = self.create_volume(snapshot_id=snapshot2['id'])
111 volume_device_name, __ = self._attach_and_get_volume_device_name(
112 server, volume_snap_2, instance_ip, self.keypair['private_key'])
113 count_snap_2, md5_file_2 = self.get_md5_from_file(
114 server, instance_ip, 'file2', dev_name=volume_device_name)
115 # Detach the volume
116 self.nova_volume_detach(server, volume_snap_2)
117
118 self.assertEqual(count_snap_2, 2)
119 self.assertEqual(file2_md5, md5_file_2)
120
121 # Create volume from snapshot, attach it to instance and check file
122 # and contents for snap3
123 volume_snap_3 = self.create_volume(snapshot_id=snapshot3['id'])
124 volume_device_name, __ = self._attach_and_get_volume_device_name(
125 server, volume_snap_3, instance_ip, self.keypair['private_key'])
126 count_snap_3, md5_file_3 = self.get_md5_from_file(
127 server, instance_ip, 'file3', dev_name=volume_device_name)
128 # Detach the volume
129 self.nova_volume_detach(server, volume_snap_3)
130
131 self.assertEqual(count_snap_3, 3)
132 self.assertEqual(file3_md5, md5_file_3)
111 self.assertEqual(count_snap, i)
112 self.assertEqual(file_map[i], md5_file)