Merge ~enr0n/+git/systemd-hwe:main into ~canonical-foundations/+git/systemd-hwe:main

Proposed by Nick Rosbrook
Status: Merged
Merged at revision: 01bb9581ff1f687b2924a8ab88888c9564f138b5
Proposed branch: ~enr0n/+git/systemd-hwe:main
Merge into: ~canonical-foundations/+git/systemd-hwe:main
Diff against target: 256 lines (+184/-0)
12 files modified
Makefile (+3/-0)
debian/changelog (+10/-0)
debian/control (+18/-0)
debian/copyright (+24/-0)
debian/rules (+4/-0)
debian/source/format (+1/-0)
debian/systemd-hwe-hwdb.install (+1/-0)
debian/systemd-hwe-hwdb.postinst (+12/-0)
debian/systemd-hwe-hwdb.postrm (+12/-0)
debian/tests/control (+6/-0)
hwdb.d/90-hwe-ubuntu.hwdb (+11/-0)
tests/hwdb-redundancy (+82/-0)
Reviewer Review Type Date Requested Status
Lukas Märdian Approve
Review via email: mp+426491@code.launchpad.net

Description of the change

This adds the initial src:systemd-hwe package. With this in place, new hwdb rules can be added to the package by adding them to the appropriate hwdb.d/90-*-ubuntu.hwdb file.

To post a comment you must log in.
Revision history for this message
Lukas Märdian (slyon) wrote (last edit ):

Thank you Nick! I very much like what you did here.

Some comments/suggestions:

d/changelog:
* should the version number be somehow related to the upstream systemd version and/or the Ubuntu series? The package needs to be adopted for each upstream release, due to hwdb changes that we cherry-picked into systemd-hwe-hwdb might now be in conflict with upstream's version, which makes this package FTBFS via the test case provided. Maybe the version number should account for that, to make clear that e.g. 0.2.0 in Kinetic+1/LL isn't a linear extension to 0.1.0 in Kinetic/KK.
Some ideas (similar to https://launchpad.net/ubuntu/+source/ubuntu-release-upgrader):
- 22.10.1 (Ubuntu series + incremental ".X")
- 251.2.1 (corresponding systemd version + incremental ".X") <- I think this is my favorite, but please try to evaluate this a bit more, maybe ask Brian for some more input (as I'm not super sure about it)?

d/control:
* b-d udev >= 251.2-2ubuntu1~
* Lintian: E: systemd-hwe-hwdb: extended-description-is-empty

d/tests/control:
* I wonder if it'd make sense to copy/fork upstream's test/hwdb-test.sh as an additional autopkgtest?
* We could call the binary directly, avoiding the additional one-line script, e.g.:
--- a/debian/tests/control
+++ b/debian/tests/control
@@ -1,5 +1,6 @@
-Tests: test-sd-hwdb
+Test-Command: /usr/lib/systemd/tests/test-sd-hwdb
 Depends: systemd-tests,
   udev,
   systemd-hwe-hwdb,
 Restrictions: needs-root, allow-stderr
+Features: test-name=test-sd-hwdb

tests/test-hwdb-redundancy-check:
* rename file to tests/hwdb-redundancy (there's lots of tests/test/check redundancy in this path)? but MEH...
* get_hwdb_properties: we could use output.splitlines() to make it a bit more explicit
* test_no_duplicates: IIUC the test fails if we try to override a property of any pre-existing modalias. Shouldn't we only fail on a modalias setting the exact same values/properties? (i.e. a full duplicate) and maybe only print a warning for the "intersection" case, where some matches are only partially overriden? Otherwise, we wouldn't be able to change/override a (potentially wrong) property from upstream systemd via systemd-hwe-hwdb.

Revision history for this message
Nick Rosbrook (enr0n) wrote :

> Thank you Nick! I very much like what you did here.
>
> Some comments/suggestions:
>
> d/changelog:
> * should the version number be somehow related to the upstream systemd version
> and/or the Ubuntu series? The package needs to be adopted for each upstream
> release, due to hwdb changes that we cherry-picked into systemd-hwe-hwdb might
> now be in conflict with upstream's version, which makes this package FTBFS via
> the test case provided. Maybe the version number should account for that, to
> make clear that e.g. 0.2.0 in Kinetic+1/LL isn't a linear extension to 0.1.0
> in Kinetic/KK.
> Some ideas (similar to https://launchpad.net/ubuntu/+source/ubuntu-release-
> upgrader):
> - 22.10.1 (Ubuntu series + incremental ".X")
> - 251.2.1 (corresponding systemd version + incremental ".X") <- I think this
> is my favorite, but please try to evaluate this a bit more, maybe ask Brian
> for some more input (as I'm not super sure about it)?

Yes, I figured we might want something like this. I can ask Brian about the u-r-u convention to decide if it's a good fit. Otherwise I think basing the version number on the systemd version number would be good.

>
> d/control:
> * b-d udev >= 251.2-2ubuntu1~
> * Lintian: E: systemd-hwe-hwdb: extended-description-is-empty
>
>
> d/tests/control:
> * I wonder if it'd make sense to copy/fork upstream's test/hwdb-test.sh as an
> additional autopkgtest?

When I looked closer at it, I didn't think it provided any additional value to us. It's really intended to test the systemd-hwdb binary itself. But, maybe we could borrow the logic that checks for warnings on malformed rules, and fail the build if that happens (so I guess this would be a build time test rather than autopkgtest).

> * We could call the binary directly, avoiding the additional one-line script,
> e.g.:
> --- a/debian/tests/control
> +++ b/debian/tests/control
> @@ -1,5 +1,6 @@
> -Tests: test-sd-hwdb
> +Test-Command: /usr/lib/systemd/tests/test-sd-hwdb
> Depends: systemd-tests,
> udev,
> systemd-hwe-hwdb,
> Restrictions: needs-root, allow-stderr
> +Features: test-name=test-sd-hwdb

Nice, thanks!

> tests/test-hwdb-redundancy-check:
> * rename file to tests/hwdb-redundancy (there's lots of tests/test/check
> redundancy in this path)? but MEH...
> * get_hwdb_properties: we could use output.splitlines() to make it a bit more
> explicit
> * test_no_duplicates: IIUC the test fails if we try to override a property of
> any pre-existing modalias. Shouldn't we only fail on a modalias setting the
> exact same values/properties? (i.e. a full duplicate) and maybe only print a
> warning for the "intersection" case, where some matches are only partially
> overriden? Otherwise, we wouldn't be able to change/override a (potentially
> wrong) property from upstream systemd via systemd-hwe-hwdb.

ACK on the first two suggestions. However, your understanding on the test case is slightly off. The current implementation *does* only fail with exact duplicates, not when a property is overridden for a given modalias (the list items are of the form `KEY=VALUE`).

Revision history for this message
Nick Rosbrook (enr0n) wrote :

I believe I addressed all of your review comments. Of note, I went with the "follow systemd's version number" option. I think this is basically analogous to u-r-u's approach, but in that case following the Ubuntu release number makes sense.

Also, I added a check in tests/hwdb-redundancy for stderr output from `systemd-hwdb update`. IMO, this replicates the only functionality we would benefit from if we copied upstream's test/hwdb-test.sh.

Revision history for this message
Lukas Märdian (slyon) wrote :

Thank you very much for addressing my concerns and explaining + extending the test case.

LGTM!

I talked to Łukasz about how to best get this into Kinetic (being a new package):
Could you please create a tracking bug on Launchpad (against the "ubuntu" component, i.e.: https://bugs.launchpad.net/ubuntu/+filebug) briefly describing the rational of this new package.

This bug reference should then be closed form debian/changelog, e.g.:
--- a/debian/changelog
+++ b/debian/changelog
@@ -1,6 +1,6 @@
-systemd-hwe (251.2.1) UNRELEASED; urgency=medium
+systemd-hwe (251.2.1) kinetic; urgency=medium

- * Initial release.
+ * Initial release. (LP: #XXX)
   * Add hwdb.d/90-hwe-ubuntu.hwdb as a placeholder, and to serve as
     documentation.
   * Add a build-time test to check for duplicate rules between

Please feel free to push that change to the git repo directly. I'm happy to sponsor this package into Kinetic's NEW queue afterwards, for any archive-admin to pick up on.

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
diff --git a/Makefile b/Makefile
0new file mode 1006440new file mode 100644
index 0000000..bb70475
--- /dev/null
+++ b/Makefile
@@ -0,0 +1,3 @@
1.PHONY: test
2test:
3 ./tests/hwdb-redundancy
diff --git a/debian/changelog b/debian/changelog
0new file mode 1006444new file mode 100644
index 0000000..42a99df
--- /dev/null
+++ b/debian/changelog
@@ -0,0 +1,10 @@
1systemd-hwe (251.2.1) UNRELEASED; urgency=medium
2
3 * Initial release.
4 * Add hwdb.d/90-hwe-ubuntu.hwdb as a placeholder, and to serve as
5 documentation.
6 * Add a build-time test to check for duplicate rules between
7 systemd-hwe-hwdb and udev.
8 * Use test-sd-hwdb from system-tests as an autopkgtest.
9
10 -- Nick Rosbrook <nick.rosbrook@canonical.com> Wed, 06 Jul 2022 13:19:33 -0400
diff --git a/debian/control b/debian/control
0new file mode 10064411new file mode 100644
index 0000000..855daa2
--- /dev/null
+++ b/debian/control
@@ -0,0 +1,18 @@
1Source: systemd-hwe
2Section: admin
3Priority: optional
4Maintainer: Ubuntu Developers <ubuntu-devel-discuss@lists.ubuntu.com>
5Build-Depends: debhelper-compat (= 13),
6 python3-all,
7 udev (>= 251.2-2ubuntu1~),
8Standards-Version: 4.6.0
9Rules-Requires-Root: no
10Vcs-Git: https://git.launchpad.net/~canonical-foundations/+git/systemd-hwe -b main
11
12Package: systemd-hwe-hwdb
13Architecture: all
14Depends: ${misc:Depends},
15 udev,
16Description: udev rules for hardware enablement (HWE)
17 systemd-hwe-hwdb contains hwdb rules for HWE on Ubuntu,
18 which are not yet present in systemd.
diff --git a/debian/copyright b/debian/copyright
0new file mode 10064419new file mode 100644
index 0000000..76853e1
--- /dev/null
+++ b/debian/copyright
@@ -0,0 +1,24 @@
1Format: https://www.debian.org/doc/packaging-manuals/copyright-format/1.0/
2Upstream-Name: Ubuntu systemd hardware enablement (HWE)
3Source: https://git.launchpad.net/~canonical-foundations/+git/systemd-hwe
4
5Files: *
6Copyright: 2022 Canonical Ltd.
7License: GPL-2.0+
8
9License: GPL-2.0+
10 This package is free software; you can redistribute it and/or modify
11 it under the terms of the GNU General Public License as published by
12 the Free Software Foundation; either version 2 of the License, or
13 (at your option) any later version.
14 .
15 This package is distributed in the hope that it will be useful,
16 but WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 GNU General Public License for more details.
19 .
20 You should have received a copy of the GNU General Public License
21 along with this program. If not, see <https://www.gnu.org/licenses/>
22 .
23 On Debian systems, the complete text of the GNU General
24 Public License version 2 can be found in "/usr/share/common-licenses/GPL-2".
diff --git a/debian/rules b/debian/rules
0new file mode 10075525new file mode 100755
index 0000000..a5e0d78
--- /dev/null
+++ b/debian/rules
@@ -0,0 +1,4 @@
1#! /usr/bin/make -f
2
3%:
4 dh $@
diff --git a/debian/source/format b/debian/source/format
0new file mode 1006445new file mode 100644
index 0000000..89ae9db
--- /dev/null
+++ b/debian/source/format
@@ -0,0 +1 @@
13.0 (native)
diff --git a/debian/systemd-hwe-hwdb.install b/debian/systemd-hwe-hwdb.install
0new file mode 1006442new file mode 100644
index 0000000..6e78ded
--- /dev/null
+++ b/debian/systemd-hwe-hwdb.install
@@ -0,0 +1 @@
1hwdb.d/* lib/udev/hwdb.d
diff --git a/debian/systemd-hwe-hwdb.postinst b/debian/systemd-hwe-hwdb.postinst
0new file mode 1006442new file mode 100644
index 0000000..e6584d5
--- /dev/null
+++ b/debian/systemd-hwe-hwdb.postinst
@@ -0,0 +1,12 @@
1#!/bin/sh
2
3set -e
4
5case "$1" in
6 configure)
7 systemd-hwdb --usr update || true
8 exit 0
9 ;;
10esac
11
12#DEBHELPER#
diff --git a/debian/systemd-hwe-hwdb.postrm b/debian/systemd-hwe-hwdb.postrm
0new file mode 10064413new file mode 100644
index 0000000..8dc5169
--- /dev/null
+++ b/debian/systemd-hwe-hwdb.postrm
@@ -0,0 +1,12 @@
1#!/bin/sh
2
3set -e
4
5case "$1" in
6 remove|purge)
7 systemd-hwdb --usr update || true
8 exit 0
9 ;;
10esac
11
12#DEBHELPER#
diff --git a/debian/tests/control b/debian/tests/control
0new file mode 10064413new file mode 100644
index 0000000..d68bdab
--- /dev/null
+++ b/debian/tests/control
@@ -0,0 +1,6 @@
1Test-Command: /usr/lib/systemd/tests/test-sd-hwdb
2Depends: systemd-tests,
3 udev,
4 systemd-hwe-hwdb,
5Restrictions: needs-root, allow-stderr
6Features: test-name=test-sd-hwdb
diff --git a/hwdb.d/90-hwe-ubuntu.hwdb b/hwdb.d/90-hwe-ubuntu.hwdb
0new file mode 1006447new file mode 100644
index 0000000..0e023ac
--- /dev/null
+++ b/hwdb.d/90-hwe-ubuntu.hwdb
@@ -0,0 +1,11 @@
1# This file intentionally contains no hwdb rules, and serves as documentation
2# for hwdb rules shipped with systemd-hwe-hwdb.
3#
4# The systemd-hwe-hwdb package contains hwdb rules for hardware enablement
5# (HWE) on Ubuntu, which are not (yet) present in systemd. The hwdb files
6# included in systemd-hwe-hwdb follow the convention of those shipped with
7# systemd. For example, HWE hwdb rules for keyboards (if any) are defined in
8# 90-keyboard-ubuntu.hwdb.
9#
10# If no additional hwdb rules are needed for a particular systemd release, this
11# may be the only file included in systemd-hwe-hwdb.
diff --git a/tests/hwdb-redundancy b/tests/hwdb-redundancy
0new file mode 10075512new file mode 100755
index 0000000..7adade1
--- /dev/null
+++ b/tests/hwdb-redundancy
@@ -0,0 +1,82 @@
1#!/usr/bin/env python3
2# Check against current udev rules for any redundant hwdb rules.
3
4import os
5import sys
6import glob
7import subprocess
8import tempfile
9import shutil
10import unittest
11
12
13def get_modalias_list(root=''):
14 modalias_list = []
15
16 for path in glob.glob('{}/**/*.hwdb'.format(root), recursive=True):
17 with open(path, 'r') as f:
18 lines = f.readlines()
19
20 for line in lines:
21 line = str(line).rstrip()
22 if line.startswith(' ') or line.startswith('#'):
23 continue
24
25 if line in ['\n', '\r\n']:
26 continue
27
28 if not line in modalias_list:
29 modalias_list.append(line)
30
31 return modalias_list
32
33def get_hwdb_properties(modalias_list, root=None):
34 properties = {}
35
36 cmd = ['systemd-hwdb', 'query']
37 if root is not None:
38 cmd += ['--root', root]
39
40 for modalias in modalias_list:
41 output = subprocess.run(cmd + [modalias],
42 stdout=subprocess.PIPE).stdout.decode('utf-8')
43 properties[modalias] = [line for line in output.splitlines() if line]
44
45 return properties
46
47
48class RedundancyCheckTest(unittest.TestCase):
49 """ Check for hwdb rule redundancies. """
50
51 def setUp(self):
52 # Using the hwdb rules from this package, generate a hwdb.bin
53 # in a temporary directory
54 self.tmpdir = tempfile.mkdtemp(prefix='systemd-hwe-hwdb-test')
55
56 src = os.path.join(os.path.dirname(os.path.realpath(__file__)),
57 '../hwdb.d')
58 dst = os.path.join(self.tmpdir, 'etc/udev/hwdb.d')
59 shutil.copytree(src, dst)
60 p = subprocess.run(['systemd-hwdb', 'update', '--root', self.tmpdir],
61 stdout=subprocess.PIPE, stderr=subprocess.PIPE)
62 self.assertEqual(p.returncode, 0)
63 self.assertEqual(p.stderr, b'', 'hwdb rules produced warnings')
64
65 def tearDown(self):
66 shutil.rmtree(self.tmpdir)
67
68 def test_no_duplicates(self):
69 modalias_list = get_modalias_list(root=self.tmpdir)
70 existing_hwdb_props = get_hwdb_properties(modalias_list)
71 new_hwdb_props = get_hwdb_properties(modalias_list, root=self.tmpdir)
72
73 for modalias in modalias_list:
74 intersection = list(set(existing_hwdb_props[modalias]) &
75 set(new_hwdb_props[modalias]))
76 self.assertEqual([], intersection,
77 'Duplicate hwdb rules for {}'.format(modalias))
78
79
80if __name__ == '__main__':
81 unittest.main(testRunner=unittest.TextTestRunner(stream=sys.stdout,
82 verbosity=2))

Subscribers

People subscribed via source and target branches