Commit Graph

169 Commits

Author SHA1 Message Date
Darragh Bailey
3599fd7600 Ensure explicit setting of inputs respected (#1619)
Make sure that explicit defining of input devices prevents injection of
the default mouse using ps/2 entry.

Fixes: #1092
2022-09-30 17:06:59 +01:00
Darragh Bailey
997fbc7faf Replace 9p synced folder :owner with :access (#1571)
The 9p synced folder option :owner is better named as :access, which is
documented by 9p and less likely to cause confusion on the expected
behaviour as it does not control the owner of the files.

Relates-To: #378
2022-09-28 19:13:41 +00:00
Darragh Bailey
0af8931c36 Facilitate profiling of tests (#1611)
Allow for optional installation of test profilers to help development
identify slow areas needing additional work.
2022-09-28 18:23:25 +00:00
Darragh Bailey
6f2674eec6 Remove need to pass machine and domain around in driver (#1579)
The driver is created with a specific machine instance, use this in
stead of requiring a specific instance be passed in. Apply the same
approach to domain where possible which allows the same get ip address
function to be called with and without a domain being passed in to save
lookup during loops.
2022-09-28 17:40:32 +00:00
Darragh Bailey
c8e3e2c805 Mock out synced folders for action tests (#1610)
Allowing synced folders to be validated as part of the action tests can
cause an excessive amount of time to be consumed due to many calls to
systemd and distro packager to check if nfs is available on the host.
2022-09-28 18:17:18 +01:00
Darragh Bailey
f111842dbe Handle different attribute and element ordering (#1592)
Normalise the XML to ensure the attributes for both documents have the
same ordering to prevent excessive noise when differences are detected.
Additionally sort various elements based on attributes that make
ordering irrelevant to allow for simpler comparison using xmlsimple.

Closes: #1583
2022-09-22 17:14:49 +01:00
Darragh Bailey
aae0ddb37b Update specs to check for warning not being emitted (#1605)
Updating the behaviour to only warn on the XML differing instead of
erroring missed updating the spec tests to replace the check for the
error message with a warn message.
2022-09-22 15:12:16 +00:00
Dan Čermák
33f2a39b3d Spec fixes (#1603)
- the sysprep.sh script was not executable (flagged by rpmlint)
- Need to explicitly `require 'tmpdir'` in `spec_helper.rb` on openSUSE
Tumbleweed,
  otherwise you get tons of failures like:
```
An error occurred while loading ./spec/unit/action/prepare_nfs_settings_spec.rb.
Failure/Error: temp_dir = Dir.mktmpdir("rspec-")

NoMethodError:
  undefined method `mktmpdir' for Dir:Class

    temp_dir = Dir.mktmpdir("rspec-")
                  ^^^^^^^^^
  Did you mean?  mkdir
# ./spec/spec_helper.rb:44:in `block in <top (required)>'
# ./spec/spec_helper.rb:41:in `<top (required)>'
# ./spec/unit/action/prepare_nfs_settings_spec.rb:3:in `require'
# ./spec/unit/action/prepare_nfs_settings_spec.rb:3:in `<top (required)>'
```
2022-09-22 11:35:14 +01:00
Darragh Bailey
7d48c5ec46 Make failure to apply XML domain update non fatal (#1581)
As this is the first time people may be alerted to an issue applying
changes, given that previously they would be silently discarded, better
to switch to warning the end user rather than blocking the domain start.
This is no worse than the previous position, and allows previous
configurations that were understood to be working, to continue to work
as they are, with hopefully issues logged by users that will allow
more correct XML to be sent before making failure to match the changes
applied fatal.
2022-09-07 10:35:25 +00:00
Darragh Bailey
1db6618f76 Remove need to explicitly set VAGRANT_HOME before running tests (#1580)
Ensure that the tests always set VAGRANT_HOME into the environment to
prevent the global plugin manager from trying to load the plugins under
this directory.
2022-09-06 12:30:18 +01:00
Darragh Bailey
316ca8e1d4 Reduce nested rescues in start domain (#1573)
Remove the unnecessary nesting of begin/rescue entries in start domain
which partially existed due to vagrant-libvirt destroying domain
definitions on error, even for machines that had previously been
created.

Since this is no longer a problem as existing domains will be halted
rather than removed when an exception occurs, it is perfectly fine to
let the exception percolate upwards and be handled by the warden, which
is what the current code is doing, but at the expense of catching and
re-raising multiple times.
2022-09-03 16:28:56 +01:00
Darragh Bailey
606b86df67 Return early from set_boot_order if not needed (#1578)
Switch to calling the returning the next middleware in the chain as soon
as possible in the set boot order action. Makes the overall remaining
logic tidier.

Include basic tests to check existing behaviour.
2022-09-03 16:11:11 +01:00
Darragh Bailey
cede7fff8b Ensure XML diff output if not fully applied (#1576)
Make sure to perform a diff of the actual XML strings and not the object
representations if encountering the bug where the XML failed to be
updated correctly.
2022-09-03 15:01:03 +01:00
Darragh Bailey
439830b6d4 Switch to xml-simple for document comparison (#1567)
The switch to compare-xml exhibits non intuitive behaviour in that
comparing without use of verbose mode does not detect documents that are
identical. The if statement allowed the tests to pass but reads that if
the documents compare as true then emit an error message and raise an
exception. However this is because it returns false even with the docs
are the same content. Unfortunately there was no pre-existing test
case added when

Since there were concerns about equivalent-xml not being active upstream
raised by a distribution maintainer, switching back should be avoided.
Attempted use of nokogiri-diff indicated that whitespace changes would
be treated as differences with it being unclear how to easily exclude.

Moving to xml-simple, which although will treat whitespace as
significant and even with NormaliseSpace set to disregard any whitespace
around content elements, it requires walking the returned structure to
remove the empty content attribute that is left behind to allow a direct
comparison between the data structures.

To ensure the XML comparison is validated add a test where libvirt
returns XML that is different to what was requested, and assert that
the expected error is raised, an error message emitted and that the
domain define would be reverted to the previous state if possible.

Relates-To: #1565
Fixes: #1556
2022-08-30 12:47:05 +01:00
Darragh Bailey
fc5598ddb8 Use equivalent-xml to compare xml (#1564)
Using diffy alone is insufficient to spot when the XML returned by
libvirt for the changes applied is equivalent but formatted differently.

When libvirt returns slightly differently formatted XML corresponding to
what changes were actually applied, it can result in an error being
assumed to have happened when the update actually worked as expected.

Equivalent-xml handles detecting XML documents as being identical,
therefore switching to using it instead of diffy should produce more
reliable results, while retaining diffy for better formatted diffs
should an issue occur is useful.

Fixes: #1556
2022-08-28 12:10:46 +01:00
Darragh Bailey
f19478b050 Ensure boot order is preserved unless overridden (#1560)
Add boot_order to the merge function to ensure that provider config
sections will persist the value if defined in earlier blocks. However to
ensure it is possible to override, definitions in latter sections will
replace the earlier definitions, but only if provided.

Fixes: #937
2022-08-25 17:46:33 +00:00
Darragh Bailey
8673fa2791 Ensure usernames with at symbols handled (#1558)
Domain usernames may use '@' as part of the username, which requires
encoding to be able to be used within an URI.
2022-08-24 18:16:14 +01:00
Darragh Bailey
1945754f67 Allow bridges referenced by libvirt networks (#1554)
Permit reference to bridge devices referenced by existing libvirt
networks.

Fixes: #1553
2022-08-22 18:05:04 +01:00
Darragh Bailey
591e151b13 Use libvirt to query host physical devices (#1550)
Request the list of physical devices from libvirt when performing
config validation. This ensures remote instances using bridges will get
the correct list of devices as well as be alerted when the device needed
does not exist.

Fixes issue introduced with #1499
2022-08-17 15:14:25 +01:00
Nils Ballmann
63d265d9ca add sysinfo support (#1500)
For testing certain scenarios with vagrant-libvirt, need in the guest system a
value for the systems serial number in the DMI/SMBIOS system information.
The domain https://libvirt.org/formatdomain.html#smbios-system-information
format of libvirt allows to specify those values.

While adding `-smbios type=1,serial=$serial_value` to the `qemuargs` parameter
of the libvirt provider is already able to achieve this, a dedicated provider config
value adds native support from the `Vagrantfile` layering system. For example,
in the .box included Vagrantfile a random serial number can be enforced by
adding the following:

require 'securerandom'
Vagrant.configure("2") do |config|
  config.vm.provider :libvirt do |libvirt|
    libvirt.dmi_system_serial = SecureRandom.alphanumeric(8).upcase
  end
end

Then in an instance specific Vagrantfile this value can be overwritten by adding:

Vagrant.configure("2") do |config|
  config.vm.provider :libvirt do |libvirt|
    libvirt.dmi_system_serial = "ABCDEFGH"
  end
end

Co-authored-by: Nils Ballmann <nils.ballmann.ext@siemens.com>
Co-authored-by: Darragh Bailey <daragh.bailey@gmail.com>
2022-08-16 17:44:11 +01:00
a1346054
af77b859e3 Trim trailing whitespace 2022-08-08 22:46:07 +00:00
a1346054
fc996b795f Stop mixing tabs and spaces 2022-08-08 22:44:45 +00:00
a1346054
759a851428 Add missing final newline 2022-08-08 22:44:45 +00:00
a1346054
dbd2d3fdce Fix typos 2022-08-08 22:44:45 +00:00
Darragh Bailey
206a9244a8 Simple prepare test for 9p and virtiofs synced_folders (#1529)
Provide basic tests for 9p and virtiofs synced_folder capabilities to
validate prepare behaviour.
2022-07-13 16:36:17 +00:00
Darragh Bailey
c5ed4bd89c Ensure disk controller passed to create domain (#1520)
Previous PR added tests but missed that the disk controller was not
being set correctly in the create domain action by default.

Update config documentation to include option.
2022-06-25 15:48:05 +01:00
Michael Kerrin
37c3330de1 Allow use of virtio-scsi driver for SCSI devices (#692)
For better performance allows enabling the virtio-scsi model on the
scsi controller in VM's.

Additionally supports inferring use of virtio-scsi model from disk
device or bus, and similarly infer the correct values for these
based on device or bus.

Currently one controller per 7 domain volume disks is created, this
follows virt-manager's behaviour, and is assumed a reasonable default.
However note that virtio-scsi should be capable of allowing many more
disks to be assigned per controller than this. It is presumed that the
source of the number 7 is allowing for 8 devices per controller
including the host adapter, which therefore allows for 7. Hardware SCSI
controllers typically supported 16 addressable devices including the
adapter providing for a 15 disk limit. Whether this is necessary is not
yet clear.

Co-authored-by: Darragh Bailey <daragh.bailey@gmail.com>
2022-06-24 19:02:11 +01:00
Darragh Bailey
a4842acf12 Adjust spec to avoid early setting domain volumes (#1518) 2022-06-24 17:02:05 +00:00
Darragh Bailey
b2c3c23962 Tidy up driver code (#1505)
Clean up the driver code to allow it to be close to passing with a
rubocop scan.
2022-06-14 10:53:36 +01:00
Darragh Bailey
41bd20269e Migrate acceptance tests to rspec (#1513)
Move existing tests executed with the help of bats to use rspec directly
combined with tags to filter them out from being executed by default.

This allows for more complex assertions as well as easier debug as the
code supports use of setting 'VAGRANT_SPEC_SKIP_CLEANUP' to prevent the
tests from removing the temporary directory created for home and work
directories.

Extend a number of classes from vagrant-spec to override default
behaviour to allow passing of additional environment variables for
packaging tests, as well as supporting the skip cleanup. Given the use
of after to perform the cleanup, need to vendor the vagrant-spec
acceptance context in order to modify it easily.
2022-06-13 23:43:06 +01:00
Darragh Bailey
66e0fa7dda Ensure box version default of 0 uses mtime (#1512)
If a box is added directly without a version, vagrant will default set
it to 0. When this occurs it is necessary to ensure use of mtime to
distinguish when the disk image in the box was last updated to allow
replacement of the box to trigger a fresh upload.

Fixes: #1382
2022-06-13 10:25:43 +01:00
Darragh Bailey
a792fe0990 Only populate domain_name if not provided (#1509)
Ensure that when no box is defined for a pxe install, that the domain
name is only populated for subsequent boots and if it is already
provided by a create action, skip attempting to retrieve from a
non-existing domain XML.

Fixes: #1508
2022-06-08 19:37:51 +01:00
Darragh Bailey
9885e58c21 Update after hook definition for recent vagrant (#1506)
Vagrant newer than 2.2.11 reworked how the after hook definition
functions requiring it to be called in a different way to ensure it is
possible to hook the box remove action to perform the expected local
action.

Add a compatibility function to ensure that the plugin works with both
mechanisms and some simple tests to ensure that with the unit tests
validated against the older vagrant versions that it confirms the action
will be called as expected.

As part of fixing the call of the remove_libvirt_image action, ensure it
only executes when the box removed is a libvirt one and ignores all
others.

Fixes: #1196
2022-06-05 17:44:10 +01:00
Darragh Bailey
225009a19f Add basic tests for synced folders 9p and virtiofs (#1504)
Basic tests for synced folder capabilities for 9p and virtiofs should
ensure consistent detection of files for coverage across multiple
versions of ruby as some versions pick up these files and others do not.
2022-06-04 14:20:20 +01:00
Darragh Bailey
70866ecbaa Flag when source device for public network does not exist (#1499)
Detect when the device provided for connecting the VM to a public
network via the host does not exist and attempt to provide a useful
error message to give end users a hint of how to correct.

Fixes: #1477
2022-06-03 14:54:37 +01:00
Darragh Bailey
c7bcb50b2b Avoid domain undefine on configuration update (#1496)
Calling undefine on a domain and recreating it can result in some edge
case errors where if the current capabilities of libvirt have been
reduced, it may not be possible to restore the old definition.

Instead switch to calling `domain_define` with the new definition and
check that the resulting libvirt domain definition has been updated in
the expected manner, otherwise report an error to the user.

Fixes: #949
Relates-to: #1329
Relates-to: #1027
Relates-to: #1371
2022-06-03 09:42:28 +00:00
Rodolfo Olivieri
7233c85504 Add support for snapshots (#1456)
Builds on the work started by @randomvariable in #840 addressing the comments
left there.

Fixes: #529

Signed-off-by: Rodolfo Olivieri rodolfo.olivieri3@gmail.com
2022-06-03 09:34:35 +00:00
Darragh Bailey
37597e22f9 Add action to resolve disk settings (#1502)
With multi volume boxes, need to ensure that disk settings such as the
device assigned are resolved dynamically once it has been established
which devices have already been assigned to the box volumes on either
initial creation or subsequent boots.

Otherwise users are forced to always explicitly define the device for
additional storage instead of having it be automatically assigned the
next available device.

Consequently previous changes have broken the ability for machines
with additional storage to be halted and restarted correctly.

Include an integration test that for additional storage checks that the
machine can be stopped and started again.

Fixes: #1490
2022-06-02 19:09:18 +01:00
Darragh Bailey
f498f102e1 Ensure updating loader tag supported (#1494)
The loader tag is required when nvram is being enabled. Ensure it is
marked as a requirement of validation and also support it's
configuration during the start domain action.
2022-05-17 15:03:55 +01:00
Darragh Bailey
e4122f480a Use instance doubles for driver where possible (#1491)
Switch to instance doubles for driver where possible and reduce usage of
allow_any_instance_of.

Additionally replace some incorrect allows with expects to validate
calls are not made.
2022-05-06 19:30:55 +00:00
byonoy-dne
c4fcfee510 Set undefine flags to keep NVRAM (#1329)
Handle enabling and disabling of NVRAM during start domain.

This patch contains latent support for upstream PR fog-libvirt#102 to support destroy
with NVRAM enabled once that is merged.

Fixes #1027.
2022-05-06 12:43:42 +01:00
Dan Čermák
f734a89681 Replace tabs with spaces in domain_all_settings.xml (#1489)
The xml renderer stopped rendering tabs and now uses spaces instead, which made
the test fail.
2022-05-05 09:37:42 +01:00
Jamie Barber
4e515e6f21 Guest PCI address options for passthrough devices (#1481)
When assigning a pci passthrough device, the domain, bus, slot and
function parameters pertain to the host device address. Add guest_
flavours of these to allow setting the address of the device in the
guest as well.

Fixes: #1475
2022-05-04 09:11:50 +00:00
ebaklund
008e910856 Added fix for issue #1472 (#1473)
Avoid crash caused by power management suspension where fog fails to translate domain state pmsuspended.

Changed the driver.state() function so that it does not crash on undefined domain state. Just return nil :unknown instead.

Added unittests and made existing more general.

Closes #1472
2022-04-04 09:58:10 +01:00
Darragh Bailey
55a220f1c8 Pass ssh command for port forwarding using array (#1469)
Switch to the command as an array format when passing the port
forwarding ssh command to spawn to switch to execution of the ssh
process directly instead of being executed by the default shell.

Fixes: #1467
2022-03-22 07:09:18 +00:00
Ruben Kerkhof
b3cf54a946 Fix a few typos in unit test (#1437) 2022-01-17 14:45:24 +00:00
Ruben Kerkhof
a9e0fefa1d Change the default amount of video ram to 16MB (#1435)
Libvirt did already change the current 9216kb
to 16384kb when starting a domain so in practice this is a no-op.

The libvirt default was changed in 2014 in 81ba2298b2
2022-01-17 14:10:23 +00:00
Darragh Bailey
15b110da49 Reduce patching for distro default session use (#1424)
Reduce the patching needed should a distro wish to switch the default
from using the system connection by default to using a session
connection by default.

Should now only require patching the default value and a single test
checking the defaults.
2021-12-11 14:58:59 +00:00
Darragh Bailey
62b98dea0b Cpu mode host-passthrough allows topology and features (#1423)
When cpu mode was set to host-passthrough the template would skip
setting all other settings for the cpu, while it appears from the
documentation that it supports use of feature elements, and testing
confirms that it also supports the topology element.

https://libvirt.org/formatdomain.html#cpu-model-and-topology

Fixes: #975
2021-12-08 19:48:31 +00:00
Darragh Bailey
87ec540994 Rework prevent destroy if provider completed (#1422)
Adjust handling to use a method reference instead of attempting to
update the env value as that only appears to be available to actions
further down the chain and any changes are not visible during recovery
when exercised for real.

By passing a function reference can limit the actions that can be taken
to only allow a single call that will set a flag internal to the clean
up action.

Fixes: #1328
2021-12-04 21:03:53 +00:00