Bug 1770075 - Snippet template may render incorrect result when non-default scope class is used to render the main template. [NEEDINFO]
Summary: Snippet template may render incorrect result when non-default scope class is ...
Keywords:
Status: VERIFIED
Alias: None
Product: Red Hat Satellite
Classification: Red Hat
Component: Provisioning Templates
Version: 6.5.0
Hardware: Unspecified
OS: Unspecified
medium
medium vote
Target Milestone: 6.11.0
Assignee: satellite6-bugs
QA Contact: Akhil Jha
URL:
Whiteboard:
Depends On:
Blocks:
TreeView+ depends on / blocked
 
Reported: 2019-11-08 04:39 UTC by Hao Chang Yu
Modified: 2022-06-23 14:31 UTC (History)
12 users (show)

Fixed In Version:
Doc Type: If docs needed, set a value
Doc Text:
Clone Of:
Environment:
Last Closed:
Target Upstream Version:
fperalta: needinfo? (hyu)
fperalta: needinfo? (satellite6-bugs)


Attachments (Terms of Use)


Links
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

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@redhat.com

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

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


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