Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 8 additions & 4 deletions lib/kitchen/provisioner/habitat.rb
Original file line number Diff line number Diff line change
Expand Up @@ -195,8 +195,10 @@ def prepare_command
# Shell code that installs the package under test and loads it as a
# service.
#
# The package is only loaded with +hab svc load+ if it ships a +run+
# hook, so library packages converge cleanly without a service. After
# The package is only loaded with +hab svc load+ if it ships a run
# hook -- either +hooks/run+ or a +run+ file in the package root, both
# of which the supervisor accepts -- so library packages converge
# cleanly without a service. After
# loading, this polls +hab svc status+ until the service appears, giving
# up after +service_load_timeout+ seconds.
#
Expand All @@ -223,7 +225,8 @@ def run_command
$env:Path += ";C:\\ProgramData\\Habitat"
}
hab pkg install #{target_pkg} --channel #{config[:channel]} --force
if (Test-Path -Path "$(hab pkg path #{target_ident})\\hooks\\run") {
$PkgPath = hab pkg path #{target_ident}
if (@("hooks\\run", "hooks\\run.ps1", "run", "run.ps1") | Where-Object { Test-Path -Path (Join-Path $PkgPath $_) }) {
hab svc load #{target_ident} #{service_options} --force
$timer = 0
Do {
Expand All @@ -241,7 +244,8 @@ def run_command
sleep 5
done
sudo hab pkg install #{target_pkg} --channel #{config[:channel]} --force
if [ -f "$(sudo hab pkg path #{target_ident})/hooks/run" ]
pkg_path="$(sudo hab pkg path #{target_ident})"
if [ -f "$pkg_path/hooks/run" ] || [ -f "$pkg_path/run" ]
then
sudo -E hab svc load #{target_ident} #{service_options} --force
timer=0
Expand Down
27 changes: 25 additions & 2 deletions spec/kitchen/provisioner/habitat/run_command_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,24 @@
expect(command).to include("sudo -E hab svc load core/redis")
end

it "guards the load with a test for the package's run hook" do
# The supervisor accepts a run hook in either place: hooks/run from a
# hook template, or a run file in the package root from pkg_svc_run.
# Only hooks/run used to be checked, so a package built the second way
# -- core/redis, among many others -- was installed and then silently
# never loaded, and the converge reported success.
it "guards the load with a test for a run hook in either place" do
config[:package_name] = "redis"

expect(provisioner.run_command).to include(%(if [ -f "$(sudo hab pkg path core/redis)/hooks/run" ]))
command = provisioner.run_command

expect(command).to include(%(pkg_path="$(sudo hab pkg path core/redis)"))
expect(command).to include(%(if [ -f "$pkg_path/hooks/run" ] || [ -f "$pkg_path/run" ]))
end

it "asks hab for the package path only once" do
config[:package_name] = "redis"

expect(provisioner.run_command.scan("hab pkg path").length).to eq(1)
end

# The timeout used to be spelled `[$timer -gt 300]` with no spaces, which
Expand Down Expand Up @@ -105,6 +119,15 @@

expect(provisioner.run_command).to include("if ($timer -gt 42){exit 1}")
end

it "guards the load with a test for a run hook in either place" do
config[:package_name] = "redis"

command = provisioner.run_command

expect(command).to include("$PkgPath = hab pkg path core/redis")
expect(command).to include(%(@("hooks\\run", "hooks\\run.ps1", "run", "run.ps1")))
end
end
end

Expand Down
Loading