Skip to content

OWLS-102288 fix test code #3391

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Sep 8, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@
import static oracle.weblogic.kubernetes.utils.ClusterUtils.addClusterToDomain;
import static oracle.weblogic.kubernetes.utils.ClusterUtils.createClusterAndVerify;
import static oracle.weblogic.kubernetes.utils.ClusterUtils.createClusterResource;
import static oracle.weblogic.kubernetes.utils.ClusterUtils.removeReplicasSettingAndVerify;
import static oracle.weblogic.kubernetes.utils.ClusterUtils.scaleCluster;
import static oracle.weblogic.kubernetes.utils.CommonTestUtils.checkPodReadyAndServiceExists;
import static oracle.weblogic.kubernetes.utils.CommonTestUtils.checkServiceExists;
Expand Down Expand Up @@ -413,17 +414,20 @@ void testDomainK8sEventsScalePastMaxWithoutChangingIntrospectVersion() {
void testDomainK8sEventsScalePastMaxAndChangeIntrospectVersion() {
OffsetDateTime timestamp = now();
try {
logger.info("Scaling cluster using patching");
removeReplicasSettingAndVerify(domainUid, cluster1Name, domainNamespace3, replicaCount,
managedServerPodNamePrefix);

String introspectVersion = assertDoesNotThrow(() -> getNextIntrospectVersion(domainUid, domainNamespace3));
assertFalse(scaleCluster(cluster1Name, domainNamespace3, 3), "failed to scale cluster via patching");
String patchStr
= "["
+ "{\"op\": \"replace\", \"path\": \"/spec/introspectVersion\", \"value\": \"" + introspectVersion + "\"}"
+ "{\"op\": \"replace\", \"path\": \"/spec/introspectVersion\", \"value\": \"" + introspectVersion + "\"},"
+ "{\"op\": \"replace\", \"path\": \"/spec/replicas\", \"value\": 3}"
+ "]";

logger.info("Updating introspect version using patch string: {0}", patchStr);
assertTrue(patchDomainCustomResource(domainUid, domainNamespace3, new V1Patch(patchStr),
V1Patch.PATCH_FORMAT_JSON_PATCH), "Patch domain failed");
V1Patch.PATCH_FORMAT_JSON_PATCH), "Patch domain did not fail as expected");


logger.info("verify the Failed event is generated");
checkFailedEvent(opNamespace, domainNamespace3, domainUid, REPLICAS_TOO_HIGH_ERROR, "Warning", timestamp);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import static oracle.weblogic.kubernetes.actions.impl.Cluster.listClusterCustomResources;
import static oracle.weblogic.kubernetes.assertions.TestAssertions.clusterDoesNotExist;
import static oracle.weblogic.kubernetes.assertions.TestAssertions.clusterExists;
import static oracle.weblogic.kubernetes.utils.CommonTestUtils.checkPodReadyAndServiceExists;
import static oracle.weblogic.kubernetes.utils.CommonTestUtils.testUntil;
import static oracle.weblogic.kubernetes.utils.ThreadSafeLogger.getLogger;
import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
Expand Down Expand Up @@ -154,4 +155,25 @@ public static DomainResource addClusterToDomain(String clusterResName, String na
domain.getSpec().withCluster(new V1LocalObjectReference().name(clusterResName));
return domain;
}

/**
* Remove the replicas setting from a cluster resource.
* @param domainUid uid of the domain
* @param clusterName name of the cluster resource
* @param namespace namespace
* @param replicaCount original replicaCount
* @param msPodNamePrefix prefix of managed server pod names
* */
public static void removeReplicasSettingAndVerify(String domainUid, String clusterName, String namespace,
int replicaCount, String msPodNamePrefix) {
getLogger().info("Remove replicas setting from cluster resource {0} in namespace {1}", clusterName, namespace);
String patchStr = "[{\"op\": \"remove\",\"path\": \"/spec/replicas\"}]";
assertTrue(patchClusterCustomResource(clusterName, namespace, new V1Patch(patchStr),
V1Patch.PATCH_FORMAT_JSON_PATCH), "Patch cluster resource failed");

// verify there is no pod created larger than max size of cluster
for (int i = 1; i <= replicaCount; i++) {
checkPodReadyAndServiceExists(msPodNamePrefix + i, domainUid, namespace);
}
}
}