diff --git a/.github/workflows/setup-xapi-environment/action.yml b/.github/workflows/setup-xapi-environment/action.yml index d46ae3a5b96..e32110ad977 100644 --- a/.github/workflows/setup-xapi-environment/action.yml +++ b/.github/workflows/setup-xapi-environment/action.yml @@ -27,9 +27,9 @@ runs: shell: bash run: sudo apt-get update - - name: Install python2 + - name: Install python3 shell: bash - run: sudo apt-get install python2 + run: sudo apt-get install python3 - name: Use disk with more space for TMPDIR and XDG_CACHE_HOME shell: bash diff --git a/doc/content/xapi/storage/_index.md b/doc/content/xapi/storage/_index.md index c265353869a..009ceabd4bd 100644 --- a/doc/content/xapi/storage/_index.md +++ b/doc/content/xapi/storage/_index.md @@ -245,7 +245,7 @@ From this interface we generate and appear in the` _build/default/python/xapi/storage/api/v5` directory. - On a XenServer host, they are stored in the - `/usr/lib/python2.7/site-packages/xapi/storage/api/v5/` + `/usr/lib/python3.6/site-packages/xapi/storage/api/v5/` directory ### SMAPIv3 Plugins diff --git a/ocaml/doc/wire-protocol.md b/ocaml/doc/wire-protocol.md index 20e39627cc3..cc5734e76b8 100644 --- a/ocaml/doc/wire-protocol.md +++ b/ocaml/doc/wire-protocol.md @@ -463,7 +463,7 @@ XML-RPC and JSON-RPC client libraries. First, initialise python: ```bash -$ python2.7 +$ python3 >>> ``` diff --git a/ocaml/xapi-storage-script/examples/datapath/block/Datapath.activate b/ocaml/xapi-storage-script/examples/datapath/block/Datapath.activate index 3115f233480..9cda8c0cf23 100755 --- a/ocaml/xapi-storage-script/examples/datapath/block/Datapath.activate +++ b/ocaml/xapi-storage-script/examples/datapath/block/Datapath.activate @@ -1,4 +1,4 @@ -#!/usr/bin/env python2 +#!/usr/bin/env python3 import sys sys.path.append("/home/vagrant/djs55/dbus-test/python") @@ -17,10 +17,10 @@ if __name__ == "__main__": args = vars(parser.parse_args()) if not(args['json']): - print "Not implemented" + print("Not implemented") sys.exit(1) dispatcher = d.Datapath_server_dispatcher(Implementation()) - request = json.loads(sys.stdin.readline(),) + request = json.loads(sys.stdin.readline()) results = dispatcher.activate(request) - print json.dumps(results) + print(json.dumps(results)) diff --git a/ocaml/xapi-storage-script/examples/datapath/block/Datapath.attach b/ocaml/xapi-storage-script/examples/datapath/block/Datapath.attach index db6eb6de2eb..6a2ec399460 100755 --- a/ocaml/xapi-storage-script/examples/datapath/block/Datapath.attach +++ b/ocaml/xapi-storage-script/examples/datapath/block/Datapath.attach @@ -1,15 +1,15 @@ -#!/usr/bin/env python2 +#!/usr/bin/env python3 import sys sys.path.append("/home/vagrant/djs55/dbus-test/python") import xapi, d -import argparse, json, urlparse +import argparse, json, urllib.parse class Implementation(d.Datapath_skeleton): def attach(self, dbg, uri, domain): - u = urlparse.urlparse(uri) + u = urllib.parse.urlparse(uri) return { 'implementations': [ ['XenDisk', {"backend_type":"vbd", "extra":{}, "params":u.path}], ['BlockDevice', {"path":u.path}] ] } @@ -20,10 +20,10 @@ if __name__ == "__main__": args = vars(parser.parse_args()) if not(args['json']): - print "Not implemented" + print("Not implemented") sys.exit(1) dispatcher = d.Datapath_server_dispatcher(Implementation()) - request = json.loads(sys.stdin.readline(),) + request = json.loads(sys.stdin.readline()) results = dispatcher.attach(request) - print json.dumps(results) + print(json.dumps(results)) diff --git a/ocaml/xapi-storage-script/examples/datapath/block/Datapath.deactivate b/ocaml/xapi-storage-script/examples/datapath/block/Datapath.deactivate index 48240856deb..1585a267eb0 100755 --- a/ocaml/xapi-storage-script/examples/datapath/block/Datapath.deactivate +++ b/ocaml/xapi-storage-script/examples/datapath/block/Datapath.deactivate @@ -1,4 +1,4 @@ -#!/usr/bin/env python2 +#!/usr/bin/env python3 import sys sys.path.append("/home/vagrant/djs55/dbus-test/python") @@ -17,10 +17,10 @@ if __name__ == "__main__": args = vars(parser.parse_args()) if not(args['json']): - print "Not implemented" + print("Not implemented") sys.exit(1) dispatcher = d.Datapath_server_dispatcher(Implementation()) - request = json.loads(sys.stdin.readline(),) + request = json.loads(sys.stdin.readline()) results = dispatcher.deactivate(request) - print json.dumps(results) + print(json.dumps(results)) diff --git a/ocaml/xapi-storage-script/examples/datapath/block/Datapath.detach b/ocaml/xapi-storage-script/examples/datapath/block/Datapath.detach index aac2e9d3773..5e42f252943 100755 --- a/ocaml/xapi-storage-script/examples/datapath/block/Datapath.detach +++ b/ocaml/xapi-storage-script/examples/datapath/block/Datapath.detach @@ -1,4 +1,4 @@ -#!/usr/bin/env python2 +#!/usr/bin/env python3 import sys sys.path.append("/home/vagrant/djs55/dbus-test/python") @@ -17,10 +17,10 @@ if __name__ == "__main__": args = vars(parser.parse_args()) if not(args['json']): - print "Not implemented" + print("Not implemented") sys.exit(1) dispatcher = d.Datapath_server_dispatcher(Implementation()) - request = json.loads(sys.stdin.readline(),) + request = json.loads(sys.stdin.readline()) results = dispatcher.detach(request) - print json.dumps(results) + print(json.dumps(results)) diff --git a/ocaml/xapi-storage/python/Makefile b/ocaml/xapi-storage/python/Makefile index bc8eff9b851..a2ccad97c8c 100644 --- a/ocaml/xapi-storage/python/Makefile +++ b/ocaml/xapi-storage/python/Makefile @@ -1,5 +1,5 @@ PREFIX?=/usr -PYTHON?=python2 +PYTHON?=python3 .PHONY: build release clean install uninstall diff --git a/ocaml/xapi-storage/python/examples/datapath/loop+blkback/datapath.py b/ocaml/xapi-storage/python/examples/datapath/loop+blkback/datapath.py index ed65d595477..f076b700a6f 100755 --- a/ocaml/xapi-storage/python/examples/datapath/loop+blkback/datapath.py +++ b/ocaml/xapi-storage/python/examples/datapath/loop+blkback/datapath.py @@ -1,6 +1,6 @@ -#!/usr/bin/env python2 +#!/usr/bin/env python3 # -# Copyright (C) Citrix Systems Inc. +# Copyright (C) Cloud Software Group. # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU Lesser General Public License as published @@ -15,10 +15,10 @@ # along with this program; if not, write to the Free Software Foundation, Inc., # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA -from __future__ import print_function + import os import sys -import urlparse +import urllib.parse import xapi.storage.api.v5.datapath from xapi.storage.common import call @@ -64,8 +64,8 @@ def activate(self, dbg, uri, domain): pass def attach(self, dbg, uri, domain): - parsed_url = urlparse.urlparse(uri) - query = urlparse.parse_qs(parsed_url.query) + parsed_url = urllib.parse.urlparse(uri) + query = urllib.parse.parse_qs(parsed_url.query) file_path = os.path.realpath(parsed_url.path) @@ -97,7 +97,7 @@ def deactivate(self, dbg, uri, domain): pass def detach(self, dbg, uri, domain): - parsed_url = urlparse.urlparse(uri) + parsed_url = urllib.parse.urlparse(uri) file_path = os.path.realpath(parsed_url.path) diff --git a/ocaml/xapi-storage/python/examples/datapath/loop+blkback/plugin.py b/ocaml/xapi-storage/python/examples/datapath/loop+blkback/plugin.py index e16a53794a7..4cbc9939fbd 100755 --- a/ocaml/xapi-storage/python/examples/datapath/loop+blkback/plugin.py +++ b/ocaml/xapi-storage/python/examples/datapath/loop+blkback/plugin.py @@ -1,6 +1,6 @@ -#!/usr/bin/env python2 +#!/usr/bin/env python3 # -# Copyright (C) Citrix Systems Inc. +# Copyright (C) Cloud Software Group,Inc. # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU Lesser General Public License as published diff --git a/ocaml/xapi-storage/python/examples/volume/org.xen.xapi.storage.simple-file/plugin.py b/ocaml/xapi-storage/python/examples/volume/org.xen.xapi.storage.simple-file/plugin.py index 61a41db978f..583043015ed 100755 --- a/ocaml/xapi-storage/python/examples/volume/org.xen.xapi.storage.simple-file/plugin.py +++ b/ocaml/xapi-storage/python/examples/volume/org.xen.xapi.storage.simple-file/plugin.py @@ -1,6 +1,6 @@ -#!/usr/bin/env python2 +#!/usr/bin/env python3 # -# Copyright (C) Citrix Systems Inc. +# Copyright (C) Cloud Software Group, Inc. # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU Lesser General Public License as published diff --git a/ocaml/xapi-storage/python/examples/volume/org.xen.xapi.storage.simple-file/sr.py b/ocaml/xapi-storage/python/examples/volume/org.xen.xapi.storage.simple-file/sr.py index 35e96b6ab83..07f4f9c0436 100755 --- a/ocaml/xapi-storage/python/examples/volume/org.xen.xapi.storage.simple-file/sr.py +++ b/ocaml/xapi-storage/python/examples/volume/org.xen.xapi.storage.simple-file/sr.py @@ -1,6 +1,6 @@ -#!/usr/bin/env python2 +#!/usr/bin/env python3 # -# Copyright (C) Citrix Systems Inc. +# Copyright (C) Cloud Software Group, Inc. # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU Lesser General Public License as published @@ -18,8 +18,9 @@ from __future__ import print_function import os import sys -import urllib -import urlparse +import urllib.request +import urllib.parse +import urllib.error import xapi.storage.api.v5.volume from xapi import InternalError @@ -66,12 +67,12 @@ def attach(self, dbg, configuration): # As a simple "stateless" implementation, encode all the # configuration into the URI returned. This is passed back # into volume interface APIs and the stat and ls operations. - return urlparse.urlunparse(( + return urllib.parse.urlunparse(( 'file', '', configuration['path'], '', - urllib.urlencode(configuration, True), + urllib.parse.urlencode(configuration, True), None)) def detach(self, dbg, sr): @@ -96,8 +97,8 @@ def stat(self, dbg, sr): [stat sr] returns summary metadata associated with [sr]. Note this call does not return details of sub-volumes, see SR.ls. """ - parsed_url = urlparse.urlparse(sr) - config = urlparse.parse_qs(parsed_url.query) + parsed_url = urllib.parse.urlparse(sr) + config = urllib.parse.parse_qs(parsed_url.query) description = (config['description'][0] if 'description' in config diff --git a/ocaml/xapi-storage/python/examples/volume/org.xen.xapi.storage.simple-file/volume.py b/ocaml/xapi-storage/python/examples/volume/org.xen.xapi.storage.simple-file/volume.py index d97ceb4ab5d..6593a8fd536 100755 --- a/ocaml/xapi-storage/python/examples/volume/org.xen.xapi.storage.simple-file/volume.py +++ b/ocaml/xapi-storage/python/examples/volume/org.xen.xapi.storage.simple-file/volume.py @@ -1,6 +1,6 @@ -#!/usr/bin/env python2 +#!/usr/bin/env python3 # -# Copyright (C) Citrix Systems Inc. +# Copyright (C) Cloud Software Group, Inc. # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU Lesser General Public License as published @@ -21,8 +21,9 @@ import os import sys import uuid -import urllib -import urlparse +import urllib.request +import urllib.parse +import urllib.error import xapi.storage.api.v5.volume from xapi.storage import log @@ -31,8 +32,8 @@ class Implementation(xapi.storage.api.v5.volume.Volume_skeleton): def parse_sr(self, sr_uri): - parsed_url = urlparse.urlparse(sr_uri) - config = urlparse.parse_qs(parsed_url.query) + parsed_url = urllib.parse.urlparse(sr_uri) + config = urllib.parse.parse_qs(parsed_url.query) return parsed_url, config def create_volume_data(self, name, description, size, uris, uuid): @@ -50,8 +51,8 @@ def create_volume_data(self, name, description, size, uris, uuid): } def volume_uris(self, sr_path, name, size): - query = urllib.urlencode({'size': size}, True) - return [urlparse.urlunparse( + query = urllib.parse.urlencode({'size': size}, True) + return [urllib.parse.urlunparse( ('loop+blkback', None, os.path.join(sr_path, name), None, query, None))] @@ -187,7 +188,7 @@ def ls(self, dbg, sr): """ [ls sr] lists the volumes from [sr] """ - parsed_url = urlparse.urlparse(sr) + parsed_url = urllib.parse.urlparse(sr) sr_path = parsed_url.path files = glob.glob(os.path.join(sr_path, '*.inf')) log.debug('files to list {}'.format(files)) diff --git a/ocaml/xapi-storage/python/xapi/__init__.py b/ocaml/xapi-storage/python/xapi/__init__.py index d2a0eed3f94..57a7c0c9f2d 100644 --- a/ocaml/xapi-storage/python/xapi/__init__.py +++ b/ocaml/xapi-storage/python/xapi/__init__.py @@ -1,7 +1,7 @@ -#!/usr/bin/env python2 +#!/usr/bin/env python3 """ -Copyright (c) 2013-2018, Citrix Inc. +Copyright (c) 2013-2024, Cloud Software Group,Inc. All rights reserved. Redistribution and use in source and binary forms, with or without diff --git a/ocaml/xapi-storage/python/xapi/storage/__init__.py b/ocaml/xapi-storage/python/xapi/storage/__init__.py index 18ff5363796..e5a0d9b4834 100644 --- a/ocaml/xapi-storage/python/xapi/storage/__init__.py +++ b/ocaml/xapi-storage/python/xapi/storage/__init__.py @@ -1 +1 @@ -#!/usr/bin/env python2 +#!/usr/bin/env python3 diff --git a/ocaml/xapi-storage/python/xapi/storage/api/__init__.py b/ocaml/xapi-storage/python/xapi/storage/api/__init__.py index 18ff5363796..e5a0d9b4834 100644 --- a/ocaml/xapi-storage/python/xapi/storage/api/__init__.py +++ b/ocaml/xapi-storage/python/xapi/storage/api/__init__.py @@ -1 +1 @@ -#!/usr/bin/env python2 +#!/usr/bin/env python3 diff --git a/ocaml/xapi-storage/python/xapi/storage/api/v5/__init__.py b/ocaml/xapi-storage/python/xapi/storage/api/v5/__init__.py index 18ff5363796..e5a0d9b4834 100644 --- a/ocaml/xapi-storage/python/xapi/storage/api/v5/__init__.py +++ b/ocaml/xapi-storage/python/xapi/storage/api/v5/__init__.py @@ -1 +1 @@ -#!/usr/bin/env python2 +#!/usr/bin/env python3 diff --git a/ocaml/xapi-storage/python/xapi/storage/common.py b/ocaml/xapi-storage/python/xapi/storage/common.py index a311446a416..e8d34869277 100644 --- a/ocaml/xapi-storage/python/xapi/storage/common.py +++ b/ocaml/xapi-storage/python/xapi/storage/common.py @@ -1,4 +1,4 @@ -#!/usr/bin/env python2 +#!/usr/bin/env python3 from xapi.storage import log import xapi diff --git a/pyproject.toml b/pyproject.toml index 5ea22b96551..2fb086f0b11 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -251,11 +251,9 @@ expected_to_fail = [ # SSLSocket.send() only accepts bytes, not unicode string as argument: "scripts/examples/python/exportimport.py", # Other fixes needed: - "scripts/examples/python/mini-xenrt.py", "scripts/examples/python/XenAPI/XenAPI.py", "scripts/examples/python/monitor-unwanted-domains.py", "scripts/examples/python/shell.py", - "scripts/examples/smapiv2.py", "scripts/static-vdis", "scripts/plugins/extauth-hook-AD.py", ] diff --git a/scripts/examples/python/mini-xenrt.py b/scripts/examples/python/mini-xenrt.py index 0907132da80..b30e9d9973c 100644 --- a/scripts/examples/python/mini-xenrt.py +++ b/scripts/examples/python/mini-xenrt.py @@ -109,7 +109,7 @@ def make_operation_list(vm): print(" -- performs parallel operations on VMs with the specified other-config key") sys.exit(1) - x = xmlrpc.client.server(sys.argv[1]) + x = xmlrpc.client.ServerProxy(sys.argv[1]) key = sys.argv[2] session = x.session.login_with_password("root", "xenroot", "1.0", "xen-api-scripts-minixenrt.py")["Value"] vms = x.VM.get_all_records(session)["Value"] diff --git a/scripts/examples/python/provision.py b/scripts/examples/python/provision.py index 4c5ab11daef..3b8a224ffae 100644 --- a/scripts/examples/python/provision.py +++ b/scripts/examples/python/provision.py @@ -107,5 +107,5 @@ def setProvisionSpec(session, vm, ps): txt2 = printProvisionSpec(ps) print(txt2) if txt != txt2: - raise AssertionError("Sanity-check failed: print(parse(print(x))) <> print(x)") + raise AssertionError("Sanity-check failed: print(parse(print(x))) != print(x)") print("* OK: print(parse(print(x))) == print(x)") diff --git a/scripts/examples/smapiv2.py b/scripts/examples/smapiv2.py index cc990dcadf2..1047f57825c 100644 --- a/scripts/examples/smapiv2.py +++ b/scripts/examples/smapiv2.py @@ -13,7 +13,7 @@ def reopenlog(log_file): if log_file: try: log_f = open(log_file, "a") - except FilenotFoundError: + except FileNotFoundError: log_f = open(log_file, "w") else: log_f = open(os.dup(sys.stdout.fileno()), "a")