From 20556df7ab807d39b1541b71555b44fac332f64d Mon Sep 17 00:00:00 2001 From: Lee Yarwood Date: Fri, 12 Nov 2021 09:38:18 +0000 Subject: [PATCH] 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 --- tempest/api/compute/base.py | 17 ++--------------- tempest/common/compute.py | 29 +++++++++++++++++++++++++++++ 2 files changed, 31 insertions(+), 15 deletions(-) diff --git a/tempest/api/compute/base.py b/tempest/api/compute/base.py index ed5028276c..a110eb4b44 100644 --- a/tempest/api/compute/base.py +++ b/tempest/api/compute/base.py @@ -487,21 +487,8 @@ class BaseV2ComputeTest(api_version_utils.BaseMicroversionTest, :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 04b67e46b5..1e59e172cc 100644 --- a/tempest/common/compute.py +++ b/tempest/common/compute.py @@ -25,9 +25,11 @@ from oslo_utils import excutils 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 @@ def is_scheduler_filter_enabled(filter_name): 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,