Skip to content

Commit

Permalink
initial commit with working POC to diff control files
Browse files Browse the repository at this point in the history
  • Loading branch information
Philip Roche committed Mar 25, 2024
1 parent b6eefb7 commit 88ddb1c
Show file tree
Hide file tree
Showing 3 changed files with 105 additions and 1 deletion.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -157,4 +157,4 @@ cython_debug/
# be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore
# and can be added to the global gitignore or merged into this file. For a more nuclear
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
#.idea/
.idea/
57 changes: 57 additions & 0 deletions README.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
Goal of this project
====================

The goal is to be able to track the differences between Ubuntu packaging of google-guest-agent and the upstream
packaging of google-guest-agent.

We need to be able to annotate/exclude some of these differences to that if the differences change we can report and alert.

Usage
-----

.. code-block:: bash
wget --output-document=upstream-control "https://raw.githubusercontent.com/GoogleCloudPlatform/guest-agent/main/packaging/debian/control"
wget --output-document=ubuntu-control "https://git.launchpad.net/ubuntu/+source/google-guest-agent/plain/debian/control?h=applied/ubuntu/noble-devel"
python3 google_guest_agent_packaging_diff_tool.py --upstream-control-file ./upstream-control --ubuntu-control-file ./ubuntu-control
TODO
----

This project is very much in progress and is currently in POC stage. The following are the things that need to be done:

* Currently the differences are printed to stdout. We need to add a way to annotate the differences so that we can track them.
* Report on annotated differences as well as unannotated differences.
* Exit 1 if there are differences that are not annotated/expected.

The current output is as follow:

.. code-block:: bash
❯ python3 google_guest_agent_packaging_diff_tool.py --upstream-control-file ./upstream-control --ubuntu-control-file ./ubuntu-control
Build-Depends
[[{'name': 'debhelper', 'archqual': None, 'version': ('>=', '9.20160709'), 'arch': None, 'restrictions': None}], [{'name': 'dh-golang', 'archqual': None, 'version': ('>=', '1.1'), 'arch': None, 'restrictions': None}], [{'name': 'golang-go', 'archqual': None, 'version': None, 'arch': None, 'restrictions': None}]]
upstream: debhelper ('>=', '9.20160709')
upstream: dh-golang ('>=', '1.1')
upstream: golang-go None
[[{'name': 'debhelper-compat', 'archqual': None, 'version': ('=', '12'), 'arch': None, 'restrictions': None}], [{'name': 'dh-golang', 'archqual': None, 'version': None, 'arch': None, 'restrictions': None}], [{'name': 'golang-any', 'archqual': None, 'version': None, 'arch': None, 'restrictions': None}]]
ubuntu: debhelper-compat ('=', '12')
ubuntu: dh-golang None
ubuntu: golang-any None
Depends
cannot parse package relationship "${misc:Depends}", returning it raw
[[{'name': '${misc:Depends}', 'archqual': None, 'version': None, 'arch': None, 'restrictions': None}], [{'name': 'google-compute-engine-oslogin', 'archqual': None, 'version': ('>=', '1:20231003'), 'arch': None, 'restrictions': None}]]
upstream: ${misc:Depends} None
upstream: google-compute-engine-oslogin ('>=', '1:20231003')
cannot parse package relationship "${misc:Depends}", returning it raw
cannot parse package relationship "${shlibs:Depends}", returning it raw
[[{'name': '${misc:Depends}', 'archqual': None, 'version': None, 'arch': None, 'restrictions': None}], [{'name': '${shlibs:Depends}', 'archqual': None, 'version': None, 'arch': None, 'restrictions': None}], [{'name': 'google-compute-engine-oslogin', 'archqual': None, 'version': ('>=', '20231004.00-0ubuntu1'), 'arch': None, 'restrictions': None}]]
ubuntu: ${misc:Depends} None
ubuntu: ${shlibs:Depends} None
ubuntu: google-compute-engine-oslogin ('>=', '20231004.00-0ubuntu1')
Breaks
upstream: None
ubuntu: None
Replaces
upstream: None
ubuntu: None
47 changes: 47 additions & 0 deletions google_guest_agent_packaging_diff_tool.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
from pprint import pprint
import os
import click
from debian import deb822

def parse_control_file(control_file):
control_file_text = control_file.read()
control_file_text_no_blank_lines = os.linesep.join([s for s in control_file_text.splitlines() if s])
control_fileds = deb822.Deb822(control_file_text_no_blank_lines)
return control_fileds


@click.command()
@click.option('--upstream-control-file', type=click.File(), required=True, help='Upstream control files to compare')
@click.option('--ubuntu-control-file', type=click.File(), required=True, help='Ubuntu control files to compare')
def main(upstream_control_file, ubuntu_control_file):
# wget --output-document=ubuntu-control "https://git.launchpad.net/ubuntu/+source/google-guest-agent/tree/debian/control?h=applied/ubuntu/noble-devel"
# wget --output-document=ubuntu-control "https://git.launchpad.net/ubuntu/+source/google-guest-agent/plain/debian/control?h=applied/ubuntu/noble-devel"
ubuntu_control_fields = parse_control_file(ubuntu_control_file)
upstream_control_fields = parse_control_file(upstream_control_file)
fields_to_compare = ['Build-Depends', 'Depends', 'Recommends', 'Suggests', 'Breaks', 'Conflicts', 'Replaces', 'Provides']

# compare the above control fields
for field_name in [field_to_compare for field_to_compare in ubuntu_control_fields.keys() if field_to_compare in fields_to_compare]:
print(f'{field_name}')
if field_name in upstream_control_fields.keys():
# print(f'\tupstream: {upstream_control_fields[field_name]}')
relations = deb822.PkgRelation.parse_relations(upstream_control_fields[field_name])
print(relations)
for relation in relations:
for relation_item in relation:
print(f'\tupstream: {relation_item["name"]} {relation_item["version"]}')
else:
print(f'\tupstream: None')
if field_name in upstream_control_fields.keys():
# print(f'\tubuntu: {ubuntu_control_fields[field_name]}')
relations = deb822.PkgRelation.parse_relations(ubuntu_control_fields[field_name])
print(relations)
for relation in relations:
for relation_item in relation:
print(f'\tubuntu: {relation_item["name"]} {relation_item["version"]}')
else:
print(f'\tubuntu: None')


if __name__ == '__main__':
main()

0 comments on commit 88ddb1c

Please sign in to comment.