Skip to content

Commit

Permalink
Print and compare checksum when adding new box
Browse files Browse the repository at this point in the history
Update script used to download a box to the locally hosted Vagrant
catalog to compare box's sha1sum with the one availble on the original
registry, saving time when publishing new box templates.

Signed-off-by: Armando Neto <abiagion@redhat.com>
  • Loading branch information
netoarmando committed Nov 25, 2020
1 parent 0cd73c2 commit 92bc32d
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions scripts/cache-vagrant-box.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#!/bin/env python3
import argparse
import hashlib
import logging
import os
import pathlib
Expand All @@ -22,6 +23,16 @@
)


def sha1sum(filename):
hashsum = hashlib.sha1()
buffer_ = bytearray(128 * 1024)
mv = memoryview(buffer_)
with open(filename, 'rb', buffering=0) as f:
for n in iter(lambda: f.readinto(mv), 0):
hashsum.update(mv[:n])
return hashsum.hexdigest()


def download_box(user_name, box_name, box_version):
'''Download box to CATALOG_PATH, following the same structure as Vagrant.
'''
Expand Down Expand Up @@ -96,6 +107,14 @@ def download_box(user_name, box_name, box_version):
)
shutil.move(temp_box_path, final_box_path)

box_sha1sum = sha1sum(final_box_path)
logger.info(f'sha1sum: {box_sha1sum}')

if provider.get('checksum') and provider.get('checksum_type') == 'sha1':
if box_sha1sum != provider.get('checksum'):
logger.error("Vagrant cloud and local box checksums dont't match")
return 1

return 0


Expand Down

0 comments on commit 92bc32d

Please sign in to comment.