#391 Fix the deduplication code when `conf.lightblue_released_dependencies_only = True`.
Merged by lucarval. Opened by jkaluza.
jkaluza/freshmaker models-fix  into  master

Download 391.patch

This is follow-up of https://pagure.io/freshmaker/pull-request/388.

In that PR, we fixed deduplication code for case when image changed
its parent image completely within the same version but different
release.

The issue is that this works only when lightblue_released_dependencies_only
is set to False. In case it is set to True, the latest_released_nvr_index
is set to -1 indicating that the deduplication code should replace all
the images with latest release version (so in case the image is released
but based on the unreleased image, we move it back to released release
of that parent image).

When latest_released_nvr_index is -1, the current code to set latest_image
is simply broken, because it does latest_image = nvr_to_image[nvrs[latest_released_nvr_index]]
and therefore effectively sets the latest_image to the oldest image (nvrs[-1]).

This commit fixes this issue.

It also removes n_to_nvs which is not used anymore and one try/except
block which has been forgotten there from times when n_to_nvs was used.

This will raise ValueError if latest_released_nvr is not in nvrs list. Is that no longer a valid use case?

Maybe consider this:

latest_released_nvr_index = -1
if not conf.lightblue_released_dependencies_only:
  try:
    latest_released_nvr_index = nvrs.index(latest_released_nvr)
  except ValueError:
    pass

@lucarval, that's no longer the valid use-case. Previously, there was special code to handle foo-docker to foo-container in a way that if foo-docker image was always replaced by foo-container image. But that code has been removed in the PR#388.

In the current code, the latest_release_nvr is always something from nvrs list.

To give you an example, in the previous, removed, code, the latest_released_nvr could be foo-container-1-15 while the nvrs was list like ["foo-docker-1-13", "foo-docker-1-14"]. But the code which actually allows setting NVR outside of nvrs as latest_released_nvr has been removed.

:thumbsup: Thanks for clarifying!

Pull-Request has been merged by lucarval

Metadata