コード例 #1
0
    def test_upgrade_logging(self):
        """
        This function contains test to upgrade openshift-logging
        with Entry and Exit criteria for checks

        """

        ceph_cluster = CephCluster()
        with CephHealthMonitor(ceph_cluster):

            #  Pre-check
            logger.info("Checking cluster logging before starting to upgrade")
            check_cluster_logging()

            # Matching the OCP version and cluster-Logging version
            ocp_version = get_ocp_version()
            logger.info(f"OCP version {ocp_version}")
            subscription = get_clusterlogging_subscription()
            logging_channel = subscription.get('spec').get('channel')
            logger.info(
                f"Current Logging channel {logging_channel}"
            )
            upgrade_info(logging_channel)
            upgrade_channel = config.UPGRADE['upgrade_logging_channel']
            if ocp_version > logging_channel:
                # Upgrade Elastic search operator Subscription
                es_subscription_cmd = (
                    'oc patch subscription elasticsearch-operator '
                    f'-n {constants.OPENSHIFT_OPERATORS_REDHAT_NAMESPACE} '
                    '--type merge -p \'{"spec":{"channel": '
                    f'"{upgrade_channel}"}}}}\''
                )
                # Upgrade Cluster-logging operator subscription
                clo_subscription_cmd = (
                    'oc patch subscription cluster-logging '
                    f'-n {constants.OPENSHIFT_LOGGING_NAMESPACE} '
                    '--type merge -p \'{"spec":{"channel": '
                    f'"{upgrade_channel}"}}}}\''
                )
                run_cmd(es_subscription_cmd)
                run_cmd(clo_subscription_cmd)
                assert check_csv_logging_phase(
                    upgrade_channel
                ), "Logging upgrade not completed yet!"
                logger.info(
                    "Logging upgrade completed!"
                )
                assert check_csv_version_post_upgrade(
                    upgrade_channel
                ), "Unable to get version "
                logger.info("Version Matches!")
                upgrade_info(upgrade_channel)
                check_cluster_logging()
            else:
                logger.info(
                    "Logging Version matches the OCP version, "
                    "No upgrade needed"
                )
コード例 #2
0
def install_logging():

    csv = ocp.OCP(
        kind=constants.CLUSTER_SERVICE_VERSION,
        namespace=constants.OPENSHIFT_LOGGING_NAMESPACE,
    )
    logging_csv = csv.get().get("items")
    if logging_csv:
        logger.info("Logging is already configured, Skipping Installation")
        return

    logger.info("Configuring Openshift-logging")

    # Gets OCP version to align logging version to OCP version
    ocp_version = version.get_semantic_ocp_version_from_config()
    logging_channel = "stable" if ocp_version >= version.VERSION_4_7 else ocp_version

    # Creates namespace openshift-operators-redhat
    ocp_logging_obj.create_namespace(yaml_file=constants.EO_NAMESPACE_YAML)

    # Creates an operator-group for elasticsearch
    assert ocp_logging_obj.create_elasticsearch_operator_group(
        yaml_file=constants.EO_OG_YAML,
        resource_name=constants.OPENSHIFT_OPERATORS_REDHAT_NAMESPACE,
    )

    # Set RBAC policy on the project
    assert ocp_logging_obj.set_rbac(
        yaml_file=constants.EO_RBAC_YAML, resource_name="prometheus-k8s"
    )

    # Creates subscription for elastic-search operator
    subscription_yaml = templating.load_yaml(constants.EO_SUB_YAML)
    subscription_yaml["spec"]["channel"] = logging_channel
    helpers.create_resource(**subscription_yaml)
    assert ocp_logging_obj.get_elasticsearch_subscription()

    # Creates a namespace openshift-logging
    ocp_logging_obj.create_namespace(yaml_file=constants.CL_NAMESPACE_YAML)

    # Creates an operator-group for cluster-logging
    assert ocp_logging_obj.create_clusterlogging_operator_group(
        yaml_file=constants.CL_OG_YAML
    )

    # Creates subscription for cluster-logging
    cl_subscription = templating.load_yaml(constants.CL_SUB_YAML)
    cl_subscription["spec"]["channel"] = logging_channel
    helpers.create_resource(**cl_subscription)
    assert ocp_logging_obj.get_clusterlogging_subscription()

    # Creates instance in namespace openshift-logging
    cluster_logging_operator = OCP(
        kind=constants.POD, namespace=constants.OPENSHIFT_LOGGING_NAMESPACE
    )
    logger.info(f"The cluster-logging-operator {cluster_logging_operator.get()}")
    ocp_logging_obj.create_instance()
コード例 #3
0
def test_fixture(request):
    """
    Setup and teardown
    * The setup will deploy openshift-logging in the cluster
    * The teardown will uninstall cluster-logging from the cluster
    """

    def finalizer():
        teardown()

    request.addfinalizer(finalizer)

    # Deploys elastic-search operator on the project openshift-operators-redhat
    ocp_logging_obj.create_namespace(yaml_file=constants.EO_NAMESPACE_YAML)
    assert ocp_logging_obj.create_elasticsearch_operator_group(
        yaml_file=constants.EO_OG_YAML,
        resource_name='openshift-operators-redhat'
    )
    assert ocp_logging_obj.set_rbac(
        yaml_file=constants.EO_RBAC_YAML, resource_name='prometheus-k8s'
    )
    logging_version = config.ENV_DATA['logging_version']
    subscription_yaml = templating.load_yaml(constants.EO_SUB_YAML)
    subscription_yaml['spec']['channel'] = logging_version
    helpers.create_resource(**subscription_yaml)
    assert ocp_logging_obj.get_elasticsearch_subscription()

    # Deploys cluster-logging operator on the project openshift-loggingno nee
    ocp_logging_obj.create_namespace(yaml_file=constants.CL_NAMESPACE_YAML)
    assert ocp_logging_obj.create_clusterlogging_operator_group(
        yaml_file=constants.CL_OG_YAML
    )
    cl_subscription = templating.load_yaml(constants.CL_SUB_YAML)
    cl_subscription['spec']['channel'] = logging_version
    helpers.create_resource(**cl_subscription)
    assert ocp_logging_obj.get_clusterlogging_subscription()
    cluster_logging_operator = OCP(
        kind=constants.POD, namespace=constants.OPENSHIFT_LOGGING_NAMESPACE
    )
    logger.info(f"The cluster-logging-operator {cluster_logging_operator.get()}")

    create_instance()