Bug 568861

Summary: [RHEL 5.5 Beta] anaconda crashes with full path specified in %post --log parameter
Product: Red Hat Enterprise Linux 5 Reporter: Jeff Bastian <jbastian>
Component: anacondaAssignee: David Cantrell <dcantrell>
Status: CLOSED ERRATA QA Contact: Release Test Team <release-test-team-automation>
Severity: high Docs Contact:
Priority: high    
Version: 5.5CC: atodorov, james.leddy, pbokoc, rlandman, rlerch, tao
Target Milestone: rcKeywords: Regression
Target Release: ---   
Hardware: All   
OS: Linux   
Whiteboard:
Fixed In Version: anaconda-11.1.2.213-1 Doc Type: Bug Fix
Doc Text:
Prior to Red Hat Enterprise Linux 5.5, the --log option in anaconda was not aware of whether %pre and %post scripts in kickstart files were running in a chroot environment or not. Therefore, kickstart files had to provide absolute paths to log files. Improvements to anaconda in Red Hat Enterprise Linux 5.5 made the --log option aware of chroot environments. Consequently, if unmodified kickstart files from Red Hat Enterprise Linux 5.4 were used to install Red Hat Enterprise Linux 5.5, anaconda sometimes crashed and reported that the directory did not exist. The --log option is now further modified to accept either absolute or relative paths. The presence of absolute paths does not prevent the use of kickstart files created for earlier versions of Red Hat Enterprise Linux 5.
Story Points: ---
Clone Of:
: 597279 (view as bug list) Environment:
Last Closed: 2011-01-13 21:54:28 UTC Type: ---
Regression: --- Mount Type: ---
Documentation: --- CRM:
Verified Versions: Category: ---
oVirt Team: --- RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: --- Target Upstream Version:
Embargoed:
Bug Depends On:    
Bug Blocks: 540752, 597279    
Attachments:
Description Flags
path to strip '/mnt/sysimage' none

Description Jeff Bastian 2010-02-26 18:54:54 UTC
Description of problem:
With RHEL 5.4 and earlier, to save the output of a %post script in a log file, the kickstart file would specify the full path from outside the chroot jail, for example:
   %post --log=/mnt/sysimage/root/ks-post.log

This causes RHEL 5.5 Beta to crash with the error
IOError: [Errno 2] No such file or directory: '/mnt/sysimage//mnt/sysimage/root/
install.logs/install.post.gslog'

This is due to the changes from bug 510636 comment 8.  The new method is one of
   %post --log=/root/ks-post.log
   %post --nochroot --log=/mnt/sysimage/root/ks-post.log

This breaks kickstart files for RHEL 5.0 through 5.4.

Version-Release number of selected component (if applicable):
anaconda-11.1.2.202-4

How reproducible:
every time

Steps to Reproduce:
1. install RHEL 5.5 Beta with a kickstart file that contains
      %post --log=/mnt/sysimage/root/ks-post.log
      echo "Running post script"
  
Actual results:
anaconda crashes

Expected results:
anaconda gracefully handles the problem

Additional info:
http://git.fedoraproject.org/git/?p=anaconda.git;a=commitdiff;h=17149c7b698132d567f84d81be5f377bfbf04b3b;hp=ee53c0fef1977811ad30d5f8cab83ba3afdd1a2e

Comment 1 Jeff Bastian 2010-02-26 18:57:54 UTC
Full anaconda traceback:

Traceback (most recent call first):
 File "/usr/lib/anaconda/iutil.py", line 45, in execWithRedirect
   stdout = open(stdout, "w")
 File "/usr/lib/anaconda/kickstart.py", line 75, in run
   root = scriptRoot)
 File "/usr/lib/anaconda/kickstart.py", line 901, in <lambda>
   map (lambda s: s.run(anaconda.rootPath, serial, anaconda.intf), postScripts)
 File "/usr/lib/anaconda/kickstart.py", line 901, in postAction
   map (lambda s: s.run(anaconda.rootPath, serial, anaconda.intf), postScripts)
 File "/usr/lib/anaconda/packages.py", line 44, in doPostAction
   anaconda.id.instClass.postAction(anaconda, flags.serial)
 File "/usr/lib/anaconda/dispatch.py", line 204, in moveStep
   rc = stepFunc(self.anaconda)
 File "/usr/lib/anaconda/dispatch.py", line 127, in gotoNext
   self.moveStep()
 File "/usr/lib/anaconda/cmdline.py", line 146, in run
   anaconda.dispatch.gotoNext()
 File "/usr/bin/anaconda", line 974, in ?
   anaconda.intf.run(anaconda)
IOError: [Errno 2] No such file or directory: '/mnt/sysimage//mnt/sysimage/root/
ks-post.log'

Local variables in innermost frame:
searchPath: 0
stdout: /mnt/sysimage//mnt/sysimage/root/ks-post.log
stdin: 0
argv: ['/tmp/ks-script-42QHgs']
chroot: <function chroot at 0x1fbcc0c8>
command: /bin/sh
stderr: /mnt/sysimage//mnt/sysimage/root/ks-post.log
root: /mnt/sysimage

Comment 2 Jeff Bastian 2010-02-26 19:04:51 UTC
Created attachment 396631 [details]
path to strip '/mnt/sysimage'

One possible method to make anaconda gracefully handle kickstart files with /mnt/sysimage in the path is to strip it from the path if it's there.  The attached patch does this.

Of course, this could introduce a new bug if someone intentionally wants a /mnt/sysimage within the /mnt/sysimage chroot jail.  That is, /mnt/sysimage/mnt/sysimage is the path from outside the jail.

Comment 3 Chris Lumens 2010-02-26 19:16:32 UTC
> With RHEL 5.4 and earlier, to save the output of a %post script in a log file,
> the kickstart file would specify the full path from outside the chroot jail,
> for example:
>    %post --log=/mnt/sysimage/root/ks-post.log

I'd argue that this was broken behavior in 5.4 and earlier - logs should take the chroot into account just like everything else about kickstart scripts.

> This causes RHEL 5.5 Beta to crash with the error
> IOError: [Errno 2] No such file or directory:
> '/mnt/sysimage//mnt/sysimage/root/
> install.logs/install.post.gslog'

However, this is bad.  We should definitely be handling the case where the containing directory does not first exist.  In fact the patch was intended to do that, except that I used basename instead of dirname at kickstart.py:65.

Comment 6 Issue Tracker 2010-02-26 19:43:48 UTC
Event posted on 02-26-2010 02:40pm EST by jleddy

Hi Jeff,

I meant to comment on this bug earlier, but lost track of time. I don't
disagree that the 5.4 behavior was a bug, but it wasn't documented as
such. The impressionis that using /mnt/sysimage as documented, and that
there isn't any documenting to address this change. 

My other concern is that I initially thought the directory was not
created, but if you look at the code there is clearly the os.makedirs
call. How is it possible that this is throwing "No such file or
directory"?


This event sent from IssueTracker by jleddy 
 issue 566533

Comment 7 Jeff Bastian 2010-02-26 19:57:03 UTC
(copying response from issue tracker)

(In reply to comment #6)
> ...there is clearly the os.makedirs call. How is it possible that this is
> throwing "No such file or directory"?

This is what Chris mentioned in comment 3 about using basename instead of dirname:
 65             d = os.path.basename(messages)
 66             if not os.path.exists(d):
 67                 os.makedirs(d)

basename returns the filename, not the directories, so it was essentially running os.makedirs("ks-post.log")

Comment 9 Jeff Bastian 2010-02-26 20:14:04 UTC
Technical note added. If any revisions are required, please edit the "Technical Notes" field
accordingly. All revisions will be proofread by the Engineering Content Services team.

New Contents:
Cause
=====
In Red Hat Enterprise Linux 5.5, anaconda was improved to provide better logging of errors while running %pre and %post scripts in kickstart files.  As part of this improvement, the --log option is now aware if the %post script is running in a chroot environment or not.

Consequence
===========
The full path to the log file needs to take into account if the script is running in a chroot environment.  These are equivalent:
   %post --log=/root/ks-post.log
   %post --nochroot --log=/mnt/sysimage/root/ks-post.log

Change
======
In RHEL 5.4 and earlier, the --log option always required the path to contain /mnt/sysimage for the logs to be saved on the system.  In RHEL 5.5, you should only specify /mnt/sysimage if using the --nochroot option also.

Result
======
If unmodified kickstart files from RHEL 5.4 are used to install RHEL 5.5, the log files will be saved in an unexpected location.  For example, if the kickstart file contains
   %post --nochroot --log=/mnt/sysimage/root/ks-post.log
then the ks-post.log will be found in /mnt/sysimage/root, not /root, after installation is complete.

Comment 10 James M. Leddy 2010-02-26 20:33:38 UTC
(In reply to comment #7)
> basename returns the filename, not the directories, so it was essentially
> running os.makedirs("ks-post.log")    

Ah this makes sense. With this fixed anyone should be able to install in any case. It was the crashing Anaconda for using '/mnt/sysimage' that causes a lot of hurt.

Comment 14 Jeff Bastian 2010-02-26 22:23:54 UTC
Technical note updated. If any revisions are required, please edit the "Technical Notes" field
accordingly. All revisions will be proofread by the Engineering Content Services team.

Diffed Contents:
@@ -14,6 +14,4 @@
 
 Result
 ======
-If unmodified kickstart files from RHEL 5.4 are used to install RHEL 5.5, the log files will be saved in an unexpected location.  For example, if the kickstart file contains
+If unmodified kickstart files from RHEL 5.4 are used to install RHEL 5.5, anaconda may crash and complain that the directory does not exist.  This is a known issue and may be fixed in a future update of RHEL.-   %post --nochroot --log=/mnt/sysimage/root/ks-post.log
-then the ks-post.log will be found in /mnt/sysimage/root, not /root, after installation is complete.

Comment 18 Ludek Smid 2010-03-11 12:17:01 UTC
Since it is too late to address this issue in RHEL 5.5, it has been proposed for RHEL 5.6.  Contact your support representative if you need to escalate this issue.

Comment 20 Ryan Lerch 2010-03-28 22:25:35 UTC
Technical note updated. If any revisions are required, please edit the "Technical Notes" field
accordingly. All revisions will be proofread by the Engineering Content Services team.

Diffed Contents:
@@ -1,17 +1 @@
-Cause
+If unmodified kickstart files from Red Hat Enterprise Linux 5.4 are used to install Red Hat Enterprise Linux 5.5, anaconda may crash and complain that the directory required to save the log files does not exist.(BZ#568861)-=====
-In Red Hat Enterprise Linux 5.5, anaconda was improved to provide better logging of errors while running %pre and %post scripts in kickstart files.  As part of this improvement, the --log option is now aware if the %post script is running in a chroot environment or not.
-
-Consequence
-===========
-The full path to the log file needs to take into account if the script is running in a chroot environment.  These are equivalent:
-   %post --log=/root/ks-post.log
-   %post --nochroot --log=/mnt/sysimage/root/ks-post.log
-
-Change
-======
-In RHEL 5.4 and earlier, the --log option always required the path to contain /mnt/sysimage for the logs to be saved on the system.  In RHEL 5.5, you should only specify /mnt/sysimage if using the --nochroot option also.
-
-Result
-======
-If unmodified kickstart files from RHEL 5.4 are used to install RHEL 5.5, anaconda may crash and complain that the directory does not exist.  This is a known issue and may be fixed in a future update of RHEL.

Comment 21 Chris Lumens 2010-06-02 20:12:43 UTC
David - this is similar to bug 597279 which you just sent a patch off for.

Comment 22 RHEL Program Management 2010-06-04 15:58:42 UTC
This request was evaluated by Red Hat Product Management for inclusion in a Red
Hat Enterprise Linux maintenance release.  Product Management has requested
further review of this request by Red Hat Engineering, for potential
inclusion in a Red Hat Enterprise Linux Update release for currently deployed
products.  This request is not yet committed for inclusion in an Update
release.

Comment 23 David Cantrell 2010-08-18 19:43:51 UTC
Deleted Technical Notes Contents.

Old Contents:
If unmodified kickstart files from Red Hat Enterprise Linux 5.4 are used to install Red Hat Enterprise Linux 5.5, anaconda may crash and complain that the directory required to save the log files does not exist.(BZ#568861)

Comment 26 Ruediger Landmann 2011-01-12 05:32:13 UTC
    Technical note added. If any revisions are required, please edit the "Technical Notes" field
    accordingly. All revisions will be proofread by the Engineering Content Services team.
    
    New Contents:
Prior to Red Hat Enterprise Linux 5.5, the --log option in anaconda was 
not aware of whether %pre and %post scripts in  kickstart files were 
running in a chroot environment or not. Therefore, kickstart files had to
provide absolute paths to log files. Improvements to anaconda in Red Hat 
Enterprise Linux 5.5 made the --log option aware of chroot environments. 
Consequently, if unmodified kickstart files from Red Hat Enterprise Linux 
5.4 were used to install Red Hat Enterprise Linux 5.5, anaconda sometimes 
crashed and reported that the directory did not exist. The --log option 
is now further modified to accept either absolute or relative paths. The
presence of absolute paths does not prevent the use of kickstart files 
created for earlier versions of Red Hat Enterprise Linux 5.

Comment 28 errata-xmlrpc 2011-01-13 21:54:28 UTC
An advisory has been issued which should help the problem
described in this bug report. This report is therefore being
closed with a resolution of ERRATA. For more information
on therefore solution and/or where to find the updated files,
please follow the link below. You may reopen this bug report
if the solution does not work for you.

http://rhn.redhat.com/errata/RHBA-2011-0030.html