Skip to content

Commit

Permalink
Merge branch 'monexpnewtest' into 'main'
Browse files Browse the repository at this point in the history
added test for monitoring exported side car exporting metrics from domain with  rest management services disabled

See merge request weblogic-cloud/weblogic-kubernetes-operator!4400
  • Loading branch information
rjeberhard committed Aug 21, 2023
2 parents 87fba46 + 60dc6d4 commit b6f27d2
Show file tree
Hide file tree
Showing 3 changed files with 157 additions and 31 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,15 @@
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;
import org.junit.jupiter.api.Tag;
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;
Expand All @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -137,7 +144,7 @@ class ItMonitoringExporterSideCar {
*/
@BeforeAll

public static void initAll(@Namespaces(6) List<String> namespaces) {
public static void initAll(@Namespaces(7) List<String> namespaces) {

logger = getLogger();

Expand Down Expand Up @@ -170,9 +177,13 @@ public static void initAll(@Namespaces(6) List<String> 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);
Expand Down Expand Up @@ -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<String> ns = new ArrayList<>();
ns.add(domain4Namespace);
LoggingUtil.generateLog(this, ns);
shutdownDomain(domain4Uid, domain4Namespace);
}
}
}

private void changeMonitoringExporterSideCarConfig(String configYamlFile, String domainUid,
String domainNamespace,
String configSearchKey,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -1024,48 +1056,50 @@ 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
logger.info("Create model in image domain {0} in namespace {1} using image {2}",
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);
}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -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'

0 comments on commit b6f27d2

Please sign in to comment.