From 64eb0080ddd3257a206213e9052b3cec4fcb5e0f Mon Sep 17 00:00:00 2001 From: Davide Cavalca Date: Jan 03 2021 18:37:24 +0000 Subject: Initial import (#1911705) --- diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..e6e71e0 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +/dcrpm-0.6.2.tar.gz diff --git a/5bdb25ebb80a598e088c6c9ccf211a9dc9a22baa.patch b/5bdb25ebb80a598e088c6c9ccf211a9dc9a22baa.patch new file mode 100644 index 0000000..b9a152d --- /dev/null +++ b/5bdb25ebb80a598e088c6c9ccf211a9dc9a22baa.patch @@ -0,0 +1,36 @@ +From 5bdb25ebb80a598e088c6c9ccf211a9dc9a22baa Mon Sep 17 00:00:00 2001 +From: Davide Cavalca +Date: Wed, 30 Dec 2020 10:43:18 -0800 +Subject: [PATCH] tests: properly mock yum process name + +--- + tests/test_yum.py | 4 ++-- + 1 file changed, 2 insertions(+), 2 deletions(-) + +diff --git a/tests/test_yum.py b/tests/test_yum.py +index 68340bd..de1ba2a 100644 +--- a/tests/test_yum.py ++++ b/tests/test_yum.py +@@ -16,12 +16,12 @@ + from dcrpm import pidutil, yum + from tests.mock_process import make_mock_process + +- + class TestYum(testslide.TestCase): + def setUp(self): + # type: () -> None + super(TestYum, self).setUp() + self.yum = yum.Yum() # type: yum.Yum ++ self.yum.yum = "fakeyum" + + # check_stuck + def test_check_stuck_filenotfound(self): +@@ -91,7 +91,7 @@ def test_check_stuck_kill_yumpid(self): + ( + self.mock_callable(pidutil, "process") + .for_call(12345) +- .to_return_value(make_mock_process(pid=12345, open_files=[], name="yum")) ++ .to_return_value(make_mock_process(pid=12345, open_files=[], name="fakeyum")) + .and_assert_called_once() + ) + self.assertTrue(self.yum.check_stuck()) diff --git a/efc0166793db58e08b57ba3839638f7571355b93.patch b/efc0166793db58e08b57ba3839638f7571355b93.patch new file mode 100644 index 0000000..1ab5e69 --- /dev/null +++ b/efc0166793db58e08b57ba3839638f7571355b93.patch @@ -0,0 +1,76 @@ +From efc0166793db58e08b57ba3839638f7571355b93 Mon Sep 17 00:00:00 2001 +From: Davide Cavalca +Date: Wed, 30 Dec 2020 10:35:50 -0800 +Subject: [PATCH] tests: fix Popen mock + +--- + tests/test_util.py | 14 +++++++------- + 1 file changed, 7 insertions(+), 7 deletions(-) + +diff --git a/tests/test_util.py b/tests/test_util.py +index 13a1e43..b7748a5 100644 +--- a/tests/test_util.py ++++ b/tests/test_util.py +@@ -86,7 +86,7 @@ def test_call_with_timeout_real_raises(self): + def test_run_with_timeout_success(self): + # type: () -> None + ( +- self.mock_callable(subprocess, "Popen") ++ self.mock_constructor(subprocess, "Popen") + .for_call( + ["/bin/true"], + stdout=subprocess.PIPE, +@@ -103,7 +103,7 @@ def test_run_with_timeout_timeout(self): + # type: () -> None + mock_popen = make_mock_popen(communicate_raise=True) + ( +- self.mock_callable(subprocess, "Popen") ++ self.mock_constructor(subprocess, "Popen") + .for_call( + ["/bin/true"], + stdout=subprocess.PIPE, +@@ -121,7 +121,7 @@ def test_run_with_timeout_terminates_on_timeout(self): + # type: () -> None + mock_popen = make_mock_popen(communicate_raise=True) + ( +- self.mock_callable(subprocess, "Popen") ++ self.mock_constructor(subprocess, "Popen") + .for_call( + ["/bin/true"], + stdout=subprocess.PIPE, +@@ -140,7 +140,7 @@ def test_run_with_timeout_kills_on_terminate_timeout(self): + # type: () -> None + mock_popen = make_mock_popen(communicate_raise=True, terminate_raise=True) + ( +- self.mock_callable(subprocess, "Popen") ++ self.mock_constructor(subprocess, "Popen") + .for_call( + ["/bin/true"], + stdout=subprocess.PIPE, +@@ -158,7 +158,7 @@ def test_run_with_timeout_kills_on_terminate_timeout(self): + def test_run_with_timeout_raise_on_nonzero(self): + # type: () -> None + ( +- self.mock_callable(subprocess, "Popen") ++ self.mock_constructor(subprocess, "Popen") + .for_call( + ["/bin/true"], + stdout=subprocess.PIPE, +@@ -174,7 +174,7 @@ def test_run_with_timeout_raise_on_nonzero(self): + def test_run_with_timeout_no_raise_on_nonzero(self): + # type: () -> None + ( +- self.mock_callable(subprocess, "Popen") ++ self.mock_constructor(subprocess, "Popen") + .for_call( + ["/bin/true"], + stdout=subprocess.PIPE, +@@ -191,7 +191,7 @@ def test_run_with_timeout_no_raise_on_timeout(self): + # type: () -> None + mock_popen = make_mock_popen(returncode=1, communicate_raise=True) + ( +- self.mock_callable(subprocess, "Popen") ++ self.mock_constructor(subprocess, "Popen") + .for_call( + ["/bin/true"], + stdout=subprocess.PIPE, diff --git a/f7f89146e37c009a164e0e81de9b6b23d4874ffc.patch b/f7f89146e37c009a164e0e81de9b6b23d4874ffc.patch new file mode 100644 index 0000000..c0f2cc0 --- /dev/null +++ b/f7f89146e37c009a164e0e81de9b6b23d4874ffc.patch @@ -0,0 +1,25 @@ +From f7f89146e37c009a164e0e81de9b6b23d4874ffc Mon Sep 17 00:00:00 2001 +From: Davide Cavalca +Date: Wed, 30 Dec 2020 10:34:44 -0800 +Subject: [PATCH] tests: properly mock bdb in db_stat test + +--- + tests/test_dcrpm.py | 5 +++++ + 1 file changed, 5 insertions(+) + +diff --git a/tests/test_dcrpm.py b/tests/test_dcrpm.py +index aad5ca7..7e9d69e 100644 +--- a/tests/test_dcrpm.py ++++ b/tests/test_dcrpm.py +@@ -89,6 +89,11 @@ def test_run_recovery_dry_run(self): + def test_db_stat_forensic(self): + # type: () -> None + self.mock_callable(pidutil, "send_signals").and_assert_not_called() ++ ( ++ self.mock_callable(self.rpmutil, "get_db_backend") ++ .to_return_value("bdb") ++ .and_assert_called() ++ ) + ( + self.mock_callable(self.rpmutil, "db_stat") + .to_return_value(None) diff --git a/python-dcrpm.spec b/python-dcrpm.spec new file mode 100644 index 0000000..031e4df --- /dev/null +++ b/python-dcrpm.spec @@ -0,0 +1,86 @@ +# Skip tests on EPEL due to missing dependencies +%if 0%{?rhel} +%bcond_with tests +%else +%bcond_without tests +%endif + +# Created by pyp2rpm-3.3.5 +%global pypi_name dcrpm + +Name: python-%{pypi_name} +Version: 0.6.2 +Release: 1%{?dist} +Summary: A tool to detect and correct common issues around RPM database corruption + +License: GPLv2 +URL: https://github.com/facebookincubator/dcrpm +Source0: %{pypi_source} +# tests: fix Popen mock +Patch0: %{url}/commit/efc0166793db58e08b57ba3839638f7571355b93.patch +# tests: properly mock bdb in db_stat test +Patch1: %{url}/commit/f7f89146e37c009a164e0e81de9b6b23d4874ffc.patch +# tests: properly mock yum process name +Patch2: %{url}/commit/5bdb25ebb80a598e088c6c9ccf211a9dc9a22baa.patch +BuildArch: noarch + +BuildRequires: python3-devel +BuildRequires: python3dist(psutil) +BuildRequires: python3dist(setuptools) +%if 0%{?el8} +# pypandoc is an optional dependency and is not available in EPEL 8 +%else +BuildRequires: python3dist(pypandoc) +%endif +%if %{with tests} +BuildRequires: python3dist(mock) +BuildRequires: python3dist(testslide) +BuildRequires: dnf +BuildRequires: libdb-utils +%endif + +%description +dcrpm is a tool to detect and correct common issues around RPM database +corruption. + +%package -n %{pypi_name} +Summary: %{summary} +%{?python_provide:%python_provide python3-%{pypi_name}} + +Requires: python3dist(psutil) +Requires: python3dist(setuptools) +Requires: lsof +Recommends: libdb-utils +%description -n %{pypi_name} +dcrpm is a tool to detect and correct common issues around RPM database +corruption. + +%prep +%autosetup -n %{pypi_name}-%{version} -p1 +# Remove unnecessary shebang +sed -e '\|#!/usr/bin/env python|d' -i dcrpm/*.py +# Remove bundled egg-info +rm -rf %{pypi_name}.egg-info + +%build +%py3_build + +%install +%py3_install + +%if %{with tests} +%check +%{__python3} setup.py test +%endif + +%files -n %{pypi_name} +%license LICENSE +%doc README.md CONTRIBUTING.md CODE_OF_CONDUCT.md +%doc HISTORY.md MANUAL_RPM_CLEANUP.md +%{_bindir}/dcrpm +%{python3_sitelib}/%{pypi_name} +%{python3_sitelib}/%{pypi_name}-%{version}-py%{python3_version}.egg-info + +%changelog +* Wed Dec 30 2020 Davide Cavalca - 0.6.2-1 +- Initial package. diff --git a/sources b/sources new file mode 100644 index 0000000..2d05ad7 --- /dev/null +++ b/sources @@ -0,0 +1 @@ +SHA512 (dcrpm-0.6.2.tar.gz) = dad635628ae6a40fb7b7153e6ee079e22ba196068f1620c33ad82c350e71555f9677efdaf4022e9bb80d684a11172652fb4da3306d0a0cf9bd6009fd554d0607