Skip to content

Commit

Permalink
chore(RHTAPWATCH-640): add get_rpmdb implementation
Browse files Browse the repository at this point in the history
Add implementation and tests for get_rpmdb

Signed-off-by: Yftach Herzog <[email protected]>
  • Loading branch information
yftacherzog committed Dec 17, 2023
1 parent 98d05e4 commit 15026b2
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 2 deletions.
20 changes: 19 additions & 1 deletion tests/test_rpm_verifier.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,12 @@
from pytest import MonkeyPatch

from verify_rpms import rpm_verifier
from verify_rpms.rpm_verifier import ImageProcessor, ProcessedImage, generate_output
from verify_rpms.rpm_verifier import (
ImageProcessor,
ProcessedImage,
generate_output,
get_rpmdb,
)


@pytest.mark.parametrize(
Expand Down Expand Up @@ -130,6 +135,19 @@ def test_call(
assert out == ProcessedImage(image=img, unsigned_rpms=unsigned_rpms)


def test_get_rpmdb(tmp_path: Path) -> None:
"""Test get_rpmdb"""
image = "my-image"
mock_runner = MagicMock()
out = get_rpmdb(
container_image=image,
target_dir=tmp_path,
runner=mock_runner,
)
assert mock_runner.call_count == 1
assert out == tmp_path


class TestMain:
"""Test call to rpm_verifier.py main function"""

Expand Down
15 changes: 14 additions & 1 deletion verify_rpms/rpm_verifier.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,20 @@ def __str__(self) -> str:

def get_rpmdb(container_image: str, target_dir: Path, runner: Callable = run) -> Path:
"""Extract RPM DB from a given container image reference"""
raise NotImplementedError()
runner(
[
"oc",
"image",
"extract",
container_image,
"--path",
f"/var/lib/rpm/:{target_dir}",
],
capture_output=True,
text=True,
check=True,
)
return target_dir


def get_unsigned_rpms(rpmdb: Path, runner: Callable = run) -> list[str]:
Expand Down

0 comments on commit 15026b2

Please sign in to comment.