Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions integration-tests/USECASES.MD
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,9 @@ 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 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 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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -26,6 +28,7 @@ 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
Expand Down Expand Up @@ -84,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);
Expand All @@ -107,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);
}
Expand All @@ -129,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);
Expand All @@ -152,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);
Expand All @@ -176,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");
Expand All @@ -190,13 +193,127 @@ public void testServerPodsRestartByChangingZImage() throws Exception {
logger.info("SUCCESS - " + testMethodName);
}

/**
* 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: 1000.
*
* @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 {
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-added
String domainFileName =
BaseTest.getUserProjectsDir() + "/weblogic-domains/" + domainUid + "/domain.yaml";
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 verifyDomainServerPodRestart for Domain: "
+ domain.getDomainUid()
+ " change container securityContext:\n"
+ " runAsUser: 1000\n"
+ " fsGroup: 1000 ");
domain.verifyDomainServerPodRestart(domainYaml);
domain.findServerPropertyChange("securityContext", "admin-server");
domain.findServerPropertyChange("securityContext", "managed-server1");

logger.info("SUCCESS - " + testMethodName);
}

/**
* 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.
*
* @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 {
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-added
String domainFileName =
BaseTest.getUserProjectsDir() + "/weblogic-domains/" + domainUid + "/domain.yaml";
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 verifyDomainServerPodRestart for Domain: "
+ domain.getDomainUid()
+ " change securityContext:\n"
+ " runAsUser: 1000\n"
+ " fsGroup: 2000 ");
domain.verifyDomainServerPodRestart(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 domain.yaml. Verify all pods
* re-started. The property tested is: resources: limits: cpu: "1" requests: cpu: "0.5" args: -
* -cpus - "2".
*
* @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 {
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 =
(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 verifyDomainServerPodRestart for Domain: "
+ domain.getDomainUid()
+ " change resource:\n"
+ " cpu: 500m");
domain.verifyDomainServerPodRestart(domainYaml);
domain.findServerPropertyChange("cpu: 500m", "admin-server");
domain.findServerPropertyChange("cpu: 500m", "managed-server1");

logger.info("SUCCESS - " + testMethodName);
}

private static Domain createPodsRestartdomain() throws Exception {

Map<String, Object> domainMap = TestUtils.loadYaml(DOMAINONPV_WLST_YAML);
domainMap.put("domainUID", "domainpodsrestart");
domainMap.put("initialManagedServerReplicas", new Integer("1"));

logger.info("Creating Domain domain& verifing the domain creation");
domainUid = (String) domainMap.get("domainUID");
logger.info("Creating and verifying the domain creation with domainUid: " + domainUid);

domain = TestUtils.createDomain(domainMap);
domain.verifyDomainCreated();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -815,13 +815,13 @@ 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
* @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 testDomainServerPodRestart(String oldPropertyString, String newPropertyString)
public void verifyDomainServerPodRestart(String oldPropertyString, String newPropertyString)
throws Exception {
logger.info("Inside testDomainServerPodRestart");
String content =
Expand Down Expand Up @@ -871,6 +871,91 @@ public void testDomainServerPodRestart(String oldPropertyString, String newPrope
logger.info("Done - testDomainServerPodRestart");
}

/**
* Get runtime server yaml file and verify the changed property is in that file.
*
* @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");
// get runtime server pod yaml file
String outDir = BaseTest.getUserProjectsDir() + "/weblogic-domains/" + domainUid + "/";
StringBuffer command = new StringBuffer();
Copy link
Contributor

Choose a reason for hiding this comment

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

As you are already executing a command, you can change it to

kubectl get pod <podname> -o yaml -n ns | grep changedProperty 

instead of saving the file and looking for a string later..

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

command
.append("kubectl get po/")
.append(
domainUid
+ "-"
+ serverName
+ " -o yaml -n "
+ domainNS
+ "|"
+ "grep "
+ "\""
+ changedProperty
+ "\"");
logger.info("kubectl execut with command: " + command.toString());
TestUtils.exec(command.toString());

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");
}

/**
* 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 or errors occurred if the tested server is not restarted
*/
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(domainYamlFile, newDomainYamlFile);

// append the file with changed property to the end of domain_new.yaml
Files.write(
Paths.get(newDomainYamlFile),
Files.readAllBytes(Paths.get(fileWithChangedProperty)),
StandardOpenOption.APPEND);

// kubectl apply the new constructed 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(newDomainYamlFile, domainYamlFile);

logger.info("Done - testDomainServerPodRestart with domainYamlWithChangedProperty");
}

/**
* verify that admin server pod gets restarted.
*
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# Add podSecurityContext section at ServerPod Level
# Make sure all pod(s) re-started
#serverPod:
# containerSecurityContext:
# runAsUser: 1000
# fsGroup: 1000
# The generated server pods should look like:
#spec:
# containers:
# - name: weblogic.server
# securityContext:

serverPod:
containerSecurityContext:
runAsUser: 1000
fsGroup: 1000
env:
- name: JAVA_OPTIONS
value: "-Dweblogic.StdoutDebugEnabled=false"
- name: USER_MEM_ARGS
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

Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# 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

serverPod:
podSecurityContext:
runAsUser: 1000
fsGroup: 2000
env:
- name: JAVA_OPTIONS
value: "-Dweblogic.StdoutDebugEnabled=false"
- name: USER_MEM_ARGS
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

Loading