From f8aeef25fc7a1eed0133f4c5af3ee419e6eb5ba5 Mon Sep 17 00:00:00 2001 From: Mike Place Date: Tue, 10 Feb 2015 08:46:42 -0700 Subject: [PATCH] Fix mod_random test on older distros --- salt/modules/mod_random.py | 4 ++++ tests/unit/modules/mod_random_test.py | 14 ++++++++++++++ 2 files changed, 18 insertions(+) diff --git a/salt/modules/mod_random.py b/salt/modules/mod_random.py index 28fcd25e91..d1e49bfdab 100644 --- a/salt/modules/mod_random.py +++ b/salt/modules/mod_random.py @@ -20,6 +20,10 @@ def __virtual__(): ''' Confirm this module is on a Debian based system ''' + # Certain versions of hashlib do not contain + # the necessary functions + if not hasattr(hashlib, 'algorithms'): + return False return __virtualname__ diff --git a/tests/unit/modules/mod_random_test.py b/tests/unit/modules/mod_random_test.py index a0bc59afcb..0d95883ed0 100644 --- a/tests/unit/modules/mod_random_test.py +++ b/tests/unit/modules/mod_random_test.py @@ -29,6 +29,20 @@ mod_random.__context__ = {} mod_random.__opts__ = {} +def _test_hashlib(): + try: + import hashlib + except ImportError: + return False + if not hasattr(hashlib, 'algorithms'): + return False + else: + return True + +SUPPORTED_HASHLIB = _test_hashlib() + + +@skipIf(not SUPPORTED_HASHLIB, 'Hashlib does not contain needed functionality') @skipIf(NO_MOCK, NO_MOCK_REASON) class ModrandomTestCase(TestCase): '''