diff mbox series

[v1,10/26] tests/vm: Port basevm to Python 3

Message ID 20190530101603.22254-11-alex.bennee@linaro.org
State Superseded
Headers show
Series testing/next queue (iotests, docker, tests/vm) | expand

Commit Message

Alex Bennée May 30, 2019, 10:15 a.m. UTC
From: Wainer dos Santos Moschetta <wainersm@redhat.com>


Fixed tests/vm/basevm.py to run with Python 3:
 - hashlib.sha1() requires an binary encoded object.
 - uses floor division ("//") (PEP 238).
 - decode bytes to unicode when needed.

Signed-off-by: Wainer dos Santos Moschetta <wainersm@redhat.com>

Reviewed-by: Philippe Mathieu-Daudé <philmd@redhat.com>

Message-Id: <20190329210804.22121-3-wainersm@redhat.com>
Signed-off-by: Alex Bennée <alex.bennee@linaro.org>

---
 tests/vm/basevm.py | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

-- 
2.20.1

Comments

Philippe Mathieu-Daudé May 31, 2019, 6:22 a.m. UTC | #1
On 5/30/19 12:15 PM, Alex Bennée wrote:
> From: Wainer dos Santos Moschetta <wainersm@redhat.com>

> 

> Fixed tests/vm/basevm.py to run with Python 3:

>  - hashlib.sha1() requires an binary encoded object.

>  - uses floor division ("//") (PEP 238).

>  - decode bytes to unicode when needed.

> 

> Signed-off-by: Wainer dos Santos Moschetta <wainersm@redhat.com>

> Reviewed-by: Philippe Mathieu-Daudé <philmd@redhat.com>

> Message-Id: <20190329210804.22121-3-wainersm@redhat.com>

> Signed-off-by: Alex Bennée <alex.bennee@linaro.org>


Tested-by: Philippe Mathieu-Daudé <philmd@redhat.com>


> ---

>  tests/vm/basevm.py | 8 ++++----

>  1 file changed, 4 insertions(+), 4 deletions(-)

> 

> diff --git a/tests/vm/basevm.py b/tests/vm/basevm.py

> index 0556bdcf9e9..083befce9f5 100755

> --- a/tests/vm/basevm.py

> +++ b/tests/vm/basevm.py

> @@ -85,12 +85,12 @@ class BaseVM(object):

>              if not sha256sum:

>                  return True

>              checksum = subprocess.check_output(["sha256sum", fname]).split()[0]

> -            return sha256sum == checksum

> +            return sha256sum == checksum.decode()

>  

>          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).hexdigest())

> +        fname = os.path.join(cache_dir, hashlib.sha1(url.encode()).hexdigest())

>          if os.path.exists(fname) and check_sha256sum(fname):

>              return fname

>          logging.debug("Downloading %s to %s...", url, fname)

> @@ -134,7 +134,7 @@ class BaseVM(object):

>          raise NotImplementedError

>  

>      def add_source_dir(self, src_dir):

> -        name = "data-" + hashlib.sha1(src_dir).hexdigest()[:5]

> +        name = "data-" + hashlib.sha1(src_dir.encode()).hexdigest()[:5]

>          tarfile = os.path.join(self._tmpdir, name + ".tar")

>          logging.debug("Creating archive %s for src_dir dir: %s", tarfile, src_dir)

>          subprocess.check_call(["./scripts/archive-source.sh", tarfile],

> @@ -204,7 +204,7 @@ def parse_args(vmcls):

>  

>      def get_default_jobs():

>          if kvm_available(vmcls.arch):

> -            return multiprocessing.cpu_count() / 2

> +            return multiprocessing.cpu_count() // 2

>          else:

>              return 1

>  

>
diff mbox series

Patch

diff --git a/tests/vm/basevm.py b/tests/vm/basevm.py
index 0556bdcf9e9..083befce9f5 100755
--- a/tests/vm/basevm.py
+++ b/tests/vm/basevm.py
@@ -85,12 +85,12 @@  class BaseVM(object):
             if not sha256sum:
                 return True
             checksum = subprocess.check_output(["sha256sum", fname]).split()[0]
-            return sha256sum == checksum
+            return sha256sum == checksum.decode()
 
         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).hexdigest())
+        fname = os.path.join(cache_dir, hashlib.sha1(url.encode()).hexdigest())
         if os.path.exists(fname) and check_sha256sum(fname):
             return fname
         logging.debug("Downloading %s to %s...", url, fname)
@@ -134,7 +134,7 @@  class BaseVM(object):
         raise NotImplementedError
 
     def add_source_dir(self, src_dir):
-        name = "data-" + hashlib.sha1(src_dir).hexdigest()[:5]
+        name = "data-" + hashlib.sha1(src_dir.encode()).hexdigest()[:5]
         tarfile = os.path.join(self._tmpdir, name + ".tar")
         logging.debug("Creating archive %s for src_dir dir: %s", tarfile, src_dir)
         subprocess.check_call(["./scripts/archive-source.sh", tarfile],
@@ -204,7 +204,7 @@  def parse_args(vmcls):
 
     def get_default_jobs():
         if kvm_available(vmcls.arch):
-            return multiprocessing.cpu_count() / 2
+            return multiprocessing.cpu_count() // 2
         else:
             return 1