Skip to content

Commit 72c46f7

Browse files
authored
OWLS-90888 added negative AI test: Error path due File Permission issue (#2463)
* added test for file permission in the AI image
1 parent bcd564b commit 72c46f7

File tree

2 files changed

+141
-0
lines changed

2 files changed

+141
-0
lines changed

integration-tests/src/test/java/oracle/weblogic/kubernetes/ItMiiAuxiliaryImage.java

Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -736,6 +736,108 @@ public void testErrorPathDomainWithFailCustomMountCommand() {
736736
checkPodReady(adminServerPodName, domainUid, domainNamespace);
737737
}
738738

739+
/**
740+
* Negative Test to create domain with file , created by user tester with permission read only
741+
* and not accessible by oracle user in auxiliary image
742+
* via provided Dockerfile.
743+
* Check the error msg is in introspector pod log, domain events and operator pod log.
744+
*/
745+
@Test
746+
@Order(7)
747+
@DisplayName("Negative Test to create domain with file in auxiliary image not accessible by oracle user")
748+
public void testErrorPathFilePermission() {
749+
750+
OffsetDateTime timestamp = now();
751+
String errorPathAuxiliaryImage1 = MII_AUXILIARY_IMAGE_NAME + ":errorpathimage4";
752+
753+
final String auxiliaryImageVolumeName = "auxiliaryImageVolume1";
754+
final String auxiliaryImagePath = "/auxiliary";
755+
756+
createSecretsForDomain(adminSecretName, encryptionSecretName, errorpathDomainNamespace);
757+
758+
// create stage dir for auxiliary image
759+
Path errorpathAIPath1 = Paths.get(RESULTS_ROOT, "errorpathauxiimage4");
760+
assertDoesNotThrow(() -> FileUtils.deleteDirectory(errorpathAIPath1.toFile()));
761+
assertDoesNotThrow(() -> Files.createDirectories(errorpathAIPath1));
762+
763+
Path errorpathAIPathToFile = Paths.get(RESULTS_ROOT, "errorpathauxiimage4/test1.txt");
764+
String content = "some text ";
765+
assertDoesNotThrow(() -> Files.write(errorpathAIPathToFile, content.getBytes()),
766+
"Can't write to file " + errorpathAIPathToFile);
767+
768+
// create models dir and copy model for image
769+
Path modelsPath1 = Paths.get(errorpathAIPath1.toString(), "models");
770+
assertDoesNotThrow(() -> Files.createDirectories(modelsPath1));
771+
assertDoesNotThrow(() -> Files.copy(
772+
Paths.get(MODEL_DIR, MII_BASIC_WDT_MODEL_FILE),
773+
Paths.get(modelsPath1.toString(), MII_BASIC_WDT_MODEL_FILE),
774+
StandardCopyOption.REPLACE_EXISTING));
775+
776+
// build app
777+
assertTrue(buildAppArchive(defaultAppParams()
778+
.srcDirList(Collections.singletonList(MII_BASIC_APP_NAME))
779+
.appName(MII_BASIC_APP_NAME)),
780+
String.format("Failed to create app archive for %s", MII_BASIC_APP_NAME));
781+
782+
// copy app archive to models
783+
assertDoesNotThrow(() -> Files.copy(
784+
Paths.get(ARCHIVE_DIR, MII_BASIC_APP_NAME + ".zip"),
785+
Paths.get(modelsPath1.toString(), MII_BASIC_APP_NAME + ".zip"),
786+
StandardCopyOption.REPLACE_EXISTING));
787+
788+
// unzip WDT installation file into work dir
789+
unzipWDTInstallationFile(errorpathAIPath1.toString());
790+
791+
// create image with model and wdt installation files
792+
createAuxiliaryImage(errorpathAIPath1.toString(),
793+
Paths.get(RESOURCE_DIR, "auxiliaryimage", "/negative/Dockerfile").toString(), errorPathAuxiliaryImage1);
794+
795+
// push image to repo for multi node cluster
796+
if (!DOMAIN_IMAGES_REPO.isEmpty()) {
797+
logger.info("docker push image {0} to registry {1}", errorPathAuxiliaryImage1, DOMAIN_IMAGES_REPO);
798+
assertTrue(dockerPush(errorPathAuxiliaryImage1),
799+
String.format("docker push failed for image %s", errorPathAuxiliaryImage1));
800+
}
801+
802+
// create domain custom resource using auxiliary images
803+
logger.info("Creating domain custom resource with domainUid {0} and auxiliary image {1}",
804+
domainUid, errorPathAuxiliaryImage1);
805+
Domain domainCR = createDomainResource(domainUid, errorpathDomainNamespace,
806+
WEBLOGIC_IMAGE_NAME + ":" + WEBLOGIC_IMAGE_TAG, adminSecretName, OCIR_SECRET_NAME,
807+
encryptionSecretName, replicaCount, "cluster-1", auxiliaryImagePath,
808+
auxiliaryImageVolumeName, errorPathAuxiliaryImage1);
809+
810+
// create domain and verify it is failed
811+
logger.info("Creating domain {0} with auxiliary image {1} in namespace {2}",
812+
domainUid, errorPathAuxiliaryImage1, errorpathDomainNamespace);
813+
assertDoesNotThrow(() -> createDomainCustomResource(domainCR), "createDomainCustomResource throws Exception");
814+
815+
// check the introspector pod log contains the expected error msg
816+
String expectedErrorMsg = "cp: can't open '/auxiliary/test1.txt': Permission denied";
817+
String introspectorPodName = assertDoesNotThrow(() -> getIntrospectorPodName(domainUid, errorpathDomainNamespace));
818+
checkPodLogContainsString(errorpathDomainNamespace, introspectorPodName, expectedErrorMsg);
819+
820+
// check the domain event contains the expected error msg
821+
checkDomainEventContainsExpectedMsg(opNamespace, errorpathDomainNamespace, domainUid, DOMAIN_PROCESSING_FAILED,
822+
"Warning", timestamp, expectedErrorMsg);
823+
824+
// check the operator pod log contains the expected error msg
825+
String operatorPodName =
826+
assertDoesNotThrow(() -> getOperatorPodName(OPERATOR_RELEASE_NAME, opNamespace));
827+
checkPodLogContainsString(opNamespace, operatorPodName, expectedErrorMsg);
828+
829+
// check there are no admin server and managed server pods and services not created
830+
checkPodDoesNotExist(adminServerPodName, domainUid, errorpathDomainNamespace);
831+
checkServiceDoesNotExist(adminServerPodName, errorpathDomainNamespace);
832+
for (int i = 1; i <= replicaCount; i++) {
833+
checkPodDoesNotExist(managedServerPrefix + i, domainUid, errorpathDomainNamespace);
834+
checkServiceDoesNotExist(managedServerPrefix + i, errorpathDomainNamespace);
835+
}
836+
837+
// delete domain1
838+
deleteDomainResource(errorpathDomainNamespace, domainUid);
839+
}
840+
739841
private static void patchDomainWithAuxiliaryImageAndVerify(String oldImageName, String newImageName,
740842
String domainUid, String domainNamespace) {
741843
String adminServerPodName = domainUid + "-admin-server";
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
# Copyright (c) 2021, Oracle and/or its affiliates.
2+
# Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl.
3+
4+
# This is a sample Dockerfile for supplying Model in Image model files
5+
# and a WDT installation in a small separate auxiliary
6+
# image. This is an alternative to supplying the files directly
7+
# in the domain resource `domain.spec.image` image.
8+
9+
# AUXILIARY_IMAGE_PATH arg:
10+
# Parent location for Model in Image model and WDT installation files.
11+
# Must match domain resource 'domain.spec.auxiliaryImageVolumes.mountPath'
12+
# For model-in-image, the following two domain resource attributes can
13+
# be a directory in the mount path:
14+
# 1) 'domain.spec.configuration.model.modelHome'
15+
# 2) 'domain.spec.configuration.model.wdtInstallHome'
16+
# Default '/auxiliary'.
17+
#
18+
19+
FROM busybox
20+
ARG AUXILIARY_IMAGE_PATH=/auxiliary
21+
ARG USER=tester
22+
ARG USERID=1001
23+
ARG GROUP=myroot
24+
ENV AUXILIARY_IMAGE_PATH=${AUXILIARY_IMAGE_PATH}
25+
RUN addgroup -g $USERID $GROUP
26+
RUN adduser -D -u ${USERID} -G $GROUP $USER
27+
COPY ./ ${AUXILIARY_IMAGE_PATH}/
28+
RUN chgrp $GROUP ${AUXILIARY_IMAGE_PATH}/models
29+
RUN chgrp $GROUP ${AUXILIARY_IMAGE_PATH}/test1.txt
30+
RUN chown -R $USER:$GROUP ${AUXILIARY_IMAGE_PATH}/models
31+
RUN chown -R $USER:$GROUP ${AUXILIARY_IMAGE_PATH}/test1.txt
32+
RUN chmod 640 ${AUXILIARY_IMAGE_PATH}/test1.txt
33+
RUN chmod 640 ${AUXILIARY_IMAGE_PATH}/models
34+
ARG USER=oracle
35+
ARG USERID=1000
36+
ARG GROUP=root
37+
RUN adduser -D -u ${USERID} -G $GROUP $USER
38+
RUN chown -R $USER:$GROUP ${AUXILIARY_IMAGE_PATH}/weblogic-deploy
39+
USER $USER

0 commit comments

Comments
 (0)