Dzahn has submitted this change and it was merged.

Change subject: wmf-reimage: fix puppet clean certificate and facts
......................................................................


wmf-reimage: fix puppet clean certificate and facts

Bug: T145544
Change-Id: I4e518c3a9833a773a46d7248b216a1722480455c
---
M .rubocop_todo.yml
D modules/puppetmaster/files/puppetstoredconfigclean.rb
M modules/puppetmaster/files/wmf-reimage
M modules/puppetmaster/manifests/scripts.pp
4 files changed, 5 insertions(+), 109 deletions(-)

Approvals:
  Dzahn: Looks good to me, approved
  jenkins-bot: Verified



diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml
index f71c886..ca1f7ec 100644
--- a/.rubocop_todo.yml
+++ b/.rubocop_todo.yml
@@ -10,7 +10,6 @@
 # Configuration parameters: AllowSafeAssignment.
 Lint/AssignmentInCondition:
   Exclude:
-    - 'modules/puppetmaster/files/puppetstoredconfigclean.rb'
     - 'modules/wmflib/lib/hiera/backend/nuyaml_backend.rb'
     - 'modules/wmflib/lib/hiera/backend/role_backend.rb'
     - 'modules/wmflib/lib/puppet/parser/functions/secret.rb'
@@ -40,7 +39,6 @@
     - 'modules/base/files/monitoring/check_puppetrun'
     - 'modules/ganeti/lib/facter/ganeti.rb'
     - 'modules/puppet_statsd/lib/puppet/reports/statsd.rb'
-    - 'modules/puppetmaster/files/puppetstoredconfigclean.rb'
     - 'modules/service/Rakefile'
     - 'modules/wmflib/lib/hiera/backend/nuyaml_backend.rb'
     - 'modules/wmflib/lib/puppet/parser/functions/validate_array_re.rb'
@@ -209,7 +207,6 @@
 Style/Not:
   Exclude:
     - 'modules/base/files/monitoring/check_puppetrun'
-    - 'modules/puppetmaster/files/puppetstoredconfigclean.rb'
     - 'modules/wmflib/lib/hiera/backend/proxy_backend.rb'
     - 'modules/wmflib/lib/puppet/parser/functions/role.rb'
     - 'utils/hiera_lookup'
@@ -366,7 +363,6 @@
 # Cop supports --auto-correct.
 Style/SpecialGlobalVars:
   Exclude:
-    - 'modules/puppetmaster/files/puppetstoredconfigclean.rb'
     - 'utils/expanderb.rb'
 
 # Offense count: 188
diff --git a/modules/puppetmaster/files/puppetstoredconfigclean.rb 
b/modules/puppetmaster/files/puppetstoredconfigclean.rb
deleted file mode 100644
index f5e2753..0000000
--- a/modules/puppetmaster/files/puppetstoredconfigclean.rb
+++ /dev/null
@@ -1,91 +0,0 @@
-#!/usr/bin/env ruby
-
-# Script to clean up stored configs for (a) given host(s)
-#
-# Credits:
-# Script was taken from 
http://reductivelabs.com/trac/puppet/attachment/wiki/UsingStoredConfiguration/kill_node_in_storedconfigs_db.rb
 (link no longer valid),
-# which haven been initially posted by James Turnbull
-# duritong adapted and improved the script a bit.
-
-require 'getoptlong'
-config = '/etc/puppet/puppet.conf'
-
-def printusage(error_code)
-  puts "Usage: #{$0} [ list of hostnames as stored in hosts table ]"
-  puts "\n Options:"
-  puts "--config <puppet config file>"
-  exit(error_code)
-end
-
-
-      opts = GetoptLong.new(
-
-    [ "--config",     "-c",   GetoptLong::REQUIRED_ARGUMENT ],
-    [ "--help",        "-h",   GetoptLong::NO_ARGUMENT ],
-    [ "--usage",       "-u",   GetoptLong::NO_ARGUMENT ],
-
-    [ "--version",     "-v",   GetoptLong::NO_ARGUMENT ]
-)
-
-begin
-  opts.each do |opt, arg|
-    case opt
-    when "--config"
-      config = arg
-
-    when "--help"
-      printusage(0)
-
-    when "--usage"
-      printusage(0)
-
-    when "--version"
-      puts "#{Puppet.version}"
-      exit
-    end
-  end
-rescue GetoptLong::InvalidOption => detail
-  $stderr.puts "Try '#{$0} --help'"
-  exit(1)
-end
-
-printusage(1) unless ARGV.size > 0
-
-require 'puppet/rails'
-Puppet[:config] = config
-Puppet.parse_config
-pm_conf = Puppet.settings.instance_variable_get(:@values)[:master]
-
-adapter = pm_conf[:dbadapter]
-args = {:adapter => adapter, :log_level => pm_conf[:rails_loglevel]}
-
-case adapter
-when "sqlite3"
-  args[:dbfile] = pm_conf[:dblocation]
-when "mysql", "postgresql"
-  args[:host]     = pm_conf[:dbserver] unless pm_conf[:dbserver].to_s.empty?
-  args[:username] = pm_conf[:dbuser] unless pm_conf[:dbuser].to_s.empty?
-  args[:password] = pm_conf[:dbpassword] unless 
pm_conf[:dbpassword].to_s.empty?
-  args[:database] = pm_conf[:dbname] unless pm_conf[:dbname].to_s.empty?
-  args[:port]     = pm_conf[:dbport] unless pm_conf[:dbport].to_s.empty?
-  socket          = pm_conf[:dbsocket]
-  args[:socket]   = socket unless socket.to_s.empty?
-else
-  raise ArgumentError, "Invalid db adapter #{adapter}"
-end
-
-args[:database] = "puppet" unless not args[:database].to_s.empty?
-
-ActiveRecord::Base.establish_connection(args)
-
-ARGV.each { |hostname|
-  if @host = Puppet::Rails::Host.find_by_name(hostname.strip)
-    print "Killing #{hostname}..."
-    $stdout.flush
-    @host.destroy
-    puts "done."
-  else
-    puts "Can't find host #{hostname}."
-  end
-}
-exit 0
diff --git a/modules/puppetmaster/files/wmf-reimage 
b/modules/puppetmaster/files/wmf-reimage
index 25ba300..b8e0f3e 100755
--- a/modules/puppetmaster/files/wmf-reimage
+++ b/modules/puppetmaster/files/wmf-reimage
@@ -15,16 +15,14 @@
 
 function clean_puppet {
     nodename=${1}
-    log "cleaning puppet certificate for ${nodename}"
-    puppet cert clean ${nodename}
+    log "cleaning puppet facts and certificate for ${nodename}"
+    puppet node clean ${nodename} 2> /dev/null
     # An additional, paranoid check.
-    if puppet cert list --all | fgrep -q ${nodename}; then
+    if puppet cert list --all 2> /dev/null | fgrep -q ${nodename}; then
         log "unable to clean puppet cert, please check manually"
         log "Maybe you need to use the -n switch?"
         exit 1
     fi
-    log "cleaning puppet facts cache for ${nodename}"
-    /usr/local/sbin/puppetstoredconfigclean.rb ${nodename}
 }
 
 function __salt_key {
@@ -60,7 +58,7 @@
     force_yes=${2}
     log "Seeking the Puppet certificate to sign"
     while true; do
-        res=$(puppet cert list | sed -ne "s/\"$nodename\"//p")
+        res=$(puppet cert list 2> /dev/null | sed -ne "s/\"$nodename\"//p")
         if [ "x${res}" == "x" ]; then
             #log "cert not found, sleeping for ${SLEEPTIME}s"
             echo -n "."
@@ -80,7 +78,7 @@
                 exit 1
             fi
         fi
-        puppet cert -s ${nodename}
+        puppet cert -s ${nodename} 2> /dev/null
         break
     done
 }
diff --git a/modules/puppetmaster/manifests/scripts.pp 
b/modules/puppetmaster/manifests/scripts.pp
index 1f9d073..243bff7 100644
--- a/modules/puppetmaster/manifests/scripts.pp
+++ b/modules/puppetmaster/manifests/scripts.pp
@@ -13,13 +13,6 @@
     $keep_reports_minutes = 960, # 16 hours
 ) {
 
-    file {'/usr/local/sbin/puppetstoredconfigclean.rb':
-        ensure => 'present',
-        owner  => 'root',
-        group  => 'root',
-        mode   => '0555',
-        source => 'puppet:///modules/puppetmaster/puppetstoredconfigclean.rb'
-    }
     file{'/usr/local/bin/puppet-merge':
         ensure => present,
         owner  => 'root',

-- 
To view, visit https://gerrit.wikimedia.org/r/310614
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: merged
Gerrit-Change-Id: I4e518c3a9833a773a46d7248b216a1722480455c
Gerrit-PatchSet: 4
Gerrit-Project: operations/puppet
Gerrit-Branch: production
Gerrit-Owner: Volans <rcocci...@wikimedia.org>
Gerrit-Reviewer: Alexandros Kosiaris <akosia...@wikimedia.org>
Gerrit-Reviewer: Dzahn <dz...@wikimedia.org>
Gerrit-Reviewer: Giuseppe Lavagetto <glavage...@wikimedia.org>
Gerrit-Reviewer: jenkins-bot <>

_______________________________________________
MediaWiki-commits mailing list
MediaWiki-commits@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to