From 11d863ac35e7dfa56e8d95a4979ee3d96bd7d3b9 Mon Sep 17 00:00:00 2001 From: Eduardo Olivares Date: Thu, 18 Jul 2024 12:01:36 +0200 Subject: [PATCH] Find OCP nodes based on hostname instead of list of CIDRs For some reason, the list of CIDRs from an OCP node sometimes does not include some of its IP addresses. The method `get_ocp_main_ip` will use the hostname in order to identify OCP nodes instead. Change-Id: Ie3e4460d9d338aed21f62b4b17471aef26bebd4a --- .../tests/scenario/base.py | 23 +++++++++---------- 1 file changed, 11 insertions(+), 12 deletions(-) diff --git a/whitebox_neutron_tempest_plugin/tests/scenario/base.py b/whitebox_neutron_tempest_plugin/tests/scenario/base.py index 8b79b75..728459a 100644 --- a/whitebox_neutron_tempest_plugin/tests/scenario/base.py +++ b/whitebox_neutron_tempest_plugin/tests/scenario/base.py @@ -19,7 +19,6 @@ from multiprocessing import Process import os import random import re -import socket import time import yaml @@ -210,18 +209,18 @@ class BaseTempestWhiteboxTestCase(base.BaseTempestTestCase): def get_ocp_main_ip(host): LOG.debug('Searching for OCP node main IP corresponding to %s', host) - ocp_ip = socket.gethostbyname(host) for ocp_node_yaml in ocp_node_yaml_list: - # eval is needed here to convert a string into a list - for cidr in eval(ocp_node_yaml[ - 'metadata']['annotations']['k8s.ovn.org/host-cidrs']): - if ocp_ip == cidr.split('/')[0]: - for address in ocp_node_yaml['status']['addresses']: - if address['type'] == 'InternalIP': - ocp_main_ip = address['address'] - LOG.debug('IP address found for %s: %s', - host, ocp_main_ip) - return ocp_main_ip + ocp_main_ip = None + ocp_hostname = None + for address in ocp_node_yaml['status']['addresses']: + if address['type'] == 'InternalIP': + ocp_main_ip = address['address'] + if address['type'] == 'Hostname': + ocp_hostname = address['address'] + if ocp_main_ip and ocp_hostname == host.split('.')[0]: + LOG.debug('IP address found for %s: %s', host, ocp_main_ip) + return ocp_main_ip + LOG.warning('No IP address found for %s', host) return host