SHA1 => MD5

This commit is contained in:
Julien Duponchelle 2015-05-28 15:23:18 +02:00
parent c007f414ea
commit 0f66856fa7
6 changed files with 19 additions and 19 deletions

View File

@ -25,7 +25,7 @@
{
"filename": "Aboot-veos-2.1.0.iso",
"version": "2.1.0",
"sha1sum": "ea9dc1989764fc6db1d388b061340743016214a7",
"md5sum": "44177f7f9157354f213a1545c65e92ec",
"download_url": "https://www.arista.com/en/support/software-download"
}
],
@ -33,7 +33,7 @@
{
"filename": "vEOS-lab-4.13.8M.vmdk",
"version": "4.13.8M",
"sha1sum": "ff50656fe817c420e9f7fbb0c0ee41f1ca52fee2",
"md5sum": "a47145b9e6e7a24171c0850f8755535e",
"download_url": "https://www.arista.com/en/support/software-download"
}
]

View File

@ -29,7 +29,7 @@
{
"filename": "VSR1000_HP-CMW710-R0204P01-X64.iso",
"version": "7.10.R0204P01",
"sha1sum": "9ead89601e84aa7dd341869c1d7933a583ab2794",
"md5sum": "d0b539f3ba9723ad8c3ed46f6d772627",
"download_url": "https://h10145.www1.hp.com/Downloads/DownloadSoftware.aspx?SoftwareReleaseUId=11832&ProductNumber=JG811AAE&lang=en&cc=us&prodSeriesId=5443163&OrderNumber=&PurchaseDate="
}
]

View File

@ -24,14 +24,14 @@
{
"filename": "linux-microcore-3.4.1.img",
"version": "3.4.1",
"sha1sum": "5f42d71b30bc682e44ccf7340e20ea7ea8967ef5",
"md5sum": "fa2ec4b1fffad67d8103c3391bbf9df2",
"download_url": "https://sourceforge.net/projects/gns-3/files/Qemu%20Appliances/",
"direct_download_url": "http://downloads.sourceforge.net/project/gns-3/Qemu%20Appliances/linux-microcore-3.4.1.img"
},
{
"filename": "linux-microcore-4.0.2-clean.img",
"version": "4.0.2",
"sha1sum": "0252f2c913519c993b812325bbd553af2d77218a",
"md5sum": "e13d0d1c0b3999ae2386bba70417930c",
"download_url": "https://sourceforge.net/projects/gns-3/files/Qemu%20Appliances/",
"direct_download_url": "http://downloads.sourceforge.net/project/gns-3/Qemu%20Appliances/linux-microcore-4.0.2-clean.img"
}

View File

@ -28,7 +28,7 @@ class Image:
:params: path of the image
"""
self._path = path
self._sha1sum = None
self._md5sum = None
self._version = None
@property
@ -53,20 +53,20 @@ class Image:
self._version = version
@property
def sha1sum(self):
def md5sum(self):
"""
Compute a sha1 hash for file
:returns: hexadecimal sha1
"""
if self._sha1sum is None:
m = hashlib.sha1()
if self._md5sum is None:
m = hashlib.md5()
with open(self._path, "rb") as f:
while True:
buf = f.read(128)
buf = f.read(4096)
if not buf:
break
m.update(buf)
self._sha1sum = m.hexdigest()
return self._sha1sum
self._md5sum = m.hexdigest()
return self._md5sum

View File

@ -58,11 +58,11 @@ class Registry:
return configurations
def download_image(self, sha1sum, images_dir):
def download_image(self, md5sum, images_dir):
for config in self._all_configs():
for image_type in config.get("images", {}):
for file in config["images"].get(image_type, []):
if file["sha1sum"] == sha1sum:
if file["md5sum"] == md5sum:
path = os.path.join(images_dir, "QEMU", file["filename"])
if "direct_download_url" in file:
@ -107,7 +107,7 @@ class Registry:
continue
for file in images:
if isinstance(file, dict):
if file.get("sha1sum", None) == image.sha1sum:
if file.get("md5sum", None) == image.md5sum:
image.version = file["version"]
config["images"][image_type] = image
matched = True

View File

@ -146,7 +146,7 @@ def test_add_images_cdrom(empty_config, linux_microcore_img):
"kernel_image": "",
"legacy_networking": False,
"name": "HP VSR1001 7.10.R0204P01",
"options": "-nographic",
"options": "",
"process_priority": "normal",
"qemu_path": "qemu-system-x86_64",
"ram": 1024,
@ -160,13 +160,13 @@ def test_add_images_router_two_disk(empty_config):
image = MagicMock()
image.version = "2.1.0"
image.sha1sum = "ea9dc1989764fc6db1d388b061340743016214a7"
image.md5sum = "ea9dc1989764fc6db1d388b061340743016214a7"
image.path = "/a"
config["images"]["hda_disk_image"] = image
image = MagicMock()
image.version = "4.13.8M"
image.sha1sum = "ff50656fe817c420e9f7fbb0c0ee41f1ca52fee2"
image.md5sum = "ff50656fe817c420e9f7fbb0c0ee41f1ca52fee2"
image.path = "/b"
config["images"]["hdb_disk_image"] = image
@ -218,7 +218,7 @@ def test_add_images_two_disk_one_missing(empty_config):
image = MagicMock()
image.version = "2.1.0"
image.sha1sum = "ea9dc1989764fc6db1d388b061340743016214a7"
image.md5sum = "ea9dc1989764fc6db1d388b061340743016214a7"
config["images"]["hda_disk_image"] = image
with pytest.raises(ConfigException):