Move get_server_ip into tempest.common.compute
This will be required by the new wait_until={PINGABLE|SSHABLE} logic
within the module so move this down from
tempest.api.compute.base.BaseV2ComputeTest.
A version of this is also present in tempest.scenario.manager however
unifying that with this version is left for another change.
Change-Id: Iddfdf48da58320844e265fb1209e25a53d501f93
diff --git a/tempest/api/compute/base.py b/tempest/api/compute/base.py
index ed50282..a110eb4 100644
--- a/tempest/api/compute/base.py
+++ b/tempest/api/compute/base.py
@@ -487,21 +487,8 @@
:param validation_resources: The dict of validation resources
provisioned for the server.
"""
- if CONF.validation.connect_method == 'floating':
- if validation_resources:
- return validation_resources['floating_ip']['ip']
- else:
- msg = ('When validation.connect_method equals floating, '
- 'validation_resources cannot be None')
- raise lib_exc.InvalidParam(invalid_param=msg)
- elif CONF.validation.connect_method == 'fixed':
- addresses = server['addresses'][CONF.validation.network_for_ssh]
- for address in addresses:
- if address['version'] == CONF.validation.ip_version_for_ssh:
- return address['addr']
- raise exceptions.ServerUnreachable(server_id=server['id'])
- else:
- raise lib_exc.InvalidConfiguration()
+ return compute.get_server_ip(
+ server, validation_resources=validation_resources)
@classmethod
def create_volume(cls, image_ref=None, **kwargs):
diff --git a/tempest/common/compute.py b/tempest/common/compute.py
index 04b67e4..1e59e17 100644
--- a/tempest/common/compute.py
+++ b/tempest/common/compute.py
@@ -25,9 +25,11 @@
from tempest.common import waiters
from tempest import config
+from tempest import exceptions
from tempest.lib.common import fixed_network
from tempest.lib.common import rest_client
from tempest.lib.common.utils import data_utils
+from tempest.lib import exceptions as lib_exc
CONF = config.CONF
@@ -54,6 +56,33 @@
return False
+def get_server_ip(server, validation_resources=None):
+ """Get the server fixed or floating IP.
+
+ Based on the configuration we're in, return a correct ip
+ address for validating that a guest is up.
+
+ :param server: The server dict as returned by the API
+ :param validation_resources: The dict of validation resources
+ provisioned for the server.
+ """
+ if CONF.validation.connect_method == 'floating':
+ if validation_resources:
+ return validation_resources['floating_ip']['ip']
+ else:
+ msg = ('When validation.connect_method equals floating, '
+ 'validation_resources cannot be None')
+ raise lib_exc.InvalidParam(invalid_param=msg)
+ elif CONF.validation.connect_method == 'fixed':
+ addresses = server['addresses'][CONF.validation.network_for_ssh]
+ for address in addresses:
+ if address['version'] == CONF.validation.ip_version_for_ssh:
+ return address['addr']
+ raise exceptions.ServerUnreachable(server_id=server['id'])
+ else:
+ raise lib_exc.InvalidConfiguration()
+
+
def create_test_server(clients, validatable=False, validation_resources=None,
tenant_network=None, wait_until=None,
volume_backed=False, name=None, flavor=None,