Skip to content

Commit

Permalink
Remove retries gem
Browse files Browse the repository at this point in the history
  • Loading branch information
ekohl committed Aug 31, 2020
1 parent 88942b2 commit 19d6187
Show file tree
Hide file tree
Showing 7 changed files with 21 additions and 85 deletions.
9 changes: 0 additions & 9 deletions NATIVE_TYPES_AND_PROVIDERS.md
Original file line number Diff line number Diff line change
Expand Up @@ -124,8 +124,6 @@ class { '::jenkins':
include ::jenkins::cli_helper
```

The ruby gem `retries` is presently required by all providers.

### `puppetserver`

There is a known issue with `puppetserver` being unable to load code from
Expand All @@ -144,13 +142,6 @@ jruby-puppet: {

See [SERVER-973](https://tickets.puppetlabs.com/browse/SERVER-973)

Additionally, the `retries` gem is required. This may be installed on the master by running:

```
/opt/puppetlabs/bin/puppetserver gem install retries
```


Types
--

Expand Down
3 changes: 0 additions & 3 deletions lib/puppet/feature/retries.rb

This file was deleted.

20 changes: 9 additions & 11 deletions lib/puppet/x/jenkins/provider/cli.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ def self.inherited(subclass)
initvars

commands java: 'java'
confine feature: :retries

# subclasses should inherit this value once it has been determined that
# jenkins requires authorization, it shortens the run time be elemating the
Expand Down Expand Up @@ -220,19 +219,18 @@ def self.execute_with_retry(command, options = {}, cli_pre_cmd = [])
# retry on "unknown" execution errors but don't catch AuthErrors. If an
# AuthError has bubbled up to this level it means either an ssh_private_key
# is required and we don't have one or that one we have was rejected.
handler = proc do |exception, attempt_number, total_delay|
Puppet.debug("#{sname} caught #{exception.class.to_s.match(%r{::([^:]+)$})[1]}; retry attempt #{attempt_number}; #{total_delay.round(3)} seconds have passed")
end
with_retries(
max_tries: cli_tries,
base_sleep_seconds: 1,
max_sleep_seconds: cli_try_sleep,
rescue: [UnknownError, NetError],
handler: handler
) do
attempt_number = 0
begin
result = execute_with_auth(cli_cmd, auth_cmd, options)
Puppet.debug("#{sname} command stdout:\n#{result}") unless result == ''
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
sleep(cli_try_sleep)
retry
end
end
end
private_class_method :execute_with_retry
Expand Down
19 changes: 0 additions & 19 deletions manifests/cli/config.pp
Original file line number Diff line number Diff line change
Expand Up @@ -20,29 +20,10 @@
Optional[Boolean] $cli_remoting_free = undef,
Optional[String] $ssh_private_key_content = undef,
) {

if str2bool($facts['is_pe']) {
$gem_provider = 'pe_gem'
# lint:ignore:legacy_facts
} elsif $facts['rubysitedir'] and ('/opt/puppetlabs/puppet/lib/ruby' in $facts['rubysitedir']) {
# lint:endignore
# AIO puppet
$gem_provider = 'puppet_gem'
} else {
$gem_provider = 'gem'
}

# lint:ignore:legacy_facts
$is_root = $facts['id'] == 'root'
# lint:endignore

# required by PuppetX::Jenkins::Provider::Clihelper base
if ! defined(Package['retries']) {
package { 'retries':
provider => $gem_provider,
}
}

if $ssh_private_key and $ssh_private_key_content {
file { $ssh_private_key:
ensure => 'file',
Expand Down
20 changes: 0 additions & 20 deletions spec/classes/cli/config_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -122,26 +122,6 @@
end # when ssh_private_key is also set
end # ssh_private_key_content
end # parameters

describe 'package gem provider' do
context 'is_pe fact' do
context 'true' do
let :facts do
super().merge(is_pe: true)
end

it { is_expected.to contain_package('retries').with(provider: 'pe_gem') }
end

context 'false' do
let :facts do
super().merge(is_pe: false)
end

it { is_expected.to contain_package('retries').with(provider: 'gem') }
end
end # 'is_pe fact' do
end # 'package gem provider' do
end
end
end
26 changes: 12 additions & 14 deletions spec/unit/puppet/x/jenkins/provider/cli_spec.rb
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
require 'spec_helper'
require 'unit/puppet/x/spec_jenkins_providers'

# we need to make sure retries is always loaded or random test ordering can
# cause failures when a side effect hasn't yet caused the lib to be loaded
require 'retries'
require 'puppet/x/jenkins/provider/cli'

describe Puppet::X::Jenkins::Provider::Cli do
Expand Down Expand Up @@ -309,13 +306,6 @@
end # ::clihelper

describe '::cli' do
before do
# disable with_retries sleeping to [vastly] speed up testing
#
# we are relying the side effects of ::suitable? from a previous example
Retries.sleep_enabled = false
end

shared_examples 'uses default values' do
it 'uses default values' do
expect(described_class.superclass).to receive(:execute).with(
Expand Down Expand Up @@ -575,7 +565,9 @@
)
catalog.add_resource jenkins

expect(described_class).to receive(:with_retries).with(hash_including(max_sleep_seconds: 2))
expect(described_class.superclass).to receive(:execute_with_auth).and_raise(AuthError)
expect(sleep).to receive(2)
expect(described_class.superclass).to receive(:execute_with_auth)

described_class.cli('foo', catalog: catalog)
end
Expand All @@ -587,7 +579,9 @@
)
catalog.add_resource jenkins

expect(described_class).to receive(:with_retries).with(hash_including(max_sleep_seconds: 3))
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)

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

expect(described_class).to receive(:with_retries).with(hash_including(max_sleep_seconds: 4))
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)

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

expect(described_class).to receive(:with_retries).with(hash_including(max_sleep_seconds: 3))
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)

described_class.cli('foo', catalog: catalog)
end
Expand Down
9 changes: 0 additions & 9 deletions spec/unit/puppet/x/spec_jenkins_providers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,6 @@
described_class.confine_collection.instance_variable_get(:@confines)
end

context 'feature :retries' do
it do
expect(confines).to include(
be_kind_of(Puppet::Confine::Feature).
and(have_attributes(values: [:retries]))
)
end
end

context 'commands :java' do
it do
expect(confines).to include(
Expand Down

0 comments on commit 19d6187

Please sign in to comment.