Bug 386691 - Need unattended way to run sosreport
Need unattended way to run sosreport
Status: CLOSED ERRATA
Product: Red Hat Enterprise Linux 5
Classification: Red Hat
Component: sos (Show other bugs)
5.1
All Linux
low Severity low
: rc
: ---
Assigned To: Adam Stokes
: ZStream
: 429405 (view as bug list)
Depends On:
Blocks: 463257 494952 495060
  Show dependency treegraph
 
Reported: 2007-11-16 07:49 EST by Jay Brannen
Modified: 2012-08-21 14:25 EDT (History)
6 users (show)

See Also:
Fixed In Version:
Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of:
: 494952 (view as bug list)
Environment:
Last Closed: 2009-01-20 16:42:28 EST
Type: ---
Regression: ---
Mount Type: ---
Documentation: ---
CRM:
Verified Versions:
Category: ---
oVirt Team: ---
RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: ---


Attachments (Terms of Use)
Updated prework() to accept optional @name and @ticketnumber values for unattended execution. (1.62 KB, patch)
2008-07-03 00:49 EDT, Robert Jackson
no flags Details | Diff
Updates sosreport with the --name and --ticket-number options for unattended execution. (2.74 KB, patch)
2008-07-03 00:49 EDT, Robert Jackson
no flags Details | Diff
Properly sets default empty values for --name and --ticket-number. (2.74 KB, patch)
2008-07-03 01:14 EDT, Robert Jackson
no flags Details | Diff
Properly sets default empty values for --name and --ticket-number. (3.01 KB, patch)
2008-07-03 01:38 EDT, Robert Jackson
no flags Details | Diff
adds --name and --ticket-number to the man page. (711 bytes, patch)
2008-08-28 13:21 EDT, Robert Jackson
no flags Details | Diff

  None (edit)
Description Jay Brannen 2007-11-16 07:49:29 EST
Need unattended way to run sosreport.

sysreport could be run as "echo y | sysreport" to require no further prompting.
It would you useful for sosreport to provide something similar (maybe just
command line options for confirmation, name and case number).
Comment 2 Adam Stokes 2008-04-30 20:31:11 EDT
*** Bug 429405 has been marked as a duplicate of this bug. ***
Comment 3 Robert Jackson 2008-07-03 00:47:39 EDT
Attached are 2 patches which implement this functionality through the
commandline options --name and --ticket-number. Both of these options must be
present for an unattended execution to occur.

sosreport:

--- /usr/sbin/sosreport 2008-03-28 10:28:49.000000000 -0400             
+++ /usr/sbin/sosreport2        2008-07-03 00:46:25.000000000 -0400     
@@ -142,6 +142,12 @@                                                    
 __cmdParser__.add_option("--no-multithread", action="store_true", \    
                      dest="nomultithread", \                           
                      help="disable multi-threaded gathering mode (slower)",
default=False)
+__cmdParser__.add_option("--name", action="extend", \                         
           
+                    dest="name",type="string", \                              
           
+                    help="first initial and last name.")                      
           
+__cmdParser__.add_option("--ticket-number", action="extend", \                
           
+                    dest="ticketnumber", type="string", \                     
           
+                    help="ticket number.")                                    
           
                                                                               
           
 if sys.argv[0].endswith("sysreport"):
     try:
@@ -538,9 +544,12 @@
     if not len(loadedplugins):
         soslog.error(_("no valid plugins were enabled"))
         sys.exit(1)
-
-    try:
-        raw_input(_("""This utility will collect some detailed  information
about the
+
+    isUnattended = False
+    if len(__cmdLineOpts__.name) > 0 and len(__cmdLineOpts__.ticketnumber) > 0:
isUnattended = True
+    if not isUnattended:
+        try:
+            raw_input(_("""This utility will collect some detailed  information
about the
 hardware and  setup of your  Red Hat Enterprise Linux  system.
 The information is collected and an archive is  packaged under
 /tmp, which you can send to a support representative.
@@ -552,9 +561,9 @@

 Press ENTER to continue, or CTRL-C to quit.
 """))
-    except KeyboardInterrupt:
-        print
-        sys.exit(0)
+        except KeyboardInterrupt:
+            print
+            sys.exit(0)

     # Call the diagnose() method for each plugin
     tmpcount = 0
@@ -583,7 +592,10 @@
         print
         try:
            while True:
-              yorno = raw_input( _("Are you sure you would like to continue
(y/n) ? ") )
+              if not isUnattended:
+                 yorno = raw_input( _("Are you sure you would like to continue
(y/n) ? ") )
+             else:
+                 yorno = _("Y")
               if yorno == _("y") or yorno == _("Y"):
                  print
                  break
@@ -594,7 +606,7 @@
            print
            sys.exit(0)

-    policy.preWork()
+    policy.preWork(__cmdLineOpts__.name, __cmdLineOpts__.ticketnumber)

     # Call the setup() method for each plugin
     for plugname, plug in loadedplugins:


=================
policyredhat.py:

--- /usr/lib/python2.4/site-packages/sos/policyredhat.py        2008-07-03
00:36:27.000000000 -0400
+++ /usr/lib/python2.4/site-packages/sos/policyredhat.py2       2008-07-03
00:35:32.000000000 -0400
@@ -121,19 +121,25 @@
         name = "-".join(fields[:-3])
         return (name, version, release, arch)

-    def preWork(self):
+    def preWork(self, name="", ticket=""):
         # this method will be called before the gathering begins

         localname = commands.getoutput("/bin/uname -n").split(".")[0]

         try:
-            self.reportName = raw_input(_("Please enter your first initial and
last name [%s]: ") % localname)
-            self.reportName = re.sub(r"[^a-zA-Z.0-9]", "", self.reportName)
+            if len(name) == 0:
+               self.reportName = raw_input(_("Please enter your first initial
and last name [%s]: ") % localname)
+            else:
+               self.reportName = str(name)
+           self.reportName = re.sub(r"[^a-zA-Z.0-9]", "", self.reportName)
             if len(self.reportName) == 0:
                 self.reportName = localname

-            self.ticketNumber = raw_input(_("Please enter the case number that
you are generating this report for: "))
-            self.ticketNumber = re.sub(r"[^0-9]", "", self.ticketNumber)
+            if len(ticket) == 0:
+               self.ticketNumber = raw_input(_("Please enter the case number
that you are generating this report for: "))
+            else:
+               self.ticketNumber = str(ticket)
+           self.ticketNumber = re.sub(r"[^0-9]", "", self.ticketNumber)
             print
         except KeyboardInterrupt:
             print
Comment 4 Robert Jackson 2008-07-03 00:49:16 EDT
Created attachment 310878 [details]
Updated prework() to accept optional @name and @ticketnumber values for unattended execution.
Comment 5 Robert Jackson 2008-07-03 00:49:54 EDT
Created attachment 310879 [details]
Updates sosreport with the --name and --ticket-number options for unattended execution.
Comment 6 Robert Jackson 2008-07-03 01:11:58 EDT
Revised sosreport patch:
- Storing values properly now


--- /usr/sbin/sosreport 2008-03-28 10:28:49.000000000 -0400              
+++ /usr/sbin/sosreport2        2008-07-03 01:09:10.000000000 -0400      
@@ -142,6 +142,12 @@                                                     
 __cmdParser__.add_option("--no-multithread", action="store_true", \     
                      dest="nomultithread", \                            
                      help="disable multi-threaded gathering mode (slower)",
default=False)
+__cmdParser__.add_option("--name", action="store", \                          
           
+                    dest="name",type="string", \                              
           
+                    help="first initial and last name.", default="")          
           
+__cmdParser__.add_option("--ticket-number", action="store", \                 
           
+                    dest="ticketnumber", type="string", \                     
           
+                    help="ticket number.", default="")                        
           
                                                                               
           
 if sys.argv[0].endswith("sysreport"):                                         
           
     try:                                                                      
           
@@ -538,9 +544,12 @@                                                           
           
     if not len(loadedplugins):
         soslog.error(_("no valid plugins were enabled"))
         sys.exit(1)
-
-    try:
-        raw_input(_("""This utility will collect some detailed  information
about the
+
+    isUnattended = False
+    if len(__cmdLineOpts__.name) > 0 and len(__cmdLineOpts__.ticketnumber) > 0:
isUnattended = True
+    if not isUnattended:
+        try:
+            raw_input(_("""This utility will collect some detailed  information
about the
 hardware and  setup of your  Red Hat Enterprise Linux  system.
 The information is collected and an archive is  packaged under
 /tmp, which you can send to a support representative.
@@ -552,9 +561,9 @@

 Press ENTER to continue, or CTRL-C to quit.
 """))
-    except KeyboardInterrupt:
-        print
-        sys.exit(0)
+        except KeyboardInterrupt:
+            print
+            sys.exit(0)

     # Call the diagnose() method for each plugin
     tmpcount = 0
@@ -583,7 +592,10 @@
         print
         try:
            while True:
-              yorno = raw_input( _("Are you sure you would like to continue
(y/n) ? ") )
+              if not isUnattended:
+                 yorno = raw_input( _("Are you sure you would like to continue
(y/n) ? ") )
+             else:
+                 yorno = _("Y")
               if yorno == _("y") or yorno == _("Y"):
                  print
                  break
@@ -594,7 +606,10 @@
            print
            sys.exit(0)

-    policy.preWork()
+    if isUnattended:
+       policy.preWork(__cmdLineOpts__.name, __cmdLineOpts__.ticketnumber)
+    else:
+       policy.preWork()

     # Call the setup() method for each plugin
     for plugname, plug in loadedplugins:
Comment 7 Robert Jackson 2008-07-03 01:14:32 EDT
Created attachment 310880 [details]
Properly sets default empty values for --name and --ticket-number.

- Properly sets default empty values for --name and --ticket-number.
- Only attempts to pass the values to preWork() for unattended execution if
they are both present.
Comment 8 Robert Jackson 2008-07-03 01:38:57 EDT
Created attachment 310881 [details]
Properly sets default empty values for --name and --ticket-number.
Comment 9 RHEL Product and Program Management 2008-07-03 12:03:35 EDT
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 10 Adam Stokes 2008-07-03 21:49:38 EDT
rhel5 changeset for this patch :

https://fedorahosted.org/sos/changeset/508/branches/RHEL-5
Comment 12 Robert Jackson 2008-08-28 13:21:01 EDT
Created attachment 315268 [details]
adds --name and --ticket-number to the man page.
Comment 16 errata-xmlrpc 2009-01-20 16:42:28 EST
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-2009-0171.html

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