From 84d82badea8dd43ee9ac504fe5d1f74e839ed5a4 Mon Sep 17 00:00:00 2001 From: Maggie He Date: Mon, 25 Mar 2019 12:14:12 -0700 Subject: [PATCH 01/13] initial version for server scope podrestart --- .../kubernetes/operator/ITPodsRestart.java | 394 ++++++++++++++++++ .../kubernetes/operator/utils/Domain.java | 156 ++++++- .../kubernetes/operator/utils/TestUtils.java | 78 +++- .../src/test/resources/annotation.domain.yaml | 46 ++ .../cont.security.context.domain.yaml | 58 +++ .../pod.security.context.domain.yaml | 58 +++ .../src/test/resources/resource.domain.yaml | 61 +++ .../src/test/resources/secret.domain.yaml | 49 +++ 8 files changed, 898 insertions(+), 2 deletions(-) create mode 100644 integration-tests/src/test/java/oracle/kubernetes/operator/ITPodsRestart.java create mode 100644 integration-tests/src/test/resources/annotation.domain.yaml create mode 100644 integration-tests/src/test/resources/cont.security.context.domain.yaml create mode 100644 integration-tests/src/test/resources/pod.security.context.domain.yaml create mode 100644 integration-tests/src/test/resources/resource.domain.yaml create mode 100644 integration-tests/src/test/resources/secret.domain.yaml diff --git a/integration-tests/src/test/java/oracle/kubernetes/operator/ITPodsRestart.java b/integration-tests/src/test/java/oracle/kubernetes/operator/ITPodsRestart.java new file mode 100644 index 00000000000..24baa0b1136 --- /dev/null +++ b/integration-tests/src/test/java/oracle/kubernetes/operator/ITPodsRestart.java @@ -0,0 +1,394 @@ +// Copyright 2018, Oracle Corporation and/or its affiliates. All rights reserved. +// Licensed under the Universal Permissive License v 1.0 as shown at +// http://oss.oracle.com/licenses/upl. + +package oracle.kubernetes.operator; + +import java.util.Map; +import oracle.kubernetes.operator.utils.Domain; +import oracle.kubernetes.operator.utils.Operator; +import oracle.kubernetes.operator.utils.TestUtils; +import org.junit.AfterClass; +import org.junit.Assert; +import org.junit.Assume; +import org.junit.BeforeClass; +import org.junit.FixMethodOrder; +import org.junit.Test; +import org.junit.runners.MethodSorters; + +/** + * Simple JUnit test file used for testing Operator. + * + *

This test is used for testing pods being restarted by some properties change. + */ +@FixMethodOrder(MethodSorters.NAME_ASCENDING) +public class ITPodsRestart extends BaseTest { + + private static Domain domain = null; + private static Operator operator1; + private static String domainUid = ""; + + /** + * This method gets called only once before any of the test methods are executed. It does the + * initialization of the integration test properties defined in OperatorIT.properties and setting + * the resultRoot, pvRoot and projectRoot attributes. Create Operator1 and domainOnPVUsingWLST + * with admin server and 1 managed server if they are not running + * + * @throws Exception + */ + @BeforeClass + public static void staticPrepare() throws Exception { + // initialize test properties and create the directories + if (!QUICKTEST) { + initialize(APP_PROPS_FILE); + + logger.info("Checking if operator1 and domain are running, if not creating"); + if (operator1 == null) { + operator1 = TestUtils.createOperator(OPERATOR1_YAML); + } + + domain = createPodsRestartdomain(); + Assert.assertNotNull(domain); + } + } + + /** + * Releases k8s cluster lease, archives result, pv directories + * + * @throws Exception + */ + @AfterClass + public static void staticUnPrepare() throws Exception { + if (!QUICKTEST) { + logger.info("+++++++++++++++++++++++++++++++++---------------------------------+"); + logger.info("BEGIN"); + logger.info("Run once, release cluster lease"); + + // destroyPodsRestartdomain(); + // tearDown(); + + logger.info("SUCCESS"); + } + } + + /** + * The property tested is: env: "-Dweblogic.StdoutDebugEnabled=false"--> + * "-Dweblogic.StdoutDebugEnabled=true" + * + * @throws Exception + */ + @Test + public void testServerPodsRestartByChangingEnvProperty() throws Exception { + Assume.assumeFalse(QUICKTEST); + String testMethodName = new Object() {}.getClass().getEnclosingMethod().getName(); + logTestBegin(testMethodName); + + // boolean testDomainServerPodRestart = false; + logger.info( + "About to testDomainServerPodRestart for Domain: " + + domain.getDomainUid() + + " env property: StdoutDebugEnabled=false to StdoutDebugEnabled=true"); + domain.testDomainServerPodRestart( + "\"-Dweblogic.StdoutDebugEnabled=false\"", "\"-Dweblogic.StdoutDebugEnabled=true\""); + + logger.info("SUCCESS - " + testMethodName); + } + + /** + * The property tested is: logHomeEnabled: true --> logHomeEnabled: false + * + * @throws Exception + */ + @Test + public void testServerPodsRestartByChangingLogHomeEnabled() throws Exception { + Assume.assumeFalse(QUICKTEST); + String testMethodName = new Object() {}.getClass().getEnclosingMethod().getName(); + logTestBegin(testMethodName); + + // boolean testDomainServerPodRestart = false; + + logger.info( + "About to testDomainServerPodRestart for Domain: " + + domain.getDomainUid() + + " logHomeEnabled: true --> logHomeEnabled: false"); + domain.testDomainServerPodRestart("logHomeEnabled: true", "logHomeEnabled: false"); + + logger.info("SUCCESS - " + testMethodName); + } + + /** + * The property tested is: imagePullPolicy: IfNotPresent --> imagePullPolicy: Never + * + * @throws Exception + */ + @Test + public void testServerPodsRestartByChangingImagePullPolicy() throws Exception { + Assume.assumeFalse(QUICKTEST); + String testMethodName = new Object() {}.getClass().getEnclosingMethod().getName(); + logTestBegin(testMethodName); + + // boolean testDomainServerPodRestart = false; + + logger.info( + "About to testDomainServerPodRestart for Domain: " + + domain.getDomainUid() + + " imagePullPolicy: IfNotPresent --> imagePullPolicy: Never "); + domain.testDomainServerPodRestart( + "imagePullPolicy: \"IfNotPresent\"", "imagePullPolicy: \"Never\" "); + + logger.info("SUCCESS - " + testMethodName); + } + + /** + * The property tested is: includeServerOutInPodLog: true --> includeServerOutInPodLog: false + * + * @throws Exception + */ + @Test + public void testServerPodsRestartByChangingIncludeServerOutInPodLog() throws Exception { + Assume.assumeFalse(QUICKTEST); + String testMethodName = new Object() {}.getClass().getEnclosingMethod().getName(); + logTestBegin(testMethodName); + + // boolean testDomainServerPodRestart = false; + + logger.info( + "About to testDomainServerPodRestart for Domain: " + + domain.getDomainUid() + + " includeServerOutInPodLog: true --> includeServerOutInPodLog: false"); + domain.testDomainServerPodRestart( + "includeServerOutInPodLog: true", "includeServerOutInPodLog: false"); + + logger.info("SUCCESS - " + testMethodName); + } + + /** + * The property tested is: image: "store/oracle/weblogic:12.2.1.3" --> image: + * "store/oracle/weblogic:duplicate" + * + * @throws Exception + */ + @Test + public void testServerPodsRestartByChangingZImage() throws Exception { + Assume.assumeFalse(QUICKTEST); + String testMethodName = new Object() {}.getClass().getEnclosingMethod().getName(); + logTestBegin(testMethodName); + + // boolean testDomainServerPodRestart = false; + try { + logger.info( + "About to testDomainServerPodRestart for Domain: " + + domain.getDomainUid() + + " Image property: store/oracle/weblogic:12.2.1.3 to store/oracle/weblogic:duplicate"); + TestUtils.dockerTagImage("store/oracle/weblogic:12.2.1.3", "store/oracle/weblogic:duplicate"); + domain.testDomainServerPodRestart( + "\"store/oracle/weblogic:12.2.1.3\"", "\"store/oracle/weblogic:duplicate\""); + } finally { + TestUtils.dockerRemoveImage("store/oracle/weblogic:duplicate"); + } + + logger.info("SUCCESS - " + testMethodName); + } + + /** + * Modify the containerSecurityContext section at ServerPod Level using kubectl apply -f + * domain.yaml.Verify all the pods re-started serverPod: containerSecurityContext: runAsUser: 1000 + * fsGroup: 2000 + * + * @throws Exception + */ + @Test + public void testServerPodsRestartByChangingContSecurityContext() throws Exception { + Assume.assumeFalse(QUICKTEST); + String testMethodName = new Object() {}.getClass().getEnclosingMethod().getName(); + logTestBegin(testMethodName); + + // domainYaml: the yaml file name with changed property under resources dir + String domainYaml = "cont.security.context.domain.yaml"; + try { + logger.info( + "About to testDomainServerPodRestart for Domain: " + + domain.getDomainUid() + + " change container securityContext:\n" + + " runAsUser: 1000\n" + + " fsGroup: 2000 "); + domain.testDomainServerPodRestart(domainYaml); + domain.findServerPropertyChange("runAsUser: 1000", "admin-server"); + domain.findServerPropertyChange("runAsUser: 1000", "managed-server1"); + } finally { + // bring back the domain into previous State + logger.info("in the finally block to bring back the domain into previous State"); + String yamlFile = + BaseTest.getUserProjectsDir() + "/weblogic-domains/" + domainUid + "/domain.yaml"; + TestUtils.kubectlapply(yamlFile); + domain.verifyAdminServerRestarted(); + domain.verifyManagedServersRestarted(); + } + + logger.info("SUCCESS - " + testMethodName); + } + + /** + * Modify the podSecurityContext section at ServerPod level using kubectl apply -f domain.yaml Add + * Verify all pod(s) re-started podSecurityContext: runAsUser: 1000 fsGroup: 2000 The generated + * + * @throws Exception + */ + @Test + public void testServerPodsRestartByChangingPodSecurityContext() throws Exception { + Assume.assumeFalse(QUICKTEST); + String testMethodName = new Object() {}.getClass().getEnclosingMethod().getName(); + logTestBegin(testMethodName); + + // domainYaml: the yaml file name with changed property under resources dir + String domainYaml = "pod.security.context.domain.yaml"; + try { + logger.info( + "About to testDomainServerPodRestart for Domain: " + + domain.getDomainUid() + + " change securityContext:\n" + + " runAsUser: 1000\n" + + " fsGroup: 2000 "); + domain.testDomainServerPodRestart(domainYaml); + domain.findServerPropertyChange("fsGroup: 2000", "admin-server"); + domain.findServerPropertyChange("fsGroup: 2000", "managed-server1"); + } finally { + // bring back the domain into previous State + String yamlFile = + BaseTest.getUserProjectsDir() + "/weblogic-domains/" + domainUid + "/domain.yaml"; + TestUtils.kubectlapply(yamlFile); + domain.verifyAdminServerRestarted(); + domain.verifyManagedServersRestarted(); + } + + logger.info("SUCCESS - " + testMethodName); + } + + /** + * Add imagePullSecrets section at Domain Level using kubectl apply -f domain.yaml Verify all pods + * re-started. imagePullSecrets:- name: imagePullSecr value: myImagePullSecret + * + * @throws Exception + */ + @Test + public void testServerPodsRestartByChangingImagePullSecrets() throws Exception { + Assume.assumeFalse(QUICKTEST); + String testMethodName = new Object() {}.getClass().getEnclosingMethod().getName(); + logTestBegin(testMethodName); + + // domainYaml: the yaml file name with changed property under resources dir + String domainYaml = "secret.domain.yaml"; + try { + logger.info( + "About to testDomainServerPodRestart for Domain: " + + domain.getDomainUid() + + " change imagePullSecrets:\n" + + " name: imagePullSecret\n" + + " value: myImagePullSecret "); + domain.testDomainServerPodRestart(domainYaml); + domain.findServerPropertyChange("myImagePullSecret", "admin-server"); + domain.findServerPropertyChange("myImagePullSecret", "managed-server1"); + } finally { + // bring back the domain into previous State + String yamlFile = + BaseTest.getUserProjectsDir() + "/weblogic-domains/" + domainUid + "/domain.yaml"; + TestUtils.kubectlapply(yamlFile); + domain.verifyAdminServerRestarted(); + domain.verifyManagedServersRestarted(); + } + + logger.info("SUCCESS - " + testMethodName); + } + + /** + * Modify/Add resources at ServerPod level using kubectl apply -f domain.yaml Verify all pods + * re-started. serverPod: resources: limits: cpu: "1" requests: cpu: "0.5" args: - -cpus - "2" + * + * @throws Exception + */ + @Test + public void testServerPodsRestartByChangingResource() throws Exception { + Assume.assumeFalse(QUICKTEST); + String testMethodName = new Object() {}.getClass().getEnclosingMethod().getName(); + logTestBegin(testMethodName); + + // domainYaml: the yaml file name with changed property under resources dir + String domainYaml = "resource.domain.yaml"; + try { + logger.info( + "About to testDomainServerPodRestart for Domain: " + + domain.getDomainUid() + + " change resource:\n" + + " cpu: 500m"); + domain.testDomainServerPodRestart(domainYaml); + domain.findServerPropertyChange("cpu: 500m", "admin-server"); + domain.findServerPropertyChange("cpu: 500m", "managed-server1"); + } finally { + // bring back the domain into previous State + String yamlFile = + BaseTest.getUserProjectsDir() + "/weblogic-domains/" + domainUid + "/domain.yaml"; + TestUtils.kubectlapply(yamlFile); + domain.verifyAdminServerRestarted(); + domain.verifyManagedServersRestarted(); + } + + logger.info("SUCCESS - " + testMethodName); + } + + /** + * Modify the annotations at ServerPod level using kubectl apply -f domain.yaml. Verify all po + * re-started. annotations: custom: "DATETIME" + * + * @throws Exception + */ + @Test + public void testServerPodsRestartByChangingAnnotation() throws Exception { + Assume.assumeFalse(QUICKTEST); + String testMethodName = new Object() {}.getClass().getEnclosingMethod().getName(); + logTestBegin(testMethodName); + + // domainYaml: the yaml file name with changed property under resources dir + String domainYaml = "annotation.domain.yaml"; + try { + logger.info( + "About to testDomainServerPodRestart for Domain: " + + domain.getDomainUid() + + " change annotation" + + " annotations:\n" + + " custom: \"DATETIME\""); + domain.testDomainServerPodRestart(domainYaml); + + } finally { + // bring back the domain into previous State + String yamlFile = + BaseTest.getUserProjectsDir() + "/weblogic-domains/" + domainUid + "/domain.yaml"; + TestUtils.kubectlapply(yamlFile); + domain.verifyAdminServerRestarted(); + domain.verifyManagedServersRestarted(); + } + + logger.info("SUCCESS - " + testMethodName); + } + + private static Domain createPodsRestartdomain() throws Exception { + + Map domainMap = TestUtils.loadYaml(DOMAINONPV_WLST_YAML); + domainMap.put("domainUID", "domainpodsrestart"); + domainMap.put("adminNodePort", new Integer("30707")); + domainMap.put("t3ChannelPort", new Integer("30081")); + domainMap.put("initialManagedServerReplicas", new Integer("1")); + + domainUid = (String) domainMap.get("domainUID"); + logger.info("Creating and verifying the domain creation with domainUid: " + domainUid); + domain = TestUtils.createDomain(domainMap); + domain.verifyDomainCreated(); + + return domain; + } + + private static void destroyPodsRestartdomain() throws Exception { + if (domain != null) { + domain.destroy(); + } + } +} diff --git a/integration-tests/src/test/java/oracle/kubernetes/operator/utils/Domain.java b/integration-tests/src/test/java/oracle/kubernetes/operator/utils/Domain.java index ae1f70b39b0..a9f50220682 100644 --- a/integration-tests/src/test/java/oracle/kubernetes/operator/utils/Domain.java +++ b/integration-tests/src/test/java/oracle/kubernetes/operator/utils/Domain.java @@ -850,6 +850,155 @@ private void createPV() throws Exception { new PersistentVolume("/scratch/acceptance_test_pv/persistentVolume-" + domainUid, pvMap); } + public void testDomainServerPodRestart(String oldPropertyString, String newPropertyString) + throws Exception { + logger.info("Inside testDomainServerPodRestart"); + String content = + new String( + Files.readAllBytes( + Paths.get( + BaseTest.getUserProjectsDir() + + "/weblogic-domains/" + + domainUid + + "/domain.yaml"))); + boolean result = content.indexOf(newPropertyString) >= 0; + logger.info("The search result for " + newPropertyString + " is: " + result); + if (!result) { + TestUtils.createNewYamlFile( + BaseTest.getUserProjectsDir() + "/weblogic-domains/" + domainUid + "/domain.yaml", + BaseTest.getUserProjectsDir() + "/weblogic-domains/" + domainUid + "/domain_new.yaml", + oldPropertyString, + newPropertyString); + logger.info( + "Done - generate new domain.yaml for " + + domainUid + + " oldProperty: " + + oldPropertyString + + " newProperty: " + + newPropertyString); + + // kubectl apply the new generated domain yaml file with changed property + StringBuffer command = new StringBuffer(); + command + .append("kubectl apply -f ") + .append( + BaseTest.getUserProjectsDir() + + "/weblogic-domains/" + + domainUid + + "/domain_new.yaml"); + logger.info("kubectl execut with command: " + command.toString()); + + ExecResult exeResult = TestUtils.exec(command.toString()); + if (!exeResult.stdout().contains(domainUid)) + throw new RuntimeException("FAILURE: domain not found, exiting!"); + + // verify the servers in the domain are being restarted in a sequence + verifyAdminServerRestarted(); + verifyManagedServersRestarted(); + // let domain.yaml include the new changed property + TestUtils.copyFile( + BaseTest.getUserProjectsDir() + "/weblogic-domains/" + domainUid + "/domain_new.yaml", + BaseTest.getUserProjectsDir() + "/weblogic-domains/" + domainUid + "/domain.yaml"); + } + logger.info("Done - testDomainServerPodRestart"); + } + + public void findServerPropertyChange(String changedProperty, String serverName) throws Exception { + logger.info("Inside findServerPropertyChange"); + // get runtime server pod yaml file + String outDir = BaseTest.getUserProjectsDir() + "/weblogic-domains/" + domainUid + "/"; + StringBuffer command = new StringBuffer(); + command + .append("kubectl get po/") + .append( + domainUid + + "-" + + serverName + + " -o yaml -n " + + domainNS + + " > " + + outDir + + serverName + + ".yaml"); + logger.info("kubectl execut with command: " + command.toString()); + TestUtils.exec(command.toString()); + Thread.sleep(10 * 1000); + try { + String content = new String(Files.readAllBytes(Paths.get(outDir + serverName + ".yaml"))); + boolean result = content.indexOf(changedProperty) >= 0; + logger.info( + "Server name: " + + serverName + + " Search result for " + + changedProperty + + " is: " + + result); + if (!result) { + throw new Exception( + "FAILURE: didn't find the property: " + + changedProperty + + "in the " + + serverName + + ".yaml file"); + } + } finally { + // String cmdString = "rm -rf " + outDir + serverName + ".yaml"; + // TestUtils.exec(cmdString); + } + logger.info("Done - findServerPropertyChange"); + } + + public void verifyAdminServerRestarted() throws Exception { + logger.info("Checking if admin pod(" + domainUid + "-" + adminServerName + ") is Terminating"); + TestUtils.checkPodTerminating(domainUid + "-" + adminServerName, domainNS); + Thread.sleep(10 * 1000); + logger.info("Checking if admin pod(" + domainUid + "-" + adminServerName + ") is Running"); + TestUtils.checkPodCreated(domainUid + "-" + adminServerName, domainNS); + Thread.sleep(10 * 1000); + } + + public void testDomainServerPodRestart(String fileNameWithChangedProperty) throws Exception { + logger.info("Inside testDomainServerPodRestart domainYamlWithChangedProperty"); + + // kubectl apply the supplied domain yaml file under resources dir with changed property + String yamlDir = BaseTest.getProjectRoot() + "/integration-tests/src/test/resources/"; + TestUtils.kubectlapply(yamlDir + fileNameWithChangedProperty); + Thread.sleep(10 * 1000); + + // verify the servers in the domain are being restarted in a sequence + verifyAdminServerRestarted(); + verifyManagedServersRestarted(); + + logger.info("Done - testDomainServerPodRestart with domainYamlWithChangedProperty"); + } + + public void verifyManagedServersRestarted() throws Exception { + if (domainMap.get("serverStartPolicy") == null + || (domainMap.get("serverStartPolicy") != null + && !domainMap.get("serverStartPolicy").toString().trim().equals("ADMIN_ONLY"))) { + // check managed server pods + for (int i = 1; i <= initialManagedServerReplicas; i++) { + logger.info( + "Checking if managed pod(" + + domainUid + + "-" + + managedServerNameBase + + i + + ") is Terminating"); + TestUtils.checkPodTerminating(domainUid + "-" + managedServerNameBase + i, domainNS); + Thread.sleep(10 * 1000); + logger.info( + "Checking if managed pod(" + + domainUid + + "-" + + managedServerNameBase + + i + + ") is Running"); + TestUtils.checkPodCreated(domainUid + "-" + managedServerNameBase + i, domainNS); + } + } + } + private void createSecret() throws Exception { Secret secret = new Secret( @@ -896,7 +1045,12 @@ private void callCreateDomainScript(String outputDir) throws Exception { StandardCopyOption.REPLACE_EXISTING); } - StringBuffer createDomainScriptCmd = new StringBuffer(BaseTest.getResultDir()); + StringBuffer createDomainScriptCmd = new StringBuffer("export JAVA_HOME="); + + createDomainScriptCmd + .append(System.getenv("JAVA_HOME")) + .append(" && export PATH=$JAVA_HOME/bin:$PATH && ") + .append(BaseTest.getResultDir()); // call different create-domain.sh based on the domain type if (domainMap.containsKey("domainHomeImageBase")) { diff --git a/integration-tests/src/test/java/oracle/kubernetes/operator/utils/TestUtils.java b/integration-tests/src/test/java/oracle/kubernetes/operator/utils/TestUtils.java index d11c907a851..843da229eec 100644 --- a/integration-tests/src/test/java/oracle/kubernetes/operator/utils/TestUtils.java +++ b/integration-tests/src/test/java/oracle/kubernetes/operator/utils/TestUtils.java @@ -4,10 +4,15 @@ package oracle.kubernetes.operator.utils; +import java.io.BufferedReader; import java.io.File; import java.io.FileInputStream; +import java.io.FileReader; import java.io.FileWriter; import java.io.InputStream; +import java.nio.file.Files; +import java.nio.file.Paths; +import java.nio.file.StandardCopyOption; import java.security.KeyStore; import java.util.ArrayList; import java.util.HashMap; @@ -55,6 +60,16 @@ public static void checkPodCreated(String podName, String domainNS) throws Excep checkCmdInLoop(cmd.toString(), "Running", podName); } + /** @param cmd - kubectl get pod -n namespace */ + public static void checkPodTerminating(String podName, String domainNS) throws Exception { + + StringBuffer cmd = new StringBuffer(); + cmd.append("kubectl get pod ").append(podName).append(" -n ").append(domainNS); + + // check for admin pod + checkCmdInLoop(cmd.toString(), "Terminating", podName); + } + /** * @param cmd - kubectl get service -n namespace * @throws Exception @@ -191,7 +206,6 @@ public static void deletePVC(String pvcName, String namespace, String domainUid) public static ExecResult exec(String cmd) throws Exception { ExecResult result = ExecCommand.exec(cmd); if (result.exitValue() != 0) { - logger.info("Command " + cmd + " failed with " + result.stderr() + " \n " + result.stdout()); throw new RuntimeException( "FAILURE: Command " + cmd + " failed with " + result.stderr() + " \n " + result.stdout()); } @@ -432,6 +446,14 @@ public static void kubectlexec(String podName, String namespace, String scriptPa } } + public static void kubectlapply(String yamlFile) throws Exception { + + StringBuffer command = new StringBuffer(); + command.append("kubectl apply -f ").append(yamlFile); + logger.info("kubectl execut with command: " + command.toString()); + exec(command.toString()); + } + public static int makeOperatorPostRestCall(Operator operator, String url, String jsonObjStr) throws Exception { return makeOperatorRestCall(operator, url, jsonObjStr); @@ -1051,4 +1073,58 @@ private static void checkCmdInLoopForDelete(String cmd, String matchStr, String } } } + + // create yaml file with changed property + public static void createNewYamlFile( + String inputYamlFile, String generatedYamlFile, String oldString, String newString) + throws Exception { + logger.info("Creating new " + generatedYamlFile); + + Files.copy( + new File(inputYamlFile).toPath(), + Paths.get(generatedYamlFile), + StandardCopyOption.REPLACE_EXISTING); + + // read each line in input domain file and replace with intended changed property + BufferedReader reader = new BufferedReader(new FileReader(generatedYamlFile)); + String line = ""; + StringBuffer changedLines = new StringBuffer(); + boolean isLineChanged = false; + while ((line = reader.readLine()) != null) { + if (line.contains(oldString)) { + String changedLine = line.replace(line.substring(line.indexOf(oldString)), newString); + changedLines.append(changedLine).append("\n"); + isLineChanged = true; + } + + if (!isLineChanged) { + changedLines.append(line).append("\n"); + } + isLineChanged = false; + } + reader.close(); + // writing to the file + Files.write(Paths.get(generatedYamlFile), changedLines.toString().getBytes()); + logger.info("Done - generate the new yaml file "); + } + + public static void copyFile(String fromFile, String toFile) throws Exception { + logger.info("Copying file from " + fromFile + " to " + toFile); + + Files.copy(new File(fromFile).toPath(), Paths.get(toFile), StandardCopyOption.REPLACE_EXISTING); + } + + public static void dockerTagImage(String sourceImage, String targetImage) throws Exception { + logger.info("Tagging souceImage: " + sourceImage + " to " + targetImage); + String dockerCmd = "docker tag " + sourceImage + " " + targetImage; + logger.info("Executing cmd " + dockerCmd); + exec(dockerCmd); + } + + public static void dockerRemoveImage(String imageName) throws Exception { + logger.info("Removing image: " + imageName); + String dockerCmd = "docker rmi -f " + imageName; + logger.info("Executing cmd " + dockerCmd); + exec(dockerCmd); + } } diff --git a/integration-tests/src/test/resources/annotation.domain.yaml b/integration-tests/src/test/resources/annotation.domain.yaml new file mode 100644 index 00000000000..c56024e6f87 --- /dev/null +++ b/integration-tests/src/test/resources/annotation.domain.yaml @@ -0,0 +1,46 @@ +#Modify the annotations at ServerPod Level +#This should re-start all the pods + +apiVersion: "weblogic.oracle/v3alpha1" +kind: Domain +metadata: + name: domainpodsrestart + namespace: default + labels: + weblogic.resourceVersion: domain-v2 + weblogic.domainUID: domainpodsrestart +spec: + domainHome: /shared/domains/domainpodsrestart + domainHomeInImage: false + image: "store/oracle/weblogic:12.2.1.3" + imagePullPolicy: "IfNotPresent" + webLogicCredentialsSecret: + name: domainpodsrestart-weblogic-credentials + includeServerOutInPodLog: true + logHomeEnabled: true + logHome: /shared/logs/domainpodsrestart + serverStartPolicy: "IF_NEEDED" + serverPod: + annotations: + custom: "DATETIME" + env: + - name: JAVA_OPTIONS + value: "-Dweblogic.StdoutDebugEnabled=false -Xms64m -Xmx1024m" + - name: USER_MEM_ARGS + value: "-Xms64m -Xmx256m " + volumes: + - name: weblogic-domain-storage-volume + persistentVolumeClaim: + claimName: domainpodsrestart-weblogic-sample-pvc + volumeMounts: + - mountPath: /shared + name: weblogic-domain-storage-volume + adminServer: + serverStartState: "RUNNING" + adminService: + channels: + - channelName: T3Channel + clusters: + - clusterName: cluster-1 + serverStartState: "RUNNING" + replicas: 1 diff --git a/integration-tests/src/test/resources/cont.security.context.domain.yaml b/integration-tests/src/test/resources/cont.security.context.domain.yaml new file mode 100644 index 00000000000..3ec2ae5a65f --- /dev/null +++ b/integration-tests/src/test/resources/cont.security.context.domain.yaml @@ -0,0 +1,58 @@ +# Add podSecurityContext section at ServerPod Level +# Make sure all pod(s) re-started +#serverPod: +# containerSecurityContext: +# runAsUser: 1000 +# fsGroup: 2000 +# The generated server pods should look like: +#spec: +# containers: +# - name: weblogic.server +# securityContext: + +apiVersion: "weblogic.oracle/v3alpha1" +kind: Domain +metadata: + name: domainpodsrestart + namespace: default + labels: + weblogic.resourceVersion: domain-v2 + weblogic.domainUID: domainpodsrestart +spec: + domainHome: /shared/domains/domainpodsrestart + domainHomeInImage: false + image: "store/oracle/weblogic:12.2.1.3" + imagePullPolicy: "IfNotPresent" + imagePullSecrets: + - name: myImagePullSecret + webLogicCredentialsSecret: + name: domainpodsrestart-weblogic-credentials + includeServerOutInPodLog: true + logHomeEnabled: true + logHome: /shared/logs/domainpodsrestart + serverStartPolicy: "IF_NEEDED" + serverPod: + containerSecurityContext: + runAsUser: 1000 + fsGroup: 2000 + env: + - name: JAVA_OPTIONS + value: "-Dweblogic.StdoutDebugEnabled=false -Xms64m -Xmx1024m" + - name: USER_MEM_ARGS + value: "-Xms64m -Xmx256m " + volumes: + - name: weblogic-domain-storage-volume + persistentVolumeClaim: + claimName: domainpodsrestart-weblogic-sample-pvc + volumeMounts: + - mountPath: /shared + name: weblogic-domain-storage-volume + adminServer: + serverStartState: "RUNNING" + adminService: + channels: + - channelName: T3Channel + clusters: + - clusterName: cluster-1 + serverStartState: "RUNNING" + replicas: 1 diff --git a/integration-tests/src/test/resources/pod.security.context.domain.yaml b/integration-tests/src/test/resources/pod.security.context.domain.yaml new file mode 100644 index 00000000000..9735cdfdd4f --- /dev/null +++ b/integration-tests/src/test/resources/pod.security.context.domain.yaml @@ -0,0 +1,58 @@ +# Add podSecurityContext section at ServerPod Level +# Make sure all pod(s) re-started +#serverPod: +# podSecurityContext: +# runAsUser: 1000 +# fsGroup: 2000 +# The generated server pods should look like: +#spec: +# securityContext: +# runAsUser: 1000 +# fsGroup: 2000 + +apiVersion: "weblogic.oracle/v3alpha1" +kind: Domain +metadata: + name: domainpodsrestart + namespace: default + labels: + weblogic.resourceVersion: domain-v2 + weblogic.domainUID: domainpodsrestart +spec: + domainHome: /shared/domains/domainpodsrestart + domainHomeInImage: false + image: "store/oracle/weblogic:12.2.1.3" + imagePullPolicy: "IfNotPresent" + imagePullSecrets: + - name: myImagePullSecret + webLogicCredentialsSecret: + name: domainpodsrestart-weblogic-credentials + includeServerOutInPodLog: true + logHomeEnabled: true + logHome: /shared/logs/domainpodsrestart + serverStartPolicy: "IF_NEEDED" + serverPod: + podSecurityContext: + runAsUser: 1000 + fsGroup: 2000 + env: + - name: JAVA_OPTIONS + value: "-Dweblogic.StdoutDebugEnabled=false -Xms64m -Xmx1024m" + - name: USER_MEM_ARGS + value: "-Xms64m -Xmx256m " + volumes: + - name: weblogic-domain-storage-volume + persistentVolumeClaim: + claimName: domainpodsrestart-weblogic-sample-pvc + volumeMounts: + - mountPath: /shared + name: weblogic-domain-storage-volume + adminServer: + serverStartState: "RUNNING" + adminService: + channels: + - channelName: T3Channel + clusters: + - clusterName: cluster-1 + serverStartState: "RUNNING" + replicas: 1 diff --git a/integration-tests/src/test/resources/resource.domain.yaml b/integration-tests/src/test/resources/resource.domain.yaml new file mode 100644 index 00000000000..6cf9c167b18 --- /dev/null +++ b/integration-tests/src/test/resources/resource.domain.yaml @@ -0,0 +1,61 @@ +# Add a resource section at Server Pod Level +# Make sure all pod(s) re-started +#serverPod: +# resources: +# limits: +# cpu: "1" +# requests: +# cpu: "0.5" +# args: +# - -cpus +# - "2" + +apiVersion: "weblogic.oracle/v3alpha1" +kind: Domain +metadata: + name: domainpodsrestart + namespace: default + labels: + weblogic.resourceVersion: domain-v2 + weblogic.domainUID: domainpodsrestart +spec: + domainHome: /shared/domains/domainpodsrestart + domainHomeInImage: false + image: "store/oracle/weblogic:12.2.1.3" + imagePullPolicy: "IfNotPresent" + webLogicCredentialsSecret: + name: domainpodsrestart-weblogic-credentials + includeServerOutInPodLog: true + logHomeEnabled: true + logHome: /shared/logs/domainpodsrestart + serverStartPolicy: "IF_NEEDED" + serverPod: + resources: + limits: + cpu: "1" + requests: + cpu: "0.5" + args: + - -cpus + - "2" + env: + - name: JAVA_OPTIONS + value: "-Dweblogic.StdoutDebugEnabled=false -Xms64m -Xmx1024m" + - name: USER_MEM_ARGS + value: "-Xms64m -Xmx256m " + volumes: + - name: weblogic-domain-storage-volume + persistentVolumeClaim: + claimName: domainpodsrestart-weblogic-sample-pvc + volumeMounts: + - mountPath: /shared + name: weblogic-domain-storage-volume + adminServer: + serverStartState: "RUNNING" + adminService: + channels: + - channelName: T3Channel + clusters: + - clusterName: cluster-1 + serverStartState: "RUNNING" + replicas: 1 diff --git a/integration-tests/src/test/resources/secret.domain.yaml b/integration-tests/src/test/resources/secret.domain.yaml new file mode 100644 index 00000000000..885f3473c65 --- /dev/null +++ b/integration-tests/src/test/resources/secret.domain.yaml @@ -0,0 +1,49 @@ +# Add imagePullSecrets section at Domain Level +# Make sure all pod(s) re-started +# imagePullSecrets: +# - name: imagePullSecret +# value: myImagePullSecret + +apiVersion: "weblogic.oracle/v3alpha1" +kind: Domain +metadata: + name: domainpodsrestart + namespace: default + labels: + weblogic.resourceVersion: domain-v2 + weblogic.domainUID: domainpodsrestart +spec: + domainHome: /shared/domains/domainpodsrestart + domainHomeInImage: false + image: "store/oracle/weblogic:12.2.1.3" + imagePullPolicy: "IfNotPresent" + imagePullSecrets: + - name: myImagePullSecret + webLogicCredentialsSecret: + name: domainpodsrestart-weblogic-credentials + includeServerOutInPodLog: true + logHomeEnabled: true + logHome: /shared/logs/domainpodsrestart + serverStartPolicy: "IF_NEEDED" + serverPod: + env: + - name: JAVA_OPTIONS + value: "-Dweblogic.StdoutDebugEnabled=false -Xms64m -Xmx1024m" + - name: USER_MEM_ARGS + value: "-Xms64m -Xmx256m " + volumes: + - name: weblogic-domain-storage-volume + persistentVolumeClaim: + claimName: domainpodsrestart-weblogic-sample-pvc + volumeMounts: + - mountPath: /shared + name: weblogic-domain-storage-volume + adminServer: + serverStartState: "RUNNING" + adminService: + channels: + - channelName: T3Channel + clusters: + - clusterName: cluster-1 + serverStartState: "RUNNING" + replicas: 1 From 491830abc3c2e5fa7b226255ef607814b76675ae Mon Sep 17 00:00:00 2001 From: Maggie He Date: Mon, 25 Mar 2019 13:41:43 -0700 Subject: [PATCH 02/13] minor modification --- .../oracle/kubernetes/operator/ITPodsRestart.java | 2 +- .../oracle/kubernetes/operator/utils/Domain.java | 13 ++----------- 2 files changed, 3 insertions(+), 12 deletions(-) diff --git a/integration-tests/src/test/java/oracle/kubernetes/operator/ITPodsRestart.java b/integration-tests/src/test/java/oracle/kubernetes/operator/ITPodsRestart.java index 736160a34f6..2851995f2dc 100644 --- a/integration-tests/src/test/java/oracle/kubernetes/operator/ITPodsRestart.java +++ b/integration-tests/src/test/java/oracle/kubernetes/operator/ITPodsRestart.java @@ -182,7 +182,7 @@ public void testServerPodsRestartByChangingZImage() throws Exception { + " Image property: store/oracle/weblogic:12.2.1.3 to store/oracle/weblogic:duplicate"); TestUtils.exec("docker tag store/oracle/weblogic:12.2.1.3 store/oracle/weblogic:duplicate"); - domain.testDomainServerPodRestart( + domain.testDomainServerPodRestart( "\"store/oracle/weblogic:12.2.1.3\"", "\"store/oracle/weblogic:duplicate\""); } finally { TestUtils.exec("docker rmi -f store/oracle/weblogic:duplicate"); diff --git a/integration-tests/src/test/java/oracle/kubernetes/operator/utils/Domain.java b/integration-tests/src/test/java/oracle/kubernetes/operator/utils/Domain.java index d068a93975a..3601b039aef 100644 --- a/integration-tests/src/test/java/oracle/kubernetes/operator/utils/Domain.java +++ b/integration-tests/src/test/java/oracle/kubernetes/operator/utils/Domain.java @@ -947,21 +947,12 @@ public void findServerPropertyChange(String changedProperty, String serverName) + ".yaml file"); } } finally { - // String cmdString = "rm -rf " + outDir + serverName + ".yaml"; - // TestUtils.exec(cmdString); + String cmdString = "rm -rf " + outDir + serverName + ".yaml"; + TestUtils.exec(cmdString); } logger.info("Done - findServerPropertyChange"); } - public void verifyAdminServerRestarted() throws Exception { - logger.info("Checking if admin pod(" + domainUid + "-" + adminServerName + ") is Terminating"); - TestUtils.checkPodTerminating(domainUid + "-" + adminServerName, domainNS); - Thread.sleep(10 * 1000); - logger.info("Checking if admin pod(" + domainUid + "-" + adminServerName + ") is Running"); - TestUtils.checkPodCreated(domainUid + "-" + adminServerName, domainNS); - Thread.sleep(10 * 1000); - } - public void testDomainServerPodRestart(String fileNameWithChangedProperty) throws Exception { logger.info("Inside testDomainServerPodRestart domainYamlWithChangedProperty"); From 8531631f55c8f1cbd497a8f1d1a2ab9ab490bd7d Mon Sep 17 00:00:00 2001 From: Maggie He Date: Tue, 26 Mar 2019 13:56:17 -0700 Subject: [PATCH 03/13] javadoc and minor change --- .../kubernetes/operator/ITPodsRestart.java | 45 +++++++++---------- .../kubernetes/operator/utils/Domain.java | 26 +++++++---- .../kubernetes/operator/utils/TestUtils.java | 12 ----- 3 files changed, 38 insertions(+), 45 deletions(-) diff --git a/integration-tests/src/test/java/oracle/kubernetes/operator/ITPodsRestart.java b/integration-tests/src/test/java/oracle/kubernetes/operator/ITPodsRestart.java index 2851995f2dc..989f7b126b3 100644 --- a/integration-tests/src/test/java/oracle/kubernetes/operator/ITPodsRestart.java +++ b/integration-tests/src/test/java/oracle/kubernetes/operator/ITPodsRestart.java @@ -63,7 +63,7 @@ public static void staticUnPrepare() throws Exception { logger.info("+++++++++++++++++++++++++++++++++---------------------------------+"); logger.info("BEGIN"); logger.info("Run once, release cluster lease"); - + destroyPodsRestartdomain(); tearDown(); @@ -72,7 +72,7 @@ public static void staticUnPrepare() throws Exception { } /** - * Modify the domain scope env property on the domain resource using kubectl apply -f domain.yaml + * Modify the domain scope env property on the domain resource using kubectl apply -f domain.yaml * Verify that all the server pods in the domain got re-started. The property tested is: env: * "-Dweblogic.StdoutDebugEnabled=false"--> "-Dweblogic.StdoutDebugEnabled=true" * @@ -181,8 +181,8 @@ public void testServerPodsRestartByChangingZImage() throws Exception { + domain.getDomainUid() + " Image property: store/oracle/weblogic:12.2.1.3 to store/oracle/weblogic:duplicate"); - TestUtils.exec("docker tag store/oracle/weblogic:12.2.1.3 store/oracle/weblogic:duplicate"); - domain.testDomainServerPodRestart( + TestUtils.exec("docker tag store/oracle/weblogic:12.2.1.3 store/oracle/weblogic:duplicate"); + domain.testDomainServerPodRestart( "\"store/oracle/weblogic:12.2.1.3\"", "\"store/oracle/weblogic:duplicate\""); } finally { TestUtils.exec("docker rmi -f store/oracle/weblogic:duplicate"); @@ -193,8 +193,8 @@ public void testServerPodsRestartByChangingZImage() throws Exception { /** * Modify the containerSecurityContext section at ServerPod Level using kubectl apply -f - * domain.yaml.Verify all the pods re-started serverPod: containerSecurityContext: runAsUser: 1000 - * fsGroup: 2000 + * domain.yaml.Verify all the pods re-started. The property tested is: serverPod: + * containerSecurityContext: runAsUser: 1000 fsGroup: 2000 * * @throws Exception */ @@ -217,8 +217,8 @@ public void testServerPodsRestartByChangingContSecurityContext() throws Exceptio domain.findServerPropertyChange("runAsUser: 1000", "admin-server"); domain.findServerPropertyChange("runAsUser: 1000", "managed-server1"); } finally { - // bring back the domain into previous State - logger.info("in the finally block to bring back the domain into previous State"); + // bring back the domain into previous state + logger.info("In the finally block to bring back the domain into previous State"); String yamlFile = BaseTest.getUserProjectsDir() + "/weblogic-domains/" + domainUid + "/domain.yaml"; TestUtils.kubectlapply(yamlFile); @@ -230,8 +230,9 @@ public void testServerPodsRestartByChangingContSecurityContext() throws Exceptio } /** - * Modify the podSecurityContext section at ServerPod level using kubectl apply -f domain.yaml Add - * Verify all pod(s) re-started podSecurityContext: runAsUser: 1000 fsGroup: 2000 The generated + * Modify the podSecurityContext section at ServerPod level using kubectl apply -f domain.yaml. + * Verify all pod(s) re-started. The property tested is: podSecurityContext: runAsUser: 1000 + * fsGroup: 2000 * * @throws Exception */ @@ -266,8 +267,9 @@ public void testServerPodsRestartByChangingPodSecurityContext() throws Exception } /** - * Add imagePullSecrets section at Domain Level using kubectl apply -f domain.yaml Verify all pods - * re-started. imagePullSecrets:- name: imagePullSecr value: myImagePullSecret + * Add imagePullSecrets section at Domain Level using kubectl apply -f domain.yaml. Verify all pods + * re-started. The property tested is: imagePullSecrets:- name: imagePullSecr value: + * myImagePullSecret * * @throws Exception */ @@ -290,7 +292,7 @@ public void testServerPodsRestartByChangingImagePullSecrets() throws Exception { domain.findServerPropertyChange("myImagePullSecret", "admin-server"); domain.findServerPropertyChange("myImagePullSecret", "managed-server1"); } finally { - // bring back the domain into previous State + // bring back the domain into previous state String yamlFile = BaseTest.getUserProjectsDir() + "/weblogic-domains/" + domainUid + "/domain.yaml"; TestUtils.kubectlapply(yamlFile); @@ -302,8 +304,9 @@ public void testServerPodsRestartByChangingImagePullSecrets() throws Exception { } /** - * Modify/Add resources at ServerPod level using kubectl apply -f domain.yaml Verify all pods - * re-started. serverPod: resources: limits: cpu: "1" requests: cpu: "0.5" args: - -cpus - "2" + * Modify/Add resources at ServerPod level using kubectl apply -f domain.yaml. Verify all pods + * re-started. The property tested is:serverPod: resources: limits: cpu: "1" requests: cpu: "0.5" + * args: - -cpus - "2" * * @throws Exception */ @@ -325,7 +328,7 @@ public void testServerPodsRestartByChangingResource() throws Exception { domain.findServerPropertyChange("cpu: 500m", "admin-server"); domain.findServerPropertyChange("cpu: 500m", "managed-server1"); } finally { - // bring back the domain into previous State + // bring back the domain into previous state String yamlFile = BaseTest.getUserProjectsDir() + "/weblogic-domains/" + domainUid + "/domain.yaml"; TestUtils.kubectlapply(yamlFile); @@ -338,7 +341,7 @@ public void testServerPodsRestartByChangingResource() throws Exception { /** * Modify the annotations at ServerPod level using kubectl apply -f domain.yaml. Verify all po - * re-started. annotations: custom: "DATETIME" + * re-started. The property tested is: annotations: "TSTAMP" --> "DATETIME" * * @throws Exception */ @@ -360,18 +363,12 @@ public void testServerPodsRestartByChangingAnnotation() throws Exception { domain.testDomainServerPodRestart(domainYaml); } finally { - // bring back the domain into previous State + // bring back the domain into previous state String yamlFile = BaseTest.getUserProjectsDir() + "/weblogic-domains/" + domainUid + "/domain.yaml"; TestUtils.kubectlapply(yamlFile); domain.verifyAdminServerRestarted(); domain.verifyManagedServersRestarted(); - - TestUtils.exec("docker tag store/oracle/weblogic:12.2.1.3 store/oracle/weblogic:duplicate"); - domain.testDomainServerPodRestart( - "\"store/oracle/weblogic:12.2.1.3\"", "\"store/oracle/weblogic:duplicate\""); - } finally { - TestUtils.exec("docker rmi -f store/oracle/weblogic:duplicate"); } logger.info("SUCCESS - " + testMethodName); diff --git a/integration-tests/src/test/java/oracle/kubernetes/operator/utils/Domain.java b/integration-tests/src/test/java/oracle/kubernetes/operator/utils/Domain.java index 3601b039aef..d6097e85ff9 100644 --- a/integration-tests/src/test/java/oracle/kubernetes/operator/utils/Domain.java +++ b/integration-tests/src/test/java/oracle/kubernetes/operator/utils/Domain.java @@ -899,7 +899,6 @@ public void testDomainServerPodRestart(String oldPropertyString, String newPrope // verify the servers in the domain are being restarted in a sequence verifyAdminServerRestarted(); verifyManagedServersRestarted(); - // make domain.yaml include the new changed property TestUtils.copyFile( BaseTest.getUserProjectsDir() + "/weblogic-domains/" + domainUid + "/domain_new.yaml", @@ -908,7 +907,14 @@ public void testDomainServerPodRestart(String oldPropertyString, String newPrope logger.info("Done - testDomainServerPodRestart"); } -public void findServerPropertyChange(String changedProperty, String serverName) throws Exception { + /** + * Get runtime server yaml file and verify the changed property is that file + * + * @param changedProperty + * @param serverName + * @throws Exception + */ + public void findServerPropertyChange(String changedProperty, String serverName) throws Exception { logger.info("Inside findServerPropertyChange"); // get runtime server pod yaml file String outDir = BaseTest.getUserProjectsDir() + "/weblogic-domains/" + domainUid + "/"; @@ -953,13 +959,20 @@ public void findServerPropertyChange(String changedProperty, String serverName) logger.info("Done - findServerPropertyChange"); } + /** + * verify domain server pods get restarted after the property change by kubectl apply -f + * newDomainYamlfileWithChangedProperty + * + * @param fileNameWithChangedProperty + * @throws Exception + */ public void testDomainServerPodRestart(String fileNameWithChangedProperty) throws Exception { logger.info("Inside testDomainServerPodRestart domainYamlWithChangedProperty"); // kubectl apply the supplied domain yaml file under resources dir with changed property String yamlDir = BaseTest.getProjectRoot() + "/integration-tests/src/test/resources/"; TestUtils.kubectlapply(yamlDir + fileNameWithChangedProperty); - + // verify the servers in the domain are being restarted in a sequence verifyAdminServerRestarted(); verifyManagedServersRestarted(); @@ -1058,12 +1071,7 @@ private void callCreateDomainScript(String outputDir) throws Exception { StandardCopyOption.REPLACE_EXISTING); } - StringBuffer createDomainScriptCmd = new StringBuffer("export JAVA_HOME="); - - createDomainScriptCmd - .append(System.getenv("JAVA_HOME")) - .append(" && export PATH=$JAVA_HOME/bin:$PATH && ") - .append(BaseTest.getResultDir()); + StringBuffer createDomainScriptCmd = new StringBuffer(BaseTest.getResultDir()); // call different create-domain.sh based on the domain type if (domainMap.containsKey("domainHomeImageBase")) { diff --git a/integration-tests/src/test/java/oracle/kubernetes/operator/utils/TestUtils.java b/integration-tests/src/test/java/oracle/kubernetes/operator/utils/TestUtils.java index ca723fa2790..b8e2e0887da 100644 --- a/integration-tests/src/test/java/oracle/kubernetes/operator/utils/TestUtils.java +++ b/integration-tests/src/test/java/oracle/kubernetes/operator/utils/TestUtils.java @@ -60,16 +60,6 @@ public static void checkPodCreated(String podName, String domainNS) throws Excep checkCmdInLoop(cmd.toString(), "Running", podName); } - /** @param cmd - kubectl get pod -n namespace */ - public static void checkPodTerminating(String podName, String domainNS) throws Exception { - - StringBuffer cmd = new StringBuffer(); - cmd.append("kubectl get pod ").append(podName).append(" -n ").append(domainNS); - - // check for admin pod - checkCmdInLoop(cmd.toString(), "Terminating", podName); - } - /** * check pod is in Terminating state * @@ -1131,7 +1121,6 @@ public static void createNewYamlFile( logger.info("Done - generate the new yaml file "); } - /** * copy file from source to target * @@ -1143,5 +1132,4 @@ public static void copyFile(String fromFile, String toFile) throws Exception { logger.info("Copying file from " + fromFile + " to " + toFile); Files.copy(new File(fromFile).toPath(), Paths.get(toFile), StandardCopyOption.REPLACE_EXISTING); } - } From c240e676f01be62b6d1f4f1e5062b78e6121ac68 Mon Sep 17 00:00:00 2001 From: Maggie He Date: Tue, 26 Mar 2019 15:20:14 -0700 Subject: [PATCH 04/13] minor code refactoring --- .../kubernetes/operator/ITPodsRestart.java | 45 +++++++------------ .../kubernetes/operator/utils/Domain.java | 2 +- .../kubernetes/operator/utils/TestUtils.java | 1 + 3 files changed, 18 insertions(+), 30 deletions(-) diff --git a/integration-tests/src/test/java/oracle/kubernetes/operator/ITPodsRestart.java b/integration-tests/src/test/java/oracle/kubernetes/operator/ITPodsRestart.java index 989f7b126b3..e7128d79341 100644 --- a/integration-tests/src/test/java/oracle/kubernetes/operator/ITPodsRestart.java +++ b/integration-tests/src/test/java/oracle/kubernetes/operator/ITPodsRestart.java @@ -218,12 +218,7 @@ public void testServerPodsRestartByChangingContSecurityContext() throws Exceptio domain.findServerPropertyChange("runAsUser: 1000", "managed-server1"); } finally { // bring back the domain into previous state - logger.info("In the finally block to bring back the domain into previous State"); - String yamlFile = - BaseTest.getUserProjectsDir() + "/weblogic-domains/" + domainUid + "/domain.yaml"; - TestUtils.kubectlapply(yamlFile); - domain.verifyAdminServerRestarted(); - domain.verifyManagedServersRestarted(); + restoreDomain(); } logger.info("SUCCESS - " + testMethodName); @@ -256,19 +251,15 @@ public void testServerPodsRestartByChangingPodSecurityContext() throws Exception domain.findServerPropertyChange("fsGroup: 2000", "managed-server1"); } finally { // bring back the domain into previous State - String yamlFile = - BaseTest.getUserProjectsDir() + "/weblogic-domains/" + domainUid + "/domain.yaml"; - TestUtils.kubectlapply(yamlFile); - domain.verifyAdminServerRestarted(); - domain.verifyManagedServersRestarted(); + restoreDomain(); } logger.info("SUCCESS - " + testMethodName); } /** - * Add imagePullSecrets section at Domain Level using kubectl apply -f domain.yaml. Verify all pods - * re-started. The property tested is: imagePullSecrets:- name: imagePullSecr value: + * Add imagePullSecrets section at Domain Level using kubectl apply -f domain.yaml. Verify all + * pods re-started. The property tested is: imagePullSecrets:- name: imagePullSecr value: * myImagePullSecret * * @throws Exception @@ -293,11 +284,7 @@ public void testServerPodsRestartByChangingImagePullSecrets() throws Exception { domain.findServerPropertyChange("myImagePullSecret", "managed-server1"); } finally { // bring back the domain into previous state - String yamlFile = - BaseTest.getUserProjectsDir() + "/weblogic-domains/" + domainUid + "/domain.yaml"; - TestUtils.kubectlapply(yamlFile); - domain.verifyAdminServerRestarted(); - domain.verifyManagedServersRestarted(); + restoreDomain(); } logger.info("SUCCESS - " + testMethodName); @@ -329,18 +316,14 @@ public void testServerPodsRestartByChangingResource() throws Exception { domain.findServerPropertyChange("cpu: 500m", "managed-server1"); } finally { // bring back the domain into previous state - String yamlFile = - BaseTest.getUserProjectsDir() + "/weblogic-domains/" + domainUid + "/domain.yaml"; - TestUtils.kubectlapply(yamlFile); - domain.verifyAdminServerRestarted(); - domain.verifyManagedServersRestarted(); + restoreDomain(); } logger.info("SUCCESS - " + testMethodName); } /** - * Modify the annotations at ServerPod level using kubectl apply -f domain.yaml. Verify all po + * Modify the annotations at ServerPod level using kubectl apply -f domain.yaml. Verify all pods * re-started. The property tested is: annotations: "TSTAMP" --> "DATETIME" * * @throws Exception @@ -364,11 +347,7 @@ public void testServerPodsRestartByChangingAnnotation() throws Exception { } finally { // bring back the domain into previous state - String yamlFile = - BaseTest.getUserProjectsDir() + "/weblogic-domains/" + domainUid + "/domain.yaml"; - TestUtils.kubectlapply(yamlFile); - domain.verifyAdminServerRestarted(); - domain.verifyManagedServersRestarted(); + restoreDomain(); } logger.info("SUCCESS - " + testMethodName); @@ -394,4 +373,12 @@ private static void destroyPodsRestartdomain() throws Exception { domain.destroy(); } } + + private static void restoreDomain() throws Exception { + String yamlFile = + BaseTest.getUserProjectsDir() + "/weblogic-domains/" + domainUid + "/domain.yaml"; + TestUtils.kubectlapply(yamlFile); + domain.verifyAdminServerRestarted(); + domain.verifyManagedServersRestarted(); + } } diff --git a/integration-tests/src/test/java/oracle/kubernetes/operator/utils/Domain.java b/integration-tests/src/test/java/oracle/kubernetes/operator/utils/Domain.java index d6097e85ff9..a0d31ad0590 100644 --- a/integration-tests/src/test/java/oracle/kubernetes/operator/utils/Domain.java +++ b/integration-tests/src/test/java/oracle/kubernetes/operator/utils/Domain.java @@ -908,7 +908,7 @@ public void testDomainServerPodRestart(String oldPropertyString, String newPrope } /** - * Get runtime server yaml file and verify the changed property is that file + * Get runtime server yaml file and verify the changed property is in that file * * @param changedProperty * @param serverName diff --git a/integration-tests/src/test/java/oracle/kubernetes/operator/utils/TestUtils.java b/integration-tests/src/test/java/oracle/kubernetes/operator/utils/TestUtils.java index b8e2e0887da..94aef6e4cb4 100644 --- a/integration-tests/src/test/java/oracle/kubernetes/operator/utils/TestUtils.java +++ b/integration-tests/src/test/java/oracle/kubernetes/operator/utils/TestUtils.java @@ -211,6 +211,7 @@ public static void deletePVC(String pvcName, String namespace, String domainUid) public static ExecResult exec(String cmd) throws Exception { ExecResult result = ExecCommand.exec(cmd); if (result.exitValue() != 0) { + logger.info("Command " + cmd + " failed with " + result.stderr() + " \n " + result.stdout()); throw new RuntimeException( "FAILURE: Command " + cmd + " failed with " + result.stderr() + " \n " + result.stdout()); } From fb34c373bbda6dbd9c5650691bb921e12456d517 Mon Sep 17 00:00:00 2001 From: Maggie He Date: Tue, 26 Mar 2019 15:52:32 -0700 Subject: [PATCH 05/13] update README.md --- integration-tests/README.md | 5 +++++ .../test/java/oracle/kubernetes/operator/ITPodsRestart.java | 6 +++--- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/integration-tests/README.md b/integration-tests/README.md index 3e9a02958d7..3649e5306a2 100644 --- a/integration-tests/README.md +++ b/integration-tests/README.md @@ -87,6 +87,11 @@ Basic Use Cases described above are verified in all the domain configurations. A | Server pods restarted by changing imagePullPolicy | Verify admin and managed server pods being restarted by property change: imagePullPolicy: IfNotPresent --> imagePullPolicy: Never | | Server pods restarted by changing includeServerOutInPodLog | Verify admin and managed server pods being restarted by property change: includeServerOutInPodLog: true --> includeServerOutInPodLog: false | | Server pods restarted by changing logHomeEnable | Verify admin and managed server pods being restarted by property change: logHomeEnabled: true --> logHomeEnabled: false | +| Server pods restarted by changing annotations | Verify admin and managed server pods being restarted by property change: annotations: "TSTAMP" --> "DATETIME" | +| Server pods restarted by changing containerSecurityContext | Verify admin and managed server pods being restarted by adding property change: containerSecurityContext: runAsUser: 1000 fsGroup: 2000 | +| Server pods restarted by changing podSecurityContex | Verify admin and managed server pods being restarted by adding property change: podSecurityContext: runAsUser: 1000 fsGroup: 2000 | +| Server pods restarted by changing imagePullSecrets | Verify admin and managed server pods being restarted by adding property change: imagePullSecrets: name: imagePullSecr value: myImagePullSecret | +| Server pods restarted by changing resources | Verify admin and managed server pods being restarted by adding property change: resources: limits: cpu: "1" requests: cpu: "0.5" args: - -cpus - "2" | Configuration Overrides Usecases diff --git a/integration-tests/src/test/java/oracle/kubernetes/operator/ITPodsRestart.java b/integration-tests/src/test/java/oracle/kubernetes/operator/ITPodsRestart.java index e7128d79341..0c61293bf28 100644 --- a/integration-tests/src/test/java/oracle/kubernetes/operator/ITPodsRestart.java +++ b/integration-tests/src/test/java/oracle/kubernetes/operator/ITPodsRestart.java @@ -192,7 +192,7 @@ public void testServerPodsRestartByChangingZImage() throws Exception { } /** - * Modify the containerSecurityContext section at ServerPod Level using kubectl apply -f + * Modify/Add the containerSecurityContext section at ServerPod Level using kubectl apply -f * domain.yaml.Verify all the pods re-started. The property tested is: serverPod: * containerSecurityContext: runAsUser: 1000 fsGroup: 2000 * @@ -225,7 +225,7 @@ public void testServerPodsRestartByChangingContSecurityContext() throws Exceptio } /** - * Modify the podSecurityContext section at ServerPod level using kubectl apply -f domain.yaml. + * Modify/Add the podSecurityContext section at ServerPod level using kubectl apply -f domain.yaml. * Verify all pod(s) re-started. The property tested is: podSecurityContext: runAsUser: 1000 * fsGroup: 2000 * @@ -258,7 +258,7 @@ public void testServerPodsRestartByChangingPodSecurityContext() throws Exception } /** - * Add imagePullSecrets section at Domain Level using kubectl apply -f domain.yaml. Verify all + * Modify/Add imagePullSecrets section at Domain Level using kubectl apply -f domain.yaml. Verify all * pods re-started. The property tested is: imagePullSecrets:- name: imagePullSecr value: * myImagePullSecret * From a13d3edeaecd02fde140b293077ec5fcb8087088 Mon Sep 17 00:00:00 2001 From: Maggie He Date: Tue, 26 Mar 2019 16:09:09 -0700 Subject: [PATCH 06/13] format --- .../oracle/kubernetes/operator/ITPodsRestart.java | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/integration-tests/src/test/java/oracle/kubernetes/operator/ITPodsRestart.java b/integration-tests/src/test/java/oracle/kubernetes/operator/ITPodsRestart.java index 0c61293bf28..fa475bf55b0 100644 --- a/integration-tests/src/test/java/oracle/kubernetes/operator/ITPodsRestart.java +++ b/integration-tests/src/test/java/oracle/kubernetes/operator/ITPodsRestart.java @@ -225,9 +225,9 @@ public void testServerPodsRestartByChangingContSecurityContext() throws Exceptio } /** - * Modify/Add the podSecurityContext section at ServerPod level using kubectl apply -f domain.yaml. - * Verify all pod(s) re-started. The property tested is: podSecurityContext: runAsUser: 1000 - * fsGroup: 2000 + * Modify/Add the podSecurityContext section at ServerPod level using kubectl apply -f + * domain.yaml. Verify all pod(s) re-started. The property tested is: podSecurityContext: + * runAsUser: 1000 fsGroup: 2000 * * @throws Exception */ @@ -258,8 +258,8 @@ public void testServerPodsRestartByChangingPodSecurityContext() throws Exception } /** - * Modify/Add imagePullSecrets section at Domain Level using kubectl apply -f domain.yaml. Verify all - * pods re-started. The property tested is: imagePullSecrets:- name: imagePullSecr value: + * Modify/Add imagePullSecrets section at Domain Level using kubectl apply -f domain.yaml. Verify + * all pods re-started. The property tested is: imagePullSecrets:- name: imagePullSecr value: * myImagePullSecret * * @throws Exception @@ -292,8 +292,8 @@ public void testServerPodsRestartByChangingImagePullSecrets() throws Exception { /** * Modify/Add resources at ServerPod level using kubectl apply -f domain.yaml. Verify all pods - * re-started. The property tested is:serverPod: resources: limits: cpu: "1" requests: cpu: "0.5" - * args: - -cpus - "2" + * re-started. The property tested is: resources: limits: cpu: "1" requests: cpu: "0.5" args: - + * -cpus - "2" * * @throws Exception */ From 71e1f47c1ed45158ef60d5a09e0378187cd25ec1 Mon Sep 17 00:00:00 2001 From: Maggie He Date: Wed, 27 Mar 2019 12:43:39 -0700 Subject: [PATCH 07/13] remove one hard sleep --- .../src/test/java/oracle/kubernetes/operator/utils/Domain.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/integration-tests/src/test/java/oracle/kubernetes/operator/utils/Domain.java b/integration-tests/src/test/java/oracle/kubernetes/operator/utils/Domain.java index 0738b519a4a..131ffed5d7c 100644 --- a/integration-tests/src/test/java/oracle/kubernetes/operator/utils/Domain.java +++ b/integration-tests/src/test/java/oracle/kubernetes/operator/utils/Domain.java @@ -951,7 +951,7 @@ public void findServerPropertyChange(String changedProperty, String serverName) + ".yaml"); logger.info("kubectl execut with command: " + command.toString()); TestUtils.exec(command.toString()); - Thread.sleep(10 * 1000); + try { String content = new String(Files.readAllBytes(Paths.get(outDir + serverName + ".yaml"))); boolean result = content.indexOf(changedProperty) >= 0; From a8519d99692fed6a2d87cec19fb38053c6f8e85a Mon Sep 17 00:00:00 2001 From: Maggie He Date: Fri, 29 Mar 2019 15:14:43 -0700 Subject: [PATCH 08/13] jenkins-ignore javadoc update --- .../kubernetes/operator/ITPodsRestart.java | 24 +++++++++---------- .../kubernetes/operator/utils/TestUtils.java | 6 +++++ 2 files changed, 18 insertions(+), 12 deletions(-) diff --git a/integration-tests/src/test/java/oracle/kubernetes/operator/ITPodsRestart.java b/integration-tests/src/test/java/oracle/kubernetes/operator/ITPodsRestart.java index fa475bf55b0..2b1f0e3b615 100644 --- a/integration-tests/src/test/java/oracle/kubernetes/operator/ITPodsRestart.java +++ b/integration-tests/src/test/java/oracle/kubernetes/operator/ITPodsRestart.java @@ -193,8 +193,8 @@ public void testServerPodsRestartByChangingZImage() throws Exception { /** * Modify/Add the containerSecurityContext section at ServerPod Level using kubectl apply -f - * domain.yaml.Verify all the pods re-started. The property tested is: serverPod: - * containerSecurityContext: runAsUser: 1000 fsGroup: 2000 + * cont.security.context.domain.yaml. Verify all the pods re-started. The property tested is: + * serverPod: containerSecurityContext: runAsUser: 1000 fsGroup: 2000 * * @throws Exception */ @@ -226,8 +226,8 @@ public void testServerPodsRestartByChangingContSecurityContext() throws Exceptio /** * Modify/Add the podSecurityContext section at ServerPod level using kubectl apply -f - * domain.yaml. Verify all pod(s) re-started. The property tested is: podSecurityContext: - * runAsUser: 1000 fsGroup: 2000 + * pod.security.context.domain.yaml. Verify all the pods re-started. The property tested is: + * podSecurityContext: runAsUser: 1000 fsGroup: 2000 * * @throws Exception */ @@ -258,9 +258,9 @@ public void testServerPodsRestartByChangingPodSecurityContext() throws Exception } /** - * Modify/Add imagePullSecrets section at Domain Level using kubectl apply -f domain.yaml. Verify - * all pods re-started. The property tested is: imagePullSecrets:- name: imagePullSecr value: - * myImagePullSecret + * Modify/Add imagePullSecrets section at Domain Level using kubectl apply -f secret.domain.yaml. + * Verify all pods re-started. The property tested is: imagePullSecrets:- name: imagePullSecr + * value: myImagePullSecret * * @throws Exception */ @@ -291,9 +291,9 @@ public void testServerPodsRestartByChangingImagePullSecrets() throws Exception { } /** - * Modify/Add resources at ServerPod level using kubectl apply -f domain.yaml. Verify all pods - * re-started. The property tested is: resources: limits: cpu: "1" requests: cpu: "0.5" args: - - * -cpus - "2" + * Modify/Add resources at ServerPod level using kubectl apply -f resource.domain.yaml. Verify all + * pods re-started. The property tested is: resources: limits: cpu: "1" requests: cpu: "0.5" args: + * - -cpus - "2" * * @throws Exception */ @@ -323,8 +323,8 @@ public void testServerPodsRestartByChangingResource() throws Exception { } /** - * Modify the annotations at ServerPod level using kubectl apply -f domain.yaml. Verify all pods - * re-started. The property tested is: annotations: "TSTAMP" --> "DATETIME" + * Modify the annotations at ServerPod level using kubectl apply -f annotation.domain.yaml. Verify + * all pods re-started. The property tested is: annotations: "TSTAMP" --> "DATETIME" * * @throws Exception */ diff --git a/integration-tests/src/test/java/oracle/kubernetes/operator/utils/TestUtils.java b/integration-tests/src/test/java/oracle/kubernetes/operator/utils/TestUtils.java index d3466a38462..e144efe18b3 100644 --- a/integration-tests/src/test/java/oracle/kubernetes/operator/utils/TestUtils.java +++ b/integration-tests/src/test/java/oracle/kubernetes/operator/utils/TestUtils.java @@ -498,6 +498,12 @@ public static void kubectlexec(String podName, String namespace, String scriptPa } } + /** + * exec kubectl apply -f yamlFile + * + * @param yamlFile + * @throws Exception + */ public static void kubectlapply(String yamlFile) throws Exception { StringBuffer command = new StringBuffer(); From 7011ae1026152d78a7a19b17f3a91645d57bf8b3 Mon Sep 17 00:00:00 2001 From: Maggie He Date: Wed, 3 Apr 2019 13:32:18 -0700 Subject: [PATCH 09/13] revise the code to supply only fragment of domain yaml file with added property --- .../kubernetes/operator/ITPodsRestart.java | 177 ++++++------------ .../kubernetes/operator/utils/Domain.java | 33 +++- .../kubernetes/operator/utils/TestUtils.java | 50 +++++ .../src/test/resources/annotation.domain.yaml | 46 ----- .../cont.security.context.domain.yaml | 39 +--- .../pod.security.context.domain.yaml | 37 +--- .../src/test/resources/resource.domain.yaml | 35 +--- .../src/test/resources/secret.domain.yaml | 49 ----- 8 files changed, 147 insertions(+), 319 deletions(-) delete mode 100644 integration-tests/src/test/resources/annotation.domain.yaml delete mode 100644 integration-tests/src/test/resources/secret.domain.yaml diff --git a/integration-tests/src/test/java/oracle/kubernetes/operator/ITPodsRestart.java b/integration-tests/src/test/java/oracle/kubernetes/operator/ITPodsRestart.java index 2b1f0e3b615..11cf30df9b6 100644 --- a/integration-tests/src/test/java/oracle/kubernetes/operator/ITPodsRestart.java +++ b/integration-tests/src/test/java/oracle/kubernetes/operator/ITPodsRestart.java @@ -194,9 +194,11 @@ public void testServerPodsRestartByChangingZImage() throws Exception { /** * Modify/Add the containerSecurityContext section at ServerPod Level using kubectl apply -f * cont.security.context.domain.yaml. Verify all the pods re-started. The property tested is: - * serverPod: containerSecurityContext: runAsUser: 1000 fsGroup: 2000 + * serverPod: containerSecurityContext: runAsUser: 1000 fsGroup: 1000. * - * @throws Exception + * @throws Exception - assertion fails due to unmatched value or errors occurred if tested servers + * are not restarted or after restart the server yaml file doesn't include the new added + * property */ @Test public void testServerPodsRestartByChangingContSecurityContext() throws Exception { @@ -204,22 +206,23 @@ public void testServerPodsRestartByChangingContSecurityContext() throws Exceptio String testMethodName = new Object() {}.getClass().getEnclosingMethod().getName(); logTestBegin(testMethodName); + // firstly ensure that original domain.yaml doesn't include the property-to-be-added + String domainFileName = + BaseTest.getUserProjectsDir() + "/weblogic-domains/" + domainUid + "/domain.yaml"; + boolean result = TestUtils.checkFileIncludeProperty("fsGroup: 1000", domainFileName); + Assert.assertFalse(result); + // domainYaml: the yaml file name with changed property under resources dir String domainYaml = "cont.security.context.domain.yaml"; - try { - logger.info( - "About to testDomainServerPodRestart for Domain: " - + domain.getDomainUid() - + " change container securityContext:\n" - + " runAsUser: 1000\n" - + " fsGroup: 2000 "); - domain.testDomainServerPodRestart(domainYaml); - domain.findServerPropertyChange("runAsUser: 1000", "admin-server"); - domain.findServerPropertyChange("runAsUser: 1000", "managed-server1"); - } finally { - // bring back the domain into previous state - restoreDomain(); - } + logger.info( + "About to testDomainServerPodRestart for Domain: " + + domain.getDomainUid() + + " change container securityContext:\n" + + " runAsUser: 1000\n" + + " fsGroup: 1000 "); + domain.testDomainServerPodRestart(domainYaml); + domain.findServerPropertyChange("securityContext", "admin-server"); + domain.findServerPropertyChange("securityContext", "managed-server1"); logger.info("SUCCESS - " + testMethodName); } @@ -227,9 +230,11 @@ public void testServerPodsRestartByChangingContSecurityContext() throws Exceptio /** * Modify/Add the podSecurityContext section at ServerPod level using kubectl apply -f * pod.security.context.domain.yaml. Verify all the pods re-started. The property tested is: - * podSecurityContext: runAsUser: 1000 fsGroup: 2000 + * podSecurityContext: runAsUser: 1000 fsGroup: 2000. * - * @throws Exception + * @throws Exception - assertion fails due to unmatched value or errors occurred if tested servers + * are not restarted or after restart the server yaml file doesn't include the new added + * property */ @Test public void testServerPodsRestartByChangingPodSecurityContext() throws Exception { @@ -237,65 +242,36 @@ public void testServerPodsRestartByChangingPodSecurityContext() throws Exception String testMethodName = new Object() {}.getClass().getEnclosingMethod().getName(); logTestBegin(testMethodName); + // firstly ensure that original domain.yaml doesn't include the property-to-be-added + String domainFileName = + BaseTest.getUserProjectsDir() + "/weblogic-domains/" + domainUid + "/domain.yaml"; + boolean result = TestUtils.checkFileIncludeProperty("fsGroup: 2000", domainFileName); + Assert.assertFalse(result); + // domainYaml: the yaml file name with changed property under resources dir String domainYaml = "pod.security.context.domain.yaml"; - try { - logger.info( - "About to testDomainServerPodRestart for Domain: " - + domain.getDomainUid() - + " change securityContext:\n" - + " runAsUser: 1000\n" - + " fsGroup: 2000 "); - domain.testDomainServerPodRestart(domainYaml); - domain.findServerPropertyChange("fsGroup: 2000", "admin-server"); - domain.findServerPropertyChange("fsGroup: 2000", "managed-server1"); - } finally { - // bring back the domain into previous State - restoreDomain(); - } - logger.info("SUCCESS - " + testMethodName); - } - - /** - * Modify/Add imagePullSecrets section at Domain Level using kubectl apply -f secret.domain.yaml. - * Verify all pods re-started. The property tested is: imagePullSecrets:- name: imagePullSecr - * value: myImagePullSecret - * - * @throws Exception - */ - @Test - public void testServerPodsRestartByChangingImagePullSecrets() throws Exception { - Assume.assumeFalse(QUICKTEST); - String testMethodName = new Object() {}.getClass().getEnclosingMethod().getName(); - logTestBegin(testMethodName); - - // domainYaml: the yaml file name with changed property under resources dir - String domainYaml = "secret.domain.yaml"; - try { - logger.info( - "About to testDomainServerPodRestart for Domain: " - + domain.getDomainUid() - + " change imagePullSecrets:\n" - + " name: imagePullSecret\n" - + " value: myImagePullSecret "); - domain.testDomainServerPodRestart(domainYaml); - domain.findServerPropertyChange("myImagePullSecret", "admin-server"); - domain.findServerPropertyChange("myImagePullSecret", "managed-server1"); - } finally { - // bring back the domain into previous state - restoreDomain(); - } + logger.info( + "About to testDomainServerPodRestart for Domain: " + + domain.getDomainUid() + + " change securityContext:\n" + + " runAsUser: 1000\n" + + " fsGroup: 2000 "); + domain.testDomainServerPodRestart(domainYaml); + domain.findServerPropertyChange("fsGroup: 2000", "admin-server"); + domain.findServerPropertyChange("fsGroup: 2000", "managed-server1"); logger.info("SUCCESS - " + testMethodName); } /** - * Modify/Add resources at ServerPod level using kubectl apply -f resource.domain.yaml. Verify all - * pods re-started. The property tested is: resources: limits: cpu: "1" requests: cpu: "0.5" args: - * - -cpus - "2" + * Modify/Add resources at ServerPod level using kubectl apply -f domain.yaml. Verify all pods + * re-started. The property tested is: resources: limits: cpu: "1" requests: cpu: "0.5" args: - + * -cpus - "2". * - * @throws Exception + * @throws Exception - assertion fails due to unmatched value or errors occurred if tested servers + * are not restarted or after restart the server yaml file doesn't include the new added + * property */ @Test public void testServerPodsRestartByChangingResource() throws Exception { @@ -303,52 +279,23 @@ public void testServerPodsRestartByChangingResource() throws Exception { String testMethodName = new Object() {}.getClass().getEnclosingMethod().getName(); logTestBegin(testMethodName); - // domainYaml: the yaml file name with changed property under resources dir - String domainYaml = "resource.domain.yaml"; - try { - logger.info( - "About to testDomainServerPodRestart for Domain: " - + domain.getDomainUid() - + " change resource:\n" - + " cpu: 500m"); - domain.testDomainServerPodRestart(domainYaml); - domain.findServerPropertyChange("cpu: 500m", "admin-server"); - domain.findServerPropertyChange("cpu: 500m", "managed-server1"); - } finally { - // bring back the domain into previous state - restoreDomain(); - } - - logger.info("SUCCESS - " + testMethodName); - } - - /** - * Modify the annotations at ServerPod level using kubectl apply -f annotation.domain.yaml. Verify - * all pods re-started. The property tested is: annotations: "TSTAMP" --> "DATETIME" - * - * @throws Exception - */ - @Test - public void testServerPodsRestartByChangingAnnotation() throws Exception { - Assume.assumeFalse(QUICKTEST); - String testMethodName = new Object() {}.getClass().getEnclosingMethod().getName(); - logTestBegin(testMethodName); + // firstly ensure that original domain.yaml doesn't include the property-to-be-addeded + String domainFileName = + BaseTest.getUserProjectsDir() + "/weblogic-domains/" + domainUid + "/domain.yaml"; + boolean result = TestUtils.checkFileIncludeProperty("cpu: 500m", domainFileName); + Assert.assertFalse(result); // domainYaml: the yaml file name with changed property under resources dir - String domainYaml = "annotation.domain.yaml"; - try { - logger.info( - "About to testDomainServerPodRestart for Domain: " - + domain.getDomainUid() - + " change annotation" - + " annotations:\n" - + " custom: \"DATETIME\""); - domain.testDomainServerPodRestart(domainYaml); + String domainYaml = "resource.domain.yaml"; - } finally { - // bring back the domain into previous state - restoreDomain(); - } + logger.info( + "About to testDomainServerPodRestart for Domain: " + + domain.getDomainUid() + + " change resource:\n" + + " cpu: 500m"); + domain.testDomainServerPodRestart(domainYaml); + domain.findServerPropertyChange("cpu: 500m", "admin-server"); + domain.findServerPropertyChange("cpu: 500m", "managed-server1"); logger.info("SUCCESS - " + testMethodName); } @@ -373,12 +320,4 @@ private static void destroyPodsRestartdomain() throws Exception { domain.destroy(); } } - - private static void restoreDomain() throws Exception { - String yamlFile = - BaseTest.getUserProjectsDir() + "/weblogic-domains/" + domainUid + "/domain.yaml"; - TestUtils.kubectlapply(yamlFile); - domain.verifyAdminServerRestarted(); - domain.verifyManagedServersRestarted(); - } } diff --git a/integration-tests/src/test/java/oracle/kubernetes/operator/utils/Domain.java b/integration-tests/src/test/java/oracle/kubernetes/operator/utils/Domain.java index 235195aa109..2b30402310e 100644 --- a/integration-tests/src/test/java/oracle/kubernetes/operator/utils/Domain.java +++ b/integration-tests/src/test/java/oracle/kubernetes/operator/utils/Domain.java @@ -981,23 +981,42 @@ public void findServerPropertyChange(String changedProperty, String serverName) } /** - * verify domain server pods get restarted after the property change by kubectl apply -f - * newDomainYamlfileWithChangedProperty + * verify domain server pods get restarted after the property change by kubectl apply -f new + * domain yaml file with added/changed property * - * @param fileNameWithChangedProperty - * @throws Exception + * @param fileNameWithChangedProperty - the fragment of domain yaml file with new added property + * change + * @throws Exception - IOException when file is copied or errors occurred if the tested server is + * not restarted */ public void testDomainServerPodRestart(String fileNameWithChangedProperty) throws Exception { logger.info("Inside testDomainServerPodRestart domainYamlWithChangedProperty"); - // kubectl apply the supplied domain yaml file under resources dir with changed property - String yamlDir = BaseTest.getProjectRoot() + "/integration-tests/src/test/resources/"; - TestUtils.kubectlapply(yamlDir + fileNameWithChangedProperty); + // copy the original domain.yaml to domain_new.yaml + TestUtils.copyFile( + BaseTest.getUserProjectsDir() + "/weblogic-domains/" + domainUid + "/domain.yaml", + BaseTest.getUserProjectsDir() + "/weblogic-domains/" + domainUid + "/domain_new.yaml"); + + // append the file with changed property to the end of domain_new.yaml + TestUtils.concatFile( + BaseTest.getProjectRoot() + + "/integration-tests/src/test/resources/" + + fileNameWithChangedProperty, + BaseTest.getUserProjectsDir() + "/weblogic-domains/" + domainUid + "/domain_new.yaml"); + + // kubectl apply the new constructed domain_new.yaml + TestUtils.kubectlapply( + BaseTest.getUserProjectsDir() + "/weblogic-domains/" + domainUid + "/domain_new.yaml"); // verify the servers in the domain are being restarted in a sequence verifyAdminServerRestarted(); verifyManagedServersRestarted(); + // make domain.yaml include the new changed property + TestUtils.copyFile( + BaseTest.getUserProjectsDir() + "/weblogic-domains/" + domainUid + "/domain_new.yaml", + BaseTest.getUserProjectsDir() + "/weblogic-domains/" + domainUid + "/domain.yaml"); + logger.info("Done - testDomainServerPodRestart with domainYamlWithChangedProperty"); } diff --git a/integration-tests/src/test/java/oracle/kubernetes/operator/utils/TestUtils.java b/integration-tests/src/test/java/oracle/kubernetes/operator/utils/TestUtils.java index e144efe18b3..066d6e8edb2 100644 --- a/integration-tests/src/test/java/oracle/kubernetes/operator/utils/TestUtils.java +++ b/integration-tests/src/test/java/oracle/kubernetes/operator/utils/TestUtils.java @@ -9,6 +9,7 @@ import java.io.FileInputStream; import java.io.FileReader; import java.io.FileWriter; +import java.io.IOException; import java.io.InputStream; import java.nio.file.Files; import java.nio.file.Paths; @@ -1202,4 +1203,53 @@ public static void copyFile(String fromFile, String toFile) throws Exception { logger.info("Copying file from " + fromFile + " to " + toFile); Files.copy(new File(fromFile).toPath(), Paths.get(toFile), StandardCopyOption.REPLACE_EXISTING); } + + /** + * append source file to the end of target file + * + * @param sourceFile - source file name + * @param targetFile - target file name + * @throws Exception + */ + public static void concatFile(String sourceFile, String targetFile) throws Exception { + FileReader fr = null; + FileWriter fw = null; + try { + fr = new FileReader(sourceFile); + fw = new FileWriter(targetFile, true); + int c = fr.read(); + while (c != -1) { + fw.write(c); + c = fr.read(); + } + } catch (IOException e) { + e.printStackTrace(); + } finally { + if (fr != null) { + fr.close(); + } + if (fw != null) { + fw.close(); + } + } + } + + /** + * check whether a certain property(String)is included in the file + * + * @param property + * @param fileName + * @return result of above checking + */ + public static boolean checkFileIncludeProperty(String property, String fileName) { + boolean result = false; + try { + String content = new String(Files.readAllBytes(Paths.get(fileName))); + result = content.indexOf(property) >= 0; + logger.info("the result for checkFileIncludeProperty " + fileName + " result: " + result); + } catch (IOException e) { + e.printStackTrace(); + } + return result; + } } diff --git a/integration-tests/src/test/resources/annotation.domain.yaml b/integration-tests/src/test/resources/annotation.domain.yaml deleted file mode 100644 index c56024e6f87..00000000000 --- a/integration-tests/src/test/resources/annotation.domain.yaml +++ /dev/null @@ -1,46 +0,0 @@ -#Modify the annotations at ServerPod Level -#This should re-start all the pods - -apiVersion: "weblogic.oracle/v3alpha1" -kind: Domain -metadata: - name: domainpodsrestart - namespace: default - labels: - weblogic.resourceVersion: domain-v2 - weblogic.domainUID: domainpodsrestart -spec: - domainHome: /shared/domains/domainpodsrestart - domainHomeInImage: false - image: "store/oracle/weblogic:12.2.1.3" - imagePullPolicy: "IfNotPresent" - webLogicCredentialsSecret: - name: domainpodsrestart-weblogic-credentials - includeServerOutInPodLog: true - logHomeEnabled: true - logHome: /shared/logs/domainpodsrestart - serverStartPolicy: "IF_NEEDED" - serverPod: - annotations: - custom: "DATETIME" - env: - - name: JAVA_OPTIONS - value: "-Dweblogic.StdoutDebugEnabled=false -Xms64m -Xmx1024m" - - name: USER_MEM_ARGS - value: "-Xms64m -Xmx256m " - volumes: - - name: weblogic-domain-storage-volume - persistentVolumeClaim: - claimName: domainpodsrestart-weblogic-sample-pvc - volumeMounts: - - mountPath: /shared - name: weblogic-domain-storage-volume - adminServer: - serverStartState: "RUNNING" - adminService: - channels: - - channelName: T3Channel - clusters: - - clusterName: cluster-1 - serverStartState: "RUNNING" - replicas: 1 diff --git a/integration-tests/src/test/resources/cont.security.context.domain.yaml b/integration-tests/src/test/resources/cont.security.context.domain.yaml index 3ec2ae5a65f..499500b2a94 100644 --- a/integration-tests/src/test/resources/cont.security.context.domain.yaml +++ b/integration-tests/src/test/resources/cont.security.context.domain.yaml @@ -3,43 +3,22 @@ #serverPod: # containerSecurityContext: # runAsUser: 1000 -# fsGroup: 2000 +# fsGroup: 1000 # The generated server pods should look like: #spec: # containers: # - name: weblogic.server # securityContext: -apiVersion: "weblogic.oracle/v3alpha1" -kind: Domain -metadata: - name: domainpodsrestart - namespace: default - labels: - weblogic.resourceVersion: domain-v2 - weblogic.domainUID: domainpodsrestart -spec: - domainHome: /shared/domains/domainpodsrestart - domainHomeInImage: false - image: "store/oracle/weblogic:12.2.1.3" - imagePullPolicy: "IfNotPresent" - imagePullSecrets: - - name: myImagePullSecret - webLogicCredentialsSecret: - name: domainpodsrestart-weblogic-credentials - includeServerOutInPodLog: true - logHomeEnabled: true - logHome: /shared/logs/domainpodsrestart - serverStartPolicy: "IF_NEEDED" serverPod: containerSecurityContext: runAsUser: 1000 - fsGroup: 2000 + fsGroup: 1000 env: - name: JAVA_OPTIONS - value: "-Dweblogic.StdoutDebugEnabled=false -Xms64m -Xmx1024m" + value: "-Dweblogic.StdoutDebugEnabled=false" - name: USER_MEM_ARGS - value: "-Xms64m -Xmx256m " + value: "-Djava.security.egd=file:/dev/./urandom -Xms64m -Xmx256m " volumes: - name: weblogic-domain-storage-volume persistentVolumeClaim: @@ -47,12 +26,4 @@ spec: volumeMounts: - mountPath: /shared name: weblogic-domain-storage-volume - adminServer: - serverStartState: "RUNNING" - adminService: - channels: - - channelName: T3Channel - clusters: - - clusterName: cluster-1 - serverStartState: "RUNNING" - replicas: 1 + \ No newline at end of file diff --git a/integration-tests/src/test/resources/pod.security.context.domain.yaml b/integration-tests/src/test/resources/pod.security.context.domain.yaml index 9735cdfdd4f..18c1fdfc311 100644 --- a/integration-tests/src/test/resources/pod.security.context.domain.yaml +++ b/integration-tests/src/test/resources/pod.security.context.domain.yaml @@ -10,49 +10,20 @@ # runAsUser: 1000 # fsGroup: 2000 -apiVersion: "weblogic.oracle/v3alpha1" -kind: Domain -metadata: - name: domainpodsrestart - namespace: default - labels: - weblogic.resourceVersion: domain-v2 - weblogic.domainUID: domainpodsrestart -spec: - domainHome: /shared/domains/domainpodsrestart - domainHomeInImage: false - image: "store/oracle/weblogic:12.2.1.3" - imagePullPolicy: "IfNotPresent" - imagePullSecrets: - - name: myImagePullSecret - webLogicCredentialsSecret: - name: domainpodsrestart-weblogic-credentials - includeServerOutInPodLog: true - logHomeEnabled: true - logHome: /shared/logs/domainpodsrestart - serverStartPolicy: "IF_NEEDED" serverPod: podSecurityContext: runAsUser: 1000 fsGroup: 2000 env: - name: JAVA_OPTIONS - value: "-Dweblogic.StdoutDebugEnabled=false -Xms64m -Xmx1024m" + value: "-Dweblogic.StdoutDebugEnabled=false" - name: USER_MEM_ARGS - value: "-Xms64m -Xmx256m " + value: "-Djava.security.egd=file:/dev/./urandom -Xms64m -Xmx256m " volumes: - name: weblogic-domain-storage-volume persistentVolumeClaim: claimName: domainpodsrestart-weblogic-sample-pvc volumeMounts: - mountPath: /shared - name: weblogic-domain-storage-volume - adminServer: - serverStartState: "RUNNING" - adminService: - channels: - - channelName: T3Channel - clusters: - - clusterName: cluster-1 - serverStartState: "RUNNING" - replicas: 1 + name: weblogic-domain-storage-volume + \ No newline at end of file diff --git a/integration-tests/src/test/resources/resource.domain.yaml b/integration-tests/src/test/resources/resource.domain.yaml index 6cf9c167b18..6f92ba6c273 100644 --- a/integration-tests/src/test/resources/resource.domain.yaml +++ b/integration-tests/src/test/resources/resource.domain.yaml @@ -10,25 +10,6 @@ # - -cpus # - "2" -apiVersion: "weblogic.oracle/v3alpha1" -kind: Domain -metadata: - name: domainpodsrestart - namespace: default - labels: - weblogic.resourceVersion: domain-v2 - weblogic.domainUID: domainpodsrestart -spec: - domainHome: /shared/domains/domainpodsrestart - domainHomeInImage: false - image: "store/oracle/weblogic:12.2.1.3" - imagePullPolicy: "IfNotPresent" - webLogicCredentialsSecret: - name: domainpodsrestart-weblogic-credentials - includeServerOutInPodLog: true - logHomeEnabled: true - logHome: /shared/logs/domainpodsrestart - serverStartPolicy: "IF_NEEDED" serverPod: resources: limits: @@ -40,22 +21,14 @@ spec: - "2" env: - name: JAVA_OPTIONS - value: "-Dweblogic.StdoutDebugEnabled=false -Xms64m -Xmx1024m" + value: "-Dweblogic.StdoutDebugEnabled=false" - name: USER_MEM_ARGS - value: "-Xms64m -Xmx256m " + value: "-Djava.security.egd=file:/dev/./urandom -Xms64m -Xmx256m " volumes: - name: weblogic-domain-storage-volume persistentVolumeClaim: claimName: domainpodsrestart-weblogic-sample-pvc volumeMounts: - mountPath: /shared - name: weblogic-domain-storage-volume - adminServer: - serverStartState: "RUNNING" - adminService: - channels: - - channelName: T3Channel - clusters: - - clusterName: cluster-1 - serverStartState: "RUNNING" - replicas: 1 + name: weblogic-domain-storage-volume + \ No newline at end of file diff --git a/integration-tests/src/test/resources/secret.domain.yaml b/integration-tests/src/test/resources/secret.domain.yaml deleted file mode 100644 index 885f3473c65..00000000000 --- a/integration-tests/src/test/resources/secret.domain.yaml +++ /dev/null @@ -1,49 +0,0 @@ -# Add imagePullSecrets section at Domain Level -# Make sure all pod(s) re-started -# imagePullSecrets: -# - name: imagePullSecret -# value: myImagePullSecret - -apiVersion: "weblogic.oracle/v3alpha1" -kind: Domain -metadata: - name: domainpodsrestart - namespace: default - labels: - weblogic.resourceVersion: domain-v2 - weblogic.domainUID: domainpodsrestart -spec: - domainHome: /shared/domains/domainpodsrestart - domainHomeInImage: false - image: "store/oracle/weblogic:12.2.1.3" - imagePullPolicy: "IfNotPresent" - imagePullSecrets: - - name: myImagePullSecret - webLogicCredentialsSecret: - name: domainpodsrestart-weblogic-credentials - includeServerOutInPodLog: true - logHomeEnabled: true - logHome: /shared/logs/domainpodsrestart - serverStartPolicy: "IF_NEEDED" - serverPod: - env: - - name: JAVA_OPTIONS - value: "-Dweblogic.StdoutDebugEnabled=false -Xms64m -Xmx1024m" - - name: USER_MEM_ARGS - value: "-Xms64m -Xmx256m " - volumes: - - name: weblogic-domain-storage-volume - persistentVolumeClaim: - claimName: domainpodsrestart-weblogic-sample-pvc - volumeMounts: - - mountPath: /shared - name: weblogic-domain-storage-volume - adminServer: - serverStartState: "RUNNING" - adminService: - channels: - - channelName: T3Channel - clusters: - - clusterName: cluster-1 - serverStartState: "RUNNING" - replicas: 1 From 572399a4f8cf0e9e26da2ac3415dc0dc40162f07 Mon Sep 17 00:00:00 2001 From: Maggie He Date: Wed, 3 Apr 2019 13:35:10 -0700 Subject: [PATCH 10/13] update README.md --- integration-tests/README.md | 2 -- 1 file changed, 2 deletions(-) diff --git a/integration-tests/README.md b/integration-tests/README.md index a350b3340be..f28475c2b86 100644 --- a/integration-tests/README.md +++ b/integration-tests/README.md @@ -87,10 +87,8 @@ Basic Use Cases described above are verified in all the domain configurations. A | Server pods restarted by changing imagePullPolicy | Verify admin and managed server pods being restarted by property change: imagePullPolicy: IfNotPresent --> imagePullPolicy: Never | | Server pods restarted by changing includeServerOutInPodLog | Verify admin and managed server pods being restarted by property change: includeServerOutInPodLog: true --> includeServerOutInPodLog: false | | Server pods restarted by changing logHomeEnable | Verify admin and managed server pods being restarted by property change: logHomeEnabled: true --> logHomeEnabled: false | -| Server pods restarted by changing annotations | Verify admin and managed server pods being restarted by property change: annotations: "TSTAMP" --> "DATETIME" | | Server pods restarted by changing containerSecurityContext | Verify admin and managed server pods being restarted by adding property change: containerSecurityContext: runAsUser: 1000 fsGroup: 2000 | | Server pods restarted by changing podSecurityContex | Verify admin and managed server pods being restarted by adding property change: podSecurityContext: runAsUser: 1000 fsGroup: 2000 | -| Server pods restarted by changing imagePullSecrets | Verify admin and managed server pods being restarted by adding property change: imagePullSecrets: name: imagePullSecr value: myImagePullSecret | | Server pods restarted by changing resources | Verify admin and managed server pods being restarted by adding property change: resources: limits: cpu: "1" requests: cpu: "0.5" args: - -cpus - "2" | Configuration Overrides Usecases From bfa884bd7a5f0f70f269ff804bfbb443b5335328 Mon Sep 17 00:00:00 2001 From: Maggie He Date: Wed, 3 Apr 2019 15:15:42 -0700 Subject: [PATCH 11/13] javadoc update --- .../oracle/kubernetes/operator/utils/Domain.java | 11 ++++++----- .../oracle/kubernetes/operator/utils/TestUtils.java | 12 ++++++------ 2 files changed, 12 insertions(+), 11 deletions(-) diff --git a/integration-tests/src/test/java/oracle/kubernetes/operator/utils/Domain.java b/integration-tests/src/test/java/oracle/kubernetes/operator/utils/Domain.java index 2b30402310e..b23364205a6 100644 --- a/integration-tests/src/test/java/oracle/kubernetes/operator/utils/Domain.java +++ b/integration-tests/src/test/java/oracle/kubernetes/operator/utils/Domain.java @@ -872,7 +872,7 @@ private void createPV() throws Exception { } /** - * verify domain server pods get restarted after a property change + * Verify domain server pods get restarted after a property change. * * @param oldPropertyString * @param newPropertyString @@ -929,11 +929,12 @@ public void testDomainServerPodRestart(String oldPropertyString, String newPrope } /** - * Get runtime server yaml file and verify the changed property is in that file + * Get runtime server yaml file and verify the changed property is in that file. * - * @param changedProperty - * @param serverName - * @throws Exception + * @param changedProperty - the changed/added property + * @param serverName - server name that is being tested + * @throws Exception - test FAILURE Exception if the changed property is not found in the server + * yaml file */ public void findServerPropertyChange(String changedProperty, String serverName) throws Exception { logger.info("Inside findServerPropertyChange"); diff --git a/integration-tests/src/test/java/oracle/kubernetes/operator/utils/TestUtils.java b/integration-tests/src/test/java/oracle/kubernetes/operator/utils/TestUtils.java index 066d6e8edb2..ee4b6170dc7 100644 --- a/integration-tests/src/test/java/oracle/kubernetes/operator/utils/TestUtils.java +++ b/integration-tests/src/test/java/oracle/kubernetes/operator/utils/TestUtils.java @@ -500,10 +500,10 @@ public static void kubectlexec(String podName, String namespace, String scriptPa } /** - * exec kubectl apply -f yamlFile + * The method to execute kubectl apply -f yamlFile. * - * @param yamlFile - * @throws Exception + * @param yamlFile - yaml file name + * @throws Exception - errors occurred while execute kubectl apply */ public static void kubectlapply(String yamlFile) throws Exception { @@ -1205,13 +1205,13 @@ public static void copyFile(String fromFile, String toFile) throws Exception { } /** - * append source file to the end of target file + * Method to append source file to the end of target file. * * @param sourceFile - source file name * @param targetFile - target file name - * @throws Exception + * @throws Exception - IOException during FileReader or FileWrite close call */ - public static void concatFile(String sourceFile, String targetFile) throws Exception { + public static void concatFile(String sourceFile, String targetFile) throws IOException { FileReader fr = null; FileWriter fw = null; try { From ab056c8e81fa5b1c78566370564f3e212a0b5e2a Mon Sep 17 00:00:00 2001 From: Maggie He Date: Thu, 4 Apr 2019 18:33:30 -0700 Subject: [PATCH 12/13] refactor the code --- .../kubernetes/operator/ITPodsRestart.java | 43 ++++++----- .../kubernetes/operator/utils/Domain.java | 73 +++++++++---------- .../kubernetes/operator/utils/TestUtils.java | 64 ---------------- 3 files changed, 57 insertions(+), 123 deletions(-) diff --git a/integration-tests/src/test/java/oracle/kubernetes/operator/ITPodsRestart.java b/integration-tests/src/test/java/oracle/kubernetes/operator/ITPodsRestart.java index 11cf30df9b6..0a627824735 100644 --- a/integration-tests/src/test/java/oracle/kubernetes/operator/ITPodsRestart.java +++ b/integration-tests/src/test/java/oracle/kubernetes/operator/ITPodsRestart.java @@ -4,6 +4,8 @@ package oracle.kubernetes.operator; +import java.nio.file.Files; +import java.nio.file.Paths; import java.util.Map; import oracle.kubernetes.operator.utils.Domain; import oracle.kubernetes.operator.utils.Operator; @@ -85,10 +87,10 @@ public void testServerPodsRestartByChangingEnvProperty() throws Exception { logTestBegin(testMethodName); logger.info( - "About to testDomainServerPodRestart for Domain: " + "About to verifyDomainServerPodRestart for Domain: " + domain.getDomainUid() + " env property: StdoutDebugEnabled=false to StdoutDebugEnabled=true"); - domain.testDomainServerPodRestart( + domain.verifyDomainServerPodRestart( "\"-Dweblogic.StdoutDebugEnabled=false\"", "\"-Dweblogic.StdoutDebugEnabled=true\""); logger.info("SUCCESS - " + testMethodName); @@ -108,10 +110,10 @@ public void testServerPodsRestartByChangingLogHomeEnabled() throws Exception { logTestBegin(testMethodName); logger.info( - "About to testDomainServerPodRestart for Domain: " + "About to verifyDomainServerPodRestart for Domain: " + domain.getDomainUid() + " logHomeEnabled: true --> logHomeEnabled: false"); - domain.testDomainServerPodRestart("logHomeEnabled: true", "logHomeEnabled: false"); + domain.verifyDomainServerPodRestart("logHomeEnabled: true", "logHomeEnabled: false"); logger.info("SUCCESS - " + testMethodName); } @@ -130,10 +132,10 @@ public void testServerPodsRestartByChangingImagePullPolicy() throws Exception { logTestBegin(testMethodName); logger.info( - "About to testDomainServerPodRestart for Domain: " + "About to verifyDomainServerPodRestart for Domain: " + domain.getDomainUid() + " imagePullPolicy: IfNotPresent --> imagePullPolicy: Never "); - domain.testDomainServerPodRestart( + domain.verifyDomainServerPodRestart( "imagePullPolicy: \"IfNotPresent\"", "imagePullPolicy: \"Never\" "); logger.info("SUCCESS - " + testMethodName); @@ -153,10 +155,10 @@ public void testServerPodsRestartByChangingIncludeServerOutInPodLog() throws Exc logTestBegin(testMethodName); logger.info( - "About to testDomainServerPodRestart for Domain: " + "About to verifyDomainServerPodRestart for Domain: " + domain.getDomainUid() + " includeServerOutInPodLog: true --> includeServerOutInPodLog: false"); - domain.testDomainServerPodRestart( + domain.verifyDomainServerPodRestart( "includeServerOutInPodLog: true", "includeServerOutInPodLog: false"); logger.info("SUCCESS - " + testMethodName); @@ -177,12 +179,12 @@ public void testServerPodsRestartByChangingZImage() throws Exception { try { logger.info( - "About to testDomainServerPodRestart for Domain: " + "About to verifyDomainServerPodRestart for Domain: " + domain.getDomainUid() + " Image property: store/oracle/weblogic:12.2.1.3 to store/oracle/weblogic:duplicate"); TestUtils.exec("docker tag store/oracle/weblogic:12.2.1.3 store/oracle/weblogic:duplicate"); - domain.testDomainServerPodRestart( + domain.verifyDomainServerPodRestart( "\"store/oracle/weblogic:12.2.1.3\"", "\"store/oracle/weblogic:duplicate\""); } finally { TestUtils.exec("docker rmi -f store/oracle/weblogic:duplicate"); @@ -209,18 +211,19 @@ public void testServerPodsRestartByChangingContSecurityContext() throws Exceptio // firstly ensure that original domain.yaml doesn't include the property-to-be-added String domainFileName = BaseTest.getUserProjectsDir() + "/weblogic-domains/" + domainUid + "/domain.yaml"; - boolean result = TestUtils.checkFileIncludeProperty("fsGroup: 1000", domainFileName); + boolean result = + (new String(Files.readAllBytes(Paths.get(domainFileName)))).contains("fsGroup: 1000"); Assert.assertFalse(result); // domainYaml: the yaml file name with changed property under resources dir String domainYaml = "cont.security.context.domain.yaml"; logger.info( - "About to testDomainServerPodRestart for Domain: " + "About to verifyDomainServerPodRestart for Domain: " + domain.getDomainUid() + " change container securityContext:\n" + " runAsUser: 1000\n" + " fsGroup: 1000 "); - domain.testDomainServerPodRestart(domainYaml); + domain.verifyDomainServerPodRestart(domainYaml); domain.findServerPropertyChange("securityContext", "admin-server"); domain.findServerPropertyChange("securityContext", "managed-server1"); @@ -245,19 +248,20 @@ public void testServerPodsRestartByChangingPodSecurityContext() throws Exception // firstly ensure that original domain.yaml doesn't include the property-to-be-added String domainFileName = BaseTest.getUserProjectsDir() + "/weblogic-domains/" + domainUid + "/domain.yaml"; - boolean result = TestUtils.checkFileIncludeProperty("fsGroup: 2000", domainFileName); + boolean result = + (new String(Files.readAllBytes(Paths.get(domainFileName)))).contains("fsGroup: 2000"); Assert.assertFalse(result); // domainYaml: the yaml file name with changed property under resources dir String domainYaml = "pod.security.context.domain.yaml"; logger.info( - "About to testDomainServerPodRestart for Domain: " + "About to verifyDomainServerPodRestart for Domain: " + domain.getDomainUid() + " change securityContext:\n" + " runAsUser: 1000\n" + " fsGroup: 2000 "); - domain.testDomainServerPodRestart(domainYaml); + domain.verifyDomainServerPodRestart(domainYaml); domain.findServerPropertyChange("fsGroup: 2000", "admin-server"); domain.findServerPropertyChange("fsGroup: 2000", "managed-server1"); @@ -282,18 +286,19 @@ public void testServerPodsRestartByChangingResource() throws Exception { // firstly ensure that original domain.yaml doesn't include the property-to-be-addeded String domainFileName = BaseTest.getUserProjectsDir() + "/weblogic-domains/" + domainUid + "/domain.yaml"; - boolean result = TestUtils.checkFileIncludeProperty("cpu: 500m", domainFileName); + boolean result = + (new String(Files.readAllBytes(Paths.get(domainFileName)))).contains("cpu: 500m"); Assert.assertFalse(result); // domainYaml: the yaml file name with changed property under resources dir String domainYaml = "resource.domain.yaml"; logger.info( - "About to testDomainServerPodRestart for Domain: " + "About to verifyDomainServerPodRestart for Domain: " + domain.getDomainUid() + " change resource:\n" + " cpu: 500m"); - domain.testDomainServerPodRestart(domainYaml); + domain.verifyDomainServerPodRestart(domainYaml); domain.findServerPropertyChange("cpu: 500m", "admin-server"); domain.findServerPropertyChange("cpu: 500m", "managed-server1"); diff --git a/integration-tests/src/test/java/oracle/kubernetes/operator/utils/Domain.java b/integration-tests/src/test/java/oracle/kubernetes/operator/utils/Domain.java index b23364205a6..c7358a12dca 100644 --- a/integration-tests/src/test/java/oracle/kubernetes/operator/utils/Domain.java +++ b/integration-tests/src/test/java/oracle/kubernetes/operator/utils/Domain.java @@ -878,7 +878,7 @@ private void createPV() throws Exception { * @param newPropertyString * @throws Exception */ - public void testDomainServerPodRestart(String oldPropertyString, String newPropertyString) + public void verifyDomainServerPodRestart(String oldPropertyString, String newPropertyString) throws Exception { logger.info("Inside testDomainServerPodRestart"); String content = @@ -949,35 +949,22 @@ public void findServerPropertyChange(String changedProperty, String serverName) + serverName + " -o yaml -n " + domainNS - + " > " - + outDir - + serverName - + ".yaml"); + + "|" + + "grep " + + "\"" + + changedProperty + + "\""); logger.info("kubectl execut with command: " + command.toString()); TestUtils.exec(command.toString()); - try { - String content = new String(Files.readAllBytes(Paths.get(outDir + serverName + ".yaml"))); - boolean result = content.indexOf(changedProperty) >= 0; - logger.info( - "Server name: " - + serverName - + " Search result for " - + changedProperty - + " is: " - + result); - if (!result) { - throw new Exception( - "FAILURE: didn't find the property: " - + changedProperty - + "in the " - + serverName - + ".yaml file"); - } - } finally { - String cmdString = "rm -rf " + outDir + serverName + ".yaml"; - TestUtils.exec(cmdString); + String result = ((TestUtils.exec(command.toString())).stdout()); + logger.info( + "in the method findServerPropertyChange, " + command.toString() + " return " + result); + if (!result.contains(changedProperty)) { + throw new Exception( + "FAILURE: didn't find the property: " + changedProperty + " for the server" + serverName); } + logger.info("Done - findServerPropertyChange"); } @@ -990,33 +977,39 @@ public void findServerPropertyChange(String changedProperty, String serverName) * @throws Exception - IOException when file is copied or errors occurred if the tested server is * not restarted */ - public void testDomainServerPodRestart(String fileNameWithChangedProperty) throws Exception { + public void verifyDomainServerPodRestart(String fileNameWithChangedProperty) throws Exception { logger.info("Inside testDomainServerPodRestart domainYamlWithChangedProperty"); + String newDomainYamlFile = + BaseTest.getUserProjectsDir() + "/weblogic-domains/" + domainUid + "/domain_new.yaml"; + String domainYamlFile = + BaseTest.getUserProjectsDir() + "/weblogic-domains/" + domainUid + "/domain.yaml"; + String fileWithChangedProperty = + BaseTest.getProjectRoot() + + "/integration-tests/src/test/resources/" + + fileNameWithChangedProperty; + // copy the original domain.yaml to domain_new.yaml - TestUtils.copyFile( - BaseTest.getUserProjectsDir() + "/weblogic-domains/" + domainUid + "/domain.yaml", - BaseTest.getUserProjectsDir() + "/weblogic-domains/" + domainUid + "/domain_new.yaml"); + TestUtils.copyFile(domainYamlFile, newDomainYamlFile); // append the file with changed property to the end of domain_new.yaml - TestUtils.concatFile( - BaseTest.getProjectRoot() - + "/integration-tests/src/test/resources/" - + fileNameWithChangedProperty, - BaseTest.getUserProjectsDir() + "/weblogic-domains/" + domainUid + "/domain_new.yaml"); + Files.write( + Paths.get(newDomainYamlFile), + Files.readAllBytes(Paths.get(fileWithChangedProperty)), + StandardOpenOption.APPEND); // kubectl apply the new constructed domain_new.yaml - TestUtils.kubectlapply( - BaseTest.getUserProjectsDir() + "/weblogic-domains/" + domainUid + "/domain_new.yaml"); + StringBuffer command = new StringBuffer(); + command.append("kubectl apply -f ").append(newDomainYamlFile); + logger.info("kubectl execut with command: " + command.toString()); + TestUtils.exec(command.toString()); // verify the servers in the domain are being restarted in a sequence verifyAdminServerRestarted(); verifyManagedServersRestarted(); // make domain.yaml include the new changed property - TestUtils.copyFile( - BaseTest.getUserProjectsDir() + "/weblogic-domains/" + domainUid + "/domain_new.yaml", - BaseTest.getUserProjectsDir() + "/weblogic-domains/" + domainUid + "/domain.yaml"); + TestUtils.copyFile(newDomainYamlFile, domainYamlFile); logger.info("Done - testDomainServerPodRestart with domainYamlWithChangedProperty"); } diff --git a/integration-tests/src/test/java/oracle/kubernetes/operator/utils/TestUtils.java b/integration-tests/src/test/java/oracle/kubernetes/operator/utils/TestUtils.java index ee4b6170dc7..25912719d30 100644 --- a/integration-tests/src/test/java/oracle/kubernetes/operator/utils/TestUtils.java +++ b/integration-tests/src/test/java/oracle/kubernetes/operator/utils/TestUtils.java @@ -9,7 +9,6 @@ import java.io.FileInputStream; import java.io.FileReader; import java.io.FileWriter; -import java.io.IOException; import java.io.InputStream; import java.nio.file.Files; import java.nio.file.Paths; @@ -499,20 +498,6 @@ public static void kubectlexec(String podName, String namespace, String scriptPa } } - /** - * The method to execute kubectl apply -f yamlFile. - * - * @param yamlFile - yaml file name - * @throws Exception - errors occurred while execute kubectl apply - */ - public static void kubectlapply(String yamlFile) throws Exception { - - StringBuffer command = new StringBuffer(); - command.append("kubectl apply -f ").append(yamlFile); - logger.info("kubectl execut with command: " + command.toString()); - exec(command.toString()); - } - public static int makeOperatorPostRestCall(Operator operator, String url, String jsonObjStr) throws Exception { return makeOperatorRestCall(operator, url, jsonObjStr); @@ -1203,53 +1188,4 @@ public static void copyFile(String fromFile, String toFile) throws Exception { logger.info("Copying file from " + fromFile + " to " + toFile); Files.copy(new File(fromFile).toPath(), Paths.get(toFile), StandardCopyOption.REPLACE_EXISTING); } - - /** - * Method to append source file to the end of target file. - * - * @param sourceFile - source file name - * @param targetFile - target file name - * @throws Exception - IOException during FileReader or FileWrite close call - */ - public static void concatFile(String sourceFile, String targetFile) throws IOException { - FileReader fr = null; - FileWriter fw = null; - try { - fr = new FileReader(sourceFile); - fw = new FileWriter(targetFile, true); - int c = fr.read(); - while (c != -1) { - fw.write(c); - c = fr.read(); - } - } catch (IOException e) { - e.printStackTrace(); - } finally { - if (fr != null) { - fr.close(); - } - if (fw != null) { - fw.close(); - } - } - } - - /** - * check whether a certain property(String)is included in the file - * - * @param property - * @param fileName - * @return result of above checking - */ - public static boolean checkFileIncludeProperty(String property, String fileName) { - boolean result = false; - try { - String content = new String(Files.readAllBytes(Paths.get(fileName))); - result = content.indexOf(property) >= 0; - logger.info("the result for checkFileIncludeProperty " + fileName + " result: " + result); - } catch (IOException e) { - e.printStackTrace(); - } - return result; - } } From d74e7b7416b9b8aef41e97da2bc4edbc721db56c Mon Sep 17 00:00:00 2001 From: Maggie He Date: Thu, 4 Apr 2019 18:47:52 -0700 Subject: [PATCH 13/13] javadoc update --- .../oracle/kubernetes/operator/utils/Domain.java | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/integration-tests/src/test/java/oracle/kubernetes/operator/utils/Domain.java b/integration-tests/src/test/java/oracle/kubernetes/operator/utils/Domain.java index c7358a12dca..fb291f512c6 100644 --- a/integration-tests/src/test/java/oracle/kubernetes/operator/utils/Domain.java +++ b/integration-tests/src/test/java/oracle/kubernetes/operator/utils/Domain.java @@ -874,9 +874,9 @@ private void createPV() throws Exception { /** * Verify domain server pods get restarted after a property change. * - * @param oldPropertyString - * @param newPropertyString - * @throws Exception + * @param oldPropertyString - the old property value + * @param newPropertyString - the new property value + * @throws Exception - IOException or errors occurred if the tested server is not restarted */ public void verifyDomainServerPodRestart(String oldPropertyString, String newPropertyString) throws Exception { @@ -969,13 +969,12 @@ public void findServerPropertyChange(String changedProperty, String serverName) } /** - * verify domain server pods get restarted after the property change by kubectl apply -f new - * domain yaml file with added/changed property + * Verify domain server pods get restarted after the property change by kubectl apply -f new + * domain yaml file with added/changed property. * * @param fileNameWithChangedProperty - the fragment of domain yaml file with new added property * change - * @throws Exception - IOException when file is copied or errors occurred if the tested server is - * not restarted + * @throws Exception - IOException or errors occurred if the tested server is not restarted */ public void verifyDomainServerPodRestart(String fileNameWithChangedProperty) throws Exception { logger.info("Inside testDomainServerPodRestart domainYamlWithChangedProperty");