Ejemplo n.º 1
0
def image_push(image_url, namespace):
    """
    Function to push images to destination

    Args:
        image_url (str): Image url container image repo link
        namespace (str): Image to be uploaded namespace

    Returns:
        registry_path (str): Uploaded image path

    """
    cmd_list = get_oc_podman_login_cmd()
    route = get_default_route_name()
    split_image_url = image_url.split("/")
    tag_name = split_image_url[-1]
    img_path = f"{route}/{namespace}/{tag_name}"
    cmd_list.append(f"podman tag {image_url} {img_path}")
    cmd_list.append(f"podman push {img_path}")
    master_list = helpers.get_master_nodes()
    ocp_obj = ocp.OCP()
    ocp_obj.exec_oc_debug_cmd(node=master_list[0], cmd_list=cmd_list)
    logger.info(f"Pushed {img_path} to registry")
    image_list_all()
    return img_path
Ejemplo n.º 2
0
def get_oc_podman_login_cmd():
    """
    Function to get oc and podman login commands on node

    Returns:
        cmd_list (list): List of cmd for oc/podman login

    """
    user = config.RUN['username']
    filename = os.path.join(config.ENV_DATA['cluster_path'],
                            config.RUN['password_location'])
    with open(filename) as f:
        password = f.read()
    helpers.refresh_oc_login_connection()
    ocp_obj = ocp.OCP()
    token = ocp_obj.get_user_token()
    route = get_default_route_name()
    cmd_list = [
        'export KUBECONFIG=/home/core/auth/kubeconfig',
        f"oc login -u {user} -p {password}",
        f"podman login {route} -u {user} -p {token}"
    ]
    master_list = helpers.get_master_nodes()
    helpers.rsync_kubeconf_to_node(node=master_list[0])
    return cmd_list
Ejemplo n.º 3
0
def enable_route_and_create_ca_for_registry_access():
    """
    Function to enable route and to create ca,
    copy to respective location for registry access

    Raises:
        AssertionError: When failure in enabling registry default route

    """
    ocp_obj = ocp.OCP(
        kind=constants.CONFIG, namespace=constants.OPENSHIFT_IMAGE_REGISTRY_NAMESPACE
    )
    assert ocp_obj.patch(
        resource_name=constants.IMAGE_REGISTRY_RESOURCE_NAME,
        params='{"spec": {"defaultRoute": true}}', format_type='merge'
    ), f"Registry pod defaultRoute enable is not success"
    logger.info(f"Enabled defaultRoute to true")
    ocp_obj = ocp.OCP()
    crt_cmd = f"get secret {constants.DEFAULT_ROUTE_CRT} " \
              f"-n {constants.OPENSHIFT_INGRESS_NAMESPACE} -o yaml"
    crt_dict = ocp_obj.exec_oc_cmd(command=crt_cmd)
    crt = crt_dict.get('data').get('tls.crt')
    route = get_default_route_name()
    if not os.path.exists('/tmp/secret'):
        run_cmd(cmd='mkdir /tmp/secret')
    with open(f"/tmp/secret/{route}.crt", "wb") as temp:
        temp.write(base64.b64decode(crt))
    master_list = helpers.get_master_nodes()
    ocp.rsync(
        src=f"/tmp/secret/", dst='/etc/pki/ca-trust/source/anchors',
        node=master_list[0], dst_node=True
    )
    ocp_obj.exec_oc_debug_cmd(node=master_list[0], cmd_list=['update-ca-trust enable'])
    logger.info(f"Created base64 secret, copied to source location and enabled ca-trust")
Ejemplo n.º 4
0
def get_oc_podman_login_cmd(skip_tls_verify=True):
    """
    Function to get oc and podman login commands on node

    Args:
        skip_tls_verify (bool): If true, the server's certificate will not be checked for validity

    Returns:
        cmd_list (list): List of cmd for oc/podman login

    """
    user = config.RUN['username']
    filename = os.path.join(config.ENV_DATA['cluster_path'],
                            config.RUN['password_location'])
    with open(filename) as f:
        password = f.read().strip()
    cluster_name = config.ENV_DATA['cluster_name']
    base_domain = config.ENV_DATA['base_domain']
    cmd_list = [
        'export KUBECONFIG=/home/core/auth/kubeconfig',
        f"oc login -u {user} -p {password} "
        f"https://api-int.{cluster_name}.{base_domain}:6443"
        f" --insecure-skip-tls-verify={skip_tls_verify}",
        f"podman login -u {user} -p $(oc whoami -t) image-registry.openshift-image-registry.svc:5000"
    ]
    master_list = helpers.get_master_nodes()
    helpers.rsync_kubeconf_to_node(node=master_list[0])
    return cmd_list
    def test_run_couchbase_node_reboot(self, cb_setup, nodes,
                                       pod_name_of_node):
        """
        Test couchbase workload with node reboot
        """
        if pod_name_of_node == 'couchbase':
            node_list = self.cb.get_couchbase_nodes()
        elif pod_name_of_node == 'osd':
            node_list = get_osd_running_nodes()
        elif pod_name_of_node == 'master':
            node_list = get_master_nodes()

        node_1 = get_node_objs(node_list[random.randint(0,
                                                        len(node_list) - 1)])

        # Check worker node utilization (adm_top)
        get_node_resource_utilization_from_adm_top(node_type='worker',
                                                   print_table=True)
        get_node_resource_utilization_from_adm_top(node_type='master',
                                                   print_table=True)
        # Restart relevant node
        nodes.restart_nodes(node_1)
        for sample in TimeoutSampler(300, 5, self.cb.result.done):
            if sample:
                break
            else:
                logging.info(
                    "#### ....Waiting for couchbase threads to complete...")
        self.sanity_helpers.health_check()
Ejemplo n.º 6
0
def image_list_all():
    """
    Function to list the images in the podman registry

    Returns:
        image_list_output (str): Images present in cluster

    """
    cmd_list = get_oc_podman_login_cmd()
    cmd_list.append(f"podman image list --format json")
    master_list = helpers.get_master_nodes()
    ocp_obj = ocp.OCP()
    return ocp_obj.exec_oc_debug_cmd(node=master_list[0], cmd_list=cmd_list)
Ejemplo n.º 7
0
def image_pull(image_url):
    """
    Function to pull images from repositories

    Args:
        image_url (str): Image url container image repo link

    """
    cmd_list = get_oc_podman_login_cmd()
    cmd_list.append(f"podman pull {image_url}")
    master_list = helpers.get_master_nodes()
    ocp_obj = ocp.OCP()
    ocp_obj.exec_oc_debug_cmd(node=master_list[0], cmd_list=cmd_list)
Ejemplo n.º 8
0
def image_rm(registry_path):
    """
    Function to remove images from registry

    Args:
        registry_path (str): Image registry path

    """
    cmd_list = get_oc_podman_login_cmd()
    cmd_list.append(f"podman rm {registry_path}")
    master_list = helpers.get_master_nodes()
    ocp_obj = ocp.OCP()
    ocp_obj.exec_oc_debug_cmd(node=master_list[0], cmd_list=cmd_list)
    logger.info(f"Image {registry_path} rm successful")
def create_instance_in_clusterlogging():
    """
    Creation of instance for clusterlogging that creates PVCs,
    ElasticSearch, curator fluentd and kibana pods and checks for all
    the pods and PVCs

    Args:
        sc_name (str): Storage class name to create PVCs

    Returns:
        dict: Contains all detailed information of the
            instance such as pods that got created, its resources and limits
            values, storage class and size details etc.

    """
    num_of_worker_nodes = len(helpers.get_worker_nodes())
    num_of_master_nodes = len(helpers.get_master_nodes())
    nodes_in_cluster = num_of_worker_nodes + num_of_master_nodes
    inst_data = templating.load_yaml(constants.CL_INSTANCE_YAML)
    es_node_count = inst_data['spec']['logStore']['elasticsearch']['nodeCount']
    helpers.create_resource(wait=False, **inst_data)
    oc = ocp.OCP('v1', 'ClusterLogging', 'openshift-logging')
    logging_instance = oc.get(resource_name='instance', out_yaml_format='True')
    if logging_instance:
        logger.info("Successfully created instance for cluster-logging")
        logger.debug(logging_instance)
    else:
        logger.error("Instance for clusterlogging is not created properly")

    pod_obj = ocp.OCP(kind=constants.POD, namespace='openshift-logging')
    pod_status = pod_obj.wait_for_resource(condition=constants.STATUS_RUNNING,
                                           resource_count=2 + es_node_count +
                                           nodes_in_cluster,
                                           timeout=300,
                                           sleep=5)
    assert pod_status, "Pods are not in Running state."
    logger.info("All pods are in Running state")
    pvc_obj = ocp.OCP(kind=constants.PVC, namespace='openshift-logging')
    pvc_status = pvc_obj.wait_for_resource(condition=constants.STATUS_BOUND,
                                           resource_count=es_node_count,
                                           timeout=150,
                                           sleep=5)
    assert pvc_status, "PVCs are not in bound state."
    logger.info("PVCs are Bound")
    return logging_instance
Ejemplo n.º 10
0
def get_oc_podman_login_cmd():
    """
    Function to get oc and podman login commands on node

    Returns:
        cmd_list (list): List of cmd for oc/podman login

    """
    user = config.RUN['username']
    helpers.refresh_oc_login_connection()
    ocp_obj = ocp.OCP()
    token = ocp_obj.get_user_token()
    route = get_default_route_name()
    cmd_list = [
        'export KUBECONFIG=/home/core/auth/kubeconfig',
        f"podman login {route} -u {user} -p {token}"
    ]
    master_list = helpers.get_master_nodes()
    helpers.rsync_kubeconf_to_node(node=master_list[0])
    return cmd_list
Ejemplo n.º 11
0
def image_push(image_url, namespace):
    """
    Function to push images to destination

    Args:
        image_url (str): Image url container image repo link
        namespace (str): Image to be uploaded namespace

    Returns:
        registry_path (str): Uploaded image path

    """
    image_path = f"image-registry.openshift-image-registry.svc:5000/{namespace}/image"
    tag_cmd = f"podman tag {image_url} {image_path}"
    push_cmd = f"podman push image-registry.openshift-image-registry.svc:5000/{namespace}/image"
    cmd_list = get_oc_podman_login_cmd()
    cmd_list.append(tag_cmd)
    cmd_list.append(push_cmd)
    master_list = helpers.get_master_nodes()
    ocp_obj = ocp.OCP()
    ocp_obj.exec_oc_debug_cmd(node=master_list[0], cmd_list=cmd_list)
    logger.info(f"Pushed {image_path} to registry")
    image_list_all()
    return image_path