Skip to content

Commit 521ff6e

Browse files
authored
Merge pull request #572 from oracle/sit-cfg-unit-testing
Sit cfg mock/unit testing - initial version
2 parents 176107b + a771106 commit 521ff6e

File tree

5 files changed

+177
-22
lines changed

5 files changed

+177
-22
lines changed

operator/src/main/resources/scripts/introspectDomain.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -878,8 +878,28 @@ def generateAndValidate(self):
878878
if not os.path.exists(self.env.CUSTOM_SITCFG_PATH):
879879
return
880880

881+
# We expect the user to include a 'version.txt' file in their situational
882+
# config directory.
883+
#
884+
# That file is expected to contain '2.0'
885+
#
886+
versionPath=os.path.join(self.env.CUSTOM_SITCFG_PATH,"version.txt")
887+
if not os.path.exists(versionPath):
888+
self.env.addError("Error, Required file, '"+versionPath+"', does not exist")
889+
else:
890+
version=self.env.readFile(versionPath).strip()
891+
if not version == "2.0":
892+
# truncate and ellipsify at 75 characters
893+
version = version[:75] + (version[75:] and '...')
894+
self.env.addError("Error, "+versionPath+" does not have the value of"
895+
+ " '2.0'. The current content: '" + version
896+
+ "' is not valid.")
897+
881898
for the_file in os.listdir(self.env.CUSTOM_SITCFG_PATH):
882899

900+
if the_file == "version.txt":
901+
continue
902+
883903
the_file_path = os.path.join(self.env.CUSTOM_SITCFG_PATH, the_file)
884904

885905
if not os.path.isfile(the_file_path):
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
/Servers/admin-server,ListenAddress,,domain1-admin-server
2+
#/Servers/admin-server,ListenAddress,foob,domain1-admin-server
3+
#/Servers/admin-server,ListenAddress,,foob
4+
#/Servers/admin-server,ListenAddress,,
5+
#,
6+
Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
# Copyright 2018, Oracle Corporation and/or its affiliates. All rights reserved.
2+
# Licensed under the Universal Permissive License v 1.0 as shown at http://oss.oracle.com/licenses/upl.a
3+
4+
import sys
5+
import os
6+
7+
#
8+
# This program verifies that bean attr values are expected values.
9+
#
10+
# Usage:
11+
#
12+
# Create a file with lines of format:
13+
# bean-path,attr-name,original-val,overridden-val
14+
#
15+
# For example:
16+
# /Servers/admin-server,ListenAddress,,domain1-admin-server
17+
#
18+
# If you don't want to check the original-val is as expected
19+
# then specify an asterisk (*) instead of the expected value.
20+
#
21+
# Then run this program:
22+
# wlst.sh checkBeans admin_name admin_pass url input_file_name
23+
#
24+
# The program will check that the original-val matches the value
25+
# in the 'domainConfig' mbean tree and that the overridden-val
26+
# matches the value in the 'serverConfig' mbean tree.
27+
#
28+
# The program exits with a non-zero exit code on any failure
29+
# (including an unexpected attribute value).
30+
#
31+
#
32+
33+
admin_username = sys.argv[1]
34+
admin_password = sys.argv[2]
35+
url = sys.argv[3]
36+
input_file = sys.argv[4]
37+
38+
connect(admin_username,admin_password,url)
39+
40+
errors=[]
41+
def addError(err):
42+
errors.append(err)
43+
44+
file = open(input_file, 'r')
45+
46+
line_no=0
47+
for line in file:
48+
line=line.strip()
49+
line_no+=1
50+
print "Info: input file line# " + str(line_no) + " ='"+line+"'"
51+
if len(line)>0 and line[0]=='#':
52+
continue
53+
words=line.split(',')
54+
if len(words) != 4:
55+
if line != '':
56+
addError("Error in line syntax line#=" + str(line_no) + " line='"+line+"'")
57+
continue
58+
bean_path=words[0]
59+
attr=words[1]
60+
originalExpected=words[2]
61+
overriddenExpected=words[3]
62+
63+
print(
64+
"Info: Checking bean_path='" + bean_path + "'"
65+
+ " attr='" + attr + "'"
66+
+ " originalExpected='" + originalExpected + "'"
67+
+ " overriddenExpected='" + overriddenExpected + "'"
68+
)
69+
70+
domainConfig()
71+
cd(bean_path)
72+
originalActual=str(get(attr))
73+
serverConfig()
74+
cd(bean_path)
75+
overriddenActual=str(get(attr))
76+
77+
print("Info: originalActual='" + originalActual + "'")
78+
print("Info: overriddenActual='" + overriddenActual + "'")
79+
80+
if originalExpected != '*' and originalActual != originalExpected:
81+
addError(
82+
"Error: got '" + originalActual + "'"
83+
+ " but expected value '" + originalExpected + "'"
84+
+ " for bean_path=domainConfig/" + bean_path
85+
+ " attr='" + attr + "'. "
86+
)
87+
88+
if overriddenActual != overriddenExpected:
89+
addError(
90+
"Error: got '" + overriddenActual + "'"
91+
+ " but expected value '" + overriddenExpected + "'"
92+
+ " for bean_path=serverConfig/" + bean_path
93+
+ " attr='" + attr + "'. "
94+
)
95+
file.close()
96+
97+
if len(errors) > 0:
98+
print "Found " + str(len(errors)) + " errors:"
99+
for err in errors:
100+
print " --> " + err
101+
exit(exitcode=1)
102+
103+
print "Test Passed!"

src/integration-tests/introspector/introspectTest.sh

Lines changed: 40 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ export NODEMGR_HOME=${NODEMGR_HOME:-/shared/nodemanagers}
117117
# values match the values in those macros.
118118

119119
export ADMIN_NAME=${ADMIN_NAME:-"admin-server"}
120-
export ADMIN_PORT=${ADMIN_PROT:-7001}
120+
export ADMIN_PORT=${ADMIN_PORT:-7001}
121121
export MANAGED_SERVER_NAME_BASE=${MANAGED_SERVER_NAME_BASE:-"managed-server"}
122122
export DOMAIN_NAME=${DOMAIN_NAME:-"base_domain"}
123123

@@ -241,7 +241,7 @@ function deployYamlTemplate() {
241241
if [ -f "{test_home}/${yaml_file}" ]; then
242242
kubectl -n $NAMESPACE delete -f ${test_home}/${yaml_file} \
243243
--ignore-not-found \
244-
2>&1 | tracePipe "kubectl output: "
244+
2>&1 | tracePipe "Info: kubectl output: "
245245
rm -f ${test_home}/${yaml_file}
246246
fi
247247

@@ -250,7 +250,7 @@ function deployYamlTemplate() {
250250
${SCRIPTPATH}/util_subst.sh -g ${yaml_file}t ${test_home}/${yaml_file} || exit 1
251251

252252
kubectl create -f ${test_home}/${yaml_file} \
253-
2>&1 | tracePipe "kubectl output: " || exit 1
253+
2>&1 | tracePipe "Info: kubectl output: " || exit 1
254254
}
255255

256256
#############################################################################
@@ -265,13 +265,13 @@ createConfigMapFromDir() {
265265

266266
kubectl -n $NAMESPACE create cm ${cm_name} \
267267
--from-file ${cm_dir} \
268-
2>&1 | tracePipe "kubectl output: " || exit 1
268+
2>&1 | tracePipe "Info: kubectl output: " || exit 1
269269

270270
kubectl -n $NAMESPACE label cm ${cm_name} \
271271
weblogic.createdByOperator=true \
272272
weblogic.operatorName=look-ma-no-hands \
273273
weblogic.resourceVersion=domain-v2 \
274-
2>&1 | tracePipe "kubectl output: " || exit 1
274+
2>&1 | tracePipe "Info: kubectl output: " || exit 1
275275
}
276276

277277

@@ -300,7 +300,7 @@ function deployDomainConfigMap() {
300300

301301
kubectl -n $NAMESPACE delete cm weblogic-domain-cm \
302302
--ignore-not-found \
303-
2>&1 | tracePipe "kubectl output: "
303+
2>&1 | tracePipe "Info: kubectl output: "
304304

305305
createConfigMapFromDir weblogic-domain-cm ${SOURCEPATH}/operator/src/main/resources/scripts
306306
}
@@ -329,7 +329,7 @@ function deployTestScriptConfigMap() {
329329

330330
kubectl -n $NAMESPACE delete cm test-script-cm \
331331
--ignore-not-found \
332-
2>&1 | tracePipe "kubectl output: "
332+
2>&1 | tracePipe "Info: kubectl output: "
333333

334334
createConfigMapFromDir test-script-cm ${test_home}/test-scripts
335335

@@ -413,7 +413,7 @@ function deployIntrospectJob() {
413413

414414
kubectl -n $NAMESPACE delete cm $introspect_output_cm_name \
415415
--ignore-not-found \
416-
2>&1 | tracePipe "kubectl output: "
416+
2>&1 | tracePipe "Info: kubectl output: "
417417

418418
# run introspection job
419419

@@ -452,26 +452,31 @@ function deployPod() {
452452
if [ -f "${target_yaml}" ]; then
453453
kubectl -n $NAMESPACE delete -f ${target_yaml} \
454454
--ignore-not-found \
455-
2>&1 | tracePipe "kubectl output: "
455+
2>&1 | tracePipe "Info: kubectl output: "
456456
rm -f ${target_yaml}
457457
fi
458458

459459
# Generate server pod yaml from template and deploy it
460460

461461
(
462462
export SERVER_NAME=${server_name}
463-
# TBD SERVER_NAME should be derived from introspect results
463+
# TBD SERVER_NAME, ADMIN_PORT, MANAGED_SERVER_PORT should be derived from introspect results
464464
export SERVICE_NAME=`toDNS1123Legal ${DOMAIN_UID}-${server_name}`
465465
export AS_SERVICE_NAME=`toDNS1123Legal ${DOMAIN_UID}-${ADMIN_NAME}`
466+
if [ "${SERVER_NAME}" = "${ADMIN_NAME}" ]; then
467+
export LOCAL_SERVER_DEFAULT_PORT=$ADMIN_PORT
468+
else
469+
export LOCAL_SERVER_DEFAULT_PORT=$MANAGED_SERVER_PORT
470+
fi
466471
${SCRIPTPATH}/util_subst.sh -g wl-pod.yamlt ${target_yaml} || exit 1
467472
) || exit 1
468473

469474
kubectl create -f ${target_yaml} \
470-
2>&1 | tracePipe "kubectl output: " || exit 1
475+
2>&1 | tracePipe "Info: kubectl output: " || exit 1
471476

472477
# Wait for pod to come up successfully
473478

474-
tracen "Waiting for pod readiness"
479+
tracen "Info: Waiting for pod readiness"
475480
local status="0/1"
476481
local startsecs=$SECONDS
477482
local maxsecs=180
@@ -504,7 +509,7 @@ function deploySinglePodService() {
504509
if [ -f "${target_yaml}" ]; then
505510
kubectl -n $NAMESPACE delete -f ${target_yaml} \
506511
--ignore-not-found \
507-
2>&1 | tracePipe "kubectl output: "
512+
2>&1 | tracePipe "Info: kubectl output: "
508513
rm -f ${target_yaml}
509514
fi
510515

@@ -517,7 +522,7 @@ function deploySinglePodService() {
517522
)
518523

519524
kubectl create -f ${target_yaml} \
520-
2>&1 | tracePipe "kubectl output: " || exit 1
525+
2>&1 | tracePipe "Info: kubectl output: " || exit 1
521526

522527
local svc=""
523528
local startsecs=$SECONDS
@@ -561,14 +566,32 @@ deployIntrospectJob
561566
# topology file
562567
#
563568

564-
deployPod ${ADMIN_NAME}
569+
deployPod ${ADMIN_NAME?}
570+
571+
deploySinglePodService ${ADMIN_NAME?} ${ADMIN_PORT?} 30701
565572

566-
deploySinglePodService ${ADMIN_NAME} 7001 30701
573+
deployPod ${MANAGED_SERVER_NAME_BASE?}1
567574

568-
deployPod ${MANAGED_SERVER_NAME_BASE}1
575+
deploySinglePodService ${MANAGED_SERVER_NAME_BASE?}1 ${MANAGED_SERVER_PORT?} 30801
569576

570577
#
571578
# TBD potentially add additional checks to verify wl pods are healthy
572579
#
573580

581+
# TBD 1 weblogic/welcome1 should be deduced via a base64 of the admin secret
582+
# TBD 2 generate checkBeans.input instead of using a hard coded file, add more beans to check, and check mgd servers too
583+
584+
trace "Info: Checking beans to see if sit-cfg took effect. Input file 'checkBeans.input', output file '$test_home/checkBeans.out'."
585+
kubectl cp checkBeans.input domain1-admin-server:/shared/checkBeans.input || exit 1
586+
kubectl cp checkBeans.py domain1-admin-server:/shared/checkBeans.py || exit 1
587+
kubectl exec -it domain1-admin-server \
588+
wlst.sh /shared/checkBeans.py \
589+
weblogic welcome1 t3://domain1-admin-server:7001 \
590+
/shared/checkBeans.input \
591+
> $test_home/checkBeans.out 2>&1
592+
if [ $? -ne 0 ]; then
593+
trace "Error: checkBeans failed, see '$test_home/checkBeans.out'."
594+
exit 1
595+
fi
596+
574597
trace "Info: success!"

src/integration-tests/introspector/wl-pod.yamlt

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,8 @@ spec:
4343
value: "${SERVICE_NAME}"
4444
- name: AS_SERVICE_NAME
4545
value: "${AS_SERVICE_NAME}"
46+
- name: LOCAL_SERVER_DEFAULT_PORT
47+
value: "${LOCAL_SERVER_DEFAULT_PORT}"
4648
- name: ADMIN_USERNAME
4749
value: ""
4850
- name: ADMIN_PASSWORD
@@ -71,15 +73,16 @@ spec:
7173
# timeoutSeconds: 5
7274
name: weblogic-server
7375
ports:
74-
- containerPort: ${ADMIN_PORT}
76+
- containerPort: ${LOCAL_SERVER_DEFAULT_PORT}
7577
protocol: TCP
7678
readinessProbe:
77-
exec:
78-
command:
79-
- /weblogic-operator/scripts/readinessProbe.sh
8079
failureThreshold: 1
80+
httpGet:
81+
path: /weblogic
82+
port: ${LOCAL_SERVER_DEFAULT_PORT}
83+
scheme: HTTP
8184
initialDelaySeconds: 2
82-
periodSeconds: 5
85+
periodSeconds: 1
8386
successThreshold: 1
8487
timeoutSeconds: 5
8588
resources: {}

0 commit comments

Comments
 (0)