Skip to content

Commit 5a98781

Browse files
committed
Merge branch 'master' into hash-each-pair-return
2 parents 8d9bfee + 38c4ae0 commit 5a98781

File tree

5 files changed

+37
-7
lines changed

5 files changed

+37
-7
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ Puppet 4.10.0 is the new minimum required version of Puppet.
1010
* The Elasticsearch log directory is no longer recursively managed to avoid stomping on the user/mode settings that Elasticsearch prefers.
1111
* Package management on apt-based systems no longer encounters dependency errors when `manage_repo => false`.
1212
* An error related to elasticsearch_roles and `yield` errors has been fixed
13+
* Correctly permit instances to be set to `absent` without errors.
1314

1415
#### Features
1516

lib/puppet/provider/elasticsearch_service_file/ruby.rb

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -63,9 +63,18 @@ def destroy?
6363
end
6464

6565
def flush
66-
opt_flag, opt_flags = Puppet_X::Elastic::EsVersioning.opt_flags(
67-
resource[:package_name], resource.catalog
68-
)
66+
begin
67+
opt_flag, opt_flags = Puppet_X::Elastic::EsVersioning.opt_flags(
68+
resource[:package_name], resource.catalog
69+
)
70+
rescue ElasticsearchPackageNotFoundError
71+
# If the Elasticsearch package is not present at all, we don't know what
72+
# version is present, so we just set these as empty values for the
73+
# template.
74+
opt_flag = ''
75+
opt_flags = []
76+
end
77+
6978
# This should only be present on systemd systems.
7079
opt_flags.delete('--quiet') unless resource[:name].include?('systemd')
7180

lib/puppet/type/elasticsearch_service_file.rb

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,15 @@ def insync?(is)
2929

3030
template = ERB.new(should, 0, '-')
3131
is == template.result(binding)
32+
rescue ElasticsearchPackageNotFoundError
33+
# This behavior is extremely confusing because of the fact that while
34+
# someone should be able to indicate that an instance should be absent,
35+
# if there is no service file to query via Puppet providers, it can't
36+
# determine this fact. If no package exists and thus `absent` has been
37+
# instructed, indicate that the template contents are correct, because
38+
# we don't really care what's in there anyway - the service file is for
39+
# an absent instance of Elasticsearch anyway.
40+
return true
3241
end
3342

3443
# Represent as a checksum, not the whole file

lib/puppet_x/elastic/es_versioning.rb

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
class ElasticsearchPackageNotFoundError < StandardError; end
2+
13
module Puppet_X
24
module Elastic
35
# Assists with discerning the locally installed version of Elasticsearch.
@@ -50,11 +52,16 @@ def self.min_version(ver, package_name, catalog)
5052

5153
# Fetch the package version for a locally installed package.
5254
def self.version(package_name, catalog)
53-
if (es_pkg = catalog.resource("Package[#{package_name}]"))
54-
es_pkg.provider.properties[:version] || es_pkg.provider.properties[:ensure]
55-
else
56-
raise Puppet::Error, "could not find `Package[#{package_name}]` resource"
55+
es_pkg = catalog.resource("Package[#{package_name}]")
56+
raise Puppet::Error, "could not find `Package[#{package_name}]` resource" unless es_pkg
57+
[
58+
es_pkg.provider.properties[:version],
59+
es_pkg.provider.properties[:ensure]
60+
].each do |property|
61+
return property if property.is_a? String
5762
end
63+
Puppet.warning("could not find valid version for `Package[#{package_name}]` resource")
64+
raise ElasticsearchPackageNotFoundError
5865
end
5966
end
6067
end

spec/helpers/acceptance/tests/removal_shared_examples.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,10 @@ class { 'elasticsearch': ensure => 'absent', oss => #{v[:oss]} }
1717
apply_manifest manifest, :catch_failures => true
1818
end
1919

20+
it 'is idempotent' do
21+
apply_manifest manifest, :catch_changes => true
22+
end
23+
2024
instances.each do |instance|
2125
describe file("/etc/elasticsearch/#{instance}") do
2226
it { should_not be_directory }

0 commit comments

Comments
 (0)