Commit Graph

71 Commits

Author SHA1 Message Date
Richard Turc
00cd79aa35 Use qemu-img json output and compute virtual size #1308 2021-06-11 16:38:35 +02:00
Darragh Bailey
0c35a1e275 Vagrant up expects machine data_dir to exist afterwards (#1298)
Ensure the machine data_dir is recreated after removal because vagrant
up expects the directory to exist even if there has been an exception
and the machine has been deleted subsequently.
2021-05-28 15:40:34 +01:00
Darragh Bailey
199bfe19f9 Provide Vagrantfile path in description by default (#1299)
Ensure the source Vagrantfile appears in the virtual machine description
to help people using virsh/virt-manager subsequently to understand where
machines have come from.

Fixes: #496
2021-05-28 14:46:57 +01:00
Darragh Bailey
994f95e24f Handle extraction of keyfile from uri (#1297)
If the keyfile is specified as part of the URI provided, extract it and
set the appropriate option so that it can be provided to the proxy
command subsequently.
2021-05-27 18:28:12 +01:00
Darragh Bailey
daa8f8af55 Handle custom port for remote libvirt (#1296)
Extract the port number from the parsed URI as part of finalizing the
uri and associated options. Don't expose this as a separate item to be
set as it can be passed in as part of the host entry.

Closes: #789
2021-05-27 17:28:25 +01:00
Darragh Bailey
7ce85f2216 Make disks attribute path required check for name collisions (#1293)
Ensure the path attribute for disks in the new format is required to
ensure there is always one parameter required for the hash element in
the array of disks. This avoids a certain amount of magical behaviour.

Identify that the name attribute is optional, however add checks for
collisions in volume names generated, as well as ensuring the volumes
are still prefixed in a way to prevent accidental collisions between
boxes utilizing the same names.

Add notes to the README identifying the format as experimental, with
notes on how the format should appear.
2021-05-22 16:59:11 +01:00
Darragh Bailey
1fe5a80516 Ensure state is correct reflected in global-status (#1292)
Vagrant relies on the side effect of checking the machine state to
trigger updating of the state in the global machine index. As a
consequence any action should not inspect the domain state directly and
instead should access the machine state.

Additionally as part of the up/start actions should switch to built-in
WaitForCommunicator which will inspect the machine states by default to
align with the expected state updating side effects that would be in
effect for any internal provider shipped with vagrant.

Closes: #948
Partial-Fix: #193
2021-05-20 13:36:23 +01:00
Darragh Bailey
981642afeb Invert forward ssh port behaviour (#1289)
Multi machines environments will result in collisions until auto
correction is implemented. Therefore invert to keep the forwarding of
the default ssh port disabled by default initially until can handle the
port collisions detection and resolving.

Relates: #1012
2021-05-18 18:30:56 +01:00
Darragh Bailey
878b5ffe61 Ensure state is fully removed for destroy (#1288)
Completely remove state after a destroy, and ensure removal of a
non-existing domain also scrubs the machine folder clean.

Closes: #1132
2021-05-18 18:21:54 +01:00
Matthias Blümel
07391048af Enable forward ssh-port to host
Provides an option to disable the forwarding in case it causes issues.
However based on original PRs adding the forwarded behaviour, it does
not appear to be intentional to exclude it permanently.

Closes: #1011
Closes: #1012
2021-05-16 19:55:54 +01:00
Darragh Bailey
f0b6897095 Adjust forwarded ports test to include other network (#1287)
Ensure the forwarded ports tests filter out other types of network
entries.
2021-05-16 19:27:37 +01:00
Darragh Bailey
5f09673c2a Basic forward port tests and refactor out @env (#1281)
Adds some basic unit spec tests to validate the main behaviours around
the port forwarding to allow for subsequent behaviour changes.

Additionally removes the dependency on the instance variable @env for
internal functions to allow testing some of the internal functions
without needing to inject an instance variable that is not set on
initialization.

Includes a file contents matcher lifted from the cucumber/aruba project
on github, with some minor modifications instead of including the entire
gem.
2021-05-15 14:37:55 +01:00
Zdenek Zambersky
3b1b17a5c9 Add support for spinlocks hyperv feature 2021-05-12 20:50:23 +02:00
Darragh Bailey
98ff2dfb51 Retrieve disk format and virtual size directly (#1274)
When uploading disks to libvirt storage it is unnecessary to require
that the virtual size or the format be provided as these can be
retrieved by calling qemu-img on the box files to retrieve the required
information.

Update the handle box image support to separate the handling of the two
different formats and remove the need to specify the additional settings
in the case of the V2 format for multi disk boxes.
2021-05-10 23:02:25 +01:00
TJ
4c2e59bc3f Allow Vagrantfile to set the CDROM image type
Although it is possible to attach additional images (disk or cdrom) the
cdrom functionality doesn't allow setting the :type - it defaults to
'raw' since vagrant-libvirt is assuming cdrom images are in ISO9660
format.

This assumption breaks down when using vagrant-mutate to convert a box
with multiple storage devices. A common situation is the Ubuntu boxes
built for VirtualBox that contain a cloud-init ISO9660 image with
user-data. vagrant-mutate converts the image to qcow* format (not
ISO9660) in order to not have to deal with what is inside.

This means the resulting libvirt domain needs to be told the type is
'qcow2' in order for the guest to see it as an ISO9660 image.

This patch adds the required option along with a sensible default.
2021-05-10 10:23:12 +01:00
Darragh Bailey
86cf4e08a7 Handle nil volumes when cd-rom attached (#1273)
When a cd-rom is attached as an additional storage, listing the volumes
can include a nil element. Make sure to check that the element is valid
before attempting to access the attribute.

Update the test to better match the observed behaviour.

Fixes: #1209, #1262
2021-05-08 17:27:04 +01:00
Darragh Bailey
fbf32889d7 Support force halt behaviour (#1270)
Vagrant subcommand halt accepts an argument -f that should result in
VMs being halted immediately instead of attempting a graceful shutdown.

Add support for this option and include tests to cover the rest of the
halt behaviour.

Fixes: #1265
2021-05-08 17:14:13 +01:00
Richard Turc
225237b125 Allow to use many disks in vagrant box for libvirt provider
Adds support for a new multi disk box format and handling to upload the
multiple disks to the storage pool.

New format is:
{
  'disks': [
    {
      'name': 'disk1.img',
      'virtual_size': 10,
      'format': 'qcow2'
    },
    {
      'name': 'disk2.img',
      'virtual_size': 15,
      'format': 'qcow2'
    },
    {
      'name': 'disk3.img',
    }
  ],
  'provider': 'libvirt',
  'format': 'qcow2'
}

It is expected to remove format from being set at the top level when
using the new format, with the assuming that qcow2 should be the default
format, and other formats should be permitted to be specified as needed.

Includes tests for handling the box images and creation of domain
volumes. Additionally includes an integration test to ensure a box with
2 disks will work as expected.

Partially fixes: #602
2021-05-08 17:04:10 +01:00
Darragh Bailey
1c82be1357 Raise expected Timeout to ensure retryable retries (#1241)
With the refactor to where the domain addresses are looked up, a log
message was added in case of timeout, however it was missed that when
this occurs still need to raise the exception to ensure that checks for
this timeout can occur within the original calling function.

Update tests to ensure that the code will retry the expected number of
times before triggering the expected failure message and aborting the
machine bring up.

Additionally to allow running the wait_till_up_spec.rb separately,
needed to ensure the plugin.rb which is loaded by the code pulls in the
action.rb to ensure `Action.remove_libvirt_image` can be correctly
resolved when the rest of the test suite is not running.

Fixes: #1239
2021-04-03 14:57:31 +01:00
Dan Čermák
db61946828 Add a simple Proc extension to support bindings (#1240)
This removes the dependency on the contextual_proc gem

Fixes: #1238
2021-04-03 14:41:44 +01:00
Darragh Bailey
a16c3f7898 Move proxy_command to config and support templating (#1226)
Migrate the proxy_command specification to the config and add support
for user override template to be used for edge cases. Moving it to the
config allows mistakes in the interpolation to be caught before the
machine is brought up.

Note this uses a more restrictive replacement to avoid requiring
escaping of '%' or '$'.

Issue #921 already partially resolved thanks to @ElArtista, this
completes the fix by allowing users to override as needed.

Fixes: #921
2021-03-21 15:19:53 +00:00
Darragh Bailey
4548e19be9 Enable ssh connection on keyfile being set (#1225)
Auto enable ssh connections if the ssh keyfile has been explicitly set
and switch a number of settings from being explicitly set until after
attempts to resolve the values have failed in order to allow decisions
to be main on whether to set them based on inferred values only if not
explicitly provided elsewhere.

Add some additional tests and transport modes to expand the coverage of
what is accepted to align as close to what libvirt will accept as
possible.
2021-03-20 16:19:33 +00:00
Darragh Bailey
876e906de0 Improve id_ssh_key_file finalizing (#1230)
Move finalizing the id_ssh_key_file based on how other settings are
currently defined to a separate private function and extend the tests to
accept defining additional expects/allows within the table.

This should apply a consistent set of rules where if the user explicitly
supplies the key, it will attempt to resolve it based on the expected
ssh directory, and will always retain the explicit setting even if it
doesn't exist. Where connect_via_ssh is enabled, it will attempt to
detect if the default key exists, otherwise it will disable the setting.
If the user does not want automatic guesses, they can explicitly disable
by setting it to `nil`.

Fixes: #1228
2021-03-20 15:38:02 +00:00
Darragh Bailey
bbbcdaa44b Only set ssh connection params if transport is ssh (#1224)
Skip setting various additional connection params if the transport for
the libvirt connection is not ssh based as these will be ignored and may
cause confusion as to why they do not apply.
2021-03-17 15:36:09 +00:00
Darragh Bailey
4ee40728b3 Make LIBVIRT_DEFAULT_URI a fackball mechanism (#1223)
Switch to only picking up LIBVIRT_DEFAULT_URI if no settings that could
affect the uri have been explicitly set. Some of these may not actually
appear in the URI depending on what is actually set or not set, however
it is important that should only use the env variable if the user has
not explicitly configured options relevant and instead allow them to
configure as needed.
2021-03-17 14:41:14 +00:00
Darragh Bailey
c8c590f586 Consolidate ip address retreival to single method (#1199)
Refactor WaitTillUp action to make use of the domain IP address
retrieval code in the driver to ensure a single place to maintain.

Remove references to machine option for driver where already should be
available as an instance variable.
2021-03-13 19:55:17 +00:00
Darragh Bailey
e6ae883ec3 Refactor uri config tests (#1219)
Update config tests replacing the multiple sets of tests exercising
aspects of how the uri setting should be constructed with a single table
of tests including some pending tests to describe how the code should
work not just how it currently works.

This should make it easier to identify and describe the correct
behaviour that should occur and then ensure the code in the future
implements the needed changes.
2021-03-13 15:19:41 +00:00
David Scaife
5471caabe5 Add disk driver options with minor refactor (#1000)
Adds disk driver options: io, copy_on_read, discard and detect_zeroes
for both the primary vm disk and additional disks.

Minor refactor of existing volume_cache to deprecate and replace with a
single call to disk_driver that contains all of the options. Usage of
the volume_cache option will now result in a message to ui that it has
been replaced, as well as a warning that it is ignored if disk_driveris
set.

The old option volume_cache is only used if disk_driver is not present
(even if :cache is not set - in that case, the hypervisor default is
always used).

Resolves #998
2020-12-17 11:03:47 +00:00
zzambers
d0787c803d Add support for clock setup (#1047)
This adds support for setting clock offset and timers.

See https://libvirt.org/formatdomain.html#elementsTime for more info.
2020-12-16 19:19:24 +00:00
Edmund Rhudy
a11750cc3b Add support for configuring memballoon-related settings (#1083)
Allow configuration of various memballoon-related settings. It was 
discovered that it may be needed to be able to control the memballoon's 
PCI slot/bus location in order to prevent it from conflicting with 
other explicit PCI location assignments. For example when configuring 
the management network NIC to go to slot 0x05, libvirt would try to put 
the memballoon there as well and resulting in a fatal error.
2020-12-15 17:40:05 +00:00
Jason Tarasovic
1251189145 Add ability to use emulated tpm (#1166)
Qemu has supported tpm 2 and the ability to start swtpm. Additionally 
it expands the tests for the tpm configuration to ensure that only when 
the options cause a change to the domain XML will the domain be updated 
on a subsequent start. This change just allows passing through the 
necessary config.

Vagrant.configure("2") do |config|
  config.vm.provider :libvirt do |libvirt|
    libvirt.tpm_model = "tpm-crb"
    libvirt.tpm_type = "emulator"
    libvirt.tpm_version = "2.0"
  end
end

closes #965
2020-12-15 12:43:46 +00:00
Darragh Bailey
f51192e80b Provide uid/gid for additional volumes qemu:///session (#1170)
When using qemu:///session, it's necessary to ensure the correct
user/group is passed in when creating additional volume storage as
otherwise the default is to attempt to chown/chgrp it to 0:0 which will
fail.

With this in place and recent changes around uri/qemu_use_session,
remove the checks guarding retrieving the storage pool as it is also
possible for it to be created as expected for the session.

Update create domain tests to check for the correct settings such as
storage path and user/group id's passed to the volume create call for
the additional disks.

Fixes: #986
2020-12-05 15:49:25 +00:00
Darragh Bailey
21f7a796ff Reduce start domain unnecessary domain redefines (#1178)
Various checks in the start domain action were accidentally causing a
redefine right after initial create. Update to provide debug output when
the domain needs to be changed to allow capture of the redefines
occurring in the future and to make it easy for the tests to pick up
where the redefine was triggered by setting an expectation on the log
output.

Include a small fix to avoid running strip on what might be a nil object
returned for elements without any text attributes.

Fix a bug where changes to tpm settings made to the config after an
initial domain creation where there was previously no tpm defined, would
be ignored.

Adds a logger double and updates other tests that trigger log calls.

should fix #1176
2020-12-05 15:24:42 +00:00
Darragh Bailey
71503ed62e Rudimentary start domain action spec (#1167)
Add default domain start spec test and fix bug triggered by whitespace
mismatch in string comparison that would trigger unexpected domain
undefine and recreate.
2020-11-15 23:28:43 +00:00
Darragh Bailey
06e31d3918 Add rudimentary create domain spec test (#1158)
Provide a simple create domain test that uncovered a bug with an
exception in addition to fixing the tests to avoid unnecessary output
when the code sends messages via the UI.
2020-10-23 14:31:29 +01:00
Dusty Mabe
41bcae26e4 config: allow for setting URI from environment
Users are allowed to set a LIBVIRT_DEFAULT_URI environment variable that
controls tools (i.e. virsh, virt-install, etc) that communicate with
libvirt. Let's allow for that mechanism to be used here.
2020-08-16 16:37:57 +01:00
Darragh Bailey
d16bdcc1dc Add @uri config tests and minor refactor (#1139)
Test settings modifying the `@uri` and `@qemu_use_session` variables to make
it easier to update and perform an initial minor refactor to reduce some
of the code currently in use to set `@uri`.
2020-08-16 16:27:27 +01:00
Darragh Bailey
74c381a30d Update test syntax to remove stubs (#1138)
Use of stubs are deprecated, switch to the newer expect/allow syntax.
2020-08-16 16:06:05 +01:00
Rui Lopes
19cd1d5629 let the user set the domain title and description 2020-08-12 22:06:05 +01:00
Julio Lajara
f00bc0eaae Add qemu commandline environment variable support. (#961)
Make it easier to tweak some qemu options by allowing passthru of
command line environment variables.

- Also cleans up weird variable indirection used for qemu commandline args
  variable through `qargs` in various constructors.
- Addresses some functionality discussed in #776.
2020-05-10 14:37:31 +01:00
Quinten Johnson
7e966febbd Allow setting of PCI domain (#927) 2020-05-10 11:40:29 +01:00
Quinten Johnson
618c8b251d Allow specification of domain shares (#925)
Weighted priority of the domain relative to others on the host.
2020-05-10 11:24:06 +01:00
Quinten Johnson
d9c5f63410 Allow specification of numa nodeset (#924)
This specifies the physical numa nodes on which the virtual memory can be
placed.
2020-05-10 10:52:46 +01:00
Quinten Johnson
60ef4b03d1 Allow specification of cpuset (#923)
Allows the pinning of vcpus to physical cpus.
2020-04-29 19:08:01 +01:00
Darragh Bailey
c02905be14 Merge pull request #885 from brianjmurrell/patch-1
Don't add _ after user defined default_prefix
2019-02-13 15:24:42 +00:00
David Scaife
019f43d32d USB: Fix redirfilter template test 2018-08-14 20:38:55 +10:00
Brian J. Murrell
2cfec56325 Update unit test for building simple domain name
Make the unit test match the new requirement that if a _ postfix is desired
when default_prefix is defined, then it must be added to the default_prefix.
2018-04-18 10:59:19 -04:00
Antonio Huete Jimenez
6bdff043a7 Allow specifying Hypervisor HyperV features (#870) 2018-03-21 19:00:28 +01:00
David Scaife
60e93d4925 USB controller configuration (#861)
* Add USB controller configuration

* Update README with USB controller configuration info

* Rename USB controller parameter to usb_controller

* Code style fixup
2018-03-18 09:25:01 +01:00
Tamara Herzog
64a076468e QEMU libvirt nvram support
Some UEFI firmwares may want to use a non-volatile memory to store
variables.
This requires to specify loader and nvram to use UEFI boot in QEMU.
Specifying loader and nvram at the same time will set loader to
type 'pflash' instead of 'rom'.
If loader is used without nvram option type will remain 'rom'.

Further information can be found at libvirt documentation:
https://libvirt.org/formatdomain.html#elementsOS
2018-03-02 11:59:14 +01:00