Skip to content

Commit d517aca

Browse files
authored
Merge pull request #36 from jpartlow/gh-35-add-stop-service-to-install
(gh-35) Add a stop_service parameter to install task
2 parents ba856f3 + 6c07d34 commit d517aca

File tree

7 files changed

+173
-11
lines changed

7 files changed

+173
-11
lines changed

.github/workflows/pr_testing.yaml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ jobs:
4141
uses: ./.github/actions/bolt
4242
with:
4343
os-codename: ${{ matrix.os-details.codename }}
44-
- name: Run openvox-agent install task
44+
- name: Run install task for openvox-agent
4545
run: bolt task run openvox_bootstrap::install --targets localhost --run-as root
4646
- name: Verify openvox-agent is installed
4747
run: bolt task run openvox_bootstrap::check --targets localhost --run-as root
@@ -71,7 +71,7 @@ jobs:
7171
path: openvox_bootstrap
7272
- id: prep
7373
uses: ./openvox_bootstrap/.github/actions/container_task_prep
74-
- name: Run openvox-agent install task manually
74+
- name: Run install task manually for openvox-agent
7575
env:
7676
PT_collection: openvox8
7777
run: ./openvox_bootstrap/tasks/install_linux.sh
@@ -104,7 +104,7 @@ jobs:
104104
path: openvox_bootstrap
105105
- id: prep
106106
uses: ./openvox_bootstrap/.github/actions/container_task_prep
107-
- name: Run openvox-agent install task manually
107+
- name: Run install task manually for openvox-agent
108108
env:
109109
PT_version: "8.14.0"
110110
run: ./openvox_bootstrap/tasks/install_linux.sh
@@ -137,7 +137,7 @@ jobs:
137137
path: openvox_bootstrap
138138
- id: prep
139139
uses: ./openvox_bootstrap/.github/actions/container_task_prep
140-
- name: Run openvox-agent install task manually
140+
- name: Run install task manually for openvox-server
141141
env:
142142
PT_package: "openvox-server"
143143
run: ./openvox_bootstrap/tasks/install_linux.sh
@@ -168,7 +168,7 @@ jobs:
168168
path: openvox_bootstrap
169169
- id: prep
170170
uses: ./openvox_bootstrap/.github/actions/container_task_prep
171-
- name: Run openvox-agent install task manually
171+
- name: Run install task manually for openvox-server
172172
env:
173173
PT_package: "openvox-server"
174174
PT_version: "8.8.0"

.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+
bolt command run '/opt/puppetlabs/bin/puppet resource service openvox-agent' --inventory inventory.yaml --targets test-agent-1 > service.state
132+
grep -E "ensure [ ]*=> [ ]*'stopped'" service.state
133+
grep -E "enable [ ]*=> [ ]*'false'" service.state

REFERENCE.md

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -123,15 +123,15 @@ Installs an openvox package. By default, this will be the latest openvox-agent f
123123

124124
##### `package`
125125

126-
Data type: `String[1]`
126+
Data type: `Optional[String]`
127127

128128
The name of the package to install.
129129

130130
##### `version`
131131

132132
Data type: `Optional[String]`
133133

134-
The version of the openvox-agent package to install. Defaults to latest.
134+
The version of the openvox-agent package to install.
135135

136136
##### `collection`
137137

@@ -151,6 +151,12 @@ Data type: `Optional[String]`
151151

152152
The yum source repository to retrieve rpm packages from.
153153

154+
##### `stop_service`
155+
156+
Data type: `Optional[Boolean]`
157+
158+
Whether to stop the given service after install. (Requires puppet on the system.)
159+
154160
### <a name="install_build_artifact"></a>`install_build_artifact`
155161

156162
Downloads and installs a package directly from the openvox build artifact server.

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: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,13 @@
33
"parameters": {
44
"package": {
55
"description": "The name of the package to install.",
6-
"type": "String[1]",
6+
"type": "Optional[String]",
77
"default": "openvox-agent"
88
},
99
"version": {
10-
"description": "The version of the openvox-agent package to install. Defaults to latest.",
11-
"type": "Optional[String]"
10+
"description": "The version of the openvox-agent package to install.",
11+
"type": "Optional[String]",
12+
"default": "latest"
1213
},
1314
"collection": {
1415
"description": "The openvox collection to install from.",
@@ -24,6 +25,11 @@
2425
"description": "The yum source repository to retrieve rpm packages from.",
2526
"type": "Optional[String]",
2627
"default": "https://yum.voxpupuli.org"
28+
},
29+
"stop_service": {
30+
"description": "Whether to stop the given service after install. (Requires puppet on the system.)",
31+
"type": "Optional[Boolean]",
32+
"default": false
2733
}
2834
},
2935
"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)