285 Commits

Author SHA1 Message Date
Richard W.M. Jones
08e27451a6 tests: Add script to check documented tool options match actual options.
podcheck.pl is run as part of the tests to perform various checks on
the documentation and the tool.

Currently we check only that the documented options matches the
options that the tool implements and vice versa.  This commit would
also allow us (in future) to check --help, --long-options,
--short-options, --version output.

This commit includes scripts to run the tests and various fixes to the
manual pages to ensure that the tests pass.
2016-07-19 13:06:14 +01:00
Pino Toscano
99797a3d2f mllib: Getopt: add Getopt.Symbol
Introduce a new type of option to allow a value out of a fixed choice,
much like Arg.Symbol.
2016-07-18 18:20:57 +02:00
Richard W.M. Jones
ba2cf9a2eb mllib: Use L"..." and S '...' for long and short options.
There is also an M"..." variant which acts the same way as
L but handles the annoying virt-v2v two letter options.
2016-07-18 17:01:22 +01:00
Richard W.M. Jones
c2fda2c1f2 build: Factor out definition of BEST and OCAMLLINKFLAGS.
No change, just refactoring.
2016-07-18 14:11:22 +01:00
Richard W.M. Jones
2c6bfccb06 build: Fix dependencies on mllib and customize.
Binaries should be rebuilt if mllib.cma/mllib.cmxa or
customize.cma/customize.cmxa change.

Fixes commit 1e2877c6f4.
2016-07-18 14:10:28 +01:00
Richard W.M. Jones
6a0fe553b9 customize: Build a customize.cma/customize.cmxa library.
Instead of linking with individual objects, which is very tedious,
build a proper library and link virt-builder, virt-customize and
virt-sysprep to it.

This makes the binaries a tiny bit smaller because .cmxa/.a files
allow unused code to be removed by the linker, whereas explicitly
linking .cmx/.o files does not.
2016-07-14 15:40:42 +01:00
Richard W.M. Jones
1e2877c6f4 mllib: Build a mllib.cma/mllib.cmxa library.
Instead of linking with individual objects, which is very tedious,
build a proper library and link the other tools with it.

This doesn't make the resulting binaries any larger.
2016-07-14 15:28:10 +01:00
Richard W.M. Jones
f3c69fe60b customize: Add module for doing SELinux relabel of filesystem (RHBZ#554829, RHBZ#983969, RHBZ#1089100).
This implements the --selinux-relabel option for virt-customize,
virt-builder and virt-sysprep.  There is no need to autorelabel
functionality now.

Thanks: Stephen Smalley
2016-07-14 15:28:10 +01:00
Richard W.M. Jones
eb22e2d36e v2v: Move augeas_debug_errors (renamed debug_augeas_errors) to common code.
Since the function uses the StringMap module, I also had to
move this to mllib.

The function is renamed and the 'if verbose ()' part is moved into the
function, but apart from that, it's all just code motion.
2016-07-14 11:40:22 +01:00
Pino Toscano
7a404b1110 mllib: Getopt: support hidden options
Add a dummy description value to mark an option as "hidden", so it will
not be shown in the help text.

Mark few options as hidden:
- common: --short-options, --long-options, --debug-gc
- virt-sysprep: --dump-pod, --dump-pod-options

Since --debug-gc is now really considered internal, it is no more
documented.
2016-07-14 10:58:56 +02:00
Pino Toscano
0f7bf8f714 OCaml tools: add and use a Getopt module
Add a new Getopt module to mllib, to parse command line arguments with
handlers close to the ones used with Arg, but using getopt(3) (actually
getopt_long_only) to do the real parsing.  This allow us to provide
options for OCaml tools with a syntax similar to the C tools, and use
the additional features getopt offers and Arg does not.
Getopt now handles every part of the command line handling, including
the output of short & long options.

Do a single-step conversion of Common_utils and all the OCaml tools to
the syntax of Getopt.

Move a couple of utility functions from Common_utils to Getopt, since
they fit better there (and Common_utils cannot be used in Getopt, as
the former already uses the latter).

As side-change due to the conversion, extra arguments for sysprep
operation can have more keys for the same argument.
2016-07-13 18:43:32 +02:00
Maxim Perevedentsev
4e0dbf94e7 sysprep: fix btrfs subvolume processing in fs-uuids
guestfs_set_uuid wants device as argument.
Moreover, btrfstune -U is unable to set uuid for subvolumes,
only unmounted partitions are supported.

Here we skip btrfs subvolumes.
2016-07-08 13:21:42 +01:00
Richard W.M. Jones
123dc018b8 mllib: Rename unshift -> push_front, push -> push_back etc.
The C++ function names are more regular.

Updates commit 1c57c71d46.
2016-07-08 09:56:47 +01:00
Richard W.M. Jones
442092a305 Replace 'xs := x :: !xs' with 'unshift x xs'.
In one case, I used prepend instead.
2016-07-07 18:13:07 +01:00
Richard W.M. Jones
b000d6bc68 virt tools: Add common --colours option.
This option (alternately spelled: --color, --colour, --colors, or
--colours) enables ANSI colour sequences output even if that would be
disabled becaues the output is not a TTY.
2016-06-18 21:15:59 +01:00
Richard W.M. Jones
6e79a3c84d Convert source so it can be compiled with OCaml '-safe-string' option.
OCaml 4.02 introduced the 'bytes' type, a mutable string intended to
replace the existing 'string' type for those cases where the byte
array can be mutated.  In future the 'string' type will become
immutable.  This is not the default now, but it can be forced using
the '-safe-string' compile option.

This commit changes the code so that it could be compiled using
'-safe-string' (but does not actually make that change).

If we detect OCaml < 4.02, we create a dummy 'Bytes' compatibility
module ((nearly) an alias for the 'String' module).  The only
significant difference from upstream OCaml is that you must write the
'bytes' type as 'Bytes.t' in interfaces, apart from that everything
else should work.
2016-06-16 15:22:04 +01:00
Richard W.M. Jones
669e25049e sysprep: Add --network to enable the network (RHBZ#1345813).
In commit ae6f726ecc we started to use
the virt-customize code to replace various virt-sysprep operations.
This had the effect of adding many more possible operations to
virt-sysprep, but some of them (specifically --install) did not work
unless the appliance network is enabled.  It was not enabled in
virt-sysprep, so these operations never worked.

This change does NOT enable the network by default.  However it adds a
--network flag which may be used in conjunction with --install etc to
make those commands work.

In addition we now emit a warning for certain customize operations if
they fail and if the network is not enabled.  It will print:

  [   4.5] Installing packages: tcpdump
  Error: Cannot retrieve repository metadata (repomd.xml) for repository: base. Please verify its path and try again
  Could not retrieve mirrorlist http://mirrorlist.centos.org/?release=6&arch=x86_64&repo=os&infra=stock error was

  virt-sysprep: warning: the command may have failed because the network is
  disabled.  Try either removing '--no-network' or adding '--network' on the
  command line.

  virt-sysprep: error: yum -y install 'tcpdump': command exited with an error

(If the network is already enabled, or if the command is successful,
then the warning is not printed.)

Thanks: Xianghua Chen
2016-06-13 15:39:34 +01:00
Richard W.M. Jones
a3cb12ab2c ocaml: Move identical rules for building OCaml objects to common file. 2016-06-13 08:51:46 +01:00
Richard W.M. Jones
df7a33768e mllib: Add Common_utils.is_partition function.
Returns true if the device is a host partition.

The only tedious bit of this patch is that now Common_utils depends on
Dev_t so we have to add extra objects every time something links with
Common_utils.
2016-06-03 13:05:07 +01:00
Cédric Bosdonnat
ee78c06b7f customize: add support for pvvxsvc
SUSE VMDP comes with a replacement for rhsrvany.exe named pvvxsvc.exe.
Check for either one of them instead of only rhsrvany.
2016-05-20 10:39:58 +01:00
Pino Toscano
d5b3f558e0 tests: remove remaining relative paths to binaries
Tests are run via the ./run binary, so all the binaries in the build
directory are available via $PATH already.

Followup of commit e85a976c5a.
2016-05-19 19:06:00 +02:00
Pino Toscano
64bb9edd52 tests: specify the image format when possible
When possible, make the disk image format explicit when invoking tools
or using add-drive. This avoids warnings from qemu about the unspecified
format for the image, and also makes qemu slightly faster (skipping the
disk image probing).
Tests checking the image probing are not touched.

This changes also:
- old-style invocations of tools (`$tool $filename`) into new style
  (`$tool -a $filename`)
- add-drive-ro/add-drive-with-if guestfish commands into add/add-drive
  with explicit readonly/iface arguments

There should be no change in the tests results.
2016-05-19 19:06:00 +02:00
Richard W.M. Jones
a1e47c4b47 tools: Reduce use of _ (wildcard) in match statements.
No functional change, just various improvements to the safety of match
statements.
2016-04-21 12:50:58 +01:00
Richard W.M. Jones
dec30914e8 mllib: Rename uRI -> URI.
There is no difference in the OCaml module name, which remains 'URI'.
2016-04-20 22:48:37 +01:00
Pino Toscano
82b0d25bb2 mllib: factor out mounting of guest root
Introduce and use a new inspect_mount_root function to mount all the
mountpoints of a root in the guest, replacing the same code doing that
in different tools.

inspect_mount_root_ro is inspect_mount_root with readonly mount option.
2016-03-03 14:52:39 +01:00
Pino Toscano
9753986819 fish, sysprep: run FUSE-related tests only when FUSE is available
They will fail anyway in that case, so run them only when the FUSE
support is built in.
2016-02-11 18:40:04 +01:00
Pino Toscano
14b8e67f0b sysprep, get-kernel: explicit the Guestfs parameter
Help the OCaml compiler by expliciting Guestfs.guestfs as type for 'g'
in some functions.
2016-02-04 10:22:18 +01:00
Richard W.M. Jones
446f7794e0 podwrapper: Add --warning flag for manual pages of CLI tools (RHBZ#1293527).
This doesn't add --warning flags to the translated pages,
which is a bug to be fixed at some point.
2016-01-11 13:42:49 +00: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
be1b9315ac customize, dib, resize, sysprep: Use 'may' pattern in various places. 2015-11-11 16:12:36 +00:00
Pino Toscano
4cc98d8f6e OCaml tools: use open_guestfs everywhere
Instead of creating Guestfs handles and manually apply common options
(e.g. debug and trace), use the open_guestfs in Common_utils.
This also applies the common options to handles which didn't set them
before, so we can inspect also their messages if needed.
2015-11-10 11:38:40 +01:00
Richard W.M. Jones
a2edda266e build: Make 'make clean' remove more files.
Remove man pages and other pages which 'make clean' did not remove
before.

To evaluate which pages could be removed, I did a full build and
check, and then ran 'make clean' followed by 'git clean -xdf'.  By
examining the output of the git clean command I could see which files
were being missed.

Files that are _not_ removed by make clean or make distclean:

 - generator-built files

 - Makefile, Makefile.in, .deps, .depend

 - any ./configure output files (maybe they should be?)
2015-11-03 13:53:37 +00:00
Richard W.M. Jones
47b095b928 website: Put website into a separate directory.
Move the random set of HTML files we build from html/ into
the website/ directory.

Also in the website/ directory, put the index.html file from
http://libguestfs.org, which was previously not under version control.
It is generated from index.html.in so we can automatically add the
current version and release date.

Also in the website/ directory, put various CSS file, images, etc.
which are required by the website and were also previously not under
version control.

Change the 'make website' rule to 'make maintainer-upload-website'.
As the name suggests, it is only useful for the maintainer, and will
fail with an error for anyone else.
2015-10-31 17:09:29 +00:00
Richard W.M. Jones
dc1d0880b0 tests: Move the tests/data and tests/guests directories to test-data.
Create a new top-level directory called test-data, which will carry
all the test data which is large and/or shared between multiple tests.

There are actually several new subdirectories created:

test-data/binaries: The pre-built binary and library files for random
architectures that we use to test various architecture detection
features (was part of tests/data).

test-data/blank-disks: The blank disks which are used for disk format
detection (was part of tests/data).

test-data/files: Other miscellaneous test files from tests/data that
are not included in the above.

test-data/phony-guests: The phony guests (was tests/guests).

test-data: The top-level directory builds the 'test.iso' image file
that is used for testing the C API and in miscellaneous other tests.
2015-10-30 16:07:32 +00:00
Richard W.M. Jones
63952d9666 ocaml: Rename Config module as Guestfs_config.
Unfortunately Coccinelle places a Config module in the ocaml libdir,
and this confuses ocamlfind (only when Coccinelle is installed).
Since this is a private module that only libguestfs tools use
internally, just rename it from Config -> Guestfs_config.
2015-10-30 09:45:02 +00:00
Richard W.M. Jones
0944acf90c mllib: Replace various ad hoc string_* functions with String.*
This is just a straight refactoring.  Various ad hoc string_*
functions that appeared in Common_utils have been renamed and placed
in the String.* namespace.  The old vs "new" functions are:

string_prefix  -> String.is_prefix
string_suffix  -> String.is_suffix
string_find    -> String.find
replace_str    -> String.replace
string_nsplit  -> String.nsplit
string_split   -> String.split
string_lines_split -> String.lines_split
string_random8 -> String.random8
2015-10-06 13:40:34 +01:00
Pino Toscano
2ec0332e5e mllib: move -q/--quiet as common option
Most of the OCaml-based tools had it already, except from virt-dib and
virt-get-kernel.
2015-09-02 00:25:55 +02:00
Pino Toscano
4cc3cc3fbd mllib: set --debug-gc as common option
Move --debug-gc as common option for all the OCaml-based tools, even a
couple of them which didn't have it previously.

As implementation note, make set_debug_gc private to
set_standard_options, as it needed to be moved otherwise, and it is no
more required as public function.
2015-08-31 18:34:37 +02:00
Pino Toscano
2af6e48ba3 mllib: add and use set_standard_options
Introduce a new common helper to add the common options for libguestfs
tools (short/long options, version, verbose, trace), and sort them.
All the OCaml-based tools had these options already, so there are no
functional changes in the interface they provide.

The only difference is that now the options are always sorted, while
some tools didn't had them like that previously: because of this, a
couple of ditto markers (as descriptions) don't match what's above them
anymore, and thus their full description is put instead.
2015-08-31 18:25:48 +02:00
Roman Kagan
a628fb65fa handle --debug-gc universally via at_exit hook
Several tools handle --debug-gc command-line option, by explicitly
forcing GC on every exit path.  This is tedious and prone to forgetting
some of the exit paths.

Instead, add a generic handler for --debug-gc, which installs an at_exit
hook to do the GC consistency check, and which can be called right in
the command-line parser.  Also adjust all users of --debug-gc to use
that handler.

Signed-off-by: Roman Kagan <rkagan@virtuozzo.com>
2015-08-28 17:53:41 +01:00
Richard W.M. Jones
91c06391c1 automake: Admit defeat and use 'subdir-objects'.
Because this 'feature' is broken (since 2013):

  https://debbugs.gnu.org/cgi/bugreport.cgi?bug=13928

we have to replace all instances of $(top_srcdir) in *_SOURCES lines
with a relative path.  According to what I read, this shouldn't break
split builds, but I didn't test it.

The only things automake moans about now are:

* Unescaped left brace in regex is deprecated, passed through in regex; marked by <-- HERE in m/\${ <-- HERE ([^ \t=:+{}]+)}/ at /usr/bin/automake line 3936.

  - This is another bug in automake

* autoreconf: configure.ac: AM_GNU_GETTEXT is used, but not AM_GNU_GETTEXT_VERSION

  - This is a feature, not a bug.
2015-08-05 13:01:12 +01:00
Richard W.M. Jones
d9c6370831 sysprep: Allow test-virt-sysprep.sh to be skipped.
It fails in Fedora Rawhide because LVM is broken (RHBZ#1237136).
2015-08-02 17:33:07 +01:00
Pino Toscano
37a0378556 sysprep: machine_id: handle /var/lib/dbus/machine-id
Another machine-id file, used by D-Bus.
2015-07-29 13:47:08 +02:00
Pino Toscano
bc598ff52a sysprep: machine_id: simplify implementation
Instead of rm + touch, just truncate the file if existing.
In case there was no file previously, now nothing is created, as most
probably the system was fine even without it.

Also, turn the single path into a list, so more machine-id files can be
handled at once.
2015-07-29 13:36:23 +02:00
Pino Toscano
44f71d0782 customize: add basic subscription-manager operations
Add simple operations for RHEL guests using subscription-manager, so it
is possible to e.g. install software on them.
2015-07-17 17:03:04 +02:00
Pino Toscano
261be1f952 sysprep: rework and fix cron-spool operation (RHBZ#1229305)
When cleaning the directories with cron/at jobs, remove only files
there, as subdirectories might be used by other systems; for example
in Debian under /var/spool/cron/ there is the atjobs subdirectory with
the actual at queue.

Make sure to not remove .SEQ files anymore, as they represent the at job
counter which is needed by the at daemon. Instead, reset these files to
0.

Furthermore, add also the path to the .SEQ location in Debian-based
systems.
2015-07-01 17:17:58 +02:00
Pino Toscano
a614f3451d mllib: add and use last_part_of
Collect this small snippet to get the part of a string after the last
occurrency of a character; replace with it the current snippets doing
the same.

Should be just code motion.
2015-07-01 17:17:58 +02:00
Richard W.M. Jones
533901409e pod: Use F<> for filenames instead of C<>.
Done using a sequence of regular expressions like this:

  perl -pi.bak -e 's{C</}{F</}g' `git ls-files \*.pod` generator/actions.ml
  perl -pi.bak -e 's{C<C:\\}{F<C:\\}g' `git ls-files \*.pod` generator/actions.ml
  [etc]

and then tediously checking every change by hand.
2015-06-15 15:42:46 +01:00
Chen Hanxiao
7429b6b261 sysprep_operation: fix a typo
s/rathern/rather

Signed-off-by: Chen Hanxiao <chenhanxiao@cn.fujitsu.com>
2015-06-06 14:21:34 +01:00
Richard W.M. Jones
f2aa9261a8 ocaml tools: Translate a few messages which were not internationalized. 2015-05-15 19:10:28 +01:00