|
38 | 38 | import oracle.weblogic.kubernetes.annotations.IntegrationTest; |
39 | 39 | import oracle.weblogic.kubernetes.annotations.Namespaces; |
40 | 40 | import oracle.weblogic.kubernetes.logging.LoggingFacade; |
| 41 | +import org.awaitility.core.ConditionFactory; |
41 | 42 | import org.junit.jupiter.api.AfterAll; |
42 | 43 | import org.junit.jupiter.api.BeforeAll; |
43 | 44 | import org.junit.jupiter.api.DisplayName; |
|
48 | 49 | import org.junit.jupiter.params.ParameterizedTest; |
49 | 50 | import org.junit.jupiter.params.provider.ValueSource; |
50 | 51 |
|
| 52 | +import static java.util.concurrent.TimeUnit.MINUTES; |
| 53 | +import static java.util.concurrent.TimeUnit.SECONDS; |
51 | 54 | import static oracle.weblogic.kubernetes.TestConstants.ADMIN_PASSWORD_DEFAULT; |
52 | 55 | import static oracle.weblogic.kubernetes.TestConstants.ADMIN_USERNAME_DEFAULT; |
53 | 56 | import static oracle.weblogic.kubernetes.TestConstants.BASE_IMAGES_REPO_SECRET; |
|
109 | 112 | import static oracle.weblogic.kubernetes.utils.SecretUtils.createSecretWithUsernamePassword; |
110 | 113 | import static oracle.weblogic.kubernetes.utils.ThreadSafeLogger.getLogger; |
111 | 114 | import static oracle.weblogic.kubernetes.utils.WLSTUtils.executeWLSTScript; |
| 115 | +import static org.awaitility.Awaitility.with; |
112 | 116 | import static org.junit.jupiter.api.Assertions.assertDoesNotThrow; |
113 | 117 | import static org.junit.jupiter.api.Assertions.assertEquals; |
114 | 118 | import static org.junit.jupiter.api.Assertions.assertFalse; |
@@ -155,6 +159,10 @@ class ItKubernetesEvents { |
155 | 159 |
|
156 | 160 | private static LoggingFacade logger = null; |
157 | 161 |
|
| 162 | + public static ConditionFactory withLongRetryPolicy = with().pollDelay(2, SECONDS) |
| 163 | + .and().with().pollInterval(10, SECONDS) |
| 164 | + .atMost(10, MINUTES).await(); |
| 165 | + |
158 | 166 | /** |
159 | 167 | * Assigns unique namespaces for operator and domains. |
160 | 168 | * Pull WebLogic image if running tests in Kind cluster. |
@@ -188,7 +196,7 @@ public static void initAll(@Namespaces(6) List<String> namespaces) { |
188 | 196 | externalRestHttpsPort = getServiceNodePort(opNamespace, "external-weblogic-operator-svc"); |
189 | 197 |
|
190 | 198 | // This test uses the operator restAPI to scale the domain. To do this in OKD cluster, |
191 | | - // we need to expose the external service as route and set tls termination to passthrough |
| 199 | + // we need to expose the external service as route and set tls termination to passthrough |
192 | 200 | logger.info("Create a route for the operator external service - only for OKD"); |
193 | 201 | String opExternalSvc = createRouteForOKD("external-weblogic-operator-svc", opNamespace); |
194 | 202 | // Patch the route just created to set tls termination to passthrough |
@@ -292,54 +300,82 @@ void testDomainK8sEventsNonExistingCluster() { |
292 | 300 | } |
293 | 301 |
|
294 | 302 | /** |
295 | | - * Test the following domain events are logged when domain resource goes through various life cycle stages. |
296 | | - * Patch the domain resource to remove the webLogicCredentialsSecret and verify DomainChanged is |
297 | | - * logged when operator processes the domain resource changes. |
298 | | - * Verifies DomainProcessingRetrying is logged when operator retries the failed domain resource |
299 | | - * changes since webLogicCredentialsSecret is still missing. |
| 303 | + * Test the following domain events are logged when domain resource goes through introspector failure. |
| 304 | + * Patch the domain resource to shutdown servers. |
| 305 | + * Patch the domain resource to point to a bad DOMAIN_HOME and update serverStartPolicy to IF_NEEDED. |
| 306 | + * Verifies DomainProcessingFailed event is logged. |
300 | 307 | * Verifies DomainProcessingAborted is logged when operator exceeds the maximum retries and gives |
301 | 308 | * up processing the domain resource. |
| 309 | + * Cleanup by patching the domain resource to a valid location and introspectVersion to bring up all servers again. |
302 | 310 | */ |
303 | 311 | @Order(4) |
304 | 312 | @Test |
305 | 313 | @DisplayName("Test domain events for failed/retried domain life cycle changes") |
306 | 314 | void testDomainK8SEventsFailed() { |
307 | 315 | V1Patch patch; |
308 | 316 | String patchStr; |
| 317 | + Domain domain = assertDoesNotThrow(() -> getDomainCustomResource(domainUid, domainNamespace1)); |
| 318 | + String originalDomainHome = domain.getSpec().getDomainHome(); |
309 | 319 |
|
310 | 320 | OffsetDateTime timestamp = now(); |
311 | 321 | try { |
312 | | - logger.info("remove the webLogicCredentialsSecret to verify the following events" |
313 | | - + " DomainChanged, DomainProcessingRetrying and DomainProcessingAborted are logged"); |
314 | | - patchStr = "[{\"op\": \"remove\", \"path\": \"/spec/webLogicCredentialsSecret\"}]"; |
315 | | - logger.info("PatchStr for webLogicCredentialsSecret: {0}", patchStr); |
| 322 | + logger.info("Shutting down all servers in domain with serverStartPolicy : NEVER"); |
| 323 | + patchStr = "[{\"op\": \"replace\", \"path\": \"/spec/serverStartPolicy\", \"value\": \"NEVER\"}]"; |
| 324 | + patch = new V1Patch(patchStr); |
| 325 | + assertTrue(patchDomainCustomResource(domainUid, domainNamespace1, patch, V1Patch.PATCH_FORMAT_JSON_PATCH), |
| 326 | + "patchDomainCustomResource failed"); |
| 327 | + |
| 328 | + logger.info("Checking if the admin server {0} is shutdown in namespace {1}", |
| 329 | + adminServerPodName, domainNamespace1); |
| 330 | + checkPodDoesNotExist(adminServerPodName, domainUid, domainNamespace1); |
| 331 | + |
| 332 | + for (int i = 1; i <= replicaCount; i++) { |
| 333 | + logger.info("Checking if the managed server {0} is shutdown in namespace {1}", |
| 334 | + managedServerPodNamePrefix + i, domainNamespace1); |
| 335 | + checkPodDoesNotExist(managedServerPodNamePrefix + i, domainUid, domainNamespace1); |
| 336 | + } |
| 337 | + |
| 338 | + logger.info("Replace the domainHome to a nonexisting location to verify the following events" |
| 339 | + + " DomainChanged, DomainProcessingRetrying and DomainProcessingAborted are logged"); |
| 340 | + patchStr = "[{\"op\": \"replace\", " |
| 341 | + + "\"path\": \"/spec/domainHome\", \"value\": \"" + originalDomainHome + "bad\"}," |
| 342 | + + "{\"op\": \"replace\", \"path\": \"/spec/serverStartPolicy\", \"value\": \"IF_NEEDED\"}]"; |
| 343 | + logger.info("PatchStr for domainHome: {0}", patchStr); |
316 | 344 |
|
317 | 345 | patch = new V1Patch(patchStr); |
318 | 346 | assertTrue(patchDomainCustomResource(domainUid, domainNamespace1, patch, V1Patch.PATCH_FORMAT_JSON_PATCH), |
319 | | - "patchDomainCustomResource failed"); |
| 347 | + "patchDomainCustomResource failed"); |
320 | 348 |
|
321 | 349 | logger.info("verify domain changed event is logged"); |
322 | 350 | checkEvent(opNamespace, domainNamespace1, domainUid, DOMAIN_CHANGED, "Normal", timestamp); |
323 | | - |
324 | | - // logger.info("verify domain processing retrying event"); |
325 | | - // checkEvent(opNamespace, domainNamespace1, domainUid, DOMAIN_PROCESSING_RETRYING, "Normal", timestamp); |
326 | | - |
327 | 351 | logger.info("verify domain processing aborted event"); |
328 | 352 | checkEvent(opNamespace, domainNamespace1, domainUid, DOMAIN_PROCESSING_ABORTED, "Warning", timestamp); |
329 | 353 | } finally { |
| 354 | + logger.info("Restoring the domain with valid location and bringing up all servers"); |
330 | 355 | timestamp = now(); |
331 | | - // add back the webLogicCredentialsSecret |
332 | | - patchStr = "[{\"op\": \"add\", \"path\": \"/spec/webLogicCredentialsSecret\", " |
333 | | - + "\"value\" : {\"name\":\"" + wlSecretName + "\" , \"namespace\":\"" + domainNamespace1 + "\"}" |
334 | | - + "}]"; |
335 | | - logger.info("PatchStr for webLogicCredentialsSecret: {0}", patchStr); |
| 356 | + String introspectVersion = assertDoesNotThrow(() -> getNextIntrospectVersion(domainUid, domainNamespace1)); |
| 357 | + // add back the original domain home |
| 358 | + patchStr = "[" |
| 359 | + + "{\"op\": \"replace\", \"path\": \"/spec/domainHome\", \"value\": \"" + originalDomainHome + "\"}," |
| 360 | + + "{\"op\": \"add\", \"path\": \"/spec/introspectVersion\", \"value\": \"" + introspectVersion + "\"}" |
| 361 | + + "]"; |
| 362 | + logger.info("PatchStr for domainHome: {0}", patchStr); |
336 | 363 |
|
337 | 364 | patch = new V1Patch(patchStr); |
338 | 365 | assertTrue(patchDomainCustomResource(domainUid, domainNamespace1, patch, V1Patch.PATCH_FORMAT_JSON_PATCH), |
339 | | - "patchDomainCustomResource failed"); |
| 366 | + "patchDomainCustomResource failed"); |
340 | 367 |
|
341 | 368 | logger.info("verify domain changed event is logged"); |
342 | 369 | checkEvent(opNamespace, domainNamespace1, domainUid, DOMAIN_CHANGED, "Normal", timestamp); |
| 370 | + logger.info("verifying the admin server is created and started"); |
| 371 | + checkPodReadyAndServiceExists(adminServerPodName, domainUid, domainNamespace1); |
| 372 | + |
| 373 | + // verify managed server services created |
| 374 | + for (int i = 1; i <= replicaCount; i++) { |
| 375 | + logger.info("Checking managed server service/pod {0} is created in namespace {1}", |
| 376 | + managedServerPodNamePrefix + i, domainNamespace1); |
| 377 | + checkPodReadyAndServiceExists(managedServerPodNamePrefix + i, domainUid, domainNamespace1); |
| 378 | + } |
343 | 379 | } |
344 | 380 | } |
345 | 381 |
|
@@ -889,7 +925,7 @@ public static void tearDown() { |
889 | 925 | private static void checkEvent( |
890 | 926 | String opNamespace, String domainNamespace, String domainUid, |
891 | 927 | String reason, String type, OffsetDateTime timestamp) { |
892 | | - testUntil( |
| 928 | + testUntil(withLongRetryPolicy, |
893 | 929 | checkDomainEvent(opNamespace, domainNamespace, domainUid, reason, type, timestamp), |
894 | 930 | logger, |
895 | 931 | "domain event {0} to be logged in namespace {1}", |
|
0 commit comments