Skip to content

Commit

Permalink
Merge pull request #284 from MichalHaluza/load_productid_via_pushsource
Browse files Browse the repository at this point in the history
Load ProductID certificate metadata via pushsource [RHELDST-24276]
  • Loading branch information
MichalHaluza committed May 16, 2024
2 parents 5166766 + 04a496e commit 2a17378
Show file tree
Hide file tree
Showing 8 changed files with 505 additions and 536 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/docs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ jobs:
sudo apt-get -y update
sudo apt-get install -y libkrb5-dev
- name: Install Tox
run: pip install tox 'virtualenv<20.21.1'
run: pip install tox
- name: Run Tox
run: tox -e docs
- name: Publish
Expand Down
12 changes: 6 additions & 6 deletions .github/workflows/tox-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ jobs:
with:
python-version: 3.8
- name: Install Tox
run: pip install tox 'virtualenv<20.21.1'
run: pip install tox
- name: Run Tox
run: tox -e py38
static:
Expand All @@ -34,7 +34,7 @@ jobs:
with:
python-version: 3.8
- name: Install Tox
run: pip install tox 'virtualenv<20.21.1'
run: pip install tox
- name: Run Tox
run: tox -e static
coverage:
Expand All @@ -50,7 +50,7 @@ jobs:
with:
python-version: 3.8
- name: Install Tox
run: pip install tox 'virtualenv<20.21.1'
run: pip install tox
- name: Install pytest cov
run: pip install pytest-cov
- name: Run Tox
Expand All @@ -75,7 +75,7 @@ jobs:
with:
python-version: 3.8
- name: Install Tox
run: pip install tox 'virtualenv<20.21.1'
run: pip install tox
- name: Run Tox
run: tox -e docs
bandit-exitzero:
Expand All @@ -92,7 +92,7 @@ jobs:
with:
python-version: 3.8
- name: Install Tox
run: pip install tox 'virtualenv<20.21.1'
run: pip install tox
- name: Run Tox
run: tox -e bandit-exitzero
bandit:
Expand All @@ -109,6 +109,6 @@ jobs:
with:
python-version: 3.8
- name: Install Tox
run: pip install tox 'virtualenv<20.21.1'
run: pip install tox
- name: Run Tox
run: tox -e bandit
6 changes: 2 additions & 4 deletions pubtools/_pulp/tasks/push/items/productid.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import attr
from more_executors.futures import f_flat_map, f_map, f_sequence
from pushsource import ProductIdPushItem
import rhsm.certificate
from pubtools.pulplib import Criteria

from .base import supports_type
Expand Down Expand Up @@ -79,9 +78,8 @@ class PulpProductIdPushItem(PulpDirectUploadPushItem):

@product_versions.default
def _product_versions_from_cert(self):
if self.pushsource_item and self.pushsource_item.src:
cert = rhsm.certificate.create_from_file(self.pushsource_item.src)
versions = [p.version for p in cert.products]
if self.pushsource_item:
versions = [p.version for p in self.pushsource_item.products]
return sorted(set(versions))
return []

Expand Down
3 changes: 1 addition & 2 deletions requirements.in
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,5 @@ pubtools-pulplib>=2.36.0
fastpurge
more_executors>=2.7.0
pushcollector>=1.2.0
pushsource>=2.27.0
rhsm
pushsource>=2.45.0
monotonic; python_version < '3.3'
379 changes: 184 additions & 195 deletions requirements.txt

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion test-requirements.in
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ pytest-cov
coveralls
mock
requests_mock
rpm-py-installer
rpmdyn

# The following deps are not relevant for the legacy test env.
black; python_version>='3'
Expand Down
604 changes: 299 additions & 305 deletions test-requirements.txt

Large diffs are not rendered by default.

33 changes: 11 additions & 22 deletions tests/push/test_productid_updates_versions.py
Original file line number Diff line number Diff line change
@@ -1,22 +1,11 @@
from pushsource import ProductIdPushItem
from pushsource import ProductId, ProductIdPushItem

import rhsm.certificate
from pubtools.pulplib import FakeController, YumRepository
from pubtools._pulp.tasks.push.items import PulpProductIdPushItem
from pubtools._pulp.tasks.push.items.base import UploadContext


class FakeProduct(object):
def __init__(self, version):
self.version = version


class FakeCert(object):
def __init__(self, versions):
self.products = [FakeProduct(v) for v in versions]


def test_updates_product_versions(monkeypatch, tmpdir):
def test_updates_product_versions(tmpdir):
"""Uploading a productid to a repo will update the product_versions field
on that repo and related repos.
"""
Expand Down Expand Up @@ -79,22 +68,22 @@ def test_updates_product_versions(monkeypatch, tmpdir):
ctrl.insert_repository(repo7)
ctrl.insert_repository(repo8)

# Set up cert parser to use a fake cert object (saves us having to explicitly
# generate certs with certain values)
monkeypatch.setattr(
rhsm.certificate, "create_from_file", lambda _: FakeCert(["a", "d"])
)

# make a fake productid.
# content doesn't matter since we patched the cert parser, it just has
# make a fake productid file.
# content doesn't matter since we inject the ProductIDs, it just has
# to be an existing file.
productid = tmpdir.join("productid")
productid.write("")

# make an item targeting two of the repos
item = PulpProductIdPushItem(
pushsource_item=ProductIdPushItem(
name="test", src=str(productid), dest=["repo2", "repo7"]
name="test",
src=str(productid),
dest=["repo2", "repo7"],
products=[
ProductId(id=1234, version="a"),
ProductId(id=1234, version="d"),
],
)
)

Expand Down

0 comments on commit 2a17378

Please sign in to comment.