Adding comparison script to list patches added to one distro compared to another 52/51052/14
authorJamo Luhrsen <jluhrsen@redhat.com>
Thu, 26 Jan 2017 01:21:21 +0000 (17:21 -0800)
committerDaniel Farrell <dfarrell@redhat.com>
Tue, 7 Feb 2017 17:32:59 +0000 (17:32 +0000)
Change-Id: Iae9028304bf3407a0075b026ae22b3fd21997c76
Signed-off-by: Jamo Luhrsen <jluhrsen@redhat.com>
Signed-off-by: Sam Hague <shague@redhat.com>
Signed-off-by: Jamo Luhrsen <jluhrsen@redhat.com>
tools/distchanges/changes.py
tools/distchanges/distcompare.py [new file with mode: 0644]
tools/distchanges/tests/test_changes.py

index a17c2ba625db8b5ca047187f01ca064a99c78e3d..46178b5d274a85b0a1057b0c9f4b88f7646da2e8 100644 (file)
@@ -3,7 +3,6 @@ import argparse
 import gerritquery
 import os
 import re
-import shutil
 import sys
 import time
 import urllib3
@@ -40,7 +39,7 @@ See the License for the specific language governing permissions and
 limitations under the License."""
 
 
-class Changes:
+class Changes(object):
     # NETVIRT_PROJECTS, as taken from autorelease dependency info [0]
     # TODO: it would be nice to fetch the dependency info on the fly in case it changes down the road
     # [0] https://logs.opendaylight.org/releng/jenkins092/autorelease-release-carbon/127/archives/dependencies.log.gz
@@ -77,6 +76,7 @@ class Changes:
         self.project_names = project_names
         self.remote_url = remote_url
         self.verbose = verbose
+        self.projects = {}
 
     def epoch_to_utc(self, epoch):
         utc = time.gmtime(epoch)
@@ -189,7 +189,7 @@ class Changes:
             zf = zipfile.ZipFile(fullpath, "r")
             try:
                 pfile = zf.open("META-INF/git.properties")
-                return pfile.read()
+                return str(pfile.read())
             except KeyError:
                 pass
         return None
@@ -288,6 +288,7 @@ class Changes:
         for project in self.projects:
             changeid = self.find_distro_changeid(project)
             if changeid:
+                self.projects[project]['commit'] = changeid
                 self.projects[project]["includes"] = self.get_includes(project, changeid)
         return self.projects
 
diff --git a/tools/distchanges/distcompare.py b/tools/distchanges/distcompare.py
new file mode 100644 (file)
index 0000000..ce363fa
--- /dev/null
@@ -0,0 +1,68 @@
+from changes import Changes
+
+# assumes that the new/current and older distributions are unzipped in /tmp/distro_new and
+# /tmp_distro_old respectively
+
+
+class DistCompare(object):
+
+    @staticmethod
+    def get_project_names():
+        # TODO: when autorelease starts publishing the dependencies.log artifact, this function (or the consumer
+        # of this tool) can take the latest dependencies.log from jenkins lastSuccessfulArtifacts and put it
+        # in /tmp/ For now the functionality to read the projects from that file are commented.
+
+        """
+        projects = []
+        with open("/tmp/dependencies.log") as dep_file:
+            for line in dep_file:
+                if line != "\n":
+                    projects.append(line.split(":")[0])
+
+        return projects
+        """
+
+        # this hard coded list of projects was taken from a Carbon dependencies.log - late January 2017
+        return ['eman', 'integration/distribution', 'snbi', 'mdsal', 'alto', 'sfc', 'sdninterfaceapp', 'topoprocessing',
+                'usc', 'ovsdb', 'lispflowmapping', 'groupbasedpolicy', 'usecplugin', 'snmp4sdn', 'capwap', 'aaa',
+                'honeycomb/vbd', 'atrium', 'next', 'nic', 'vtn', 'lacp', 'openflowplugin', 'faas', 'ttp', 'of-config',
+                'packetcable', 'genius', 'yangtools', 'natapp', 'didm', 'infrautils', 'netide', 'netvirt', 'neutron',
+                'cardinal', 'snmp', 'bgpcep', 'nemo', 'netconf', 'yang-push', 'iotdm', 'tsdr', 'sxp', 'centinel',
+                'odlparent', 'l2switch', 'unimgr', 'openflowjava', 'ocpplugin', 'dlux', 'controller']
+
+    def run_cmd(self):
+        query_limit = 100
+        num_to_display = 50
+        branch = 'master'
+        project_names = self.get_project_names()
+        extracted_distro_locations = {'new': '/tmp/distro_new', 'old': '/tmp/distro_old'}
+
+        new_changes = Changes(branch, extracted_distro_locations['new'], num_to_display,
+                              query_limit, project_names)
+        new_projects = new_changes.run_cmd()
+        new_changes.pretty_print_projects(new_projects)
+
+        old_changes = Changes(branch, extracted_distro_locations['old'], num_to_display,
+                              query_limit, project_names)
+        old_projects = old_changes.run_cmd()
+        old_changes.pretty_print_projects(old_projects)
+
+        patchset_diff = []
+        print("\nPatch differences:\n------------------")
+        for project_name, values in new_projects.items():
+            new_gerrits = values['includes']
+            for gerrit in new_gerrits:
+                if gerrit not in old_projects[project_name]['includes']:
+                    patchset_diff.append(gerrit)
+                    print('{:<20}{}\t{}'.format(project_name, gerrit['url'], gerrit['subject']))
+
+        print("\n%s different patches between the two distros." % len(patchset_diff))
+
+
+def main():
+    distc = DistCompare()
+    distc.run_cmd()
+
+
+if __name__ == "__main__":
+    main()
index 8fb8d1d9774a970f406418185c559fa66f7354c8..0fc57b2a9c8fb2d1a27cca788fe75709f4466681 100644 (file)
@@ -1,7 +1,7 @@
 #!/usr/bin/env python
 
 import unittest
-
+import distcompare
 from changes import Changes
 
 REMOTE_URL = 'ssh://git.opendaylight.org:29418'
@@ -53,6 +53,9 @@ class TestChanges(unittest.TestCase):
         changes = Changes(BRANCH, DISTRO_PATH, LIMIT, QLIMIT, project_names, REMOTE_URL)
         print("utc: %s" % changes.epoch_to_utc(1483974872))
 
+    def test_distcompare(self):
+        distcompare.main()
+
 
 if __name__ == '__main__':
     unittest.main()