Migrate test_snapshot_pattern to tempest client
Migrate the test and along with it migrate all the shared
functions used by the tests from OfficialClienTest to
ScenarioTest,create_server_snapshot()
Change-Id: I4d95cd02fcbbb62bb1631a38ee5d2c7e7d8f8d63
diff --git a/tempest/scenario/manager.py b/tempest/scenario/manager.py
index 5331b04..bc8872d 100644
--- a/tempest/scenario/manager.py
+++ b/tempest/scenario/manager.py
@@ -79,6 +79,8 @@
cls.floating_ips_client = cls.manager.floating_ips_client
# Glance image client v1
cls.image_client = cls.manager.image_client
+ # Compute image client
+ cls.images_client = cls.manager.images_client
cls.keypairs_client = cls.manager.keypairs_client
cls.networks_client = cls.admin_manager.networks_client
# Nova security groups client
@@ -387,6 +389,29 @@
LOG.debug(self.servers_client.get_console_output(server['id'],
length=None))
+ def create_server_snapshot(self, server, name=None):
+ # Glance client
+ _image_client = self.image_client
+ # Compute client
+ _images_client = self.images_client
+ if name is None:
+ name = data_utils.rand_name('scenario-snapshot-')
+ LOG.debug("Creating a snapshot image for server: %s", server['name'])
+ resp, image = _images_client.create_image(server['id'], name)
+ image_id = resp['location'].split('images/')[1]
+ _image_client.wait_for_image_status(image_id, 'active')
+ self.addCleanup_with_wait(
+ waiter_callable=_image_client.wait_for_resource_deletion,
+ thing_id=image_id, thing_id_param='id',
+ cleanup_callable=self.delete_wrapper,
+ cleanup_args=[_image_client.delete_image, image_id])
+ _, snapshot_image = _image_client.get_image_meta(image_id)
+ image_name = snapshot_image['name']
+ self.assertEqual(name, image_name)
+ LOG.debug("Created snapshot image %s for server %s",
+ image_name, server['name'])
+ return snapshot_image
+
class OfficialClientTest(tempest.test.BaseTestCase):
"""
diff --git a/tempest/scenario/test_snapshot_pattern.py b/tempest/scenario/test_snapshot_pattern.py
index ffdd006..d500065 100644
--- a/tempest/scenario/test_snapshot_pattern.py
+++ b/tempest/scenario/test_snapshot_pattern.py
@@ -25,7 +25,7 @@
LOG = log.getLogger(__name__)
-class TestSnapshotPattern(manager.OfficialClientTest):
+class TestSnapshotPattern(manager.ScenarioTest):
"""
This test is for snapshotting an instance and booting with it.
The following is the scenario outline:
@@ -37,9 +37,9 @@
"""
def _boot_image(self, image_id):
- security_groups = [self.security_group.name]
+ security_groups = [self.security_group]
create_kwargs = {
- 'key_name': self.keypair.name,
+ 'key_name': self.keypair['name'],
'security_groups': security_groups
}
return self.create_server(image=image_id, create_kwargs=create_kwargs)
@@ -66,12 +66,15 @@
self.assertEqual(self.timestamp, got_timestamp)
def _create_floating_ip(self):
- floating_ip = self.compute_client.floating_ips.create()
- self.addCleanup(self.delete_wrapper, floating_ip)
+ _, floating_ip = self.floating_ips_client.create_floating_ip()
+ self.addCleanup(self.delete_wrapper,
+ self.floating_ips_client.delete_floating_ip,
+ floating_ip['id'])
return floating_ip
def _set_floating_ip_to_server(self, server, floating_ip):
- server.add_floating_ip(floating_ip)
+ self.floating_ips_client.associate_floating_ip_to_server(
+ floating_ip['ip'], server['id'])
@testtools.skipUnless(CONF.compute_feature_enabled.snapshot,
'Snapshotting is not available.')
@@ -86,7 +89,7 @@
if CONF.compute.use_floatingip_for_ssh:
fip_for_server = self._create_floating_ip()
self._set_floating_ip_to_server(server, fip_for_server)
- self._write_timestamp(fip_for_server.ip)
+ self._write_timestamp(fip_for_server['ip'])
else:
self._write_timestamp(server)
@@ -94,13 +97,13 @@
snapshot_image = self.create_server_snapshot(server=server)
# boot a second instance from the snapshot
- server_from_snapshot = self._boot_image(snapshot_image.id)
+ server_from_snapshot = self._boot_image(snapshot_image['id'])
# 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()
self._set_floating_ip_to_server(server_from_snapshot,
fip_for_snapshot)
- self._check_timestamp(fip_for_snapshot.ip)
+ self._check_timestamp(fip_for_snapshot['ip'])
else:
self._check_timestamp(server_from_snapshot)