コード例 #1
0
def set_hosts_roles(client, cluster, nodes_details, machine_net, tf,
                    master_count, static_network_mode):
    networks_names = (nodes_details["libvirt_network_name"],
                      nodes_details["libvirt_secondary_network_name"])

    # don't set roles in bip role
    if machine_net.has_ip_v4:
        libvirt_nodes = utils.get_libvirt_nodes_mac_role_ip_and_name(
            networks_names[0])
        libvirt_nodes.update(
            utils.get_libvirt_nodes_mac_role_ip_and_name(networks_names[1]))
        if static_network_mode:
            log.info(
                "Setting hostnames when running in static network config mode")
            update_hostnames = True
        else:
            update_hostnames = False
    else:
        log.warning(
            "Work around libvirt for Terrafrom not setting hostnames of IPv6-only hosts"
        )
        libvirt_nodes = utils.get_libvirt_nodes_from_tf_state(
            networks_names, tf.get_state())
        update_hostnames = True

    utils.update_hosts(client,
                       cluster.id,
                       libvirt_nodes,
                       update_hostnames=update_hostnames,
                       update_roles=master_count > 1)
コード例 #2
0
 def set_hostnames(self, cluster, nodes_count: int, is_ipv6: bool, is_static_ip: bool = False):
     if is_ipv6 or is_static_ip:
         # When using IPv6 with libvirt, hostnames are not set automatically by DHCP.  Therefore, we must find out
         # the hostnames using terraform's tfstate file. In case of static ip, the hostname is localhost and must be
         # set to valid hostname
         # TODO - NodeController has no `params` and `tf` attributes
         network_name = self.controller.params.libvirt_network_name
         libvirt_nodes = utils.get_libvirt_nodes_from_tf_state(network_name, self.controller.tf.get_state())
         utils.update_hosts(cluster.api_client, cluster.id, libvirt_nodes, update_hostnames=True,
                            update_roles=(nodes_count != 1))
コード例 #3
0
def get_nodes_details(cluster_name, namespace, tf):
    tf_folder = utils.get_tf_folder(cluster_name, namespace)
    tf_vars = utils.get_tfvars(tf_folder)
    networks_names = (
        tf_vars['libvirt_network_name'],
        tf_vars['libvirt_secondary_network_name'],
    )
    return utils.get_libvirt_nodes_from_tf_state(
        network_names=networks_names,
        tf_state=tf.get_state(),
    )
コード例 #4
0
ファイル: nodes.py プロジェクト: oshercc/assisted-test-infra
 def set_hostnames(self, cluster):
     ipv6 = env_variables.get('ipv6')
     if ipv6:
         # When using IPv6 with libvirt, hostnames are not set automatically by DHCP.  Therefore, we must find out
         # the hostnames using terraform's tfstate file
         network_name = self.controller.params.libvirt_network_name
         libvirt_nodes = utils.get_libvirt_nodes_from_tf_state(
             network_name, self.controller.tf.get_state())
         utils.update_hosts(cluster.api_client,
                            cluster.id,
                            libvirt_nodes,
                            update_hostnames=True)
コード例 #5
0
def get_nodes_details(cluster_name, namespace, tf):
    tf_folder = utils.get_tf_folder(cluster_name, namespace)
    baremetal_template = os.path.join(tf_folder, consts.Platforms.BARE_METAL)

    tf_vars = utils.get_tfvars(baremetal_template)
    networks_names = (
        tf_vars["libvirt_network_name"],
        tf_vars["libvirt_secondary_network_name"],
    )
    return utils.get_libvirt_nodes_from_tf_state(
        network_names=networks_names,
        tf_state=tf.get_state(),
    )
コード例 #6
0
ファイル: nodes.py プロジェクト: omertuc/assisted-test-infra
 def set_hostnames(self, cluster):
     ipv6 = env_variables.get('ipv6')
     static_ips_config = env_variables.get('static_ips_config')
     if ipv6 or static_ips_config:
         # When using IPv6 with libvirt, hostnames are not set automatically by DHCP.  Therefore, we must find out
         # the hostnames using terraform's tfstate file. In case of static ip, the hostname is localhost and must be set
         # to valid hostname
         network_name = self.controller.params.libvirt_network_name
         libvirt_nodes = utils.get_libvirt_nodes_from_tf_state(
             network_name, self.controller.tf.get_state())
         nodes_count = env_variables.get('num_nodes')
         utils.update_hosts(cluster.api_client,
                            cluster.id,
                            libvirt_nodes,
                            update_hostnames=True,
                            update_roles=(nodes_count != 1))
コード例 #7
0
def nodes_flow(client, cluster_name, cluster, image_path):
    nodes_details = _create_node_details(cluster_name)
    if cluster:
        nodes_details["cluster_inventory_id"] = cluster.id

    tf_folder = utils.get_tf_folder(cluster_name, args.namespace)
    utils.recreate_folder(tf_folder)

    utils.copy_template_tree(tf_folder, is_none_platform_mode())

    tf = terraform_utils.TerraformUtils(working_dir=tf_folder)
    machine_net = MachineNetwork(args.ipv4, args.ipv6, args.vm_network_cidr,
                                 args.vm_network_cidr6, args.ns_index)

    create_nodes_and_wait_till_registered(cluster_name=cluster_name,
                                          inventory_client=client,
                                          cluster=cluster,
                                          image_path=image_path,
                                          storage_path=args.storage_path,
                                          master_count=args.master_count,
                                          nodes_details=nodes_details,
                                          tf=tf,
                                          machine_net=machine_net)

    if client:
        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):
            utils.wait_till_hosts_with_macs_are_in_status(
                client=client,
                cluster_id=cluster.id,
                macs=macs,
                statuses=[
                    consts.NodesStatus.INSUFFICIENT,
                    consts.NodesStatus.PENDING_FOR_INPUT,
                ],
            )

            if args.vip_dhcp_allocation:
                set_cluster_machine_cidr(client, cluster.id, machine_net)
            else:
                set_cluster_vips(client, cluster.id, machine_net)
        else:
            log.info("VIPs already configured")

        networks_names = (nodes_details["libvirt_network_name"],
                          nodes_details["libvirt_secondary_network_name"])
        if machine_net.has_ip_v4:
            libvirt_nodes = utils.get_libvirt_nodes_mac_role_ip_and_name(
                networks_names[0])
            libvirt_nodes.update(
                utils.get_libvirt_nodes_mac_role_ip_and_name(
                    networks_names[1]))
            update_hostnames = False
        else:
            log.warning(
                "Work around libvirt for Terrafrom not setting hostnames of IPv6-only hosts"
            )
            libvirt_nodes = utils.get_libvirt_nodes_from_tf_state(
                networks_names, tf.get_state())
            update_hostnames = True

        utils.update_hosts(client, cluster.id, libvirt_nodes, update_hostnames)
        utils.wait_till_hosts_with_macs_are_in_status(
            client=client,
            cluster_id=cluster.id,
            macs=macs,
            statuses=[consts.NodesStatus.KNOWN],
        )

        if args.install_cluster:
            time.sleep(10)
            install_cluster.run_install_flow(
                client=client,
                cluster_id=cluster.id,
                kubeconfig_path=consts.DEFAULT_CLUSTER_KUBECONFIG_PATH,
                pull_secret=args.pull_secret,
                tf=tf)
            # Validate DNS domains resolvability
            validate_dns(client, cluster.id)
            if args.wait_for_cvo:
                cluster_info = client.cluster_get(cluster.id)
                log.info("Start waiting till CVO status is available")
                config_etc_hosts(cluster_info.name,
                                 cluster_info.base_dns_domain,
                                 cluster_info.api_vip)
                utils.wait_for_cvo_available()