Pino Toscano
2020-Jan-10 15:47 UTC
[Libguestfs] [v2v PATCH 0/6] Various Python pycodestyle fixes
Fixes the majority of the pycodestyle issues in the Python scripts, and fix the existing test-v2v-python-syntax.sh to use pycodestyle to actually perform style checks. Pino Toscano (6): PEP 8: adapt whitespaces in lines PEP 8: move imports at the top PEP 8: adapt empty lines tests: find all the Python scripts for syntax checks -o rhv-upload: remove unused Python imports Revamp check for Python code style config.sh.in | 1 + m4/guestfs-progs.m4 | 3 + .../ovirtsdk4/__init__.py | 39 +++++-- .../ovirtsdk4/types.py | 40 ++++--- v2v/rhv-upload-createvm.py | 20 ++-- v2v/rhv-upload-deletedisks.py | 14 +-- v2v/rhv-upload-plugin.py | 105 ++++++++++++------ v2v/rhv-upload-precheck.py | 18 ++- v2v/rhv-upload-vmcheck.py | 16 ++- v2v/test-v2v-python-syntax.sh | 17 ++- 10 files changed, 165 insertions(+), 108 deletions(-) -- 2.24.1
Pino Toscano
2020-Jan-10 15:47 UTC
[Libguestfs] [v2v PATCH 1/6] PEP 8: adapt whitespaces in lines
Fix continuation indentation, and whitespaces around operators. This is just code reformatting, with no behaviour changes; no content changed beside whitespaces, so "git diff -w" gives an empty diff --- .../ovirtsdk4/__init__.py | 16 ++--- .../ovirtsdk4/types.py | 28 ++++---- v2v/rhv-upload-createvm.py | 18 ++--- v2v/rhv-upload-deletedisks.py | 12 ++-- v2v/rhv-upload-plugin.py | 72 +++++++++---------- v2v/rhv-upload-precheck.py | 16 ++--- v2v/rhv-upload-vmcheck.py | 14 ++-- 7 files changed, 88 insertions(+), 88 deletions(-) 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 09d861d3..774c7a5c 100644 --- a/tests/test-v2v-o-rhv-upload-module/ovirtsdk4/__init__.py +++ b/tests/test-v2v-o-rhv-upload-module/ovirtsdk4/__init__.py @@ -26,12 +26,12 @@ class NotFoundError(Error): class Connection(object): def __init__( self, - url = None, - username = None, - password = None, - ca_file = None, - log = None, - insecure = False, + url=None, + username=None, + password=None, + ca_file=None, + log=None, + insecure=False, debug=True, ): pass @@ -119,7 +119,7 @@ class ImageTransfersService(object): class StorageDomainsService(object): def list(self, search=None, case_sensitive=False): - return [ StorageDomain() ] + return [StorageDomain()] class VmsService(object): def add(self, vm): @@ -179,5 +179,5 @@ imageio_port = httpd.server_address[1] def server(): httpd.serve_forever() -thread = threading.Thread(target = server, args = [], daemon = True) +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 0b165c24..3b5cd0ac 100644 --- a/tests/test-v2v-o-rhv-upload-module/ovirtsdk4/types.py +++ b/tests/test-v2v-o-rhv-upload-module/ovirtsdk4/types.py @@ -63,14 +63,14 @@ class DiskStatus(Enum): class Disk(object): def __init__( self, - id = None, - name = None, - description = None, - format = None, - initial_size = None, - provisioned_size = None, - sparse = False, - storage_domains = None + id=None, + name=None, + description=None, + format=None, + initial_size=None, + provisioned_size=None, + sparse=False, + storage_domains=None ): self.id = id @@ -98,9 +98,9 @@ class ImageTransferPhase(Enum): class ImageTransfer(object): def __init__( self, - disk = None, - host = None, - inactivity_timeout = None, + disk=None, + host=None, + inactivity_timeout=None, ): pass @@ -113,7 +113,7 @@ class Initialization(object): pass class StorageDomain(object): - def __init__(self, name = None): + def __init__(self, name=None): pass id = "ba87af68-b630-4211-a73a-694c1a689405" @@ -122,8 +122,8 @@ class StorageDomain(object): class Vm(object): def __init__( self, - cluster = None, - initialization = None + cluster=None, + initialization=None ): pass diff --git a/v2v/rhv-upload-createvm.py b/v2v/rhv-upload-createvm.py index ed57a9b2..f0b747ec 100644 --- a/v2v/rhv-upload-createvm.py +++ b/v2v/rhv-upload-createvm.py @@ -55,12 +55,12 @@ username = parsed.username or "admin@internal" # Connect to the server. connection = sdk.Connection( - url = params['output_conn'], - username = username, - password = output_password, - ca_file = params['rhv_cafile'], - log = logging.getLogger(), - insecure = params['insecure'], + url=params['output_conn'], + username=username, + password=output_password, + ca_file=params['rhv_cafile'], + log=logging.getLogger(), + insecure=params['insecure'], ) system_service = connection.system_service() @@ -74,9 +74,9 @@ vm = vms_service.add( types.Vm( cluster=cluster, initialization=types.Initialization( - configuration = types.Configuration( - type = types.ConfigurationType.OVA, - data = ovf, + configuration=types.Configuration( + type=types.ConfigurationType.OVA, + data=ovf, ) ) ) diff --git a/v2v/rhv-upload-deletedisks.py b/v2v/rhv-upload-deletedisks.py index bdd570b4..3c970801 100644 --- a/v2v/rhv-upload-deletedisks.py +++ b/v2v/rhv-upload-deletedisks.py @@ -50,12 +50,12 @@ username = parsed.username or "admin@internal" # Connect to the server. connection = sdk.Connection( - url = params['output_conn'], - username = username, - password = output_password, - ca_file = params['rhv_cafile'], - log = logging.getLogger(), - insecure = params['insecure'], + url=params['output_conn'], + username=username, + password=output_password, + ca_file=params['rhv_cafile'], + log=logging.getLogger(), + insecure=params['insecure'], ) system_service = connection.system_service() diff --git a/v2v/rhv-upload-plugin.py b/v2v/rhv-upload-plugin.py index 3942ec72..ab14bc2d 100644 --- a/v2v/rhv-upload-plugin.py +++ b/v2v/rhv-upload-plugin.py @@ -34,7 +34,7 @@ import ovirtsdk4.types as types # Timeout to wait for oVirt disks to change status, or the transfer # object to finish initializing [seconds]. -timeout = 5*60 +timeout = 5 * 60 # Parameters are passed in via a JSON doc from the OCaml code. # Because this Python code ships embedded inside virt-v2v there @@ -93,12 +93,12 @@ def failing(func): def open(readonly): connection = sdk.Connection( - url = params['output_conn'], - username = parse_username(), - password = read_password(), - ca_file = params['rhv_cafile'], - log = logging.getLogger(), - insecure = params['insecure'], + url=params['output_conn'], + username=parse_username(), + password=read_password(), + ca_file=params['rhv_cafile'], + log=logging.getLogger(), + insecure=params['insecure'], ) # Use the local host is possible. @@ -175,7 +175,7 @@ def pread(h, count, offset): http = h['http'] transfer = h['transfer'] - headers = {"Range": "bytes=%d-%d" % (offset, offset+count-1)} + headers = {"Range": "bytes=%d-%d" % (offset, offset + count - 1)} if h['needs_auth']: headers["Authorization"] = transfer.signed_ticket @@ -196,14 +196,14 @@ def pwrite(h, buf, offset): transfer = h['transfer'] count = len(buf) - h['highestwrite'] = max(h['highestwrite'], offset+count) + h['highestwrite'] = max(h['highestwrite'], offset + count) http.putrequest("PUT", h['path'] + "?flush=n") if h['needs_auth']: http.putheader("Authorization", transfer.signed_ticket) # The oVirt server only uses the first part of the range, and the # content-length. - http.putheader("Content-Range", "bytes %d-%d/*" % (offset, offset+count-1)) + http.putheader("Content-Range", "bytes %d-%d/*" % (offset, offset + count - 1)) http.putheader("Content-Length", str(count)) http.endheaders() @@ -258,17 +258,17 @@ def emulate_zero(h, count, offset): # Since we've just created a new disk it's safe to ignore these # requests as long as they are smaller than the highest write seen. # After that we must emulate them with writes. - if offset+count < h['highestwrite']: + if offset + count < h['highestwrite']: http.putrequest("PUT", h['path']) if h['needs_auth']: http.putheader("Authorization", transfer.signed_ticket) http.putheader("Content-Range", - "bytes %d-%d/*" % (offset, offset+count-1)) + "bytes %d-%d/*" % (offset, offset + count - 1)) http.putheader("Content-Length", str(count)) http.endheaders() try: - buf = bytearray(128*1024) + buf = bytearray(128 * 1024) while count > len(buf): http.send(buf) count -= len(buf) @@ -426,7 +426,7 @@ def find_host(connection): host = hosts[0] debug("host.id = %r" % host.id) - return types.Host(id = host.id) + return types.Host(id=host.id) def create_disk(connection): """ @@ -443,23 +443,23 @@ def create_disk(connection): disk_format = types.DiskFormat.COW disk = disks_service.add( - disk = types.Disk( + disk=types.Disk( # The ID is optional. - id = params.get('rhv_disk_uuid'), - name = params['disk_name'], - description = "Uploaded by virt-v2v", - format = disk_format, + id=params.get('rhv_disk_uuid'), + name=params['disk_name'], + description="Uploaded by virt-v2v", + format=disk_format, # XXX For qcow2 disk on block storage, we should use the estimated # size, based on qemu-img measure of the overlay. - initial_size = params['disk_size'], - provisioned_size = params['disk_size'], + initial_size=params['disk_size'], + provisioned_size=params['disk_size'], # XXX Ignores params['output_sparse']. # Handling this properly will be complex, see: # https://www.redhat.com/archives/libguestfs/2018-March/msg00177.html - sparse = True, - storage_domains = [ + sparse=True, + storage_domains=[ types.StorageDomain( - name = params['output_storage'], + name=params['output_storage'], ) ], ) @@ -498,9 +498,9 @@ def create_transfer(connection, disk, host): transfer = transfers_service.add( types.ImageTransfer( - disk = types.Disk(id = disk.id), - host = host, - inactivity_timeout = 3600, + disk=types.Disk(id=disk.id), + host=host, + inactivity_timeout=3600, **extra, ) ) @@ -559,8 +559,8 @@ def cancel_transfer(connection, transfer): """ debug("canceling transfer %s" % transfer.id) transfer_service = (connection.system_service() - .image_transfers_service() - .image_transfer_service(transfer.id)) + .image_transfers_service() + .image_transfer_service(transfer.id)) transfer_service.cancel() def finalize_transfer(connection, transfer, disk_id): @@ -585,16 +585,16 @@ def finalize_transfer(connection, transfer, disk_id): """ debug("finalizing transfer %s" % transfer.id) transfer_service = (connection.system_service() - .image_transfers_service() - .image_transfer_service(transfer.id)) + .image_transfers_service() + .image_transfer_service(transfer.id)) start = time.time() transfer_service.finalize() disk_service = (connection.system_service() - .disks_service() - .disk_service(disk_id)) + .disks_service() + .disk_service(disk_id)) while True: time.sleep(1) @@ -656,13 +656,13 @@ def create_http(url): """ if url.scheme == "https": context = \ - ssl.create_default_context(purpose = ssl.Purpose.SERVER_AUTH, - cafile = params['rhv_cafile']) + ssl.create_default_context(purpose=ssl.Purpose.SERVER_AUTH, + cafile=params['rhv_cafile']) if params['insecure']: context.check_hostname = False context.verify_mode = ssl.CERT_NONE - return HTTPSConnection(url.hostname, url.port, context = context) + return HTTPSConnection(url.hostname, url.port, context=context) elif url.scheme == "http": return HTTPConnection(url.hostname, url.port) else: diff --git a/v2v/rhv-upload-precheck.py b/v2v/rhv-upload-precheck.py index 1b344ba2..e8be90c5 100644 --- a/v2v/rhv-upload-precheck.py +++ b/v2v/rhv-upload-precheck.py @@ -50,12 +50,12 @@ username = parsed.username or "admin@internal" # Connect to the server. connection = sdk.Connection( - url = params['output_conn'], - username = username, - password = output_password, - ca_file = params['rhv_cafile'], - log = logging.getLogger(), - insecure = params['insecure'], + url=params['output_conn'], + username=username, + password=output_password, + ca_file=params['rhv_cafile'], + log=logging.getLogger(), + insecure=params['insecure'], ) system_service = connection.system_service() @@ -97,8 +97,8 @@ cluster = clusters[0] # Otherwise everything is OK, print a JSON with the results. results = { - "rhv_storagedomain_uuid": storage_domain.id, - "rhv_cluster_uuid": cluster.id, + "rhv_storagedomain_uuid": storage_domain.id, + "rhv_cluster_uuid": cluster.id, } json.dump(results, sys.stdout) diff --git a/v2v/rhv-upload-vmcheck.py b/v2v/rhv-upload-vmcheck.py index fbb884b9..89ead726 100644 --- a/v2v/rhv-upload-vmcheck.py +++ b/v2v/rhv-upload-vmcheck.py @@ -50,12 +50,12 @@ username = parsed.username or "admin@internal" # Connect to the server. connection = sdk.Connection( - url = params['output_conn'], - username = username, - password = output_password, - ca_file = params['rhv_cafile'], - log = logging.getLogger(), - insecure = params['insecure'], + url=params['output_conn'], + username=username, + password=output_password, + ca_file=params['rhv_cafile'], + log=logging.getLogger(), + insecure=params['insecure'], ) system_service = connection.system_service() @@ -63,7 +63,7 @@ system_service = connection.system_service() # Find if a virtual machine already exists with that name. vms_service = system_service.vms_service() vms = vms_service.list( - search = ("name=%s" % params['output_name']), + search=("name=%s" % params['output_name']), ) if len(vms) > 0: vm = vms[0] -- 2.24.1
Pino Toscano
2020-Jan-10 15:47 UTC
[Libguestfs] [v2v PATCH 2/6] PEP 8: move imports at the top
No functional changes. --- tests/test-v2v-o-rhv-upload-module/ovirtsdk4/__init__.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) 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 774c7a5c..0bc2890f 100644 --- a/tests/test-v2v-o-rhv-upload-module/ovirtsdk4/__init__.py +++ b/tests/test-v2v-o-rhv-upload-module/ovirtsdk4/__init__.py @@ -18,6 +18,10 @@ # Fake ovirtsdk4 module used as a test harness. # See v2v/test-v2v-o-rhv-upload.sh +from http.server import HTTPServer, BaseHTTPRequestHandler +import threading + + class Error(Exception): pass class NotFoundError(Error): @@ -131,9 +135,6 @@ class VmsService(object): # Create a background thread running a web server which is # simulating the imageio server. -from http.server import HTTPServer, BaseHTTPRequestHandler -import threading - class RequestHandler(BaseHTTPRequestHandler): protocol_version = 'HTTP/1.1' -- 2.24.1
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_test.py + @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
Pino Toscano
2020-Jan-10 15:47 UTC
[Libguestfs] [v2v PATCH 4/6] tests: find all the Python scripts for syntax checks
Find all the Python scripts in v2v, instead of hardcoding a list. --- v2v/test-v2v-python-syntax.sh | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/v2v/test-v2v-python-syntax.sh b/v2v/test-v2v-python-syntax.sh index 035d92a2..e2936826 100755 --- a/v2v/test-v2v-python-syntax.sh +++ b/v2v/test-v2v-python-syntax.sh @@ -22,14 +22,14 @@ $TEST_FUNCTIONS skip_if_skipped # Files to check. -files="rhv-upload-createvm.py rhv-upload-plugin.py rhv-upload-precheck.py" +files="$(find "$srcdir" -name '*.py')" # Base version of Python. python=python3 # Checks the files are syntactically correct, but not very much else. for f in $files; do - $python -m py_compile "$srcdir/$f" + $python -m py_compile "$f" done # Checks the files correspond to PEP8 coding style. @@ -40,6 +40,6 @@ if $python-pep8 --version >/dev/null 2>&1; then # E226 missing whitespace around arithmetic operator # E251 unexpected spaces around keyword / parameter equals # E302 expected 2 blank lines, found 1 - $python-pep8 --ignore=E226,E251,E302 "$srcdir/$f" + $python-pep8 --ignore=E226,E251,E302 "$f" done fi -- 2.24.1
Pino Toscano
2020-Jan-10 15:47 UTC
[Libguestfs] [v2v PATCH 5/6] -o rhv-upload: remove unused Python imports
No functional changes. --- v2v/rhv-upload-createvm.py | 2 -- v2v/rhv-upload-deletedisks.py | 2 -- v2v/rhv-upload-precheck.py | 2 -- v2v/rhv-upload-vmcheck.py | 2 -- 4 files changed, 8 deletions(-) diff --git a/v2v/rhv-upload-createvm.py b/v2v/rhv-upload-createvm.py index f0b747ec..50bb7e34 100644 --- a/v2v/rhv-upload-createvm.py +++ b/v2v/rhv-upload-createvm.py @@ -19,9 +19,7 @@ import json import logging import sys -import time -from http.client import HTTPSConnection from urllib.parse import urlparse import ovirtsdk4 as sdk diff --git a/v2v/rhv-upload-deletedisks.py b/v2v/rhv-upload-deletedisks.py index 3c970801..8ed8cb88 100644 --- a/v2v/rhv-upload-deletedisks.py +++ b/v2v/rhv-upload-deletedisks.py @@ -19,9 +19,7 @@ import json import logging import sys -import time -from http.client import HTTPSConnection from urllib.parse import urlparse import ovirtsdk4 as sdk diff --git a/v2v/rhv-upload-precheck.py b/v2v/rhv-upload-precheck.py index e8be90c5..5f33db98 100644 --- a/v2v/rhv-upload-precheck.py +++ b/v2v/rhv-upload-precheck.py @@ -19,9 +19,7 @@ import json import logging import sys -import time -from http.client import HTTPSConnection from urllib.parse import urlparse import ovirtsdk4 as sdk diff --git a/v2v/rhv-upload-vmcheck.py b/v2v/rhv-upload-vmcheck.py index 89ead726..2255d714 100644 --- a/v2v/rhv-upload-vmcheck.py +++ b/v2v/rhv-upload-vmcheck.py @@ -19,9 +19,7 @@ import json import logging import sys -import time -from http.client import HTTPSConnection from urllib.parse import urlparse import ovirtsdk4 as sdk -- 2.24.1
Pino Toscano
2020-Jan-10 15:47 UTC
[Libguestfs] [v2v PATCH 6/6] Revamp check for Python code style
It turns out that a) the standalone pep8 executable is deprecated in favour of pycodestyle b) $python-pep8 does not exist in modern distros and thus the style checks for Python scripts have been skipped for a long time. Instead, switch to pycodestyle directly, updating the list of ignored issues to the two categories left. --- config.sh.in | 1 + m4/guestfs-progs.m4 | 3 +++ v2v/test-v2v-python-syntax.sh | 13 +++++-------- 3 files changed, 9 insertions(+), 8 deletions(-) diff --git a/config.sh.in b/config.sh.in index f3245379..be304b39 100644 --- a/config.sh.in +++ b/config.sh.in @@ -20,3 +20,4 @@ # mostly used in other shell scripts. export VIRT_V2V_NBDKIT_PYTHON_PLUGIN="@VIRT_V2V_NBDKIT_PYTHON_PLUGIN@" +export PYCODESTYLE="@PYCODESTYLE@" diff --git a/m4/guestfs-progs.m4 b/m4/guestfs-progs.m4 index 5f481a75..56baa857 100644 --- a/m4/guestfs-progs.m4 +++ b/m4/guestfs-progs.m4 @@ -73,3 +73,6 @@ AS_IF([test "x$VALGRIND" != "xno"],[ ]) AC_SUBST([VG]) AM_SUBST_NOTMAKE([VG]) + +dnl pycodestyle, used to check the Python scripts. +AC_CHECK_PROGS([PYCODESTYLE],[pycodestyle],[no]) diff --git a/v2v/test-v2v-python-syntax.sh b/v2v/test-v2v-python-syntax.sh index e2936826..4fd2184a 100755 --- a/v2v/test-v2v-python-syntax.sh +++ b/v2v/test-v2v-python-syntax.sh @@ -34,12 +34,9 @@ done # Checks the files correspond to PEP8 coding style. # https://www.python.org/dev/peps/pep-0008/ -if $python-pep8 --version >/dev/null 2>&1; then - for f in $files; do - # Ignore: - # E226 missing whitespace around arithmetic operator - # E251 unexpected spaces around keyword / parameter equals - # E302 expected 2 blank lines, found 1 - $python-pep8 --ignore=E226,E251,E302 "$f" - done +if test "x$PYCODESTYLE" != xno; then + # Ignore: + # E501 line too long + # E722 do not use bare 'except' + $PYCODESTYLE --ignore=E501,E722 $files fi -- 2.24.1
Richard W.M. Jones
2020-Jan-14 09:57 UTC
Re: [Libguestfs] [v2v PATCH 6/6] Revamp check for Python code style
Looks all fine, ACK series. Rich. -- Richard Jones, Virtualization Group, Red Hat http://people.redhat.com/~rjones Read my programming and virtualization blog: http://rwmj.wordpress.com virt-p2v converts physical machines to virtual machines. Boot with a live CD or over the network (PXE) and turn machines into KVM guests. http://libguestfs.org/virt-v2v
Maybe Matching Threads
- [v2v PATCH 0/6] Various Python pycodestyle fixes
- [PATCH 7/7] python: add a pycodestyle test
- [PATCH v8] v2v: Add -o rhv-upload output mode (RHBZ#1557273).
- [PATCH v9] v2v: Add -o rhv-upload output mode (RHBZ#1557273).
- [PATCH v2 8/8] python: add a pycodestyle test