From 80bf585baa5506b84a0f31b67058b4bf1b931911 Mon Sep 17 00:00:00 2001 From: Artem Bannikov <62880541+artembannikov@users.noreply.github.com> Date: Thu, 14 Sep 2023 11:02:10 +0200 Subject: [PATCH] [tmsUpload] Use Golang implementation of the step by default (#4535) * Use new Golang implementation of tmsUpload step by default --- test/groovy/TmsUploadTest.groovy | 64 +++++++++++++++++++++++++++++--- vars/tmsUpload.groovy | 7 +++- 2 files changed, 63 insertions(+), 8 deletions(-) diff --git a/test/groovy/TmsUploadTest.groovy b/test/groovy/TmsUploadTest.groovy index 8f512502f9..ecc2f30dad 100644 --- a/test/groovy/TmsUploadTest.groovy +++ b/test/groovy/TmsUploadTest.groovy @@ -16,7 +16,9 @@ import util.JenkinsReadYamlRule import static org.hamcrest.Matchers.containsString import static org.hamcrest.Matchers.is import static org.hamcrest.Matchers.not +import static org.junit.Assert.assertEquals import static org.junit.Assert.assertThat +import static org.junit.Assert.assertTrue public class TmsUploadTest extends BasePiperTest { @@ -84,6 +86,42 @@ public class TmsUploadTest extends BasePiperTest { calledTmsMethodsWithArgs.clear() } + @Test + public void defaultUseGoStep__callsPiperExecuteBin() { + String calledStep = '' + String usedMetadataFile = '' + List credInfo = [] + helper.registerAllowedMethod('piperExecuteBin', [Map, String, String, List], { + Map parameters, String stepName, + String metadataFile, List credentialInfo -> + calledStep = stepName + usedMetadataFile = metadataFile + credInfo = credentialInfo + }) + + jenkinsUtilsStub = new JenkinsUtilsMock("Test User") + + stepRule.step.tmsUpload( + script: nullScript, + jenkinsUtilsStub: jenkinsUtilsStub, + mtaPath: 'dummy.mtar', + nodeName: 'myNode', + credentialsId: 'TMS_ServiceKey' + ) + + assertEquals('tmsUpload', calledStep) + assertEquals('metadata/tmsUpload.yaml', usedMetadataFile) + + // contains assertion does not work apparently when comparing a list of lists against an expected list + boolean found = false + credInfo.each { entry -> + if (entry == [type: 'token', id: 'credentialsId', env: ['PIPER_tmsServiceKey']]) { + found = true + } + } + assertTrue(found) + } + @Test public void minimalConfig__isSuccessful() { jenkinsUtilsStub = new JenkinsUtilsMock("Test User") @@ -97,7 +135,8 @@ public class TmsUploadTest extends BasePiperTest { transportManagementService: tmsStub, mtaPath: 'dummy.mtar', nodeName: 'myNode', - credentialsId: 'TMS_ServiceKey' + credentialsId: 'TMS_ServiceKey', + useGoStep: false ) assertThat(calledTmsMethodsWithArgs[0], is("authentication('${uaaUrl}', '${oauthClientId}', '${oauthClientSecret}')")) @@ -123,9 +162,12 @@ public class TmsUploadTest extends BasePiperTest { mtaPath: 'dummy.mtar', nodeName: 'myNode', credentialsId: 'TMS_ServiceKey', - verbose: true + verbose: true, + useGoStep: false ) + assertThat(loggingRule.log, containsString("[TransportManagementService] Using deprecated Groovy implementation of 'tmsUpload' step instead of the default Golang one, since 'useGoStep' toggle parameter is explicitly set to 'false'.")) + assertThat(loggingRule.log, containsString("[TransportManagementService] WARNING: Note that the deprecated Groovy implementation will be completely removed after February 29th, 2024. Consider using the Golang implementation by not setting the 'useGoStep' toggle parameter to 'false'.")) assertThat(loggingRule.log, containsString("[TransportManagementService] CredentialsId: 'TMS_ServiceKey'")) assertThat(loggingRule.log, containsString("[TransportManagementService] Node name: 'myNode'")) assertThat(loggingRule.log, containsString("[TransportManagementService] MTA path: 'dummy.mtar'")) @@ -148,7 +190,8 @@ public class TmsUploadTest extends BasePiperTest { transportManagementService: tmsStub, mtaPath: 'dummy.mtar', nodeName: 'myNode', - credentialsId: 'TMS_ServiceKey' + credentialsId: 'TMS_ServiceKey', + useGoStep: false ) assertThat(calledTmsMethodsWithArgs[1], is("uploadFile('${uri}', 'myToken', './dummy.mtar', 'Piper-Pipeline')")) @@ -168,7 +211,8 @@ public class TmsUploadTest extends BasePiperTest { mtaPath: 'dummy.mtar', nodeName: 'myNode', credentialsId: 'TMS_ServiceKey', - customDescription: 'My custom description for testing.' + customDescription: 'My custom description for testing.', + useGoStep: false ) assertThat(calledTmsMethodsWithArgs[2], is("uploadFileToNode('${uri}', 'myToken', 'myNode', '1234', 'My custom description for testing.')")) @@ -193,6 +237,7 @@ public class TmsUploadTest extends BasePiperTest { credentialsId: 'TMS_ServiceKey', nodeExtDescriptorMapping: nodeExtDescriptorMap, mtaVersion: '0.0.1', + useGoStep: false ) assertThat(loggingRule.log, containsString("[TransportManagementService] MTA Extension Descriptor with ID 'com.sap.piper.tms.test.extension' successfully uploaded to Node 'testNode1'.")) @@ -219,6 +264,7 @@ public class TmsUploadTest extends BasePiperTest { credentialsId: 'TMS_ServiceKey', nodeExtDescriptorMapping: nodeExtDescriptorMap, mtaVersion: '1.2.2', + useGoStep: false ) assertThat(loggingRule.log, containsString("[TransportManagementService] MTA Extension Descriptor with ID 'com.sap.piper.tms.test.another.extension' successfully updated for Node 'testNode1'.")) @@ -249,6 +295,7 @@ public class TmsUploadTest extends BasePiperTest { credentialsId: 'TMS_ServiceKey', nodeExtDescriptorMapping: nodeExtDescriptorMap, mtaVersion: '9.9.9', + useGoStep: false ) assertThat(calledTmsMethodsWithArgs[2], is("getMtaExtDescriptor('${uri}', 'myToken', 1, 'com.sap.piper.tms.test', '9.9.9')")) @@ -271,7 +318,8 @@ public class TmsUploadTest extends BasePiperTest { mtaPath: 'dummy.mtar', nodeName: 'myNode', credentialsId: 'TMS_ServiceKey', - customDescription: 'My custom description for testing.' + customDescription: 'My custom description for testing.', + useGoStep: false ) } @@ -288,7 +336,8 @@ public class TmsUploadTest extends BasePiperTest { jenkinsUtilsStub: jenkinsUtilsStub, transportManagementService: tmsStub, nodeName: 'myNode', - credentialsId: 'TMS_ServiceKey' + credentialsId: 'TMS_ServiceKey', + useGoStep: false ) assertThat(calledTmsMethodsWithArgs[1], is("uploadFile('${uri}', 'myToken', './dummy.mtar', 'Test User')")) @@ -316,6 +365,7 @@ public class TmsUploadTest extends BasePiperTest { credentialsId: 'TMS_ServiceKey', nodeExtDescriptorMapping: nodeExtDescriptorMap, mtaVersion: '0.0.1', + useGoStep: false ) } @@ -340,6 +390,7 @@ public class TmsUploadTest extends BasePiperTest { credentialsId: 'TMS_ServiceKey', nodeExtDescriptorMapping: nodeExtDescriptorMap, mtaVersion: '0.0.1', + useGoStep: false ) } @@ -365,6 +416,7 @@ public class TmsUploadTest extends BasePiperTest { credentialsId: 'TMS_ServiceKey', nodeExtDescriptorMapping: nodeExtDescriptorMap, mtaVersion: '0.0.1', + useGoStep: false ) } diff --git a/vars/tmsUpload.groovy b/vars/tmsUpload.groovy index 817569a173..d89203c922 100644 --- a/vars/tmsUpload.groovy +++ b/vars/tmsUpload.groovy @@ -52,7 +52,7 @@ import static com.sap.piper.Prerequisites.checkScript */ 'proxy', /** - * Toggle to activate a new Golang implementation of the step. Off by default. + * The new Golang implementation of the step is used now by default. Utilizing this toggle with value true is therefore redundant and can be omitted. If used with value false, the toggle deactivates the new Golang implementation and instructs the step to use the old Groovy one. Note that possibility to switch to the old Groovy implementation will be completely removed and this toggle will be deprecated after February 29th, 2024. * @possibleValues true, false */ 'useGoStep' @@ -94,7 +94,7 @@ void call(Map parameters = [:]) { def namedUser = jenkinsUtils.getJobStartedByUserId() - if (config.useGoStep == true) { + if (config.useGoStep != false) { List credentials = [ [type: 'token', id: 'credentialsId', env: ['PIPER_tmsServiceKey']] ] @@ -108,6 +108,9 @@ void call(Map parameters = [:]) { return } + echo "[TransportManagementService] Using deprecated Groovy implementation of '${STEP_NAME}' step instead of the default Golang one, since 'useGoStep' toggle parameter is explicitly set to 'false'." + echo "[TransportManagementService] WARNING: Note that the deprecated Groovy implementation will be completely removed after February 29th, 2024. Consider using the Golang implementation by not setting the 'useGoStep' toggle parameter to 'false'." + // telemetry reporting new Utils().pushToSWA([ step : STEP_NAME,