fix image checksums

This commit is contained in:
Jim Rollenhagen 2014-01-16 14:53:49 -08:00
parent 53e82a1a20
commit da7ba831a0
2 changed files with 8 additions and 5 deletions

View File

@ -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

View File

@ -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)