Skip to content

Use kubectl exec to fix a test hanging issue #1834

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 27, 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 @@ -80,7 +80,7 @@
import static oracle.weblogic.kubernetes.actions.TestActions.dockerLogin;
import static oracle.weblogic.kubernetes.actions.TestActions.dockerPush;
import static oracle.weblogic.kubernetes.actions.TestActions.patchDomainCustomResource;
import static oracle.weblogic.kubernetes.assertions.TestAssertions.appAccessibleInPod;
import static oracle.weblogic.kubernetes.assertions.TestAssertions.appAccessibleInPodKubectl;
import static oracle.weblogic.kubernetes.assertions.TestAssertions.appNotAccessibleInPod;
import static oracle.weblogic.kubernetes.assertions.TestAssertions.doesImageExist;
import static oracle.weblogic.kubernetes.assertions.TestAssertions.domainResourceImagePatched;
Expand Down Expand Up @@ -956,7 +956,7 @@ private void checkAppIsRunning(
namespace,
condition.getElapsedTimeInMS(),
condition.getRemainingTimeInMS()))
.until(() -> appAccessibleInPod(
.until(() -> appAccessibleInPodKubectl(
namespace,
podName,
internalPort,
Expand Down Expand Up @@ -1051,7 +1051,7 @@ private static void collectAppAvaiability(
while (!v2AppAvailable) {
v2AppAvailable = true;
for (int i = 1; i <= replicaCount; i++) {
v2AppAvailable = v2AppAvailable && appAccessibleInPod(
v2AppAvailable = v2AppAvailable && appAccessibleInPodKubectl(
namespace,
managedServerPrefix + i,
internalPort,
Expand All @@ -1061,7 +1061,7 @@ private static void collectAppAvaiability(

int count = 0;
for (int i = 1; i <= replicaCount; i++) {
if (appAccessibleInPod(
if (appAccessibleInPodKubectl(
namespace,
managedServerPrefix + i,
internalPort,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -389,6 +389,27 @@ public static boolean appAccessibleInPod(
return Application.appAccessibleInPod(namespace, podName, port, appPath, expectedResponse);
}

/**
* Check if an application is accessible inside a WebLogic server pod using
* "kubectl exec" command.
*
* @param namespace Kubernetes namespace where the WebLogic server pod is running
* @param podName name of the WebLogic server pod
* @param port internal port of the managed server running in the pod
* @param appPath path to access the application
* @param expectedResponse the expected response from the application
* @return true if the command succeeds
*/
public static boolean appAccessibleInPodKubectl(
String namespace,
String podName,
String port,
String appPath,
String expectedResponse
) {
return Application.appAccessibleInPodKubectl(namespace, podName, port, appPath, expectedResponse);
}

/**
* Check if an application is Not running inside a WebLogic server pod.
* .
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
import java.io.IOException;

import io.kubernetes.client.openapi.ApiException;
import oracle.weblogic.kubernetes.actions.impl.primitive.Command;
import oracle.weblogic.kubernetes.actions.impl.primitive.CommandParams;
import oracle.weblogic.kubernetes.utils.ExecResult;

import static oracle.weblogic.kubernetes.actions.TestActions.execCommand;
Expand Down Expand Up @@ -78,6 +80,42 @@ public static boolean appAccessibleInPod(
getLogger().warning(String.format("Failed to find pod %s to check the app", podName));
return false;
}
}
}

/**
* Check if an application is accessible inside a WebLogic server pod.
*
* @param namespace Kubernetes namespace where the WebLogic server pod is running
* @param podName name of the WebLogic server pod
* @param port internal port of the managed server running in the pod
* @param appPath path to access the application
* @param expectedResponse expected response from the app
* @return true if the command succeeds
*/
public static boolean appAccessibleInPodKubectl(
String namespace,
String podName,
String port,
String appPath,
String expectedResponse
) {

// calling "kubectl exec" command to access the app inside a pod
String cmd = String.format(
"kubectl -n %s exec -it %s -- /bin/bash -c 'curl http://%s:%s/%s'",
namespace,
podName,
podName,
port,
appPath);

CommandParams params = Command
.defaultCommandParams()
.command(cmd)
.saveResults(true)
.redirect(false)
.verbose(false);
return Command.withParams(params).executeAndVerify(expectedResponse);
}

}