Vagrant provider for libvirt.
Go to file
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
.github Fix github context reference in workflow (#1548) 2022-08-17 12:23:19 +01:00
docs Ensure boot order is preserved unless overridden (#1560) 2022-08-25 17:46:33 +00:00
example_box Trim trailing whitespace 2022-08-08 22:46:07 +00:00
lib Switch to xml-simple for document comparison (#1567) 2022-08-30 12:47:05 +01:00
locales Trim trailing whitespace 2022-08-08 22:46:07 +00:00
spec Switch to xml-simple for document comparison (#1567) 2022-08-30 12:47:05 +01:00
tools Properly quote variable 2022-08-08 22:44:44 +00:00
.coveralls.yml Switch from travis to github actions for unit tests (#1206) 2021-02-20 15:23:16 +00:00
.dockerignore Ignore dockerfile changes by default (#1503) 2022-06-04 13:28:06 +00:00
.gitattributes Support building from git-archive tarballs (#1187) 2020-12-14 18:49:50 +00:00
.gitignore Migrate documentation to github pages (#1523) 2022-07-19 13:48:02 +00:00
.ruby-gemset Provide ruby version and gemset config for rvm (#1511) 2022-06-09 06:19:04 +00:00
.ruby-version Provide ruby version and gemset config for rvm (#1511) 2022-06-09 06:19:04 +00:00
Dockerfile vagrant 2.2.19 (#1399) 2021-11-16 13:01:07 +00:00
entrypoint.sh Protect against $VAGRANT_HOME containing a space 2022-08-08 22:44:41 +00:00
Gemfile Fix typos 2022-08-08 22:44:45 +00:00
LICENSE Initial commit 2013-03-27 00:55:30 +01:00
Rakefile Enable frozen string across project (#1319) 2021-06-30 13:27:03 +01:00
README.md Update URL for logo display in README (#1559) 2022-08-25 15:59:25 +00:00
vagrant-libvirt.gemspec Switch to xml-simple for document comparison (#1567) 2022-08-30 12:47:05 +01:00

Vagrant Libvirt Provider

Vagrant Libvirt Logo

Join the chat at https://gitter.im/vagrant-libvirt/vagrant-libvirt Build Status Coverage Status Gem Version

This is a Vagrant plugin that adds a Libvirt provider to Vagrant, allowing Vagrant to control and provision machines via Libvirt toolkit.

Note: Actual version is still a development one. Feedback is welcome and can help a lot :-)

Vagrant-libvirt Documentation is published at https://vagrant-libvirt.github.io/vagrant-libvirt/

Index

Installing

Installation typically involves a number of distribution package dependencies to ensure that Libvirt is available. Recommend that you follow the installation guide.

Running

Once installed, use vagrant-libvirt through vagrant.

Locate a vagrant box containing the distribution you want to use at Vagrant Cloud and initialize.

vagrant init fedora/32-cloud-base

Then run following command:

vagrant up --provider=libvirt

Vagrant needs to know that we want to use Libvirt and not default VirtualBox. That's why there is --provider=libvirt option specified. Other way to tell Vagrant to use Libvirt provider is to setup environment variable

export VAGRANT_DEFAULT_PROVIDER=libvirt

Afterwards to enter the VM simply use:

vagrant ssh

If you can't find a box that works as you need, have a look at our documentation on creating boxes on how to take existing ones, customize them and repackage.

Development

To work on the vagrant-libvirt plugin, clone this repository out, and use Bundler to get the dependencies:

git clone https://github.com/vagrant-libvirt/vagrant-libvirt.git
cd vagrant-libvirt
bundle install

Once you have the dependencies, verify the unit tests pass with rspec:

export VAGRANT_HOME=$(mktemp -d)
bundle exec rspec --fail-fast --color --format documentation

If those pass, you're ready to start developing the plugin.

Setting VAGRANT_HOME is to avoid issues with conflicting with other plugins/gems or data already present under ~/.vagrant.d.

Additionally if you wish to test against a specific version of vagrant you can control the version using the following before running the tests:

export VAGRANT_VERSION=v2.2.14
bundle update && bundle exec rspec --fail-fast --color --format documentation

Note rvm is used by the maintainers to help provide an environment to test against multiple ruby versions that align with the ones used by vagrant for their embedded ruby depending on the release. You can see what version is used by looking at the current unit tests workflow. By default if you have rvm installed and enabled it this project looks to use ruby 2.6.6 and configures a separate gemset, both of which will be switched to each time you enter the project directory.

You can test the plugin without installing it into your Vagrant environment by just creating a Vagrantfile in the top level of this directory (it is gitignored) that uses it. You can add the following line to your Vagrantfile while in development to ensure vagrant checks that the plugin is installed:

Vagrant.configure("2") do |config|
  config.vagrant.plugins = "vagrant-libvirt"
end

Or add the following to the top of the file to ensure that any required plugins are installed globally:

REQUIRED_PLUGINS = %w(vagrant-libvirt)
exit unless REQUIRED_PLUGINS.all? do |plugin|
  Vagrant.has_plugin?(plugin) || (
    puts "The #{plugin} plugin is required. Please install it with:"
    puts "$ vagrant plugin install #{plugin}"
    false
  )
end

Now you can use bundler to execute Vagrant:

$ bundle exec vagrant up --provider=libvirt

IMPORTANT NOTE: bundle is crucial. You need to use bundled Vagrant.

Contributing

contributions welcome

  1. Fork it
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Add some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create new Pull Request

For future work take a look at open issues.