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 14, 2023
1 parent 445b226 commit 0dd5b99
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 2 deletions.
16 changes: 15 additions & 1 deletion tests/test_rpm_verifier.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,26 @@
"""Test rpm_verifier.py end-to-end"""

from pathlib import Path
from unittest.mock import MagicMock, call, create_autospec, sentinel

import pytest
from pytest import MonkeyPatch

from verify_rpms import rpm_verifier
from verify_rpms.rpm_verifier import ImageProcessor, generate_output
from verify_rpms.rpm_verifier import ImageProcessor, generate_output, get_rpmdb


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:
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 @@ -22,7 +22,20 @@ class ProcessedImage:

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 0dd5b99

Please sign in to comment.