From 29b873f37e5d12ddebe0f95594dc123b929a91f2 Mon Sep 17 00:00:00 2001 From: Javier Pena Date: Thu, 7 Sep 2017 12:38:10 +0200 Subject: [PATCH] Sanitize nova_manage output in provider nova-manage can output a warning message in some cases (see [1] for an example with the latest oslo.db), and that confuses the nova_manage provider. Since the command in a provider cannot separate stdout and stderr[2], we use a workaround with Puppet::Util::Execution.execute, and use that instead of the provider command in the nova_cells and nova_cell_v2 providers. [1] - https://logs.rdoproject.org/23/9323/2/experimental/gate-weirdo-dlrn-master-puppet-scenario001/Z6a290513d2904561a2adc60ddbfd7084/weirdo-project/puppet.txt.gz [2] - https://github.com/puppetlabs/puppet/blob/master/lib/puppet/util/execution.rb#L14-L16 Change-Id: I79f76592672d968b96338b3e0f6a86c9b7faeb93 (cherry picked from commit 682174b778ca5398536842f5a2e8094907fc43a1) --- lib/puppet/provider/nova.rb | 14 ++++++++++++++ lib/puppet/provider/nova_cell_v2/nova_manage.rb | 12 +++++------- lib/puppet/provider/nova_cells/nova_manage.rb | 17 ++++++++++------- 3 files changed, 29 insertions(+), 14 deletions(-) diff --git a/lib/puppet/provider/nova.rb b/lib/puppet/provider/nova.rb index 134df89cf..6484cc05b 100644 --- a/lib/puppet/provider/nova.rb +++ b/lib/puppet/provider/nova.rb @@ -38,6 +38,20 @@ class Puppet::Provider::Nova < Puppet::Provider::Openstack Puppet::Provider::Openstack.request(service, action, properties, @credentials) end + def self.nova_manage_request(*args) + # Not using the nova-manage command directly, + # so we can disable combining of stderr/stdout output. + Puppet::Util::Execution.execute("#{Puppet::Util.which('nova-manage')} #{args.join(' ')}", { + :failonfail => true, + :combine => false, + :custom_environment => {} + }) + end + + def nova_manage_request(*args) + self.class.nova_manage_request(args) + end + def self.conf_filename '/etc/nova/nova.conf' end diff --git a/lib/puppet/provider/nova_cell_v2/nova_manage.rb b/lib/puppet/provider/nova_cell_v2/nova_manage.rb index dbeecf7d2..56168036d 100644 --- a/lib/puppet/provider/nova_cell_v2/nova_manage.rb +++ b/lib/puppet/provider/nova_cell_v2/nova_manage.rb @@ -8,8 +8,6 @@ Puppet::Type.type(:nova_cell_v2).provide( desc "Manage nova cellv2 cells" - optional_commands :nova_manage => 'nova-manage' - mk_resource_methods def initialize(value={}) @@ -18,7 +16,7 @@ Puppet::Type.type(:nova_cell_v2).provide( end def self.instances - cells_list = nova_manage("cell_v2", "list_cells", "--verbose") + cells_list = nova_manage_request("cell_v2", "list_cells", "--verbose") cells_list.split("\n")[3..-2].collect do |cell| $name, $uuid, $transport_url, $database_connection = cell.split('|')[1..-1].map{ |x| x.strip} @@ -93,7 +91,7 @@ Puppet::Type.type(:nova_cell_v2).provide( optional_opts.push(opt).push(resource[param]) end end - cell_uuid = nova_manage('cell_v2', 'create_cell', + cell_uuid = nova_manage_request('cell_v2', 'create_cell', optional_opts, "--verbose" ) @property_hash = { @@ -119,7 +117,7 @@ Puppet::Type.type(:nova_cell_v2).provide( def flush @property_hash.update(@property_flush) if @property_flush[:ensure] == :absent - nova_manage("cell_v2", "delete_cell", "--cell_uuid", @property_hash[:uuid]) + nova_manage_request("cell_v2", "delete_cell", "--cell_uuid", @property_hash[:uuid]) elsif @property_flush[:transport_url] or @property_flush[:database_connection] opts = [] if not @property_flush[:transport_url] @@ -140,8 +138,8 @@ Puppet::Type.type(:nova_cell_v2).provide( end opts.push('--database_connection').push(@property_flush[:database_connection]) - nova_manage("cell_v2", "update_cell", "--cell_uuid", @property_hash[:uuid], opts) + nova_manage_request("cell_v2", "update_cell", "--cell_uuid", @property_hash[:uuid], opts) end @property_flush = {} end -end \ No newline at end of file +end diff --git a/lib/puppet/provider/nova_cells/nova_manage.rb b/lib/puppet/provider/nova_cells/nova_manage.rb index 76faf05a9..1ed085722 100644 --- a/lib/puppet/provider/nova_cells/nova_manage.rb +++ b/lib/puppet/provider/nova_cells/nova_manage.rb @@ -20,15 +20,18 @@ # nova_cells provider # -Puppet::Type.type(:nova_cells).provide(:nova_manage) do +require File.join(File.dirname(__FILE__), '..','..','..', 'puppet/provider/nova') + +Puppet::Type.type(:nova_cells).provide( + :nova_manage, + :parent => Puppet::Provider::Nova +) do desc "Manage nova cells" - optional_commands :nova_manage => 'nova-manage' - def self.instances begin - cells_list = nova_manage("cell", "list") + cells_list = nova_manage_request("cell", "list") rescue Exception => e if e.message =~ /No cells defined/ return [] @@ -63,14 +66,14 @@ Puppet::Type.type(:nova_cells).provide(:nova_manage) do end end - nova_manage('cell', 'create', + nova_manage_request('cell', 'create', optional_opts ) end def exists? begin - cells_list = nova_manage("cell", "list") + cells_list = nova_manage_request("cell", "list") return cells_list.split("\n")[1..-1].detect do |n| n =~ /^(\S+)\s+(#{resource[:cells].split('/').first})/ end @@ -81,7 +84,7 @@ Puppet::Type.type(:nova_cells).provide(:nova_manage) do def destroy - nova_manage("cell", "delete", resource[:name]) + nova_manage_request("cell", "delete", resource[:name]) end end