Use remove_warnings from puppet-keystone

Glance client is getting the same warnings as Keystone client,
hence puppet-glance should use the same hack as puppet-keystone
until providers will be refactored to use API calls instead.

See https://bugzilla.redhat.com/show_bug.cgi?id=1043725 for more details

Change-Id: I99e4308d0731307c019ad6cab8db5feee1b0ed73
This commit is contained in:
Martin Magr 2014-01-23 16:37:40 +01:00
parent 30fd048fc8
commit 9bc8d08681
1 changed files with 25 additions and 2 deletions

View File

@ -72,11 +72,11 @@ class Puppet::Provider::Glance < Puppet::Provider
def self.auth_glance(*args)
begin
g = glance_credentials
glance('-T', g['admin_tenant_name'], '-I', g['admin_user'], '-K', g['admin_password'], '-N', auth_endpoint, args)
remove_warnings(glance('-T', g['admin_tenant_name'], '-I', g['admin_user'], '-K', g['admin_password'], '-N', auth_endpoint, args))
rescue Exception => e
if (e.message =~ /\[Errno 111\] Connection refused/) or (e.message =~ /\(HTTP 400\)/) or (e.message =~ /HTTP Unable to establish connection/)
sleep 10
glance('-T', g['admin_tenant_name'], '-I', g['admin_user'], '-K', g['admin_password'], '-N', auth_endpoint, args)
remove_warnings(glance('-T', g['admin_tenant_name'], '-I', g['admin_user'], '-K', g['admin_password'], '-N', auth_endpoint, args))
else
raise(e)
end
@ -132,4 +132,27 @@ class Puppet::Provider::Glance < Puppet::Provider
return attrs
end
# Remove warning from the output. This is a temporary hack until
# things will be refactored to use the REST API
def self.remove_warnings(results)
found_header = false
in_warning = false
results.split("\n").collect do |line|
unless found_header
if line =~ /^\+[-\+]+\+$/
in_warning = false
found_header = true
line
elsif line =~ /^WARNING/ or line =~ /UserWarning/ or in_warning
# warnings can be multi line, we have to skip all of them
in_warning = true
nil
else
line
end
else
line
end
end.compact.join("\n")
end
end