Obtain OCP node main IPs

In case of podified setups without CRC, instead of using the IPs
for the OCP nodes from the inventory, their IPs should be obtained with
the command `oc get node/<nodename> -o yaml` from the status.addresses
field.

Change-Id: I9d5e614274adda61d57a177d8d9243993305564c
This commit is contained in:
Eduardo Olivares 2024-07-08 18:20:00 +02:00
parent 8807beed60
commit 30af407669

View File

@ -19,6 +19,7 @@ from multiprocessing import Process
import os
import random
import re
import socket
import time
import yaml
@ -204,6 +205,24 @@ class BaseTempestWhiteboxTestCase(base.BaseTempestTestCase):
@classmethod
def get_podified_nodes_data(cls):
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
LOG.warning('No IP address found for %s', host)
return host
def append_node_data(node, is_crc):
if 'controller' in node:
return
@ -216,10 +235,12 @@ class BaseTempestWhiteboxTestCase(base.BaseTempestTestCase):
hosts_data[node][key].replace(
'~', '/home/{}'.format(WB_CONF.proxy_host_user)))
node_key = hosts_data[node][key].split('/')[-1]
node_ip = get_ocp_main_ip(hosts_data[node]['ansible_host'])
else:
node_key = 'id_cifw_key'
node_ip = hosts_data[node]['ansible_host']
node_data = {
'ip': hosts_data[node]['ansible_host'],
'ip': node_ip,
'user': hosts_data[node]['ansible_user'],
'key': node_key}
nodes.append(node_data)
@ -232,6 +253,16 @@ class BaseTempestWhiteboxTestCase(base.BaseTempestTestCase):
ocps = inventory_data['all']['children']['ocps']
if 'hosts' in ocps and 'crc' in ocps['hosts'].keys():
is_crc = True
else:
# create ocp_node_yaml_list
ocp_node_list = cls.proxy_host_client.exec_command(
"{} get nodes -o name".format(cls.OC)).splitlines()
ocp_node_yaml_list = []
for ocp_node in ocp_node_list:
output = cls.proxy_host_client.exec_command(
"{} get {} -o yaml".format(cls.OC, ocp_node))
ocp_node_yaml_list.append(yaml.safe_load(output))
LOG.debug("Environment is{} based on CRC".format(
"" if is_crc else "n't"))
items = inventory_data['all']['children']