#636 Allow product version matching by subject ID
Merged 2 years ago by lholecek. Opened 2 years ago by lholecek.
lholecek/greenwave product-version-match  into  master

@@ -4,3 +4,6 @@ 

  item_dict:

    # {"productmd.compose.id": ITEM}

    item_key: "productmd.compose.id"

+ product_version_match:

+   - match: '^(RHEL-\d*)\..*'

maybe it's better to use lower case there, as you are lowering the case in the code

+     product_version: '\1'

@@ -1,5 +1,7 @@ 

  # SPDX-License-Identifier: GPL-2.0+

  

+ import re

+ 

  

  def _to_dict(format_dict, item):

      result = {}
@@ -61,6 +63,11 @@ 

  

      @property

      def product_version(self):

+         for pv_match in self._type.product_version_match:

+             pv = re.sub(pv_match['match'], pv_match['product_version'], self.item)

+             if pv and pv != self.item:

+                 return pv.lower()

+ 

          return self._type.product_version

  

      @property

@@ -40,6 +40,14 @@ 

          # Omit responding with HTTP 404 if there is no applicable policy.

          'ignore_missing_policy': SafeYAMLBool(optional=True, default=False),

  

+         # List of dicts. Each dict must have:

+         # - 'match' field containing regular expression to match subject ID

+         # - 'product_version' field containing product version (can contain

+         #   '\1', '\2' etc, expanded to matched groups)

+         'product_version_match': SafeYAMLList(item_type=dict, optional=True),

+ 

+         # Fixed product version for the subject type used if

+         # product_version_match is undefined or does not match subject ID.

          'product_version': SafeYAMLString(optional=True),

  

          # Serialization dict for decision.

@@ -65,3 +65,14 @@ 

  def test_subject_to_repr_generic(app):

      subject = create_subject('some_type', 'some_nvr')

      assert repr(subject) == "Subject(<GenericSubjectType 'some_type'>, 'some_nvr')"

+ 

+ 

+ @pytest.mark.parametrize('compose, expected_product_version', (

+     ('RHEL-8.5.0-20210101.d.1', 'rhel-8'),

+     ('RHEL-9.0.0-20210101.d.2', 'rhel-9'),

+     ('FEDORA-2021-35759ad8d3', None),

+ ))

+ def test_subject_product_version_match(compose, expected_product_version, app):

+     subject = create_subject('compose', compose)

+     assert subject._type.product_version_match

+     assert subject.product_version == expected_product_version, compose

maybe it's better to use lower case there, as you are lowering the case in the code

maybe it's better to use lower case there, as you are lowering the case in the code

This tries to match the original item/subject-ID which is upper-case for compose. The lower case transformation is done after match.

rebased onto d7685c17399a963c48939a6fda10513f83fa9859

2 years ago

rebased onto 1c4a085

2 years ago

I'm merging this. Feel free to review next week.

Pull-Request has been merged by lholecek

2 years ago

compare https://pagure.io/greenwave/pull-request/633 , where I suggested something similar but we decided not to do it as you can just use the existing fnmatch matching...I'm not clear on the exact real-world case here, but would that not have worked for it too?

compare https://pagure.io/greenwave/pull-request/633 , where I suggested something similar but we decided not to do it as you can just use the existing fnmatch matching...I'm not clear on the exact real-world case here, but would that not have worked for it too?

This different. This patch is for Greenwave to figure out from a test result message what is the product version for a subject ID for a specific subject type.

In this case it is required for internal composes which are named "RHEL-X.Y.Z...".