Bug 1770075 - Snippet template may render incorrect result when non-default scope class is used to render the main template.
Summary: Snippet template may render incorrect result when non-default scope class is ...
Alias: None
Product: Red Hat Satellite
Classification: Red Hat
Component: Provisioning Templates
Version: 6.5.0
Hardware: Unspecified
OS: Unspecified
Target Milestone: 6.11.0
Assignee: satellite6-bugs
QA Contact: Akhil Jha
Depends On:
TreeView+ depends on / blocked
Reported: 2019-11-08 04:39 UTC by Hao Chang Yu
Modified: 2023-09-15 01:28 UTC (History)
12 users (show)

Fixed In Version:
Doc Type: If docs needed, set a value
Doc Text:
Clone Of:
Last Closed: 2022-07-05 14:27:54 UTC
Target Upstream Version:

Attachments (Terms of Use)

System ID Private Priority Status Summary Last Updated
Foreman Issue Tracker 28221 0 High Closed Snippet template may render incorrect result when non-default scope class is used to render the main template 2021-07-28 17:35:18 UTC
Red Hat Product Errata RHSA-2022:5498 0 None None None 2022-07-05 14:28:06 UTC

Description Hao Chang Yu 2019-11-08 04:39:56 UTC
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: {})
    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)

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(':', '-')

  # 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 != ''
    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}")
      dns.each { |server|

  # optional repository for Atomic
  if @host.operatingsystem.name.match(/Atomic/i)

  if @host.operatingsystem.name.match(/Atomic/i) || host_param('kickstart_liveimg')
    options.push('inst.stage2=' + @host.operatingsystem.medium_uri(@host).to_s)

  ksoptions = options.join(' ')
  timeout = host_param('loader_timeout').to_i * 10
  timeout = 100 if timeout.nil? || timeout <= 0

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 %>

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 
MENU TITLE Booting into OS installer (ESC to stop)
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.usersys.redhat.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=:: nameserver=

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.

Comment 10 Bryan Kearney 2021-05-15 22:36:32 UTC
Upstream bug assigned to dmatoule

Comment 11 Bryan Kearney 2021-05-15 22:36:35 UTC
Upstream bug assigned to dmatoule

Comment 12 Bryan Kearney 2021-06-16 12:01:16 UTC
Moving this bug to POST for triage into Satellite since the upstream issue https://projects.theforeman.org/issues/28221 has been resolved.

Comment 14 Akhil Jha 2022-04-29 08:18:34 UTC
Satellite 6.11-18.0

Comment 17 errata-xmlrpc 2022-07-05 14:27:54 UTC
Since the problem described in this bug report should be
resolved in a recent advisory, it has been closed with a
resolution of ERRATA.

For information on the advisory (Moderate: Satellite 6.11 Release), and where to find the updated
files, follow the link below.

If the solution does not work for you, open a new bug report.


Comment 18 Red Hat Bugzilla 2023-09-15 01:28:52 UTC
The needinfo request[s] on this closed bug have been removed as they have been unresolved for 365 days

Note You need to log in before you can comment on or make changes to this bug.