Commit Graph

161 Commits

Author SHA1 Message Date
Darragh Bailey
f8eff3d7a9 Rework destroy domain for multiple box volumes (#1404)
When destroying domains were there are multiple box volumes to be
removed, need to perform a series of checks to establish that the
correct volumes are being removed.

- check if device aliases are in use
- process the box volume removals first
- detect if disks attached outside of vagrant-libvirt
- prefer aliases for additional disks
- avoid use of devices for multiple disks to detect as currently
  assigned incorrectly.
- fallback to detecting number of box volumes to determine
  point at which additional disks start

Attempts to flag a number of cases where behaviour might be incorrect to
help users spot when vagrant-libvirt may accidentally remove something
it shouldn't.
2021-11-21 11:52:45 +00:00
Darragh Bailey
bb267e3910 Derive system URI from default URI (#1398)
To facilitate using session on a remote instance, ensure the system_uri
configuration attribute is by default derived from the default uri
provided or constructed based on other settings, so that it contains any
host and transport settings.
2021-11-08 22:54:45 +00:00
Darragh Bailey
e917a2dbda Switch back to read-only system connection (#1397)
With the rework to use the default connection to retrieve the domain to
allow running of the qemu agent, no longer necessary to use a read
write system connection, and can revert to a read-only connection that
requires less privileges.

This should remove an occurrence of polkit requesting a password when
bringing a VM up using a session connection.

Fixes: #1342
2021-11-08 22:14:47 +00:00
Darragh Bailey
df55c78010 Reorder qemu agent usage for use with sessions (#1396)
Adjust the order of checks around use of qemu sessions to allow use of
the agent as a priority when enabled, which should remove the need to
retrieve the address from the system connection when enabled.

Additionally adjust the call to the agent to ensure it uses the default
connection to retrieve the correct domain, rather than forcing the
system connection, which will fail to find the domain if it was created
via a user session.

Add tests that validate most of this behaviour, as well as resulting in
some minor fixes around downcasing the mac address for comparisons, and
also using instance mocks with rspec instead of pure doubles to help
catch false positives where mocks are allowing calls that done exist.

Related: #1342
2021-11-08 11:31:04 +00:00
Darragh Bailey
0b53be59cf Regression unit test for frozen string literal fix (#1393)
Add a unit test for the prepare nfs settings action to act as a
regression test for the recent fix to avoiding modifying a frozen string
literal.

As part of this fix how the communicator is returned via a call to a
machine for testing purposes and remove an obsolete expect from the
wait till up tests as the code that would result in the communicator
being called has been removed.

Ensure that nfsd is not required to run the tests by mocking out the
host capability check.
2021-11-04 10:55:51 +00:00
Aleksandr Mezin
dcbfea2f49 Add options for 3d acceleration (#1386)
When enabling video_accel3d, as graphics_gl is typically required, will 
by default set it to true unless explicitly set to false.

Enabling these should result in a significant performance improvement 
for any VM where the desktop is being used.

Fixes: #893
Fixes: #1009
2021-10-26 10:11:30 +01:00
Itxaka
b771048f0e Add basic support to control serial console settings (#1385)
Support limited user defined serial console settings to redirect boot
time messages to a log file.

Authored-by: Darragh Bailey <daragh.bailey@gmail.com>
Signed-off-by: Itxaka <igarcia@suse.com>
2021-10-19 14:37:46 +00:00
Darragh Bailey
23a23029a7 Re-upload un-versioned boxes based on modified time (#1382)
If no box version available, use the image modified time as part of the
final path in order to allow replacement anytime the box package is
altered.
2021-10-16 14:49:18 +01:00
Darragh Bailey
5b70a4a669 Ensure ssh_run and ssh actions match vagrant (#1378)
Vagrant expects that providers raise specific errors if the machines are
not available. Update to match the built-in providers.

Fixes: #1376
2021-10-12 09:45:49 +01:00
Darragh Bailey
551c303e41 Rework shutdown domain to avoid trailing action (#1377)
Using the trailing action for ShutdownDomain results in it being
executed as part of the start up sequence in the reload action.

This appears to happen because the halt action is not executed in
isolation from the start action that is scheduled afterwards and
consequently the chaining behaviour spans both instead of being treated
as the combination of two distinct actions that should complete.

While this fixes the issue, it is important that subsequently call such
actions can be done without allowing the out part of the middleware
behaviour to be applied to subsequent actions.

Partial-Fix: #1376
2021-10-11 19:47:40 +01:00
Darragh Bailey
b3e445a8b0 Add aliases for devices (#1374)
It is more reliable to identify disk and network devices by use of
aliases, in addition to being able to establish in the absence of
information the purpose of such devices.

There is a possibility that in some cases this will also resolve issues
where the same device attach issued twice with the same details will
fail due to the second request not appearing to be honoured.

Additionally when destroying domains, may not have the relevant details
on how many disks are provided by the box, for those that support
multiple disks. Being able to traverse the domain XML and destroy the
appropriate volumes based on aliases names will remove the need to have
predictable device identifiers during the destroy and allow for an
improved resolver.

Relates: #1342
2021-10-08 18:00:01 +01:00
Darragh Bailey
56282b965c Provide support for packaging into v2 format (#1360)
Support packaging multi disk machines however default to v1 format
unless v2 format is explicitly enabled. Output a warning to alert users
of the possible change in behaviour in the future.

Allows selecting the format to use via the environment, where use of v1
format with a multi disk machine will ignore the other disks.
2021-10-08 11:05:10 +01:00
Darragh Bailey
81b6fb715a Handle VM not accessible during reboot (#1367)
To support commands requesting a reboot of a VM after execution, the
query of ssh_info needs to avoid triggering an error when the IP address
is not yet retrievable as this indicates the VM would not be reachable.

Wrap the returning of the state in the driver to distinguish between the
following states:
- :running - indicates the machine is available
- :inaccessible - the machine is running but not yet available to
  connect

This is based on the behaviour from the virtualbox provider.

Includes some rudimentary tests to exercise the driver state code.

Closes: #1366
2021-09-30 12:35:30 +00:00
Darragh Bailey
5de17b0d01 Refactor create domain tests (#1364)
Adjust create domain tests to exercise both with a box defined and
undefined. Switch the default vagrantfile definition to have a box
defined as it is the expected behaviour.
2021-09-28 13:17:22 +01:00
Darragh Bailey
605aabcd98 Support provider URI per machine definition (#1363)
Save the variables on the instance to allow for different connection
settings to be specified on a per machine basis.

Provide some rudimentary tests that ensure that the different URIs are
used when constructing connections, and additionally the connection is
created only once, no matter how many times it is subsequently called.

Fixes: #1358
2021-09-27 18:11:29 +01:00
Darragh Bailey
de4721f62e Ensure sensible default USB controller model used (#1362)
When users adding devices either via the pass through or USB redirector
approach, ensure a default controller is added using the xhci stack.
This should work for all versions of USB, where as the previous default
of piix3-uhci appears to only work for some USB 1 controllers.

Fixes: #1346
2021-09-27 16:49:15 +01:00
Darragh Bailey
c3e96d149e Avoid blanking username if set by user (#1352)
While the username may not be used unless the connection is via ssh,
should avoid forcing to nil by accident when re-parsing from the uri.
2021-09-25 10:24:00 +01:00
Darragh Bailey
b49b1991b9 Improve handling of cpu model and initrd settings (#1333)
Avoid triggering a reconfig of the domain when the cpu model and the
initrd haven't been set via the config.
2021-09-11 22:00:33 +01:00
Darragh Bailey
0756362b84 Output XML elements to debug logs (#1345)
Because libvirt may handle updating the XML of components differently
across different versions and user environments, add the generated
contents to the debug log to assist in understanding what is happening
for different users.
2021-09-11 19:29:45 +01:00
Oded Arbel
bc1e6c3a8c added test for nil volume (verified that it fails without the bugfix) 2021-08-19 22:38:12 +03:00
Darragh Bailey
2ae1421421 Ensure shutdown timeout adjusted if graceful halt fails 2021-08-14 00:13:44 +01:00
Chris Roberts
dd6b17ff9a Add coverage on the ShutdownDomain action 2021-08-14 00:12:58 +01:00
Chris Roberts
44d7c5526d Update HaltDomain spec to cover updated implementation 2021-08-14 00:12:58 +01:00
Darragh Bailey
18ebb9d9ed Enable frozen string across project (#1319)
Turn on frozen string support in all files by using a comment to avoid
enabling across dependencies where it may not work.

Fixes: #1177
2021-06-30 13:27:03 +01:00
Darragh Bailey
1174685e7b Basic packaging tests and restructure action (#1307)
Restructure action to remove custom handling around packaging of the
box and instead use more of the built-in provided actions instead.

Includes some packaging tests to cover both simple where the public
key is retained (can't modify the tinycore VM without more complex
provisioning steps), and a more complex one that utilizes a script
and supports triggering regenerating the hosts on subsequent boots.

The use of the upstream packaging helpers means that when the
default insecure ssh key has been replaced, the packaging process
will automatically include the generated key.

Fixes: #759
Fixes: #765
Fixes: #1013
Fixes: #994
2021-06-25 20:01:02 +01:00
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
aa1c8bcb5f Exclude LIBVIRT_DEFAULT_URI from impacting tests (#1283)
Some build environments may have this environment variable set to a
different default value than is expected by the tests. Have rspec delete
it from the environment before starting the test run to ensure that only
the tests that explicitly set it or other config values need expect
different behaviour.

Closes: #1255
2021-05-15 13:54:10 +00: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