Skip to content

Commit e747e71

Browse files
authored
Adding diagnostic log collection feature to integration tests (#1562)
* Adding diagnostic features to integration test * wip * wip * wip * wip * initial implementation of diagnostic logging * wip * changed the implementation to use LifecycleMethodExecutionExceptionHandler * Added javadoc * fix newline * fixed javadocs in Kubernetes.java * debuggging * fix javadocs * changed the implmentation for namespace collectioin * added test status overrides * Fix javadocs * Fix for the empty namespace list * remove debug code * Get domain object lists using CustomObjectsApi * Catch the exception * Remove double message logging * wip * wip * wip * wip * wip * wip * wip * wip * wip * wip * wip * wip * fix javadoc * fixed pvc list * use RESULT_ROOT in Jenkins or tmp dir for local runs * fix comment * changes as per Ryan's comments * fix pv location * Changes as per Ryan's comments * remove getting logs for all domains * Address Mark comments * address mark's review comments * correct the typos
1 parent 6fb007a commit e747e71

File tree

12 files changed

+1029
-252
lines changed

12 files changed

+1029
-252
lines changed

new-integration-tests/src/test/java/oracle/weblogic/kubernetes/ItMiiDomain.java

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,11 @@
3131
import oracle.weblogic.domain.ServerPod;
3232
import oracle.weblogic.kubernetes.actions.impl.OperatorParams;
3333
import oracle.weblogic.kubernetes.actions.impl.primitive.HelmParams;
34+
import oracle.weblogic.kubernetes.annotations.IntegrationTest;
35+
import oracle.weblogic.kubernetes.annotations.Namespaces;
3436
import oracle.weblogic.kubernetes.annotations.tags.MustNotRunInParallel;
3537
import oracle.weblogic.kubernetes.annotations.tags.Slow;
3638
import oracle.weblogic.kubernetes.extensions.LoggedTest;
37-
import oracle.weblogic.kubernetes.extensions.Timing;
3839
import org.awaitility.core.ConditionFactory;
3940
import org.junit.jupiter.api.AfterAll;
4041
import org.junit.jupiter.api.AfterEach;
@@ -44,7 +45,6 @@
4445
import org.junit.jupiter.api.Order;
4546
import org.junit.jupiter.api.Test;
4647
import org.junit.jupiter.api.TestMethodOrder;
47-
import org.junit.jupiter.api.extension.ExtendWith;
4848

4949
import static java.util.concurrent.TimeUnit.MINUTES;
5050
import static java.util.concurrent.TimeUnit.SECONDS;
@@ -57,7 +57,6 @@
5757
import static oracle.weblogic.kubernetes.actions.TestActions.createMiiImage;
5858
import static oracle.weblogic.kubernetes.actions.TestActions.createSecret;
5959
import static oracle.weblogic.kubernetes.actions.TestActions.createServiceAccount;
60-
import static oracle.weblogic.kubernetes.actions.TestActions.createUniqueNamespace;
6160
import static oracle.weblogic.kubernetes.actions.TestActions.defaultAppParams;
6261
import static oracle.weblogic.kubernetes.actions.TestActions.defaultWitParams;
6362
import static oracle.weblogic.kubernetes.actions.TestActions.deleteDomainCustomResource;
@@ -78,12 +77,13 @@
7877
import static oracle.weblogic.kubernetes.utils.FileUtils.checkDirectory;
7978
import static org.awaitility.Awaitility.with;
8079
import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
80+
import static org.junit.jupiter.api.Assertions.assertNotNull;
8181
import static org.junit.jupiter.api.Assertions.assertTrue;
8282

8383
// Test to create model in image domain and verify the domain started successfully
8484
@TestMethodOrder(MethodOrderer.OrderAnnotation.class)
8585
@DisplayName("Test to create model in image domain and start the domain")
86-
@ExtendWith(Timing.class)
86+
@IntegrationTest
8787
class ItMiiDomain implements LoggedTest {
8888

8989
// operator constants
@@ -119,24 +119,24 @@ class ItMiiDomain implements LoggedTest {
119119

120120
/**
121121
* Install Operator.
122+
* @param namespaces list of namespaces created by the IntegrationTestWatcher by the
123+
JUnit engine parameter resolution mechanism
122124
*/
123125
@BeforeAll
124-
public static void initAll() {
126+
public static void initAll(@Namespaces(2) List<String> namespaces) {
125127
// create standard, reusable retry/backoff policy
126128
withStandardRetryPolicy = with().pollDelay(2, SECONDS)
127129
.and().with().pollInterval(10, SECONDS)
128130
.atMost(5, MINUTES).await();
129131

130132
// get a new unique opNamespace
131133
logger.info("Creating unique namespace for Operator");
132-
opNamespace = assertDoesNotThrow(() -> createUniqueNamespace(),
133-
"Failed to create unique namespace due to ApiException");
134-
logger.info("Created a new namespace called {0}", opNamespace);
134+
assertNotNull(namespaces.get(0), "Namespace list is null");
135+
opNamespace = namespaces.get(0);
135136

136137
logger.info("Creating unique namespace for Domain");
137-
domainNamespace = assertDoesNotThrow(() -> createUniqueNamespace(),
138-
"Failed to create unique namespace due to ApiException");
139-
logger.info("Created a new namespace called {0}", domainNamespace);
138+
assertNotNull(namespaces.get(1), "Namespace list is null");
139+
domainNamespace = namespaces.get(1);
140140

141141
// Create a service account for the unique opNamespace
142142
logger.info("Creating service account");

new-integration-tests/src/test/java/oracle/weblogic/kubernetes/ItSimpleDomainValidation.java

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33

44
package oracle.weblogic.kubernetes;
55

6+
import java.util.List;
7+
68
import io.kubernetes.client.custom.Quantity;
79
import io.kubernetes.client.openapi.models.V1HostPathVolumeSource;
810
import io.kubernetes.client.openapi.models.V1ObjectMeta;
@@ -18,6 +20,7 @@
1820
import oracle.weblogic.kubernetes.actions.TestActions;
1921
import oracle.weblogic.kubernetes.actions.impl.primitive.Kubernetes;
2022
import oracle.weblogic.kubernetes.annotations.IntegrationTest;
23+
import oracle.weblogic.kubernetes.annotations.Namespaces;
2124
import oracle.weblogic.kubernetes.annotations.tags.Slow;
2225
import oracle.weblogic.kubernetes.extensions.LoggedTest;
2326
import org.junit.jupiter.api.DisplayName;
@@ -33,23 +36,26 @@
3336
import static oracle.weblogic.kubernetes.assertions.TestAssertions.domainExists;
3437
import static org.awaitility.Awaitility.with;
3538
import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
39+
import static org.junit.jupiter.api.Assertions.assertNotNull;
3640
import static org.junit.jupiter.api.Assertions.assertTrue;
3741

3842
@DisplayName("Simple validation of basic domain functions")
43+
// Every test class needs to tagged with this annotation for log collection, diagnostic messages logging
44+
// and namespace creation.
3945
@IntegrationTest
4046
class ItSimpleDomainValidation implements LoggedTest {
4147

4248
@Test
4349
@DisplayName("Create a domain")
4450
@Slow
45-
public void testCreatingDomain() {
51+
public void testCreatingDomain(@Namespaces(1) List<String> namespaces) {
4652

4753
final String domainUid = "domain1";
4854

4955
// get a new unique namespace
50-
final String namespace = assertDoesNotThrow(TestActions::createUniqueNamespace,
51-
"Failed to create unique namespace due to ApiException");
52-
logger.info("Got a new namespace called {0}", namespace);
56+
logger.info("Creating unique namespace for Operator");
57+
assertNotNull(namespaces.get(0), "Namespace list is null");
58+
String namespace = namespaces.get(0);
5359

5460
// Create a service account for the unique namespace
5561
final String serviceAccountName = namespace + "-sa";
@@ -91,7 +97,7 @@ public void testCreatingDomain() {
9197
.putCapacityItem("storage", Quantity.fromString("10Gi"))
9298
.persistentVolumeReclaimPolicy("Recycle")
9399
.hostPath(new V1HostPathVolumeSource()
94-
.path(System.getProperty("java.io.tmpdir") + domainUid + "-persistentVolume")))
100+
.path(System.getProperty("java.io.tmpdir") + "/" + domainUid + "-persistentVolume")))
95101
.metadata(new V1ObjectMetaBuilder()
96102
.withName(pvName)
97103
.withNamespace(namespace)

new-integration-tests/src/test/java/oracle/weblogic/kubernetes/ItSimpleOperatorValidation.java

Lines changed: 13 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -4,23 +4,24 @@
44
package oracle.weblogic.kubernetes;
55

66
import java.util.Arrays;
7+
import java.util.List;
78

89
import io.kubernetes.client.openapi.ApiException;
910
import io.kubernetes.client.openapi.models.V1ObjectMeta;
1011
import io.kubernetes.client.openapi.models.V1ServiceAccount;
1112
import oracle.weblogic.kubernetes.actions.impl.OperatorParams;
1213
import oracle.weblogic.kubernetes.actions.impl.primitive.HelmParams;
14+
import oracle.weblogic.kubernetes.annotations.IntegrationTest;
15+
import oracle.weblogic.kubernetes.annotations.Namespaces;
1316
import oracle.weblogic.kubernetes.annotations.tags.MustNotRunInParallel;
1417
import oracle.weblogic.kubernetes.annotations.tags.Slow;
1518
import oracle.weblogic.kubernetes.extensions.LoggedTest;
16-
import oracle.weblogic.kubernetes.extensions.Timing;
1719
import org.junit.jupiter.api.AfterEach;
1820
import org.junit.jupiter.api.DisplayName;
1921
import org.junit.jupiter.api.MethodOrderer;
2022
import org.junit.jupiter.api.Order;
2123
import org.junit.jupiter.api.Test;
2224
import org.junit.jupiter.api.TestMethodOrder;
23-
import org.junit.jupiter.api.extension.ExtendWith;
2425

2526
import static java.util.concurrent.TimeUnit.MINUTES;
2627
import static java.util.concurrent.TimeUnit.SECONDS;
@@ -35,6 +36,7 @@
3536
import static org.assertj.core.api.Assertions.assertThat;
3637
import static org.assertj.core.api.Assertions.assertThatCode;
3738
import static org.awaitility.Awaitility.with;
39+
import static org.junit.jupiter.api.Assertions.assertNotNull;
3840

3941

4042
// this is a POC for a new way of writing tests.
@@ -52,10 +54,7 @@
5254
// order. this is controlled with the TestMethodOrder annotation
5355
@TestMethodOrder(MethodOrderer.OrderAnnotation.class)
5456
@DisplayName("Simple validation of basic operator functions")
55-
// this is an example of registering an extension that will time how long each test takes.
56-
@ExtendWith(Timing.class)
57-
// by implementing the LoggedTest, we will automatically get a logger injected and it
58-
// will also automatically log entry/exit messages for each test method.
57+
@IntegrationTest
5958
class ItSimpleOperatorValidation implements LoggedTest {
6059

6160
private HelmParams opHelmParams = null;
@@ -72,22 +71,19 @@ class ItSimpleOperatorValidation implements LoggedTest {
7271
// like these two:
7372
@Slow
7473
@MustNotRunInParallel
75-
public void testInstallingOperator() {
74+
public void testInstallingOperator(@Namespaces(3) List<String> namespaces) {
7675
// this first example is an operation that we wait for.
7776
// installOperator() is one of our custom, reusable actions.
7877
// imagine that installOperator() will try to install the operator, by creating
7978
// the kubernetes deployment. this will complete quickly, and will either be
8079
// successful or not.
81-
82-
// get a new unique opNamespace
83-
opNamespace = createNamespace();
84-
logger.info(String.format("Created a new namespace called %s", opNamespace));
85-
86-
domainNamespace1 = createNamespace();
87-
logger.info(String.format("Created a new namespace called %s", domainNamespace1));
88-
89-
domainNamespace2 = createNamespace();
90-
logger.info(String.format("Created a new namespace called %s", domainNamespace2));
80+
// get unique namespaces for operator and domains
81+
namespaces.forEach((namespace) -> {
82+
assertNotNull(namespace, "Namespace " + namespace + "is null");
83+
});
84+
opNamespace = namespaces.get(0);
85+
domainNamespace1 = namespaces.get(1);
86+
domainNamespace2 = namespaces.get(2);
9187

9288
// Create a service account for the unique opNamespace
9389
final String serviceAccountName = opNamespace + "-sa";

new-integration-tests/src/test/java/oracle/weblogic/kubernetes/ItWitValidation.java

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
import java.util.List;
99
import java.util.Map;
1010

11+
import oracle.weblogic.kubernetes.annotations.IntegrationTest;
1112
import oracle.weblogic.kubernetes.extensions.LoggedTest;
1213
import org.junit.jupiter.api.DisplayName;
1314
import org.junit.jupiter.api.Test;
@@ -25,6 +26,7 @@
2526
import static org.assertj.core.api.Assertions.assertThat;
2627

2728
@DisplayName("Simple validation of basic WIT functions")
29+
@IntegrationTest
2830
class ItWitValidation implements LoggedTest {
2931
private static final String WDT_MODEL_FILE = "model1-wls.yaml";
3032
private static final String IMAGE_NAME = "test-mii-image-2";
@@ -40,17 +42,17 @@ public void testCreatingMiiImage() {
4042

4143
// build the model file list
4244
final List<String> modelList = Collections.singletonList(MODEL_DIR + "/" + WDT_MODEL_FILE);
43-
45+
4446
// build an application archive using what is in resources/apps/APP_NAME
4547
boolean archiveBuilt = buildAppArchive(
4648
defaultAppParams()
4749
.srcDir(APP_NAME));
48-
50+
4951
assertThat(archiveBuilt)
5052
.as("Create an app archive")
5153
.withFailMessage("Failed to create app archive for " + APP_NAME)
5254
.isTrue();
53-
55+
5456
// build the archive list
5557
String zipFile = String.format("%s/%s.zip", ARCHIVE_DIR, APP_NAME);
5658
List<String> archiveList = Collections.singletonList(zipFile);
@@ -77,6 +79,5 @@ public void testCreatingMiiImage() {
7779
.isTrue();
7880

7981
dockerImageExists(IMAGE_NAME, IMAGE_TAG);
80-
}
82+
}
8183
}
82-

new-integration-tests/src/test/java/oracle/weblogic/kubernetes/actions/TestActions.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -443,7 +443,7 @@ public static boolean deleteClusterRoleBinding(String name) {
443443
public static boolean helmList(HelmParams params) {
444444
return Helm.list(params);
445445
}
446-
446+
447447
// ------------------------ Application Builder -------------------------
448448

449449
/**

0 commit comments

Comments
 (0)