Example #1
0
def get_api_client(offline_token=env_variables['offline_token'], **kwargs):
    url = env_variables['remote_service_url']

    if not url:
        url = utils.get_local_assisted_service_url(
            utils.get_env('PROFILE'), utils.get_env('NAMESPACE'), 'assisted-service', utils.get_env('DEPLOY_TARGET'))
    
    return assisted_service_api.create_client(url, offline_token, **kwargs)
def api_client():
    url = env_variables['remote_service_url']

    if not url:
        url = utils.get_local_assisted_service_url(
            utils.get_env('PROFILE'), utils.get_env('NAMESPACE'),
            'assisted-service', utils.get_env('DEPLOY_TARGET'))

    yield assisted_service_api.create_client(url)
Example #3
0
def execute_day2_flow(cluster_id, args, day2_type_flag, has_ipv6):
    utils.recreate_folder(consts.IMAGE_FOLDER, force_recreate=False)

    client = ClientFactory.create_client(
        url=utils.get_assisted_service_url_by_args(args=args),
        offline_token=utils.get_env("OFFLINE_TOKEN"))

    cluster = client.cluster_get(cluster_id=cluster_id)
    cluster_name = cluster.name
    openshift_version = cluster.openshift_version
    api_vip_dnsname = "api." + cluster_name + "." + cluster.base_dns_domain
    api_vip_ip = cluster.api_vip
    terraform_cluster_dir_prefix = cluster_name
    if day2_type_flag == "ocp":
        terraform_cluster_dir_prefix = f"{consts.CLUSTER_PREFIX}-{consts.DEFAULT_NAMESPACE}"
    else:
        cluster_id = str(uuid.uuid4())
        copy_proxy_from_cluster = cluster
        cluster = client.create_day2_cluster(
            cluster_name + "-day2", cluster_id,
            **_day2_cluster_create_params(openshift_version, api_vip_dnsname))
        set_cluster_pull_secret(client, cluster_id, args.pull_secret)
        set_cluster_proxy(client, cluster_id, copy_proxy_from_cluster, args)

    config_etc_hosts(api_vip_ip, api_vip_dnsname)
    image_path = os.path.join(consts.IMAGE_FOLDER,
                              f'{args.namespace}-installer-image.iso')

    tf_folder = os.path.join(
        utils.get_tf_folder(terraform_cluster_dir_prefix, args.namespace),
        consts.Platforms.BARE_METAL)
    set_day2_tf_configuration(tf_folder, args.number_of_day2_workers,
                              api_vip_ip, api_vip_dnsname)

    static_network_config = None
    if args.with_static_network_config:
        static_network_config = static_network.generate_day2_static_network_data_from_tf(
            tf_folder, args.number_of_day2_workers)

    client.generate_and_download_image(
        cluster_id=cluster.id,
        image_path=image_path,
        ssh_key=args.ssh_key,
        static_network_config=static_network_config)

    day2_nodes_flow(
        client,
        terraform_cluster_dir_prefix,
        tf_folder,
        cluster,
        has_ipv6,
        args.number_of_day2_workers,
        api_vip_ip,
        api_vip_dnsname,
        args.install_cluster,
        day2_type_flag,
        args.with_static_network_config,
        cluster_name,
    )
Example #4
0
def create_client(url,
                  offline_token=utils.get_env('OFFLINE_TOKEN'),
                  pull_secret="",
                  wait_for_api=True):
    log.info('Creating assisted-service client for url: %s', url)
    c = InventoryClient(url, offline_token, pull_secret)
    if wait_for_api:
        c.wait_for_api_readiness()
    return c
Example #5
0
def create_client(
        url,
        offline_token=utils.get_env('OFFLINE_TOKEN'),
        pull_secret="",
        wait_for_api=True,
        timeout=consts.WAIT_FOR_BM_API
):
    warnings.warn("create_client is deprecated. Use ClientFactory.create_client instead.", DeprecationWarning)
    return ClientFactory.create_client(url, offline_token, pull_secret, wait_for_api, timeout)
 def __init__(self,
              env_var: str,
              default_prefix: str,
              prefix: str = None,
              suffix: str = None):
     self._default_prefix = default_prefix
     self.prefix = prefix if prefix is not None else get_env(
         env_var, default_prefix)
     self.suffix = suffix if suffix is not None else get_name_suffix()
def get_kubeconfig_path():
    kubeconfig_dir = Path("/build/kubeconfig")
    default = kubeconfig_dir.joinpath(f"kubeconfig_{cluster_name}")
    kubeconfig_path = utils.get_env('KUBECONFIG', str(default))

    if kubeconfig_path == str(default):
        kubeconfig_dir.mkdir(parents=True, exist_ok=True)

    return kubeconfig_path
Example #8
0
def get_api_client(offline_token=None, **kwargs) -> InventoryClient:
    url = global_variables.remote_service_url
    offline_token = offline_token or global_variables.offline_token

    if not url:
        url = utils.get_local_assisted_service_url(
            global_variables.namespace, 'assisted-service',
            utils.get_env('DEPLOY_TARGET'))

    return ClientFactory.create_client(url, offline_token, **kwargs)
def try_get_cluster():
    if args.cluster_id:
        try:
            client = ClientFactory.create_client(
                url=utils.get_assisted_service_url_by_args(args=args),
                offline_token=utils.get_env("OFFLINE_TOKEN"))

            return client, client.cluster_get(cluster_id=args.cluster_id)

        except ApiException as e:
            log.warning(f"Can't retrieve cluster_id={args.cluster_id}, {e}")

    return None, None
def execute_day1_flow():
    client, cluster = try_get_cluster()
    cluster_name = f'{args.cluster_name or consts.CLUSTER_PREFIX}-{args.namespace}'

    if cluster:
        args.base_dns_domain = cluster.base_dns_domain
        cluster_name = cluster.name

    elif args.managed_dns_domains:
        args.base_dns_domain = args.managed_dns_domains.split(":")[0]

    log.info('Cluster name: %s', cluster_name)

    machine_net = MachineNetwork(args.ipv4, args.ipv6, args.vm_network_cidr,
                                 args.vm_network_cidr6, args.ns_index)
    image_path = args.image or os.path.join(
        consts.IMAGE_FOLDER, f'{args.namespace}-installer-image.iso')
    set_tf_config(cluster_name)

    if not args.image:
        utils.recreate_folder(consts.IMAGE_FOLDER, force_recreate=False)
        if not client:
            client = ClientFactory.create_client(
                url=utils.get_assisted_service_url_by_args(args=args),
                offline_token=utils.get_env("OFFLINE_TOKEN"))

        if args.cluster_id:
            cluster = client.cluster_get(cluster_id=args.cluster_id)
        else:
            cluster = client.create_cluster(cluster_name,
                                            ssh_public_key=args.ssh_key,
                                            **_cluster_create_params(client))

        static_network_config = apply_static_network_config(
            cluster_name=cluster_name,
            kube_client=None,
        )

        client.generate_and_download_image(
            cluster_id=cluster.id,
            image_path=image_path,
            image_type=args.iso_image_type,
            ssh_key=args.ssh_key,
            static_network_config=static_network_config,
        )

    # Iso only, cluster will be up and iso downloaded but vm will not be created
    if not args.iso_only:
        run_nodes_flow(client, cluster_name, cluster, machine_net, image_path)

    return cluster.id if cluster else None
def try_to_delete_cluster(namespace, tfvars):
    """ Try to delete cluster if assisted-service is up and such cluster
        exists.
    """
    cluster_id = tfvars.get('cluster_inventory_id')
    if args.kube_api or not cluster_id:
        return

    args.namespace = namespace
    client = ClientFactory.create_client(
        url=utils.get_assisted_service_url_by_args(args=args, wait=False),
        offline_token=utils.get_env("OFFLINE_TOKEN"))

    client.delete_cluster(cluster_id=cluster_id)
Example #12
0
class ClusterName:
    suffix: str = str(uuid.uuid4())[: consts.SUFFIX_LENGTH]
    prefix: str = get_env("CLUSTER_NAME", f"{consts.CLUSTER_PREFIX}")

    def __str__(self):
        return self.get()

    def __repr__(self):
        return self.get()

    def get(self):
        name = self.suffix
        if self.prefix == consts.CLUSTER_PREFIX:
            name = self.prefix + "-" + self.suffix
        return name
def main():
    _verify_kube_download_folder(args.kubeconfig_path)
    log.info("Creating assisted service client")
    # if not cluster id is given, reads it from latest run
    tf = None
    if not args.cluster_id:
        cluster_name = f'{args.cluster_name or consts.CLUSTER_PREFIX}-{args.namespace}'
        tf_folder = utils.get_tf_folder(cluster_name, args.namespace)
        args.cluster_id = utils.get_tfvars(tf_folder).get(
            'cluster_inventory_id')
        tf = terraform_utils.TerraformUtils(working_dir=tf_folder)

    client = ClientFactory.create_client(
        url=utils.get_assisted_service_url_by_args(args=args, wait=False),
        offline_token=utils.get_env("OFFLINE_TOKEN"))

    run_install_flow(client=client,
                     cluster_id=args.cluster_id,
                     kubeconfig_path=args.kubeconfig_path,
                     pull_secret=args.pull_secret,
                     tf=tf)
def main():
    args = handle_arguments()

    if args.sosreport:
        gather_sosreport_data(output_dir=args.dest)

    client = ClientFactory.create_client(
        url=args.inventory_url,
        timeout=CONNECTION_TIMEOUT,
        offline_token=get_env("OFFLINE_TOKEN"))
    if args.cluster_id:
        cluster = client.cluster_get(args.cluster_id)
        download_cluster_logs(client,
                              json.loads(
                                  json.dumps(cluster.to_dict(),
                                             sort_keys=True,
                                             default=str)),
                              args.dest,
                              args.must_gather,
                              args.update_by_events,
                              pull_secret=args.pull_secret)
    else:
        clusters = get_clusters(client, args.download_all)

        if not clusters:
            log.info('No clusters were found')
            return

        for cluster in clusters:
            if args.download_all or should_download_logs(cluster):
                download_cluster_logs(client,
                                      cluster,
                                      args.dest,
                                      args.must_gather,
                                      args.update_by_events,
                                      pull_secret=args.pull_secret)

        log.info(
            "Cluster installation statuses: %s",
            dict(Counter(cluster["status"] for cluster in clusters).items()))
Example #15
0
def _get_cluster_name():
    cluster_name = utils.get_env('CLUSTER_NAME', f'{consts.CLUSTER_PREFIX}')
    if cluster_name == consts.CLUSTER_PREFIX:
        cluster_name = cluster_name + '-' + str(uuid.uuid4())[:8]
    return cluster_name
Example #16
0
    return cluster_name

# TODO changes it
if is_qe_env():
    from test_infra.controllers.node_controllers.qe_vm_controler import \
        QeVmController as nodeController
    qe_env = True
else:
    from test_infra.controllers.node_controllers.terraform_controller import \
        TerraformController as nodeController


private_ssh_key_path_default = os.path.join(os.getcwd(), "ssh_key/key") if not qe_env else \
    os.path.join(str(Path.home()), ".ssh/id_rsa")

env_variables = {"ssh_public_key": utils.get_env('SSH_PUB_KEY'),
                 "remote_service_url": utils.get_env('REMOTE_SERVICE_URL'),
                 "pull_secret": utils.get_env('PULL_SECRET'),
                 "offline_token": utils.get_env('OFFLINE_TOKEN'),
                 "openshift_version": utils.get_openshift_version(),
                 "base_domain": utils.get_env('BASE_DOMAIN', "redhat.com"),
                 "num_masters": int(utils.get_env('NUM_MASTERS', consts.NUMBER_OF_MASTERS)),
                 "num_workers": max(2, int(utils.get_env('NUM_WORKERS', 0))),
                 "vip_dhcp_allocation": bool(util.strtobool(utils.get_env('VIP_DHCP_ALLOCATION'))),
                 "worker_memory": int(utils.get_env('WORKER_MEMORY', '8892')),
                 "master_memory": int(utils.get_env('MASTER_MEMORY', '16984')),
                 "network_mtu": utils.get_env('NETWORK_MTU', '1500'),
                 "worker_disk": int(utils.get_env('WORKER_DISK', '21474836480')),
                 "master_disk": int(utils.get_env('MASTER_DISK', '128849018880')),
                 "storage_pool_path": utils.get_env('STORAGE_POOL_PATH', os.path.join(os.getcwd(), "storage_pool")),
                 "cluster_name": _get_cluster_name(),
Example #17
0
# TODO changes it
if is_qe_env():
    from test_infra.controllers.node_controllers.qe_vm_controler import \
        QeVmController as nodeController

    qe_env = True
else:
    from test_infra.controllers.node_controllers.terraform_controller import \
        TerraformController as nodeController

private_ssh_key_path_default = os.path.join(os.getcwd(), "ssh_key/key") if not qe_env else \
    os.path.join(str(Path.home()), ".ssh/id_rsa")

env_variables = {
    "ssh_public_key":
    utils.get_env('SSH_PUB_KEY'),
    "remote_service_url":
    utils.get_env('REMOTE_SERVICE_URL'),
    "pull_secret":
    utils.get_env('PULL_SECRET'),
    "offline_token":
    utils.get_env('OFFLINE_TOKEN'),
    "openshift_version":
    utils.get_openshift_version(),
    "base_domain":
    utils.get_env('BASE_DOMAIN', "redhat.com"),
    "num_masters":
    int(utils.get_env('NUM_MASTERS', consts.NUMBER_OF_MASTERS)),
    "num_workers":
    max(2, int(utils.get_env('NUM_WORKERS', 0))),
    "num_day2_workers":
Example #18
0
def execute_kube_api_flow():
    log.info("Executing kube-api flow")
    cluster_name = f'{args.cluster_name or consts.CLUSTER_PREFIX}-{args.namespace}'
    utils.recreate_folder(consts.IMAGE_FOLDER, force_recreate=False)
    machine_net = MachineNetwork(args.ipv4, args.ipv6, args.vm_network_cidr, args.vm_network_cidr6, args.ns_index)
    kube_client = create_kube_api_client()
    cluster_deployment = ClusterDeployment(
        kube_api_client=kube_client,
        name=cluster_name,
        namespace=args.namespace
    )
    set_tf_config(cluster_name)

    secret = Secret(
        kube_api_client=kube_client,
        name=cluster_name,
        namespace=args.namespace,
    )
    secret.apply(pull_secret=args.pull_secret)

    imageSet=ClusterImageSet(
        kube_api_client=kube_client,
        name=f"{cluster_name}-image-set",
        namespace=args.namespace
    )
    releaseImage=utils.get_env('OPENSHIFT_INSTALL_RELEASE_IMAGE', utils.get_openshift_release_image("4.8"))
    imageSet.apply(releaseImage=releaseImage)

    ipv4 = args.ipv4 and args.ipv4.lower() in MachineNetwork.YES_VALUES
    ipv6 = args.ipv6 and args.ipv6.lower() in MachineNetwork.YES_VALUES
    api_vip, ingress_vip = "", ""
    if args.master_count > 1:
        api_vip, ingress_vip = _get_vips_ips(machine_net)

    agent_cluster_install = AgentClusterInstall(
        kube_api_client=kube_client,
        name=f'{cluster_name}-agent-cluster-install',
        namespace=args.namespace
    )

    image_set_ref = ClusterImageSetReference(name=f'{cluster_name}-image-set')
    cluster_deployment.apply(
        secret=secret,
        base_domain=args.base_dns_domain,
        agent_cluster_install_ref=agent_cluster_install.ref,
    )

    agent_cluster_install.apply(
        cluster_deployment_ref=cluster_deployment.ref,
        api_vip=api_vip,
        ingress_vip=ingress_vip,
        image_set_ref=image_set_ref,
        cluster_cidr=args.cluster_network if ipv4 else args.cluster_network6,
        host_prefix=args.host_prefix if ipv4 else args.host_prefix6,
        service_network=args.service_network if ipv4 else args.service_network6,
        ssh_pub_key=args.ssh_key,
        control_plane_agents=args.master_count,
        worker_agents=args.number_of_workers,
        machine_cidr=get_machine_cidr_from_machine_net(machine_net),
    )
    agent_cluster_install.wait_to_be_ready(False)

    apply_static_network_config(
        cluster_name=cluster_name,
        kube_client=kube_client,
    )

    image_path = os.path.join(
        consts.IMAGE_FOLDER,
        f'{args.namespace}-installer-image.iso'
    )

    log.info("Creating infraEnv")
    http_proxy, https_proxy, no_proxy = _get_http_proxy_params(ipv4=ipv4, ipv6=ipv6)
    infra_env = InfraEnv(
        kube_api_client=kube_client,
        name=f"{cluster_name}-infra-env",
        namespace=args.namespace
    )
    infra_env.apply(
        cluster_deployment=cluster_deployment,
        secret=secret,
        proxy=Proxy(
            http_proxy=http_proxy,
            https_proxy=https_proxy,
            no_proxy=no_proxy
        ),
        ssh_pub_key=args.ssh_key,
        nmstate_label=cluster_name,
    )
    infra_env.status()
    image_url = infra_env.get_iso_download_url()
    utils.download_iso(image_url, image_path)
    try:
        nodes_flow_kube_api(cluster_name, machine_net, cluster_deployment, agent_cluster_install)
    finally:
        if not image_path or args.keep_iso:
            return
        log.info('deleting iso: %s', image_path)
        os.unlink(image_path)
Example #19
0
# TODO changes it
if is_qe_env():
    from test_infra.controllers.node_controllers.qe_vm_controler import \
        QeVmController as nodeController
    qe_env = True
else:
    from test_infra.controllers.node_controllers.terraform_controller import \
        TerraformController as nodeController


private_ssh_key_path_default = os.path.join(os.getcwd(), "ssh_key/key") if not qe_env else \
    os.path.join(str(Path.home()), ".ssh/id_rsa")

env_variables = {
    "ssh_public_key":
    utils.get_env('SSH_PUB_KEY'),
    "remote_service_url":
    utils.get_env('REMOTE_SERVICE_URL'),
    "pull_secret":
    utils.get_env('PULL_SECRET'),
    "offline_token":
    utils.get_env('OFFLINE_TOKEN'),
    "openshift_version":
    utils.get_openshift_version(),
    "base_domain":
    utils.get_env('BASE_DOMAIN', "redhat.com"),
    "num_masters":
    int(utils.get_env('NUM_MASTERS', consts.NUMBER_OF_MASTERS)),
    "num_workers":
    max(2, int(utils.get_env('NUM_WORKERS', 0))),
    "vip_dhcp_allocation":
Example #20
0
import pytest
from contextlib import suppress
from typing import Optional
from tests.base_test import BaseTest
from tests.conftest import env_variables, get_api_client
from assisted_service_client.rest import ApiException
from test_infra import utils
from test_infra.helper_classes.cluster import Cluster

SECOND_OFFLINE_TOKEN = utils.get_env('SECOND_OFFLINE_TOKEN')
SECOND_PULL_SECRET = utils.get_env('SECOND_PULL_SECRET')


@pytest.fixture()
def api_client():
    yield get_api_client


@pytest.mark.skipif(not env_variables['offline_token'], reason="not cloud env")
class TestAuth(BaseTest):
    @pytest.fixture()
    def cluster(self):
        clusters = []

        def get_cluster_func(api_client,
                             cluster_name: Optional[str] = None,
                             cluster_id: Optional[str] = None):
            res = Cluster(api_client=api_client,
                          cluster_name=cluster_name,
                          cluster_id=cluster_id)
            clusters.append(res)
Example #21
0
qe_env = False

# TODO changes it
if os.environ.get('NODE_ENV') == 'QE_VM':
    from test_infra.controllers.node_controllers.qe_vm_controler import \
        QeVmController as nodeController
    qe_env = True
else:
    from test_infra.controllers.node_controllers.terraform_controller import \
        TerraformController as nodeController


private_ssh_key_path_default = os.path.join(os.getcwd(), "ssh_key/key") if not qe_env else \
    os.path.join(str(Path.home()), ".ssh/id_rsa")

env_variables = {"ssh_public_key": utils.get_env('SSH_PUB_KEY'),
                 "remote_service_url": utils.get_env('REMOTE_SERVICE_URL'),
                 "pull_secret": utils.get_env('PULL_SECRET'),
                 "offline_token": utils.get_env('OFFLINE_TOKEN'),
                 "openshift_version": utils.get_env('OPENSHIFT_VERSION', '4.6'),
                 "base_domain": utils.get_env('BASE_DOMAIN', "redhat.com"),
                 "num_masters": int(utils.get_env('NUM_MASTERS', consts.NUMBER_OF_MASTERS)),
                 "num_workers": max(2, int(utils.get_env('NUM_WORKERS', 0))),
                 "vip_dhcp_allocation": bool(util.strtobool(utils.get_env('VIP_DHCP_ALLOCATION'))),
                 "machine_cidr": utils.get_env('NETWORK_CIDR', '192.168.126.0/24'),
                 "worker_memory": int(utils.get_env('WORKER_MEMORY', '8892')),
                 "master_memory": int(utils.get_env('MASTER_MEMORY', '16984')),
                 "network_mtu": utils.get_env('NETWORK_MTU', '1500'),
                 "worker_disk": int(utils.get_env('WORKER_DISK', '21474836480')),
                 "master_disk": int(utils.get_env('WORKER_DISK', '128849018880')),
                 "storage_pool_path": utils.get_env('STORAGE_POOL_PATH', os.path.join(os.getcwd(), "storage_pool")),
Example #22
0
class _EnvVariablesDefaults(ABC):
    ssh_public_key: str = get_env("SSH_PUB_KEY")
    remote_service_url: str = get_env("REMOTE_SERVICE_URL")
    pull_secret: str = get_env("PULL_SECRET")
    offline_token: str = get_env("OFFLINE_TOKEN")
    openshift_version: str = ""
    base_dns_domain: str = get_env("BASE_DOMAIN",
                                   consts.DEFAULT_BASE_DNS_DOMAIN)
    masters_count: int = int(
        get_env("MASTERS_COUNT",
                get_env("NUM_MASTERS",
                        env_defaults.DEFAULT_NUMBER_OF_MASTERS)))
    workers_count: int = int(
        get_env("WORKERS_COUNT",
                get_env("NUM_WORKERS", env_defaults.DEFAULT_WORKERS_COUNT)))
    nodes_count: int = masters_count + workers_count
    num_day2_workers: int = int(
        get_env("NUM_DAY2_WORKERS", env_defaults.DEFAULT_DAY2_WORKERS_COUNT))
    vip_dhcp_allocation: bool = bool(strtobool(get_env("VIP_DHCP_ALLOCATION")))
    worker_memory: int = int(
        get_env("WORKER_MEMORY", resources.DEFAULT_WORKER_MEMORY))
    master_memory: int = int(
        get_env("MASTER_MEMORY", resources.DEFAULT_MASTER_MEMORY))
    network_mtu: int = int(get_env("NETWORK_MTU", resources.DEFAULT_MTU))
    worker_disk: int = int(
        get_env("WORKER_DISK", resources.DEFAULT_WORKER_DISK))
    master_disk: int = int(
        get_env("MASTER_DISK", resources.DEFAULT_MASTER_DISK))
    master_disk_count: int = int(
        get_env("MASTER_DISK_COUNT", resources.DEFAULT_DISK_COUNT))
    worker_disk_count: int = int(
        get_env("WORKER_DISK_COUNT", resources.DEFAULT_DISK_COUNT))
    storage_pool_path: str = get_env("STORAGE_POOL_PATH",
                                     env_defaults.DEFAULT_STORAGE_POOL_PATH)
    private_ssh_key_path: Path = Path(
        get_env("PRIVATE_KEY_PATH", env_defaults.DEFAULT_SSH_PRIVATE_KEY_PATH))
    installer_kubeconfig_path: str = get_env(
        "INSTALLER_KUBECONFIG", env_defaults.DEFAULT_INSTALLER_KUBECONFIG)
    log_folder: str = get_env("LOG_FOLDER", env_defaults.DEFAULT_LOG_FOLDER)
    is_static_ip: bool = bool(
        strtobool(
            get_env("STATIC_IPS",
                    default=str(env_defaults.DEFAULT_STATIC_IPS))))
    iso_image_type: str = get_env("ISO_IMAGE_TYPE",
                                  env_defaults.DEFAULT_IMAGE_TYPE)
    worker_vcpu: str = get_env("WORKER_CPU", resources.DEFAULT_WORKER_CPU)
    master_vcpu: str = get_env("MASTER_CPU", resources.DEFAULT_MASTER_CPU)
    test_teardown: bool = bool(
        strtobool(
            get_env("TEST_TEARDOWN", str(env_defaults.DEFAULT_TEST_TEARDOWN))))
    namespace: str = get_env("NAMESPACE", consts.DEFAULT_NAMESPACE)
    spoke_namespace: str = get_env("SPOKE_NAMESPACE",
                                   consts.DEFAULT_SPOKE_NAMESPACE)
    olm_operators: List[str] = field(default_factory=list)
    platform: str = get_env("PLATFORM", env_defaults.DEFAULT_PLATFORM)
    user_managed_networking: bool = env_defaults.DEFAULT_USER_MANAGED_NETWORKING
    high_availability_mode: str = env_defaults.DEFAULT_HIGH_AVAILABILITY_MODE
    download_image: bool = bool(
        strtobool(
            get_env("DOWNLOAD_IMAGE",
                    str(env_defaults.DEFAULT_DOWNLOAD_IMAGE))))
    is_ipv4: bool = bool(
        strtobool(get_env("IPv4", str(env_defaults.DEFAULT_IS_IPV4))))
    is_ipv6: bool = bool(
        strtobool(get_env("IPv6", str(env_defaults.DEFAULT_IS_IPV6))))
    cluster_id: str = get_env("CLUSTER_ID")
    additional_ntp_source: str = get_env(
        "ADDITIONAL_NTP_SOURCE", env_defaults.DEFAULT_ADDITIONAL_NTP_SOURCE)
    network_name: str = get_env("NETWORK_NAME",
                                env_defaults.DEFAULT_NETWORK_NAME)
    bootstrap_in_place: bool = bool(
        strtobool(
            get_env("BOOTSTRAP_IN_PLACE",
                    str(env_defaults.DEFAULT_BOOTSTRAP_IN_PLACE))))
    single_node_ip: str = get_env("SINGLE_NODE_IP",
                                  env_defaults.DEFAULT_SINGLE_NODE_IP)
    worker_cpu_mode: str = get_env("WORKER_CPU_MODE",
                                   env_defaults.DEFAULT_TF_CPU_MODE)
    master_cpu_mode: str = get_env("MASTER_CPU_MODE",
                                   env_defaults.DEFAULT_TF_CPU_MODE)
    iso_download_path: str = get_env(
        "ISO_DOWNLOAD_PATH",
        get_env("ISO"))  # todo replace ISO env var->ISO_DOWNLOAD_PATH
    hyperthreading: str = get_env("HYPERTHREADING")
    network_type: str = get_env("NETWORK_TYPE",
                                env_defaults.DEFAULT_NETWORK_TYPE)
    is_kube_api: bool = bool(
        strtobool(get_env("KUBE_API", str(env_defaults.DEFAULT_IS_KUBE_API))))

    vsphere_cluster: str = get_env("VSPHERE_CLUSTER")
    vsphere_username: str = get_env("VSPHERE_USERNAME")
    vsphere_password: str = get_env("VSPHERE_PASSWORD")
    vsphere_network: str = get_env("VSPHERE_NETWORK")
    vsphere_vcenter: str = get_env("VSPHERE_VCENTER")
    vsphere_datacenter: str = get_env("VSPHERE_DATACENTER")
    vsphere_datastore: str = get_env("VSPHERE_DATASTORE")

    __instance: ClassVar = None

    def __new__(cls, *args, **kwargs):
        """ Prevent creating another env_var instance """
        if isinstance(cls.__instance, cls):
            raise Exception(
                "Can't initialized more then one global configuration object")
        cls.__instance = object.__new__(cls, *args, **kwargs)
        return cls.__instance

    def __post_init__(self):
        self._set("olm_operators",
                  operators_utils.parse_olm_operators_from_env())

    def _set(self, key: str, value: Any):
        if not hasattr(self, key):
            raise AttributeError(f"Invalid key {key}")

        super().__setattr__(key, value)
Example #23
0
from test_infra import assisted_service_api, consts, utils


def _get_cluster_name():
    cluster_name = utils.get_env('CLUSTER_NAME', f'{consts.CLUSTER_PREFIX}')
    if cluster_name == consts.CLUSTER_PREFIX:
        cluster_name = cluster_name + '-' + str(
            uuid.uuid4())[:consts.SUFFIX_LENGTH]
    return cluster_name


private_ssh_key_path_default = os.path.join(os.getcwd(), "ssh_key/key")

env_variables = {
    "ssh_public_key":
    utils.get_env('SSH_PUB_KEY'),
    "remote_service_url":
    utils.get_env('REMOTE_SERVICE_URL'),
    "pull_secret":
    utils.get_env('PULL_SECRET'),
    "offline_token":
    utils.get_env('OFFLINE_TOKEN'),
    "openshift_version":
    utils.get_openshift_version(),
    "base_domain":
    utils.get_env('BASE_DOMAIN', consts.DEFAULT_BASE_DNS_DOMAIN),
    "num_masters":
    int(utils.get_env('NUM_MASTERS', consts.NUMBER_OF_MASTERS)),
    "num_workers":
    int(utils.get_env('NUM_WORKERS', 0)),
    "num_day2_workers":
Example #24
0
 def get_machine_cidr(self):
     return utils.get_env('NETWORK_CIDR', '192.168.123.0/24')
Example #25
0
 def __init__(self, prefix: str = None, suffix: str = None):
     self.prefix = prefix if prefix is not None else get_env(
         "CLUSTER_NAME", f"{consts.CLUSTER_PREFIX}")
     self.suffix = suffix if suffix is not None else get_cluster_name_suffix(
     )