Skip to content

Commit

Permalink
MGMT-3603 Changes for single node IPv6
Browse files Browse the repository at this point in the history
  • Loading branch information
ori-amizur committed Jan 18, 2021
1 parent 7209196 commit d9f185a
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 18 deletions.
23 changes: 15 additions & 8 deletions discovery-infra/start_discovery.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import os
import time
import distutils.util
from netaddr import IPNetwork
from netaddr import IPNetwork, IPAddress

from test_infra import assisted_service_api, consts, utils
from test_infra.helper_classes import cluster as helper_cluster
Expand Down Expand Up @@ -229,13 +229,13 @@ def set_cluster_vips(client, cluster_id, machine_net):
client.update_cluster(cluster_id, cluster_info)


def set_cluster_machine_cidr(client, cluster_id, machine_net):
def set_cluster_machine_cidr(client, cluster_id, machine_net, set_vip_dhcp_allocation=True):
cluster_info = client.cluster_get(cluster_id)
cluster_info.vip_dhcp_allocation = True
cluster_info.machine_network_cidr = machine_net.cidr_v4
if set_vip_dhcp_allocation:
cluster_info.vip_dhcp_allocation = True
cluster_info.machine_network_cidr = machine_net.cidr_v6 if machine_net.has_ip_v6 and not machine_net.has_ip_v4 else machine_net.cidr_v4
client.update_cluster(cluster_id, cluster_info)


def _get_vips_ips(machine_net):
if machine_net.has_ip_v4:
network_subnet_starting_ip = str(
Expand Down Expand Up @@ -288,7 +288,7 @@ def _cluster_create_params():
ipv4 = args.ipv4 and args.ipv4.lower() in MachineNetwork.YES_VALUES
ipv6 = args.ipv6 and args.ipv6.lower() in MachineNetwork.YES_VALUES
ntp_source = _get_host_ip_from_cidr(args.vm_network_cidr6 if ipv6 and not ipv4 else args.vm_network_cidr)
user_managed_networking = is_none_platform_mode()
user_managed_networking = is_user_managed_networking()
http_proxy, https_proxy, no_proxy = _get_http_proxy_params(ipv4=ipv4, ipv6=ipv6)
params = {
"openshift_version": utils.get_openshift_version(),
Expand Down Expand Up @@ -394,7 +394,7 @@ def nodes_flow(client, cluster_name, cluster):
cluster_info = client.cluster_get(cluster.id)
macs = utils.get_libvirt_nodes_macs(nodes_details["libvirt_network_name"])

if not (cluster_info.api_vip and cluster_info.ingress_vip) and args.master_count != 1:
if not (cluster_info.api_vip and cluster_info.ingress_vip):
utils.wait_till_hosts_with_macs_are_in_status(
client=client,
cluster_id=cluster.id,
Expand All @@ -406,7 +406,10 @@ def nodes_flow(client, cluster_name, cluster):
],
)

if args.vip_dhcp_allocation:
if args.master_count == 1 and machine_net.has_ip_v6 and not machine_net.has_ip_v4:
set_cluster_machine_cidr(client, cluster.id, machine_net, set_vip_dhcp_allocation=False)
tf.change_variables({"libvirt_master_ips": [[helper_cluster.Cluster.get_ip_for_single_node_v6(client, cluster.id)]]})
elif args.vip_dhcp_allocation:
set_cluster_machine_cidr(client, cluster.id, machine_net)
else:
set_cluster_vips(client, cluster.id, machine_net)
Expand Down Expand Up @@ -533,6 +536,10 @@ def execute_day1_flow(cluster_name):
return cluster.id


def is_user_managed_networking():
return is_none_platform_mode() or args.master_count == 1


def is_none_platform_mode():
return args.platform.lower() == consts.Platforms.NONE

Expand Down
24 changes: 18 additions & 6 deletions discovery-infra/test_infra/helper_classes/cluster.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
from typing import List
import requests
from collections import Counter
from netaddr import IPNetwork, IPAddress
from assisted_service_client import models

from tests.conftest import env_variables
Expand Down Expand Up @@ -657,20 +658,31 @@ def wait_for_event(self, event_to_find, reference_time, params_list=[], host_id=
raise

@staticmethod
def get_inventory_host_nics_data(host: dict):
def get_inventory_host_nics_data(host: dict, ipv4_first=True):

def get_network_interface_ip(interface):
if len(interface.ipv4_addresses) > 0:
return interface.ipv4_addresses[0].split("/")[0]
if len(interface.ipv6_addresses) > 0:
return interface.ipv6_addresses[0].split("/")[0]
return
addresses = interface.ipv4_addresses + interface.ipv6_addresses if ipv4_first else \
interface.ipv6_addresses + interface.ipv4_addresses
return addresses[0].split("/")[0] if len(addresses) > 0 else None

inventory = models.Inventory(**json.loads(host["inventory"]))
interfaces_list = [models.Interface(**interface) for interface in inventory.interfaces]
return [{'name': interface.name, 'model': interface.product, 'mac': interface.mac_address,
'ip': get_network_interface_ip(interface), 'speed': interface.speed_mbps} for interface in interfaces_list]

@staticmethod
def get_ip_for_single_node_v6(client, cluster_id):
cluster_info = client.cluster_get(cluster_id).to_dict()
if len(cluster_info["hosts"]) == 0:
raise Exception("No host found")
network = IPNetwork(args.vm_network_cidr6)
interfaces = Cluster.get_inventory_host_nics_data(cluster_info["hosts"][0], ipv4_first=False)
for intf in interfaces:
ip = intf["ip"]
if IPAddress(ip) in network:
return ip
raise Exception("IP for single node IPv6 not found")

def get_inventory_host_ips_data(self, host: dict):
nics = self.get_inventory_host_nics_data(host)
return [nic["ip"] for nic in nics]
Expand Down
8 changes: 4 additions & 4 deletions terraform_files/baremetal/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -161,25 +161,25 @@ resource "libvirt_domain" "worker" {
# the count directive to include/exclude elements

data "libvirt_network_dns_host_template" "api" {
count = 1
count = !var.bootstrap_in_place || length(var.libvirt_master_ips[0]) > 0 ? 1 : 0
ip = var.bootstrap_in_place ? var.libvirt_master_ips[count.index][0] : var.api_vip
hostname = "api.${var.cluster_name}.${var.cluster_domain}"
}

data "libvirt_network_dns_host_template" "api-int" {
count = var.bootstrap_in_place ? 1 : 0
count = var.bootstrap_in_place && length(var.libvirt_master_ips[0]) > 0 ? 1 : 0
ip = var.libvirt_master_ips[count.index][0]
hostname = "api-int.${var.cluster_name}.${var.cluster_domain}"
}

data "libvirt_network_dns_host_template" "oauth" {
count = var.bootstrap_in_place ? 1 : 0
count = var.bootstrap_in_place && length(var.libvirt_master_ips[0]) > 0 ? 1 : 0
ip = var.libvirt_master_ips[count.index][0]
hostname = "oauth-openshift.apps.${var.cluster_name}.${var.cluster_domain}"
}

data "libvirt_network_dns_host_template" "console" {
count = var.bootstrap_in_place ? 1 : 0
count = var.bootstrap_in_place && length(var.libvirt_master_ips[0]) > 0 ? 1 : 0
ip = var.libvirt_master_ips[count.index][0]
hostname = "console-openshift-console.apps.${var.cluster_name}.${var.cluster_domain}"
}

0 comments on commit d9f185a

Please sign in to comment.