Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
ekohl committed Sep 1, 2020
1 parent 76ee2bc commit d7e6c5a
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 12 deletions.
4 changes: 2 additions & 2 deletions lib/puppet/x/jenkins/provider/cli.rb
Original file line number Diff line number Diff line change
Expand Up @@ -226,8 +226,8 @@ def self.execute_with_retry(command, options = {}, cli_pre_cmd = [])
return result
rescue UnknownError, NetError => exception
Puppet.debug("#{sname} caught #{exception.class.to_s.match(%r{::([^:]+)$})[1]}; retry attempt #{attempt_number}")
if attempt < cli_tries
attempt += 1
if attempt_number < cli_tries
attempt_number += 1
sleep(cli_try_sleep)
retry
end
Expand Down
22 changes: 12 additions & 10 deletions spec/unit/puppet/x/jenkins/provider/cli_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -472,6 +472,7 @@
context 'without ssh_private_key' do
CLI_NET_ERRORS.each do |error|
it 'does not retry cli on AuthError exception' do
expect(described_class).to receive(:sleep).with(2).exactly(30).times
expect(described_class.superclass).to receive(:execute).with(
'java -jar /usr/lib/jenkins/jenkins-cli.jar -s http://localhost:8080 -logger WARNING foo',
failonfail: true, combine: true
Expand All @@ -495,6 +496,7 @@
)
catalog.add_resource jenkins

expect(described_class).to receive(:sleep).with(2).exactly(30).times
expect(described_class.superclass).to receive(:execute).with(
'java -jar /usr/lib/jenkins/jenkins-cli.jar -s http://localhost:8080 -logger WARNING foo',
failonfail: true, combine: true
Expand All @@ -511,6 +513,7 @@
)
catalog.add_resource jenkins

expect(described_class).to receive(:sleep).with(2).exactly(2).times
expect(described_class.superclass).to receive(:execute).with(
'java -jar /usr/lib/jenkins/jenkins-cli.jar -s http://localhost:8080 -logger WARNING foo',
failonfail: true, combine: true
Expand All @@ -528,6 +531,7 @@
)
catalog.add_resource jenkins

expect(described_class).to receive(:sleep).with(2).exactly(3).times
expect(described_class.superclass).to receive(:execute).with(
'java -jar /usr/lib/jenkins/jenkins-cli.jar -s http://localhost:8080 -logger WARNING foo',
failonfail: true, combine: true
Expand All @@ -546,6 +550,7 @@
)
catalog.add_resource jenkins

expect(described_class).to receive(:sleep).with(2).exactly(2).times
expect(described_class.superclass).to receive(:execute).with(
'java -jar /usr/lib/jenkins/jenkins-cli.jar -s http://localhost:8080 -logger WARNING foo',
failonfail: true, combine: true
Expand All @@ -566,7 +571,7 @@
catalog.add_resource jenkins

expect(described_class.superclass).to receive(:execute_with_auth).and_raise(AuthError)
expect(sleep).to receive(2)
expect(described_class).to receive(:sleep).with(2).exactly(30).times
expect(described_class.superclass).to receive(:execute_with_auth)

described_class.cli('foo', catalog: catalog)
Expand All @@ -579,9 +584,8 @@
)
catalog.add_resource jenkins

expect(described_class.superclass).to receive(:execute_with_auth).and_raise(AuthError)
expect(sleep).to receive(3)
expect(described_class.superclass).to receive(:execute_with_auth)
expect(described_class).to receive(:execute_with_auth).and_raise(AuthError)
expect(described_class).to receive(:sleep).with(3).exactly(30).times

described_class.cli('foo', catalog: catalog)
end
Expand All @@ -594,9 +598,8 @@
)
catalog.add_resource jenkins

expect(described_class.superclass).to receive(:execute_with_auth).and_raise(AuthError)
expect(sleep).to receive(4)
expect(described_class.superclass).to receive(:execute_with_auth)
expect(described_class).to receive(:execute_with_auth).and_raise(AuthError)
expect(described_class).to receive(:sleep).with(4).exactly(30).times

described_class.cli('foo', catalog: catalog)
end
Expand All @@ -610,9 +613,8 @@
)
catalog.add_resource jenkins

expect(described_class.superclass).to receive(:execute_with_auth).and_raise(AuthError)
expect(sleep).to receive(3)
expect(described_class.superclass).to receive(:execute_with_auth)
expect(described_class).to receive(:execute_with_auth).and_raise(AuthError)
expect(described_class).to receive(:sleep).with(3).exactly(30).times

described_class.cli('foo', catalog: catalog)
end
Expand Down

0 comments on commit d7e6c5a

Please sign in to comment.