Skip to content

Adding Junit5 Operator upgrade tests #1841

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 22 commits into from
Aug 4, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
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 @@ -209,6 +209,11 @@ private void uninstallAndInstallNewVersionOperatorAndVerify() throws Exception {
operator = TestUtils.createOperator(operatorMap, Operator.RestCertType.LEGACY);

checkCrdVersion();
// 250 domain needs to be restarted for scaling to work, see OWLS-83813
if (OP_NS.contains("250")) {
domain.shutdownUsingServerStartPolicy();
domain.restartUsingServerStartPolicy();
}
testClusterScaling(operator, domain, false);
}

Expand Down
9 changes: 7 additions & 2 deletions kindtest.sh
Original file line number Diff line number Diff line change
Expand Up @@ -221,5 +221,10 @@ echo 'Clean up result root...'
rm -rf "${RESULT_ROOT:?}/*"

echo 'Run tests...'
echo "Running mvn -Dit.test=${test_filter} -DPARALLEL_CLASSES=${parallel_run} -DNUMBER_OF_THREADS=${threads} -pl new-integration-tests -P integration-tests verify"
time mvn -Dit.test="${test_filter}" -DPARALLEL_CLASSES="${parallel_run}" -DNUMBER_OF_THREADS="${threads}" -pl new-integration-tests -P integration-tests verify 2>&1 | tee "${RESULT_ROOT}/kindtest.log"
if [ "${test_filter}" = "ItOperatorUpgrade" ]; then
echo "Running mvn -Dit.test=${test_filter} -pl new-integration-tests -P integration-tests verify"
time mvn -Dit.test="${test_filter}" -pl new-integration-tests -P integration-tests verify 2>&1 | tee "${RESULT_ROOT}/kindtest.log"
else
echo "Running mvn -Dit.test=${test_filter} -DPARALLEL_CLASSES=${parallel_run} -DNUMBER_OF_THREADS=${threads} -Dexclude-failsafe=ItOperatorUpgrade -pl new-integration-tests -P integration-tests verify"
time mvn -Dit.test="${test_filter}" -DPARALLEL_CLASSES="${parallel_run}" -DNUMBER_OF_THREADS="${threads}" -Dexclude-failsafe=ItOperatorUpgrade -pl new-integration-tests -P integration-tests verify 2>&1 | tee "${RESULT_ROOT}/kindtest.log"
fi
Original file line number Diff line number Diff line change
Expand Up @@ -148,8 +148,8 @@
import static oracle.weblogic.kubernetes.utils.CommonTestUtils.installAndVerifyNginx;
import static oracle.weblogic.kubernetes.utils.CommonTestUtils.installAndVerifyOperator;
import static oracle.weblogic.kubernetes.utils.CommonTestUtils.installAndVerifyPrometheus;
import static oracle.weblogic.kubernetes.utils.CommonTestUtils.replaceStringInFile;
import static oracle.weblogic.kubernetes.utils.CommonTestUtils.scaleAndVerifyCluster;
import static oracle.weblogic.kubernetes.utils.FileUtils.replaceStringInFile;
import static oracle.weblogic.kubernetes.utils.TestUtils.callWebAppAndCheckForServerNameInResponse;
import static oracle.weblogic.kubernetes.utils.TestUtils.getNextFreePort;
import static oracle.weblogic.kubernetes.utils.ThreadSafeLogger.getLogger;
Expand Down

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@
public interface TestConstants {

// domain constants
public static final String DOMAIN_VERSION = "v8";
public static final String DOMAIN_VERSION = Optional.ofNullable(System.getenv("DOMAIN_VERSION"))
.orElse("v8");
public static final String DOMAIN_API_VERSION = "weblogic.oracle/" + DOMAIN_VERSION;
public static final String ADMIN_SERVER_NAME_BASE = "admin-server";
public static final String MANAGED_SERVER_NAME_BASE = "managed-server";
Expand Down Expand Up @@ -44,6 +45,8 @@ public interface TestConstants {
.orElse(REPO_DUMMY_VALUE);
public static final String REPO_EMAIL = Optional.ofNullable(System.getenv("REPO_EMAIL"))
.orElse(REPO_DUMMY_VALUE);
public static final String OPERATOR_GITHUB_CHART_REPO_URL =
"https://oracle.github.io/weblogic-kubernetes-operator/charts";

// OCR registry
public static final String OCR_SECRET_NAME = "ocr-secret";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,17 @@ public static String getOperatorImageName() {
public static boolean buildOperatorImage(String image) {
return Operator.buildImage(image);
}

/**
* Get the image name used in the Operator container.
* @param namespace namespace of the operator
* @return image name
* @throws ApiException if Kubernetes client API call fails
*/
public static String getOperatorContainerImageName(String namespace) throws ApiException {
return Operator.getOperatorContainerImage(namespace);
}

// ---------------------- domain -----------------------------------

/**
Expand Down Expand Up @@ -675,6 +686,18 @@ public static int getServiceNodePort(String namespace, String serviceName, Strin
return Service.getServiceNodePort(namespace, serviceName, channelName);
}


/**
* Get node port of a namespaced service.
*
* @param namespace name of the namespace in which to get the service
* @param serviceName name of the service
* @return node port if service is found, otherwise -1
*/
public static Integer getServiceNodePort(String namespace, String serviceName) {
return Service.getServiceNodePort(namespace, serviceName);
}

/**
* Get port of a namespaced service given the channel name.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,10 @@
import oracle.weblogic.kubernetes.actions.impl.primitive.Kubernetes;
import oracle.weblogic.kubernetes.logging.LoggingFacade;
import oracle.weblogic.kubernetes.utils.ExecResult;
import org.awaitility.core.ConditionFactory;

import static java.util.concurrent.TimeUnit.MINUTES;
import static java.util.concurrent.TimeUnit.SECONDS;
import static oracle.weblogic.kubernetes.TestConstants.ADMIN_PASSWORD_DEFAULT;
import static oracle.weblogic.kubernetes.TestConstants.ADMIN_SERVER_NAME_BASE;
import static oracle.weblogic.kubernetes.TestConstants.ADMIN_USERNAME_DEFAULT;
Expand All @@ -50,6 +53,7 @@
import static oracle.weblogic.kubernetes.assertions.impl.ClusterRoleBinding.clusterRoleBindingExists;
import static oracle.weblogic.kubernetes.assertions.impl.RoleBinding.roleBindingExists;
import static oracle.weblogic.kubernetes.utils.ThreadSafeLogger.getLogger;
import static org.awaitility.Awaitility.with;

public class Domain {

Expand Down Expand Up @@ -271,6 +275,11 @@ public static boolean scaleClusterWithRestApi(String domainUid,
String opNamespace,
String opServiceAccount) {
LoggingFacade logger = getLogger();
final ConditionFactory withStandardRetryPolicy =
with().pollDelay(10, SECONDS)
.and().with().pollInterval(10, SECONDS)
.atMost(2, MINUTES).await();

logger.info("Getting the secret of service account {0} in namespace {1}", opServiceAccount, opNamespace);
String secretName = Secret.getSecretOfServiceAccount(opNamespace, opServiceAccount);
if (secretName.isEmpty()) {
Expand Down Expand Up @@ -324,7 +333,17 @@ public static boolean scaleClusterWithRestApi(String domainUid,
.saveResults(true)
.redirect(true);

return Command.withParams(params).execute();
logger.info("Calling curl to scale the cluster");
withStandardRetryPolicy
.conditionEvaluationListener(
condition -> logger.info("Calling curl command, waiting for success "
+ "(elapsed time {0}ms, remaining time {1}ms)",
condition.getElapsedTimeInMS(),
condition.getRemainingTimeInMS()))
.until(() -> {
return Command.withParams(params).execute();
});
return true;
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

import java.util.Optional;

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.actions.impl.primitive.Helm;
Expand All @@ -15,6 +16,7 @@
import static oracle.weblogic.kubernetes.TestConstants.IMAGE_NAME_OPERATOR;
import static oracle.weblogic.kubernetes.TestConstants.OPERATOR_DOCKER_BUILD_SCRIPT;
import static oracle.weblogic.kubernetes.TestConstants.REPO_NAME;
import static oracle.weblogic.kubernetes.actions.impl.primitive.Kubernetes.getContainerImage;

/**
* Action class with implementation methods for Operator.
Expand Down Expand Up @@ -101,4 +103,15 @@ public static boolean buildImage(String image) {
.command(command))
.execute();
}

/**
* Get the container's image in the pod.
* @param namespace name of the pod's namespace
* @return image used for the container
* @throws ApiException if Kubernetes client API call fails
*/
public static String getOperatorContainerImage(String namespace) throws ApiException {
return getContainerImage(namespace, "weblogic-operator-",
String.format("weblogic.operatorName in (%s)", namespace), null);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,17 @@ public static int getServiceNodePort(String namespace, String serviceName, Strin
return Kubernetes.getServiceNodePort(namespace, serviceName, channelName);
}

/**
* Get node port of a namespaced service.
*
* @param namespace name of the namespace in which to get the service
* @param serviceName name of the service
* @return node port if service and channel is found, otherwise -1
*/
public static int getServiceNodePort(String namespace, String serviceName) {
return Kubernetes.getServiceNodePort(namespace, serviceName);
}

/**
* Get port of a namespaced service given the channel name.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,6 @@ public static boolean addRepo(String repoName, String repoUrl) {
*/
private static String valuesToString(Map<String, Object> helmValues) {
StringBuffer valuesString = new StringBuffer("");

// values can be Map or String
for (Map.Entry<String,Object> entry : helmValues.entrySet()) {
if (entry.getValue() instanceof Map) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
import io.kubernetes.client.openapi.models.V1ClusterRoleList;
import io.kubernetes.client.openapi.models.V1ConfigMap;
import io.kubernetes.client.openapi.models.V1ConfigMapList;
import io.kubernetes.client.openapi.models.V1Container;
import io.kubernetes.client.openapi.models.V1ContainerStatus;
import io.kubernetes.client.openapi.models.V1Deployment;
import io.kubernetes.client.openapi.models.V1DeploymentList;
Expand Down Expand Up @@ -480,7 +481,7 @@ public static boolean deletePod(String name, String namespace) {
public static V1Pod getPod(String namespace, String labelSelector, String podName) throws ApiException {
V1PodList pods = listPods(namespace, labelSelector);
for (var pod : pods.getItems()) {
if (podName.equals(pod.getMetadata().getName())) {
if (pod.getMetadata().getName().contains(podName)) {
return pod;
}
}
Expand Down Expand Up @@ -557,6 +558,36 @@ public static int getContainerRestartCount(
return 0;
}

/**
* Get the container's image in the pod.
* @param namespace name of the pod's namespace
* @param labelSelector in the format "weblogic.operatorName in (%s)"
* @param podName name of the pod
* @param containerName name of the container, null if there is only one container
* @return image used for the container
* @throws ApiException if Kubernetes client API call fails
*/
public static String getContainerImage(String namespace, String podName,
String labelSelector, String containerName) throws ApiException {
V1Pod pod = getPod(namespace, labelSelector, podName);
if (pod != null) {
List<V1Container> containerList = pod.getSpec().getContainers();
if (containerName == null && containerList.size() >= 1) {
return containerList.get(0).getImage();
} else {
for (V1Container container : containerList) {
if (containerName.equals(container.getName())) {
return container.getImage();
}
}
getLogger().info("Container {0} doesn't exist in pod {1} namespace {2}",
containerName, podName, namespace);
}
} else {
getLogger().severe("Pod " + podName + " doesn't exist in namespace " + namespace);
}
return null;
}

/**
* Get the weblogic.domainRestartVersion label from a given pod.
Expand Down Expand Up @@ -1699,6 +1730,23 @@ public static int getServiceNodePort(String namespace, String serviceName, Strin
return -1;
}

/**
* Get port of a namespaced service.
*
* @param namespace name of the namespace in which to get the service
* @param serviceName name of the service
* @return node port if service found otherwise -1
*/
public static Integer getServiceNodePort(String namespace, String serviceName) {
List<V1Service> services = listServices(namespace).getItems();
for (V1Service service : services) {
if (service.getMetadata().getName().startsWith(serviceName)) {
return service.getSpec().getPorts().get(0).getNodePort();
}
}
return -1;
}

/**
* Get port of a namespaced service given the channel name.
*
Expand Down
Loading