beaker 4.9.0 → 4.10.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: aaccea8cc8165229c874ea04ca98c7a9cf8f2f6b
4
- data.tar.gz: 399f13de4b1d8f2e420aa0c77325d9feecbe2ba6
3
+ metadata.gz: e7c29f137a2fc6b34d0503cd2e0db009a3b42dff
4
+ data.tar.gz: 8036e85ce20e94d978d300d257dba7480cd13a98
5
5
  SHA512:
6
- metadata.gz: b0b10ca3c14140283f5b6379e679db95f67cf8bb00579c491628908c8274486e6dea92f626602ab5ef8bf678208a52b74c62fe8a65affaad4e7ab3d231d5905b
7
- data.tar.gz: 7e60c41932f7947b7d8ab96263faab067a7780670a6401bada39b7365aec2ef8d2f19e67587dd54464e910d2dc5cebdc193bd82c80f9f828d7c8c4d0f0533aff
6
+ metadata.gz: 692f011aa278495d2d45790412abe987e54b36297088f0826527f1e267df9b9e5d9d17858cf070c97a691e5de9fd1bb3d68b6f2f97c3374dfd00c9057a8a6354
7
+ data.tar.gz: 7ac79722b6a8679366cb4f73517b13a2b0e410846b6c1ff4ce7e0d51dca8c7a2ead15e29c9b25347a68b356f80d71ce8c58126807dea7d9d92c937ad39af8fbe
@@ -45,6 +45,7 @@ Gem::Specification.new do |s|
45
45
  s.add_runtime_dependency 'hocon', '~> 1.0'
46
46
  s.add_runtime_dependency 'net-ssh', '~> 5.0'
47
47
  s.add_runtime_dependency 'net-scp', '~> 1.2'
48
+ s.add_runtime_dependency 'net-ping', '~> 2.0'
48
49
  s.add_runtime_dependency 'inifile', '~> 3.0'
49
50
 
50
51
  s.add_runtime_dependency 'rsync', '~> 1.0.9'
@@ -2,6 +2,7 @@ require 'socket'
2
2
  require 'timeout'
3
3
  require 'benchmark'
4
4
  require 'rsync'
5
+ require 'net/ping'
5
6
 
6
7
  require 'beaker/dsl/helpers'
7
8
  require 'beaker/dsl/patterns'
@@ -18,6 +19,7 @@ module Beaker
18
19
  include Beaker::DSL::Patterns
19
20
 
20
21
  class CommandFailure < StandardError; end
22
+ class RebootFailure < CommandFailure; end
21
23
 
22
24
  # This class provides array syntax for using puppet --configprint on a host
23
25
  class PuppetConfigReader
@@ -575,6 +577,25 @@ module Beaker
575
577
  raise Beaker::Host::CommandFailure, result.error
576
578
  end
577
579
 
580
+ def ping?
581
+ check = Net::Ping::External.new(self)
582
+ check.ping?
583
+ end
584
+
585
+ def down?
586
+ @logger.debug("host.down?: checking if host has gone down using ping...")
587
+ host_up = true
588
+ repeat_fibonacci_style_for 11 do
589
+ host_up = self.ping?
590
+ @logger.debug("- ping result: #{host_up}. Done checking? #{!host_up}")
591
+ !host_up # host down? -> continue looping. up? -> finished
592
+ end
593
+ if host_up
594
+ raise Beaker::Host::RebootFailure, 'Host failed to go down'
595
+ end
596
+ @logger.debug("host.down? host stopped responding, returning true")
597
+ true
598
+ end
578
599
  end
579
600
 
580
601
  [
@@ -7,7 +7,14 @@ module Unix::Exec
7
7
  else
8
8
  exec(Beaker::Command.new("/sbin/shutdown -r now"), :expect_connection_failure => true)
9
9
  end
10
- sleep(10) #if we attempt a reconnect too quickly we end up blocking ¯\_(ツ)_/¯
10
+ down? # Verify the host went down
11
+ begin
12
+ exec(Beaker::Command.new("exit"))
13
+ rescue Beaker::Host::CommandFailure => e
14
+ raise Beaker::Host::RebootFailure, "Command failed in reboot: #{e.message}"
15
+ rescue Exception => e
16
+ raise Beaker::Host::RebootFailure, "Unexpected exception in reboot: #{e.message}"
17
+ end
11
18
  end
12
19
 
13
20
  def echo(msg, abs=true)
@@ -18,7 +18,7 @@ module Beaker
18
18
  while not done and attempt <= attempts do
19
19
  done = block.call
20
20
  attempt += 1
21
- sleep wait
21
+ sleep wait unless done
22
22
  last_wait, wait = wait, last_wait + wait
23
23
  end
24
24
  return done
@@ -1,5 +1,5 @@
1
1
  module Beaker
2
2
  module Version
3
- STRING = '4.9.0'
3
+ STRING = '4.10.0'
4
4
  end
5
5
  end
@@ -157,5 +157,21 @@ module Beaker
157
157
  expect(instance.selinux_enabled?).to be === false
158
158
  end
159
159
  end
160
+
161
+ describe '#reboot' do
162
+ before :each do
163
+ expect(instance).to receive(:exec).and_return(false)
164
+ expect(instance).to receive(:down?)
165
+ end
166
+ it 'raises a reboot failure when command fails' do
167
+ expect(instance).to receive(:exec).and_raise(Host::CommandFailure)
168
+ expect{ instance.reboot }.to raise_error(Beaker::Host::RebootFailure, /Command failed in reboot: .*/)
169
+ end
170
+
171
+ it 'raises a reboot failure when we receive an unexpected error' do
172
+ expect(instance).to receive(:exec).and_raise(Net::SSH::HostKeyError)
173
+ expect{ instance.reboot }.to raise_error(Beaker::Host::RebootFailure, /Unexpected exception in reboot: .*/)
174
+ end
175
+ end
160
176
  end
161
177
  end
@@ -824,5 +824,30 @@ module Beaker
824
824
  expect(host.wait_for_port(22, 0)).to be false
825
825
  end
826
826
  end
827
+
828
+ describe "#down?" do
829
+
830
+ it "repeats 11 times & fails if ping never returns false" do
831
+ allow(host).to receive(:sleep)
832
+ expect(host).to receive(:ping?).exactly(11).times.and_return(true)
833
+ expect {
834
+ host.down?
835
+ }.to raise_error(Beaker::Host::RebootFailure, /failed to go down/)
836
+ end
837
+
838
+ it "returns that the host is down (true) if ping? is false" do
839
+ expect(host).to receive(:ping?).exactly(1).times.and_return(false)
840
+
841
+ expect(host.down?).to be true
842
+ end
843
+
844
+ it "cuts off execution correctly if host becomes unreachable" do
845
+ expect(host).to receive(:sleep).exactly(3).times
846
+ expect(host).to receive(:ping?).exactly(3).times.and_return(true).ordered
847
+ expect(host).to receive(:ping?).exactly(1).times.and_return(false).ordered
848
+
849
+ expect(host.down?).to be true
850
+ end
851
+ end
827
852
  end
828
853
  end
@@ -4,7 +4,7 @@ module Beaker
4
4
  module Shared
5
5
  describe Repetition do
6
6
 
7
- context 'repeat_for' do
7
+ describe '#repeat_for' do
8
8
  it "repeats a block for 5 seconds" do
9
9
  allow( Time ).to receive( :now ).and_return( 0, 1, 2, 3, 4, 5, 6 )
10
10
 
@@ -30,12 +30,13 @@ module Beaker
30
30
 
31
31
  end
32
32
 
33
- context 'repeat_fibonacci_style_for' do
34
- it "sleeps in fibonacci increasing intervals" do
33
+ describe '#repeat_fibonacci_style_for' do
34
+ let(:block) { double("block") }
35
35
 
36
- block = double( 'block' )
36
+ it "sleeps in fibonacci increasing intervals" do
37
37
  expect( block ).to receive( :exec ).exactly( 5 ).times.and_return( false )
38
38
  allow( subject ).to receive( 'sleep' ).and_return( true )
39
+
39
40
  expect( subject ).to receive( :sleep ).with( 1 ).exactly( 2 ).times
40
41
  expect( subject ).to receive( :sleep ).with( 2 ).once
41
42
  expect( subject ).to receive( :sleep ).with( 3 ).once
@@ -45,25 +46,46 @@ module Beaker
45
46
  subject.repeat_fibonacci_style_for( 5 ) do
46
47
  block.exec
47
48
  end
48
-
49
49
  end
50
50
 
51
- it "should short circuit if the block is complete" do
51
+ it "should short circuit if the block succeeds (returns true)" do
52
+ expect(block).to receive(:exec).and_return(false).ordered.exactly(4).times
53
+ expect(block).to receive(:exec).and_return( true).ordered.once
52
54
 
53
- block = double( 'block' )
54
- expect( block ).to receive( :exec ).once.and_return( true )
55
- allow( subject ).to receive( 'sleep' ).and_return( true )
56
- expect( subject ).to receive( :sleep ).with( 1 ).once
57
- expect( subject ).to receive( :sleep ).with( 2 ).never
58
- expect( subject ).to receive( :sleep ).with( 3 ).never
59
- expect( subject ).to receive( :sleep ).with( 5 ).never
60
- expect( subject ).to receive( :sleep ).with( 8 ).never
55
+ expect(subject).to receive(:sleep).with(1).exactly(2).times
56
+ expect(subject).to receive(:sleep).with(2).once
57
+ expect(subject).to receive(:sleep).with(3).once
58
+ expect(subject).to receive(:sleep).with(anything).never
61
59
 
62
- subject.repeat_fibonacci_style_for( 5 ) do
60
+ subject.repeat_fibonacci_style_for(20) do
63
61
  block.exec
64
62
  end
63
+ end
64
+
65
+ it "returns false if block never returns that it is done (true)" do
66
+ expect(block).to receive(:abcd).exactly(3).times.and_return(false)
67
+
68
+ expect(subject).to receive(:sleep).with(1).exactly(2).times
69
+ expect(subject).to receive(:sleep).with(2).once
70
+ expect(subject).to receive(:sleep).with(anything).never
65
71
 
72
+ success_result = subject.repeat_fibonacci_style_for(3) do
73
+ block.abcd
74
+ end
75
+ expect(success_result).to be false
66
76
  end
77
+
78
+ it "never sleeps if block is successful right at first (returns true)" do
79
+ expect(block).to receive(:fake01).once.and_return(true)
80
+
81
+ expect(subject).to receive(:sleep).never
82
+
83
+ subject.repeat_fibonacci_style_for(3) do
84
+ block.fake01
85
+ end
86
+ end
87
+
88
+
67
89
  end
68
90
 
69
91
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: beaker
3
3
  version: !ruby/object:Gem::Version
4
- version: 4.9.0
4
+ version: 4.10.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Puppet
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-06-19 00:00:00.000000000 Z
11
+ date: 2019-07-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rspec
@@ -240,6 +240,20 @@ dependencies:
240
240
  - - "~>"
241
241
  - !ruby/object:Gem::Version
242
242
  version: '1.2'
243
+ - !ruby/object:Gem::Dependency
244
+ name: net-ping
245
+ requirement: !ruby/object:Gem::Requirement
246
+ requirements:
247
+ - - "~>"
248
+ - !ruby/object:Gem::Version
249
+ version: '2.0'
250
+ type: :runtime
251
+ prerelease: false
252
+ version_requirements: !ruby/object:Gem::Requirement
253
+ requirements:
254
+ - - "~>"
255
+ - !ruby/object:Gem::Version
256
+ version: '2.0'
243
257
  - !ruby/object:Gem::Dependency
244
258
  name: inifile
245
259
  requirement: !ruby/object:Gem::Requirement