Skip to content

Commit 14b1575

Browse files
committed
Added unit tests for extractDomainResource
1 parent 9c40c6b commit 14b1575

File tree

4 files changed

+192
-0
lines changed

4 files changed

+192
-0
lines changed

core/src/test/python/base_test.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,9 @@ def _match(self, value, dictionary, *args):
7070
key = '/'.join(list(args))
7171
self.fail(key + ' equals ' + str(dictionary_value) + ', should equal ' + str(value))
7272

73+
def _match_values(self, description, actual, expected):
74+
self.assertEqual(actual, expected, description + " equals " + str(actual) + ", should equal " + str(expected))
75+
7376
def _no_dictionary_key(self, dictionary, key):
7477
if key in dictionary:
7578
self.fail('Dictionary should not contain ' + key)
Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
"""
2+
Copyright (c) 2021, Oracle and/or its affiliates.
3+
Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl.
4+
"""
5+
import os
6+
7+
from base_test import BaseTestCase
8+
from wlsdeploy.logging.platform_logger import PlatformLogger
9+
from wlsdeploy.tool.extract.domain_resource_extractor import DomainResourceExtractor
10+
from wlsdeploy.util.model import Model
11+
from wlsdeploy.util.model_context import ModelContext
12+
from wlsdeploy.util.model_translator import FileToPython
13+
14+
15+
class ExtractTest(BaseTestCase):
16+
__logger = PlatformLogger('wlsdeploy.extract')
17+
18+
def __init__(self, *args):
19+
BaseTestCase.__init__(self, *args)
20+
self.MODELS_DIR = os.path.join(self.TEST_CLASSES_DIR, 'extract')
21+
self.EXTRACT_OUTPUT_DIR = os.path.join(self.TEST_OUTPUT_DIR, 'extract')
22+
23+
def setUp(self):
24+
BaseTestCase.setUp(self)
25+
self._establish_directory(self.EXTRACT_OUTPUT_DIR)
26+
27+
def testDefaultModel(self):
28+
"""
29+
Test that default values and information from the model
30+
are incorporated into the resulting domain resource file.
31+
"""
32+
resource = self._extract_domain_resource('1')
33+
34+
# clusters from topology should be in the domain resource file
35+
cluster_list = self._traverse(resource, 'spec', 'clusters')
36+
self._match_values("Cluster count", len(cluster_list), 2)
37+
self._match_values("Cluster 0 clusterName", cluster_list[0]['clusterName'], 'cluster1')
38+
self._match_values("Cluster 0 replicas", cluster_list[0]['replicas'], 3)
39+
self._match_values("Cluster 1 clusterName", cluster_list[1]['clusterName'], 'cluster2')
40+
self._match_values("Cluster 1 replicas", cluster_list[1]['replicas'], 12)
41+
42+
# secrets from the model should be in the domain resource file
43+
secret_list = self._traverse(resource, 'spec', 'configuration', 'secrets')
44+
self._match_values("Secret count", len(secret_list), 2)
45+
self._match_values("Secret 0", secret_list[0], 'demodomain-m1-system')
46+
self._match_values("Secret 1", secret_list[1], 'demodomain-m2-system')
47+
48+
def testKubernetesModel(self):
49+
"""
50+
Test that fields from the kubernetes section of the model
51+
are transferred to the resulting domain resource file
52+
"""
53+
resource = self._extract_domain_resource('2')
54+
55+
# clusters from kubernetes section should be in the domain resource file
56+
cluster_list = self._traverse(resource, 'spec', 'clusters')
57+
self._match_values("Cluster count", len(cluster_list), 2)
58+
self._match_values("Cluster 0 clusterName", cluster_list[0]['clusterName'], 'CLUSTER_1')
59+
self._match_values("Cluster 1 clusterName", cluster_list[1]['clusterName'], 'CLUSTER_2')
60+
61+
# secrets from the model should be in the domain resource file
62+
secret_list = self._traverse(resource, 'spec', 'configuration', 'secrets')
63+
self._match_values("Secret count", len(secret_list), 2)
64+
self._match_values("Secret 0", secret_list[0], 'secret-1')
65+
self._match_values("Secret 1", secret_list[1], 'secret-2')
66+
67+
def _extract_domain_resource(self, suffix):
68+
model_file = os.path.join(self.MODELS_DIR, 'model-' + suffix + '.yaml')
69+
translator = FileToPython(model_file, use_ordering=True)
70+
model_dict = translator.parse()
71+
model = Model(model_dict)
72+
73+
resource_file = os.path.join(self.EXTRACT_OUTPUT_DIR, 'domain-resource-' + suffix + '.yaml')
74+
args_map = {
75+
'-domain_home': '/u01/domain',
76+
'-oracle_home': '/oracle',
77+
'-domain_resource_file': resource_file
78+
}
79+
model_context = ModelContext('ExtractTest', args_map)
80+
81+
extractor = DomainResourceExtractor(model, model_context, self.__logger)
82+
extractor.extract()
83+
84+
translator = FileToPython(resource_file, use_ordering=True)
85+
return translator.parse()
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# Copyright (c) 2021, Oracle Corporation 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+
# Test model for extractDomainResource.
5+
# This will test that default values and information from the model
6+
# are incorporated into the resulting domain resource file.
7+
8+
topology:
9+
Name: DemoDomain
10+
Cluster:
11+
cluster1:
12+
# should get a replicas value of 3, since 3 servers are assigned
13+
cluster2:
14+
# should get a replicas value of 12, based on dynamic cluster size
15+
DynamicServers:
16+
DynamicClusterSize: 12
17+
Server:
18+
AdminServer:
19+
Cluster: cluster1
20+
m1:
21+
Cluster: cluster1
22+
# secrets should be listed in domain resource
23+
SystemPasswordEncrypted: '@@SECRET:@@ENV:DOMAIN_UID@@-m1-system:password@@'
24+
m2:
25+
Cluster: cluster1
26+
# secrets should be listed in domain resource
27+
SystemPasswordEncrypted: '@@SECRET:@@ENV:DOMAIN_UID@@-m2-system:password@@'
Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
# Copyright (c) 2021, Oracle Corporation 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+
# Test model for extractDomainResource.
5+
# This will test that fields from the kubernetes section of the model
6+
# are transferred to the resulting domain resource file
7+
8+
kubernetes:
9+
apiVersion: weblogic.oracle/v6
10+
kind: Domain
11+
metadata:
12+
name: DOMAIN_UID
13+
namespace: NAMESPACE
14+
labels:
15+
weblogic.resourceVersion: domain-v2
16+
weblogic.domainUID: DOMAIN_UID
17+
spec:
18+
domainHome: DOMAIN_HOME
19+
domainHomeInImage: true
20+
image: phx.ocir.io/weblogick8s/onprem-domain-image:2.0
21+
imagePullPolicy: Always
22+
imagePullSecrets:
23+
- name: WEBLOGIC_IMAGE_PULL_SECRET_NAME
24+
webLogicCredentialsSecret:
25+
name: WEBLOGIC_CREDENTIALS_SECRET_NAME
26+
includeServerOutInPodLog: 1
27+
logHomeEnabled: 0
28+
logHome: /scratch/logs
29+
dataHome: /data
30+
serverStartPolicy: IF_NEEDED
31+
serverPod:
32+
env:
33+
- name: JAVA_OPTIONS
34+
value: -good_java
35+
- name: USER_MEM_ARGS
36+
value: '-XX:+UseContainerSupport -Djava.security.egd=file:/dev/./urandom '
37+
volumes:
38+
- name: weblogic-domain-storage-volume
39+
persistentVolumeClaim:
40+
claimName: DOMAIN_PVC_NAME
41+
volumeMounts:
42+
- name: weblogic-domain-storage-volume
43+
mountPath: DOMAIN_ROOT_DIR
44+
adminServer:
45+
serverStartState: RUNNING
46+
serverStartPolicy: ADMIN_ONLY
47+
restartVersion: xyz
48+
adminService:
49+
annotations:
50+
abc: xyz
51+
lmn: opq
52+
labels:
53+
abc: xyz
54+
lmn: opq
55+
channels:
56+
- channelName: default
57+
nodePort: 5001
58+
- channelName: T3Channel
59+
serverPod:
60+
env:
61+
- name: JAVA_OPTIONS
62+
value: -im_admin_pod
63+
- name: USER_MEM_ARGS
64+
value: '-XX:+UseContainerSupport -Djava.security.egd=file:/dev/./urandom '
65+
clusters:
66+
- clusterName: CLUSTER_1
67+
serverStartState: RUNNING
68+
replicas: 1
69+
- clusterName: CLUSTER_2
70+
serverStartState: RUNNING
71+
replicas: 4
72+
configuration:
73+
model:
74+
domainType: WLS
75+
secrets:
76+
- secret-1
77+
- secret-2

0 commit comments

Comments
 (0)