Merge "Refactor tempest scenarios tests"
diff --git a/tempest/common/utils/linux/remote_client.py b/tempest/common/utils/linux/remote_client.py
index 9308390..3bead88 100644
--- a/tempest/common/utils/linux/remote_client.py
+++ b/tempest/common/utils/linux/remote_client.py
@@ -171,3 +171,14 @@
if dhcp_client == 'udhcpc' and not fixed_ip:
raise ValueError("need to set 'fixed_ip' for udhcpc client")
return getattr(self, '_renew_lease_' + dhcp_client)(fixed_ip=fixed_ip)
+
+ def mount(self, dev_name, mount_path='/mnt'):
+ cmd_mount = 'sudo mount /dev/%s %s' % (dev_name, mount_path)
+ self.exec_command(cmd_mount)
+
+ def umount(self, mount_path='/mnt'):
+ self.exec_command('sudo umount %s' % mount_path)
+
+ def make_fs(self, dev_name, fs='ext4'):
+ cmd_mkfs = 'sudo /usr/sbin/mke2fs -t %s /dev/%s' % (fs, dev_name)
+ self.exec_command(cmd_mkfs)
diff --git a/tempest/scenario/manager.py b/tempest/scenario/manager.py
index 7ab3864..015cd2f 100644
--- a/tempest/scenario/manager.py
+++ b/tempest/scenario/manager.py
@@ -557,6 +557,29 @@
floating_ip['ip'], thing['id'])
return floating_ip
+ def create_timestamp(self, server_or_ip, dev_name=None, mount_path='/mnt'):
+ ssh_client = self.get_remote_client(server_or_ip)
+ if dev_name is not None:
+ ssh_client.make_fs(dev_name)
+ ssh_client.mount(dev_name)
+ cmd_timestamp = 'sudo sh -c "date > %s/timestamp; sync"' % mount_path
+ ssh_client.exec_command(cmd_timestamp)
+ timestamp = ssh_client.exec_command('sudo cat %s/timestamp'
+ % mount_path)
+ if dev_name is not None:
+ ssh_client.umount(mount_path)
+ return timestamp
+
+ def get_timestamp(self, server_or_ip, dev_name=None, mount_path='/mnt'):
+ ssh_client = self.get_remote_client(server_or_ip)
+ if dev_name is not None:
+ ssh_client.mount(dev_name)
+ timestamp = ssh_client.exec_command('sudo cat %s/timestamp'
+ % mount_path)
+ if dev_name is not None:
+ ssh_client.umount(mount_path)
+ return timestamp
+
class NetworkScenarioTest(ScenarioTest):
"""Base class for network scenario tests.
diff --git a/tempest/scenario/test_shelve_instance.py b/tempest/scenario/test_shelve_instance.py
index bf4b8e7..dbc9bbb 100644
--- a/tempest/scenario/test_shelve_instance.py
+++ b/tempest/scenario/test_shelve_instance.py
@@ -37,16 +37,6 @@
"""
- def _write_timestamp(self, server_or_ip):
- ssh_client = self.get_remote_client(server_or_ip)
- ssh_client.exec_command('date > /tmp/timestamp; sync')
- self.timestamp = ssh_client.exec_command('cat /tmp/timestamp')
-
- def _check_timestamp(self, server_or_ip):
- ssh_client = self.get_remote_client(server_or_ip)
- got_timestamp = ssh_client.exec_command('cat /tmp/timestamp')
- self.assertEqual(self.timestamp, got_timestamp)
-
def _shelve_then_unshelve_server(self, server):
self.servers_client.shelve_server(server['id'])
offload_time = CONF.compute.shelved_offload_time
@@ -96,18 +86,19 @@
floating_ip['id'])
self.floating_ips_client.associate_floating_ip_to_server(
floating_ip['ip'], server['id'])
- self._write_timestamp(floating_ip['ip'])
+ timestamp = self.create_timestamp(floating_ip['ip'])
else:
- self._write_timestamp(server)
+ timestamp = self.create_timestamp(server)
# Prevent bug #1257594 from coming back
# Unshelve used to boot the instance with the original image, not
# with the instance snapshot
self._shelve_then_unshelve_server(server)
if CONF.compute.use_floatingip_for_ssh:
- self._check_timestamp(floating_ip['ip'])
+ timestamp2 = self.get_timestamp(floating_ip['ip'])
else:
- self._check_timestamp(server)
+ timestamp2 = self.get_timestamp(server)
+ self.assertEqual(timestamp, timestamp2)
@test.idempotent_id('1164e700-0af0-4a4c-8792-35909a88743c')
@testtools.skipUnless(CONF.compute_feature_enabled.shelve,
diff --git a/tempest/scenario/test_snapshot_pattern.py b/tempest/scenario/test_snapshot_pattern.py
index b5e5da8..79b809f 100644
--- a/tempest/scenario/test_snapshot_pattern.py
+++ b/tempest/scenario/test_snapshot_pattern.py
@@ -47,16 +47,6 @@
def _add_keypair(self):
self.keypair = self.create_keypair()
- def _write_timestamp(self, server_or_ip):
- ssh_client = self.get_remote_client(server_or_ip)
- ssh_client.exec_command('date > /tmp/timestamp; sync')
- self.timestamp = ssh_client.exec_command('cat /tmp/timestamp')
-
- def _check_timestamp(self, server_or_ip):
- ssh_client = self.get_remote_client(server_or_ip)
- got_timestamp = ssh_client.exec_command('cat /tmp/timestamp')
- self.assertEqual(self.timestamp, got_timestamp)
-
@test.idempotent_id('608e604b-1d63-4a82-8e3e-91bc665c90b4')
@testtools.skipUnless(CONF.compute_feature_enabled.snapshot,
'Snapshotting is not available.')
@@ -70,9 +60,9 @@
server = self._boot_image(CONF.compute.image_ref)
if CONF.compute.use_floatingip_for_ssh:
fip_for_server = self.create_floating_ip(server)
- self._write_timestamp(fip_for_server['ip'])
+ timestamp = self.create_timestamp(fip_for_server['ip'])
else:
- self._write_timestamp(server)
+ timestamp = self.create_timestamp(server)
# snapshot the instance
snapshot_image = self.create_server_snapshot(server=server)
@@ -83,6 +73,7 @@
# check the existence of the timestamp file in the second instance
if CONF.compute.use_floatingip_for_ssh:
fip_for_snapshot = self.create_floating_ip(server_from_snapshot)
- self._check_timestamp(fip_for_snapshot['ip'])
+ timestamp2 = self.get_timestamp(fip_for_snapshot['ip'])
else:
- self._check_timestamp(server_from_snapshot)
+ timestamp2 = self.get_timestamp(server_from_snapshot)
+ self.assertEqual(timestamp, timestamp2)
diff --git a/tempest/scenario/test_stamp_pattern.py b/tempest/scenario/test_stamp_pattern.py
index 91e4657..b9d5fcc 100644
--- a/tempest/scenario/test_stamp_pattern.py
+++ b/tempest/scenario/test_stamp_pattern.py
@@ -127,23 +127,6 @@
CONF.compute.build_interval):
raise exceptions.TimeoutException
- def _create_timestamp(self, server_or_ip):
- ssh_client = self._ssh_to_server(server_or_ip)
- ssh_client.exec_command('sudo /usr/sbin/mkfs.ext4 /dev/%s'
- % CONF.compute.volume_device_name)
- ssh_client.exec_command('sudo mount /dev/%s /mnt'
- % CONF.compute.volume_device_name)
- ssh_client.exec_command('sudo sh -c "date > /mnt/timestamp;sync"')
- self.timestamp = ssh_client.exec_command('sudo cat /mnt/timestamp')
- ssh_client.exec_command('sudo umount /mnt')
-
- def _check_timestamp(self, server_or_ip):
- ssh_client = self._ssh_to_server(server_or_ip)
- ssh_client.exec_command('sudo mount /dev/%s /mnt'
- % CONF.compute.volume_device_name)
- got_timestamp = ssh_client.exec_command('sudo cat /mnt/timestamp')
- self.assertEqual(self.timestamp, got_timestamp)
-
@decorators.skip_because(bug="1205344")
@test.idempotent_id('10fd234a-515c-41e5-b092-8323060598c5')
@testtools.skipUnless(CONF.compute_feature_enabled.snapshot,
@@ -167,7 +150,8 @@
self._attach_volume(server, volume)
self._wait_for_volume_available_on_the_system(ip_for_server)
- self._create_timestamp(ip_for_server)
+ timestamp = self.create_timestamp(ip_for_server,
+ CONF.compute.volume_device_name)
self._detach_volume(server, volume)
# snapshot the volume
@@ -196,4 +180,6 @@
self._wait_for_volume_available_on_the_system(ip_for_snapshot)
# check the existence of the timestamp file in the volume2
- self._check_timestamp(ip_for_snapshot)
+ timestamp2 = self.get_timestamp(ip_for_snapshot,
+ CONF.compute.volume_device_name)
+ self.assertEqual(timestamp, timestamp2)