checksums: Ignore broken pyeclib installs
The RuntimeError gives more of a hint than the TypeError, but we haven't
really solved the issue. If there's a busted pyeclib install, it's safe
to assume it won't have ISA-L alongside it; just proceed assuming it's
not available.
Closes-Bug: #2120591
Related-Change: I64a85eb739fb72efe41f1ee829e463167246b793
Co-Authored-By: Alistair Coles <alistairncoles@gmail.com>
Signed-off-by: Tim Burke <tim.burke@gmail.com>
Change-Id: I2791566b208327b1fb536fb56a363337ab3f3941
(cherry picked from commit 81df05a9c4)
This commit is contained in:
@@ -43,14 +43,20 @@ def find_isal():
|
|||||||
# with isal baked in?
|
# with isal baked in?
|
||||||
try:
|
try:
|
||||||
import pyeclib # noqa
|
import pyeclib # noqa
|
||||||
from importlib.metadata import files as pkg_files # py38+
|
from importlib.metadata import \
|
||||||
|
files as pkg_files, PackageNotFoundError # py38+
|
||||||
except ImportError:
|
except ImportError:
|
||||||
pass
|
pass
|
||||||
else:
|
else:
|
||||||
|
# Assume busted installs won't have it
|
||||||
|
try:
|
||||||
pyeclib_files = pkg_files('pyeclib')
|
pyeclib_files = pkg_files('pyeclib')
|
||||||
if not pyeclib_files:
|
if pyeclib_files is None:
|
||||||
# see https://docs.python.org/3/library/importlib.metadata.html
|
# Have a dist-info, but no RECORD file??
|
||||||
raise RuntimeError('pyeclib installed but missing files')
|
pyeclib_files = []
|
||||||
|
except PackageNotFoundError:
|
||||||
|
# Could import pyeclib, but no dist-info directory??
|
||||||
|
pyeclib_files = []
|
||||||
isal_libs = [f for f in pyeclib_files
|
isal_libs = [f for f in pyeclib_files
|
||||||
if f.name.startswith("libisal")]
|
if f.name.startswith("libisal")]
|
||||||
if len(isal_libs) == 1:
|
if len(isal_libs) == 1:
|
||||||
|
|||||||
@@ -12,7 +12,6 @@
|
|||||||
# implied.
|
# implied.
|
||||||
# See the License for the specific language governing permissions and
|
# See the License for the specific language governing permissions and
|
||||||
# limitations under the License.
|
# limitations under the License.
|
||||||
|
|
||||||
import sys
|
import sys
|
||||||
import unittest
|
import unittest
|
||||||
from unittest import mock
|
from unittest import mock
|
||||||
@@ -25,16 +24,52 @@ from test.unit import requires_crc32c, requires_crc64nvme
|
|||||||
|
|
||||||
|
|
||||||
class TestModuleFunctions(unittest.TestCase):
|
class TestModuleFunctions(unittest.TestCase):
|
||||||
|
def test_find_isal_sys_package_preferred(self):
|
||||||
|
with mock.patch('ctypes.util.find_library', return_value='my-isal.so'):
|
||||||
|
with mock.patch('ctypes.CDLL', return_value='fake') as mock_cdll:
|
||||||
|
self.assertEqual('fake', checksum.find_isal())
|
||||||
|
self.assertEqual([mock.call('my-isal.so')], mock_cdll.call_args_list)
|
||||||
|
|
||||||
|
@unittest.skipIf(
|
||||||
|
sys.version_info.major == 3 and sys.version_info.minor < 8,
|
||||||
|
"importlib.metadata not available until py3.8")
|
||||||
|
def test_find_isal_pyeclib_install_found(self):
|
||||||
|
mock_pkg = mock.MagicMock()
|
||||||
|
mock_pkg.locate = mock.MagicMock(return_value='fake-pkg')
|
||||||
|
with mock.patch('ctypes.util.find_library', return_value=None):
|
||||||
|
with mock.patch('ctypes.CDLL', return_value='fake') as mock_cdll:
|
||||||
|
with mock.patch('importlib.metadata.files',
|
||||||
|
return_value=[mock_pkg]):
|
||||||
|
self.assertEqual('fake', checksum.find_isal())
|
||||||
|
self.assertEqual([mock.call('fake-pkg')], mock_cdll.call_args_list)
|
||||||
|
|
||||||
|
@unittest.skipIf(
|
||||||
|
sys.version_info.major == 3 and sys.version_info.minor < 8,
|
||||||
|
"importlib.metadata not available until py3.8")
|
||||||
|
def test_find_isal_pyeclib_install_not_found(self):
|
||||||
|
mock_pkg = mock.MagicMock()
|
||||||
|
mock_pkg.locate = mock.MagicMock(return_value='fake-pkg')
|
||||||
|
with mock.patch('ctypes.util.find_library', return_value=None):
|
||||||
|
with mock.patch('importlib.metadata.files', return_value=[]):
|
||||||
|
self.assertIsNone(checksum.find_isal())
|
||||||
|
|
||||||
@unittest.skipIf(
|
@unittest.skipIf(
|
||||||
sys.version_info.major == 3 and sys.version_info.minor < 8,
|
sys.version_info.major == 3 and sys.version_info.minor < 8,
|
||||||
"importlib.metadata not available until py3.8")
|
"importlib.metadata not available until py3.8")
|
||||||
def test_find_isal_pyeclib_dist_missing_files(self):
|
def test_find_isal_pyeclib_dist_missing_files(self):
|
||||||
with mock.patch('ctypes.util.find_library', return_value=None):
|
with mock.patch('ctypes.util.find_library', return_value=None):
|
||||||
with mock.patch('importlib.metadata.files', return_value=None):
|
with mock.patch('importlib.metadata.files', return_value=None):
|
||||||
with self.assertRaises(RuntimeError) as cm:
|
self.assertIsNone(checksum.find_isal())
|
||||||
checksum.find_isal()
|
|
||||||
self.assertEqual('pyeclib installed but missing files',
|
@unittest.skipIf(
|
||||||
str(cm.exception))
|
sys.version_info.major == 3 and sys.version_info.minor < 8,
|
||||||
|
"importlib.metadata not available until py3.8")
|
||||||
|
def test_find_isal_pyeclib_dist_info_missing(self):
|
||||||
|
from importlib.metadata import PackageNotFoundError
|
||||||
|
with mock.patch('ctypes.util.find_library', return_value=None):
|
||||||
|
with mock.patch('importlib.metadata.files',
|
||||||
|
side_effect=PackageNotFoundError):
|
||||||
|
self.assertIsNone(checksum.find_isal())
|
||||||
|
|
||||||
|
|
||||||
# If you're curious about the 0xe3069283, see "check" at
|
# If you're curious about the 0xe3069283, see "check" at
|
||||||
|
|||||||
Reference in New Issue
Block a user