[Piuparts-commits] rev 167 - in people/lucas/piuparts-report: . debian

Lucas Nussbaum lucas at alioth.debian.org
Tue Aug 19 12:29:13 UTC 2008


Author: lucas
Date: 2008-08-19 12:29:13 +0000 (Tue, 19 Aug 2008)
New Revision: 167

Modified:
   people/lucas/piuparts-report/debian/changelog
   people/lucas/piuparts-report/piuparts.py
Log:
applied the report patch to trunk at r166

Modified: people/lucas/piuparts-report/debian/changelog
===================================================================
--- people/lucas/piuparts-report/debian/changelog	2008-08-19 12:26:20 UTC (rev 166)
+++ people/lucas/piuparts-report/debian/changelog	2008-08-19 12:29:13 UTC (rev 167)
@@ -7,6 +7,13 @@
   * Replace all references to sarge and etch with etch and lenny.
   * Update README to reflect that piuparts runs fine in etch. 
 
+  [ Tobias Grimm ]
+  * Added report-switch, which lets piuparts run in "report mode"
+    where it tries to run a many tests and checks as possible
+    without failing immediately. A summary of the issues found
+    by piuparts will be written to a report file. 
+    (Closes: #458920, #458921)
+
  -- Holger Levsen <holger at debian.org>  Tue, 13 May 2008 11:31:07 +0200
 
 piuparts (0.31) unstable; urgency=low

Modified: people/lucas/piuparts-report/piuparts.py
===================================================================
--- people/lucas/piuparts-report/piuparts.py	2008-08-19 12:26:20 UTC (rev 166)
+++ people/lucas/piuparts-report/piuparts.py	2008-08-19 12:29:13 UTC (rev 167)
@@ -313,11 +313,14 @@
         if i in on_panic_hooks:
             on_panic_hooks[i]()
     sys.exit(1)
-    
 
-def indent_string(str):
+def check_failed():
+    if not settings.report_file:
+        panic()
+
+def indent_string(str, indent="  ", level=1):
     """Indent all lines in a string with two spaces and return result."""
-    return "\n".join(["  " + line for line in str.split("\n")])
+    return "\n".join([indent * level + line for line in str.split("\n")])
 
 
 safechars = ("abcdefghijklmnopqrstuvwxyz" +
@@ -684,7 +687,7 @@
 		
     def list_installed_files (self, pre_info, post_info):
         """List the new files installed, removed and modified between two dir trees.
-        Actually, it is a nice output of the funcion diff_meta_dat."""
+        Actually, it is a nice output of the function diff_meta_data."""
         (new, removed, modified) = diff_meta_data(pre_info, post_info)
         file_owners = self.get_files_owned_by_packages()
 
@@ -853,7 +856,10 @@
         if count > 0:
             logging.error("Processes are running inside chroot:\n%s" % 
                           indent_string(output))
-            panic()
+	    report.set('running-processes', 'FAIL')
+            check_failed()
+	else:
+	    report.set('running-processes', 'OK')
 
     def mount_proc(self):
         """Mount /proc inside chroot."""
@@ -895,9 +901,13 @@
         if broken:
             logging.error("Broken symlinks:\n%s" % 
                           indent_string("\n".join(broken)))
-	    panic()
+	    report.set('broken-symlink', 'FAIL')
+            for broken_link in broken:
+                report.set_many('broken-symlink-list', broken_link)
+            check_failed()
         else:
             logging.debug("No broken symlinks as far as we can find.")
+	    report.set('broken-symlink',  'OK')
 	    
     def check_if_cronfiles(self, packages):
         """Check if the packages have cron files under /etc/cron.d and in case positive, 
@@ -1201,8 +1211,10 @@
             for l in f:
                 logging.error("Broken symlink: " + l)
                 broken = True
-            if broken: panic()
-            logging.debug("No broken symlinks found.")
+            if broken:
+                check_failed()
+            else:
+                logging.debug("No broken symlinks found.")
         finally:
             os.remove(tf)
 
@@ -1210,6 +1222,38 @@
     def mount_proc(self): pass
     def unmount_proc(self): pass
 
+class PiupartsTest:
+    def __init__(self, name):
+	self.name = name
+	self.actions = {} # mapping from type of thing to success or not
+    def add_action(self, test_ran, result):
+	assert test_ran not in self.actions
+	self.actions[test_ran] = result
+
+class PiupartsReport:
+    def __init__(self):
+        self.out = {}
+
+    def set(self, key, value):
+	if key in self.out: # accept no contradictions
+	    if self.out[key] != value:
+               print 'REPORT: overriding key: ' + key + ': ' + self.out[key] + ' -> ' + value
+	self.out[key] = value
+
+    def set_many(self, key, value):
+	if key not in self.out:
+	    self.out[key] = []
+	self.out[key].append(value)
+
+    def finish(self, outfilename):
+	# First, clean up the out dictionary
+	for key in self.out:
+	    if type(self.out[key]) == type([]):
+		self.out[key] = '\n' + ''.join([' %s\n' % s for s in self.out[key] ])
+	# Whew, okay.  That was sort of gross, sorry.
+
+	print deb822.Deb822(self.out)
+
 def objects_are_different(pair1, pair2):
     """Are filesystem objects different based on their meta data?"""
     (m1, target1) = pair1
@@ -1271,11 +1315,17 @@
         list.append("  %s\t" % name)
         if name in file_owners:
             list.append(" owned by: %s\n" % ", ".join(file_owners[name]))
-	else:
-            list.append(" not owned\n")	
+    else:
+            list.append(" not owned\n") 
 
     return "".join(list)
 
+def file_names(meta_infos):
+    meta_infos.sort()
+    list = []
+    for name, data in meta_infos:
+        list.append(name)
+    return list
 
 def offending_packages(meta_infos, file_owners):
     """Return a Set of offending packages."""
@@ -1354,14 +1404,20 @@
     if new:
         logging.error("Package purging left files on system:\n" +
                        file_list(new, file_owners))
+        for filename in file_names(new):
+            report.set_many("purging-did-not-remove-file-list", filename)
         ok = False
     if removed:
         logging.error("After purging files have disappeared:\n" +
                       file_list(removed, file_owners))
+        for filename in file_names(removed):
+            report.set_many("purging-did-remove-file-not-installed-by-package-list", filename)
         ok = False
     if modified:
         logging.error("After purging files have been modified:\n" +
                       file_list(modified, file_owners))
+        for filename in file_names(modified):
+            report.set_many("purging-left-modified-file-list", filename)
         ok = False
 
     if ok and settings.warn_on_others and deps_info is not None:
@@ -1445,8 +1501,8 @@
         chroot.run(["apt-get", "clean"])
 
 
-    chroot.check_for_no_processes()
-    chroot.check_for_broken_symlinks()
+    chroot.check_for_no_processes() # FIXME: report
+    chroot.check_for_broken_symlinks() # FIXME: report
 
     file_owners = chroot.get_files_owned_by_packages()
 
@@ -1728,8 +1784,11 @@
 
     parser.add_option("--debfoster-options",
                       default="-o MaxPriority=required -o UseRecommends=no -f -n apt debfoster",
-		      help="Run debfoster with different parameters (default: -o MaxPriority=required -o UseRecommends=no -f -n apt debfoster).")
+              help="Run debfoster with different parameters (default: -o MaxPriority=required -o UseRecommends=no -f -n apt debfoster).")
     
+    parser.add_option("-r", "--report", metavar="FILENAME", 
+                      help="Run in report mode, writing the report to FILENAME ")
+
     (opts, args) = parser.parse_args()
 
     settings.defaults = opts.defaults
@@ -1744,6 +1803,7 @@
     settings.list_installed_files = opts.list_installed_files
     settings.no_upgrade_test = opts.no_upgrade_test
     settings.skip_cronfiles_test = opts.skip_cronfiles_test
+    settings.report_file = opts.report
     log_file_name = opts.log_file
 
     defaults = DefaultsFactory().new_defaults()
@@ -1823,6 +1883,11 @@
     logging.info("Command line arguments: %s" % " ".join(sys.argv))
     logging.info("Running on: %s %s %s %s %s" % os.uname())
 
+    failure = False
+
+    global report
+    report = PiupartsReport()
+
     # Make sure debconf does not ask questions and stop everything.
     # Packages that don't use debconf will lose.
     os.environ["DEBIAN_FRONTEND"] = "noninteractive"
@@ -1853,35 +1918,57 @@
         if not install_purge_test(chroot, root_info, selections,
 				  args, packages):
             logging.error("FAIL: Installation and purging test.")
-            panic()
-        logging.info("PASS: Installation and purging test.")
+            if settings.report_file:
+                report.set('install-purge', 'FAIL')
+            else:
+                panic()
+        else:
+            logging.info("PASS: Installation and purging test.")
+	    report.set('install-purge', 'OK')
+	
 
+       
+
         if not settings.no_upgrade_test:
             if not settings.args_are_package_files:
                 logging.info("Can't test upgrades: -a or --apt option used.")
             elif not chroot.apt_get_knows(packages):
                 logging.info("Can't test upgrade: packages not known by apt-get.")
-            elif install_upgrade_test(chroot, root_info, selections, args, 
-                                  packages):
-                logging.info("PASS: Installation, upgrade and purging tests.")
             else:
-                logging.error("FAIL: Installation, upgrade and purging tests.")
-                panic()
-    
+                if install_upgrade_test(chroot, root_info, selections, args, packages):
+                    logging.info("PASS: Installation, upgrade and purging tests.")
+		    report.set('install-upgrade', 'OK')
+
+                else:
+                    logging.error("FAIL: Installation, upgrade and purging tests.")
+		    report.set('install-upgrade', 'FAIL')
+                    if settings.report_file:
+                        failure = True
+                    else:
+                        panic()
+
         chroot.remove()
         dont_do_on_panic(id)
     else:
         if install_and_upgrade_between_distros(args, packages):
             logging.info("PASS: Upgrading between Debian distributions.")
+	    report.set('Dist-upgrade check', 'OK')
         else:
             logging.error("FAIL: Upgrading between Debian distributions.")
-            panic()
+	    report.set('Dist-upgrade check', 'FAIL')
+            if settings.report_file:
+                failure = True
+            else:
+                panic()
 
     if settings.adt_virt is not None: settings.adt_virt.shutdown()
 
-    logging.info("PASS: All tests.")
+    if not failure:
+        logging.info("PASS: All tests.")
     logging.info("piuparts run ends.")
 
+    if settings.report_file:
+        report.finish(settings.report_file)
 
 if __name__ == "__main__":
     if sys.argv[1:] == ["unittest"]:




More information about the Piuparts-commits mailing list