Fix entropy providers use of equo with locale

Previous attempt didn't work properly. This version uses the proper
`provider.has_command` api to specify the env vars which should be used.

Also catches the exit 1 thrown when `equo match --installed` doesn't
find anything, now that the wrapper script is no longer hiding the exit
code behind an explicit `exit 0`.
This commit is contained in:
2016-10-13 22:08:04 +01:00
parent 80644b6813
commit 53bbad2eb1

View File

@@ -9,9 +9,14 @@ Puppet::Type.type(:package).provide(:entropy, :parent => Puppet::Provider::Packa
has_feature :uninstallable has_feature :uninstallable
has_feature :upgradeable has_feature :upgradeable
commands({ has_command(:equo, "equo") do
:equo => 'equo', locale = Facter.value(:locale)
environment({
:LANG => locale,
:LC_ALL => locale,
:LANGUAHE => locale,
}) })
end
# Require the locale fact exist # Require the locale fact exist
confine :false => Facter.value(:locale).nil? confine :false => Facter.value(:locale).nil?
@@ -19,18 +24,12 @@ Puppet::Type.type(:package).provide(:entropy, :parent => Puppet::Provider::Packa
defaultfor :operatingsystem => :Sabayon defaultfor :operatingsystem => :Sabayon
def self.equo_with_locale(*args)
Puppet::Util.withenv :LANG => Facter.value(:locale) do
equo(args)
end
end
def self.instances def self.instances
result_format = /^(\S+)\/(\S+)-([\.\d]+(?:_?(?:a(?:lpha)?|b(?:eta)?|pre|rc|p)\d*)?(?:-r\d+)?)(?:#(\S+))?$/ result_format = /^(\S+)\/(\S+)-([\.\d]+(?:_?(?:a(?:lpha)?|b(?:eta)?|pre|rc|p)\d*)?(?:-r\d+)?)(?:#(\S+))?$/
result_fields = [:category, :name, :ensure] result_fields = [:category, :name, :ensure]
begin begin
search_output = equo_with_locale("query", "list", "installed", "--quiet", "--verbose").chomp search_output = equo("query", "list", "installed", "--quiet", "--verbose").chomp
packages = [] packages = []
search_output.each_line do |search_result| search_output.each_line do |search_result|
@@ -60,7 +59,7 @@ Puppet::Type.type(:package).provide(:entropy, :parent => Puppet::Provider::Packa
# We must install a specific version # We must install a specific version
name = "=#{name}-#{should}" name = "=#{name}-#{should}"
end end
equo_with_locale "install", name equo "install", name
end end
# The common package name format. # The common package name format.
@@ -73,7 +72,7 @@ Puppet::Type.type(:package).provide(:entropy, :parent => Puppet::Provider::Packa
end end
def uninstall def uninstall
equo_with_locale "remove", package_name equo "remove", package_name
end end
def update def update
@@ -81,12 +80,12 @@ Puppet::Type.type(:package).provide(:entropy, :parent => Puppet::Provider::Packa
end end
def query def query
result_format = /^(\S+)\/(\S+)-([\.\d]+(?:_(?:alpha|beta|pre|rc|p)\d+)?(?:-r\d+)?)(?:#(\S+))?$/ result_format = /^(\S+)\/(\S+)-([\.\d]+(?:_(?:alpha|beta|pre|rc|p)\d+)?(?:-r\d+)?)(?::[^#]+)?(?:#(\S+))?$/
result_fields = [:category, :name, :version_available] result_fields = [:category, :name, :version_available]
begin begin
# Look for an installed package from a known repository # Look for an installed package from a known repository
search_output = equo_with_locale("match", "--quiet", "--verbose", package_name).chomp search_output = equo("match", "--quiet", "--verbose", package_name).chomp
search_match = search_output.match(result_format) search_match = search_output.match(result_format)
if search_match if search_match
@@ -95,7 +94,9 @@ Puppet::Type.type(:package).provide(:entropy, :parent => Puppet::Provider::Packa
package[field] = value unless !value or value.empty? package[field] = value unless !value or value.empty?
end end
installed_output = equo_with_locale('match', '--quiet', '--verbose', '--installed', package_name).chomp
begin
installed_output = equo('match', '--quiet', '--verbose', '--installed', package_name).chomp
installed_match = installed_output.match(result_format) installed_match = installed_output.match(result_format)
if installed_match if installed_match
@@ -104,13 +105,16 @@ Puppet::Type.type(:package).provide(:entropy, :parent => Puppet::Provider::Packa
else else
package[:ensure] = :absent package[:ensure] = :absent
end end
rescue Puppet::ExecutionFailure
package[:ensure] = :absent
end
return package return package
else else
# List all installed packages and try and find if it's installed from outside a repository # List all installed packages and try and find if it's installed from outside a repository
# If so, assume the installed version is the latest available # If so, assume the installed version is the latest available
all_installed = equo_with_locale("query", "list", "installed", "--quiet", "--verbose").chomp all_installed = equo("query", "list", "installed", "--quiet", "--verbose").chomp
all_installed.split("\n").each do |installed_package| all_installed.split("\n").each do |installed_package|