Add or remove empty lines to match the needed ones around
blocks/functions/etc.
This is just formatting, no behaviour changes.
---
.../ovirtsdk4/__init__.py | 18 ++++++++++
.../ovirtsdk4/types.py | 12 +++++++
v2v/rhv-upload-plugin.py | 33 +++++++++++++++++++
3 files changed, 63 insertions(+)
diff --git a/tests/test-v2v-o-rhv-upload-module/ovirtsdk4/__init__.py
b/tests/test-v2v-o-rhv-upload-module/ovirtsdk4/__init__.py
index 0bc2890f..abb7050c 100644
--- a/tests/test-v2v-o-rhv-upload-module/ovirtsdk4/__init__.py
+++ b/tests/test-v2v-o-rhv-upload-module/ovirtsdk4/__init__.py
@@ -24,9 +24,12 @@ import threading
class Error(Exception):
pass
+
+
class NotFoundError(Error):
pass
+
class Connection(object):
def __init__(
self,
@@ -49,6 +52,7 @@ class Connection(object):
def system_service(self):
return SystemService()
+
class SystemService(object):
def clusters_service(self):
return ClustersService()
@@ -68,18 +72,22 @@ class SystemService(object):
def vms_service(self):
return VmsService()
+
class ClusterService(object):
def get(self):
return types.Cluster()
+
class ClustersService(object):
def cluster_service(self, id):
return ClusterService()
+
class DataCentersService(object):
def list(self, search=None, case_sensitive=False):
return [types.DataCenter()]
+
class DiskService(object):
def __init__(self, disk_id):
self._disk_id = disk_id
@@ -90,6 +98,7 @@ class DiskService(object):
def remove(self):
pass
+
class DisksService(object):
def add(self, disk=None):
disk.id = "756d81b0-d5c0-41bc-9bbe-b343c3fa3490"
@@ -98,6 +107,7 @@ class DisksService(object):
def disk_service(self, disk_id):
return DiskService(disk_id)
+
class ImageTransferService(object):
def __init__(self):
self._finalized = False
@@ -114,6 +124,7 @@ class ImageTransferService(object):
def finalize(self):
self._finalized = True
+
class ImageTransfersService(object):
def add(self, transfer):
return transfer
@@ -121,10 +132,12 @@ class ImageTransfersService(object):
def image_transfer_service(self, id):
return ImageTransferService()
+
class StorageDomainsService(object):
def list(self, search=None, case_sensitive=False):
return [StorageDomain()]
+
class VmsService(object):
def add(self, vm):
return vm
@@ -132,9 +145,11 @@ class VmsService(object):
def list(self, search=None):
return []
+
# Create a background thread running a web server which is
# simulating the imageio server.
+
class RequestHandler(BaseHTTPRequestHandler):
protocol_version = 'HTTP/1.1'
@@ -171,14 +186,17 @@ class RequestHandler(BaseHTTPRequestHandler):
length = int(length)
content = self.rfile.read(length)
+
server_address = ("", 0)
# XXX This should test HTTPS, not HTTP, because we are testing a
# different path through the main code.
httpd = HTTPServer(server_address, RequestHandler)
imageio_port = httpd.server_address[1]
+
def server():
httpd.serve_forever()
+
thread = threading.Thread(target=server, args=[], daemon=True)
thread.start()
diff --git a/tests/test-v2v-o-rhv-upload-module/ovirtsdk4/types.py
b/tests/test-v2v-o-rhv-upload-module/ovirtsdk4/types.py
index 3b5cd0ac..b8d4a728 100644
--- a/tests/test-v2v-o-rhv-upload-module/ovirtsdk4/types.py
+++ b/tests/test-v2v-o-rhv-upload-module/ovirtsdk4/types.py
@@ -21,14 +21,17 @@
from enum import Enum
from ovirtsdk4 import imageio_port
+
class Cluster(object):
id = "2e97537b-a783-4706-af9e-75cb2e032dcd"
name = "Default"
+
class Configuration(object):
def __init__(self, type=None, data=None):
pass
+
class ConfigurationType(Enum):
OVA = 'ova'
OVF = 'ovf'
@@ -39,6 +42,7 @@ class ConfigurationType(Enum):
def __str__(self):
return self._image
+
class DiskFormat(Enum):
COW = "cow"
RAW = "raw"
@@ -49,6 +53,7 @@ class DiskFormat(Enum):
def __str__(self):
return self._image
+
class DiskStatus(Enum):
ILLEGAL = "illegal"
LOCKED = "locked"
@@ -60,6 +65,7 @@ class DiskStatus(Enum):
def __str__(self):
return self._image
+
class Disk(object):
def __init__(
self,
@@ -76,6 +82,7 @@ class Disk(object):
status = DiskStatus.OK
+
class ImageTransferPhase(Enum):
CANCELLED = 'cancelled'
FINALIZING_FAILURE = 'finalizing_failure'
@@ -95,6 +102,7 @@ class ImageTransferPhase(Enum):
def __str__(self):
return self._image
+
class ImageTransfer(object):
def __init__(
self,
@@ -108,10 +116,12 @@ class ImageTransfer(object):
phase = ImageTransferPhase.TRANSFERRING
transfer_url = "http://localhost:" + str(imageio_port) + "/"
+
class Initialization(object):
def __init__(self, configuration):
pass
+
class StorageDomain(object):
def __init__(self, name=None):
pass
@@ -119,6 +129,7 @@ class StorageDomain(object):
id = "ba87af68-b630-4211-a73a-694c1a689405"
name = "Storage"
+
class Vm(object):
def __init__(
self,
@@ -127,6 +138,7 @@ class Vm(object):
):
pass
+
class DataCenter(object):
id = "31d8c73b-554b-4958-bb04-9ce97f0849e1"
name = "DC"
diff --git a/v2v/rhv-upload-plugin.py b/v2v/rhv-upload-plugin.py
index ab14bc2d..d3e6260e 100644
--- a/v2v/rhv-upload-plugin.py
+++ b/v2v/rhv-upload-plugin.py
@@ -41,6 +41,7 @@ timeout = 5 * 60
# is no formal API here.
params = None
+
def config(key, value):
global params
@@ -51,15 +52,18 @@ def config(key, value):
else:
raise RuntimeError("unknown configuration key '%s'" % key)
+
def config_complete():
if params is None:
raise RuntimeError("missing configuration parameters")
+
def debug(s):
if params['verbose']:
print(s, file=sys.stderr)
sys.stderr.flush()
+
def read_password():
"""
Read the password from file.
@@ -68,6 +72,7 @@ def read_password():
data = fp.read()
return data.rstrip()
+
def parse_username():
"""
Parse out the username from the output_conn URL.
@@ -75,6 +80,7 @@ def parse_username():
parsed = urlparse(params['output_conn'])
return parsed.username or "admin@internal"
+
def failing(func):
"""
Decorator marking the handle as failed if any expection is raised in the
@@ -91,6 +97,7 @@ def failing(func):
return wrapper
+
def open(readonly):
connection = sdk.Connection(
url=params['output_conn'],
@@ -134,18 +141,22 @@ def open(readonly):
'path': destination_url.path,
}
+
@failing
def can_trim(h):
return h['can_trim']
+
@failing
def can_flush(h):
return h['can_flush']
+
@failing
def get_size(h):
return params['disk_size']
+
# Any unexpected HTTP response status from the server will end up calling this
# function which logs the full error, and raises a RuntimeError exception.
def request_failed(r, msg):
@@ -165,11 +176,13 @@ def request_failed(r, msg):
# Only a short error is included in the exception.
raise RuntimeError("%s: %d %s: %r" % (msg, status, reason, body[:200]))
+
# For documentation see:
#
https://github.com/oVirt/ovirt-imageio/blob/master/docs/random-io.md
# For examples of working code to read/write from the server, see:
#
https://github.com/oVirt/ovirt-imageio/blob/master/daemon/test/server_tes...
+
@failing
def pread(h, count, offset):
http = h['http']
@@ -190,6 +203,7 @@ def pread(h, count, offset):
return r.read()
+
@failing
def pwrite(h, buf, offset):
http = h['http']
@@ -220,6 +234,7 @@ def pwrite(h, buf, offset):
r.read()
+
@failing
def zero(h, count, offset, may_trim):
http = h['http']
@@ -250,6 +265,7 @@ def zero(h, count, offset, may_trim):
r.read()
+
def emulate_zero(h, count, offset):
http = h['http']
transfer = h['transfer']
@@ -284,6 +300,7 @@ def emulate_zero(h, count, offset):
r.read()
+
@failing
def trim(h, count, offset):
http = h['http']
@@ -307,6 +324,7 @@ def trim(h, count, offset):
r.read()
+
@failing
def flush(h):
http = h['http']
@@ -325,6 +343,7 @@ def flush(h):
r.read()
+
def close(h):
http = h['http']
connection = h['connection']
@@ -362,11 +381,13 @@ def close(h):
finally:
connection.close()
+
# Modify http.client.HTTPConnection to work over a Unix domain socket.
# Derived from uhttplib written by Erik van Zijst under an MIT license.
# (
https://pypi.org/project/uhttplib/)
# Ported to Python 3 by Irit Goihman.
+
class UnixHTTPConnection(HTTPConnection):
def __init__(self, path, timeout=socket._GLOBAL_DEFAULT_TIMEOUT):
self.path = path
@@ -378,8 +399,10 @@ class UnixHTTPConnection(HTTPConnection):
self.sock.settimeout(timeout)
self.sock.connect(self.path)
+
# oVirt SDK operations
+
def find_host(connection):
"""Return the current host object or None."""
try:
@@ -428,6 +451,7 @@ def find_host(connection):
return types.Host(id=host.id)
+
def create_disk(connection):
"""
Create a new disk for the transfer and wait until the disk is ready.
@@ -483,6 +507,7 @@ def create_disk(connection):
return disk
+
def create_transfer(connection, disk, host):
"""
Create image transfer and wait until the transfer is ready.
@@ -553,6 +578,7 @@ def create_transfer(connection, disk, host):
return transfer
+
def cancel_transfer(connection, transfer):
"""
Cancel a transfer, removing the transfer disk.
@@ -563,6 +589,7 @@ def cancel_transfer(connection, transfer):
.image_transfer_service(transfer.id))
transfer_service.cancel()
+
def finalize_transfer(connection, transfer, disk_id):
"""
Finalize a transfer, making the transfer disk available.
@@ -621,6 +648,7 @@ def finalize_transfer(connection, transfer, disk_id):
"timed out waiting for transfer %s to finalize"
% transfer.id)
+
def transfer_supports_format():
"""
Return True if transfer supports the "format" argument, enabing the NBD
@@ -632,8 +660,10 @@ def transfer_supports_format():
sig = inspect.signature(types.ImageTransfer)
return "format" in sig.parameters
+
# oVirt imageio operations
+
def parse_transfer_url(transfer):
"""
Returns a parsed transfer url, preferring direct transfer if possible.
@@ -648,6 +678,7 @@ def parse_transfer_url(transfer):
else:
return urlparse(transfer.proxy_url)
+
def create_http(url):
"""
Create http connection for transfer url.
@@ -668,6 +699,7 @@ def create_http(url):
else:
raise RuntimeError("unknown URL scheme (%s)" % url.scheme)
+
def get_options(http, url):
"""
Send OPTIONS request to imageio server and return options dict.
@@ -704,6 +736,7 @@ def get_options(http, url):
raise RuntimeError("could not use OPTIONS request: %d: %s" %
(r.status, r.reason))
+
def optimize_http(http, host, options):
"""
Return an optimized http connection using unix socket if we are connected
--
2.24.1