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
This commit is contained in:
parent
c1c17025c6
commit
11d863ac35
@ -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
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user