Skip to content

Commit d83b9d2

Browse files
committed
(gh-35) Add a stop_service parameter to install task
This is for integration with openbolt for openvoxproject/openbolt@44. Bolt was providing a stop_service parameter to the puppetlabs-puppet_agent module here: https://github.com/OpenVoxProject/openbolt/blob/b9bff5a8dfe2f41218281bf8c5e6ad901bcae460/lib/bolt/plugin.rb#L133 This was for puppetlabs/bolt#1204, and while the current linux packages, at least, install with service stopped, it's probably still good practice to ensure it for the openbolt case. (This may have been more of an issue when some packages were still SysV?) Since our install task is more general, it could be used for openvox-server/openvoxdb, but there's no particular use case for this, and I haven't bothered with acceptance tests for them.
1 parent c248f2e commit d83b9d2

File tree

5 files changed

+156
-1
lines changed

5 files changed

+156
-1
lines changed

.github/workflows/pr_testing_with_nested_vms.yml

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,3 +70,64 @@ jobs:
7070
- name: Verify openvox-agent is installed
7171
run: |-
7272
bolt task run openvox_bootstrap::check version=8 test=gt --inventory inventory.yaml --targets test-agent-1
73+
74+
# The rockylinux containers aren't set up for interacting with systemd
75+
# so using nested_vms for this test.
76+
test-install-and-stop:
77+
strategy:
78+
fail-fast: false
79+
matrix:
80+
os:
81+
- [debian, '12']
82+
- [rocky, '9']
83+
- [ubuntu, '24.04']
84+
runs-on: ubuntu-22.04
85+
steps:
86+
- uses: actions/checkout@v4
87+
- id: install-bolt
88+
uses: ./.github/actions/bolt
89+
with:
90+
os-codename: jammy
91+
- id: vm-cluster
92+
uses: jpartlow/nested_vms@v1
93+
with:
94+
os: ${{ matrix.os[0] }}
95+
os-version: ${{ matrix.os[1] }}
96+
os-arch: ${{ matrix.os[2] || 'x86_64' }}
97+
image_version: ${{ matrix.os[3] }}
98+
host-root-access: true
99+
ruby-version: '3.3'
100+
install-openvox: false
101+
# Note: the cpu_mode is set to host-model for the sake of
102+
# el-9 which expects at least x86_64-2 arch. This depends on
103+
# the runner's architecture being sufficient, and there is
104+
# probably a better way to get this set on the libvirt
105+
# domain instead.
106+
vms: |-
107+
[
108+
{
109+
"role": "agent",
110+
"count": 1,
111+
"cpus": 2,
112+
"mem_mb": 4096,
113+
"cpu_mode": "host-model"
114+
}
115+
]
116+
- name: Capture dereferenced inventory for use with openvox_bootstrap
117+
working-directory: kvm_automation_tooling
118+
run: |-
119+
bolt inventory --inventory terraform/instances/inventory.test.yaml show --format json --detail | \
120+
jq '.inventory | with_entries(select(.key == "targets")) | del(.targets[0].groups)' | \
121+
yq -P > ../inventory.yaml
122+
- name: Run openvox_bootstrap::install task on nested vm
123+
run: |-
124+
bolt task run openvox_bootstrap::install --inventory inventory.yaml --targets test-agent-1 stop_service=true
125+
- name: Verify openvox-agent is installed
126+
run: |-
127+
bolt task run openvox_bootstrap::check version=8 test=gt --inventory inventory.yaml --targets test-agent-1
128+
- name: Verify service state
129+
run: |-
130+
set -e
131+
/opt/puppetlabs/bin/puppet resource service openvox-agent > service.state
132+
grep -E "ensure [ ]*=> [ ]*'stopped'" service.state
133+
grep -E "enable [ ]*=> [ ]*'false'" service.state

files/common.sh

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -510,3 +510,43 @@ set_artifacts_package_url() {
510510
export package_url # quiets shellcheck SC2034
511511
assigned 'package_url'
512512
}
513+
514+
# Stop and disable the service for the given package.
515+
#
516+
# Only intended to work for openvox-agent, openvoxdb and
517+
# openvox-server.
518+
#
519+
# Will fail if openvox isn't installed.
520+
#
521+
# (voxpupuli/puppet-openvox_bootstrap#35)
522+
# Implemented for integration with openbolt.
523+
stop_and_disable_service() {
524+
local _package="$1"
525+
# Using the full path here because openvox is installed into opt,
526+
# and if we've just installed, the shell's PATH will not include it
527+
# yet.
528+
local _puppet="${2:-/opt/puppetlabs/bin/puppet}"
529+
530+
case "${_package}" in
531+
openvox-agent)
532+
local _service='puppet'
533+
;;
534+
openvoxdb)
535+
local _service='puppetdb'
536+
;;
537+
openvox-server)
538+
local _service='puppetserver'
539+
;;
540+
*)
541+
fail "Cannot stop service. Unknown service for package: '${_package}'"
542+
;;
543+
esac
544+
545+
info "Stopping and disabling service '${_service}' for package '${_package}'"
546+
547+
if [ -x "${_puppet}" ]; then
548+
exec_and_capture "${_puppet}" resource service "${_service}" ensure=stopped enable=false
549+
else
550+
fail "Puppet executable not found at '${_puppet}'. Cannot stop and disable service '${_service}'."
551+
fi
552+
}

spec/unit/bash/common_sh_spec.rb

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -577,4 +577,48 @@
577577
end
578578
end
579579
end
580+
581+
context 'stop_and_disable_service' do
582+
it 'fails for an unknown package' do
583+
output, status = test('stop_and_disable_service unknown-package')
584+
585+
expect(status.success?).to be(false)
586+
expect(output.strip).to include("Unknown service for package: 'unknown-package'")
587+
end
588+
589+
it 'fails if puppet executable not found' do
590+
output, status = test('stop_and_disable_service openvox-agent /no/openvox')
591+
592+
expect(status.success?).to be(false)
593+
expect(output.strip).to include("Puppet executable not found at '/no/openvox'")
594+
end
595+
596+
context 'with puppet executable' do
597+
let(:mock_puppet) { "#{tmpdir}/puppet" }
598+
599+
before do
600+
# The little BashRspec lib isn't sophisticated enough
601+
# to deal with an absolute path, so using this instead of
602+
# allow_script.to receive_command(mock_puppet)...
603+
File.write(mock_puppet, <<~EOF)
604+
#!/bin/sh
605+
echo "Stopping ${3} service"
606+
EOF
607+
File.chmod(0o755, mock_puppet)
608+
end
609+
610+
[
611+
%w[openvox-agent puppet],
612+
%w[openvox-server puppetserver],
613+
%w[openvoxdb puppetdb],
614+
].each do |package, service|
615+
it "stops the #{service} service for #{package}" do
616+
output, status = test("stop_and_disable_service #{package} #{mock_puppet}")
617+
618+
expect(status.success?).to be(true)
619+
expect(output.strip).to include(service)
620+
end
621+
end
622+
end
623+
end
580624
end

tasks/install.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,11 @@
2424
"description": "The yum source repository to retrieve rpm packages from.",
2525
"type": "Optional[String]",
2626
"default": "https://yum.voxpupuli.org"
27+
},
28+
"stop_service": {
29+
"description": "Whether to stop the given service after install. (Requires puppet on the system.)",
30+
"type": "Optional[Boolean]",
31+
"default": false
2732
}
2833
},
2934
"implementations": [

tasks/install_linux.sh

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ version=${PT_version:-latest}
99
collection=${PT_collection:-openvox8}
1010
yum_source=${PT_yum_source:-https://yum.voxpupuli.org}
1111
apt_source=${PT_apt_source:-https://apt.voxpupuli.org}
12+
stop_service=${PT_stop_service:-'false'}
1213

1314
# shellcheck source=files/common.sh
1415
source "${PT__installdir}/openvox_bootstrap/files/common.sh"
@@ -75,5 +76,9 @@ download "${package_url}" "${local_release_package}"
7576
# The release package has the repository metadata needed to install
7677
# packages from the collection using the platform package manager.
7778
install_release_package "${local_release_package}"
78-
# Use the platform package manager to install openvox-agent
79+
# Use the platform package manager to install $package
7980
install_package "${package}" "${version}" "${os_family}" "${os_full_version}"
81+
# If a service stop is requested, stop the service now
82+
if [[ "${stop_service}" = 'true' ]]; then
83+
stop_and_disable_service "${package}"
84+
fi

0 commit comments

Comments
 (0)