diff --git a/checkbox-ng/plainbox/impl/unit/packaging.py b/checkbox-ng/plainbox/impl/unit/packaging.py index 9664734c7..3e40d5ef8 100644 --- a/checkbox-ng/plainbox/impl/unit/packaging.py +++ b/checkbox-ng/plainbox/impl/unit/packaging.py @@ -115,6 +115,8 @@ import abc import errno import logging +from packaging import version +import operator import re import shlex import sys @@ -295,37 +297,6 @@ def modify_packaging_tree(self) -> None: """ -def _strategy_id_version(unit, os_release): - _logger.debug(_("Considering strategy: %s"), - _("os-id == ID and os-version-id == VERSION_ID")) - return ( - 'ID' in os_release and - unit.os_id == os_release['ID'] and - 'VERSION_ID' in os_release and - unit.os_version_id == os_release['VERSION_ID'] - ) - - -def _strategy_id(unit, os_release): - _logger.debug(_("Considering strategy: %s"), - _("os-id == ID and os-version-id == undefined")) - return ( - 'ID' in os_release and - unit.os_id == os_release['ID'] and - unit.os_version_id is None - ) - - -def _strategy_id_like(unit, os_release): - _logger.debug(_("Considering strategy: %s"), - _("os-id == ID_LIKE and os-version-id == undefined")) - return ( - 'ID_LIKE' in os_release and - unit.os_id == os_release['ID_LIKE'] and - unit.os_version_id is None - ) - - class PackagingDriverBase(IPackagingDriver): """Base implementation of a packaging driver.""" @@ -334,22 +305,82 @@ def __init__(self, os_release: 'Dict[str, str]'): self.os_release = os_release def is_applicable(self, unit: Unit) -> bool: - os_release = self.os_release if unit.Meta.name != PackagingMetaDataUnit.Meta.name: return False - if (not _strategy_id_version(unit, os_release) and not - _strategy_id(unit, os_release) and not - _strategy_id_like(unit, os_release)): - _logger.debug(_("All strategies unsuccessful")) - return False - _logger.debug(_("Last strategy was successful")) - return True + + # Check each strategy and log accordingly + if self._is_id_version_match(unit): + _logger.debug(_("Strategy successful: ID and Version ID match")) + return True + if self._is_id_match(unit): + _logger.debug(_("Strategy successful: ID match, no Version ID required")) + return True + if self._is_id_like_match(unit): + _logger.debug(_("Strategy successful: ID_LIKE match, no Version ID required")) + return True + + _logger.debug(_("All strategies unsuccessful")) + return False def inspect_provider(self, provider: 'Provider1') -> None: for unit in provider.unit_list: if self.is_applicable(unit): self.collect(unit) + def _is_id_version_match(self, unit): + if not unit.os_version_id: + return False + return ( + 'ID' in self.os_release and + unit.os_id == self.os_release['ID'] and + 'VERSION_ID' in self.os_release and + self._compare_versions(unit.os_version_id, self.os_release['VERSION_ID']) + ) + + def _is_id_match(self, unit): + return ( + 'ID' in self.os_release and + unit.os_id == self.os_release['ID'] and + unit.os_version_id is None + ) + + def _is_id_like_match(self, unit): + return ( + 'ID_LIKE' in self.os_release and + unit.os_id == self.os_release['ID_LIKE'] and + unit.os_version_id is None + ) + + @staticmethod + def _compare_versions(comparison_str, system_version): + # Extract the operator and the version from the comparison string + # Make the operator optional and default to '==' + match = re.match( + r"^\s*(==|>=|<=|>|<|!=)?\s*([\d\.a-zA-Z]+)\s*$", comparison_str + ) + + if not match: + raise SystemExit( + "Invalid version comparison string: {}".format(comparison_str) + ) + operator_match, version_match = match.groups() + + # Default to '==' if no operator is provided + operators = { + None: operator.eq, + '==': operator.eq, + '>=': operator.ge, + '<=': operator.le, + '>': operator.gt, + '<': operator.lt, + '!=': operator.ne + } + + system_ver = version.parse(system_version) + target_ver = version.parse(version_match) + + return operators[operator_match](system_ver, target_ver) + class NullPackagingDriver(PackagingDriverBase): diff --git a/checkbox-ng/plainbox/impl/unit/test_packaging.py b/checkbox-ng/plainbox/impl/unit/test_packaging.py new file mode 100644 index 000000000..e227bbc2d --- /dev/null +++ b/checkbox-ng/plainbox/impl/unit/test_packaging.py @@ -0,0 +1,302 @@ +# This file is part of Checkbox. +# +# Copyright 2015 Canonical Ltd. +# Written by: +# Zygmunt Krynicki +# +# Checkbox is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License version 3, +# as published by the Free Software Foundation. +# +# Checkbox 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 General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with Checkbox. If not, see . + +"""Tests for the PackagingMetaDataUnit and friends.""" + +from unittest import TestCase +import textwrap + +from plainbox.impl.unit.packaging import DebianPackagingDriver +from plainbox.impl.unit.packaging import PackagingDriverBase +from plainbox.impl.unit.packaging import PackagingMetaDataUnit +from plainbox.impl.secure.rfc822 import load_rfc822_records + + +class DebianPackagingDriverTests(TestCase): + + """Tests for the DebianPackagingDriver class.""" + + empty_driver = DebianPackagingDriver({}) + debian_jessie_driver = DebianPackagingDriver( + { + "PRETTY_NAME": "Debian GNU/Linux 8 (jessie)", + "NAME": "Debian GNU/Linux", + "VERSION_ID": "8", + "VERSION": "8 (jessie)", + "ID": "debian", + "HOME_URL": "http://www.debian.org/", + "SUPPORT_URL": "http://www.debian.org/support/", + "BUG_REPORT_URL": "https://bugs.debian.org/", + } + ) + + debian_sid_driver = DebianPackagingDriver( + { + "PRETTY_NAME": "Debian GNU/Linux stretch/sid", + "NAME": "Debian GNU/Linux", + "ID": "debian", + "HOME_URL": "https://www.debian.org/", + "SUPPORT_URL": "https://www.debian.org/support/", + "BUG_REPORT_URL": "https://bugs.debian.org/", + } + ) + + ubuntu_vivid_driver = DebianPackagingDriver( + { + "NAME": "Ubuntu", + "VERSION": "15.04 (Vivid Vervet)", + "ID": "ubuntu", + "ID_LIKE": "debian", + "PRETTY_NAME": "Ubuntu 15.04", + "VERSION_ID": "15.04", + "HOME_URL": "http://www.ubuntu.com/", + "SUPPORT_URL": "http://help.ubuntu.com/", + "BUG_REPORT_URL": "http://bugs.launchpad.net/ubuntu/", + } + ) + + ubuntu_focal_driver = DebianPackagingDriver( + { + "NAME": "Ubuntu", + "ID": "ubuntu", + "ID_LIKE": "debian", + "VERSION_ID": "20.04", + } + ) + + ubuntu_jammy_driver = DebianPackagingDriver( + { + "NAME": "Ubuntu", + "ID": "ubuntu", + "ID_LIKE": "debian", + "VERSION_ID": "22.04", + } + ) + + debian_unit = PackagingMetaDataUnit({"os-id": "debian"}) + debian_8_unit = PackagingMetaDataUnit( + {"os-id": "debian", "os-version-id": "8"} + ) + ubuntu_unit = PackagingMetaDataUnit({"os-id": "ubuntu"}) + ubuntu_15_unit = PackagingMetaDataUnit( + {"os-id": "ubuntu", "os-version-id": "15.04"} + ) + ubuntu_22_unit = PackagingMetaDataUnit( + {"os-id": "ubuntu", "os-version-id": "22.04"} + ) + fedora_unit = PackagingMetaDataUnit( + {"os-id": "fedora", "os-version-id": "33"} + ) + + def test_fix_1476678(self): + """Check https://bugs.launchpad.net/plainbox/+bug/1476678.""" + driver = DebianPackagingDriver({}) + driver.collect( + PackagingMetaDataUnit( + { + "Depends": ( + "python3-checkbox-support (>= 0.2),\n" + "python3 (>= 3.2),\n" + ), + "Recommends": ( + "dmidecode,\n" + "dpkg (>= 1.13),\n" + "lsb-release,\n" + "wodim" + ), + } + ) + ) + self.assertEqual( + driver._depends, + ["python3-checkbox-support (>= 0.2)", "python3 (>= 3.2)"], + ) + self.assertEqual( + driver._recommends, + ["dmidecode", "dpkg (>= 1.13)", "lsb-release", "wodim"], + ) + self.assertEqual(driver._suggests, []) + + def test_fix_1477095(self): + """Check https://bugs.launchpad.net/plainbox/+bug/1477095.""" + + # This unit should apply for Debian (any version) and derivatives. + # Note below that id match lets both Debian Jessie and Debian Sid pass + # and that id_like match also lets Ubuntu Vivid pass. + unit = self.debian_unit + self.assertFalse(self.empty_driver.is_applicable(unit)) + self.assertTrue(self.debian_sid_driver.is_applicable(unit)) + self.assertTrue(self.debian_jessie_driver.is_applicable(unit)) + self.assertTrue(self.ubuntu_vivid_driver.is_applicable(unit)) + + # This unit should apply for Debian Jessie only. Note below that + # only Debian Jessie is passed and only by id and version match. + # Nothing else is allowed. + unit = self.debian_8_unit + self.assertFalse(self.empty_driver.is_applicable(unit)) + self.assertFalse(self.debian_sid_driver.is_applicable(unit)) + self.assertTrue(self.debian_jessie_driver.is_applicable(unit)) + self.assertFalse(self.ubuntu_vivid_driver.is_applicable(unit)) + + # This unit should apply for Ubuntu (any version) and derivatives. + # Note that None of the Debian versions pass anymore and the only + # version that is allowed here is the one Vivid version we test for. + # (If there was an Elementary test here it would have passed as well, I + # hope). + unit = self.ubuntu_unit + self.assertFalse(self.empty_driver.is_applicable(unit)) + self.assertFalse(self.debian_sid_driver.is_applicable(unit)) + self.assertFalse(self.debian_jessie_driver.is_applicable(unit)) + self.assertTrue(self.ubuntu_vivid_driver.is_applicable(unit)) + self.assertTrue(self.ubuntu_focal_driver.is_applicable(unit)) + + # This unit should apply for Ubuntu Vivid only. Note that it behaves + # exactly like the Debian Jessie test above. Only Ubuntu Vivid is + # passed and only by the id and version match. + unit = self.ubuntu_15_unit + self.assertFalse(self.empty_driver.is_applicable(unit)) + self.assertFalse(self.debian_sid_driver.is_applicable(unit)) + self.assertFalse(self.debian_jessie_driver.is_applicable(unit)) + self.assertTrue(self.ubuntu_vivid_driver.is_applicable(unit)) + self.assertFalse(self.ubuntu_focal_driver.is_applicable(unit)) + + def test_id_match(self): + driver = self.ubuntu_jammy_driver + # It outputs true for the same id and no version is specified + self.assertTrue(driver._is_id_match(self.ubuntu_unit)) + # It outputs false for different id + self.assertFalse(driver._is_id_match(self.debian_unit)) + # It outputs false for the same id and some version is specified + self.assertFalse(driver._is_id_match(self.ubuntu_15_unit)) + # It outputs false with no id + self.assertFalse(self.empty_driver._is_id_match(self.ubuntu_unit)) + + def test_id_like_match(self): + driver = self.ubuntu_jammy_driver + # It outputs true for the id_like id and no version is specified + self.assertTrue(driver._is_id_like_match(self.debian_unit)) + # It outputs false for different id_like id + self.assertFalse(driver._is_id_like_match(self.fedora_unit)) + # It outputs false for the same id and some version is specified + self.assertFalse(driver._is_id_like_match(self.debian_8_unit)) + # It outputs false with no id + self.assertFalse(self.empty_driver._is_id_like_match(self.ubuntu_unit)) + + def test_id_version_match(self): + driver = self.ubuntu_jammy_driver + # It outputs true for the same id and version + self.assertTrue(driver._is_id_version_match(self.ubuntu_22_unit)) + # It outputs false for the same id and different version + self.assertFalse(driver._is_id_version_match(self.ubuntu_15_unit)) + # It outputs false with no version + self.assertFalse(driver._is_id_version_match(self.ubuntu_unit)) + + def test_package_with_comparision(self): + unit = PackagingMetaDataUnit( + {"os-id": "ubuntu", "os-version-id": ">=20.04"} + ) + # Using id and version match + self.assertTrue(self.ubuntu_jammy_driver.is_applicable(unit)) + self.assertTrue(self.ubuntu_focal_driver.is_applicable(unit)) + self.assertFalse(self.ubuntu_vivid_driver.is_applicable(unit)) + self.assertFalse(self.debian_jessie_driver.is_applicable(unit)) + + def test_read_os_version_from_text(self): + file_content = textwrap.dedent( + """\ + unit: packaging meta-data + os-id: ubuntu + os-version-id: >=20.04 + Depends: python3-opencv + """ + ) + + record = load_rfc822_records(file_content)[0] + unit = PackagingMetaDataUnit.from_rfc822_record(record) + + self.assertFalse(self.ubuntu_vivid_driver.is_applicable(unit)) + self.assertTrue(self.ubuntu_focal_driver.is_applicable(unit)) + self.assertTrue(self.ubuntu_jammy_driver.is_applicable(unit)) + + def test_read_os_version_comparison_from_text(self): + file_content = textwrap.dedent( + """\ + unit: packaging meta-data + os-id: ubuntu + os-version-id: 20.04 + Depends: python3-opencv + """ + ) + + record = load_rfc822_records(file_content)[0] + unit = PackagingMetaDataUnit.from_rfc822_record(record) + + self.assertFalse(self.ubuntu_vivid_driver.is_applicable(unit)) + self.assertTrue(self.ubuntu_focal_driver.is_applicable(unit)) + self.assertFalse(self.ubuntu_jammy_driver.is_applicable(unit)) + + def test_compare_versions(self): + compare_versions = PackagingDriverBase._compare_versions + # equal operator + self.assertTrue(compare_versions("== 1.0.0", "1.0.0")) + self.assertFalse(compare_versions("== 1.0.1", "1.0.0")) + + self.assertTrue(compare_versions("1.0.0", "1.0.0")) + self.assertFalse(compare_versions("1.0.1", "1.0.0")) + + # greater than operator + self.assertTrue(compare_versions("> 1.1.9", "1.2.0")) + self.assertFalse(compare_versions("> 1.0.0", "1.0.0")) + + # greater than or equal operator + self.assertTrue(compare_versions(">= 1.0.0", "1.0.0")) + self.assertTrue(compare_versions(">= 1.0.0", "1.1.0")) + self.assertFalse(compare_versions(">= 1.0.0", "0.9.9")) + + # less than operator + self.assertTrue(compare_versions("< 1.0.0", "0.9.9")) + self.assertFalse(compare_versions("< 1.0.0", "1.0.0")) + + # less than or equal operator + self.assertTrue(compare_versions("<= 1.0.0", "1.0.0")) + self.assertTrue(compare_versions("<= 1.0.0", "0.9.9")) + + # not equal operator + self.assertTrue(compare_versions("!= 1.0.0", "1.0.1")) + self.assertFalse(compare_versions("!= 1.0.0", "1.0.0")) + + def test_malformed_versions(self): + compare_versions = PackagingDriverBase._compare_versions + + # Using just one equal operator + with self.assertRaises(SystemExit) as context: + compare_versions("= 1.0.0", "1.0.0") + self.assertIn("= 1.0.0", str(context.exception)) + + # Using a bad operator + with self.assertRaises(SystemExit) as context: + compare_versions("!!== 1.0.0", "1.0.0") + self.assertIn("!! == 1.0.0", str(context.exception)) + + # Using composed operators + with self.assertRaises(SystemExit) as context: + compare_versions(">=1.0.0, <=2.0.0", "1.0.0") + + # Using wrong version format + with self.assertRaises(SystemExit) as context: + compare_versions("== ***", "1.0.0") diff --git a/checkbox-ng/plainbox/impl/unit/test_packging.py b/checkbox-ng/plainbox/impl/unit/test_packging.py deleted file mode 100644 index 3ba388818..000000000 --- a/checkbox-ng/plainbox/impl/unit/test_packging.py +++ /dev/null @@ -1,180 +0,0 @@ -# This file is part of Checkbox. -# -# Copyright 2015 Canonical Ltd. -# Written by: -# Zygmunt Krynicki -# -# Checkbox is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License version 3, -# as published by the Free Software Foundation. -# -# Checkbox 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 General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with Checkbox. If not, see . - -"""Tests for the PackagingMetaDataUnit and friends.""" - -from unittest import TestCase - -from plainbox.impl.unit.packaging import DebianPackagingDriver -from plainbox.impl.unit.packaging import PackagingMetaDataUnit -from plainbox.impl.unit.packaging import _strategy_id -from plainbox.impl.unit.packaging import _strategy_id_like -from plainbox.impl.unit.packaging import _strategy_id_version - - -class DebianPackagingDriverTests(TestCase): - - """Tests for the DebianPackagingDriver class.""" - - DEBIAN_JESSIE = { - 'PRETTY_NAME': "Debian GNU/Linux 8 (jessie)", - 'NAME': "Debian GNU/Linux", - 'VERSION_ID': "8", - 'VERSION': "8 (jessie)", - 'ID': 'debian', - 'HOME_URL': "http://www.debian.org/", - 'SUPPORT_URL': "http://www.debian.org/support/", - 'BUG_REPORT_URL': "https://bugs.debian.org/", - } - - DEBIAN_SID = { - 'PRETTY_NAME': "Debian GNU/Linux stretch/sid", - 'NAME': "Debian GNU/Linux", - 'ID': 'debian', - 'HOME_URL': "https://www.debian.org/", - 'SUPPORT_URL': "https://www.debian.org/support/", - 'BUG_REPORT_URL': "https://bugs.debian.org/", - } - - UBUNTU_VIVID = { - 'NAME': "Ubuntu", - 'VERSION': "15.04 (Vivid Vervet)", - 'ID': 'ubuntu', - 'ID_LIKE': 'debian', - 'PRETTY_NAME': "Ubuntu 15.04", - 'VERSION_ID': "15.04", - 'HOME_URL': "http://www.ubuntu.com/", - 'SUPPORT_URL': "http://help.ubuntu.com/", - 'BUG_REPORT_URL': "http://bugs.launchpad.net/ubuntu/", - } - - def test_fix_1476678(self): - """Check https://bugs.launchpad.net/plainbox/+bug/1476678.""" - driver = DebianPackagingDriver({}) - driver.collect(PackagingMetaDataUnit({ - 'Depends': ( - 'python3-checkbox-support (>= 0.2),\n' - 'python3 (>= 3.2),\n'), - 'Recommends': ( - 'dmidecode,\n' - 'dpkg (>= 1.13),\n' - 'lsb-release,\n' - 'wodim') - })) - self.assertEqual(driver._depends, [ - 'python3-checkbox-support (>= 0.2)', - 'python3 (>= 3.2)', - ]) - self.assertEqual(driver._recommends, [ - 'dmidecode', - 'dpkg (>= 1.13)', - 'lsb-release', - 'wodim' - ]) - self.assertEqual(driver._suggests, []) - - def test_fix_1477095(self): - """Check https://bugs.launchpad.net/plainbox/+bug/1477095.""" - # This unit is supposed to for Debian (any version) and derivatives. - # Note below that id match lets both Debian Jessie and Debian Sid pass - # and that id_like match also lets Ubuntu Vivid pass. - unit = PackagingMetaDataUnit({ - 'os-id': 'debian', - }) - # Using id and version match - self.assertFalse(_strategy_id_version(unit, {})) - self.assertFalse(_strategy_id_version(unit, self.DEBIAN_SID)) - self.assertFalse(_strategy_id_version(unit, self.DEBIAN_JESSIE)) - self.assertFalse(_strategy_id_version(unit, self.UBUNTU_VIVID)) - # Using id match - self.assertFalse(_strategy_id(unit, {})) - self.assertTrue(_strategy_id(unit, self.DEBIAN_SID)) - self.assertTrue(_strategy_id(unit, self.DEBIAN_JESSIE)) - self.assertFalse(_strategy_id(unit, self.UBUNTU_VIVID)) - # Using id like - self.assertFalse(_strategy_id_like(unit, {})) - self.assertFalse(_strategy_id_like(unit, self.DEBIAN_SID)) - self.assertFalse(_strategy_id_like(unit, self.DEBIAN_JESSIE)) - self.assertTrue(_strategy_id_like(unit, self.UBUNTU_VIVID)) - # This unit is supposed to for Debian Jessie only. Note below that - # only Debian Jessie is passed and only by id and version match. - # Nothing else is allowed. - unit = PackagingMetaDataUnit({ - 'os-id': 'debian', - 'os-version-id': '8' - }) - # Using id and version match - self.assertFalse(_strategy_id_version(unit, {})) - self.assertFalse(_strategy_id_version(unit, self.DEBIAN_SID)) - self.assertTrue(_strategy_id_version(unit, self.DEBIAN_JESSIE)) - self.assertFalse(_strategy_id_version(unit, self.UBUNTU_VIVID)) - # Using id match - self.assertFalse(_strategy_id(unit, {})) - self.assertFalse(_strategy_id(unit, self.DEBIAN_SID)) - self.assertFalse(_strategy_id(unit, self.DEBIAN_JESSIE)) - self.assertFalse(_strategy_id(unit, self.UBUNTU_VIVID)) - # Using id like - self.assertFalse(_strategy_id_like(unit, {})) - self.assertFalse(_strategy_id_like(unit, self.DEBIAN_SID)) - self.assertFalse(_strategy_id_like(unit, self.DEBIAN_JESSIE)) - self.assertFalse(_strategy_id_like(unit, self.UBUNTU_VIVID)) - # This unit is supposed to for Ubuntu (any version) and derivatives. - # Note that None of the Debian versions pass anymore and the only - # version that is allowed here is the one Vivid version we test for. - # (If there was an Elementary test here it would have passed as well, I - # hope). - unit = PackagingMetaDataUnit({ - 'os-id': 'ubuntu', - }) - # Using id and version match - self.assertFalse(_strategy_id_version(unit, {})) - self.assertFalse(_strategy_id_version(unit, self.DEBIAN_SID)) - self.assertFalse(_strategy_id_version(unit, self.DEBIAN_JESSIE)) - self.assertFalse(_strategy_id_version(unit, self.UBUNTU_VIVID)) - # Using id match - self.assertFalse(_strategy_id(unit, {})) - self.assertFalse(_strategy_id(unit, self.DEBIAN_SID)) - self.assertFalse(_strategy_id(unit, self.DEBIAN_JESSIE)) - self.assertTrue(_strategy_id(unit, self.UBUNTU_VIVID)) - # Using id like - self.assertFalse(_strategy_id_like(unit, {})) - self.assertFalse(_strategy_id_like(unit, self.DEBIAN_SID)) - self.assertFalse(_strategy_id_like(unit, self.DEBIAN_JESSIE)) - self.assertFalse(_strategy_id_like(unit, self.UBUNTU_VIVID)) - # This unit is supposed to for Ubuntu Vivid only. Note that it behaves - # exactly like the Debian Jessie test above. Only Ubuntu Vivid is - # passed and only by the id and version match. - unit = PackagingMetaDataUnit({ - 'os-id': 'ubuntu', - 'os-version-id': '15.04' - }) - # Using id and version match - self.assertFalse(_strategy_id_version(unit, {})) - self.assertFalse(_strategy_id_version(unit, self.DEBIAN_SID)) - self.assertFalse(_strategy_id_version(unit, self.DEBIAN_JESSIE)) - self.assertTrue(_strategy_id_version(unit, self.UBUNTU_VIVID)) - # Using id match - self.assertFalse(_strategy_id(unit, {})) - self.assertFalse(_strategy_id(unit, self.DEBIAN_SID)) - self.assertFalse(_strategy_id(unit, self.DEBIAN_JESSIE)) - self.assertFalse(_strategy_id(unit, self.UBUNTU_VIVID)) - # Using id like - self.assertFalse(_strategy_id_like(unit, {})) - self.assertFalse(_strategy_id_like(unit, self.DEBIAN_SID)) - self.assertFalse(_strategy_id_like(unit, self.DEBIAN_JESSIE)) - self.assertFalse(_strategy_id_like(unit, self.UBUNTU_VIVID)) diff --git a/docs/reference/units/packaging-meta-data.rst b/docs/reference/units/packaging-meta-data.rst index 69d5c378f..cf0c250ad 100644 --- a/docs/reference/units/packaging-meta-data.rst +++ b/docs/reference/units/packaging-meta-data.rst @@ -37,6 +37,11 @@ Following fields may be used by a manifest entry unit. file ``/etc/os-release``. If this field is not present then the rule applies to all versions of a given operating system. + It is also possible to specify a version comparison operator, such as + ``>=`` or ``<=``. This is useful when a rule applies to a range of versions. + For example, ``os-version-id: >= 20.04`` will match all versions of Ubuntu + greater than or equal to 20.04. + The remaining fields are custom and depend on the packaging driver. The values for **Debian** are: @@ -85,8 +90,8 @@ derivatives, like Ubuntu. Each matching packaging meta-data unit is then passed to the driver to generate packaging meta-data. -Example -------- +Examples +-------- This is an example packaging meta-data unit, as taken from the resource provider:: @@ -107,6 +112,15 @@ version of ``python3-checkbox-support`` and ``python3`` in both *Debian*, recommend some utilities that are used by some of the jobs contained in this provider. +If we want a version of the package to be available in Ubuntu 20.04 or newer, +we can use the following packaging meta-data unit:: + + unit: packaging meta-data + os-id: ubuntu + os-version-id: >= 20.04 + Depends: libsvm3 + + Using Packaging Meta-Data in Debian ----------------------------------- diff --git a/providers/base/units/camera/jobs.pxu b/providers/base/units/camera/jobs.pxu index 658412242..2734ad114 100644 --- a/providers/base/units/camera/jobs.pxu +++ b/providers/base/units/camera/jobs.pxu @@ -117,7 +117,7 @@ flags: also-after-suspend _summary: Webcam brisque score for {{ product_slug }} estimated_duration: 20s depends: camera/detect -requires: lsb.release == '22.04' +requires: lsb.release >= '22.04' command: timeout 120 camera_quality_test.py -d {{ name }} || (>&2 echo "Timeout computing score"; false) diff --git a/providers/base/units/camera/packaging.pxu b/providers/base/units/camera/packaging.pxu index 8a8b89d8e..d1f83c31d 100644 --- a/providers/base/units/camera/packaging.pxu +++ b/providers/base/units/camera/packaging.pxu @@ -16,11 +16,11 @@ Depends: python3-pyqrcode # For camera/camera-quality_.* unit: packaging meta-data os-id: ubuntu -os-version-id: 22.04 +os-version-id: >= 22.04 Depends: libsvm3 # For camera/camera-quality_.* unit: packaging meta-data os-id: ubuntu -os-version-id: 22.04 +os-version-id: >= 22.04 Depends: python3-opencv diff --git a/providers/base/units/graphics/packaging.pxu b/providers/base/units/graphics/packaging.pxu index a81bc13b5..fa2a3ab3b 100644 --- a/providers/base/units/graphics/packaging.pxu +++ b/providers/base/units/graphics/packaging.pxu @@ -1,6 +1,6 @@ unit: packaging meta-data os-id: ubuntu -os-version-id: 22.04 +os-version-id: >= 22.04 Depends: gnome-randr unit: packaging meta-data