Commit Graph

54 Commits

Author SHA1 Message Date
Richard W.M. Jones
05d4fcb64d Update copyright dates for 2019.
This command run over the source:

perl -pi.bak -e 's/(20[01][0-9])-2018/$1-2019/g' `git ls-files`
2019-01-08 11:58:30 +00:00
Richard W.M. Jones
212762c593 Update copyright dates for 2018.
Run the following command over the source:

  perl -pi.bak -e 's/(20[01][0-9])-2017/$1-2018/g' `git ls-files`
2018-01-04 15:30:10 +00:00
Richard W.M. Jones
f3330e144b python: tests: Allow some tests to be skipped.
Currently test820RHBZ912499.py fails with libvirt because libvirt
still doesn't work around qemu locking properly.  Allow this test to
be skipped on a temporary basis using SKIP_TEST820RHBZ912499_PY=1
2017-10-18 18:30:05 +01:00
Pino Toscano
00bf11cba8 python: PEP 8: add empty line
Small update for commit 45e046dac9.

This is just formatting, no behaviour changes.
2017-05-15 14:31:56 +02:00
Matteo Cafasso
401c445636 python: check return value of Python object functions (RHBZ#1406906)
Verify the returned values of Python Object constructor functions
are not NULL before adding them to a collection.

This is particularly relevant when constructing Unicode strings in
Python 3 as they will return NULL if non UTF-8 characters are present.

Signed-off-by: Matteo Cafasso <noxdafox@gmail.com>
2017-05-15 14:20:31 +02:00
Richard W.M. Jones
45e046dac9 tests: Disable some tests so they don't break when ./configure --without-libvirt 2017-02-23 13:59:38 +00:00
Pino Toscano
55bf7de97c Update copyright dates for 2017
Run the following command over the source:

  perl -pi.bak -e 's/(20[01][0-9])-2016/$1-2017/g' `git ls-files`

(Thanks Rich for the perl snippet, as used in past years.)
2017-01-03 16:48:21 +01:00
Pino Toscano
43358290b3 python: PEP 8: miscellaneous coding fixes
python/guestfs.py:136:37: E712 comparison to True should be 'if cond is True:' or 'if cond:'
python/t/tests_helper.py:42:8: E713 test for membership should be 'not in'

No functional changes, as the new versions follow the suggested Python
coding style to do the same things.
2016-05-04 18:56:01 +02:00
Pino Toscano
845d518b8b python: PEP 8: miscellaneous indentation fixes
Small fixes for few remaining indentation issues.

No behaviour changes.
2016-05-04 18:56:01 +02:00
Pino Toscano
6e34396661 python: PEP 8: avoid too long lines
Reindent Python scripts to make sure lines are not longer than 80
columns.

Regarding autogenerated code (guestfs.py and bindtests.py): add an
helper function to make sure comma-separated lists are wrapped at the
wanted length.

This produces only differences in the indentation of long Python lines,
with no behaviour changes.
2016-05-04 18:56:01 +02:00
Pino Toscano
2c7bba6374 python: PEP 8: remove trailing semicolons
Remove extra semicolons at the end of single-statement lines.

No behaviour changes.
2016-05-04 18:56:01 +02:00
Pino Toscano
f85e18f62f python: PEP 8: adapt empty lines
Add or remove empty lines to match the needed ones around
blocks/functions/etc.

This is just formatting, no behaviour changes.
2016-05-04 18:56:01 +02:00
Pino Toscano
6105ee0c71 python: PEP 8: adapt whitespaces in lines
Add (after comma) or remove (before opening round bracket, and around
'=' in arguments) whitespaces according to the PEP 8 specification.

This is just code reformatting, with no behaviour changes; no content
changed beside whitespaces, so "git diff -w" gives an empty diff.
2016-05-04 18:56:01 +02:00
Richard W.M. Jones
aae74c9e4e python: Add README documenting how to run a single test. 2016-03-24 14:46:42 +00:00
Richard W.M. Jones
0024e5a13e python: Misspelling in tests, libirt -> libvirt. 2016-03-24 13:56:29 +00:00
Pino Toscano
789d256645 python: tests: fix long/int mismatch in test090RetValues.py
Cast the value to the "int_type" representing the "long" value for
test_rint64, so the test works again with Python 3.
2016-02-22 17:13:38 +01:00
Pino Toscano
519c9bc8df python: tests: move the 'int' type in tests_helper
This way it can be used in other tests as well.

Simple code motion.
2016-02-22 16:57:57 +01:00
Pino Toscano
9776615301 python: tests: refactor to use unittest's discovery
Instead of running all the tests manually, the unittest module has a
'discovery' mode to run tests by importing them from a directory: this
requires the tests to have different filenames, since they need to be
imported as modules now (hence an empty __init__.py is added), and the
current naming does not match the convention.

Using unittest as loader/runner brings another change: tests skipped as
whole cannot be done anymore with exit(77), since they are not run but
imported: thus introduce an helper module with decorators applied to the
test classes to skip them according to the current checks.  This also
gets us nicer recordings in the unittest log.

Due to the relative imports (needed for the helper code), it is no more
possible to execute tests anymore by invoking them manually; although
it is possible to run single tests, still using unittest's runner:

  $ cd python
  python$ ../run python -m unittest discover -v t test010Load.py

This does not change anything in what the tests do/check.
2016-02-22 16:57:15 +01:00
Pino Toscano
f7765ea6e4 Start adding return values tests for bindings
Introduce a new kind of bindings tests, 090-retvalues, to check all the
possible return values in bindings; start implementing them for
scripting languages such as GObject introspection, Perl, PHP, Python,
and Ruby, reusing existing implementations where existing.
2016-02-15 18:32:07 +01:00
Pino Toscano
2a2a540436 python: tests: use more targeted assert*() functions/checks
- use assertIsInstance, assertNotEqual, and assertIsNotNone as more
  specific checks (will produce better logging)
- use assertRaises when expecting exceptions being thrown
- when testing internal_test_rhashtable, instead of checking type and
  elements of the return values just check the return value as a whole
  (easier and already getting all the work needed by unittest)
2016-02-12 17:57:58 +01:00
Richard W.M. Jones
85b1815e7b tests: Make '080' be an official test of the guestfs_version API.
Useful because it tests returning a single structure.
2016-02-12 15:41:42 +00:00
Richard W.M. Jones
b647dd8b52 python: tests: Use the 'unittest' module to run the test suite. 2016-02-12 15:32:39 +00:00
Pino Toscano
2bccaa3047 python: stop using parens-less print in tests
print "" is no more available in Python 3, and print(...) is available
since Python 2.7; as one of the tests was using print(), use this form
everywhere so the tests can run fine with Python 3.
2016-01-28 14:45:23 +01:00
Richard W.M. Jones
307c83177c Update copyright dates for 2016.
Run the following command over the source:

  perl -pi.bak -e 's/(20[01][0-9])-2015/$1-2016/g' `git ls-files`
2016-01-02 21:19:51 +00:00
Richard W.M. Jones
f45b6928c5 aarch64: python: Skip test that requires IDE.
This test launches a dummy guest using IDE.  Aarch64 doesn't support
IDE, and because it also doesn't support PCI (virtio-mmio instead)
it's hard to formulate libvirt XML that will work on both x86 and
virtio-mmio.

Since this bug is not architecture specific (RHBZ#912499), skip it on
non-x86.  The test will print:

  skipping test: arch is not x86 and does not support IDE
2015-01-20 09:49:31 +00:00
Richard W.M. Jones
c5800dc97d Update copyright dates for 2015. 2015-01-17 09:08:15 +00:00
Richard W.M. Jones
8e0fc5fb46 python: Fix regression test so it works when KVM is not available.
The test assumed (for no particular reason) that it could always run a
KVM guest.  When run on a machine without KVM, or in a VM without
nested KVM, you get this error:

libvirt: Domain Config error : internal error: no supported architecture for os type 'hvm'
Traceback (most recent call last):
  File "./t/820-rhbz912499.py", line 77, in <module>
    dom = conn.createXML (xml, libvirt.VIR_DOMAIN_START_AUTODESTROY)
  File "/usr/lib64/python2.7/site-packages/libvirt.py", line 3523, in createXML
    if ret is None:raise libvirtError('virDomainCreateXML() failed', conn=self)
libvirt.libvirtError: internal error: no supported architecture for os type 'hvm'
FAIL: ./t/820-rhbz912499.py

Use a qemu guest instead, which should have a better chance of working
on all hosts.
2014-12-16 13:16:07 +00:00
Richard W.M. Jones
90e9ad7ff9 python: Add a regression test for disk labelling. 2014-12-11 15:16:42 +00:00
Richard W.M. Jones
2c9f6da034 python: Implement Pointer ("virDomainPtr", _) (RHBZ#1075164).
This allows the Python binding of guestfs_add_libvirt_dom to work.

There is a regression test to ensure this keeps working.

Note this requires a patched libvirt-python, supporting the
c_pointer() method.
2014-12-11 15:16:42 +00:00
Richard W.M. Jones
f02fddc26b tests: Update miscellaneous tests to use disk-create API.
Instead of calling out to qemu-img / truncate.
2014-01-28 21:02:11 +00:00
Richard W.M. Jones
6c971faecf Update copyright dates for 2014. 2014-01-02 16:53:34 +00:00
Richard W.M. Jones
92e1864913 events: Add a warning event and direct all warning messages through it.
This also causes warnings to be printed even in non-verbose mode,
which is useful.
2013-10-11 15:34:23 +01:00
Richard W.M. Jones
4180abcc1f tests: Use unique or temporary names for temporary files.
Review every test(!) to ensure that it:

 - Doesn't use a generic name (eg. "test1.img", "test.out") for any
   temporary file it needs.

 - Does instead use a unique name or a temporary name (eg. a name like
   "name-of-the-test.img", or a scratch disk).

 - Does not use 'rm -f' to clean up its temporary files (so we can
   detect errors if the wrong temporary file is created or removed).

This allows tests to be run in parallel, so they don't stomp on each
other's temporary files.
2013-07-23 10:16:00 +01:00
Richard W.M. Jones
14fabcd88e tests: Use new guestfs_add_drive_scratch API where possible in tests.
Replaces code such as:

  fd = open "test1.img"
  ftruncate fd, size
  close fd
  g.add_drive "test1.img"

with the shorter and simpler:

  g.add_drive_scratch size
2013-07-20 16:31:42 +01:00
Richard W.M. Jones
a24639d7d3 python: Standardize test numbering. 2013-04-30 17:34:22 +01:00
Richard W.M. Jones
ba0199c487 python: Let RHashtable be returned as a Python dict.
The initial proposal was suggested by Matt Booth and discussed on the
mailing list here:

https://www.redhat.com/archives/libguestfs/2013-April/msg00007.html
2013-04-03 19:18:07 +01:00
Richard W.M. Jones
0f849029d1 python: Add binding for guestfs_event_to_string. 2013-02-19 13:41:58 +00:00
Richard W.M. Jones
0d18a8b407 Update copyright dates for 2013. 2013-02-02 13:56:19 +00:00
Richard W.M. Jones
42e8c093b7 python: Fix optargs so we don't use special sentinel values.
Previously with Python it was impossible to set a boolean or integer
optarg to -1 because that was used as a special sentinel value to
indicate that the optarg was not set.

Instead, use None as the sentinel value, since that cannot be a
boolean or integer type.
2012-08-15 12:16:54 +01:00
Richard W.M. Jones
7486fc6f43 generator: Rename 'add_drive_opts' API to 'add_drive'.
By using the once_had_no_optargs flag, this change is backwards
compatible for callers (except Haskell, PHP and GObject as discussed
in earlier commit).
2012-07-14 12:42:24 +01:00
Richard W.M. Jones
ffbf1475f7 New API: guestfs_shutdown: Cleanly shutdown the backend.
The new API splits orderly close into a two-step process:

  if (guestfs_shutdown (g) == -1) {
    /* handle the error, eg. qemu error */
  }
  guestfs_close (g);

Note that the explicit shutdown step is only necessary in the case
where you have made changes to the disk image and want to handle write
errors.  Read the documentation for further information.

This change also:

 - deprecates guestfs_kill_subprocess

 - turns guestfs_kill_subprocess into the same as guestfs_shutdown

 - changes guestfish and other tools to call shutdown + close
   where necessary (not for read-only tools)

 - updates documentation

 - updates examples
2012-07-03 21:27:29 +01:00
Richard W.M. Jones
729bb9c6b5 launch: Treat /dev/null specially, for old KVM.
Old KVM can't add /dev/null readonly.  Treat /dev/null as a special
case.

We also fix a few tests where /dev/null was being used with
format=qcow2.  This was always incorrect behaviour, but qemu appears
to tolerate it.
2012-06-25 11:20:35 +01:00
Richard W.M. Jones
255882a3f6 python: Remove 'del g' from the docs, replace with 'g.close ()'.
'del g' is a trap for the unwary.  If the handle has any other
references, it does nothing (in fact, it can be actively dangerous if
the user was expecting the appliance to go away).  In non-CPython it
can be delayed arbitrarily long.

Using 'g.close()' on the other hand is always safe.
2012-04-17 17:41:43 +01:00
Richard W.M. Jones
b6dd7e7250 python: Add a regression test for RHBZ#811650. 2012-04-11 17:56:12 +01:00
Richard W.M. Jones
08840bab44 Tempus fugit.
Update all copyright dates to 2012.
2012-01-18 22:05:02 +00:00
Matthew Booth
04ea1375c5 Update FSF address. 2011-11-08 14:43:07 +00:00
Richard W.M. Jones
8c5bdc3e12 python: Add explicit g.close() method (RHBZ#717786). 2011-06-30 10:14:33 +01:00
Richard W.M. Jones
2cac52000a python: Implement new event API.
This implements set_event_callback and delete_event_callback so that
Python programs can use the new event mechanism.
2011-04-22 21:50:16 +01:00
Richard W.M. Jones
b034795a25 python: Combine tests to reduce number of launches. 2010-11-30 13:59:50 +00:00
Richard W.M. Jones
14490c3e1a generator: Optional arguments, add-drive-opts (RHBZ#642934,CVE-2010-3851).
This large commit changes the generator so that optional arguments
can be supported for functions.

The model for arguments (known as the "style") is changed from
(ret, args) to (ret, args, optargs) where optargs is a more limited
list of arguments.

One function has been added which takes optional arguments, it is
"add-drive-opts", modelled as:

  (RErr, [String "filename"], #required
         [Bool "readonly"; String "format"; String "iface"]) #optional

Note that this function is processed in the library (does not go over
the RPC protocol to the daemon).  This has allowed us to simplify
the current implementation by omitting changes related to RPC or the
daemon, although we plan to add these at some point in the future.

From C this function can be called in 3 different ways as in these
examples:

  guestfs_add_drive_opts (g, filename,
                          GUESTFS_ADD_DRIVE_OPTS_READONLY, 1,
			  GUESTFS_ADD_DRIVE_OPTS_FORMAT, "raw",
                          -1);

(the argument(s) between 'filename' and '-1' are the optional ones).

  guestfs_add_drive_opts_va (g, filename, args);

where 'args' is a va_list.  This works like the first version.

  struct guestfs_add_drive_opts_argv optargs = {
    .bitmask = GUESTFS_ADD_DRIVE_OPTS_READONLY_BITMASK,
    .readonly = 1,
  }
  guestfs_add_drive_opts_argv (g, filename, &optargs);

This last form lets you construct lists of optional arguments, and
is used by guestfish and the language bindings.

In guestfish optional arguments are used like this:

  add-drive-opts filename readonly:true

In OCaml these are mapped naturally to OCaml optional arguments, eg:

  g#add_drive_opts ~readonly:true filename;

In Perl these are mapped to extra arguments, eg:

  $g->add_drive_opts ($filename, readonly => 1);

In Python these are mapped to optional arguments, eg:

  g.add_drive_opts ("file", readonly = 1, format = "qcow2")

In Ruby these are mapped to a final hash argument, eg:

  g.add_drive_opts("file", {})
  g.add_drive_opts("file", :readonly => 1)
  g.add_drive_opts("file", :readonly => 1, :iface => "virtio")

In PHP these are mapped to extra parameters.  This is not quite
accurate since you cannot omit arbitrary optional parameters, but
there's not much than can be done within the limitations of PHP
as a language.

Unimplemented in: Haskell, C#, Java.
2010-10-22 17:45:00 +01:00