Merge "Fix podman client creation with IPv6 control planes"

This commit is contained in:
Zuul 2023-11-23 09:07:07 +00:00 committed by Gerrit Code Review
commit 8487bf0ba2
2 changed files with 19 additions and 7 deletions

View File

@ -153,27 +153,30 @@ class PodmanClientFixture(tobiko.SharedFixture):
'key_filename', []) 'key_filename', [])
key_file = key_files[0] if len(key_files) > 0 else None key_file = key_files[0] if len(key_files) > 0 else None
socket = podman_remote_socket socket = podman_remote_socket
podman_remote_socket_uri = f'unix:/tmp/podman.sock_{host}' # replace : with . in case of IPv6 addresses
podman_socket_file = (
f'/tmp/podman.sock_{host.replace(":", ".")}')
podman_remote_socket_uri = f'unix:{podman_socket_file}'
remote_uri = f'ssh://{username}@{host}{socket}' remote_uri = f'ssh://{username}@{host}{socket}'
if podman_version_3(): if podman_version_3():
# check if a ssh tunnel exists, if not create one # check if a ssh tunnel exists, if not create one
psall = str(subprocess.check_output(('ps', '-ef'))) psall = str(subprocess.check_output(('ps', '-ef')))
if f'ssh -L /tmp/podman.sock_{host}' not in psall: if f'ssh -L {podman_socket_file}' not in psall:
if os.path.exists(f"/tmp/podman.sock_{host}"): if os.path.exists(podman_socket_file):
subprocess.call( subprocess.call(
['rm', '-f', f'/tmp/podman.sock_{host}']) ['rm', '-f', podman_socket_file])
# start a background ssh tunnel with the remote host # start a background ssh tunnel with the remote host
command = [ command = [
'ssh', '-o', 'strictHostKeyChecking=no', '-L', 'ssh', '-o', 'strictHostKeyChecking=no', '-L',
f'/tmp/podman.sock_{host}:/run/podman/podman.sock', f'{podman_socket_file}:/run/podman/podman.sock',
'-l', username, host, '-N', '-f'] '-l', username, host, '-N', '-f']
if key_file: if key_file:
command += ['-i', key_file] command += ['-i', key_file]
subprocess.call(command) subprocess.call(command)
for _ in tobiko.retry(timeout=60., interval=1.): for _ in tobiko.retry(timeout=60., interval=1.):
if os.path.exists(f'/tmp/podman.sock_{host}'): if os.path.exists(podman_socket_file):
break break
client = podman.PodmanClient( client = podman.PodmanClient(
base_url=podman_remote_socket_uri) base_url=podman_remote_socket_uri)

View File

@ -286,7 +286,16 @@ def str_is_not_ip(check_str):
def ip_to_hostname(oc_ip): def ip_to_hostname(oc_ip):
return get_ip_to_nodes_dict()[oc_ip] ip_to_nodes_dict = get_ip_to_nodes_dict()
oc_ipv6 = oc_ip.replace(".", ":")
if netaddr.valid_ipv4(oc_ip) or netaddr.valid_ipv6(oc_ip):
return ip_to_nodes_dict[oc_ip]
elif netaddr.valid_ipv6(oc_ipv6):
LOG.debug("The provided string was a modified IPv6 address: %s",
oc_ip)
return ip_to_nodes_dict[oc_ipv6]
else:
tobiko.fail("wrong IP value provided %s" % oc_ip)
def actual_node_groups(groups): def actual_node_groups(groups):