diff mbox series

[v1,6/6] tests/vm: support sites with sha512 checksums

Message ID 20191104173654.30125-7-alex.bennee@linaro.org (mailing list archive)
State New, archived
Headers show
Series testing/next (netbsd stuff) | expand

Commit Message

Alex Bennée Nov. 4, 2019, 5:36 p.m. UTC
The NetBSD project uses SHA512 for its checksums so lets support that
in the download helper.

Signed-off-by: Alex Bennée <alex.bennee@linaro.org>
---
 tests/vm/basevm.py | 10 ++++++++--
 tests/vm/netbsd    |  3 ++-
 2 files changed, 10 insertions(+), 3 deletions(-)

Comments

Philippe Mathieu-Daudé Nov. 4, 2019, 6:50 p.m. UTC | #1
On 11/4/19 6:36 PM, Alex Bennée wrote:
> The NetBSD project uses SHA512 for its checksums so lets support that
> in the download helper.
> 
> Signed-off-by: Alex Bennée <alex.bennee@linaro.org>
> ---
>   tests/vm/basevm.py | 10 ++++++++--
>   tests/vm/netbsd    |  3 ++-
>   2 files changed, 10 insertions(+), 3 deletions(-)
> 
> diff --git a/tests/vm/basevm.py b/tests/vm/basevm.py
> index 086bfb2c66d..91a9226026d 100755
> --- a/tests/vm/basevm.py
> +++ b/tests/vm/basevm.py
> @@ -95,19 +95,25 @@ class BaseVM(object):
>               logging.info("KVM not available, not using -enable-kvm")
>           self._data_args = []
>   
> -    def _download_with_cache(self, url, sha256sum=None):
> +    def _download_with_cache(self, url, sha256sum=None, sha512sum=None):
>           def check_sha256sum(fname):
>               if not sha256sum:
>                   return True
>               checksum = subprocess.check_output(["sha256sum", fname]).split()[0]
>               return sha256sum == checksum.decode("utf-8")
>   
> +        def check_sha512sum(fname):
> +            if not sha512sum:
> +                return True
> +            checksum = subprocess.check_output(["sha512sum", fname]).split()[0]
> +            return sha512sum == checksum.decode("utf-8")
> +
>           cache_dir = os.path.expanduser("~/.cache/qemu-vm/download")
>           if not os.path.exists(cache_dir):
>               os.makedirs(cache_dir)
>           fname = os.path.join(cache_dir,
>                                hashlib.sha1(url.encode("utf-8")).hexdigest())
> -        if os.path.exists(fname) and check_sha256sum(fname):
> +        if os.path.exists(fname) and check_sha256sum(fname) and check_sha512sum(fname):
>               return fname
>           logging.debug("Downloading %s to %s...", url, fname)
>           subprocess.check_call(["wget", "-c", url, "-O", fname + ".download"],
> diff --git a/tests/vm/netbsd b/tests/vm/netbsd
> index 33779402dd1..89390e99fdd 100755
> --- a/tests/vm/netbsd
> +++ b/tests/vm/netbsd
> @@ -23,6 +23,7 @@ class NetBSDVM(basevm.BaseVM):
>       arch = "x86_64"
>   
>       link = "https://cdn.netbsd.org/pub/NetBSD/NetBSD-8.1/images/NetBSD-8.1-amd64.iso"
> +    csum = "718f275b7e0879599bdac95630c5e3f2184700032fdb6cdebf3bdd63687898c48ff3f08f57b89f4437a86cdd8ea07c01a39d432dbb37e1e4b008f4985f98da3f"
>       size = "20G"
>       pkgs = [
>           # tools
> @@ -70,7 +71,7 @@ class NetBSDVM(basevm.BaseVM):
>       ipv6 = False
>   
>       def build_image(self, img):
> -        cimg = self._download_with_cache(self.link)
> +        cimg = self._download_with_cache(self.link, sha512sum=self.csum)
>           img_tmp = img + ".tmp"
>           iso = img + ".install.iso"
>   
> 

Reviewed-by: Philippe Mathieu-Daudé <philmd@redhat.com>
Tested-by: Philippe Mathieu-Daudé <philmd@redhat.com>
diff mbox series

Patch

diff --git a/tests/vm/basevm.py b/tests/vm/basevm.py
index 086bfb2c66d..91a9226026d 100755
--- a/tests/vm/basevm.py
+++ b/tests/vm/basevm.py
@@ -95,19 +95,25 @@  class BaseVM(object):
             logging.info("KVM not available, not using -enable-kvm")
         self._data_args = []
 
-    def _download_with_cache(self, url, sha256sum=None):
+    def _download_with_cache(self, url, sha256sum=None, sha512sum=None):
         def check_sha256sum(fname):
             if not sha256sum:
                 return True
             checksum = subprocess.check_output(["sha256sum", fname]).split()[0]
             return sha256sum == checksum.decode("utf-8")
 
+        def check_sha512sum(fname):
+            if not sha512sum:
+                return True
+            checksum = subprocess.check_output(["sha512sum", fname]).split()[0]
+            return sha512sum == checksum.decode("utf-8")
+
         cache_dir = os.path.expanduser("~/.cache/qemu-vm/download")
         if not os.path.exists(cache_dir):
             os.makedirs(cache_dir)
         fname = os.path.join(cache_dir,
                              hashlib.sha1(url.encode("utf-8")).hexdigest())
-        if os.path.exists(fname) and check_sha256sum(fname):
+        if os.path.exists(fname) and check_sha256sum(fname) and check_sha512sum(fname):
             return fname
         logging.debug("Downloading %s to %s...", url, fname)
         subprocess.check_call(["wget", "-c", url, "-O", fname + ".download"],
diff --git a/tests/vm/netbsd b/tests/vm/netbsd
index 33779402dd1..89390e99fdd 100755
--- a/tests/vm/netbsd
+++ b/tests/vm/netbsd
@@ -23,6 +23,7 @@  class NetBSDVM(basevm.BaseVM):
     arch = "x86_64"
 
     link = "https://cdn.netbsd.org/pub/NetBSD/NetBSD-8.1/images/NetBSD-8.1-amd64.iso"
+    csum = "718f275b7e0879599bdac95630c5e3f2184700032fdb6cdebf3bdd63687898c48ff3f08f57b89f4437a86cdd8ea07c01a39d432dbb37e1e4b008f4985f98da3f"
     size = "20G"
     pkgs = [
         # tools
@@ -70,7 +71,7 @@  class NetBSDVM(basevm.BaseVM):
     ipv6 = False
 
     def build_image(self, img):
-        cimg = self._download_with_cache(self.link)
+        cimg = self._download_with_cache(self.link, sha512sum=self.csum)
         img_tmp = img + ".tmp"
         iso = img + ".install.iso"