Skip to content

Commit be21d58

Browse files
committed
install which command
1 parent 2688ca2 commit be21d58

File tree

7 files changed

+84
-72
lines changed

7 files changed

+84
-72
lines changed

.github/workflows/spec.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ jobs:
122122
- name: Run Static & Syntax Tests
123123
run: |
124124
buildevents cmd $TRACE_ID $STEP_ID 'static_syntax_checks Puppet ${{ matrix.puppet_version }}, Ruby ${{ matrix.ruby_version }}' -- bundle exec rake syntax lint metadata_lint check:symlinks check:git_ignore check:dot_underscore check:test_file rubocop
125-
125+
126126
- name: Run parallel_spec tests
127127
run: |
128128
buildevents cmd $TRACE_ID $STEP_ID 'rake parallel_spec Puppet ${{ matrix.puppet_version }}, Ruby ${{ matrix.ruby_version }}' -- bundle exec rake parallel_spec

spec/spec_helper_acceptance_local.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ class CommandFailure < StandardError; end
1919
# shutdown command on $PATH with the script defined in LINUX_SHUTDOWN_SCRIPT, which will output the args passed to it
2020
# from the Agent. We will then verify that these args are what we expect.
2121
def substitute_shutdown_on_path
22+
Helper.instance.run_shell('puppet resource package which ensure=latest')
23+
Helper.instance.run_shell('puppet resource package systemd-sysv ensure=latest') if os[:family] == 'debian' && os[:release].to_i == 9
2224
$shutdown_path = Helper.instance.run_shell('which shutdown').stdout.chomp
2325
if Helper.instance.run_shell("test -f #{SHUTDOWN_TEMP_LOC}", expect_failures: true).exit_code == 0
2426
return if Helper.instance.run_shell("sha1sum #{$shutdown_path} | cut -d ' ' -f 1").stdout.chomp == SHUTDOWN_SCRIPT_EXPECTED_SHA1

spec/unit/provider/reboot/linux_spec.rb

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919

2020
context '#initialize' do
2121
it 'issues a deprecation warning' do
22-
Puppet.expects(:deprecation_warning).with("The 'linux' reboot provider is deprecated and will be removed; use 'posix' instead.")
22+
expect(Puppet).to receive(:deprecation_warning).with("The 'linux' reboot provider is deprecated and will be removed; use 'posix' instead.")
2323

2424
Puppet::Type.type(:reboot).new(provider: :linux, name: 'linux_reboot')
2525
end
@@ -37,55 +37,55 @@
3737
end
3838

3939
it 'does not reboot when setting the `when` property to refreshed' do
40-
provider.expects(:reboot).never
40+
expect(provider).to receive(:reboot).never
4141

4242
provider.when = :refreshed
4343
end
4444
end
4545

4646
context 'when a reboot is triggered', if: Puppet::Util.which('shutdown') do
4747
before :each do
48-
provider.expects(:async_shutdown).with(includes('shutdown')).at_most_once
49-
Facter.stubs(:value).with(:kernel).returns('Linux')
48+
expect(provider).to receive(:async_shutdown).with(include('shutdown')).at_most(:once)
49+
allow(Facter).to receive(:value).with(:kernel).and_return('Linux')
5050
end
5151

5252
it 'stops the application by default' do
53-
Puppet::Application.expects(:stop!)
53+
expect(Puppet::Application).to receive(:stop!)
5454
provider.reboot
5555
end
5656

5757
it 'cancels the rest of the catalog transaction if apply is set to immediately' do
5858
resource[:apply] = :immediately
59-
Puppet::Application.expects(:stop!)
59+
expect(Puppet::Application).to receive(:stop!)
6060
provider.reboot
6161
end
6262

6363
it "doesn't stop the rest of the catalog transaction if apply is set to finished" do
6464
resource[:apply] = :finished
65-
Puppet::Application.expects(:stop!).never
65+
expect(Puppet::Application).to receive(:stop!).never
6666
provider.reboot
6767
end
6868

6969
it 'includes the restart flag' do
70-
provider.expects(:async_shutdown).with(includes('-r'))
70+
expect(provider).to receive(:async_shutdown).with(include('-r')).at_most(:once)
7171
provider.reboot
7272
end
7373

7474
it 'includes a timeout in the future' do
75-
provider.expects(:async_shutdown).with(includes("+#{(resource[:timeout].to_i / 60.0).ceil}"))
75+
expect(provider).to receive(:async_shutdown).with(include("+#{(resource[:timeout].to_i / 60.0).ceil}")).at_most(:once)
7676
provider.reboot
7777
end
7878

7979
it 'rounds up and provides a warning if the timeout is not a multiple of 60' do
8080
resource[:timeout] = 61
81-
Puppet.expects(:warning).with(includes('rounding'))
82-
provider.expects(:async_shutdown).with(includes("+#{(resource[:timeout].to_i / 60.0).ceil}"))
81+
expect(Puppet).to receive(:warning).with(include('rounding')).at_most(:once)
82+
expect(provider).to receive(:async_shutdown).with(include("+#{(resource[:timeout].to_i / 60.0).ceil}")).at_most(:once)
8383
provider.reboot
8484
end
8585

8686
it 'includes the quoted reboot message' do
8787
resource[:message] = 'triggering a reboot'
88-
provider.expects(:async_shutdown).with(includes('"triggering a reboot"'))
88+
expect(provider).to receive(:async_shutdown).with(include('"triggering a reboot"')).at_most(:once)
8989
provider.reboot
9090
end
9191
end

spec/unit/provider/reboot/posix_spec.rb

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -24,88 +24,88 @@
2424
end
2525

2626
it 'does not reboot when setting the `when` property to refreshed' do
27-
provider.expects(:reboot).never
27+
expect(provider).to receive(:reboot).never
2828

2929
provider.when = :refreshed
3030
end
3131
end
3232

3333
context 'when a reboot is triggered', if: Puppet::Util.which('shutdown') do
3434
before :each do
35-
provider.expects(:async_shutdown).with(includes('shutdown')).at_most_once
35+
expect(provider).to receive(:async_shutdown).with(include('shutdown')).at_most(:once)
3636
end
3737

3838
it 'stops the application by default' do
39-
Puppet::Application.expects(:stop!)
39+
expect(Puppet::Application).to receive(:stop!)
4040
provider.reboot
4141
end
4242

4343
it 'cancels the rest of the catalog transaction if apply is set to immediately' do
4444
resource[:apply] = :immediately
45-
Puppet::Application.expects(:stop!)
45+
expect(Puppet::Application).to receive(:stop!)
4646
provider.reboot
4747
end
4848

4949
it "doesn't stop the rest of the catalog transaction if apply is set to finished" do
5050
resource[:apply] = :finished
51-
Puppet::Application.expects(:stop!).never
51+
expect(Puppet::Application).to receive(:stop!).never
5252
provider.reboot
5353
end
5454

5555
context 'on Solaris' do
5656
before :each do
57-
Facter.stubs(:value).with(:kernel).returns('SunOS')
57+
allow(Facter).to receive(:value).with(:kernel).and_return('SunOS')
5858
end
5959

6060
it 'includes the pre-confirmation flag' do
61-
provider.expects(:async_shutdown).with(includes('-y'))
61+
expect(provider).to receive(:async_shutdown).with(include('-y')).at_most(:once)
6262
provider.reboot
6363
end
6464

6565
it 'includes the init-state 6 flag' do
66-
provider.expects(:async_shutdown).with(includes('-i 6'))
66+
expect(provider).to receive(:async_shutdown).with(include('-i 6')).at_most(:once)
6767
provider.reboot
6868
end
6969

7070
it 'includes a timeout in the future' do
71-
provider.expects(:async_shutdown).with(includes("-g #{resource[:timeout].to_i}"))
71+
expect(provider).to receive(:async_shutdown).with(include("-g #{resource[:timeout].to_i}")).at_most(:once)
7272
provider.reboot
7373
end
7474

7575
it 'accepts timeouts that are not multiples of 60' do
7676
resource[:timeout] = 61
77-
Puppet.expects(:warning).with(includes('rounding')).never
78-
provider.expects(:async_shutdown).with(includes("-g #{resource[:timeout].to_i}"))
77+
expect(Puppet).to receive(:warning).with(include('rounding')).never
78+
expect(provider).to receive(:async_shutdown).with(include("-g #{resource[:timeout].to_i}")).at_most(:once)
7979
provider.reboot
8080
end
8181
end
8282

8383
context 'on other systems' do
8484
before :each do
85-
Facter.stubs(:value).with(:kernel).returns('Linux')
85+
allow(Facter).to receive(:value).with(:kernel).and_return('Linux')
8686
end
8787

8888
it 'includes the restart flag' do
89-
provider.expects(:async_shutdown).with(includes('-r'))
89+
expect(provider).to receive(:async_shutdown).with(include('-r')).at_most(:once)
9090
provider.reboot
9191
end
9292

9393
it 'includes a timeout in the future' do
94-
provider.expects(:async_shutdown).with(includes("+#{(resource[:timeout].to_i / 60.0).ceil}"))
94+
expect(provider).to receive(:async_shutdown).with(include("+#{(resource[:timeout].to_i / 60.0).ceil}")).at_most(:once)
9595
provider.reboot
9696
end
9797

9898
it 'rounds up and provides a warning if the timeout is not a multiple of 60' do
9999
resource[:timeout] = 61
100-
Puppet.expects(:warning).with(includes('rounding'))
101-
provider.expects(:async_shutdown).with(includes("+#{(resource[:timeout].to_i / 60.0).ceil}"))
100+
expect(Puppet).to receive(:warning).with(include('rounding')).at_most(:once)
101+
expect(provider).to receive(:async_shutdown).with(include("+#{(resource[:timeout].to_i / 60.0).ceil}")).at_most(:once)
102102
provider.reboot
103103
end
104104
end
105105

106106
it 'includes the quoted reboot message' do
107107
resource[:message] = 'triggering a reboot'
108-
provider.expects(:async_shutdown).with(includes('"triggering a reboot"'))
108+
expect(provider).to receive(:async_shutdown).with(include('"triggering a reboot"')).at_most(:once)
109109
provider.reboot
110110
end
111111
end

spec/unit/task/init_spec.rb

Lines changed: 22 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,22 @@
11
# frozen_string_literal: true
22

33
require 'spec_helper'
4-
require_relative '../../../tasks/init'
4+
# require_relative '../../../tasks/init'
5+
require File.dirname(__FILE__) + '/../../../tasks/init.rb'
56

67
describe Reboot::Task do # rubocop:disable RSpec/FilePath
78
context 'on Windows' do
8-
before(:each) { Facter.stubs(:value).with(:kernel).returns('windows') }
9+
before(:each) do
10+
allow(Facter).to receive(:value).with(:kernel).and_return('windows')
11+
end
912

1013
context 'when rebooting' do
1114
let(:reboot) { described_class.new }
1215

1316
it 'runs the correct command' do
1417
command = 'shutdown.exe /r /t 3 /d p:4:1 '
15-
reboot.expects(:shutdown_executable_windows).returns('shutdown.exe')
16-
reboot.expects(:async_command).with(command).returns(nil)
18+
expect(reboot).to receive(:shutdown_executable_windows).and_return('shutdown.exe')
19+
expect(reboot).to receive(:async_command).with(command).and_return(nil)
1720
reboot.execute!
1821
end
1922

@@ -22,16 +25,16 @@
2225

2326
it 'handles the timeout' do
2427
command = 'shutdown.exe /r /t 20 /d p:4:1 '
25-
reboot.expects(:shutdown_executable_windows).returns('shutdown.exe')
26-
reboot.expects(:async_command).with(command).returns(nil)
28+
expect(reboot).to receive(:shutdown_executable_windows).and_return('shutdown.exe')
29+
expect(reboot).to receive(:async_command).with(command).and_return(nil)
2730
reboot.execute!
2831
end
2932

3033
it 'does not allow timeouts < 3' do
3134
reboot = described_class.new('timeout' => 0)
3235
command = 'shutdown.exe /r /t 3 /d p:4:1 '
33-
reboot.expects(:shutdown_executable_windows).returns('shutdown.exe')
34-
reboot.expects(:async_command).with(command).returns(nil)
36+
expect(reboot).to receive(:shutdown_executable_windows).and_return('shutdown.exe')
37+
expect(reboot).to receive(:async_command).with(command).and_return(nil)
3538
reboot.execute!
3639
end
3740
end
@@ -42,23 +45,23 @@
4245

4346
it 'runs the correct command' do
4447
command = 'shutdown.exe /s /t 3 /d p:4:1 '
45-
reboot.expects(:shutdown_executable_windows).returns('shutdown.exe')
46-
reboot.expects(:async_command).with(command).returns(nil)
48+
expect(reboot).to receive(:shutdown_executable_windows).and_return('shutdown.exe')
49+
expect(reboot).to receive(:async_command).with(command).and_return(nil)
4750
reboot.execute!
4851
end
4952
end
5053
end
5154

5255
context 'on Solaris' do
53-
before(:each) { Facter.stubs(:value).with(:kernel).returns('SunOS') }
56+
before(:each) { allow(Facter).to receive(:value).with(:kernel).and_return('SunOS') }
5457

5558
context 'when rebooting' do
5659
let(:reboot) { described_class.new }
5760

5861
it 'runs the correct command' do
5962
# Enforces minimum 3s timeout.
6063
command = ['shutdown', '-y', '-i', '6', '-g', 3, "''", '</dev/null', '>/dev/null', '2>&1', '&']
61-
reboot.expects(:async_command).with(command).returns(nil)
64+
expect(reboot).to receive(:async_command).with(command).and_return(nil)
6265
reboot.execute!
6366
end
6467

@@ -67,7 +70,7 @@
6770

6871
it 'handles the timeout' do
6972
command = ['shutdown', '-y', '-i', '6', '-g', 20, "''", '</dev/null', '>/dev/null', '2>&1', '&']
70-
reboot.expects(:async_command).with(command).returns(nil)
73+
expect(reboot).to receive(:async_command).with(command).and_return(nil)
7174
reboot.execute!
7275
end
7376
end
@@ -79,22 +82,22 @@
7982
it 'runs the correct command' do
8083
# Enforces minimum 3s timeout.
8184
command = ['shutdown', '-y', '-i', '5', '-g', 3, "''", '</dev/null', '>/dev/null', '2>&1', '&']
82-
reboot.expects(:async_command).with(command).returns(nil)
85+
expect(reboot).to receive(:async_command).with(command).and_return(nil)
8386
reboot.execute!
8487
end
8588
end
8689
end
8790

8891
context 'on Linux' do
89-
before(:each) { Facter.stubs(:value).with(:kernel).returns('Linux') }
92+
before(:each) { allow(Facter).to receive(:value).with(:kernel).and_return('Linux') }
9093

9194
context 'when rebooting' do
9295
let(:reboot) { described_class.new }
9396

9497
it 'runs the correct command' do
9598
command = ['shutdown', '-r', 'now', "''", '</dev/null', '>/dev/null', '2>&1', '&']
9699
# Enforces minimum 3s timeout.
97-
reboot.expects(:async_command).with(command, 3).returns(nil)
100+
expect(reboot).to receive(:async_command).with(command, 3).and_return(nil)
98101
reboot.execute!
99102
end
100103

@@ -103,7 +106,7 @@
103106

104107
it 'handles the timeout by sleeping' do
105108
command = ['shutdown', '-r', 'now', "''", '</dev/null', '>/dev/null', '2>&1', '&']
106-
reboot.expects(:async_command).with(command, 20).returns(nil)
109+
expect(reboot).to receive(:async_command).with(command, 20).and_return(nil)
107110
reboot.execute!
108111
end
109112
end
@@ -113,7 +116,7 @@
113116

114117
it 'handles the timeout by sleeping' do
115118
command = ['shutdown', '-r', '+1', "''", '</dev/null', '>/dev/null', '2>&1', '&']
116-
reboot.expects(:async_command).with(command, 30).returns(nil)
119+
expect(reboot).to receive(:async_command).with(command, 30).and_return(nil)
117120
reboot.execute!
118121
end
119122
end
@@ -125,7 +128,7 @@
125128
it 'runs the correct command' do
126129
# Enforces minimum 3s timeout.
127130
command = ['shutdown', '-P', 'now', "''", '</dev/null', '>/dev/null', '2>&1', '&']
128-
reboot.expects(:async_command).with(command, 3).returns(nil)
131+
expect(reboot).to receive(:async_command).with(command, 3).and_return(nil)
129132
reboot.execute!
130133
end
131134
end

0 commit comments

Comments
 (0)