|
|
ea335f |
From 2c47e8f0329a210d26083c7ea7fd14a5553f70b1 Mon Sep 17 00:00:00 2001
|
|
|
97ae69 |
From: "Richard W.M. Jones" <rjones@redhat.com>
|
|
|
ea335f |
Date: Mon, 22 Jul 2019 13:32:54 +0200
|
|
|
97ae69 |
Subject: [PATCH] RHEL 7: -o rhv-upload: Use Python 2 instead of Python 3.
|
|
|
97ae69 |
|
|
|
ea335f |
[Pino: few additional bits edited by me]
|
|
|
97ae69 |
---
|
|
|
a034fe |
v2v/output_rhv_upload.ml | 2 +-
|
|
|
a034fe |
v2v/python_script.ml | 2 +-
|
|
|
ea335f |
v2v/rhv-upload-createvm.py | 20 ++++++++++++---
|
|
|
ea335f |
v2v/rhv-upload-plugin.py | 46 +++++++++++++++++++++++------------
|
|
|
ea335f |
v2v/rhv-upload-precheck.py | 22 +++++++++++++----
|
|
|
97ae69 |
v2v/test-v2v-python-syntax.sh | 2 +-
|
|
|
ea335f |
6 files changed, 67 insertions(+), 27 deletions(-)
|
|
|
97ae69 |
|
|
|
97ae69 |
diff --git a/v2v/output_rhv_upload.ml b/v2v/output_rhv_upload.ml
|
|
|
a034fe |
index 3d6d99008..051ce086f 100644
|
|
|
97ae69 |
--- a/v2v/output_rhv_upload.ml
|
|
|
97ae69 |
+++ b/v2v/output_rhv_upload.ml
|
|
|
a034fe |
@@ -135,7 +135,7 @@ class output_rhv_upload output_alloc output_conn
|
|
|
97ae69 |
error (f_"nbdkit is not new enough, you need to upgrade to nbdkit ≥ 1.1.16")
|
|
|
97ae69 |
in
|
|
|
97ae69 |
|
|
|
97ae69 |
- (* Check that the python3 plugin is installed and working
|
|
|
97ae69 |
+ (* Check that the python plugin is installed and working
|
|
|
97ae69 |
* and can load the plugin script.
|
|
|
97ae69 |
*)
|
|
|
a034fe |
let error_unless_nbdkit_python_plugin_working () =
|
|
|
a034fe |
diff --git a/v2v/python_script.ml b/v2v/python_script.ml
|
|
|
a034fe |
index 3159373a1..fa052d697 100644
|
|
|
a034fe |
--- a/v2v/python_script.ml
|
|
|
a034fe |
+++ b/v2v/python_script.ml
|
|
|
a034fe |
@@ -24,7 +24,7 @@ open Unix_utils
|
|
|
97ae69 |
|
|
|
a034fe |
open Common_gettext.Gettext
|
|
|
97ae69 |
|
|
|
a034fe |
-let python = "python3" (* Defined by PEP 394 *)
|
|
|
a034fe |
+let python = "python"
|
|
|
97ae69 |
|
|
|
a034fe |
type script = {
|
|
|
a034fe |
tmpdir : string; (* Temporary directory. *)
|
|
|
97ae69 |
diff --git a/v2v/rhv-upload-createvm.py b/v2v/rhv-upload-createvm.py
|
|
|
97ae69 |
index 1d0e8c95d..3f2fae4c6 100644
|
|
|
97ae69 |
--- a/v2v/rhv-upload-createvm.py
|
|
|
97ae69 |
+++ b/v2v/rhv-upload-createvm.py
|
|
|
97ae69 |
@@ -1,5 +1,6 @@
|
|
|
97ae69 |
# -*- python -*-
|
|
|
97ae69 |
-# oVirt or RHV upload create VM used by ‘virt-v2v -o rhv-upload’
|
|
|
97ae69 |
+# coding: utf-8
|
|
|
97ae69 |
+# oVirt or RHV upload create VM used by 'virt-v2v -o rhv-upload'
|
|
|
97ae69 |
# Copyright (C) 2018 Red Hat Inc.
|
|
|
97ae69 |
#
|
|
|
97ae69 |
# This program is free software; you can redistribute it and/or modify
|
|
|
97ae69 |
@@ -21,8 +22,8 @@ import logging
|
|
|
97ae69 |
import sys
|
|
|
97ae69 |
import time
|
|
|
97ae69 |
|
|
|
97ae69 |
-from http.client import HTTPSConnection
|
|
|
97ae69 |
-from urllib.parse import urlparse
|
|
|
97ae69 |
+from httplib import HTTPSConnection
|
|
|
97ae69 |
+from urlparse import urlparse
|
|
|
97ae69 |
|
|
|
97ae69 |
import ovirtsdk4 as sdk
|
|
|
97ae69 |
import ovirtsdk4.types as types
|
|
|
97ae69 |
@@ -37,8 +38,19 @@ if len(sys.argv) != 3:
|
|
|
97ae69 |
raise RuntimeError("incorrect number of parameters")
|
|
|
97ae69 |
|
|
|
97ae69 |
# Parameters are passed in via a JSON document.
|
|
|
97ae69 |
+# https://stackoverflow.com/a/13105359
|
|
|
97ae69 |
+def byteify(input):
|
|
|
97ae69 |
+ if isinstance(input, dict):
|
|
|
97ae69 |
+ return {byteify(key): byteify(value)
|
|
|
97ae69 |
+ for key, value in input.iteritems()}
|
|
|
97ae69 |
+ elif isinstance(input, list):
|
|
|
97ae69 |
+ return [byteify(element) for element in input]
|
|
|
97ae69 |
+ elif isinstance(input, unicode):
|
|
|
97ae69 |
+ return input.encode('utf-8')
|
|
|
97ae69 |
+ else:
|
|
|
97ae69 |
+ return input
|
|
|
97ae69 |
with open(sys.argv[1], 'r') as fp:
|
|
|
97ae69 |
- params = json.load(fp)
|
|
|
97ae69 |
+ params = byteify(json.load(fp))
|
|
|
97ae69 |
|
|
|
97ae69 |
# What is passed in is a password file, read the actual password.
|
|
|
97ae69 |
with open(params['output_password'], 'r') as fp:
|
|
|
97ae69 |
diff --git a/v2v/rhv-upload-plugin.py b/v2v/rhv-upload-plugin.py
|
|
|
ea335f |
index b63d127f5..2e8486848 100644
|
|
|
97ae69 |
--- a/v2v/rhv-upload-plugin.py
|
|
|
97ae69 |
+++ b/v2v/rhv-upload-plugin.py
|
|
|
97ae69 |
@@ -1,5 +1,6 @@
|
|
|
97ae69 |
# -*- python -*-
|
|
|
97ae69 |
-# oVirt or RHV upload nbdkit plugin used by ‘virt-v2v -o rhv-upload’
|
|
|
97ae69 |
+# coding: utf-8
|
|
|
97ae69 |
+# oVirt or RHV upload nbdkit plugin used by 'virt-v2v -o rhv-upload'
|
|
|
97ae69 |
# Copyright (C) 2018 Red Hat Inc.
|
|
|
97ae69 |
#
|
|
|
97ae69 |
# This program is free software; you can redistribute it and/or modify
|
|
|
ea335f |
@@ -16,16 +17,17 @@
|
|
|
97ae69 |
# with this program; if not, write to the Free Software Foundation, Inc.,
|
|
|
97ae69 |
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
|
|
97ae69 |
|
|
|
97ae69 |
-import builtins
|
|
|
97ae69 |
+from __builtin__ import open as builtin_open
|
|
|
97ae69 |
import json
|
|
|
97ae69 |
import logging
|
|
|
97ae69 |
import socket
|
|
|
ea335f |
import ssl
|
|
|
97ae69 |
import sys
|
|
|
97ae69 |
import time
|
|
|
ea335f |
+import errno
|
|
|
97ae69 |
|
|
|
97ae69 |
-from http.client import HTTPSConnection, HTTPConnection
|
|
|
97ae69 |
-from urllib.parse import urlparse
|
|
|
97ae69 |
+from httplib import HTTPSConnection, HTTPConnection
|
|
|
97ae69 |
+from urlparse import urlparse
|
|
|
97ae69 |
|
|
|
97ae69 |
import ovirtsdk4 as sdk
|
|
|
97ae69 |
import ovirtsdk4.types as types
|
|
|
ea335f |
@@ -37,14 +39,25 @@ timeout = 5*60
|
|
|
97ae69 |
# Parameters are passed in via a JSON doc from the OCaml code.
|
|
|
97ae69 |
# Because this Python code ships embedded inside virt-v2v there
|
|
|
97ae69 |
# is no formal API here.
|
|
|
97ae69 |
+# https://stackoverflow.com/a/13105359
|
|
|
97ae69 |
+def byteify(input):
|
|
|
97ae69 |
+ if isinstance(input, dict):
|
|
|
97ae69 |
+ return {byteify(key): byteify(value)
|
|
|
97ae69 |
+ for key, value in input.iteritems()}
|
|
|
97ae69 |
+ elif isinstance(input, list):
|
|
|
97ae69 |
+ return [byteify(element) for element in input]
|
|
|
97ae69 |
+ elif isinstance(input, unicode):
|
|
|
97ae69 |
+ return input.encode('utf-8')
|
|
|
97ae69 |
+ else:
|
|
|
97ae69 |
+ return input
|
|
|
97ae69 |
params = None
|
|
|
97ae69 |
|
|
|
97ae69 |
def config(key, value):
|
|
|
97ae69 |
global params
|
|
|
97ae69 |
|
|
|
97ae69 |
if key == "params":
|
|
|
97ae69 |
- with builtins.open(value, 'r') as fp:
|
|
|
97ae69 |
- params = json.load(fp)
|
|
|
97ae69 |
+ with builtin_open(value, 'r') as fp:
|
|
|
97ae69 |
+ params = byteify(json.load(fp))
|
|
|
97ae69 |
else:
|
|
|
97ae69 |
raise RuntimeError("unknown configuration key '%s'" % key)
|
|
|
97ae69 |
|
|
|
ea335f |
@@ -54,13 +67,14 @@ def config_complete():
|
|
|
97ae69 |
|
|
|
97ae69 |
def debug(s):
|
|
|
97ae69 |
if params['verbose']:
|
|
|
97ae69 |
- print(s, file=sys.stderr)
|
|
|
97ae69 |
+ sys.stderr.write(s)
|
|
|
97ae69 |
+ sys.stderr.write("\n")
|
|
|
97ae69 |
sys.stderr.flush()
|
|
|
97ae69 |
|
|
|
97ae69 |
def find_host(connection):
|
|
|
97ae69 |
"""Return the current host object or None."""
|
|
|
97ae69 |
try:
|
|
|
97ae69 |
- with builtins.open("/etc/vdsm/vdsm.id") as f:
|
|
|
97ae69 |
+ with builtin_open("/etc/vdsm/vdsm.id") as f:
|
|
|
97ae69 |
vdsm_id = f.readline().strip()
|
|
|
97ae69 |
except Exception as e:
|
|
|
97ae69 |
# This is most likely not an oVirt host.
|
|
|
ea335f |
@@ -111,7 +125,7 @@ def open(readonly):
|
|
|
97ae69 |
username = parsed.username or "admin@internal"
|
|
|
97ae69 |
|
|
|
97ae69 |
# Read the password from file.
|
|
|
97ae69 |
- with builtins.open(params['output_password'], 'r') as fp:
|
|
|
97ae69 |
+ with builtin_open(params['output_password'], 'r') as fp:
|
|
|
97ae69 |
password = fp.read()
|
|
|
97ae69 |
password = password.rstrip()
|
|
|
97ae69 |
|
|
|
ea335f |
@@ -244,7 +258,7 @@ def open(readonly):
|
|
|
97ae69 |
# New imageio never needs authentication.
|
|
|
97ae69 |
needs_auth = False
|
|
|
97ae69 |
|
|
|
97ae69 |
- j = json.loads(data)
|
|
|
97ae69 |
+ j = byteify(json.loads(data))
|
|
|
97ae69 |
can_flush = "flush" in j['features']
|
|
|
97ae69 |
can_trim = "trim" in j['features']
|
|
|
97ae69 |
can_zero = "zero" in j['features']
|
|
|
ea335f |
@@ -369,8 +383,9 @@ def pwrite(h, buf, offset):
|
|
|
ea335f |
|
|
|
ea335f |
try:
|
|
|
ea335f |
http.send(buf)
|
|
|
ea335f |
- except BrokenPipeError:
|
|
|
ea335f |
- pass
|
|
|
ea335f |
+ except EnvironmentError as e:
|
|
|
ea335f |
+ if e.errno != errno.EPIPE:
|
|
|
ea335f |
+ raise
|
|
|
ea335f |
|
|
|
ea335f |
r = http.getresponse()
|
|
|
ea335f |
if r.status != 200:
|
|
|
ea335f |
@@ -432,8 +447,9 @@ def emulate_zero(h, count, offset):
|
|
|
ea335f |
http.send(buf)
|
|
|
ea335f |
count -= len(buf)
|
|
|
ea335f |
http.send(memoryview(buf)[:count])
|
|
|
ea335f |
- except BrokenPipeError:
|
|
|
ea335f |
- pass
|
|
|
ea335f |
+ except EnvironmentError as e:
|
|
|
ea335f |
+ if e.errno != errno.EPIPE:
|
|
|
ea335f |
+ raise
|
|
|
ea335f |
|
|
|
ea335f |
r = http.getresponse()
|
|
|
ea335f |
if r.status != 200:
|
|
|
ea335f |
@@ -533,7 +549,7 @@ def close(h):
|
|
|
97ae69 |
pass
|
|
|
97ae69 |
|
|
|
97ae69 |
# Write the disk ID file. Only do this on successful completion.
|
|
|
97ae69 |
- with builtins.open(params['diskid_file'], 'w') as fp:
|
|
|
97ae69 |
+ with builtin_open(params['diskid_file'], 'w') as fp:
|
|
|
97ae69 |
fp.write(disk.id)
|
|
|
97ae69 |
|
|
|
97ae69 |
except:
|
|
|
97ae69 |
diff --git a/v2v/rhv-upload-precheck.py b/v2v/rhv-upload-precheck.py
|
|
|
97ae69 |
index 2798a29dd..5b650899f 100644
|
|
|
97ae69 |
--- a/v2v/rhv-upload-precheck.py
|
|
|
97ae69 |
+++ b/v2v/rhv-upload-precheck.py
|
|
|
97ae69 |
@@ -1,5 +1,6 @@
|
|
|
97ae69 |
# -*- python -*-
|
|
|
97ae69 |
-# oVirt or RHV pre-upload checks used by ‘virt-v2v -o rhv-upload’
|
|
|
97ae69 |
+# coding: utf-8
|
|
|
97ae69 |
+# oVirt or RHV pre-upload checks used by 'virt-v2v -o rhv-upload'
|
|
|
97ae69 |
# Copyright (C) 2018 Red Hat Inc.
|
|
|
97ae69 |
#
|
|
|
97ae69 |
# This program is free software; you can redistribute it and/or modify
|
|
|
97ae69 |
@@ -21,8 +22,8 @@ import logging
|
|
|
97ae69 |
import sys
|
|
|
97ae69 |
import time
|
|
|
97ae69 |
|
|
|
97ae69 |
-from http.client import HTTPSConnection
|
|
|
97ae69 |
-from urllib.parse import urlparse
|
|
|
97ae69 |
+from httplib import HTTPSConnection
|
|
|
97ae69 |
+from urlparse import urlparse
|
|
|
97ae69 |
|
|
|
97ae69 |
import ovirtsdk4 as sdk
|
|
|
97ae69 |
import ovirtsdk4.types as types
|
|
|
97ae69 |
@@ -36,8 +37,19 @@ if len(sys.argv) != 2:
|
|
|
97ae69 |
raise RuntimeError("incorrect number of parameters")
|
|
|
97ae69 |
|
|
|
97ae69 |
# Parameters are passed in via a JSON document.
|
|
|
97ae69 |
+# https://stackoverflow.com/a/13105359
|
|
|
97ae69 |
+def byteify(input):
|
|
|
97ae69 |
+ if isinstance(input, dict):
|
|
|
97ae69 |
+ return {byteify(key): byteify(value)
|
|
|
97ae69 |
+ for key, value in input.iteritems()}
|
|
|
97ae69 |
+ elif isinstance(input, list):
|
|
|
97ae69 |
+ return [byteify(element) for element in input]
|
|
|
97ae69 |
+ elif isinstance(input, unicode):
|
|
|
97ae69 |
+ return input.encode('utf-8')
|
|
|
97ae69 |
+ else:
|
|
|
97ae69 |
+ return input
|
|
|
97ae69 |
with open(sys.argv[1], 'r') as fp:
|
|
|
97ae69 |
- params = json.load(fp)
|
|
|
97ae69 |
+ params = byteify(json.load(fp))
|
|
|
97ae69 |
|
|
|
97ae69 |
# What is passed in is a password file, read the actual password.
|
|
|
97ae69 |
with open(params['output_password'], 'r') as fp:
|
|
|
97ae69 |
@@ -67,7 +79,7 @@ vms = vms_service.list(
|
|
|
97ae69 |
)
|
|
|
97ae69 |
if len(vms) > 0:
|
|
|
97ae69 |
vm = vms[0]
|
|
|
97ae69 |
- raise RuntimeError("VM already exists with name ‘%s’, id ‘%s’" %
|
|
|
97ae69 |
+ raise RuntimeError("VM already exists with name '%s', id '%s'" %
|
|
|
97ae69 |
(params['output_name'], vm.id))
|
|
|
97ae69 |
|
|
|
97ae69 |
# Otherwise everything is OK, exit with no error.
|
|
|
97ae69 |
diff --git a/v2v/test-v2v-python-syntax.sh b/v2v/test-v2v-python-syntax.sh
|
|
|
97ae69 |
index b167f4610..8d5924e3c 100755
|
|
|
97ae69 |
--- a/v2v/test-v2v-python-syntax.sh
|
|
|
97ae69 |
+++ b/v2v/test-v2v-python-syntax.sh
|
|
|
97ae69 |
@@ -25,7 +25,7 @@ skip_if_skipped
|
|
|
97ae69 |
files="rhv-upload-createvm.py rhv-upload-plugin.py rhv-upload-precheck.py"
|
|
|
97ae69 |
|
|
|
97ae69 |
# Base version of Python.
|
|
|
97ae69 |
-python=python3
|
|
|
97ae69 |
+python=python
|
|
|
97ae69 |
|
|
|
97ae69 |
# Checks the files are syntactically correct, but not very much else.
|
|
|
97ae69 |
for f in $files; do
|
|
|
97ae69 |
--
|
|
|
a034fe |
2.21.0
|
|
|
97ae69 |
|