diff --git a/teeth_agent/standby.py b/teeth_agent/standby.py index 26020aa10..ef748d296 100644 --- a/teeth_agent/standby.py +++ b/teeth_agent/standby.py @@ -89,7 +89,7 @@ def _verify_image(image_info, image_location): algo = getattr(hashlib, k, None) if algo is None: continue - hash_ = algo(open(image_location).read()) + hash_ = algo(open(image_location).read()).hexdigest() if hash_ == v: return True return False diff --git a/teeth_agent/tests/standby_agent.py b/teeth_agent/tests/standby_agent.py index 169e7e377..cf51fc7b2 100644 --- a/teeth_agent/tests/standby_agent.py +++ b/teeth_agent/tests/standby_agent.py @@ -166,7 +166,8 @@ class TestBaseTeethAgent(unittest.TestCase): open_mock.return_value.__exit__ = mock.Mock() read_mock = open_mock.return_value.read read_mock.return_value = 'content' - md5_mock.return_value = image_info['hashes'].values()[0] + hexdigest_mock = md5_mock.return_value.hexdigest + hexdigest_mock.return_value = image_info['hashes'].values()[0] standby._download_image(image_info) requests_mock.assert_called_once_with(image_info['urls'][0], @@ -204,8 +205,10 @@ class TestBaseTeethAgent(unittest.TestCase): def test_verify_image_success(self, md5_mock, sha1_mock, open_mock): image_info = self._build_fake_image_info() image_info['hashes']['sha1'] = image_info['hashes']['md5'] - md5_mock.return_value = image_info['hashes']['md5'] - sha1_mock.return_value = image_info['hashes']['sha1'] + hexdigest_mock = md5_mock.return_value.hexdigest + hexdigest_mock.return_value = image_info['hashes']['md5'] + hexdigest_mock = sha1_mock.return_value.hexdigest + hexdigest_mock.return_value = image_info['hashes']['sha1'] image_location = '/foo/bar' verified = standby._verify_image(image_info, image_location) @@ -217,7 +220,7 @@ class TestBaseTeethAgent(unittest.TestCase): @mock.patch('hashlib.md5', autospec=True) def test_verify_image_failure(self, md5_mock, open_mock): image_info = self._build_fake_image_info() - md5_mock.return_value = 'wrong hash' + md5_mock.return_value.hexdigest.return_value = 'wrong hash' image_location = '/foo/bar' verified = standby._verify_image(image_info, image_location)