From 60dc6d4c1c9140a3d981f4b8164246c1b99e7444 Mon Sep 17 00:00:00 2001 From: "MARINA.KOGAN" Date: Mon, 21 Aug 2023 18:33:20 +0000 Subject: [PATCH] added test for monitoring exported side car exporting metrics from domain with rest management services disabled --- .../ItMonitoringExporterSideCar.java | 56 ++++++++++- .../kubernetes/utils/MonitoringUtils.java | 92 +++++++++++++------ .../model.sessmigr.restdisabled.yaml | 40 ++++++++ 3 files changed, 157 insertions(+), 31 deletions(-) create mode 100644 integration-tests/src/test/resources/wdt-models/model.sessmigr.restdisabled.yaml diff --git a/integration-tests/src/test/java/oracle/weblogic/kubernetes/ItMonitoringExporterSideCar.java b/integration-tests/src/test/java/oracle/weblogic/kubernetes/ItMonitoringExporterSideCar.java index 6f9ee314d1f..e80958f794b 100644 --- a/integration-tests/src/test/java/oracle/weblogic/kubernetes/ItMonitoringExporterSideCar.java +++ b/integration-tests/src/test/java/oracle/weblogic/kubernetes/ItMonitoringExporterSideCar.java @@ -23,6 +23,7 @@ import oracle.weblogic.kubernetes.annotations.IntegrationTest; import oracle.weblogic.kubernetes.annotations.Namespaces; import oracle.weblogic.kubernetes.logging.LoggingFacade; +import oracle.weblogic.kubernetes.utils.LoggingUtil; import org.junit.jupiter.api.AfterAll; import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.DisplayName; @@ -30,6 +31,7 @@ import org.junit.jupiter.api.Test; import org.junit.jupiter.api.condition.DisabledIfEnvironmentVariable; +import static oracle.weblogic.kubernetes.TestConstants.DOMAIN_STATUS_CONDITION_FAILED_TYPE; import static oracle.weblogic.kubernetes.TestConstants.GRAFANA_CHART_VERSION; import static oracle.weblogic.kubernetes.TestConstants.K8S_NODEPORT_HOST; import static oracle.weblogic.kubernetes.TestConstants.OKD; @@ -48,6 +50,8 @@ import static oracle.weblogic.kubernetes.utils.CommonTestUtils.checkPodReadyAndServiceExists; import static oracle.weblogic.kubernetes.utils.CommonTestUtils.generateNewModelFileWithUpdatedDomainUid; import static oracle.weblogic.kubernetes.utils.CommonTestUtils.getImageBuilderExtraArgs; +import static oracle.weblogic.kubernetes.utils.DomainUtils.checkDomainStatusConditionTypeExists; +import static oracle.weblogic.kubernetes.utils.DomainUtils.checkDomainStatusConditionTypeHasExpectedStatus; import static oracle.weblogic.kubernetes.utils.ImageUtils.createMiiImageAndVerify; import static oracle.weblogic.kubernetes.utils.ImageUtils.imageRepoLoginAndPushImageToRegistry; import static oracle.weblogic.kubernetes.utils.LoadBalancerUtils.installAndVerifyNginx; @@ -66,6 +70,7 @@ import static oracle.weblogic.kubernetes.utils.OperatorUtils.installAndVerifyOperator; import static oracle.weblogic.kubernetes.utils.PatchDomainUtils.patchDomainResource; import static oracle.weblogic.kubernetes.utils.PersistentVolumeUtils.createPvAndPvc; +import static oracle.weblogic.kubernetes.utils.PodUtils.verifyIntrospectorPodLogContainsExpectedErrorMsg; import static oracle.weblogic.kubernetes.utils.SessionMigrationUtil.getOrigModelFile; import static oracle.weblogic.kubernetes.utils.ThreadSafeLogger.getLogger; import static org.assertj.core.api.Assertions.assertThat; @@ -93,10 +98,12 @@ class ItMonitoringExporterSideCar { private static String domain1Namespace = null; private static String domain2Namespace = null; private static String domain3Namespace = null; + private static String domain4Namespace = null; private static String domain1Uid = "monexp-domain-1"; private static String domain2Uid = "monexp-domain-2"; private static String domain3Uid = "monexp-domain-3"; + private static String domain4Uid = "monexp-domain-4"; private static NginxParams nginxHelmParams = null; private static int nodeportshttp = 0; @@ -137,7 +144,7 @@ class ItMonitoringExporterSideCar { */ @BeforeAll - public static void initAll(@Namespaces(6) List namespaces) { + public static void initAll(@Namespaces(7) List namespaces) { logger = getLogger(); @@ -170,9 +177,13 @@ public static void initAll(@Namespaces(6) List namespaces) { assertNotNull(namespaces.get(5), "Namespace list is null"); domain3Namespace = namespaces.get(5); + logger.info("Get a unique namespace for domain4"); + assertNotNull(namespaces.get(6), "Namespace list is null"); + domain4Namespace = namespaces.get(6); + logger.info("install and verify operator"); installAndVerifyOperator(opNamespace, - domain1Namespace, domain2Namespace, domain3Namespace); + domain1Namespace, domain2Namespace, domain3Namespace, domain4Namespace); logger.info("install monitoring exporter"); installMonitoringExporter(monitoringExporterDir); @@ -273,6 +284,47 @@ void testSideCarBasicFunctionality() throws Exception { } + /** + * Test Negative test to check error message in case + * if restfull management services are disabled. + * Create Model in Image with monitoring exporter and restfull services disabled. + * Check that introspector job fails with expected error message + * if domain crd contains exporter config with restfull services disabled + */ + @Test + @DisplayName("Negative test to check error message in case if restfull" + + " services in the domain are disabled.") + void testSideCarRESTfullServicesDisabled() throws Exception { + boolean testPassed = false; + try { + // create and verify one cluster mii domain + logger.info("Create domain and verify that it's running"); + String modelFile = generateNewModelFileWithUpdatedDomainUid(domain4Uid, + "ItMonitoringExporterSideCar", "model.sessmigr.restdisabled.yaml"); + String miiImage1 = createAndVerifyMiiImage(modelFile); + String yaml = RESOURCE_DIR + "/exporter/rest_webapp.yaml"; + + createAndVerifyDomain(miiImage1, domain4Uid, domain4Namespace, + "FromModel", 2, false, yaml, exporterImage, false); + // verify the condition type Failed exists + checkDomainStatusConditionTypeExists(domain4Uid, domain4Namespace, DOMAIN_STATUS_CONDITION_FAILED_TYPE); + // verify the condition Failed type has expected status + checkDomainStatusConditionTypeHasExpectedStatus(domain4Uid, domain4Namespace, + DOMAIN_STATUS_CONDITION_FAILED_TYPE, "True"); + String errorMessage = + "[SEVERE] exporter config is specified and the topology has the REST port disabled "; + verifyIntrospectorPodLogContainsExpectedErrorMsg(domain4Uid, domain4Namespace, errorMessage); + testPassed = true; + } finally { + if (!testPassed) { + List ns = new ArrayList<>(); + ns.add(domain4Namespace); + LoggingUtil.generateLog(this, ns); + shutdownDomain(domain4Uid, domain4Namespace); + } + } + } + private void changeMonitoringExporterSideCarConfig(String configYamlFile, String domainUid, String domainNamespace, String configSearchKey, diff --git a/integration-tests/src/test/java/oracle/weblogic/kubernetes/utils/MonitoringUtils.java b/integration-tests/src/test/java/oracle/weblogic/kubernetes/utils/MonitoringUtils.java index 9cfed4e0f3f..6e21671f1ec 100644 --- a/integration-tests/src/test/java/oracle/weblogic/kubernetes/utils/MonitoringUtils.java +++ b/integration-tests/src/test/java/oracle/weblogic/kubernetes/utils/MonitoringUtils.java @@ -1016,6 +1016,38 @@ public static void createAndVerifyDomain(String miiImage, boolean twoClusters, String monexpConfig, String exporterImage) { + createAndVerifyDomain(miiImage, + domainUid, + namespace, + domainHomeSource, + replicaCount, + twoClusters, + monexpConfig, + exporterImage, true); + } + + /** + * create domain from provided image and monitoring exporter sidecar and verify it's start. + * + * @param miiImage model in image name + * @param domainUid domain uid + * @param namespace namespace + * @param domainHomeSource domain home source type + * @param replicaCount replica count for the cluster + * @param twoClusters boolean indicating if the domain has 2 clusters + * @param monexpConfig monitoring exporter config + * @param exporterImage exporter image + * @param checkPodsReady true or false if test need to check pods status + */ + public static void createAndVerifyDomain(String miiImage, + String domainUid, + String namespace, + String domainHomeSource, + int replicaCount, + boolean twoClusters, + String monexpConfig, + String exporterImage, + boolean checkPodsReady) { // create registry secret to pull the image from registry // this secret is used only for non-kind cluster // create secret for admin credentials @@ -1024,14 +1056,14 @@ public static void createAndVerifyDomain(String miiImage, logger.info("Create secret for admin credentials"); String adminSecretName = "weblogic-credentials"; assertDoesNotThrow(() -> createSecretWithUsernamePassword(adminSecretName, namespace, - "weblogic", "welcome1"), + "weblogic", "welcome1"), String.format("create secret for admin credentials failed for %s", adminSecretName)); // create encryption secret logger.info("Create encryption secret"); String encryptionSecretName = "encryptionsecret"; assertDoesNotThrow(() -> createSecretWithUsernamePassword(encryptionSecretName, namespace, - "weblogicenc", "weblogicenc"), + "weblogicenc", "weblogicenc"), String.format("create encryption secret failed for %s", encryptionSecretName)); // create domain and verify @@ -1039,33 +1071,35 @@ public static void createAndVerifyDomain(String miiImage, domainUid, namespace, miiImage); createDomainCrAndVerify(adminSecretName, TEST_IMAGES_REPO_SECRET_NAME, encryptionSecretName, miiImage,domainUid, namespace, domainHomeSource, replicaCount, twoClusters, monexpConfig, exporterImage); - String adminServerPodName = domainUid + "-admin-server"; - - // check that admin server pod is ready - logger.info("Checking that admin server pod {0} is ready in namespace {1}", - adminServerPodName, namespace); - checkPodReadyAndServiceExists(adminServerPodName, domainUid, namespace); - - // check for managed server pods existence in the domain namespace - - for (int i = 1; i <= replicaCount; i++) { - if (twoClusters) { - String managedServerCluster1PodName = domainUid - + "-" + cluster1Name + "-managed-server" + i; - String managedServerCluster2PodName = domainUid - + "-" + cluster2Name + "-managed-server" + i; - logger.info("Checking that managed server pod {0} exists and ready in namespace {1}", - managedServerCluster1PodName, namespace); - checkPodReadyAndServiceExists(managedServerCluster1PodName, domainUid, namespace); - logger.info("Checking that managed server pod {0} exists and ready in namespace {1}", - managedServerCluster2PodName, namespace); - checkPodReadyAndServiceExists(managedServerCluster2PodName, domainUid, namespace); - } else { - String managedServerPodName = domainUid + "-managed-server" + i; - // check that the managed server pod exists - logger.info("Checking that managed server pod {0} exists and ready in namespace {1}", - managedServerPodName, namespace); - checkPodReadyAndServiceExists(managedServerPodName, domainUid, namespace); + if (checkPodsReady) { + String adminServerPodName = domainUid + "-admin-server"; + + // check that admin server pod is ready + logger.info("Checking that admin server pod {0} is ready in namespace {1}", + adminServerPodName, namespace); + checkPodReadyAndServiceExists(adminServerPodName, domainUid, namespace); + + // check for managed server pods existence in the domain namespace + + for (int i = 1; i <= replicaCount; i++) { + if (twoClusters) { + String managedServerCluster1PodName = domainUid + + "-" + cluster1Name + "-managed-server" + i; + String managedServerCluster2PodName = domainUid + + "-" + cluster2Name + "-managed-server" + i; + logger.info("Checking that managed server pod {0} exists and ready in namespace {1}", + managedServerCluster1PodName, namespace); + checkPodReadyAndServiceExists(managedServerCluster1PodName, domainUid, namespace); + logger.info("Checking that managed server pod {0} exists and ready in namespace {1}", + managedServerCluster2PodName, namespace); + checkPodReadyAndServiceExists(managedServerCluster2PodName, domainUid, namespace); + } else { + String managedServerPodName = domainUid + "-managed-server" + i; + // check that the managed server pod exists + logger.info("Checking that managed server pod {0} exists and ready in namespace {1}", + managedServerPodName, namespace); + checkPodReadyAndServiceExists(managedServerPodName, domainUid, namespace); + } } } } diff --git a/integration-tests/src/test/resources/wdt-models/model.sessmigr.restdisabled.yaml b/integration-tests/src/test/resources/wdt-models/model.sessmigr.restdisabled.yaml new file mode 100644 index 00000000000..7811889b997 --- /dev/null +++ b/integration-tests/src/test/resources/wdt-models/model.sessmigr.restdisabled.yaml @@ -0,0 +1,40 @@ +# Copyright (c) 2023, Oracle and/or its affiliates. +# Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl. + +domainInfo: + AdminUserName: '@@SECRET:__weblogic-credentials__:username@@' + AdminPassword: '@@SECRET:__weblogic-credentials__:password@@' + ServerStartMode: 'prod' + +topology: + Name: 'DOMAIN_NAME' + AdminServerName: "admin-server" + RestfulManagementServices: + Enabled: false + Cluster: + "cluster-1": + DynamicServers: + ServerTemplate: "cluster-1-template" + ServerNamePrefix: "managed-server" + DynamicClusterSize: 5 + MaxDynamicClusterSize: 5 + CalculatedListenPorts: false + Server: + "admin-server": + ListenPort: 7001 + ServerTemplate: + "cluster-1-template": + NetworkAccessPoint: + T3Channel: + PublicPort: 30012 + ListenPort: 30012 + PublicAddress: kubernetes + Cluster: "cluster-1" + ListenPort: 7100 + +appDeployments: + Application: + myear: + SourcePath: "wlsdeploy/applications/sessmigr-app.ear" + ModuleType: ear + Target: 'cluster-1'