Skip to content
68 changes: 20 additions & 48 deletions Jenkinsfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,16 @@ pipeline {
agent any

environment {
wdt_tenancy = "${env.WKT_TENANCY}"
alias_test_job_name = 'wdt-alias-test-verify'
jenkins_uid = sh(returnStdout: true, script: 'id -u').trim()
jenkins_gid = sh(returnStdout: true, script: 'id -g').trim()
docker_gid = sh(returnStdout: true, script: 'getent group docker | cut -d: -f3').trim()
}

triggers {
// timer trigger for "nightly build" on main branch
cron( env.BRANCH_NAME.equals('main') ? 'H H(0-3) * * 1-5' : '')
}

stages {
stage ('Environment') {
tools {
Expand All @@ -27,21 +29,25 @@ pipeline {
jdk 'jdk8'
}
steps {
sh '''
mvn -B -DskipTests clean package
'''
// Using Maven batch mode to suppress download progress lines in Jenkins output
//
withMaven(globalMavenSettingsConfig: 'wkt-maven-settings-xml', publisherStrategy: 'EXPLICIT') {
sh "mvn -B -DskipTests clean package"
}
}
}
stage ('Test') {
agent {
docker {
alwaysPull true
reuseNode true
image 'phx.ocir.io/weblogick8s/wdt/jenkins-slave:122130'
args '-u jenkins -v /var/run/docker.sock:/var/run/docker.sock'
image 'phx.ocir.io/devweblogic/wdt/jenkins-slave:122130'
args "-u ${jenkins_uid}:${jenkins_gid} --group-add oracle --group-add opc -v /var/run/docker.sock:/var/run/docker.sock"
}
}
steps {
// Using Maven batch mode to suppress download progress lines in Jenkins output
//
sh 'mvn -B -Dunit-test-wlst-dir=${WLST_DIR} test'
}
post {
Expand All @@ -62,33 +68,16 @@ pipeline {
docker {
alwaysPull true
reuseNode true
image 'phx.ocir.io/weblogick8s/wdt/jenkins-slave:122130'
args '-u jenkins -v /var/run/docker.sock:/var/run/docker.sock'
image "phx.ocir.io/${wdt_tenancy}/wdt/jenkins-slave:122130"
args "-u ${jenkins_uid}:${docker_gid} --group-add oracle --group-add opc --group-add docker -v /var/run/docker.sock:/var/run/docker.sock"
}
}
steps {
// Using Maven batch mode to suppress download progress lines in Jenkins output
//
sh 'mvn -B -DskipITs=false -Dmw_home=${ORACLE_HOME} -Ddb.use.container.network=true install'
}
}
stage ('Analyze') {
when {
anyOf {
changeRequest()
branch "main"
}
}
tools {
maven 'maven-3.8.7'
jdk 'jdk11'
}
steps {
withSonarQubeEnv('SonarCloud') {
withCredentials([string(credentialsId: 'encj_github_token', variable: 'GITHUB_TOKEN')]) {
runSonarScanner()
}
}
}
}
stage ('Alias Test') {
// only run this stage when triggered by a cron timer and the commit does not have []skip-ci in the message
// for example, only run integration tests during the timer triggered nightly build
Expand All @@ -111,28 +100,11 @@ pipeline {
}
steps {
sh '''
oci os object put --namespace=weblogick8s --bucket-name=wko-system-test-files --config-file=/dev/null --auth=instance_principal --force --file=installer/target/weblogic-deploy.zip --name=weblogic-deploy-main.zip
oci os object put --namespace=${wdt_tenancy} --bucket-name=wko-system-test-files \
--config-file=/dev/null --auth=instance_principal --force \
--file=installer/target/weblogic-deploy.zip --name=weblogic-deploy-main.zip
'''
}
}
}
}

void runSonarScanner() {
def changeUrl = env.GIT_URL.split("/")
def org = changeUrl[3]
def repo = changeUrl[4].substring(0, changeUrl[4].length() - 4)
if (env.CHANGE_ID != null) {
sh "mvn -B sonar:sonar \
-Dsonar.projectKey=${org}_${repo} \
-Dsonar.pullrequest.provider=GitHub \
-Dsonar.pullrequest.github.repository=${org}/${repo} \
-Dsonar.pullrequest.key=${env.CHANGE_ID} \
-Dsonar.pullrequest.branch=${env.CHANGE_BRANCH} \
-Dsonar.pullrequest.base=${env.CHANGE_TARGET}"
} else {
sh "mvn -B sonar:sonar \
-Dsonar.projectKey=${org}_${repo} \
-Dsonar.branch.name=${env.BRANCH_NAME}"
}
}
9 changes: 5 additions & 4 deletions core/src/test/python/base_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,14 @@ class BaseTestCase(unittest.TestCase):

def __init__(self, *args):
unittest.TestCase.__init__(self, *args)
self.TEST_CLASSES_DIR = os.path.abspath(os.getcwd() + '/../../test-classes')
self.TEST_OUTPUT_DIR = os.path.abspath(os.getcwd() + '/../../unit-tests')
self.TEST_CLASSES_DIR = os.path.abspath(os.path.join(os.getcwd(), '../../test-classes'))
self.TEST_OUTPUT_DIR = os.path.abspath(os.path.join(os.getcwd(), '../../unit-tests'))
self.TEST_CONFIG_DIR = os.path.join(self.TEST_OUTPUT_DIR, 'wdt-config')
self.log_levels = {}

self.original_config_dir = os.environ['WDT_CUSTOM_CONFIG']
self.original_config_dir = os.environ.get('WDT_CUSTOM_CONFIG', self.TEST_CONFIG_DIR)
# config items may need to be copied from here
self.INSTALLER_LIB_DIR = os.path.abspath(self.TEST_CLASSES_DIR + '/../../../installer/src/main/lib')
self.INSTALLER_LIB_DIR = os.path.abspath(os.path.join(self.TEST_CLASSES_DIR, '../../../installer/src/main/lib'))

def setUp(self):
# subclasses should call this
Expand Down
104 changes: 49 additions & 55 deletions core/src/test/python/validation_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,45 +2,42 @@
Copyright (c) 2017, 2023, Oracle Corporation and/or its affiliates.
Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl.
"""
import unittest
import os
from java.util.logging import Level
import shutil
import unittest

from java.util.logging import Level
from oracle.weblogic.deploy.logging import SummaryHandler
from oracle.weblogic.deploy.logging import WLSDeployLogEndHandler
from oracle.weblogic.deploy.util import TranslateException

from base_test import BaseTestCase
from validate import __perform_model_file_validation
from wlsdeploy.aliases import alias_constants
from wlsdeploy.aliases.aliases import Aliases
from wlsdeploy.logging.platform_logger import PlatformLogger
from wlsdeploy.util.weblogic_helper import WebLogicHelper
from wlsdeploy.util.model_translator import FileToPython
from wlsdeploy.util.model_context import ModelContext

from wlsdeploy.tool.validate.validator import Validator
from wlsdeploy.tool.validate import validation_utils
from wlsdeploy.aliases.wlst_modes import WlstModes
from wlsdeploy.aliases import alias_constants

from validate import __perform_model_file_validation

import oracle.weblogic.deploy.util.TranslateException as TranslateException
import oracle.weblogic.deploy.validate.ValidateException as ValidateException

from wlsdeploy.logging.platform_logger import PlatformLogger
from wlsdeploy.tool.create import wlsroles_helper
from wlsdeploy.tool.validate import validation_utils
from wlsdeploy.tool.validate.validator import Validator
from wlsdeploy.util.model_context import ModelContext
from wlsdeploy.util.model_translator import FileToPython
from wlsdeploy.util.weblogic_helper import WebLogicHelper


class ValidationTestCase(unittest.TestCase):
class ValidationTestCase(BaseTestCase):
_program_name = 'validation_test'
_class_name = 'ValidationTestCase'
_resources_dir = '..' + os.sep + '..' + os.sep + 'test-classes'
# Model persistence file
_wlsdeply_store_model = os.path.abspath(os.getcwd()) + os.sep + _resources_dir + os.sep + 'validate-mii-model.json'
# _variable_file = _resources_dir + "/test_sub_variable_file.properties"
# _model_file = _resources_dir + '/test_empty.json'
# _variable_file = _resources_dir + "/test_invalid_variable_file.properties"
# _archive_file = _resources_dir + "/test_jms_archive.zip"
_wls_version = '12.2.1.3'

def __init__(self, *args):
BaseTestCase.__init__(self, *args)
self.RESOURCES_DIR = os.path.join(self.TEST_CLASSES_DIR, 'validation')
self.OUTPUT_DIR = os.path.join(self.TEST_OUTPUT_DIR, 'validation')
self.STORE_MODEL = os.path.join(self.OUTPUT_DIR, 'validate-mii-model.json')

def setUp(self):
BaseTestCase.setUp(self)
self.name = 'ValidationTestCase'
self._logger = PlatformLogger('wlsdeploy.validate')
self.wls_helper = WebLogicHelper(self._logger)
Expand All @@ -49,30 +46,35 @@ def setUp(self):
self._summary_handler = SummaryHandler()
self._logger.logger.addHandler(self._summary_handler)

# Define custom configuration path for WDT
os.environ['WDT_CUSTOM_CONFIG'] = self._resources_dir
# Indicate that WDT should persist model file
os.environ['__WLSDEPLOY_STORE_MODEL__'] = self._wlsdeply_store_model
# Indicate that WDT should persist model file, including test filter
self._establish_directory(self.OUTPUT_DIR)
os.environ['__WLSDEPLOY_STORE_MODEL__'] = self.STORE_MODEL

# Define custom configuration path for WDT, with custom filter files
self.config_dir = self._set_custom_config_dir('validation-wdt-config')
source_filters_file = os.path.join(self.RESOURCES_DIR, 'model_filters.json')
shutil.copy(source_filters_file, self.config_dir)

def tearDown(self):
BaseTestCase.tearDown(self)
# remove summary handler for next test suite
self._logger.logger.removeHandler(self._summary_handler)
WLSDeployLogEndHandler.clearHandlers()

# Clean up temporary WDT custom configuration environment variables
# and model persistence files
del os.environ['WDT_CUSTOM_CONFIG']
# Clean up model persistence file
del os.environ['__WLSDEPLOY_STORE_MODEL__']
self.deleteFile(self._wlsdeply_store_model)

# clean up temporary WDT custom configuration environment variable
self._clear_custom_config_dir()

def testModelValidation(self):
_method_name = 'testModelValidation'

# The model file refers to two File Stores that are not in the archive so validation should fail.

_model_file = self._resources_dir + '/variablestest.yaml'
_variable_file = self._resources_dir + '/variablestest.properties'
_archive_file = self._resources_dir + '/variablestest.zip'
_model_file = self.RESOURCES_DIR + '/variablestest.yaml'
_variable_file = self.RESOURCES_DIR + '/variablestest.properties'
_archive_file = self.RESOURCES_DIR + '/variablestest.zip'

mw_home = os.environ['MW_HOME']
args_map = {
Expand Down Expand Up @@ -118,8 +120,8 @@ def testYamlModelValidation(self):
Parse and validate a YAML model with '-' list type and attributes with negative values.
"""

_model_file = self._resources_dir + '/simple-model.yaml'
_archive_file = self._resources_dir + "/SingleAppDomain.zip"
_model_file = self.TEST_CLASSES_DIR + '/simple-model.yaml'
_archive_file = self.TEST_CLASSES_DIR + "/SingleAppDomain.zip"
_method_name = 'testYamlModelValidation'

mw_home = os.environ['MW_HOME']
Expand Down Expand Up @@ -156,8 +158,8 @@ def testYamlModelValidationWithRemoteOption(self):
Parse and validate a YAML model with '-remote' option, should fail with path error.
"""

_model_file = self._resources_dir + '/simple-model2.yaml'
_archive_file = self._resources_dir + "/SingleAppDomain.zip"
_model_file = self.TEST_CLASSES_DIR + '/simple-model2.yaml'
_archive_file = self.TEST_CLASSES_DIR + "/SingleAppDomain.zip"
_method_name = 'testYamlModelValidation'

mw_home = os.environ['MW_HOME']
Expand Down Expand Up @@ -232,8 +234,8 @@ def testFilterInvokedOnModelValidation(self):
"""

# Setup model context arguments
_model_file = self._resources_dir + '/simple-model.yaml'
_archive_file = self._resources_dir + "/SingleAppDomain.zip"
_model_file = self.TEST_CLASSES_DIR + '/simple-model.yaml'
_archive_file = self.TEST_CLASSES_DIR + "/SingleAppDomain.zip"
_method_name = 'testFilterInvokedOnModelValidation'

mw_home = os.environ['MW_HOME']
Expand All @@ -246,24 +248,16 @@ def testFilterInvokedOnModelValidation(self):

model_context = ModelContext('validate', args_map)

try:
# Invoke model validation
__perform_model_file_validation(_model_file, model_context)
# Invoke model validation
__perform_model_file_validation(_model_file, model_context)

# read persisted model file and convert to python dictionary
model_dictionary = FileToPython(self._wlsdeply_store_model, True)._parse_json()
except ValidateException, ve:
self._logger.severe('WLSDPLY-20000', self._program_name, ve.getLocalizedMessage(), error=ve,
class_name=self._class_name, method_name=_method_name)
# read persisted model file and convert to python dictionary
model_dictionary = FileToPython(self.STORE_MODEL, True)._parse_json()

# assert the validate filter made modifications and was persisted
self.assertEquals('gumby1234', model_dictionary['domainInfo']['AdminPassword'], "Expected validate filter to have changed AdminPassword to 'gumby1234'")
self.assertEquals('gumby1234', model_dictionary['domainInfo']['AdminPassword'],
"Expected validate filter to have changed AdminPassword to 'gumby1234'")

def deleteFile(self, path):
try:
os.remove(path)
except OSError:
pass

if __name__ == '__main__':
unittest.main()
36 changes: 27 additions & 9 deletions core/src/test/python/variable_injector_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,34 +2,41 @@
Copyright (c) 2018, 2020, Oracle Corporation and/or its affiliates. All rights reserved.
Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl.
"""
import unittest

import os
import shutil
import unittest

import wlsdeploy.tool.util.variable_injector as variable_injector
import wlsdeploy.util.variables as variables
from base_test import BaseTestCase
from wlsdeploy.aliases.alias_constants import PASSWORD_TOKEN
from wlsdeploy.aliases.location_context import LocationContext
from wlsdeploy.aliases.model_constants import ADMIN_PASSWORD
from wlsdeploy.tool.util.variable_injector import STANDARD_PASSWORD_INJECTOR
from wlsdeploy.tool.util.variable_injector import VariableInjector
from wlsdeploy.util.model_context import ModelContext
from wlsdeploy.util.model_translator import FileToPython
from wlsdeploy.util.path_utils import CUSTOM_CONFIG_VARIABLE


class VariableFileHelperTest(unittest.TestCase):
_resources_dir = '../../test-classes'
_variable_file = _resources_dir + '/variable.injector.test.properties'
_model_file = _resources_dir + '/variable_insertion.yaml'
class VariableFileHelperTest(BaseTestCase):

def __init__(self, *args):
BaseTestCase.__init__(self, *args)
self.RESOURCES_DIR = os.path.join(self.TEST_CLASSES_DIR, 'injector')
self.CONFIG_RESOURCES_DIR = os.path.join(self.RESOURCES_DIR, 'config')
self._model_file = os.path.join(self.RESOURCES_DIR, 'variable_insertion.yaml')
self.OUTPUT_DIR = os.path.join(self.TEST_OUTPUT_DIR, 'injector')
self._variable_file = os.path.join(self.OUTPUT_DIR + 'variable.injector.test.properties')

def setUp(self):
BaseTestCase.setUp(self)
self.name = 'VariableFileHelperTest'
self._model = FileToPython(self._model_file).parse()
self._model_context = ModelContext(self.name, {})
self._helper = VariableInjector(self.name, self._model, self._model_context, '12.2.1.3')

def testSingleVariableReplacement(self):
BaseTestCase.tearDown(self)
replacement_dict = dict()
replacement_dict['Machine.NodeManager.ListenAddress'] = dict()
expected = dict()
Expand Down Expand Up @@ -256,12 +263,23 @@ def testWithVariableHelperKeywords(self):
expected[short_name + '.machine1.PasswordEncrypted'] = '--FIX ME--'
expected[short_name + '.machine1.UserName'] = 'admin'

self._establish_directory(self.OUTPUT_DIR)
self._model_context._variable_properties_file = self._variable_file
os.environ[CUSTOM_CONFIG_VARIABLE] = os.path.join(self._resources_dir, 'injector-config')

# Define custom configuration path for WDT, with custom injector files
config_dir = self._set_custom_config_dir('injector-wdt-config')
injector_config_file = os.path.join(self.CONFIG_RESOURCES_DIR, 'model_variable_injector.json')
shutil.copy(injector_config_file, config_dir)
keywords_file = os.path.join(self.CONFIG_RESOURCES_DIR, 'variable_keywords.json')
shutil.copy(keywords_file, config_dir)
injectors_target_dir = os.path.join(config_dir, 'injectors')
shutil.rmtree(injectors_target_dir)
injectors_dir = os.path.join(self.CONFIG_RESOURCES_DIR, 'injectors')
shutil.copytree(injectors_dir, injectors_target_dir)

inserted, model, variable_file_name = self._helper.inject_variables_keyword_file()

os.environ[CUSTOM_CONFIG_VARIABLE] = None
self._clear_custom_config_dir()

self.assertEqual(self._variable_file, variable_file_name)
self.assertEqual(True, inserted)
Expand Down
Loading