From 749327fc3040c44236441f9703166d7e85fc6d4f Mon Sep 17 00:00:00 2001 From: Phil Henderson Date: Fri, 21 Mar 2025 16:56:47 -0400 Subject: [PATCH 1/2] SRE-2931 build: Fix daosLatestGroovy() (#28) Fix and harden daosLatestGroovy(). Also add a unit test. Signed-off-by: Phil Henderson --- Jenkinsfile | 5 +++++ vars/daosLatestVersion.groovy | 12 +++++++---- vars/trustedPipelineUnitTests.groovy | 32 ++++++++++++++++++++++++++++ 3 files changed, 45 insertions(+), 4 deletions(-) create mode 100644 vars/trustedPipelineUnitTests.groovy diff --git a/Jenkinsfile b/Jenkinsfile index 5ea2172..6ca8664 100755 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -79,6 +79,11 @@ Sleep-seconds: 2''' } } // steps } //stage('env.COMMIT_MESSAGE pragma test') + stage('Unit tests') { + steps{ + trustedPipelineUnitTests() + } + } // stage('Unit tests') stage('DAOS Build and Test') { when { beforeAgent true diff --git a/vars/daosLatestVersion.groovy b/vars/daosLatestVersion.groovy index ae5f9ac..b2f92cd 100644 --- a/vars/daosLatestVersion.groovy +++ b/vars/daosLatestVersion.groovy @@ -31,12 +31,16 @@ String distro2repo(String distro) { String getLatestVersion(String distro, BigDecimal next_version, String type='stable') { String v = null String repo = 'daos-stack-daos-' + distro2repo(distro) + '-x86_64-' + type + '-local/' + String artifactory_url = env.ARTIFACTORY_URL + /* For backwards support, add the 'artifactory' path if it is missing from the env */ + if (!artifactory_url.endsWith('/artifactory')) { + artifactory_url = "${artifactory_url}/artifactory" + } try { v = sh(label: 'Get RPM packages version for: ' + repo + ' with version < ' + next_version.toString(), - script: '$(command -v dnf) --refresh repoquery --repofrompath=daos,' + env.ARTIFACTORY_URL + - '/artifactory/' + repo + - ''' --repoid daos --qf %{version}-%{release} --whatprovides 'daos < ''' + - next_version + '''' | rpmdev-sort | tail -1''', + script: '$(command -v dnf) --refresh repoquery --repofrompath=daos,' + artifactory_url + '/' + + repo + ''' --repoid daos --qf %{version}-%{release} --whatprovides 'daos < ''' + + next_version + '''' | rpmdev-sort | tail -1''', returnStdout: true).trim() /* groovylint-disable-next-line CatchException */ } catch (Exception e) { diff --git a/vars/trustedPipelineUnitTests.groovy b/vars/trustedPipelineUnitTests.groovy new file mode 100644 index 0000000..3dd7b79 --- /dev/null +++ b/vars/trustedPipelineUnitTests.groovy @@ -0,0 +1,32 @@ +/* groovylint-disable DuplicateNumberLiteral, ParameterName, VariableName */ +// vars/trustedPipelineUnitTests.groovy + + /** + * trustedPipelineUnitTests.groovy + * + * Runs trusted-pipeline-lib unit tests + */ + +void call() { + // Run unit tests + _run_unit_tests() +} + +void _run_unit_tests() { + // Run all the unit tests + println('Test daosLatestVersion()') + _test_daosLatestVersion("master", "el8", /2.7\.\d++.*/) + _test_daosLatestVersion('release/2.4', 'el8', /2.[34]\.\d++.*/) + _test_daosLatestVersion('release/2.6', 'el8', /2.[56]\.\d++.*/) +} + +void _test_daosLatestVersion(String distro, String next_version, String expected) { + // Verify the version returned by daosLatestVersion() matches expected + println(" Running daosLatestVersion(distro=${distro}, next_version=${next_version})") + result =daosLatestVersion(distro, next_version) + println(" result: ${result}") + println(" expected: ${expected}") + assert(result.matches(expected)) + println(" PASSED") + println("") +} From 6a866662a091b1821b569ac2c9b0d252235f0c11 Mon Sep 17 00:00:00 2001 From: Tomasz Gromadzki Date: Tue, 27 May 2025 17:22:51 +0200 Subject: [PATCH 2/2] SRE-3030 ci: dnf repoquery with explicit \n (#30) The new version of dnf (v.5) generates a different result of the 'repoquery' command - all results are in one line. An explicit '\n' character is required to get the results on separate lines. Signed-off-by: Tomasz Gromadzki --- vars/daosLatestVersion.groovy | 2 +- vars/trustedPipelineUnitTests.groovy | 1 - 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/vars/daosLatestVersion.groovy b/vars/daosLatestVersion.groovy index b2f92cd..a7429c7 100644 --- a/vars/daosLatestVersion.groovy +++ b/vars/daosLatestVersion.groovy @@ -39,7 +39,7 @@ String getLatestVersion(String distro, BigDecimal next_version, String type='sta try { v = sh(label: 'Get RPM packages version for: ' + repo + ' with version < ' + next_version.toString(), script: '$(command -v dnf) --refresh repoquery --repofrompath=daos,' + artifactory_url + '/' + - repo + ''' --repoid daos --qf %{version}-%{release} --whatprovides 'daos < ''' + + repo + ''' --repoid daos --qf "%{version}-%{release}\n" --whatprovides 'daos < ''' + next_version + '''' | rpmdev-sort | tail -1''', returnStdout: true).trim() /* groovylint-disable-next-line CatchException */ diff --git a/vars/trustedPipelineUnitTests.groovy b/vars/trustedPipelineUnitTests.groovy index 3dd7b79..946b4cd 100644 --- a/vars/trustedPipelineUnitTests.groovy +++ b/vars/trustedPipelineUnitTests.groovy @@ -16,7 +16,6 @@ void _run_unit_tests() { // Run all the unit tests println('Test daosLatestVersion()') _test_daosLatestVersion("master", "el8", /2.7\.\d++.*/) - _test_daosLatestVersion('release/2.4', 'el8', /2.[34]\.\d++.*/) _test_daosLatestVersion('release/2.6', 'el8', /2.[56]\.\d++.*/) }