Revision c3db9892
Added by Lukas Zapletal about 8 years ago
.rubocop_todo.yml | ||
---|---|---|
# Offense count: 49
|
||
# Configuration parameters: CountComments.
|
||
Metrics/ClassLength:
|
||
Max: 784
|
||
Max: 800
|
||
|
||
# Offense count: 134
|
||
Metrics/CyclomaticComplexity:
|
app/models/concerns/orchestration/tftp.rb | ||
---|---|---|
# work around for ensuring that people can use @host as well, as tftp templates were usually confusing.
|
||
@host = self.host
|
||
if build?
|
||
pxe_template = host.provisioning_template({:kind => host.operatingsystem.template_kind})
|
||
failure_missing_template unless pxe_template
|
||
pxe_render pxe_template
|
||
template = host.provisioning_template({:kind => host.operatingsystem.template_kind})
|
||
failure_missing_template unless template
|
||
template_name = template.name
|
||
else
|
||
if host.operatingsystem.template_kind == "PXEGrub"
|
||
pxe_render ProvisioningTemplate.find_by_name("PXEGrub default local boot")
|
||
template_name = "PXEGrub default local boot"
|
||
else
|
||
pxe_render ProvisioningTemplate.find_by_name("PXELinux default local boot")
|
||
template_name = "PXELinux default local boot"
|
||
end
|
||
template = ProvisioningTemplate.find_by_name(template_name)
|
||
end
|
||
unattended_render template, template_name
|
||
rescue => e
|
||
failure _("Failed to generate %{template_kind} template: %{e}") % { :template_kind => host.operatingsystem.template_kind, :e => e }, e
|
||
failure _("Failed to generate %{template_kind} template %{template_name}: %{e}") % { :template_kind => host.operatingsystem.template_kind, :template_name => template_name.nil? ? '' : template_name, :e => e }, e
|
||
end
|
||
|
||
protected
|
app/models/host/managed.rb | ||
---|---|---|
def diskLayout
|
||
@host = self
|
||
template = disk.blank? ? ptable.layout : disk
|
||
pxe_render(template.tr("\r", ''))
|
||
template_name = disk.blank? ? ptable.name : 'Custom disk layout'
|
||
unattended_render(template.tr("\r", ''), template_name)
|
||
end
|
||
|
||
# returns a configuration template (such as kickstart) to a given host
|
lib/foreman/renderer.rb | ||
---|---|---|
prefix + text.gsub(/\n/, "\n#{prefix}")
|
||
end
|
||
|
||
# accepts either template object or plain string
|
||
def unattended_render(template, template_name = nil)
|
||
content = template.respond_to?(:template) ? template.template : template
|
||
template_name ||= template.respond_to?(:name) ? template.name : 'Unnamed'
|
||
raise ::Foreman::Exception.new(N_("Template '%s' is either missing or has an invalid organization or location"), template_name) if template.nil?
|
||
content = template.respond_to?(:template) ? template.template : template
|
||
allowed_variables = allowed_variables_mapping(ALLOWED_VARIABLES)
|
||
allowed_variables[:template_name] = template_name
|
||
render_safe content, ALLOWED_HELPERS, allowed_variables
|
||
end
|
||
alias_method :pxe_render, :unattended_render
|
||
|
||
def pxe_render(template, template_name = nil)
|
||
::Foreman::Deprecation.deprecation_warning("1.14", "method pxe_render will be removed, use unattended_render instead")
|
||
unattended_render(template, template_name)
|
||
end
|
||
|
||
def unattended_render_to_temp_file(content, prefix = id.to_s, options = {})
|
||
file = ""
|
test/lib/foreman/renderer_test.rb | ||
---|---|---|
tmpl = render_safe("<% @host.interfaces.each do |int| -%><%= int.to_s -%><% end -%>", [], { :host => host })
|
||
assert_equal host.name, tmpl
|
||
end
|
||
|
||
test "#{renderer_name} should error out when template was not found" do
|
||
send "setup_#{renderer_name}"
|
||
ex = assert_raises Foreman::Exception do
|
||
unattended_render(nil)
|
||
end
|
||
assert_match(/is either missing or has an invalid organization or location/, ex.message)
|
||
end
|
||
end
|
||
|
||
test 'ActiveRecord::AssociationRelation jail test' do
|
test/unit/host_test.rb | ||
---|---|---|
|
||
test "custom_disk_partition_with_erb" do
|
||
h = FactoryGirl.create(:host)
|
||
h.disk = "<%= 1 + 1 %>"
|
||
h.disk = "<%= @template_name %>"
|
||
assert h.save
|
||
assert h.disk.present?
|
||
assert_equal "2", h.diskLayout
|
||
assert_equal "Custom disk layout", h.diskLayout
|
||
end
|
||
|
||
test "custom_disk_partition_with_ptable" do
|
||
h = FactoryGirl.create(:host, :managed)
|
||
h.disk = ''
|
||
h.ptable.stubs(:name).returns("some_name")
|
||
h.ptable.stubs(:layout).returns("<%= @template_name %>")
|
||
assert h.save
|
||
assert_equal "some_name", h.diskLayout
|
||
end
|
||
|
||
test "models are updated when host.model has no value" do
|
Also available in: Unified diff
Fixes #6539 - missing templates error is now descriptive