Skip to content

Commit

Permalink
Fixes theforeman#1556, #11615 - Remove puppet rdoc support
Browse files Browse the repository at this point in the history
Puppet rdoc support has been broken for a long time. Removing it from
Foreman.
  • Loading branch information
tbrisker authored and dLobatog committed Nov 28, 2016
1 parent c0cd333 commit b1dad4c
Show file tree
Hide file tree
Showing 8 changed files with 4 additions and 175 deletions.
5 changes: 0 additions & 5 deletions app/assets/javascripts/application.js
Original file line number Diff line number Diff line change
Expand Up @@ -338,11 +338,6 @@ function ignore_subnet(item){
$(item).closest('.accordion-group').remove();
}

function show_rdoc(item){
var url = $(item).attr('data-url');
window.open(url);
}

// shows provisioning templates in a new window
$(function() {
$('[data-provisioning-template=true]').click(function(){
Expand Down
4 changes: 0 additions & 4 deletions app/helpers/puppetclasses_helper.rb
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
module PuppetclassesHelper
include PuppetclassesAndEnvironmentsHelper
include LookupKeysHelper
def rdoc_classes_path(environment, name)
klass = name.gsub('::', '/')
"puppet/rdoc/#{environment}/classes/#{klass}.html"
end

def overridden?(puppetclass)
puppetclass.class_params.present? && puppetclass.class_params.map(&:override).all?
Expand Down
86 changes: 0 additions & 86 deletions app/models/puppetclass.rb
Original file line number Diff line number Diff line change
Expand Up @@ -97,92 +97,6 @@ def hosts_count
.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
Expand Down
1 change: 0 additions & 1 deletion app/models/setting/puppet.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ def self.load_defaults
self.set('outofsync_interval', N_("Duration in minutes after the Puppet interval for servers to be classed as out of sync."), 5, N_('Out of sync interval')),
self.set('default_puppet_environment', N_("Foreman will default to this puppet environment if it cannot auto detect one"), "production", N_('Default Puppet environment'), nil, { :collection => Proc.new {Hash[Environment.all.map{|env| [env[:name], env[:name]]}]} }),
self.set('modulepath',N_("Foreman will set this as the default Puppet module path if it cannot auto detect one"), "/etc/puppet/modules", N_('Module path')),
self.set('document_root', N_("Document root where puppetdoc files should be created"), "#{Rails.root}/public/puppet/rdoc", N_('Document root')),
self.set('puppetrun', N_("Enable puppetrun support"), false, N_('Puppetrun')),
self.set('puppet_server', N_("Default Puppet server hostname"), "puppet", N_('Puppet server')),
self.set('Default_variables_Lookup_Path', N_("Foreman will evaluate host smart variables in this order by default"), ["fqdn", "hostgroup", "os", "domain"], N_('Default variables lookup path')),
Expand Down
10 changes: 4 additions & 6 deletions app/views/puppetclasses/index.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@
<thead>
<tr>
<th class="col-md-3"><%= sort :name, :as => s_("Puppetclass|Name") %></th>
<th class="col-md-3"><%= sort :environment, :as => _("Environments and documentation") %></th>
<th class="col-md-3"><%= sort :environment, :as => _("Environments") %></th>
<th class="col-md-2"><%= _('Host groups') %></th>
<th><%= _('Hosts') %></th>
<th class="col-md-1"><%= _('Hosts') %></th>
<th class="col-md-1"><%= _('Parameters') %></th>
<th class="col-md-1"><%= _('Variables') %></th>
<th class="col-md-1"><%= _("Actions") %></th>
Expand All @@ -19,10 +19,8 @@
<% for puppetclass in @puppetclasses %>
<tr>
<td class="ellipsis"><%=link_to_if_authorized puppetclass.name, hash_for_edit_puppetclass_path(:id => puppetclass).merge(:auth_object => puppetclass, :authorizer => authorizer) %></td>
<td class="">
<% puppetclass.environments.uniq.each do |environment| %>
<%= link_to_function environment, 'show_rdoc(this)', :'data-url' => rdoc_classes_path(environment, puppetclass.name) %>
<% end %>
<td class="ellipsis">
<%= puppetclass.environments.uniq.to_sentence %>
</td>
<td class=""><%= puppetclass.all_hostgroups(false).map {|hg| link_to_if_authorized trunc_with_tooltip(hg, 24), hash_for_edit_hostgroup_path(:id=>hg).merge(:auth_object => hg, :authorizer => @hostgroups_authorizer)}.to_sentence.html_safe %></td>
<td><%= link_to puppetclass.hosts_count, hosts_path(:search => "class = #{puppetclass.name}")%></td>
Expand Down
51 changes: 0 additions & 51 deletions extras/rdoc/rdoc_prepare_script.rb

This file was deleted.

17 changes: 0 additions & 17 deletions lib/tasks/puppet.rake
Original file line number Diff line number Diff line change
Expand Up @@ -6,23 +6,6 @@ require 'rake/clean'
require 'yaml'

namespace :puppet do
root = "/"
# Author: Paul Kelly ([email protected])
# Description: The tasks defined in this namespace populate a directory structure with rdocs for the
# clases defined in puppet.
namespace :rdoc do
desc "
Populates the rdoc tree with information about all the classes in your modules."
task :generate => [:environment, :prepare] do
Puppetclass.rdoc root
end
desc "
Optionally creates a copy of the current puppet modules and sanitizes it.
It should return the directory into which it has copied the cleaned modules"
task :prepare => :environment do
root = Puppetclass.prepare_rdoc root
end
end
namespace :migrate do
desc "Populates the host fields in Foreman based on your StoredConfig DB"
task :populate_hosts => :environment do
Expand Down
5 changes: 0 additions & 5 deletions test/fixtures/settings.yml
Original file line number Diff line number Diff line change
Expand Up @@ -50,11 +50,6 @@ attributes10:
category: Setting::Puppet
default: /etc/puppet/modules
description: "The Setting::Puppet default module path in case that Foreman can't auto detect it"
attributes11:
name: document_root
category: Setting::Puppet
default: /home/olevy/git/foreman/public/puppet/rdoc
description: Document root where puppetdoc files should be created
attributes12:
name: puppet_server
category: Setting::Puppet
Expand Down

0 comments on commit b1dad4c

Please sign in to comment.