Skip to content

Improve test verification #1777

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 3 commits into from
Jul 2, 2020
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 @@ -410,7 +410,7 @@ public void testPatchAppV2() {
} catch (InterruptedException ie) {
// do nothing
}

// check the application availability data that we have collected, and see if
// the application has been available all the time since the beginning of this test method
logger.info("Verify that V2 application was available when domain {0} was being patched with image {1}",
Expand Down Expand Up @@ -1045,7 +1045,7 @@ private static void collectAppAvaiability(
String appPath
) {
boolean v2AppAvailable = false;

// Access the pod periodically to check application's availability across the duration
// of patching the domain with newer version of the application.
while (!v2AppAvailable) {
Expand Down Expand Up @@ -1074,6 +1074,7 @@ private static void collectAppAvaiability(

if (count == 0) {
logger.info("XXXXXXXXXXX: application not available XXXXXXXX");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What are the "XXX" and "YYY"? What application is it?

Copy link
Member Author

@doxiao doxiao Jul 1, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Those "XXX" and "YYY" are tokens to make it easier for people to notice the failure/healthy conditions. The failure case "XXX" is INFO, and "YYY" is "FINE".

break;
} else {
logger.fine("YYYYYYYYYYY: application available YYYYYYYY count = " + count);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,8 @@
import static oracle.weblogic.kubernetes.actions.TestActions.deletePod;
import static oracle.weblogic.kubernetes.actions.TestActions.getOperatorPodName;
import static oracle.weblogic.kubernetes.actions.TestActions.getPodCreationTimestamp;
import static oracle.weblogic.kubernetes.assertions.TestAssertions.operatorIsReady;
import static oracle.weblogic.kubernetes.assertions.TestAssertions.isOperatorPodRestarted;
import static oracle.weblogic.kubernetes.assertions.TestAssertions.verifyRollingRestartOccurred;
import static oracle.weblogic.kubernetes.assertions.impl.Kubernetes.isPodRestarted;
import static oracle.weblogic.kubernetes.utils.CommonMiiTestUtils.createMiiDomainAndVerify;
import static oracle.weblogic.kubernetes.utils.CommonPatchTestUtils.checkPodRestartVersionUpdated;
import static oracle.weblogic.kubernetes.utils.CommonTestUtils.createSecretWithUsernamePassword;
Expand Down Expand Up @@ -235,18 +234,14 @@ private void restartOperatorAndVerify() {
opNamespace,
condition.getElapsedTimeInMS(),
condition.getRemainingTimeInMS()))
.until(assertDoesNotThrow(() -> operatorIsReady(opNamespace),
"operatorIsReady failed with ApiException"));
.until(assertDoesNotThrow(() -> isOperatorPodRestarted(opNamespace, opPodCreationTime),
"Failed to check if the operator is restarted with ApiException"));

String opPodNameNew =
String opPodNameNew =
assertDoesNotThrow(() -> getOperatorPodName(TestConstants.OPERATOR_RELEASE_NAME, opNamespace),
"Failed to get the name of the operator pod");
"Failed to get the name of the operator pod");

assertFalse(opPodNameNew.equals(opPodName),
"The operator names before and after a restart should be different");

assertTrue(assertDoesNotThrow(() -> isPodRestarted(opPodNameNew, opNamespace, opPodCreationTime),
"Failed to check the operator for its new creation time with ApiException"),
"Operator restart failed");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -446,6 +446,22 @@ public static Callable<Boolean> isPodRestarted(
};
}

/**
* Check if the oeprator pod in a given namespace is restarted based on podCreationTimestamp.
*
* @param namespace in which the pod is running
* @param timestamp the initial podCreationTimestamp
* @return true if the pod new timestamp is not equal to initial PodCreationTimestamp otherwise false
*/
public static Callable<Boolean> isOperatorPodRestarted(
String namespace,
DateTime timestamp
) {
return () -> {
return Kubernetes.isOperatorPodRestarted(namespace, timestamp);
};
}

/**
* Verify the pod state is not changed.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -776,4 +776,31 @@ public static void copyFileToPod(String namespace,
Copy copy = new Copy(apiClient);
copy.copyFileToPod(namespace, pod, container, srcPath, destPath);
}

/**
* Check if the operator pod in the given namespace is restarted based on podCreationTimestamp.
*
* @param namespace in which the operator pod is running
* @param timestamp the initial podCreationTimestamp
* @return true if the pod's creation timestamp is later than the initial PodCreationTimestamp
* @throws ApiException when query fails
*/
public static Boolean isOperatorPodRestarted(String namespace, DateTime timestamp) throws ApiException {
String labelSelector = String.format("weblogic.operatorName in (%s)", namespace);
V1Pod pod = getPod(namespace, labelSelector, "weblogic-operator-");
if (pod != null) {
// get the podCondition with the 'Ready' type field
V1PodCondition v1PodReadyCondition = pod.getStatus().getConditions().stream()
.filter(v1PodCondition -> "Ready".equals(v1PodCondition.getType()))
.findAny()
.orElse(null);

if (v1PodReadyCondition != null
&& v1PodReadyCondition.getStatus().equalsIgnoreCase("true")) {
String podName = pod.getMetadata().getName();
return isPodRestarted(podName, namespace, timestamp);
}
}
return false;
}
}