Sign Up
Log In
Log In
or
Sign Up
Places
All Projects
Status Monitor
Collapse sidebar
openSUSE:Step:15-SP6
salt.26142
ignore-erros-on-reading-license-files-with-dpkg...
Overview
Repositories
Revisions
Requests
Users
Attributes
Meta
File ignore-erros-on-reading-license-files-with-dpkg_lowp.patch of Package salt.26142
From 90d0e3ce40e46a9bff3e477b61e02cf3e87e8b9f Mon Sep 17 00:00:00 2001 From: Victor Zhestkov <vzhestkov@suse.com> Date: Mon, 27 Jun 2022 17:55:49 +0300 Subject: [PATCH] Ignore erros on reading license files with dpkg_lowpkg (bsc#1197288) * Ignore erros on reading license files with dpkg_lowpkg (bsc#1197288) * Add test for license reading with dpkg_lowpkg --- salt/modules/dpkg_lowpkg.py | 2 +- tests/pytests/unit/modules/test_dpkg_lowpkg.py | 18 ++++++++++++++++++ 2 files changed, 19 insertions(+), 1 deletion(-) create mode 100644 tests/pytests/unit/modules/test_dpkg_lowpkg.py diff --git a/salt/modules/dpkg_lowpkg.py b/salt/modules/dpkg_lowpkg.py index afbd619490..2c25b1fb2a 100644 --- a/salt/modules/dpkg_lowpkg.py +++ b/salt/modules/dpkg_lowpkg.py @@ -361,7 +361,7 @@ def _get_pkg_license(pkg): licenses = set() cpr = "/usr/share/doc/{}/copyright".format(pkg) if os.path.exists(cpr): - with salt.utils.files.fopen(cpr) as fp_: + with salt.utils.files.fopen(cpr, errors="ignore") as fp_: for line in salt.utils.stringutils.to_unicode(fp_.read()).split(os.linesep): if line.startswith("License:"): licenses.add(line.split(":", 1)[1].strip()) diff --git a/tests/pytests/unit/modules/test_dpkg_lowpkg.py b/tests/pytests/unit/modules/test_dpkg_lowpkg.py new file mode 100644 index 0000000000..1a89660c02 --- /dev/null +++ b/tests/pytests/unit/modules/test_dpkg_lowpkg.py @@ -0,0 +1,18 @@ +import os + +import salt.modules.dpkg_lowpkg as dpkg +from tests.support.mock import MagicMock, mock_open, patch + + +def test_get_pkg_license(): + """ + Test _get_pkg_license for ignore errors on reading license from copyright files + """ + license_read_mock = mock_open(read_data="") + with patch.object(os.path, "exists", MagicMock(return_value=True)), patch( + "salt.utils.files.fopen", license_read_mock + ): + dpkg._get_pkg_license("bash") + + assert license_read_mock.calls[0].args[0] == "/usr/share/doc/bash/copyright" + assert license_read_mock.calls[0].kwargs["errors"] == "ignore" -- 2.36.1
Locations
Projects
Search
Status Monitor
Help
OpenBuildService.org
Documentation
API Documentation
Code of Conduct
Contact
Support
@OBShq
Terms
openSUSE Build Service is sponsored by
The Open Build Service is an
openSUSE project
.
Sign Up
Log In
Places
Places
All Projects
Status Monitor