[csw-devel] SF.net SVN: gar:[21072] csw/mgar/gar/v2/lib/python

wahwah at users.sourceforge.net wahwah at users.sourceforge.net
Tue May 14 17:39:17 CEST 2013


Revision: 21072
          http://gar.svn.sourceforge.net/gar/?rev=21072&view=rev
Author:   wahwah
Date:     2013-05-14 15:39:17 +0000 (Tue, 14 May 2013)
Log Message:
-----------
integrate-catalogs: Bugfix + test cases

This bug caused an inconsitency in the kiel catalog, because two lines mushed
together resulted in an unapplied change to the kiel catalog.

Modified Paths:
--------------
    csw/mgar/gar/v2/lib/python/integrate_catalogs.py

Added Paths:
-----------
    csw/mgar/gar/v2/lib/python/integrate_catalogs_test.py

Modified: csw/mgar/gar/v2/lib/python/integrate_catalogs.py
===================================================================
--- csw/mgar/gar/v2/lib/python/integrate_catalogs.py	2013-05-14 15:38:34 UTC (rev 21071)
+++ csw/mgar/gar/v2/lib/python/integrate_catalogs.py	2013-05-14 15:39:17 UTC (rev 21072)
@@ -12,17 +12,13 @@
 
 from Cheetah import Template
 import cjson
-import gdbm
-import json
 import catalog
 import common_constants
 import logging
 import opencsw
 import optparse
-import pprint
 import rest
 import sys
-import urllib2
 import re
 
 
@@ -39,7 +35,7 @@
     "machine buildfarm.opencsw.org login \${LOGNAME} password \$(cat /etc/opt/csw/releases/auth/\${LOGNAME})"
 fi
 
-set -x
+set -e
 
 readonly CURL="curl --netrc"
 readonly REST_URL=http://buildfarm.opencsw.org/releases/
@@ -112,6 +108,7 @@
 #if "new_pkgs" in $diffs_by_catalogname[$catalogname]:
 new_pkg_$catalogname#
 #end if
+
 #if "removed_pkgs" in $diffs_by_catalogname[$catalogname]:
 remove_pkg_$catalogname#
 #end if
@@ -135,9 +132,11 @@
 #end for
 """
 
+
 class Error(Exception):
   """Generic error."""
 
+
 class UsageError(Error):
   """Wrong usage."""
 
@@ -146,7 +145,7 @@
   return dict((x[field], x) for x in d)
 
 
-def GetDiffsByCatalogname(catrel_from, catrel_to, include_downgrades,
+def GetCatalogs(catrel_from, catrel_to, include_downgrades,
                           include_version_changes):
   rest_client = rest.RestClient()
   def GetCatalog(rest_client, r_catrel, r_arch, r_osrel):
@@ -163,11 +162,9 @@
         catalogs_to_fetch_args.append((rest_client, catrel, arch, osrel))
   # Convert this to pool.map when multiprocessing if fixed.
   catalogs = dict(map(lambda x: GetCatalog(*x), catalogs_to_fetch_args))
-  diffs_by_catalogname = ComposeDiffsByCatalogname(
-      catalogs, catrel_from, catrel_to, include_version_changes,
-      include_downgrades)
-  return catalogs, diffs_by_catalogname
+  return catalogs
 
+
 def ComposeDiffsByCatalogname(catalogs, catrel_from, catrel_to,
                               include_version_changes, include_downgrades):
   """Get a data structure indexed with catalognames.
@@ -286,9 +283,12 @@
         (tuple(cjson.decode(x)), jsonable_catalogs[x])
         for x in jsonable_catalogs)
   else:
-    catalogs, diffs_by_catalogname = GetDiffsByCatalogname(
+    catalogs = GetCatalogs(
         catrel_from, catrel_to, options.include_downgrades,
         options.include_version_changes)
+    diffs_by_catalogname = ComposeDiffsByCatalogname(
+        catalogs, catrel_from, catrel_to, include_version_changes,
+        include_downgrades)
     bundles_by_md5 = {}
     bundles_missing = set()
     cp = rest.CachedPkgstats("pkgstats")
@@ -300,7 +300,6 @@
           if md5 not in bundles_by_md5 and md5 not in bundles_missing:
             stats = cp.GetPkgstats(md5)
             bundle_key = "OPENCSW_BUNDLE"
-            # pprint.pprint(stats)
             if stats:
               if bundle_key in stats["pkginfo"]:
                 bundles_by_md5[md5] = stats["pkginfo"][bundle_key]

Added: csw/mgar/gar/v2/lib/python/integrate_catalogs_test.py
===================================================================
--- csw/mgar/gar/v2/lib/python/integrate_catalogs_test.py	                        (rev 0)
+++ csw/mgar/gar/v2/lib/python/integrate_catalogs_test.py	2013-05-14 15:39:17 UTC (rev 21072)
@@ -0,0 +1,160 @@
+#!/opt/csw/bin/python2.6
+
+import Cheetah
+import mox
+import unittest2 as unittest
+
+import integrate_catalogs
+
+OUT_1 = u"""#!/bin/bash
+# Catalog modification (not integration yet): unstable-fake -> kiel-fake
+# Generated by fake_prog
+
+
+if ! grep buildfarm ~/.netrc
+then
+  touch ~/.netrc
+  chmod 0600 ~/.netrc
+  echo >> ~/.netrc     "machine buildfarm.opencsw.org login ${LOGNAME} password $(cat /etc/opt/csw/releases/auth/${LOGNAME})"
+fi
+
+set -e
+
+readonly CURL="curl --netrc"
+readonly REST_URL=http://buildfarm.opencsw.org/releases/
+
+function _add_to_cat {
+  ${CURL} -X PUT ${REST_URL}catalogs/$1/$2/$3/$4/ ; echo
+}
+
+function _del_from_cat {
+  ${CURL} -X DELETE ${REST_URL}catalogs/$1/$2/$3/$4/ ; echo
+}
+
+"""
+
+OUT_2 = OUT_1 + """function new_pkg_fake_catalogname_1 {
+  # adding fake_basename_1.pkg
+  _add_to_cat kiel-fake i386 SunOS5.10 6110aad210240504ede48f9cd8b4501c
+}
+function undo_new_pkg_fake_catalogname_1 {
+  # UNDO adding fake_basename_1.pkg
+  _del_from_cat kiel-fake i386 SunOS5.10 6110aad210240504ede48f9cd8b4501c
+}
+
+function new_pkg_fake_catalogname_2 {
+  # adding fake_basename_2.pkg
+  _add_to_cat kiel-fake sparc SunOS5.10 6110aad210240504ede48f9cd8b4501d
+}
+function undo_new_pkg_fake_catalogname_2 {
+  # UNDO adding fake_basename_2.pkg
+  _del_from_cat kiel-fake sparc SunOS5.10 6110aad210240504ede48f9cd8b4501d
+}
+function upgrade_fake_catalogname_2 {
+  # fake_catalogname_2 upgrade from 1.1.31,REV=2013.01.07 to 1.0,REV=2013.01.08
+  _del_from_cat kiel-fake i386 SunOS5.10 6110aad210240504ede48f9cd8b4501c
+  _add_to_cat kiel-fake i386 SunOS5.10 6110aad210240504ede48f9cd8b4501d
+}
+function undo_upgrade_fake_catalogname_2 {
+  # UNDO of fake_catalogname_2 upgrade from 1.1.31,REV=2013.01.07 to 1.0,REV=2013.01.08
+  _del_from_cat kiel-fake i386 SunOS5.10 6110aad210240504ede48f9cd8b4501d
+  _add_to_cat kiel-fake i386 SunOS5.10 6110aad210240504ede48f9cd8b4501c
+}
+
+new_pkg_fake_catalogname_1
+ # bundles:
+new_pkg_fake_catalogname_2
+upgrade_fake_catalogname_2 # version 1.1.31,REV=2013.01.07 to 1.0,REV=2013.01.08 # bundles:
+"""
+
+class TemplateUnitTest(mox.MoxTestBase, unittest.TestCase):
+
+  def testTemplateMinimal(self):
+    self.maxDiff = None
+    bundles_by_catalogname = {}
+    bundles_by_md5 = {}
+    diffs_by_catalogname = {}
+    namespace = {
+        "bundles_by_catalogname": bundles_by_catalogname,
+        "bundles_by_md5": bundles_by_md5,
+        "diffs_by_catalogname": diffs_by_catalogname,
+        "catrel_to": "kiel-fake",
+        "catrel_from": "unstable-fake",
+        "prog": "fake_prog",
+    }
+    t = Cheetah.Template.Template(integrate_catalogs.CATALOG_MOD_TMPL, searchList=[namespace])
+    # Compare line by line for better output.
+    self.assertEqual(OUT_1.splitlines(), unicode(t).splitlines())
+
+  def testTemplateUpgrade(self):
+    self.maxDiff = None
+    bundles_by_catalogname = {
+        "fake_catalogname_1" : [],
+        "fake_catalogname_2" : [],
+    }
+    bundles_by_md5 = {
+        "fake_md5": [],
+    }
+    catalogs = {
+        ("unstable-fake", "i386", "SunOS5.8"): [],
+        ("kiel-fake", "i386", "SunOS5.8"): [],
+        ("unstable-fake", "i386", "SunOS5.9"): [],
+        ("kiel-fake", "i386", "SunOS5.9"): [],
+        ("unstable-fake", "i386", "SunOS5.10"): [
+            {
+                "basename": "fake_basename_1.pkg",
+                "catalogname": "fake_catalogname_1",
+                "md5_sum": "6110aad210240504ede48f9cd8b4501c",
+                "version": "1.1.30,REV=2013.01.08",
+            },
+            {
+                "basename": "fake_basename_2.pkg",
+                "catalogname": "fake_catalogname_2",
+                "md5_sum": "6110aad210240504ede48f9cd8b4501d",
+                "version": "1.0,REV=2013.01.08",
+            },
+        ],
+        ("kiel-fake", "i386", "SunOS5.10"): [
+            {
+                "basename": "fake_basename_2.pkg",
+                "catalogname": "fake_catalogname_2",
+                "md5_sum": "6110aad210240504ede48f9cd8b4501c",
+                "version": "1.1.31,REV=2013.01.07",
+            },
+        ],
+        ("unstable-fake", "i386", "SunOS5.11"): [],
+        ("kiel-fake", "i386", "SunOS5.11"): [],
+
+        ("unstable-fake", "sparc", "SunOS5.8"): [],
+        ("kiel-fake", "sparc", "SunOS5.8"): [],
+        ("unstable-fake", "sparc", "SunOS5.9"): [],
+        ("kiel-fake", "sparc", "SunOS5.9"): [],
+        ("unstable-fake", "sparc", "SunOS5.10"): [
+            {
+                "basename": "fake_basename_2.pkg",
+                "catalogname": "fake_catalogname_2",
+                "md5_sum": "6110aad210240504ede48f9cd8b4501d",
+                "version": "1.0,REV=2013.01.08",
+            },
+        ],
+        ("kiel-fake", "sparc", "SunOS5.10"): [],
+        ("unstable-fake", "sparc", "SunOS5.11"): [],
+        ("kiel-fake", "sparc", "SunOS5.11"): [],
+    }
+    diffs_by_catalogname = integrate_catalogs.ComposeDiffsByCatalogname(
+        catalogs, "unstable-fake", "kiel-fake", True, True)
+    namespace = {
+        "bundles_by_catalogname": bundles_by_catalogname,
+        "bundles_by_md5": bundles_by_md5,
+        "diffs_by_catalogname": diffs_by_catalogname,
+        "catrel_to": "kiel-fake",
+        "catrel_from": "unstable-fake",
+        "prog": "fake_prog",
+    }
+    t = Cheetah.Template.Template(integrate_catalogs.CATALOG_MOD_TMPL, searchList=[namespace])
+    # Compare line by line for better output.
+    self.assertEqual(OUT_2.splitlines(), unicode(t).splitlines())
+
+
+if __name__ == '__main__':
+  unittest.main()


Property changes on: csw/mgar/gar/v2/lib/python/integrate_catalogs_test.py
___________________________________________________________________
Added: svn:executable
   + *

This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.



More information about the devel mailing list