From 38360f1d0cb717e5ee9be5a0852d9376a9523bae Mon Sep 17 00:00:00 2001 From: Roland Stengel Date: Mon, 16 Jul 2018 15:46:18 +0200 Subject: [PATCH 1/3] drop NEO version verification - introduce getVersion --- src/com/sap/piper/VersionUtils.groovy | 27 +++--- .../com/sap/piper/VersionUtilsTest.groovy | 83 +++++++++++++++++++ 2 files changed, 100 insertions(+), 10 deletions(-) create mode 100644 test/groovy/com/sap/piper/VersionUtilsTest.groovy diff --git a/src/com/sap/piper/VersionUtils.groovy b/src/com/sap/piper/VersionUtils.groovy index 270125837..95c67afa8 100644 --- a/src/com/sap/piper/VersionUtils.groovy +++ b/src/com/sap/piper/VersionUtils.groovy @@ -5,9 +5,12 @@ import hudson.AbortException class VersionUtils implements Serializable { - def static verifyVersion(script, name, executable, String version, versionOption) { + def static getVersion(script, name, executable, versionOption) { - script.echo "Verifying $name version $version or compatible version." + return new Version(getVersionDesc(script, name, executable, versionOption)) + } + + def static getVersionDesc(script, name, executable, versionOption) { def toolVersion try { @@ -16,7 +19,16 @@ class VersionUtils implements Serializable { } catch(AbortException e) { throw new AbortException("The verification of $name failed. Please check '$executable'. $e.message.") } - def installedVersion = new Version(toolVersion) + + return toolVersion + } + + def static verifyVersion(script, name, executable, String version, versionOption) { + + script.echo "Verifying $name version $version or compatible version." + + Version installedVersion = getVersion(script, name, executable, versionOption) + if (!installedVersion.isCompatibleVersion(new Version(version))) { throw new AbortException("The installed version of $name is ${installedVersion.toString()}. Please install version $version or a compatible version.") } @@ -25,13 +37,8 @@ class VersionUtils implements Serializable { def static verifyVersion(script, name, executable, Map versions, versionOption) { - def toolVersion - try { - toolVersion = script.sh returnStdout: true, script: """#!/bin/bash - $executable $versionOption""" - } catch(AbortException e) { - throw new AbortException("The verification of $name failed. Please check '$executable'. $e.message.") - } + def toolVersion = getVersionDesc(script, name, executable, versionOption) + for (def entry : versions) { if (toolVersion.contains(entry.getKey())) { def installedVersion = new Version(toolVersion) diff --git a/test/groovy/com/sap/piper/VersionUtilsTest.groovy b/test/groovy/com/sap/piper/VersionUtilsTest.groovy new file mode 100644 index 000000000..118b7d8d2 --- /dev/null +++ b/test/groovy/com/sap/piper/VersionUtilsTest.groovy @@ -0,0 +1,83 @@ +package com.sap.piper + +import hudson.AbortException +import org.junit.Before +import org.junit.Rule +import org.junit.Test +import org.junit.rules.ExpectedException +import org.junit.rules.RuleChain +import util.BasePiperTest +import util.JenkinsShellCallRule +import util.Rules + +import static org.junit.Assert.assertEquals +import static org.hamcrest.Matchers.equalTo +import static org.junit.Assert.assertTrue +import static org.junit.Assert.assertFalse +import static org.hamcrest.Matchers.is +import static org.hamcrest.Matchers.notNullValue +import static org.junit.Assert.assertNotNull +import static org.junit.Assert.assertNull +import static org.junit.Assert.assertThat + +class VersionUtilsTest extends BasePiperTest { + + ExpectedException thrown = ExpectedException.none() + + @Rule + public RuleChain ruleChain = Rules.getCommonRules(this).around(thrown) + + @Before + void init() throws Exception { + } + + @Test + void test_if_getVersionDesc_returns_desc() { + helper.registerAllowedMethod('sh', [Map], { Map m -> return 'SAP Cloud Platform Console Client\n\n\nSDK version : 2.129.5.1\nRuntime : neo-javaee6-wp\n'}) + + assertEquals('SAP Cloud Platform Console Client\n\n\nSDK version : 2.129.5.1\nRuntime : neo-javaee6-wp\n',VersionUtils.getVersionDesc(nullScript, "test", "test.sh", "version")) + } + + @Test + void test_if_getVersion_returns_version() { + helper.registerAllowedMethod('sh', [Map], { Map m -> return 'SAP Cloud Platform Console Client\n\n\nSDK version : 2.129.5.1\nRuntime : neo-javaee6-wp\n'}) + + assertEquals(new Version('2.129.5.1'),VersionUtils.getVersion(nullScript, "test", "test.sh", "version")) + } + + @Test + void test_if_verifyVersion_succeeds_compatible() { + helper.registerAllowedMethod('sh', [Map], { Map m -> return 'version : 1.0.0\runtime: key' }) + VersionUtils.verifyVersion(nullScript, "test", "test.sh", '1.0.0', "version") + } + + @Test + void test_if_verifyVersion_fails_incompatible() { + helper.registerAllowedMethod('sh', [Map], { Map m -> return 'version : 1.0.0\runtime: key' }) + + thrown.expect(AbortException) + thrown.expectMessage("The installed version of test is 1.0.0. Please install version 1.0.1 or a compatible version.") + + VersionUtils.verifyVersion(nullScript, "test", "test.sh", '1.0.1', "version") + } + + @Test + void test_if_verifyVersion_map_succeeds_compatible() { + Map versionMap = ['key1': '1.0.0', 'key2': '2.0.0', 'key3': '3.0.0'] + helper.registerAllowedMethod('sh', [Map], { Map m -> return 'version : 1.0.0\runtime: key1' }) + VersionUtils.verifyVersion(nullScript, "test", "test.sh", versionMap, "version") + } + + @Test + void test_if_verifyVersion_map_fails_incompatible() { + Map versionMap = ['key1': '1.0.1', 'key2': '2.0.1', 'key3': '3.0.1'] + helper.registerAllowedMethod('sh', [Map], { Map m -> return 'version : 1.0.0\runtime: key1' }) + + thrown.expect(AbortException) + thrown.expectMessage("The installed version of test is 1.0.0. Please install version 1.0.1 or a compatible version.") + + VersionUtils.verifyVersion(nullScript, "test", "test.sh", versionMap, "version") + } + + +} From b7a2a84e2d0748c12dea236fc110e01ac0ee01da Mon Sep 17 00:00:00 2001 From: Roland Stengel Date: Tue, 17 Jul 2018 11:18:18 +0200 Subject: [PATCH 2/3] drop NEO version verification - decouple verifyversion from getversion --- src/com/sap/piper/VersionUtils.groovy | 24 ++++++++++++++++--- src/com/sap/piper/tools/ToolDescriptor.groovy | 5 ++-- 2 files changed, 24 insertions(+), 5 deletions(-) diff --git a/src/com/sap/piper/VersionUtils.groovy b/src/com/sap/piper/VersionUtils.groovy index 95c67afa8..9e1087e26 100644 --- a/src/com/sap/piper/VersionUtils.groovy +++ b/src/com/sap/piper/VersionUtils.groovy @@ -35,13 +35,31 @@ class VersionUtils implements Serializable { script.echo "Verification success. $name version ${installedVersion.toString()} is installed." } + def static verifyVersion(script, name, String versionDesc, String versionExpected) { + + script.echo "Verifying $name version $versionExpected or compatible version." + + Version versionAvailable = new Version(versionDesc) + + if (!versionAvailable.isCompatibleVersion(new Version(versionExpected))) { + throw new AbortException("The installed version of $name is ${versionAvailable.toString()}. Please install version $versionExpected or a compatible version.") + } + script.echo "Verification success. $name version ${versionAvailable.toString()} is installed." + } + + def static verifyVersion(script, name, executable, Map versions, versionOption) { - def toolVersion = getVersionDesc(script, name, executable, versionOption) + def versionDesc = getVersionDesc(script, name, executable, versionOption) + verifyVersion(script, name, versionDesc, versions) + } + + def static verifyVersion(script, name, String versionDesc, Map versions) { + for (def entry : versions) { - if (toolVersion.contains(entry.getKey())) { - def installedVersion = new Version(toolVersion) + if (versionDesc.contains(entry.getKey())) { + def installedVersion = new Version(versionDesc) def expectedVersion = entry.getValue() script.echo "Verifying $name version $expectedVersion or compatible version." if (!installedVersion.isCompatibleVersion(new Version(expectedVersion))) { diff --git a/src/com/sap/piper/tools/ToolDescriptor.groovy b/src/com/sap/piper/tools/ToolDescriptor.groovy index 0f4681889..7886d5c9b 100644 --- a/src/com/sap/piper/tools/ToolDescriptor.groovy +++ b/src/com/sap/piper/tools/ToolDescriptor.groovy @@ -108,8 +108,9 @@ class ToolDescriptor implements Serializable { def verifyVersion(script, configuration) { def executable = getToolExecutable(script, configuration, false) - if (singleVersion) VersionUtils.verifyVersion(script, name, executable, singleVersion, versionOption) - if (multipleVersions) VersionUtils.verifyVersion(script, name, executable, multipleVersions, versionOption) + def versionDesc = VersionUtils.getVersionDesc(script, name, executable, versionOption) + if (singleVersion) VersionUtils.verifyVersion(script, name, versionDesc, singleVersion) + if (multipleVersions) VersionUtils.verifyVersion(script, name, versionDesc, multipleVersions) } def getMessage() { From 4851ba94bfabfd2e503aabb7036be466836c81ae Mon Sep 17 00:00:00 2001 From: Roland Stengel Date: Tue, 17 Jul 2018 11:47:39 +0200 Subject: [PATCH 3/3] drop NEO version verification - remove neo version check --- test/groovy/ToolValidateTest.groovy | 14 -------------- .../com/sap/piper/tools/ToolDescriptorTest.groovy | 11 +++++++++++ vars/neoDeploy.groovy | 3 +-- vars/toolValidate.groovy | 3 +-- 4 files changed, 13 insertions(+), 18 deletions(-) diff --git a/test/groovy/ToolValidateTest.groovy b/test/groovy/ToolValidateTest.groovy index c3d52b6a6..c6538b752 100644 --- a/test/groovy/ToolValidateTest.groovy +++ b/test/groovy/ToolValidateTest.groovy @@ -144,17 +144,6 @@ class ToolValidateTest extends BasePiperTest { jsr.step.call(tool: 'mta', home: home) } - @Test - void validateNeoIncompatibleVersionTest() { - - thrown.expect(AbortException) - thrown.expectMessage('The installed version of SAP Cloud Platform Console Client is 1.126.51.') - - helper.registerAllowedMethod('sh', [Map], { Map m -> getIncompatibleVersion(m) }) - - jsr.step.call(tool: 'neo', home: home) - } - @Test void validateCmIncompatibleVersionTest() { @@ -195,9 +184,6 @@ class ToolValidateTest extends BasePiperTest { helper.registerAllowedMethod('sh', [Map], { Map m -> getVersion(m) }) jsr.step.call(tool: 'neo', home: home) - - assert jlr.log.contains('Verifying SAP Cloud Platform Console Client version 3.39.10 or compatible version.') - assert jlr.log.contains('SAP Cloud Platform Console Client version 3.39.10 is installed.') } @Test diff --git a/test/groovy/com/sap/piper/tools/ToolDescriptorTest.groovy b/test/groovy/com/sap/piper/tools/ToolDescriptorTest.groovy index 69506d281..11da4eff4 100644 --- a/test/groovy/com/sap/piper/tools/ToolDescriptorTest.groovy +++ b/test/groovy/com/sap/piper/tools/ToolDescriptorTest.groovy @@ -193,6 +193,17 @@ class ToolDescriptorTest extends BasePiperTest { tool.verifyVersion(script, configuration) } + @Test + void verifyToolVersion_without_version_check() { + + def tool = new ToolDescriptor('SAP Cloud Platform Console Client', 'NEO_HOME', 'neoHome', '/tools/', 'neo.sh', null, 'version') + + helper.registerAllowedMethod('sh', [Map], { Map m -> getVersion(m) }) + + tool.verifyVersion(script, configuration) + } + + private getEnvVars(Map m) { diff --git a/vars/neoDeploy.groovy b/vars/neoDeploy.groovy index f4150ad9b..8cfec18df 100644 --- a/vars/neoDeploy.groovy +++ b/vars/neoDeploy.groovy @@ -148,8 +148,7 @@ def call(parameters = [:]) { deployAccount = utils.getMandatoryParameter(configuration, 'account') } - def neoVersions = ['neo-java-web': '3.39.10', 'neo-javaee6-wp': '2.132.6', 'neo-javaee7-wp': '1.21.13'] - def neo = new ToolDescriptor('SAP Cloud Platform Console Client', 'NEO_HOME', 'neoHome', '/tools/', 'neo.sh', neoVersions, 'version') + def neo = new ToolDescriptor('SAP Cloud Platform Console Client', 'NEO_HOME', 'neoHome', '/tools/', 'neo.sh', null, 'version') def neoExecutable = neo.getToolExecutable(this, configuration) def neoDeployScript = """#!/bin/bash "${neoExecutable}" ${warAction} \ diff --git a/vars/toolValidate.groovy b/vars/toolValidate.groovy index f1551a28b..eb840e060 100644 --- a/vars/toolValidate.groovy +++ b/vars/toolValidate.groovy @@ -31,8 +31,7 @@ def call(Map parameters = [:]) { mta.verifyVersion(this, [mtaJarLocation: home]) return case 'neo': - def neoVersions = ['neo-java-web': '3.39.10', 'neo-javaee6-wp': '2.132.6', 'neo-javaee7-wp': '1.21.13'] - def neo = new ToolDescriptor('SAP Cloud Platform Console Client', 'NEO_HOME', 'neoHome', '/tools/', 'neo.sh', neoVersions, 'version') + def neo = new ToolDescriptor('SAP Cloud Platform Console Client', 'NEO_HOME', 'neoHome', '/tools/', 'neo.sh', null, 'version') neo.verifyVersion(this, [neoHome: home]) return case 'cm':