From 0dd5b993eca2a569a5cf83185aa2ead88a99b920 Mon Sep 17 00:00:00 2001 From: Yftach Herzog Date: Thu, 14 Dec 2023 12:41:00 +0200 Subject: [PATCH] chore(RHTAPWATCH-640): add get_rpmdb implementation Add implementation and tests for get_rpmdb Signed-off-by: Yftach Herzog --- tests/test_rpm_verifier.py | 16 +++++++++++++++- verify_rpms/rpm_verifier.py | 15 ++++++++++++++- 2 files changed, 29 insertions(+), 2 deletions(-) diff --git a/tests/test_rpm_verifier.py b/tests/test_rpm_verifier.py index ecd1b92..5ae4ffa 100644 --- a/tests/test_rpm_verifier.py +++ b/tests/test_rpm_verifier.py @@ -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: diff --git a/verify_rpms/rpm_verifier.py b/verify_rpms/rpm_verifier.py index 5bdc1e9..00de54a 100644 --- a/verify_rpms/rpm_verifier.py +++ b/verify_rpms/rpm_verifier.py @@ -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]: