Skip to content

#PR2- CP-47869-Update XAPI code to python3. #5668

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 24 commits into from
Jun 12, 2024
Merged
Show file tree
Hide file tree
Changes from 23 commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
256fe98
CP-47869: Updated documentation to include python3 /doc/content/xap…
ashwin9390 May 24, 2024
f785993
CP-47869: Updated documentation to include python3 /ocaml/doc/wire-pr…
ashwin9390 May 24, 2024
c3d96a2
CP-47869: Modified code using 2to3 /ocaml/xapi-storage-script/exampl…
ashwin9390 May 24, 2024
8e4b50d
CP-47869: Modified code using 2to3 ocaml/xapi-storage-script/examples…
ashwin9390 May 24, 2024
b734b72
CP-47869: Modified code using 2to3 /ocaml/xapi-storage-script/example…
ashwin9390 May 24, 2024
ddcda0b
CP-47869: Modified code using 2to3 /ocaml/xapi-storage-script/example…
ashwin9390 May 24, 2024
b4c5764
CP-47869: Modified code using 2to3 /ocaml/xapi-storage/python/example…
ashwin9390 May 27, 2024
051f3e3
CP-47869: Update code to be compatible with python3 /ocaml/xapi-stora…
ashwin9390 May 27, 2024
93f5fee
CP-47869: Update code to be compatible with python3 ocaml/xapi-storag…
ashwin9390 May 27, 2024
88f5fd8
CP-47869: Modified code using 2to3 /ocaml/xapi-storage/python/exampl…
ashwin9390 May 27, 2024
655ca9a
CP-47869: Changed shebang to python3 /ocaml/xapi-storage/python/xapi/…
ashwin9390 May 27, 2024
981f142
CP-47869: Changed shebang to python3 /ocaml/xapi-storage/python/xapi/…
ashwin9390 May 27, 2024
26acd48
CP-47869: Changed shebang to python3 /ocaml/xapi-storage/python/xapi/…
ashwin9390 May 27, 2024
333bec8
CP-47869: Replaced <> with != to support python3 /scripts/examples/p…
ashwin9390 May 27, 2024
d73690d
CP-47869: Modified code using 2to3 /ocaml/xapi-storage/python/xapi/__…
ashwin9390 May 27, 2024
2954895
CP-47869: Changed shebang to python3 ocaml/xapi-storage/python/xapi/s…
ashwin9390 May 27, 2024
756b9f2
CP-47869: Modified to python3 /ocaml/xapi-storage/python/Makefile
ashwin9390 May 27, 2024
9929318
CP-47869: Updated to python3 .github/workflows/setup-xapi-environment…
ashwin9390 May 28, 2024
5d0a5a6
CP-47869: Fixed No attribute 'server' on module 'xmlrpc.client' [mod…
ashwin9390 Jun 3, 2024
e061a29
CP-47869: fixed Name 'FilenotFoundError' is not defined [name-error] …
ashwin9390 Jun 3, 2024
43d9130
CP-47869: removed smapiv2.py and mini-xenrt.py from expected_to_fail …
ashwin9390 Jun 3, 2024
ed86b8f
Revert "CP-47869: Modified code using 2to3 /ocaml/xapi-storage/python…
ashwin9390 Jun 11, 2024
789b9e4
CP-47869: Changed shebang to python3 /ocaml/xapi-storage/python/xapi/…
ashwin9390 Jun 11, 2024
23ed63d
CP-47869: Fix pylint reimport issue ocaml/xapi-storage/python/exampl…
ashwin9390 Jun 11, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .github/workflows/setup-xapi-environment/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion doc/content/xapi/storage/_index.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion ocaml/doc/wire-protocol.md
Original file line number Diff line number Diff line change
Expand Up @@ -463,7 +463,7 @@ XML-RPC and JSON-RPC client libraries.
First, initialise python:

```bash
$ python2.7
$ python3
>>>
```

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/env python2
#!/usr/bin/env python3

import sys
sys.path.append("/home/vagrant/djs55/dbus-test/python")
Expand All @@ -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))
Original file line number Diff line number Diff line change
@@ -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}] ]
}
Expand All @@ -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))
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/env python2
#!/usr/bin/env python3

import sys
sys.path.append("/home/vagrant/djs55/dbus-test/python")
Expand All @@ -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))
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/env python2
#!/usr/bin/env python3

import sys
sys.path.append("/home/vagrant/djs55/dbus-test/python")
Expand All @@ -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))
2 changes: 1 addition & 1 deletion ocaml/xapi-storage/python/Makefile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
PREFIX?=/usr
PYTHON?=python2
PYTHON?=python3

.PHONY: build release clean install uninstall

Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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)

Expand Down Expand Up @@ -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)

Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -18,8 +18,8 @@
from __future__ import print_function
import os
import sys
import urllib
import urlparse
import urllib.request, urllib.parse, urllib.error

Check warning on line 21 in ocaml/xapi-storage/python/examples/volume/org.xen.xapi.storage.simple-file/sr.py

View workflow job for this annotation

GitHub Actions / Python tests (3.11)

[pylint] reported by reviewdog 🐶 C0410: Multiple imports on one line (urllib.request, urllib.parse, urllib.error) (multiple-imports) Raw Output: ocaml/xapi-storage/python/examples/volume/org.xen.xapi.storage.simple-file/sr.py:21:0: C0410: Multiple imports on one line (urllib.request, urllib.parse, urllib.error) (multiple-imports)
import urllib.parse

Check warning on line 22 in ocaml/xapi-storage/python/examples/volume/org.xen.xapi.storage.simple-file/sr.py

View workflow job for this annotation

GitHub Actions / Python tests (3.11)

[pylint] reported by reviewdog 🐶 W0404: Reimport 'urllib.parse' (imported line 21) (reimported) Raw Output: ocaml/xapi-storage/python/examples/volume/org.xen.xapi.storage.simple-file/sr.py:22:0: W0404: Reimport 'urllib.parse' (imported line 21) (reimported)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

pylint: Reimport 'urllib.parse'


import xapi.storage.api.v5.volume
from xapi import InternalError
Expand Down Expand Up @@ -66,12 +66,12 @@
# 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):
Expand All @@ -96,8 +96,8 @@
[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
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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
Expand All @@ -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):
Expand All @@ -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))]

Expand Down Expand Up @@ -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))
Expand Down
4 changes: 2 additions & 2 deletions ocaml/xapi-storage/python/xapi/__init__.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down
2 changes: 1 addition & 1 deletion ocaml/xapi-storage/python/xapi/storage/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
#!/usr/bin/env python2
#!/usr/bin/env python3
2 changes: 1 addition & 1 deletion ocaml/xapi-storage/python/xapi/storage/api/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
#!/usr/bin/env python2
#!/usr/bin/env python3
2 changes: 1 addition & 1 deletion ocaml/xapi-storage/python/xapi/storage/api/v5/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
#!/usr/bin/env python2
#!/usr/bin/env python3
2 changes: 1 addition & 1 deletion ocaml/xapi-storage/python/xapi/storage/common.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/env python2
#!/usr/bin/env python3

from xapi.storage import log
import xapi
Expand Down
2 changes: 0 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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",
]
Expand Down
2 changes: 1 addition & 1 deletion scripts/examples/python/mini-xenrt.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
Expand Down
2 changes: 1 addition & 1 deletion scripts/examples/python/provision.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)")
2 changes: 1 addition & 1 deletion scripts/examples/smapiv2.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
Loading