Project

General

Profile

« Previous | Next » 

Revision b1dad4cd

Added by Tomer Brisker over 7 years ago

Fixes #1556, #11615 - Remove puppet rdoc support

Puppet rdoc support has been broken for a long time. Removing it from
Foreman.

View differences:

app/models/puppetclass.rb
.count
end
# Populates the rdoc tree with information about all the classes in your modules.
# Firstly, we prepare the modules tree
# Secondly we run puppetdoc over the modulespath and manifestdir for all environments
# The results are written into document_root/puppet/rdoc/<env>/<class>"
def self.rdoc(root)
debug, verbose = false, false
relocated = root != "/" # This is true if the prepare phase copied the modules tree
# Retrieve an optional http server's DocumentRoot from the settings.yaml file, and prepare it for writing
doc_root = Pathname.new(Setting[:document_root])
doc_root.mkpath
unless doc_root.directory? && doc_root.writable?
puts "Unable to write html to #{doc_root}"
return false
end
validator = '<div id="validator-badges">'
# For each environment we write a puppetdoc tree
for env, path in Environment.puppetEnvs
# We may need to rewrite the modulepaths because they have been changed by the prepare step
modulepaths = relocated ? path.split(":").map{|p| root + p}.join(":") : path
# Identify and prepare the output directory
out = doc_root + env
out.rmtree if out.directory?
replacement = "<div id=\\\"validator-badges\\\"><small><a href=\\\"/puppet/rdoc/#{env}/\\\">[Browser]</a></small>"
# Create the documentation
puts "*********Proccessing environment #{env} *************"
cmd = "puppetdoc --output #{out} --modulepath #{modulepaths} -m rdoc"
puts cmd if Foreman.in_rake?
sh cmd do |ok, res|
if ok
# Add a link to the class browser
files = `find #{out} -exec grep -l 'validator-badges' {} \\; 2>/dev/null`.gsub(/\n/, " ")
if files.empty?
warn "No files to update with the browser link in #{out}. This is probably due to a previous error."
else
cmd = "ruby -p -i -e '$_.gsub!(/#{validator}/,\"#{replacement}\")' #{files}"
puts cmd if debug
sh cmd
end
# Relocate the paths for files and references if the manifests were relocated and sanitized
if relocated && (files = `find #{out} -exec grep -l '#{root}' {} \\;`.gsub(/\n/, " ")) != ""
puts "Rewriting..." if verbose
cmd = "ruby -p -i -e 'rex=%r{#{root}};$_.gsub!(rex,\"\")' #{files}"
puts cmd if debug
sh cmd
# Now relocate the files/* files to match the rewritten url
mv Dir.glob("#{out}/files/#{root}/*"), "#{out}/files", :verbose => verbose
end
else
logger.warn "Failed to process puppetdocs for #{out} while executing #{cmd}"
puts "Failed to process puppetdocs for #{out} while executing #{cmd}"
end
end
puts
end
end
# Optionally creates a copy of the current puppet modules and sanitizes it.
# If your 'live' manifests and modules can be parsed by puppetdoc
# then you do not need to do this step. (Unfortunately some sites have circular
# symlinks which have to be removed.)
# If the executable Rails,root/script/rdoc_prepare_script exists then it is run
# and passed a list of all directory paths in all environments.
# It should return the directory into which it has copied the cleaned modules"
def self.prepare_rdoc(root)
debug, verbose = false, false
prepare_script = Pathname.new(Rails.root) + "script/rdoc_prepare_script.rb"
if prepare_script.executable?
dirs = Environment.puppetEnvs.values.join(":").split(":").uniq.sort.join(" ")
puts "Running #{prepare_script} #{dirs}" if debug
location = `#{prepare_script} #{dirs}`
if $CHILD_STATUS == 0
root = location.chomp
puts "Relocated modules to #{root}" if verbose
end
else
puts "No executable #{prepare_script} found so using the uncopied module sources" if verbose
end
root
end
def self.search_by_host(key, operator, value)
conditions = sanitize_sql_for_conditions(["hosts.name #{operator} ?", value_to_sql(operator, value)])
direct = Puppetclass.joins(:hosts).where(conditions).pluck('puppetclasses.id').uniq

Also available in: Unified diff