#451 Fix matching some wrong product versions
Merged 4 years ago by lholecek. Opened 4 years ago by lholecek.
lholecek/greenwave fix-product-version-match  into  master

@@ -46,7 +46,7 @@ 

          product_version = 'fedora-'

      elif toparse.startswith('epel'):

          product_version = 'epel-'

-     elif toparse.startswith('el'):

+     elif toparse.startswith('el') and len(toparse) > 2 and toparse[2].isdigit():

          product_version = 'rhel-'

      elif toparse.startswith('fc') or toparse.startswith('Fedora'):

          product_version = 'fedora-'
@@ -69,9 +69,10 @@ 

  def _subject_product_version(subject_identifier, subject_type, koji_proxy=None):

      if subject_type == 'koji_build':

          try:

-             short_prod_version = subject_identifier.split('.')[-1]

+             _, _, release = subject_identifier.rsplit('-', 2)

+             _, short_prod_version = release.rsplit('.', 1)

              return _guess_product_version(short_prod_version, koji_build=True)

-         except KeyError:

+         except (KeyError, ValueError):

              pass

  

      if subject_type == "compose":

@@ -346,6 +346,17 @@ 

      assert product_version == 'fedora-rawhide'

  

  

+ @pytest.mark.parametrize('nvr', (

+     'badnvr.elastic-1-228',

+     'badnvr-1.2-1.elastic8',

+     'el99',

+     'badnvr-1.2.f30',

+ ))

+ def test_guess_product_version_failure(nvr):

+     product_version = greenwave.consumers.resultsdb._subject_product_version(nvr, 'koji_build')

+     assert product_version is None

+ 

+ 

  @pytest.mark.parametrize("config,publish", parameters)

  @mock.patch('greenwave.resources.ResultsRetriever.retrieve')

  @mock.patch('greenwave.resources.retrieve_decision')

I don't understand how this is any different.

I believe what you want is to first separate release from the NVR, then split the release by '.'

release = subject_identifier.rsplit('-', 2)[-1]
if '.' not in release:
  return None
short_prod_version = release.split('.')[-1]
return _guess_product_version(short_prod_version, koji_build=True)

rebased onto 980d4cc0078dbd06afef6abe83185ecf1934add5

4 years ago

Updated.

Please provide some (obfuscated) real-world examples where it would fail, if you know any.

Can we avoid to set the product_version to None? Can't we use "*" or something like that?
None really seems an error/bug. Someone in the team in the past came to me asking me "why I see None in the logs? It's a bug!"

Can we avoid to set the product_version to None?

@gnaponie How about PR#453?

oh, why "_"? :( can we use a more meaningful "term"?

beside one comment, it looks good! Even though... conflicts need to be resolved.

'_' is used as a "don't care" variable name. In this case, the split should produce 3 items, and only the one is interesting. Although the line above could be identical to:

release = subject_identifier.rsplit('-', 2)[-1]

Oh I see. Didn't know that. In this case, either options are fine.
@lholecek the PR looks fine. Once resolved the conflict I think is good to go.

rebased onto 2634851a2a822059f0e724d9fc004b26f0c3ccda

4 years ago

Resolved the conflicts. @lucarval Can you review again pls?

rebased onto a6fb855

4 years ago

'_' is used as a "don't care" variable name. In this case, the split should produce 3 items, and only the one is interesting. Although the line above could be identical to:
release = subject_identifier.rsplit('-', 2)[-1]

BTW, this is not the same as "tuple unpacking".

>>> a, b, c = 'a-b'.rsplit('-', 2)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ValueError: not enough values to unpack (expected 3, got 2)

But the following doesn't ensure that there are three components.

>>> c = 'a-b'.rsplit('-', 2)[-1]
>>> c
'b'

Pull-Request has been merged by lholecek

4 years ago