a89e9d7c6d9e94389072f1e218b74f8272f31055
[integration/test.git] / tools / distchanges / distcompare.py
1 import argparse
2 from changes import Changes
3
4 # assumes that the new/current and older distributions are unzipped in /tmp/distro_new and
5 # /tmp_distro_old respectively
6
7
8 class DistCompare(object):
9
10     def __init__(self, remote_url):
11
12         self.remote_url = remote_url
13
14     @staticmethod
15     def get_project_names():
16         # TODO: when autorelease starts publishing the dependencies.log artifact, this function (or the consumer
17         # of this tool) can take the latest dependencies.log from jenkins lastSuccessfulArtifacts and put it
18         # in /tmp/ For now the functionality to read the projects from that file are commented.
19         """
20         projects = []
21         with open("/tmp/dependencies.log") as dep_file:
22             for line in dep_file:
23                 if line != "\n":
24                     projects.append(line.split(":")[0])
25
26         return projects
27         """
28         # this hard coded list of projects was taken from Oxygen dependencies.log - late January 2018
29         return ['integration/distribution', 'mdsal', 'alto', 'sfc', 'bier', 'serviceutils',
30                 'usc', 'ovsdb', 'lispflowmapping', 'groupbasedpolicy', 'snmp4sdn', 'aaa',
31                 'honeycomb/vbd', 'openflowplugin', 'of-config', 'daexim', 'dluxapps', 'coe',
32                 'packetcable', 'genius', 'yangtools', 'infrautils', 'netvirt', 'neutron',
33                 'snmp', 'bgpcep', 'nemo', 'netconf', 'tsdr', 'sxp', 'jsonrpc', 'p4plugin',
34                 'odlparent', 'l2switch', 'dlux', 'controller']
35
36     def run_cmd(self):
37         query_limit = 100
38         num_to_display = 50
39         branch = 'master'
40         project_names = self.get_project_names()
41         extracted_distro_locations = {'new': '/tmp/distro_new', 'old': '/tmp/distro_old'}
42
43         new_changes = Changes(branch, extracted_distro_locations['new'], num_to_display,
44                               query_limit, project_names, self.remote_url)
45
46         new_projects = new_changes.run_cmd()
47         new_changes.pretty_print_projects(new_projects)
48
49         old_changes = Changes(branch, extracted_distro_locations['old'], num_to_display,
50                               query_limit, project_names, self.remote_url)
51
52         old_projects = old_changes.run_cmd()
53         old_changes.pretty_print_projects(old_projects)
54
55         patchset_diff = []
56         print("\nPatch differences:\n------------------")
57         for project_name, values in new_projects.items():
58             new_gerrits = values['includes']
59             for gerrit in new_gerrits:
60                 if gerrit not in old_projects[project_name]['includes']:
61                     patchset_diff.append(gerrit)
62                     print('{:<20}{}\t{}'.format(project_name, gerrit['url'], gerrit['subject']))
63
64         print("\n%s different patches between the two distros." % len(patchset_diff))
65
66
67 def main():
68
69     parser = argparse.ArgumentParser(description='Returns the list of patches found in the unzipped distribution at '
70                                                  '/tmp/distro_new that are not found in the distribution at '
71                                                  '/tmp/distro_old. This should result in a listing of what new changes '
72                                                  'were made between the two distributions.')
73     parser.add_argument("-r", "--remote", dest="remote_url", default=Changes.REMOTE_URL,
74                         help="git remote url to use for gerrit")
75     options = parser.parse_args()
76
77     distc = DistCompare(options.remote_url)
78     distc.run_cmd()
79
80
81 if __name__ == "__main__":
82     main()