|
| 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() |
0 commit comments