forked from cockpit-project/bots
-
Notifications
You must be signed in to change notification settings - Fork 0
/
image-diff
executable file
·76 lines (60 loc) · 2.37 KB
/
image-diff
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
#!/usr/bin/python3
# This file is part of Cockpit.
#
# Copyright (C) 2020 Red Hat, Inc.
#
# Cockpit is free software; you can redistribute it and/or modify it
# under the terms of the GNU Lesser General Public License as published by
# the Free Software Foundation; either version 2.1 of the License, or
# (at your option) any later version.
#
# Cockpit is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public License
# along with Cockpit; If not, see <http://www.gnu.org/licenses/>.
import argparse
from machine import testvm
def get_packages(machine):
# List all packages, irrespective of package manager (rpm or dpkg or pacman).
# If both are missing, then the command will fail.
#
# We'd ideally like to get source packages everywhere, but it's a
# bit more difficult on RPM. (TODO)
pkgcmd = """if type dpkg-query > /dev/null 2>&1; then
dpkg-query -W 2>/dev/null;
elif type rpm > /dev/null 2>&1; then
rpm -qa --qf '%{NAME}\t%{EVR}\n' 2>/dev/null;
else pacman -Q | sed 's/ /\t/' 2>/dev/null; fi"""
output = machine.execute(pkgcmd).strip()
return dict(line.split('\t') for line in output.splitlines())
parser = argparse.ArgumentParser(description='Compare package versions on VM images')
parser.add_argument('old', help='the "old" image to compare')
parser.add_argument('new', help='the "new" image to compare')
args = parser.parse_args()
# boot the machines in parallel
old_vm = testvm.VirtMachine(image=args.old)
new_vm = testvm.VirtMachine(image=args.new)
old_vm.start()
new_vm.start()
old_vm.wait_boot()
new_vm.wait_boot()
old_pkgs = get_packages(old_vm)
new_pkgs = get_packages(new_vm)
old_vm.kill()
new_vm.kill()
print('Removed:')
for name in sorted(set(old_pkgs) - set(new_pkgs)):
print(f' {name} ({old_pkgs[name]})')
print()
print('Added:')
for name in sorted(set(new_pkgs) - set(old_pkgs)):
print(f' {name} ({new_pkgs[name]})')
print()
print('Changed:')
for name in sorted(set.intersection(set(new_pkgs), set(old_pkgs))):
if new_pkgs[name] != old_pkgs[name]:
print(f' {name} ({old_pkgs[name]} -> {new_pkgs[name]})')
print()