vagrant-libvirt 0.1.2 → 0.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +530 -100
- data/lib/vagrant-libvirt/action.rb +7 -1
- data/lib/vagrant-libvirt/action/clean_machine_folder.rb +28 -0
- data/lib/vagrant-libvirt/action/create_domain.rb +78 -22
- data/lib/vagrant-libvirt/action/create_domain_volume.rb +57 -57
- data/lib/vagrant-libvirt/action/create_network_interfaces.rb +1 -3
- data/lib/vagrant-libvirt/action/create_networks.rb +11 -4
- data/lib/vagrant-libvirt/action/destroy_domain.rb +1 -1
- data/lib/vagrant-libvirt/action/forward_ports.rb +40 -40
- data/lib/vagrant-libvirt/action/halt_domain.rb +25 -9
- data/lib/vagrant-libvirt/action/handle_box_image.rb +163 -72
- data/lib/vagrant-libvirt/action/is_running.rb +1 -3
- data/lib/vagrant-libvirt/action/is_suspended.rb +4 -4
- data/lib/vagrant-libvirt/action/package_domain.rb +10 -4
- data/lib/vagrant-libvirt/action/start_domain.rb +86 -29
- data/lib/vagrant-libvirt/action/wait_till_up.rb +8 -52
- data/lib/vagrant-libvirt/cap/{mount_p9.rb → mount_9p.rb} +2 -2
- data/lib/vagrant-libvirt/cap/mount_virtiofs.rb +37 -0
- data/lib/vagrant-libvirt/cap/public_address.rb +16 -0
- data/lib/vagrant-libvirt/cap/{synced_folder.rb → synced_folder_9p.rb} +4 -5
- data/lib/vagrant-libvirt/cap/synced_folder_virtiofs.rb +109 -0
- data/lib/vagrant-libvirt/config.rb +257 -34
- data/lib/vagrant-libvirt/driver.rb +49 -32
- data/lib/vagrant-libvirt/errors.rb +24 -1
- data/lib/vagrant-libvirt/plugin.rb +19 -5
- data/lib/vagrant-libvirt/provider.rb +2 -9
- data/lib/vagrant-libvirt/templates/domain.xml.erb +40 -10
- data/lib/vagrant-libvirt/templates/private_network.xml.erb +1 -1
- data/lib/vagrant-libvirt/templates/public_interface.xml.erb +5 -1
- data/lib/vagrant-libvirt/util.rb +1 -0
- data/lib/vagrant-libvirt/util/erb_template.rb +6 -7
- data/lib/vagrant-libvirt/util/network_util.rb +21 -3
- data/lib/vagrant-libvirt/util/ui.rb +23 -0
- data/lib/vagrant-libvirt/version +1 -0
- data/lib/vagrant-libvirt/version.rb +72 -1
- data/locales/en.yml +12 -0
- data/spec/spec_helper.rb +37 -3
- data/spec/support/binding_proc.rb +24 -0
- data/spec/support/libvirt_context.rb +3 -1
- data/spec/support/matchers/have_file_content.rb +63 -0
- data/spec/support/sharedcontext.rb +7 -3
- data/spec/unit/action/clean_machine_folder_spec.rb +48 -0
- data/spec/unit/action/create_domain_spec.rb +166 -0
- data/spec/unit/action/create_domain_spec/default_system_storage_pool.xml +17 -0
- data/spec/unit/action/create_domain_spec/default_user_storage_pool.xml +17 -0
- data/spec/unit/action/create_domain_volume_spec.rb +102 -0
- data/spec/unit/action/create_domain_volume_spec/one_disk_in_storage.xml +21 -0
- data/spec/unit/action/create_domain_volume_spec/three_disks_in_storage_disk_0.xml +21 -0
- data/spec/unit/action/create_domain_volume_spec/three_disks_in_storage_disk_1.xml +21 -0
- data/spec/unit/action/create_domain_volume_spec/three_disks_in_storage_disk_2.xml +21 -0
- data/spec/unit/action/destroy_domain_spec.rb +3 -3
- data/spec/unit/action/forward_ports_spec.rb +202 -0
- data/spec/unit/action/halt_domain_spec.rb +90 -0
- data/spec/unit/action/handle_box_image_spec.rb +363 -0
- data/spec/unit/action/set_name_of_domain_spec.rb +2 -2
- data/spec/unit/action/start_domain_spec.rb +231 -0
- data/spec/unit/action/start_domain_spec/clock_timer_rtc.xml +50 -0
- data/spec/unit/action/start_domain_spec/default.xml +48 -0
- data/spec/unit/action/start_domain_spec/default_added_tpm_path.xml +48 -0
- data/spec/unit/action/start_domain_spec/default_added_tpm_version.xml +48 -0
- data/spec/unit/action/wait_till_up_spec.rb +22 -21
- data/spec/unit/config_spec.rb +438 -0
- data/spec/unit/provider_spec.rb +11 -0
- data/spec/unit/templates/domain_all_settings.xml +16 -3
- data/spec/unit/templates/domain_custom_cpu_model.xml +4 -1
- data/spec/unit/templates/domain_defaults.xml +4 -1
- data/spec/unit/templates/domain_spec.rb +102 -3
- data/spec/unit/templates/tpm/version_1.2.xml +54 -0
- data/spec/unit/templates/tpm/version_2.0.xml +53 -0
- metadata +108 -16
- data/lib/vagrant-libvirt/action/halt_confirm.rb +0 -20
@@ -0,0 +1,23 @@
|
|
1
|
+
|
2
|
+
module VagrantPlugins
|
3
|
+
module ProviderLibvirt
|
4
|
+
module Util
|
5
|
+
module Ui
|
6
|
+
# Since v2.2.8 Vagrant support --no-tty option, which silences
|
7
|
+
# progress bars and other interactive elements for cleaner logs
|
8
|
+
# in scripts, but requires a slight change in UI object handling.
|
9
|
+
# This helper allows the vagrant-libvirt plugin to stay compatible
|
10
|
+
# with the older Vagrant versions.
|
11
|
+
# See: https://github.com/hashicorp/vagrant/pull/11465/
|
12
|
+
def rewriting(ui)
|
13
|
+
if ui.respond_to?(:rewriting)
|
14
|
+
ui.rewriting {|rw| yield rw}
|
15
|
+
else
|
16
|
+
yield ui
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
@@ -0,0 +1 @@
|
|
1
|
+
0.5.0
|
@@ -1,5 +1,76 @@
|
|
1
|
+
require 'open3'
|
2
|
+
require 'tmpdir'
|
3
|
+
|
1
4
|
module VagrantPlugins
|
2
5
|
module ProviderLibvirt
|
3
|
-
|
6
|
+
VERSION_FILE = File.dirname(__FILE__) + "/version"
|
7
|
+
|
8
|
+
GIT_ARCHIVE_VERSION = "$Format:%H %D$"
|
9
|
+
|
10
|
+
HOMEPAGE = 'https://github.com/vagrant-libvirt/vagrant-libvirt'
|
11
|
+
|
12
|
+
def self.get_version
|
13
|
+
if File.exist?(VERSION_FILE)
|
14
|
+
# built gem
|
15
|
+
version = File.read(VERSION_FILE)
|
16
|
+
elsif self.inside_git_repository
|
17
|
+
# local repo
|
18
|
+
git_version = `git describe --tags`
|
19
|
+
version = self.version_from_describe(git_version)
|
20
|
+
elsif !GIT_ARCHIVE_VERSION.start_with?('$Format')
|
21
|
+
# archive - format string replaced during export
|
22
|
+
hash, refs = GIT_ARCHIVE_VERSION.split(' ', 2)
|
23
|
+
|
24
|
+
tag = refs.split(',').select { |ref| ref.strip.start_with?("tag:") }.first
|
25
|
+
if tag != nil
|
26
|
+
# tagged
|
27
|
+
version = tag.strip.split(' ').last
|
28
|
+
else
|
29
|
+
version = ""
|
30
|
+
# arbitrary branch/commit
|
31
|
+
Dir.mktmpdir do |dir|
|
32
|
+
stdout_and_stderr, status = Open3.capture2e("git -C #{dir} clone --bare #{HOMEPAGE}")
|
33
|
+
raise "failed to clone original to resolve version: #{stdout_and_stderr}" unless status.success?
|
34
|
+
|
35
|
+
stdout_and_stderr, status = Open3.capture2e("git --git-dir=#{dir}/vagrant-libvirt.git describe --tags #{hash}")
|
36
|
+
raise "failed to determine version for #{hash}: #{stdout_and_stderr}" unless status.success?
|
37
|
+
|
38
|
+
version = version_from_describe(stdout_and_stderr)
|
39
|
+
end
|
40
|
+
|
41
|
+
# in this case write the version file to avoid cloning a second time
|
42
|
+
File.write(VERSION_FILE, version)
|
43
|
+
end
|
44
|
+
else
|
45
|
+
# no idea
|
46
|
+
version = "9999"
|
47
|
+
end
|
48
|
+
|
49
|
+
return version.freeze
|
50
|
+
end
|
51
|
+
|
52
|
+
def self.write_version
|
53
|
+
File.write(VERSION_FILE, self.get_version)
|
54
|
+
end
|
55
|
+
|
56
|
+
private
|
57
|
+
|
58
|
+
def self.inside_git_repository
|
59
|
+
_, status = Open3.capture2e("git rev-parse --git-dir")
|
60
|
+
|
61
|
+
status.success?
|
62
|
+
end
|
63
|
+
|
64
|
+
def self.version_from_describe(describe)
|
65
|
+
version_parts = describe.split('-').first(2) # drop the git sha if it exists
|
66
|
+
if version_parts.length > 1
|
67
|
+
# increment the patch number so that this is marked as a pre-release of the
|
68
|
+
# next possible release
|
69
|
+
main_version_parts = Gem::Version.new(version_parts[0]).segments
|
70
|
+
main_version_parts[-1] = main_version_parts.last + 1
|
71
|
+
version_parts = main_version_parts + ["pre", version_parts[1]]
|
72
|
+
end
|
73
|
+
version = version_parts.join(".")
|
74
|
+
end
|
4
75
|
end
|
5
76
|
end
|
data/locales/en.yml
CHANGED
@@ -72,6 +72,14 @@ en:
|
|
72
72
|
no_storage_pool: |-
|
73
73
|
No usable storage pool found! Please check if storage pool is
|
74
74
|
created and available.
|
75
|
+
box_format_duplicate_volume: |-
|
76
|
+
Encountered a duplicate volume name '%{volume}' generated for disk '%{new_disk}', due to already allocated for disk '%{orig_disk}'.
|
77
|
+
box_format_missing_attribute: |-
|
78
|
+
Invalid box metadata, missing expected attribute: '%{attribute}'
|
79
|
+
bad_box_image: |-
|
80
|
+
Received error when query the box image details from '%{image}'.
|
81
|
+
Stdout: %{out}
|
82
|
+
Stderr: %{err}
|
75
83
|
no_box_volume: |-
|
76
84
|
Volume for box image is missing in storage pools. Try to run vagrant
|
77
85
|
again, or check if storage volume is accessible.
|
@@ -92,10 +100,14 @@ en:
|
|
92
100
|
Error: %{stderr}
|
93
101
|
no_box_virtual_size: |-
|
94
102
|
No image virtual size specified for box.
|
103
|
+
no_disk_virtual_size: |-
|
104
|
+
No image virtual size specified for disk with index %{disk_index}.
|
95
105
|
no_box_format: |-
|
96
106
|
No image format specified for box.
|
97
107
|
wrong_box_format: |-
|
98
108
|
Wrong image format specified for box.
|
109
|
+
wrong_disk_format: |-
|
110
|
+
Wrong image format specified for disk with index %{disk_index}.
|
99
111
|
fog_libvirt_connection_error: |-
|
100
112
|
Error while connecting to Libvirt: %{error_message}
|
101
113
|
fog_create_volume_error: |-
|
data/spec/spec_helper.rb
CHANGED
@@ -1,9 +1,43 @@
|
|
1
|
-
require '
|
2
|
-
|
1
|
+
require 'simplecov'
|
2
|
+
require 'simplecov-lcov'
|
3
|
+
|
4
|
+
# patch simplecov configuration
|
5
|
+
if ! SimpleCov::Configuration.method_defined? :branch_coverage?
|
6
|
+
module SimpleCov
|
7
|
+
module Configuration
|
8
|
+
def branch_coverage?
|
9
|
+
return false
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
SimpleCov::Formatter::LcovFormatter.config do |config|
|
16
|
+
config.report_with_single_file = true
|
17
|
+
config.single_report_path = 'coverage/lcov.info'
|
18
|
+
end
|
19
|
+
|
20
|
+
SimpleCov.formatters = SimpleCov::Formatter::MultiFormatter.new(
|
21
|
+
[
|
22
|
+
SimpleCov::Formatter::HTMLFormatter,
|
23
|
+
SimpleCov::Formatter::LcovFormatter,
|
24
|
+
]
|
25
|
+
)
|
26
|
+
SimpleCov.start do
|
27
|
+
add_filter 'spec/'
|
28
|
+
end
|
3
29
|
|
4
30
|
require 'vagrant-libvirt'
|
5
31
|
require 'support/environment_helper'
|
6
32
|
require 'vagrant-spec/unit'
|
7
33
|
|
8
|
-
|
34
|
+
Dir[File.dirname(__FILE__) + '/support/**/*.rb'].each { |f| require f }
|
35
|
+
|
36
|
+
RSpec.configure do |config|
|
37
|
+
# ensure that setting of LIBVIRT_DEFAULT_URI in the environment is not picked
|
38
|
+
# up directly by tests, instead they must set as needed. Some build envs will
|
39
|
+
# may have it set to 'qemu:///session'.
|
40
|
+
config.before(:suite) do
|
41
|
+
ENV.delete('LIBVIRT_DEFAULT_URI')
|
42
|
+
end
|
9
43
|
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
##
|
2
|
+
# A simple extension of the Proc class that supports setting a custom binding
|
3
|
+
# and evaluates everything in the Proc using the new binding.
|
4
|
+
|
5
|
+
class ProcWithBinding < Proc
|
6
|
+
##
|
7
|
+
# Set the binding for this instance
|
8
|
+
|
9
|
+
def apply_binding(bind, *args)
|
10
|
+
@binding = bind
|
11
|
+
instance_exec(*args, &self)
|
12
|
+
end
|
13
|
+
|
14
|
+
def method_missing(method, *args)
|
15
|
+
begin
|
16
|
+
method_from_binding = eval("method(#{method.inspect})", @binding)
|
17
|
+
return method_from_binding.call(*args)
|
18
|
+
rescue NameError
|
19
|
+
# fall through on purpose
|
20
|
+
end
|
21
|
+
|
22
|
+
super
|
23
|
+
end
|
24
|
+
end
|
@@ -7,6 +7,7 @@ shared_context 'libvirt' do
|
|
7
7
|
let(:id) { 'dummy-vagrant_dummy' }
|
8
8
|
let(:connection) { double('connection') }
|
9
9
|
let(:domain) { double('domain') }
|
10
|
+
let(:logger) { double('logger') }
|
10
11
|
|
11
12
|
def connection_result(options = {})
|
12
13
|
result = options.fetch(:result, nil)
|
@@ -25,6 +26,7 @@ shared_context 'libvirt' do
|
|
25
26
|
# return some information for domain when needed
|
26
27
|
allow(domain).to receive(:mac).and_return('9C:D5:53:F1:5A:E7')
|
27
28
|
|
28
|
-
machine.
|
29
|
+
allow(machine).to receive(:id).and_return(id)
|
30
|
+
allow(Log4r::Logger).to receive(:new).and_return(logger)
|
29
31
|
end
|
30
32
|
end
|
@@ -0,0 +1,63 @@
|
|
1
|
+
require "rspec/expectations/version"
|
2
|
+
#
|
3
|
+
# Taken from https://github.com/cucumber/aruba/blob/main/lib/aruba/matchers/file/have_file_content.rb
|
4
|
+
# with minor modifications
|
5
|
+
#
|
6
|
+
# @!method have_file_content(content)
|
7
|
+
# This matchers checks if <file> has content. `content` can be a string,
|
8
|
+
# regexp or an RSpec matcher.
|
9
|
+
#
|
10
|
+
# @param [String, Regexp, Matcher] content
|
11
|
+
# Specifies the content of the file
|
12
|
+
#
|
13
|
+
# @return [Boolean] The result
|
14
|
+
#
|
15
|
+
# false:
|
16
|
+
# * if file does not exist
|
17
|
+
# * if file content is not equal string
|
18
|
+
# * if file content does not include regexp
|
19
|
+
# * if file content does not match the content specification
|
20
|
+
#
|
21
|
+
# true:
|
22
|
+
# * if file content includes regexp
|
23
|
+
# * if file content is equal string
|
24
|
+
# * if file content matches the content specification
|
25
|
+
#
|
26
|
+
# @example Use matcher with string
|
27
|
+
#
|
28
|
+
# RSpec.describe do
|
29
|
+
# it { expect(file1).to have_file_content('a') }
|
30
|
+
# end
|
31
|
+
#
|
32
|
+
# @example Use matcher with regexp
|
33
|
+
#
|
34
|
+
# RSpec.describe do
|
35
|
+
# it { expect(file1).to have_file_content(/a/) }
|
36
|
+
# end
|
37
|
+
#
|
38
|
+
# @example Use matcher with an RSpec matcher
|
39
|
+
#
|
40
|
+
# RSpec.describe do
|
41
|
+
# it { expect(file1).to have_file_content(a_string_starting_with 'a') }
|
42
|
+
# it { expect(files1).to include a_file_having_content(a_string_starting_with 'a') }
|
43
|
+
# end
|
44
|
+
RSpec::Matchers.define :have_file_content do |expected|
|
45
|
+
match do |actual|
|
46
|
+
next false unless File.exists?(actual)
|
47
|
+
|
48
|
+
@actual = File.read(actual).chomp
|
49
|
+
@expected = if expected.is_a? String
|
50
|
+
expected.chomp
|
51
|
+
else
|
52
|
+
expected
|
53
|
+
end
|
54
|
+
|
55
|
+
values_match?(@expected, @actual)
|
56
|
+
end
|
57
|
+
|
58
|
+
diffable if expected.is_a? String
|
59
|
+
|
60
|
+
description { "have file content: #{description_of expected}" }
|
61
|
+
end
|
62
|
+
|
63
|
+
RSpec::Matchers.alias_matcher :a_file_having_content, :have_file_content
|
@@ -3,10 +3,14 @@ require 'spec_helper'
|
|
3
3
|
shared_context 'unit' do
|
4
4
|
include_context 'vagrant-unit'
|
5
5
|
|
6
|
+
let(:vagrantfile_providerconfig) { '' }
|
6
7
|
let(:vagrantfile) do
|
7
8
|
<<-EOF
|
8
9
|
Vagrant.configure('2') do |config|
|
9
10
|
config.vm.define :test
|
11
|
+
config.vm.provider :libvirt do |libvirt|
|
12
|
+
#{vagrantfile_providerconfig}
|
13
|
+
end
|
10
14
|
end
|
11
15
|
EOF
|
12
16
|
end
|
@@ -17,7 +21,7 @@ shared_context 'unit' do
|
|
17
21
|
end
|
18
22
|
let(:env) { { env: iso_env, machine: machine, ui: ui, root_path: '/rootpath' } }
|
19
23
|
let(:conf) { Vagrant::Config::V2::DummyConfig.new }
|
20
|
-
let(:ui) { Vagrant::UI::
|
24
|
+
let(:ui) { Vagrant::UI::Silent.new }
|
21
25
|
let(:iso_env) { test_env.create_vagrant_env ui_class: Vagrant::UI::Basic }
|
22
26
|
let(:machine) { iso_env.machine(:test, :libvirt) }
|
23
27
|
# Mock the communicator to prevent SSH commands for being executed.
|
@@ -28,7 +32,7 @@ shared_context 'unit' do
|
|
28
32
|
let(:plugin) { register_plugin }
|
29
33
|
|
30
34
|
before (:each) do
|
31
|
-
machine.
|
32
|
-
machine.
|
35
|
+
allow(machine).to receive(:guest).and_return(guest)
|
36
|
+
allow(machine).to receive(:communicator).and_return(communicator)
|
33
37
|
end
|
34
38
|
end
|
@@ -0,0 +1,48 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'support/sharedcontext'
|
3
|
+
|
4
|
+
require 'vagrant-libvirt/action/clean_machine_folder'
|
5
|
+
|
6
|
+
describe VagrantPlugins::ProviderLibvirt::Action::CleanMachineFolder do
|
7
|
+
subject { described_class.new(app, env) }
|
8
|
+
|
9
|
+
include_context 'unit'
|
10
|
+
|
11
|
+
describe '#call' do
|
12
|
+
context 'with default options' do
|
13
|
+
it 'should verbosely remove the folder' do
|
14
|
+
expect(ui).to receive(:info).with('Deleting the machine folder')
|
15
|
+
expect(FileUtils).to receive(:rm_rf).with(machine.data_dir, {:secure => true})
|
16
|
+
|
17
|
+
expect(subject.call(env)).to be_nil
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
context 'when the data dir doesn\'t exist' do
|
22
|
+
before do
|
23
|
+
Dir.mktmpdir do |d|
|
24
|
+
# returns a temporary directory that has been already deleted when running
|
25
|
+
expect(machine).to receive(:data_dir).and_return(d.to_s).exactly(2).times
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
it 'should remove the folder' do
|
30
|
+
expect(ui).to receive(:info).with('Deleting the machine folder')
|
31
|
+
expect(FileUtils).to receive(:rm_rf).with(machine.data_dir, {:secure => true})
|
32
|
+
|
33
|
+
expect(subject.call(env)).to be_nil
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
context 'with quiet option enabled' do
|
38
|
+
subject { described_class.new(app, env, {:quiet => true}) }
|
39
|
+
|
40
|
+
it 'should quietly remove the folder' do
|
41
|
+
expect(ui).to_not receive(:info).with('Deleting the machine folder')
|
42
|
+
expect(FileUtils).to receive(:rm_rf).with(machine.data_dir, {:secure => true})
|
43
|
+
|
44
|
+
expect(subject.call(env)).to be_nil
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
@@ -0,0 +1,166 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'support/sharedcontext'
|
3
|
+
require 'support/libvirt_context'
|
4
|
+
|
5
|
+
require 'vagrant-libvirt/errors'
|
6
|
+
require 'vagrant-libvirt/action/create_domain'
|
7
|
+
|
8
|
+
describe VagrantPlugins::ProviderLibvirt::Action::CreateDomain do
|
9
|
+
subject { described_class.new(app, env) }
|
10
|
+
|
11
|
+
include_context 'unit'
|
12
|
+
include_context 'libvirt'
|
13
|
+
|
14
|
+
let(:libvirt_client) { double('libvirt_client') }
|
15
|
+
let(:servers) { double('servers') }
|
16
|
+
let(:volumes) { double('volumes') }
|
17
|
+
|
18
|
+
let(:storage_pool_xml) { File.read(File.join(File.dirname(__FILE__), File.basename(__FILE__, '.rb'), test_file)) }
|
19
|
+
let(:libvirt_storage_pool) { double('storage_pool') }
|
20
|
+
|
21
|
+
describe '#call' do
|
22
|
+
before do
|
23
|
+
allow_any_instance_of(VagrantPlugins::ProviderLibvirt::Driver)
|
24
|
+
.to receive(:connection).and_return(connection)
|
25
|
+
allow(connection).to receive(:client).and_return(libvirt_client)
|
26
|
+
|
27
|
+
allow(connection).to receive(:servers).and_return(servers)
|
28
|
+
allow(connection).to receive(:volumes).and_return(volumes)
|
29
|
+
|
30
|
+
allow(logger).to receive(:info)
|
31
|
+
|
32
|
+
env[:domain_name] = "vagrant-test_default"
|
33
|
+
|
34
|
+
env[:box_volumes] = []
|
35
|
+
env[:box_volumes].push({
|
36
|
+
:path=>"/test/box.img",
|
37
|
+
:name=>"test_vagrant_box_image_1.1.1_0.img",
|
38
|
+
:virtual_size=>5
|
39
|
+
})
|
40
|
+
# should be ignored for system session and used for user session
|
41
|
+
allow(Process).to receive(:uid).and_return(9999)
|
42
|
+
allow(Process).to receive(:gid).and_return(9999)
|
43
|
+
end
|
44
|
+
|
45
|
+
context 'connection => qemu:///system' do
|
46
|
+
context 'default pool' do
|
47
|
+
let(:test_file) { 'default_system_storage_pool.xml' }
|
48
|
+
|
49
|
+
it 'should execute correctly' do
|
50
|
+
expect(libvirt_client).to receive(:lookup_storage_pool_by_name).and_return(libvirt_storage_pool)
|
51
|
+
expect(libvirt_storage_pool).to receive(:xml_desc).and_return(storage_pool_xml)
|
52
|
+
expect(servers).to receive(:create).and_return(machine)
|
53
|
+
expect(volumes).to_not receive(:create) # additional disks only
|
54
|
+
|
55
|
+
expect(subject.call(env)).to be_nil
|
56
|
+
end
|
57
|
+
|
58
|
+
context 'additional disks' do
|
59
|
+
let(:vagrantfile) do
|
60
|
+
<<-EOF
|
61
|
+
Vagrant.configure('2') do |config|
|
62
|
+
config.vm.define :test
|
63
|
+
config.vm.provider :libvirt do |libvirt|
|
64
|
+
libvirt.storage :file, :size => '20G'
|
65
|
+
end
|
66
|
+
end
|
67
|
+
EOF
|
68
|
+
end
|
69
|
+
|
70
|
+
context 'volume create failed' do
|
71
|
+
it 'should raise an exception' do
|
72
|
+
expect(libvirt_client).to receive(:lookup_storage_pool_by_name).and_return(libvirt_storage_pool)
|
73
|
+
expect(libvirt_storage_pool).to receive(:xml_desc).and_return(storage_pool_xml)
|
74
|
+
expect(volumes).to receive(:create).and_raise(Libvirt::Error)
|
75
|
+
|
76
|
+
expect{ subject.call(env) }.to raise_error(VagrantPlugins::ProviderLibvirt::Errors::FogCreateDomainVolumeError)
|
77
|
+
end
|
78
|
+
end
|
79
|
+
|
80
|
+
context 'volume create succeeded' do
|
81
|
+
it 'should complete' do
|
82
|
+
expect(libvirt_client).to receive(:lookup_storage_pool_by_name).and_return(libvirt_storage_pool)
|
83
|
+
expect(libvirt_storage_pool).to receive(:xml_desc).and_return(storage_pool_xml)
|
84
|
+
expect(volumes).to receive(:create).with(
|
85
|
+
hash_including(
|
86
|
+
:path => "/var/lib/libvirt/images/vagrant-test_default-vdb.qcow2",
|
87
|
+
:owner => 0,
|
88
|
+
:group => 0,
|
89
|
+
:pool_name => "default",
|
90
|
+
)
|
91
|
+
)
|
92
|
+
expect(servers).to receive(:create).and_return(machine)
|
93
|
+
|
94
|
+
expect(subject.call(env)).to be_nil
|
95
|
+
end
|
96
|
+
end
|
97
|
+
end
|
98
|
+
end
|
99
|
+
|
100
|
+
context 'no default pool' do
|
101
|
+
it 'should raise an exception' do
|
102
|
+
expect(libvirt_client).to receive(:lookup_storage_pool_by_name).and_return(nil)
|
103
|
+
|
104
|
+
expect{ subject.call(env) }.to raise_error(VagrantPlugins::ProviderLibvirt::Errors::NoStoragePool)
|
105
|
+
end
|
106
|
+
end
|
107
|
+
end
|
108
|
+
|
109
|
+
context 'connection => qemu:///session' do
|
110
|
+
let(:vagrantfile) do
|
111
|
+
<<-EOF
|
112
|
+
Vagrant.configure('2') do |config|
|
113
|
+
config.vm.define :test
|
114
|
+
config.vm.provider :libvirt do |libvirt|
|
115
|
+
libvirt.qemu_use_session = true
|
116
|
+
end
|
117
|
+
end
|
118
|
+
EOF
|
119
|
+
end
|
120
|
+
|
121
|
+
context 'default pool' do
|
122
|
+
let(:test_file) { 'default_user_storage_pool.xml' }
|
123
|
+
|
124
|
+
it 'should execute correctly' do
|
125
|
+
expect(libvirt_client).to receive(:lookup_storage_pool_by_name).and_return(libvirt_storage_pool)
|
126
|
+
expect(libvirt_storage_pool).to receive(:xml_desc).and_return(storage_pool_xml)
|
127
|
+
expect(servers).to receive(:create).and_return(machine)
|
128
|
+
|
129
|
+
expect(subject.call(env)).to be_nil
|
130
|
+
end
|
131
|
+
|
132
|
+
context 'additional disks' do
|
133
|
+
let(:vagrantfile) do
|
134
|
+
<<-EOF
|
135
|
+
Vagrant.configure('2') do |config|
|
136
|
+
config.vm.define :test
|
137
|
+
config.vm.provider :libvirt do |libvirt|
|
138
|
+
libvirt.qemu_use_session = true
|
139
|
+
libvirt.storage :file, :size => '20G'
|
140
|
+
end
|
141
|
+
end
|
142
|
+
EOF
|
143
|
+
end
|
144
|
+
|
145
|
+
context 'volume create succeeded' do
|
146
|
+
it 'should complete' do
|
147
|
+
expect(libvirt_client).to receive(:lookup_storage_pool_by_name).and_return(libvirt_storage_pool)
|
148
|
+
expect(libvirt_storage_pool).to receive(:xml_desc).and_return(storage_pool_xml)
|
149
|
+
expect(volumes).to receive(:create).with(
|
150
|
+
hash_including(
|
151
|
+
:path => "/var/lib/libvirt/images/vagrant-test_default-vdb.qcow2",
|
152
|
+
:owner => 9999,
|
153
|
+
:group => 9999,
|
154
|
+
:pool_name => "default",
|
155
|
+
)
|
156
|
+
)
|
157
|
+
expect(servers).to receive(:create).and_return(machine)
|
158
|
+
|
159
|
+
expect(subject.call(env)).to be_nil
|
160
|
+
end
|
161
|
+
end
|
162
|
+
end
|
163
|
+
end
|
164
|
+
end
|
165
|
+
end
|
166
|
+
end
|