Skip to content

Commit ee1e345

Browse files
committed
(maint) Handle correct naming of narch build artifacts
Packages like openvox-server, openvoxdb and openvoxdb-termini are noarch and need a different naming schem when constructing urls to fetch them from the artifacts server. * adds a noarch_package() test to common.sh * adds a set_package_architecture() function to common.sh * extracts set_architecture() from install_build_artifact_linux.sh into common.sh and renames as set_cpu_architecture() * extracts set_package_url() from install_build_artifact_linux.sh into common.sh and renames as set_artifacts_package_url() * modifies set_artifacts_package_url() to set_package_architecture() so we get correct urls for noarch and arch packages * adds tests to the bash specs for all the above
1 parent 7ac8ae5 commit ee1e345

File tree

3 files changed

+273
-103
lines changed

3 files changed

+273
-103
lines changed

files/common.sh

Lines changed: 123 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -377,3 +377,126 @@ refresh_package_cache() {
377377
exit 1
378378
fi
379379
}
380+
381+
# Test whether the given package name matches a list of
382+
# openvox packages that are noarch.
383+
noarch_package() {
384+
local _package="$1"
385+
386+
# List of noarch packages.
387+
local noarch_packages=(
388+
'openvox-server'
389+
'openvoxdb'
390+
'openvoxdb-termini'
391+
)
392+
393+
for pkg in "${noarch_packages[@]}"; do
394+
if [[ "${_package}" == "${pkg}" ]]; then
395+
return 0
396+
fi
397+
done
398+
399+
return 1
400+
}
401+
402+
# Lookup the cpu architecture and set it as cpu_arch.
403+
# Translates x86_64 to amd64 and aarch64 to arm64 for debian/ubuntu.
404+
set_cpu_architecture() {
405+
local _family="$1"
406+
407+
local _arch
408+
_arch=$(uname -m)
409+
case "${_family}" in
410+
debian|ubuntu)
411+
case "${_arch}" in
412+
x86_64)
413+
cpu_arch="amd64"
414+
;;
415+
aarch64)
416+
cpu_arch="arm64"
417+
;;
418+
*)
419+
cpu_arch="${_arch}"
420+
;;
421+
esac
422+
;;
423+
*)
424+
cpu_arch="${_arch}"
425+
;;
426+
esac
427+
export cpu_arch # quiets shellcheck SC2034
428+
assigned 'cpu_arch'
429+
}
430+
431+
# Lookup the architecture for the given package and set it as
432+
# package_arch.
433+
#
434+
# This will either be noarch/all depending on the platform and
435+
# whether the package name matches an openvox noarch_package(),
436+
# or it will be the cpu_arch.
437+
set_package_architecture() {
438+
local _package="$1"
439+
local _os_family="${2:-${os_family}}"
440+
441+
if noarch_package "${_package}"; then
442+
case "${_os_family}" in
443+
debian|ubuntu)
444+
package_arch='all'
445+
;;
446+
*)
447+
package_arch='noarch'
448+
;;
449+
esac
450+
else
451+
set_cpu_architecture "${_os_family}"
452+
package_arch="${cpu_arch}"
453+
fi
454+
export package_arch # quiets shellcheck SC2034
455+
assigned 'package_arch'
456+
}
457+
458+
# Based on platform, package and version set:
459+
# package_name - the name of the build artifact package
460+
# package_url - the url to download the build artifact package
461+
#
462+
# Currently this is based on the structure of the package repository
463+
# at https://artifacts.voxpupuli.org, which is a page
464+
# that provides a summary of links to artifacts contained in an S3
465+
# bucket hosted by Oregon State University Open Source Lab.
466+
#
467+
# Example rpm:
468+
# https://artifacts.voxpupuli.org/openvox-agent/8.15.0/openvox-agent-8.15.0-1.el8.x86_64.rpm
469+
# Example deb:
470+
# https://artifacts.voxpupuli.org/openvox-agent/8.15.0/openvox-agent_8.15.0-1%2Bdebian12_amd64.deb
471+
set_artifacts_package_url() {
472+
local _artifacts_source="$1"
473+
local _package="$2"
474+
local _version="$3"
475+
476+
set_package_type "${os_family}"
477+
set_package_architecture "${_package}" "${os_family}"
478+
479+
case "${package_type}" in
480+
rpm)
481+
# Account for a fedora naming quirk in the build artifacts.
482+
if [[ "${os_family}" == "fedora" ]]; then
483+
_os_family="fc"
484+
else
485+
_os_family="${os_family}"
486+
fi
487+
package_name="${_package}-${_version}-1.${_os_family}${os_major_version}.${package_arch}.${package_type}"
488+
;;
489+
deb)
490+
package_name="${_package}_${_version}-1%2B${os_family}${os_full_version}_${package_arch}.${package_type}"
491+
;;
492+
*)
493+
fail "Unhandled package type: '${package_type}'"
494+
;;
495+
esac
496+
package_url="${_artifacts_source}/${_package}/${_version}/${package_name}"
497+
498+
export package_name # quiets shellcheck SC2034
499+
assigned 'package_name'
500+
export package_url # quiets shellcheck SC2034
501+
assigned 'package_url'
502+
}

spec/unit/bash/common_sh_spec.rb

Lines changed: 149 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -261,38 +261,26 @@
261261
end
262262

263263
it 'sets platform globals' do
264-
output, status = test(<<~EOT)
265-
set_platform_globals
266-
echo "set platform=$platform"
267-
echo "set os_full_version=$os_full_version"
268-
echo "set os_major_version=$os_major_version"
269-
echo "set os_family=$os_family"
270-
EOT
264+
output, status = test('set_platform_globals')
271265

272266
expect(status.success?).to be(true)
273-
expect(output).to include('set platform=Ubuntu')
274-
expect(output).to include('set os_full_version=24.04')
275-
expect(output).to include('set os_major_version=24')
276-
expect(output).to include('set os_family=ubuntu')
267+
expect(output).to include('Assigned platform=Ubuntu')
268+
expect(output).to include('Assigned os_full_version=24.04')
269+
expect(output).to include('Assigned os_major_version=24')
270+
expect(output).to include('Assigned os_family=ubuntu')
277271
end
278272

279273
context 'with a pre-release' do
280274
let(:os) { :debian13 }
281275

282276
it 'uses codename when release is n/a' do
283-
output, status = test(<<~EOT)
284-
set_platform_globals
285-
echo "set platform=$platform"
286-
echo "set os_full_version=$os_full_version"
287-
echo "set os_major_version=$os_major_version"
288-
echo "set os_family=$os_family"
289-
EOT
277+
output, status = test('set_platform_globals')
290278

291279
expect(status.success?).to be(true)
292-
expect(output).to include('set platform=Debian')
293-
expect(output).to include('set os_full_version=13')
294-
expect(output).to include('set os_major_version=13')
295-
expect(output).to include('set os_family=debian')
280+
expect(output).to include('Assigned platform=Debian')
281+
expect(output).to include('Assigned os_full_version=13')
282+
expect(output).to include('Assigned os_major_version=13')
283+
expect(output).to include('Assigned os_family=debian')
296284
end
297285
end
298286
end
@@ -308,13 +296,7 @@
308296
it 'fails for an unknown platform' do
309297
mock_facts_task_bash_sh(:unknown)
310298

311-
output, status = test(<<~EOT)
312-
set_platform_globals
313-
echo "set platform=$platform"
314-
echo "set os_full_version=$os_full_version"
315-
echo "set os_major_version=$os_major_version"
316-
echo "set os_family=$os_family"
317-
EOT
299+
output, status = test('set_platform_globals')
318300

319301
expect(status.success?).to be(false)
320302
expect(output).to include("Unhandled platform: 'Unknown'")
@@ -439,4 +421,142 @@
439421
end
440422
end
441423
end
424+
425+
context 'noarch_package' do
426+
it 'returns 0 for a noarch package' do
427+
output, status = test('noarch_package openvox-server')
428+
429+
expect(status.success?).to be(true)
430+
expect(output.strip).to be_empty
431+
end
432+
433+
it 'returns 1 for a non-noarch package' do
434+
output, status = test('noarch_package foo')
435+
436+
expect(status.success?).to be(false)
437+
expect(output.strip).to be_empty
438+
end
439+
end
440+
441+
context 'set_cpu_architecture' do
442+
context 'debian or ubuntu' do
443+
it 'sets x86_64 for amd64' do
444+
allow_script.to receive_command(:uname).and_exec('echo x86_64')
445+
output, status = test('set_cpu_architecture debian')
446+
447+
expect(status.success?).to be(true)
448+
expect(output).to include('Assigned cpu_arch=amd64')
449+
end
450+
451+
it 'sets arm64 for aarch64' do
452+
allow_script.to receive_command(:uname).and_exec('echo aarch64')
453+
output, status = test('set_cpu_architecture ubuntu')
454+
455+
expect(status.success?).to be(true)
456+
expect(output).to include('Assigned cpu_arch=arm64')
457+
end
458+
459+
it 'sets amd64 for amd64' do
460+
allow_script.to receive_command(:uname).and_exec('echo amd64')
461+
output, status = test('set_cpu_architecture debian')
462+
463+
expect(status.success?).to be(true)
464+
expect(output).to include('Assigned cpu_arch=amd64')
465+
end
466+
end
467+
468+
context 'other' do
469+
it 'sets what uname gives it' do
470+
allow_script.to receive_command(:uname).and_exec('echo x86_64')
471+
output, status = test('set_cpu_architecture el')
472+
473+
expect(status.success?).to be(true)
474+
expect(output).to include('Assigned cpu_arch=x86_64')
475+
end
476+
end
477+
end
478+
479+
context 'set_package_architecture' do
480+
it 'sets all for debian noarch' do
481+
output, status = test('set_package_architecture openvox-server debian')
482+
483+
expect(status.success?).to be(true)
484+
expect(output).to include('Assigned package_arch=all')
485+
end
486+
487+
it 'sets noarch for el noarch' do
488+
output, status = test('set_package_architecture openvoxdb el')
489+
490+
expect(status.success?).to be(true)
491+
expect(output).to include('Assigned package_arch=noarch')
492+
end
493+
494+
it 'sets system arch otherwise' do
495+
allow_script.to receive_command(:uname).and_exec('echo x86_64')
496+
output, status = test('set_package_architecture openvox-agent el')
497+
498+
expect(status.success?).to be(true)
499+
expect(output).to include('Assigned cpu_arch=x86_64')
500+
expect(output).to include('Assigned package_arch=x86_64')
501+
end
502+
end
503+
504+
context 'set_artifacts_package_url' do
505+
context 'deb' do
506+
it 'builds a debian url' do
507+
allow_script.to set_env('os_family', 'debian')
508+
allow_script.to receive_command(:uname).and_exec('echo x86_64')
509+
output, status = test('set_artifacts_package_url https://foo openvox-agent 8.18.0')
510+
511+
expect(status.success?).to be(true)
512+
package_name = 'openvox-agent_8.18.0-1%2Bdebian_amd64.deb'
513+
expect(output).to include("Assigned package_name=#{package_name}")
514+
expect(output).to include("Assigned package_url=https://foo/openvox-agent/8.18.0/#{package_name}")
515+
end
516+
517+
it 'builds a noarch package url for ubuntu' do
518+
allow_script.to set_env('os_family', 'ubuntu')
519+
output, status = test('set_artifacts_package_url https://foo openvox-server 8.9.0')
520+
521+
expect(status.success?).to be(true)
522+
package_name = 'openvox-server_8.9.0-1%2Bubuntu_all.deb'
523+
expect(output).to include("Assigned package_name=#{package_name}")
524+
expect(output).to include("Assigned package_url=https://foo/openvox-server/8.9.0/#{package_name}")
525+
end
526+
end
527+
528+
context 'rpm' do
529+
it 'builds a redhat url' do
530+
allow_script.to set_env('os_family', 'el')
531+
allow_script.to receive_command(:uname).and_exec('echo x86_64')
532+
output, status = test('set_artifacts_package_url https://foo openvox-agent 8.18.0')
533+
534+
expect(status.success?).to be(true)
535+
package_name = 'openvox-agent-8.18.0-1.el.x86_64.rpm'
536+
expect(output).to include("Assigned package_name=#{package_name}")
537+
expect(output).to include("Assigned package_url=https://foo/openvox-agent/8.18.0/#{package_name}")
538+
end
539+
540+
it 'builds a noarch package url for redhat' do
541+
allow_script.to set_env('os_family', 'el')
542+
output, status = test('set_artifacts_package_url https://foo openvoxdb-termini 8.9.1')
543+
544+
expect(status.success?).to be(true)
545+
package_name = 'openvoxdb-termini-8.9.1-1.el.noarch.rpm'
546+
expect(output).to include("Assigned package_name=#{package_name}")
547+
expect(output).to include("Assigned package_url=https://foo/openvoxdb-termini/8.9.1/#{package_name}")
548+
end
549+
550+
it 'builds a fedora url' do
551+
allow_script.to set_env('os_family', 'fedora')
552+
allow_script.to receive_command(:uname).and_exec('echo x86_64')
553+
output, status = test('set_artifacts_package_url https://foo openvox-agent 8.18.0')
554+
555+
expect(status.success?).to be(true)
556+
package_name = 'openvox-agent-8.18.0-1.fc.x86_64.rpm'
557+
expect(output).to include("Assigned package_name=#{package_name}")
558+
expect(output).to include("Assigned package_url=https://foo/openvox-agent/8.18.0/#{package_name}")
559+
end
560+
end
561+
end
442562
end

0 commit comments

Comments
 (0)