Merge ~fourdollars/pc-enablement/+git/oem-scripts:master into ~oem-solutions-engineers/pc-enablement/+git/oem-scripts:master

Proposed by Shih-Yuan Lee
Status: Merged
Merged at revision: 4baba105b3d1677c97b10f86131c904283b1f810
Proposed branch: ~fourdollars/pc-enablement/+git/oem-scripts:master
Merge into: ~oem-solutions-engineers/pc-enablement/+git/oem-scripts:master
Diff against target: 321 lines (+200/-18)
8 files modified
debian/changelog (+13/-0)
debian/tests/pkg-list (+4/-0)
oem-meta-packages (+151/-0)
oem_scripts/LaunchpadLogin.py (+1/-1)
pkg-list (+28/-17)
setup.py (+1/-0)
tests/test_flake8 (+1/-0)
tests/test_pep8 (+1/-0)
Reviewer Review Type Date Requested Status
Yuan-Chen Cheng (community) Approve
Review via email: mp+394863@code.launchpad.net

Description of the change

linux-image-4.15.0-1104-oem was pending publication so this commit aims to catch it.

$ pkg-list --apt-dir /tmp/apt.W1fko1dluV linux-oem --exclude /tmp/apt.W1fko1dluV/all.list
amd64-microcode 3.20191021.1+really3.20181128.1~ubuntu0.18.04.1
intel-microcode 3.20201110.0ubuntu0.18.04.2
iucode-tool 2.3.1-1
linux-firmware 1.173.19
linux-headers-4.15.0-1104-oem 4.15.0-1104.115
linux-headers-oem 4.15.0.1104.108
linux-image-oem 4.15.0.1104.108
linux-oem 4.15.0.1104.108
linux-oem-headers-4.15.0-1104 4.15.0-1104.115

$ pkg-list --apt-dir /tmp/apt.W1fko1dluV linux-oem --exclude /tmp/apt.W1fko1dluV/all.list --fail-unavailable
<ERROR> linux-image-4.15.0-1104-oem is unavailable.

$ run-autopkgtest lxc focal -t pkg-list -C
...
pkg-list PASS

autopkgtest-build-lxc-23ad9ac-focal-complete.log https://paste.ubuntu.com/p/gBX6gfMKX5/

$ grep ERROR autopkgtest-build-lxc-23ad9ac-focal-complete.log -A 1
<ERROR> python3:any is unavailable.
It is usual to see some Debian package still unavailable in proposed channel.

To post a comment you must log in.
Revision history for this message
Alex Tu (alextu) wrote :

I'm thinking of the possibility of a unit test for pkg-list to capture all scenario of this script like what I did in pc-sanity package [1].

So, that we have confidence that any change would not impact expected behavior and the new scenarios could also be reviewed and verified easily through unit tests.

[1] https://git.launchpad.net/plainbox-provider-pc-sanity/tree/test

Revision history for this message
Alex Tu (alextu) wrote :

LGTM.

Revision history for this message
Shih-Yuan Lee (fourdollars) wrote :

$ cat autopkgtest-build-lxc-7eeaacd-focal-summary.log
mir-bug-verification SKIP Test requires machine-level isolation but testbed does not provide that
autopkgtest-collect-credentials PASS
autopkgtest-oem-scripts-auto PASS
pkg-somerville-meta PASS
pkg-sutton-meta PASS
pkg-stella-meta PASS
launchpad-api PASS
get-private-ppa PASS
jq-lp PASS
mir-bug PASS
run-autopkgtest PASS
bug-bind PASS
pkg-list PASS
setup-apt-dir PASS
git-url-insteadof-setting PASS

autopkgtest-build-lxc-7eeaacd-focal-complete.log https://paste.ubuntu.com/p/WVJ53xfwyC/

Revision history for this message
Shih-Yuan Lee (fourdollars) wrote :
Download full text (5.9 KiB)

$ ./oem-meta-packages subscribe
<INFO> Using oem-scripts login
<INFO> Loading KWallet
<INFO> Loading SecretService
<INFO> Loading Windows
<INFO> Loading chainer
<INFO> Loading macOS
<INFO> Checking the subscriptions for oem-somerville-meera-tgl-meta...
<INFO> ubuntu/oem-somerville-meera-tgl-meta has subscribed oem-solutions-engineers.
<INFO> Checking the subscriptions for oem-sutton.bachman-banaing-meta...
<INFO> ubuntu/oem-sutton.bachman-banaing-meta has subscribed oem-solutions-engineers.
<INFO> Checking the subscriptions for oem-sutton.newell-cadyna-meta...
<INFO> ubuntu/oem-sutton.newell-cadyna-meta has subscribed oem-solutions-engineers.
<INFO> Checking the subscriptions for oem-sutton.newell-adalbrechta-meta...
<INFO> ubuntu/oem-sutton.newell-adalbrechta-meta has subscribed oem-solutions-engineers.
<INFO> Checking the subscriptions for oem-sutton.bachman-banner-meta...
<INFO> ubuntu/oem-sutton.bachman-banner-meta has subscribed oem-solutions-engineers.
<INFO> Checking the subscriptions for oem-sutton.newell-cade-meta...
<INFO> ubuntu/oem-sutton.newell-cade-meta has subscribed oem-solutions-engineers.
<INFO> Checking the subscriptions for oem-sutton.newell-cadence-meta...
<INFO> ubuntu/oem-sutton.newell-cadence-meta has subscribed oem-solutions-engineers.
<INFO> Checking the subscriptions for oem-sutton.simon-adken-meta...
<INFO> ubuntu/oem-sutton.simon-adken-meta has subscribed oem-solutions-engineers.
<INFO> Checking the subscriptions for oem-somerville-beric-icl-meta...
<INFO> ubuntu/oem-somerville-beric-icl-meta has subscribed oem-solutions-engineers.
<INFO> Checking the subscriptions for oem-sutton.newell-cameo-meta...
<INFO> ubuntu/oem-sutton.newell-cameo-meta has subscribed oem-solutions-engineers.
<INFO> Checking the subscriptions for oem-somerville-samwell-tgl-meta...
<INFO> ubuntu/oem-somerville-samwell-tgl-meta has subscribed oem-solutions-engineers.
<INFO> Checking the subscriptions for oem-sutton.newell-ace-meta...
<INFO> ubuntu/oem-sutton.newell-ace-meta has subscribed oem-solutions-engineers.
<INFO> Checking the subscriptions for oem-somerville-bulbasaur-meta...
<INFO> ubuntu/oem-somerville-bulbasaur-meta has subscribed oem-solutions-engineers.
<INFO> Checking the subscriptions for oem-sutton.bachman-bale-meta...
<INFO> ubuntu/oem-sutton.bachman-bale-meta has subscribed oem-solutions-engineers.
<INFO> Checking the subscriptions for oem-somerville-three-eyed-raven-meta...
<INFO> ubuntu/oem-somerville-three-eyed-raven-meta has subscribed oem-solutions-engineers.
<INFO> Checking the subscriptions for oem-somerville-caterpie-meta...
<INFO> ubuntu/oem-somerville-caterpie-meta has subscribed oem-solutions-engineers.
<INFO> Checking the subscriptions for oem-somerville-melisa-meta...
<INFO> ubuntu/oem-somerville-melisa-meta has subscribed oem-solutions-engineers.
<INFO> Checking the subscriptions for oem-qemu-meta...
<INFO> ubuntu/oem-qemu-meta has subscribed oem-solutions-engineers.
<INFO> Checking the subscriptions for oem-sutton.bachman-baker-meta...
<INFO> ubuntu/oem-sutton.bachman-baker-meta has subscribed oem-solutions-engineers.
<INFO> Checking the subscriptions for oem-sutton.newell-candice-meta...
<INFO> ubuntu/oem-sutto...

Read more...

Revision history for this message
Yuan-Chen Cheng (ycheng-twn) wrote :

for change related to pkg-list, they are LGTM.

Revision history for this message
Yuan-Chen Cheng (ycheng-twn) wrote :

LGTM

review: Approve
Revision history for this message
Yuan-Chen Cheng (ycheng-twn) wrote :

note: talk in the f2f with $4, I think there could be some other better place to do what oem-meta-packages is doing.

However, he can't think any other script fits. Give so, approve it.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
diff --git a/debian/changelog b/debian/changelog
index 4545eb5..20ad464 100644
--- a/debian/changelog
+++ b/debian/changelog
@@ -1,3 +1,16 @@
1oem-scripts (0.71) UNRELEASED; urgency=medium
2
3 * pkg-list: Add an option '--fail-unavailable' to return unavailable error.
4 * pkg-list: Refine the checking for depends.
5 * oem-meta-packages,
6 oem_scripts/LaunchpadLogin.py,
7 setup.py,
8 tests/test_flake8,
9 tests/test_pep8: Add oem-meta-packages to subscribe the bugs of oem meta
10 packages.
11
12 -- Shih-Yuan Lee (FourDollars) <sylee@canonical.com> Fri, 04 Dec 2020 14:50:37 +0800
13
1oem-scripts (0.70) focal; urgency=medium14oem-scripts (0.70) focal; urgency=medium
215
3 * mir-bug,16 * mir-bug,
diff --git a/debian/tests/pkg-list b/debian/tests/pkg-list
index ae02e8d..92dfe33 100644
--- a/debian/tests/pkg-list
+++ b/debian/tests/pkg-list
@@ -1,9 +1,13 @@
1#!/bin/bash1#!/bin/bash
22
3echo "=== Enable focal proposed channel ==="
3APTDIR=$(setup-apt-dir.sh -c focal -m http://uk.archive.ubuntu.com/ubuntu -p | tail -n1)4APTDIR=$(setup-apt-dir.sh -c focal -m http://uk.archive.ubuntu.com/ubuntu -p | tail -n1)
45
5echo "=== ubuntu-desktop --recommends ==="6echo "=== ubuntu-desktop --recommends ==="
6pkg-list --apt-dir "$APTDIR" ubuntu-desktop --recommends | tee ubuntu-desktop.list7pkg-list --apt-dir "$APTDIR" ubuntu-desktop --recommends | tee ubuntu-desktop.list
8if ! pkg-list --apt-dir "$APTDIR" ubuntu-desktop --recommends --fail-unavailable; then
9 echo "It is usual to see some Debian package still unavailable in proposed channel."
10fi
711
8echo "=== dkms ==="12echo "=== dkms ==="
9pkg-list --apt-dir "$APTDIR" dkms --exclude ubuntu-desktop.list | tee dkms.list13pkg-list --apt-dir "$APTDIR" dkms --exclude ubuntu-desktop.list | tee dkms.list
diff --git a/oem-meta-packages b/oem-meta-packages
10new file mode 10075514new file mode 100755
index 0000000..2deb366
--- /dev/null
+++ b/oem-meta-packages
@@ -0,0 +1,151 @@
1#!/usr/bin/env python3
2# -*- coding: utf-8 -*-
3# Copyright (C) 2020 Canonical Ltd.
4# Author: Shih-Yuan Lee (FourDollars) <sylee@canonical.com>
5#
6# This program is free software; you can redistribute it and/or modify
7# it under the terms of the GNU General Public License as published by
8# the Free Software Foundation; either version 3 of the License, or
9# (at your option) any later version.
10#
11# This program is distributed in the hope that it will be useful,
12# but WITHOUT ANY WARRANTY; without even the implied warranty of
13# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14# GNU General Public License for more details.
15#
16# You should have received a copy of the GNU General Public License
17# along with this program; if not, write to the Free Software
18# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19
20import argparse
21import difflib
22import lazr
23import os
24import types
25
26from apt import apt_pkg
27from logging import info, warning, error, debug # , critical
28from oem_scripts.LaunchpadLogin import LaunchpadLogin
29from oem_scripts.logging import setup_logging
30
31parser = argparse.ArgumentParser(formatter_class=argparse.RawDescriptionHelpFormatter,
32 epilog="""
33Make all bugs of all oem meta packages be subscribed by oem-solutions-engineers.
34 (search current apt source for package lists)
35
36Check "To all bugs in oem-qemu-meta in Ubuntu:" on https://launchpad.net/ubuntu/+source/oem-qemu-meta/+subscribe for example.
37
38examples:
39 oem-meta-packages subscribe""")
40
41parser.add_argument("-d", "--debug",
42 help="print debug messages", action="store_true")
43parser.add_argument("-q", "--quiet",
44 help="Don't print info messages", action="store_true")
45parser.add_argument("-v", "--verbose", action="store_true",
46 help="print verbose messages")
47parser.add_argument("--apt-dir",
48 type=str,
49 help="specify the dir for apt")
50
51subparsers = parser.add_subparsers(dest="subcommand")
52
53subscribe = subparsers.add_parser('subscribe', help='[-h] [--yes]')
54subscribe.add_argument("--yes",
55 help="Say yes for all prompts.", action="store_true")
56
57unsubscribe = subparsers.add_parser('unsubscribe', help='[-h] [--yes] pkgName')
58unsubscribe.add_argument("pkgName", type=str,
59 help="Specify the package name to unsubscribe.")
60unsubscribe.add_argument("--yes",
61 help="Say yes for all prompts.", action="store_true")
62
63args = parser.parse_args()
64
65setup_logging(debug=args.debug, quiet=args.quiet)
66
67if args.subcommand:
68 login = LaunchpadLogin()
69 lp = login.lp
70
71if args.apt_dir:
72 apt_pkg.init_config()
73 if args.debug:
74 old = apt_pkg.config.dump()
75 apt_pkg.config.set("Dir", args.apt_dir)
76 apt_pkg.config.set("Dir::State::status", os.path.join(args.apt_dir, "var/lib/dpkg/status"))
77 if args.debug:
78 new = apt_pkg.config.dump()
79 d = difflib.Differ()
80 diff = d.compare(old.split('\n'), new.split('\n'))
81 for line in diff:
82 debug(line.strip())
83 apt_pkg.init_system()
84
85
86def yes_or_ask(yes: bool, message: str) -> bool:
87 if yes:
88 print(f"> \033[1;34m{message}\033[1;0m (y/n) y")
89 return True
90 while True:
91 res = input(f"> \033[1;34m{message}\033[1;0m (y/n) ").lower()
92 if res not in {"y", "n"}:
93 continue
94 if res == 'y':
95 return True
96 else:
97 return False
98
99
100def _debug_obj(pkg) -> None:
101
102 if not args.debug:
103 return
104
105 debug(dir(pkg))
106
107 for attr in dir(pkg):
108 if not attr.startswith('__'):
109 if not isinstance(pkg.__getattribute__(attr), types.BuiltinFunctionType):
110 debug(f"{attr}: {pkg.__getattribute__(attr)}")
111
112
113cache = apt_pkg.Cache(progress=None)
114
115if args.subcommand == 'subscribe':
116 for pkg in cache.packages:
117 name = pkg.name
118 if not name.startswith('oem-') or not name.endswith('-meta'):
119 continue
120 info(f"Checking the subscriptions for {name}...")
121 source = lp.distributions['ubuntu'].getSourcePackage(name=name)
122 if 'oem-solutions-engineers' in map(lambda x: x.subscriber.name, source.getSubscriptions()):
123 info(f"ubuntu/{name} has subscribed oem-solutions-engineers.")
124 continue
125 warning(f"ubuntu/{name} didn't subscribe oem-solutions-engineers yet.")
126 if yes_or_ask(args.yes, f"Would you like to subscribe 'oem-solutions-engineers' for ubuntu/{name}?"):
127 try:
128 # When a person is subscribed to a source package, one actually subscribe all bugs for it.
129 source.addBugSubscription(subscriber=lp.people['oem-solutions-engineers'])
130 except lazr.restfulclient.errors.Unauthorized as e:
131 error(f"{lp.me.name} does not have permission to subscribe oem-solutions-engineers.")
132 if args.verbose:
133 print(e)
134 exit(1)
135elif args.subcommand == 'unsubscribe':
136 source = lp.distributions['ubuntu'].getSourcePackage(name=args.pkgName)
137 subscriptions = source.getSubscriptions()
138 for subscription in subscriptions:
139 if subscription.subscriber.name == 'oem-solutions-engineers':
140 info(f"ubuntu/{args.pkgName} has subscribed oem-solutions-engineers.")
141 if yes_or_ask(args.yes, f"Would you like to unsubscribe 'oem-solutions-engineers' for ubuntu/{args.pkgName}?"):
142 try:
143 source.removeBugSubscription(subscriber=lp.people['oem-solutions-engineers'])
144 except lazr.restfulclient.errors.Unauthorized as e:
145 error(f"{lp.me.name} does not have permission to unsubscribe oem-solutions-engineers.")
146 if args.verbose:
147 print(e)
148 exit(1)
149 exit(0)
150else:
151 parser.print_help()
diff --git a/oem_scripts/LaunchpadLogin.py b/oem_scripts/LaunchpadLogin.py
index 25c314f..0583ad2 100644
--- a/oem_scripts/LaunchpadLogin.py
+++ b/oem_scripts/LaunchpadLogin.py
@@ -67,7 +67,7 @@ class LaunchpadLogin():
67 logging.info("Using anonymously login")67 logging.info("Using anonymously login")
68 self.lp = Launchpad.login_anonymously(application_name, service_root)68 self.lp = Launchpad.login_anonymously(application_name, service_root)
69 elif ":" in launchpad_token:69 elif ":" in launchpad_token:
70 oauth_token, oauth_token_secret, oauth_consumer_key = launchpad_token.split(":")70 oauth_token, oauth_token_secret, oauth_consumer_key = launchpad_token.split(":", maxsplit=2)
71 self.lp = Launchpad.login(oauth_consumer_key,71 self.lp = Launchpad.login(oauth_consumer_key,
72 oauth_token,72 oauth_token,
73 oauth_token_secret,73 oauth_token_secret,
diff --git a/pkg-list b/pkg-list
index ac844db..42351d5 100755
--- a/pkg-list
+++ b/pkg-list
@@ -25,7 +25,7 @@ import sys
25import types25import types
2626
27from apt import apt_pkg27from apt import apt_pkg
28from logging import debug, error, critical # info, warning28from logging import debug, error, critical, info # , warning
29from urllib.parse import urljoin29from urllib.parse import urljoin
3030
3131
@@ -59,6 +59,9 @@ parser.add_argument("--suggests",
59parser.add_argument("--non-installed",59parser.add_argument("--non-installed",
60 action="store_true",60 action="store_true",
61 help="only get non-installed packages per check current running environments")61 help="only get non-installed packages per check current running environments")
62parser.add_argument("--fail-unavailable",
63 action="store_true",
64 help="Return error when any package is unavailable.")
62parser.add_argument("--exclude",65parser.add_argument("--exclude",
63 metavar='pkg.list',66 metavar='pkg.list',
64 type=argparse.FileType('r', encoding='UTF-8'),67 type=argparse.FileType('r', encoding='UTF-8'),
@@ -133,9 +136,18 @@ def get_depends(pkg_name: str, depends_list: list, recommends: bool, suggests: b
133136
134 pkg = cache[pkg_name]137 pkg = cache[pkg_name]
135138
139 info(f"check {pkg_name}")
136 _debug_pkg(pkg)140 _debug_pkg(pkg)
137141
142 if args.fail_unavailable and not pkg.has_versions:
143 error(f"{pkg_name} is unavailable.")
144 exit(1)
145
138 for version in pkg.version_list:146 for version in pkg.version_list:
147 if pkg_name in map(lambda x: x[0], depends_list):
148 continue
149 info(f"version {version.ver_str}")
150 _debug_pkg(version)
139 url = None151 url = None
140152
141 if not version.downloadable:153 if not version.downloadable:
@@ -160,22 +172,21 @@ def get_depends(pkg_name: str, depends_list: list, recommends: bool, suggests: b
160 item = (pkg_name, version.ver_str, url, record.hashes.find("MD5Sum"), record.hashes.find("SHA1"), record.hashes.find("SHA256"))172 item = (pkg_name, version.ver_str, url, record.hashes.find("MD5Sum"), record.hashes.find("SHA1"), record.hashes.find("SHA256"))
161 depends_list.append(item)173 depends_list.append(item)
162174
163 if 'Depends' not in version.depends_list_str:175 for target in ('PreDepends', 'Depends', 'Recommends', 'Suggests'):
164 continue176 if target == 'Recommends' and not recommends:
165177 continue
166 for depends in version.depends_list_str['Depends']:178 if target == 'Suggests' and not suggests:
167 (name, ver, _) = depends[0]179 continue
168 get_depends(name, depends_list, recommends=recommends, suggests=suggests, non_installed=non_installed)180 if target not in version.depends_list_str:
169181 continue
170 if recommends and 'Recommends' in version.depends_list_str:182 for depends in version.depends_list_str[target]:
171 for depends in version.depends_list_str['Recommends']:183 for depend in depends:
172 (name, ver, _) = depends[0]184 (name, ver, _) = depend
173 get_depends(name, depends_list, recommends=recommends, suggests=suggests, non_installed=non_installed)185 pkg = cache[name]
174186 if name in map(lambda x: x[0], depends_list):
175 if suggests and 'Suggests' in version.depends_list_str:187 continue
176 for depends in version.depends_list_str['Suggests']:188 info(f"{pkg_name} {target} {name}")
177 (name, ver, _) = depends[0]189 get_depends(name, depends_list, recommends=recommends, suggests=suggests, non_installed=non_installed)
178 get_depends(name, depends_list, recommends=recommends, suggests=suggests, non_installed=non_installed)
179190
180191
181if args.apt_dir:192if args.apt_dir:
diff --git a/setup.py b/setup.py
index c598ec5..7984690 100644
--- a/setup.py
+++ b/setup.py
@@ -45,6 +45,7 @@ Also there is a meta package oem-dev-tools that installs all scripts''',
45 'lp-bug',45 'lp-bug',
46 'live-build-image-chroot.sh',46 'live-build-image-chroot.sh',
47 'oem-getiso',47 'oem-getiso',
48 'oem-meta-packages',
48 'pkg-list',49 'pkg-list',
49 'pkg-oem-meta',50 'pkg-oem-meta',
50 'rename-everything.py',51 'rename-everything.py',
diff --git a/tests/test_flake8 b/tests/test_flake8
index 069a89d..c4b8daa 100755
--- a/tests/test_flake8
+++ b/tests/test_flake8
@@ -3,4 +3,5 @@
3flake8 --ignore E501 \3flake8 --ignore E501 \
4 lp-bug \4 lp-bug \
5 mir-bug \5 mir-bug \
6 oem-meta-packages \
6 pkg-list7 pkg-list
diff --git a/tests/test_pep8 b/tests/test_pep8
index 22fdd7e..e09071e 100755
--- a/tests/test_pep8
+++ b/tests/test_pep8
@@ -11,4 +11,5 @@ pep8 --ignore=E501 \
11 lp-bug \11 lp-bug \
12 mir-bug \12 mir-bug \
13 oem-getiso \13 oem-getiso \
14 oem-meta-packages \
14 pkg-list15 pkg-list

Subscribers

People subscribed via source and target branches