Bug #28221
Snippet template may render incorrect result when non-default scope class is used to render the main template
Description
Description of problem:
The "ForemanBootdisk::Scope::FullHostBootdisk" scope class is not parsed into the snippet template which causes snippet to render with the default scope class("Foreman::Renderer::Scope::Provisioning").
In "/usr/share/foreman/lib/foreman/renderer/scope/macros/snippet_rendering.rb"
--------------------------------
def snippet(name, options = {}, variables: {})
<snip>
begin
snippet_variables = variables.merge(options[:variables] || {})
template.render(host: host, variables: snippet_variables, mode: mode) <==== missing scope class argument.
---------------------------------
In "/usr/share/foreman/app/models/template.rb". No scope class provided for "get_scope" method so "Foreman::Renderer::Scope::Provisioning" is used for snippet.
--------------------------------
def render(host: nil, params: {}, variables: {}, mode: Foreman::Renderer::REAL_MODE, template_input_values: {})
source = Foreman::Renderer.get_source(template: self, host: host)
scope = Foreman::Renderer.get_scope(host: host, params: params, variables: variables, mode: mode, template: self, source: source, template_input_values: template_input_values)
Foreman::Renderer.render(source, scope)
end
--------------------------------
Steps to Reproduce:
1. Clone the "Kickstart default PXELinux". Rename it to "Kickstart default PXELinux Custom" and set proper Locations and Orgs and include all Operating systems
2. Create a snippet called "Sub PXELinux Custom"
3. Edit the cloned template and Cut the following block and paste it to the snippet.
<% major = @host.operatingsystem.major.to_i mac = @host.provision_interface.mac # Tell Anaconda to perform network functions with boot interface # both current and legacy syntax provided options = ["network", "ksdevice=bootif", "ks.device=bootif"] if mac bootif = '00-' + mac.gsub(':', '-') options.push("BOOTIF=#{bootif}") end # Tell Anaconda what to pass off to kickstart server # both current and legacy syntax provided options.push("kssendmac", "ks.sendmac", "inst.ks.sendmac") # handle non-DHCP environments (e.g. bootdisk) subnet = @host.provision_interface.subnet unless subnet.dhcp_boot_mode? # static network configuration ip = @host.provision_interface.ip mask = subnet.mask gw = subnet.gateway dns = [subnet.dns_primary] if subnet.dns_secondary != '' dns.push(subnet.dns_secondary) end if (@host.operatingsystem.name.match(/Fedora/i) && major < 17) || major < 7 # old Anacoda found in Fedora 16 or RHEL 6 and older dns_servers = dns.join(',') options.push("ip=#{ip}", "netmask=#{mask}", "gateway=#{gw}", "dns=#{dns_servers}") else options.push("ip=#{ip}::#{gw}:#{mask}:::none") dns.each { |server| options.push("nameserver=#{server}") } end end # optional repository for Atomic if @host.operatingsystem.name.match(/Atomic/i) options.push("inst.repo=#{medium_uri}") end if @host.operatingsystem.name.match(/Atomic/i) || host_param('kickstart_liveimg') options.push('inst.stage2=' + @host.operatingsystem.medium_uri(@host).to_s) end ksoptions = options.join(' ') timeout = host_param('loader_timeout').to_i * 10 timeout = 100 if timeout.nil? || timeout <= 0 -%> DEFAULT menu MENU TITLE Booting into OS installer (ESC to stop) TIMEOUT <%= timeout %> ONTIMEOUT installer LABEL installer MENU LABEL <%= template_name %> KERNEL <%= @kernel %> APPEND initrd=<%= @initrd %> ks=<%= foreman_url('provision') %> <%= pxe_kernel_options %> <%= ksoptions %> IPAPPEND 2
4. Call the snippet in the cloned template by adding the following line.
<%= snippet "Sub PXELinux Custom" %>
5. Assign the "Kickstart default PXELinux Custom" template to a Operating system. For example RHEL 7.7.
6. Create a host and assign the RHEL 7.7 Operating system to it.
7. Go to the host page and click Book disk -> "Full host 'some hostname' image" to download the full bootdisk.
8. Mount the downloaded bootdisk and inspect contents. You will notice that the "initrd_img" and the "vmlinux" filename are mismatch between /boot directory can the isolinux.cfg.
- The filenames in isolinux.cfg are not converted to ISO9660 standard.
"art_x86_64_7_6_22_initrd_img" VS "red-hat-enterprise-linux-7-server-kickstart-x86_64-7-6-22-initrd.img"
"kstart_x86_64_7_6_22_vmlinuz" VS "red-hat-enterprise-linux-7-server-kickstart-x86_64-7-6-22-vmlinuz"
# tree . ├── boot │ ├── art_x86_64_7_6_22_initrd_img │ └── kstart_x86_64_7_6_22_vmlinuz ├── boot.cat ├── isolinux.bin └── isolinux.cfg # cat isolinux.cfg DEFAULT menu MENU TITLE Booting into OS installer (ESC to stop) TIMEOUT 100 ONTIMEOUT installer LABEL installer MENU LABEL Sub PXELinux Custom KERNEL boot/red-hat-enterprise-linux-7-server-kickstart-x86_64-7-6-22-vmlinuz APPEND initrd=boot/red-hat-enterprise-linux-7-server-kickstart-x86_64-7-6-22-initrd.img ks=http://hao-satellite64.example.com:8000/unattended/provision?token=47e41f2e-2c36-43b5-afe0-376a4bbfca45 network ksdevice=bootif ks.device=bootif BOOTIF=00-56-6f-04-50-00-31 kssendmac ks.sendmac inst.ks.sendmac ip=::<some ip>:255.255.255.0:::none nameserver=<some ip> IPAPPEND 2
Actual results:
"initrd_img" and the "vmlinux" filename are mismatch between /boot directory can the isolinux.cfg.
Expected results:
Filename must match and converted to meet ISO9660 standard.
Associated revisions
History
#1
Updated by tentator Red Hat over 1 year ago
- Difficulty set to trivial
- Priority changed from Normal to High
Not sure if this was triaged..?
#2
Updated by tentator Red Hat over 1 year ago
Any news on this one? Should be quite trivial to fix. Are there other customers impacted?
#3
Updated by The Foreman Bot about 1 year ago
- Assignee set to Dominik Matoulek
- Status changed from New to Ready For Testing
- Pull request https://github.com/theforeman/foreman/pull/8523 added
#4
Updated by Lukas Zapletal about 1 year ago
- Description updated (diff)
#5
Updated by The Foreman Bot 11 months ago
- Fixed in Releases 3.0.0 added
#6
Updated by The Foreman Bot 11 months ago
- Fixed in Releases deleted (
3.0.0)
#7
Updated by Dominik Matoulek 11 months ago
- Status changed from Ready For Testing to Closed
Applied in changeset foreman|5051e3744f3eb1c549d1c3a2bfd884bf2b5023b8.
#8
Updated by Tomer Brisker 11 months ago
- Fixed in Releases 3.0.0 added
Fixes #28221 - Adding passing of template scope for snippet rendering
In current implementation templates can be much complex by snippet.
Reusable pieces of template code that should be in the same scope like
their templates but they are not. This PR tries to solve that.