1
0
mirror of https://gitlab.com/libvirt/libvirt-python.git synced 2025-12-02 12:23:47 +03:00
Commit Graph

1060 Commits

Author SHA1 Message Date
Philipp Hahn
9074b50259 stream: Do not use bare except
as it also catches SystemExit, InterruptedError, SyntaxError and such.

Signed-off-by: Philipp Hahn <hahn@univention.de>
2020-08-18 09:48:25 +00:00
Philipp Hahn
5777008197 override: Convert to list comprehension
:%s/retlist = list()\n\s*\(for \w\+ in ret\):\n\s*retlist.append(\(.*\))\n\n\s*return retlist/return [\2 \1]/

Signed-off-by: Philipp Hahn <hahn@univention.de>
2020-08-18 09:48:25 +00:00
Philipp Hahn
d49e850807 override: Catch type error
handler() should either return bytes or -2 or -3.
Explicitly raise ValueError or TypeError to silence mypy.

Signed-off-by: Philipp Hahn <hahn@univention.de>
2020-08-18 09:48:25 +00:00
Philipp Hahn
051a00c212 override: no type change
static typing forbids re-declaring a variable with different types.
Rename the variable.

Signed-off-by: Philipp Hahn <hahn@univention.de>
2020-08-18 09:48:25 +00:00
Philipp Hahn
abbd47f4ea override: Add manual PEP 484 type annotations
Signed-off-by: Philipp Hahn <hahn@univention.de>
2020-08-18 09:48:25 +00:00
Philipp Hahn
67af8b910b override: Simplify exception handling
sys.exc_info() returns a 3-tuple (type, value, traceback), where `value`
is the instance captured by `except type as value`.

Signed-off-by: Philipp Hahn <hahn@univention.de>
2020-08-18 09:48:25 +00:00
Vincent Vanlaer
ec76ba3507 Include libvirt-qemu-override.py in sdist
libvirt-qemu-override.py was introduced in e3da8f17 but never added to
MANIFEST.in. It was therefore not contained in the official releases on
libvirt.org.

Signed-off-by: Vincent Vanlaer <vincent.vanlaer@skynet.be>
2020-08-18 00:23:56 +02:00
Philipp Hahn
026a47928a libvirtaio: Add manual PEP 484 type annotations
Signed-off-by: Philipp Hahn <hahn@univention.de>
2020-08-07 18:05:53 +02:00
Philipp Hahn
6b97281730 libvirtaio: assert callback type
self.callbacks contains a mix of FDCallback and TimeoutCallback, while
the update code does not explicitly check for.

Signed-off-by: Philipp Hahn <hahn@univention.de>
2020-08-06 08:50:37 +02:00
Philipp Hahn
12d631d11a libvirtaio: Fix return type
libvirtaio.py:364: error: "virEventInvokeFreeCallback" does not return a value

Signed-off-by: Philipp Hahn <hahn@univention.de>
2020-08-06 08:50:37 +02:00
Philipp Hahn
f4be03b330 libvirtaio: Drop object(*args, **kwargs)
object.__init__() does not expect those parameters.

Signed-off-by: Philipp Hahn <hahn@univention.de>
2020-08-06 08:50:37 +02:00
Philipp Hahn
429973c836 libvirtaio: Cleanup imports
Move imports to top

Signed-off-by: Philipp Hahn <hahn@univention.de>
2020-08-06 08:50:37 +02:00
Philipp Hahn
bd238713ef sanitytest: no type change
static typing forbids re-declaring a variable with different types.
Rename the variable.

Signed-off-by: Philipp Hahn <hahn@univention.de>
2020-08-06 08:50:37 +02:00
Philipp Hahn
22f2ba37ae sanitytest: Use str.startswith() instead of str[0]
Signed-off-by: Philipp Hahn <hahn@univention.de>
2020-08-06 08:50:37 +02:00
Philipp Hahn
b6ad44257e sanitytest: Use set for tracking used functions
Signed-off-by: Philipp Hahn <hahn@univention.de>
2020-08-06 08:50:37 +02:00
Philipp Hahn
ddf73e40a9 sanitytest: Use 3-tuple for finalklassmap
Signed-off-by: Philipp Hahn <hahn@univention.de>
2020-08-06 08:50:37 +02:00
Philipp Hahn
809b963134 sanitytest: Use 3-tuple for basicklassmap
Signed-off-by: Philipp Hahn <hahn@univention.de>
2020-08-06 08:50:37 +02:00
Philipp Hahn
94c24929e4 sanitytest: Add PEP 484 type annotations
Signed-off-by: Philipp Hahn <hahn@univention.de>
2020-08-06 08:50:37 +02:00
Philipp Hahn
fd8b7733dc sanitytest: Drop Python 2 compatibility
Python 3 only has int, remove the Python 2 long type

Signed-off-by: Philipp Hahn <hahn@univention.de>
2020-08-06 08:50:37 +02:00
Philipp Hahn
ff9575a727 sanitytest: Drop else:pass
useless

Signed-off-by: Philipp Hahn <hahn@univention.de>
2020-08-06 08:50:37 +02:00
Philipp Hahn
6279dbefc2 sanitytest: Do not re-declare set
is a built-in python type

Signed-off-by: Philipp Hahn <hahn@univention.de>
2020-08-06 08:50:37 +02:00
Philipp Hahn
39ffa7f838 sanitytest: Convert type() to isinstance()
Signed-off-by: Philipp Hahn <hahn@univention.de>
2020-08-06 08:50:37 +02:00
Philipp Hahn
8a81fc6f2b sanitytest: Skip type annotations
Teach sanitytest to ignore typing imports

Signed-off-by: Philipp Hahn <hahn@univention.de>
2020-08-06 08:50:37 +02:00
Philipp Hahn
b5f7beb931 sanitytest: Remove unused import
Signed-off-by: Philipp Hahn <hahn@univention.de>
2020-08-06 08:50:37 +02:00
Philipp Hahn
ee5c856af7 Remove legacy libvirtError arguments
The fields have been deprecated in C with
git:f60dc0bc09f09c6817d6706a9edb1579a3e2b2b8

They are only passed to the libvirtError constructor, but not stored for
later or used anywhere else.

sed -ri '/raise libvirtError/s/, \w+=self(\._dom)?//' *.py

Signed-off-by: Philipp Hahn <hahn@univention.de>
2020-08-06 08:50:37 +02:00
Philipp Hahn
0ca8dc6340 Normalize white space
indent by 4 spaces
one spaces around assignments

Signed-off-by: Philipp Hahn <hahn@univention.de>
2020-08-06 08:50:37 +02:00
Philipp Hahn
7c93891420 examples/event-test: Fix remove return type
The remove function are supposed to return 0 on success and -1 on failure.
<https://libvirt.org/html/libvirt-libvirt-event.html#virEventRemoveTimeoutFunc>

Signed-off-by: Philipp Hahn <hahn@univention.de>
2020-08-06 08:50:37 +02:00
Philipp Hahn
74a78fa42c examples: Fix white space
indent by 4 spaces
one spaces around assignments

Signed-off-by: Philipp Hahn <hahn@univention.de>
2020-08-05 07:43:02 +00:00
Philipp Hahn
b801ff31fa examples: Replace sys.exit() with exit()
No need to import sys.

Signed-off-by: Philipp Hahn <hahn@univention.de>
2020-08-05 07:43:02 +00:00
Philipp Hahn
f496dc55ee examples: Cleanup imports
Break import into multiple lines as recommended by PEP-8

Move imports to top

Remove unused imports

Signed-off-by: Philipp Hahn <hahn@univention.de>
2020-08-05 07:43:02 +00:00
Philipp Hahn
4e22f4de6f examples: Do not use bare except
as it also catches SystemExit, InterruptedError, SyntaxError and such.

Signed-off-by: Philipp Hahn <hahn@univention.de>
2020-08-05 07:43:02 +00:00
Philipp Hahn
06aba185a8 examples: Convert to ArgumentParser
Replace getopt() and hand-rolled-parser with argparse.ArgumentParser.

Fix wrong header comments copy-pasted from domstart.py

Signed-off-by: Philipp Hahn <hahn@univention.de>
2020-08-05 07:43:02 +00:00
Philipp Hahn
9cf539a2a8 examples: Add/fix PEP 484 type annotation
Signed-off-by: Philipp Hahn <hahn@univention.de>
2020-08-05 07:43:02 +00:00
Philipp Hahn
5434ed53ff examples: Add missing return values
examples/dhcpleases.py:45: error: Missing return statement

Signed-off-by: Philipp Hahn <hahn@univention.de>
2020-08-05 07:43:02 +00:00
Philipp Hahn
c588ba982e examples/nodestat: Fix None comparison
"is" compares for "points to the same object", which for strings is the
same as comparing the byte sequence itself as Python hashes each strings
to only stores a unique copy of each string.

> examples/nodestats.py:86:43: F632 use ==/!= to compare constant literals (str, bytes, int, float, tuple)
> examples/nodestats.py:91:12: F632 use ==/!= to compare constant literals (str, bytes, int, float, tuple)
> examples/nodestats.py:94:40: F632 use ==/!= to compare constant literals (str, bytes, int, float, tuple)

Use "==" and "!=" for string comparsion.

Signed-off-by: Philipp Hahn <hahn@univention.de>
2020-08-05 07:43:02 +00:00
Philipp Hahn
900676d3c4 examples/consolecallback: Fix assorted errors
Assert stream is opened before receiving bytes.

Need to check for bytes() instead of [unicode]str().

Signed-off-by: Philipp Hahn <hahn@univention.de>
2020-08-05 07:43:01 +00:00
Philipp Hahn
55415a4870 examples/consolecallback: Add var to save callback
> examples/consolecallback.py:98: error: "Console" has no attribute "stdin_watch"

Signed-off-by: Philipp Hahn <hahn@univention.de>
2020-08-05 07:43:01 +00:00
Philipp Hahn
77f57cd5ec examples/esxlist: Fix Python 2 raw_input()
which was renamed to input() for Python 3.

Signed-off-by: Philipp Hahn <hahn@univention.de>
2020-08-05 07:43:01 +00:00
Philipp Hahn
cb8cceb0d8 examples/event-test: Use atexit for Python 3
Assigning sys.exitfunc no longer works with Python 3.

Use atexit.register() instead.

Signed-off-by: Philipp Hahn <hahn@univention.de>
2020-08-05 07:43:01 +00:00
Philipp Hahn
59c2df2fa4 examples/event-test: Remove unneeded global statement
It only needed when a value is assigned.

Signed-off-by: Philipp Hahn <hahn@univention.de>
2020-08-05 07:43:01 +00:00
Philipp Hahn
a19f086831 examples/dhcp*: Fix None comparison
None should be compared with "is None" instead of "== None", as the
later would invoke a "__cmp__()" method.

Signed-off-by: Philipp Hahn <hahn@univention.de>
2020-08-05 07:43:01 +00:00
Philipp Hahn
6aa02b3292 examples/*: Remove stray semicolon
This is Python, not C

Signed-off-by: Philipp Hahn <hahn@univention.de>
2020-08-05 07:43:01 +00:00
Daniel P. Berrangé
dc1dc11efe ci: refresh dockerfiles for changed libvirt build system
Libvirt changed from autotools to meson. All the containers need
refreshing and the CI recipes updated.

Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
2020-08-04 12:23:26 +01:00
Jiri Denemark
2966ed6085 Post-release version bump to 6.7.0
Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
2020-08-03 00:23:16 +02:00
Philipp Hahn
ca394b9f3c generator: Fix parent type
The constructors for virDomain, virStoragePool, virDomainCheckpoint,
virDomainSnapshot expect virConnect as their first argument. The current
code always uses `self`, which is okay when such an instance is created
from a method of virConnect itself, but there are several cases where
this is not the case:

    virDomain.migrate() -> virDomain
    virDomain.migrate2() -> virDomain
    virDomain.migrate3() -> virDomain
    virDomainCheckpoint.getParent() -> virDomainCheckpoint
    virDomainSnapshot.getParent() -> virDomainSnapshot
    virStorageVol.storagePoolLookupByVolume() -> virStoragePool

> libvirt.py:1850: error: Argument 1 to "virDomain" has incompatible type "virDomain"; expected "virConnect"
> libvirt.py:1871: error: Argument 1 to "virDomain" has incompatible type "virDomain"; expected "virConnect"
> libvirt.py:1888: error: Argument 1 to "virDomain" has incompatible type "virDomain"; expected "virConnect"
> libvirt.py:3422: error: Argument 1 to "virStorageVol" has incompatible type "virStoragePool"; expected "virConnect"
> libvirt.py:6835: error: Argument 1 to "virDomainCheckpoint" has incompatible type "virDomainCheckpoint"; expected "virDomain"
> libvirt.py:6943: error: Argument 1 to "virDomainSnapshot" has incompatible type "virDomainSnapshot"; expected "virDomain"

>>> import libvirt
>>> con = libvirt.open('test:///default')
>>> dom = con.lookupByName("test")
>>> first = dom.checkpointCreateXML("""<domaincheckpoint><name>First</name></domaincheckpoint>""")
>>> first.domain()
<libvirt.virDomain object at 0x7f728c3b6b80>
            ^^^^^^
>>> second = dom.checkpointCreateXML("""<domaincheckpoint><name>Second</name></domaincheckpoint>""")
>>> parent = second.getParent()
>>> parent.domain()
<libvirt.virDomainCheckpoint object at 0x7f728c424d30>
            ^^^^^^^^^^^^^^^^

Signed-off-by: Philipp Hahn <hahn@univention.de>
v6.6.0
2020-07-27 13:48:28 +02:00
Philipp Hahn
a14161f01c debug: Fix bit-rot in debug output
Let the compiler optimize out the printf() call instead of doing it with the
pre-processor as the later does not catch format string errors or the following
case, where NULLSTR() is used but not defined:

> libvirt-qemu-override.c: In function ‘libvirt_qemu_virConnectDomainQemuMonitorEventRegister’:
> libvirt-qemu-override.c:271:34: warning: implicit declaration of function ‘NULLSTR’; did you mean ‘NULL’? [-Wimplicit-function-declaration]
>   271 |           pyobj_conn, pyobj_dom, NULLSTR(event), pyobj_cbData, flags);
>       |                                  ^~~~~~~
> libvirt-qemu-override.c:39:28: note: in definition of macro ‘DEBUG’
>    39 |     while (0) {printf(fmt, __VA_ARGS__);}
>       |                            ^~~~~~~~~~~
> libvirt-qemu-override.c:270:11: warning: format ‘%s’ expects argument of type ‘char *’, but argument 4 has type ‘int’ [-Wformat=]
>   270 |     DEBUG("libvirt_qemu_virConnectDomainQemuMonitorEventRegister(%p %p %s %p %x) called\n",
>       |           ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
>   271 |           pyobj_conn, pyobj_dom, NULLSTR(event), pyobj_cbData, flags);
>       |                                  ~~~~~~~~~~~~~~
>       |                                  |
>       |                                  int
> libvirt-qemu-override.c:39:23: note: in definition of macro ‘DEBUG’
>    39 |     while (0) {printf(fmt, __VA_ARGS__);}
>       |                       ^~~
> libvirt-qemu-override.c:270:73: note: format string is defined here
>   270 |     DEBUG("libvirt_qemu_virConnectDomainQemuMonitorEventRegister(%p %p %s %p %x) called\n",
>       |                                                                        ~^
>       |                                                                         |
>       |                                                                         char *
>       |                                                                        %d

Copy the definition of NULLSTR from libvirt/src/internal.h to typewrappers.h

Signed-off-by: Philipp Hahn <hahn@univention.de>
2020-07-27 13:24:36 +02:00
Philipp Hahn
cfcf988a98 libvirtaio: Fix return types of callback
libvirt defines the signature for the callback functions, e.g. the
functions for remove() must return -1 on error and 0 on success. Raising
an exception violates that contract.

_remove_timeout() did not explicitly handle a double-remove and
implicitly passed on the exception.

update() expects no return value, so remove the pointless return to pass
on None.

Signed-off-by: Philipp Hahn <hahn@univention.de>
2020-07-27 13:24:36 +02:00
Philipp Hahn
b595e59b48 qemu-api: Fix return type
The API XML description uses "C types": "str *" is not valid.

Signed-off-by: Philipp Hahn <hahn@univention.de>
2020-07-27 13:24:36 +02:00
Philipp Hahn
932055e3cb generator: Fix domainCheckpoint.listAllChildren()
virDomainCheckpoint(dom, _obj)
expects a reference to the virDomain as its first argument, but
    virDomainCheckpoint.listAllChildren()
passes `self` instead:

libvirt.py:7056: error: Argument 1 to "virDomainCheckpoint" has incompatible type "virDomainCheckpoint"; expected "virDomain"

>>> import libvirt
>>> con = libvirt.open('test:///default')
>>> dom = con.lookupByName("test")
>>> first = dom.checkpointCreateXML("""<domaincheckpoint><name>First</name></domaincheckpoint>""")
>>> second = dom.checkpointCreateXML("""<domaincheckpoint><name>Second</name></domaincheckpoint>""")
>>> child, = first.listAllChildren()
>>> second.domain()
<libvirt.virDomain object at 0x7f828d777b80>
         ^^^^^^^^^
>>> child.domain()
<libvirt.virDomainCheckpoint object at 0x7f828d8160a0>
         ^^^^^^^^^^^^^^^^^^^

Signed-off-by: Philipp Hahn <hahn@univention.de>
2020-07-27 13:24:36 +02:00
Philipp Hahn
a65d230ded generator: Fix domainSnapshot.listAllChildren()
virDomainSnapshot(dom, _obj)
expects a reference to the virDomain as its first argument, but
    virDomainSnapshot.listAllChildren()
passes `self` instead:

libvirt.py:6459: error: Argument 1 to "virDomainSnapshot" has incompatible type "virDomainSnapshot"; expected "virDomain"

>>> import libvirt
>>> con = libvirt.open('test:///default')
>>> dom = con.lookupByName("test")
>>> first = dom.snapshotCreateXML("""<domainsnapshot><name>First</name></domainsnapshot>""")
>>> second = dom.snapshotCreateXML("""<domainsnapshot><name>Second</name></domainsnapshot>""")
>>> child, = first.listAllChildren()
>>> second.domain()
<libvirt.virDomain object at 0x7fb32be3cfd0>
         ^^^^^^^^^
>>> child.domain()
<libvirt.virDomainSnapshot object at 0x7fb32bdb9080>
         ^^^^^^^^^^^^^^^^^

Signed-off-by: Philipp Hahn <hahn@univention.de>
2020-07-27 13:24:36 +02:00