Bug 1770075

Summary: Snippet template may render incorrect result when non-default scope class is used to render the main template.
Product: Red Hat Satellite Reporter: Hao Chang Yu <hyu>
Component: Provisioning TemplatesAssignee: satellite6-bugs <satellite6-bugs>
Status: CLOSED ERRATA QA Contact: Akhil Jha <akjha>
Severity: medium Docs Contact:
Priority: medium    
Version: 6.5.0CC: ahumbe, akjha, bkearney, christoph.kieser, fperalta, ktordeur, lzap, mhulan, pcreech, rbobek, satellite6-bugs, saydas
Target Milestone: 6.11.0Keywords: EasyFix, Improvement
Target Release: Unused   
Hardware: Unspecified   
OS: Unspecified   
Whiteboard:
Fixed In Version: Doc Type: If docs needed, set a value
Doc Text:
Story Points: ---
Clone Of: Environment:
Last Closed: 2022-07-05 14:27:54 UTC Type: Bug
Regression: --- Mount Type: ---
Documentation: --- CRM:
Verified Versions: Category: ---
oVirt Team: --- RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: --- Target Upstream Version:
Embargoed:

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: {})
<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.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=::10.71.133.25:255.255.255.0:::none nameserver=10.71.133.25
  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.

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
Verified
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.

https://access.redhat.com/errata/RHSA-2022:5498

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