Skip to content

Commit

Permalink
Replace usage of _pulp_client with pubtools-pulplib [RHELDST-141]
Browse files Browse the repository at this point in the history
This commit removes the library's native _pulp_client ("legacy") and
replaces it with usage of pubtools-pulplib methods for associating and
unassociating content.

Additionally, PulpActions were replaced with simple abstractions for
grouping content to be associated/unassociated.

Tests were removed/edited as necessary.
  • Loading branch information
negillett committed Mar 26, 2024
1 parent 13ab604 commit dbab9ae
Show file tree
Hide file tree
Showing 7 changed files with 325 additions and 1,281 deletions.
108 changes: 28 additions & 80 deletions tests/integration/test_association.py
Original file line number Diff line number Diff line change
@@ -1,24 +1,22 @@
import json
import logging
import os
import subprocess
import logging

import pytest
import requests
import ubiconfig
import ubipop
import json

from ubipop._pulp_client import Pulp
from ubipop.ubi_manifest_client.client import Client

from pubtools.pulplib import (
Client,
Criteria,
Matcher,
ModulemdDefaultsUnit,
ModulemdUnit,
RpmUnit,
ModulemdDefaultsUnit,
)

import ubipop

PULP_HOSTNAME = os.getenv("TEST_PULP_HOSTNAME")
PULP_USER = os.getenv("TEST_PULP_USER")
PULP_PWD = os.getenv("TEST_PULP_PWD")
Expand Down Expand Up @@ -79,37 +77,23 @@ def run_ubipop_tool(content_set, workers=10, dry_run=False):


def get_repos_from_cs(cs, skip_dot_version=False):
kwargs = {"verify": PULP_SECURE}
if PULP_CERT_PATH is not None:
p = Pulp(
PULP_HOSTNAME, cert=(PULP_CERT_PATH, PULP_KEY_PATH), verify=PULP_SECURE
)
kwargs["cert"] = (PULP_CERT_PATH, PULP_KEY_PATH)
else:
p = Pulp(PULP_HOSTNAME, auth=(PULP_USER, PULP_PWD), verify=PULP_SECURE)

ret = p.do_request(
"post",
"repositories/search/",
{
"criteria": {
"filters": {"notes.content_set": cs},
},
"distributors": False,
},
)

ret.raise_for_status()
kwargs["auth"] = (PULP_USER, PULP_PWD)
p = Client("https://" + PULP_HOSTNAME, **kwargs)

for item in ret.json():
notes = item["notes"]
repos = p.search_repository(Criteria.with_field("notes.content_set", cs))

if skip_dot_version and "." in notes["platform_full_version"]:
for repo in repos:
if skip_dot_version and "." in repo.platform_full_version:
continue

yield {
"id": item["id"],
"name": item["display_name"],
"url": notes["relative_url"],
"arch": notes["arch"],
"id": repo.id,
"url": repo.relative_url,
"arch": repo.arch,
}


Expand Down Expand Up @@ -245,35 +229,14 @@ def separate_modules(module_list):


def get_rpm_from_repo(client, repo, rpm_list, field):
assert field in ("name", "filename")

rpm = []
if field == "name":
repo_unit = get_rpm_by_name(client, repo, rpm_list)
else:
repo_unit = get_rpm_by_filename(client, repo, rpm_list)
for item in repo_unit:
rpm.append(item.filename)
return rpm


def get_rpm_by_name(client, repo, package_name):
repo = client.get_repository(repo)
crit = Criteria.and_(
Criteria.with_unit_type(RpmUnit),
Criteria.with_field("name", Matcher.in_(package_name)),
)
repo_unit = repo.search_content(crit)
return repo_unit


def get_rpm_by_filename(client, repo, filename):
repo = client.get_repository(repo)
crit = Criteria.and_(
Criteria.with_unit_type(RpmUnit),
Criteria.with_field("filename", Matcher.in_(filename)),
Criteria.with_field(field, Matcher.in_(rpm_list)),
)
repo_unit = repo.search_content(crit)
return repo_unit
return repo.search_content(crit)


def get_modulemd_from_repo(client, repo, modulemd_nsvca):
Expand Down Expand Up @@ -442,10 +405,7 @@ def test_ubipop_does_not_associate_packages_in_exclude_list(pulp_client):
No modules are whitelisted or blacklisted.
"""
cfg = load_ubiconfig("rhel-8-for-x86_64-baseos.yaml", "ubi8.5")
(
content_set_output_repo,
content_set_output_repo_url,
) = get_input_or_output_repo_from_config(
content_set_output_repo, _ = get_input_or_output_repo_from_config(
"rhel-8-for-x86_64-baseos.yaml", "ubi8.5", in_repo=False
)
# the exclude packages are ["gettext","ncurses","gettext-debuginfo","ncurses-debuginfo"]
Expand Down Expand Up @@ -476,10 +436,7 @@ def test_ubipop_does_not_associate_packages_in_exclude_list(pulp_client):
"perl-HTTP-Tiny-0.074-2.module+el8.1.0+2926+ce7246ad.noarch.rpm"
]

(
content_set_output_repo_appstream,
content_set_output_repo_url_appstream,
) = get_input_or_output_repo_from_config(
content_set_output_repo_appstream, _ = get_input_or_output_repo_from_config(
"rhel-8-for-x86_64-appstream.yaml", "ubi8.5", in_repo=False
)

Expand Down Expand Up @@ -529,10 +486,7 @@ def test_ubipop_not_filter_non_module_rpm_and_module_rpm_with_same_package(pulp_
"rhel-8-for-s390x-appstream.yaml", "ubi8.5", in_repo=False
)

(
content_set_input_repo,
content_set_input_repo_url,
) = get_input_or_output_repo_from_config(
content_set_input_repo, _ = get_input_or_output_repo_from_config(
"rhel-8-for-s390x-appstream.yaml", "ubi8.5", in_repo=True
)

Expand Down Expand Up @@ -641,10 +595,10 @@ def test_ubipop_not_filter_module_rpm_with_different_version(pulp_client):
# verify the modulemd exist and modulemd default in the cdn server
modulemds = query_repo_modules(None, "ubi", rpm_repo_url, full_data=True)
assert len(modulemds) == 6, "Unexpected repo modulemds found."
mod_name, mod_profile = separate_modules(modulemds)[1]
assert (
mod_name == "container-tools"
), "Expected modulemd: httpd, found modulemd: {}".format(mod_name)
mod_name, mod_profile = separate_modules(modulemds)[0]
assert mod_name == "httpd", "Expected modulemd: httpd, found modulemd: {}".format(
mod_name
)
assert (
"common [d]" in mod_profile
), "Modulemd httpd should have common profile as default."
Expand All @@ -663,10 +617,7 @@ def test_ubipop_get_dependencies_module_rpm(pulp_client):
expected_packages = ["ncurses", "ncurses-base", "ncurses-libs"]

cfg = load_ubiconfig("rhel-8-for-aarch64-appstream.yaml", "ubi8.5")
(
content_set_output_repo,
content_set_output_repo_url,
) = get_input_or_output_repo_from_config(
content_set_output_repo, _ = get_input_or_output_repo_from_config(
"rhel-8-for-aarch64-appstream.yaml", "ubi8.5", in_repo=False
)

Expand Down Expand Up @@ -694,10 +645,7 @@ def test_ubipop_get_dependencies_module_rpm(pulp_client):
# verity before ubipop, there is no expected_rpm exist in ubi-8-for-aarch64-base-rpms
# and there is no such package in config
cfg_base = load_ubiconfig("rhel-8-for-aarch64-baseos.yaml", "ubi8.5")
(
content_set_output_repo_base,
content_set_output_repo_url_base,
) = get_input_or_output_repo_from_config(
content_set_output_repo_base, _ = get_input_or_output_repo_from_config(
"rhel-8-for-aarch64-baseos.yaml", "ubi8.5", in_repo=False
)
pkgs_included = [pkg.name for pkg in cfg_base.packages.whitelist]
Expand Down
Loading

0 comments on commit dbab9ae

Please sign in to comment.