Move get_server_or_ip method to common class
Moved to common class duplicate part of code for "get server or IP"
which used in few scenario tests.
Change-Id: I6368c24764e2515dc8bbcd82d1b0623c24bc77cd
diff --git a/tempest/scenario/manager.py b/tempest/scenario/manager.py
index 6548d28..ad18b48 100644
--- a/tempest/scenario/manager.py
+++ b/tempest/scenario/manager.py
@@ -601,6 +601,13 @@
ssh_client.umount(mount_path)
return timestamp
+ def get_server_or_ip(self, server):
+ if CONF.validation.connect_method == 'floating':
+ ip = self.create_floating_ip(server)['ip']
+ else:
+ ip = server
+ return ip
+
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 3b38888..0e366e9 100644
--- a/tempest/scenario/test_shelve_instance.py
+++ b/tempest/scenario/test_shelve_instance.py
@@ -78,24 +78,17 @@
server = self.create_server(image=CONF.compute.image_ref,
create_kwargs=create_kwargs)
- if CONF.compute.use_floatingip_for_ssh:
- floating_ip = self.create_floating_ip(server)['ip']
- timestamp = self.create_timestamp(
- floating_ip, private_key=keypair['private_key'])
- else:
- timestamp = self.create_timestamp(
- server, private_key=keypair['private_key'])
+ instance_ip = self.get_server_or_ip(server)
+ timestamp = self.create_timestamp(instance_ip,
+ private_key=keypair['private_key'])
# 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:
- timestamp2 = self.get_timestamp(floating_ip,
- private_key=keypair['private_key'])
- else:
- timestamp2 = self.get_timestamp(server,
- private_key=keypair['private_key'])
+
+ timestamp2 = self.get_timestamp(instance_ip,
+ private_key=keypair['private_key'])
self.assertEqual(timestamp, timestamp2)
@test.idempotent_id('1164e700-0af0-4a4c-8792-35909a88743c')
diff --git a/tempest/scenario/test_snapshot_pattern.py b/tempest/scenario/test_snapshot_pattern.py
index 5ac3a7e..e645c36 100644
--- a/tempest/scenario/test_snapshot_pattern.py
+++ b/tempest/scenario/test_snapshot_pattern.py
@@ -56,13 +56,9 @@
# boot an instance and create a timestamp file in it
server = self._boot_image(CONF.compute.image_ref, keypair,
security_group)
- if CONF.compute.use_floatingip_for_ssh:
- fip_for_server = self.create_floating_ip(server)
- timestamp = self.create_timestamp(
- fip_for_server['ip'], private_key=keypair['private_key'])
- else:
- timestamp = self.create_timestamp(
- server, private_key=keypair['private_key'])
+ instance_ip = self.get_server_or_ip(server)
+ timestamp = self.create_timestamp(instance_ip,
+ private_key=keypair['private_key'])
# snapshot the instance
snapshot_image = self.create_server_snapshot(server=server)
@@ -72,11 +68,7 @@
keypair, security_group)
# 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)
- timestamp2 = self.get_timestamp(fip_for_snapshot['ip'],
- private_key=keypair['private_key'])
- else:
- timestamp2 = self.get_timestamp(server_from_snapshot,
- private_key=keypair['private_key'])
+ server_from_snapshot_ip = self.get_server_or_ip(server_from_snapshot)
+ timestamp2 = self.get_timestamp(server_from_snapshot_ip,
+ private_key=keypair['private_key'])
self.assertEqual(timestamp, timestamp2)
diff --git a/tempest/scenario/test_stamp_pattern.py b/tempest/scenario/test_stamp_pattern.py
index 6eceeb2..e23dbea 100644
--- a/tempest/scenario/test_stamp_pattern.py
+++ b/tempest/scenario/test_stamp_pattern.py
@@ -138,11 +138,7 @@
security_group)
# create and add floating IP to server1
- if CONF.compute.use_floatingip_for_ssh:
- floating_ip_for_server = self.create_floating_ip(server)
- ip_for_server = floating_ip_for_server['ip']
- else:
- ip_for_server = server
+ ip_for_server = self.get_server_or_ip(server)
self._attach_volume(server, volume)
self._wait_for_volume_available_on_the_system(ip_for_server,
@@ -167,12 +163,7 @@
keypair, security_group)
# create and add floating IP to server_from_snapshot
- if CONF.compute.use_floatingip_for_ssh:
- floating_ip_for_snapshot = self.create_floating_ip(
- server_from_snapshot)
- ip_for_snapshot = floating_ip_for_snapshot['ip']
- else:
- ip_for_snapshot = server_from_snapshot
+ ip_for_snapshot = self.get_server_or_ip(server_from_snapshot)
# attach volume2 to instance2
self._attach_volume(server_from_snapshot, volume_from_snapshot)
diff --git a/tempest/scenario/test_volume_boot_pattern.py b/tempest/scenario/test_volume_boot_pattern.py
index 414305d..cc85d60 100644
--- a/tempest/scenario/test_volume_boot_pattern.py
+++ b/tempest/scenario/test_volume_boot_pattern.py
@@ -95,13 +95,6 @@
vol_name = data_utils.rand_name('volume')
return self.create_volume(name=vol_name, snapshot_id=snap_id)
- def _get_server_ip(self, server):
- if CONF.compute.use_floatingip_for_ssh:
- ip = self.create_floating_ip(server)['ip']
- else:
- ip = server
- return ip
-
def _delete_server(self, server):
self.servers_client.delete_server(server['id'])
waiters.wait_for_server_termination(self.servers_client, server['id'])
@@ -119,7 +112,7 @@
keypair, security_group)
# write content to volume on instance
- ip_instance_1st = self._get_server_ip(instance_1st)
+ ip_instance_1st = self.get_server_or_ip(instance_1st)
timestamp = self.create_timestamp(ip_instance_1st,
private_key=keypair['private_key'])
@@ -131,7 +124,7 @@
keypair, security_group)
# check the content of written file
- ip_instance_2nd = self._get_server_ip(instance_2nd)
+ ip_instance_2nd = self.get_server_or_ip(instance_2nd)
timestamp2 = self.get_timestamp(ip_instance_2nd,
private_key=keypair['private_key'])
self.assertEqual(timestamp, timestamp2)
@@ -141,13 +134,13 @@
# create a 3rd instance from snapshot
volume = self._create_volume_from_snapshot(snapshot['id'])
- instance_from_snapshot = (
+ server_from_snapshot = (
self._boot_instance_from_volume(volume['id'],
keypair, security_group))
# check the content of written file
- ip_instance_from_snapshot = self._get_server_ip(instance_from_snapshot)
- timestamp3 = self.get_timestamp(ip_instance_from_snapshot,
+ server_from_snapshot_ip = self.get_server_or_ip(server_from_snapshot)
+ timestamp3 = self.get_timestamp(server_from_snapshot_ip,
private_key=keypair['private_key'])
self.assertEqual(timestamp, timestamp3)