vagrant-libvirt 0.10.4 → 0.10.7
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 +1 -1
- data/lib/vagrant-libvirt/action/create_domain.rb +2 -0
- data/lib/vagrant-libvirt/action/destroy_domain.rb +4 -5
- data/lib/vagrant-libvirt/action/forward_ports.rb +16 -15
- data/lib/vagrant-libvirt/action/handle_box_image.rb +2 -0
- data/lib/vagrant-libvirt/action/package_domain.rb +1 -0
- data/lib/vagrant-libvirt/action/resolve_disk_settings.rb +2 -5
- data/lib/vagrant-libvirt/action/set_boot_order.rb +44 -42
- data/lib/vagrant-libvirt/action/start_domain.rb +384 -393
- data/lib/vagrant-libvirt/cap/synced_folder_9p.rb +2 -0
- data/lib/vagrant-libvirt/cap/synced_folder_virtiofs.rb +3 -1
- data/lib/vagrant-libvirt/config.rb +1 -2
- data/lib/vagrant-libvirt/errors.rb +4 -0
- data/lib/vagrant-libvirt/util/compat.rb +1 -1
- data/lib/vagrant-libvirt/util/network_util.rb +1 -1
- data/lib/vagrant-libvirt/util/xml.rb +47 -0
- data/lib/vagrant-libvirt/version +1 -1
- data/locales/en.yml +2 -0
- data/spec/spec_helper.rb +13 -6
- data/spec/unit/action/set_boot_order_spec/default.xml +76 -0
- data/spec/unit/action/set_boot_order_spec/explicit_boot_order.xml +77 -0
- data/spec/unit/action/set_boot_order_spec.rb +67 -0
- data/spec/unit/action/start_domain_spec.rb +26 -0
- data/spec/unit/plugin_spec.rb +1 -0
- metadata +92 -85
@@ -5,9 +5,11 @@ require 'ostruct'
|
|
5
5
|
require 'nokogiri'
|
6
6
|
require 'digest/md5'
|
7
7
|
|
8
|
-
require 'vagrant/util/subprocess'
|
9
8
|
require 'vagrant/errors'
|
9
|
+
require 'vagrant/util/subprocess'
|
10
|
+
|
10
11
|
require 'vagrant-libvirt/errors'
|
12
|
+
require 'vagrant-libvirt/util/erb_template'
|
11
13
|
|
12
14
|
module VagrantPlugins
|
13
15
|
module SyncedFolderVirtioFS
|
@@ -896,8 +896,7 @@ module VagrantPlugins
|
|
896
896
|
@initrd = '' if @initrd == UNSET_VALUE
|
897
897
|
@dtb = nil if @dtb == UNSET_VALUE
|
898
898
|
@graphics_type = 'vnc' if @graphics_type == UNSET_VALUE
|
899
|
-
@graphics_autoport =
|
900
|
-
@graphics_autoport = 'no' if @graphics_port != UNSET_VALUE
|
899
|
+
@graphics_autoport = @graphics_port == UNSET_VALUE ? 'yes' : nil
|
901
900
|
if (@graphics_type != 'vnc' && @graphics_type != 'spice') ||
|
902
901
|
@graphics_passwd == UNSET_VALUE
|
903
902
|
@graphics_passwd = nil
|
@@ -178,6 +178,10 @@ module VagrantPlugins
|
|
178
178
|
error_key(:no_domain_error)
|
179
179
|
end
|
180
180
|
|
181
|
+
class DomainStartError < VagrantLibvirtError
|
182
|
+
error_key(:domain_start_error)
|
183
|
+
end
|
184
|
+
|
181
185
|
class AttachDeviceError < VagrantLibvirtError
|
182
186
|
error_key(:attach_device_error)
|
183
187
|
end
|
@@ -11,7 +11,7 @@ module VagrantPlugins
|
|
11
11
|
module Compat
|
12
12
|
def self.action_hook_args(name, action)
|
13
13
|
# handle different number of arguments for action_hook depending on vagrant version
|
14
|
-
if Gem::Version.new(Vagrant::VERSION) >= Gem::Version.new('2.2.
|
14
|
+
if Gem::Version.new(Vagrant::VERSION) >= Gem::Version.new('2.2.6')
|
15
15
|
return name, action
|
16
16
|
end
|
17
17
|
|
@@ -120,7 +120,7 @@ module VagrantPlugins
|
|
120
120
|
logger.debug "In config found network type #{type} options #{original_options}"
|
121
121
|
# Options can be specified in Vagrantfile in short format (:ip => ...),
|
122
122
|
# or provider format # (:libvirt__network_name => ...).
|
123
|
-
# https://github.com/mitchellh/vagrant/blob/
|
123
|
+
# https://github.com/mitchellh/vagrant/blob/main/lib/vagrant/util/scoped_hash_override.rb
|
124
124
|
options = scoped_hash_override(original_options, :libvirt)
|
125
125
|
# store type in options
|
126
126
|
# use default values if not already set
|
@@ -0,0 +1,47 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'xmlsimple'
|
4
|
+
|
5
|
+
module VagrantPlugins
|
6
|
+
module ProviderLibvirt
|
7
|
+
module Util
|
8
|
+
class Xml
|
9
|
+
attr_reader :xml
|
10
|
+
|
11
|
+
def initialize(xmlstr)
|
12
|
+
@xml = compact_content(XmlSimple.xml_in(xmlstr, {'NormaliseSpace' => 2}))
|
13
|
+
end
|
14
|
+
|
15
|
+
def to_str
|
16
|
+
XmlSimple.xml_out(@xml)
|
17
|
+
end
|
18
|
+
|
19
|
+
def ==(other)
|
20
|
+
@xml == other.xml
|
21
|
+
end
|
22
|
+
|
23
|
+
private
|
24
|
+
|
25
|
+
# content elements that are empty are preserved by xml-simple and will result
|
26
|
+
# in the structures being considered different even if functionality the same
|
27
|
+
# strip any empty ones to avoid.
|
28
|
+
def compact_content(node)
|
29
|
+
if node.is_a?(Array)
|
30
|
+
node.map! do |element|
|
31
|
+
compact_content(element)
|
32
|
+
end
|
33
|
+
elsif node.is_a?(Hash)
|
34
|
+
if node['content'] and node['content'].empty?
|
35
|
+
node.delete('content')
|
36
|
+
end
|
37
|
+
node.each do |k, v|
|
38
|
+
node[k] = compact_content(v)
|
39
|
+
end
|
40
|
+
else
|
41
|
+
return node
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
data/lib/vagrant-libvirt/version
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.10.
|
1
|
+
0.10.7
|
data/locales/en.yml
CHANGED
@@ -153,6 +153,8 @@ en:
|
|
153
153
|
Error while downloading volume '%{volume_name}' from storage pool '%{pool_name}': %{error_message}
|
154
154
|
no_domain_error: |-
|
155
155
|
No domain found. %{error_message}
|
156
|
+
domain_start_error: |-
|
157
|
+
Failed to start domain: %{error_message}
|
156
158
|
attach_device_error: |-
|
157
159
|
Error while attaching new device to domain. %{error_message}
|
158
160
|
detach_device_error: |-
|
data/spec/spec_helper.rb
CHANGED
@@ -38,13 +38,12 @@ rescue LoadError
|
|
38
38
|
end
|
39
39
|
end
|
40
40
|
|
41
|
-
|
42
|
-
require 'vagrant-libvirt'
|
43
|
-
require 'vagrant-spec/unit'
|
44
|
-
|
45
|
-
Dir[File.dirname(__FILE__) + '/support/**/*.rb'].each { |f| require f }
|
46
|
-
|
47
41
|
RSpec.configure do |config|
|
42
|
+
# set VAGRANT_HOME before any thing that requires vagrant is loaded to prevent
|
43
|
+
# the global plugin manager from trying to use the default VAGRANT_HOME.
|
44
|
+
temp_dir = Dir.mktmpdir("rspec-")
|
45
|
+
ENV['VAGRANT_HOME'] = temp_dir
|
46
|
+
|
48
47
|
# ensure that setting of LIBVIRT_DEFAULT_URI in the environment is not picked
|
49
48
|
# up directly by tests, instead they must set as needed. Some build envs will
|
50
49
|
# may have it set to 'qemu:///session'.
|
@@ -52,6 +51,10 @@ RSpec.configure do |config|
|
|
52
51
|
ENV.delete('LIBVIRT_DEFAULT_URI')
|
53
52
|
end
|
54
53
|
|
54
|
+
config.after(:suite) do
|
55
|
+
FileUtils.remove_entry temp_dir
|
56
|
+
end
|
57
|
+
|
55
58
|
config.mock_with :rspec do |mocks|
|
56
59
|
mocks.verify_partial_doubles = true
|
57
60
|
end
|
@@ -59,3 +62,7 @@ RSpec.configure do |config|
|
|
59
62
|
# don't run acceptance tests by default
|
60
63
|
config.filter_run_excluding :acceptance => true
|
61
64
|
end
|
65
|
+
|
66
|
+
require 'vagrant-spec/unit'
|
67
|
+
|
68
|
+
Dir[File.dirname(__FILE__) + '/support/**/*.rb'].each { |f| require f }
|
@@ -0,0 +1,76 @@
|
|
1
|
+
<domain type="qemu">
|
2
|
+
<name>vagrant-libvirt_default</name>
|
3
|
+
<uuid>881a931b-0110-4d10-81aa-47a1a19f5726</uuid>
|
4
|
+
<description>Source: /home/test/vagrant-libvirt/Vagrantfile</description>
|
5
|
+
<memory unit="KiB">2097152</memory>
|
6
|
+
<currentMemory unit="KiB">2097152</currentMemory>
|
7
|
+
<vcpu placement="static">2</vcpu>
|
8
|
+
<os>
|
9
|
+
<type arch="x86_64" machine="pc-i440fx-6.0">hvm</type>
|
10
|
+
<boot dev="hd"/>
|
11
|
+
</os>
|
12
|
+
<features>
|
13
|
+
<acpi/>
|
14
|
+
<apic/>
|
15
|
+
<pae/>
|
16
|
+
</features>
|
17
|
+
<cpu mode="host-model" check="partial"/>
|
18
|
+
<clock offset="utc"/>
|
19
|
+
<on_poweroff>destroy</on_poweroff>
|
20
|
+
<on_reboot>restart</on_reboot>
|
21
|
+
<on_crash>destroy</on_crash>
|
22
|
+
<devices>
|
23
|
+
<emulator>/usr/bin/qemu-system-x86_64</emulator>
|
24
|
+
<disk type="file" device="disk">
|
25
|
+
<driver name="qemu" type="qcow2"/>
|
26
|
+
<source file="/var/lib/libvirt/images/vagrant-libvirt_default.img"/>
|
27
|
+
<target dev="vda" bus="virtio"/>
|
28
|
+
<address type="pci" domain="0x0000" bus="0x00" slot="0x03" function="0x0"/>
|
29
|
+
</disk>
|
30
|
+
<disk type="file" device="cdrom">
|
31
|
+
<driver name="qemu" type="raw"/>
|
32
|
+
<source file=""/>
|
33
|
+
<target dev="hda" bus="ide"/>
|
34
|
+
<readonly/>
|
35
|
+
<address type="pci" domain="0x0000" bus="0x00" slot="0x06" function="0x0"/>
|
36
|
+
</disk>
|
37
|
+
<disk type="file" device="cdrom">
|
38
|
+
<driver name="qemu" type="raw"/>
|
39
|
+
<source file=""/>
|
40
|
+
<target dev="hdb" bus="ide"/>
|
41
|
+
<readonly/>
|
42
|
+
<address type="pci" domain="0x0000" bus="0x00" slot="0x07" function="0x0"/>
|
43
|
+
</disk>
|
44
|
+
<controller type="usb" index="0" model="piix3-uhci">
|
45
|
+
<address type="pci" domain="0x0000" bus="0x00" slot="0x01" function="0x2"/>
|
46
|
+
</controller>
|
47
|
+
<controller type="pci" index="0" model="pci-root"/>
|
48
|
+
<interface type="network">
|
49
|
+
<mac address="52:54:00:7d:14:0e"/>
|
50
|
+
<source network="vagrant-libvirt"/>
|
51
|
+
<model type="virtio"/>
|
52
|
+
<address type="pci" domain="0x0000" bus="0x00" slot="0x05" function="0x0"/>
|
53
|
+
</interface>
|
54
|
+
<serial type="pty">
|
55
|
+
<target type="isa-serial" port="0">
|
56
|
+
<model name="isa-serial"/>
|
57
|
+
</target>
|
58
|
+
</serial>
|
59
|
+
<console type="pty">
|
60
|
+
<target type="serial" port="0"/>
|
61
|
+
</console>
|
62
|
+
<input type="mouse" bus="ps2"/>
|
63
|
+
<input type="keyboard" bus="ps2"/>
|
64
|
+
<graphics type="vnc" port="-1" autoport="yes" listen="127.0.0.1" keymap="en-us">
|
65
|
+
<listen type="address" address="127.0.0.1"/>
|
66
|
+
</graphics>
|
67
|
+
<audio id="1" type="none"/>
|
68
|
+
<video>
|
69
|
+
<model type="cirrus" vram="16384" heads="1" primary="yes"/>
|
70
|
+
<address type="pci" domain="0x0000" bus="0x00" slot="0x02" function="0x0"/>
|
71
|
+
</video>
|
72
|
+
<memballoon model="virtio">
|
73
|
+
<address type="pci" domain="0x0000" bus="0x00" slot="0x04" function="0x0"/>
|
74
|
+
</memballoon>
|
75
|
+
</devices>
|
76
|
+
</domain>
|
@@ -0,0 +1,77 @@
|
|
1
|
+
<?xml version="1.0"?>
|
2
|
+
<domain type="qemu">
|
3
|
+
<name>vagrant-libvirt_default</name>
|
4
|
+
<uuid>881a931b-0110-4d10-81aa-47a1a19f5726</uuid>
|
5
|
+
<description>Source: /home/test/vagrant-libvirt/Vagrantfile</description>
|
6
|
+
<memory unit="KiB">2097152</memory>
|
7
|
+
<currentMemory unit="KiB">2097152</currentMemory>
|
8
|
+
<vcpu placement="static">2</vcpu>
|
9
|
+
<os>
|
10
|
+
<type arch="x86_64" machine="pc-i440fx-6.0">hvm</type>
|
11
|
+
|
12
|
+
</os>
|
13
|
+
<features>
|
14
|
+
<acpi/>
|
15
|
+
<apic/>
|
16
|
+
<pae/>
|
17
|
+
</features>
|
18
|
+
<cpu mode="host-model" check="partial"/>
|
19
|
+
<clock offset="utc"/>
|
20
|
+
<on_poweroff>destroy</on_poweroff>
|
21
|
+
<on_reboot>restart</on_reboot>
|
22
|
+
<on_crash>destroy</on_crash>
|
23
|
+
<devices>
|
24
|
+
<emulator>/usr/bin/qemu-system-x86_64</emulator>
|
25
|
+
<disk type="file" device="disk">
|
26
|
+
<driver name="qemu" type="qcow2"/>
|
27
|
+
<source file="/var/lib/libvirt/images/vagrant-libvirt_default.img"/>
|
28
|
+
<target dev="vda" bus="virtio"/>
|
29
|
+
<address type="pci" domain="0x0000" bus="0x00" slot="0x03" function="0x0"/>
|
30
|
+
<boot order="1"/></disk>
|
31
|
+
<disk type="file" device="cdrom">
|
32
|
+
<driver name="qemu" type="raw"/>
|
33
|
+
<source file=""/>
|
34
|
+
<target dev="hda" bus="ide"/>
|
35
|
+
<readonly/>
|
36
|
+
<address type="pci" domain="0x0000" bus="0x00" slot="0x06" function="0x0"/>
|
37
|
+
<boot order="2"/></disk>
|
38
|
+
<disk type="file" device="cdrom">
|
39
|
+
<driver name="qemu" type="raw"/>
|
40
|
+
<source file=""/>
|
41
|
+
<target dev="hdb" bus="ide"/>
|
42
|
+
<readonly/>
|
43
|
+
<address type="pci" domain="0x0000" bus="0x00" slot="0x07" function="0x0"/>
|
44
|
+
<boot order="3"/></disk>
|
45
|
+
<controller type="usb" index="0" model="piix3-uhci">
|
46
|
+
<address type="pci" domain="0x0000" bus="0x00" slot="0x01" function="0x2"/>
|
47
|
+
</controller>
|
48
|
+
<controller type="pci" index="0" model="pci-root"/>
|
49
|
+
<interface type="network">
|
50
|
+
<mac address="52:54:00:7d:14:0e"/>
|
51
|
+
<source network="vagrant-libvirt"/>
|
52
|
+
<model type="virtio"/>
|
53
|
+
<address type="pci" domain="0x0000" bus="0x00" slot="0x05" function="0x0"/>
|
54
|
+
<boot order="4"/></interface>
|
55
|
+
<serial type="pty">
|
56
|
+
<target type="isa-serial" port="0">
|
57
|
+
<model name="isa-serial"/>
|
58
|
+
</target>
|
59
|
+
</serial>
|
60
|
+
<console type="pty">
|
61
|
+
<target type="serial" port="0"/>
|
62
|
+
</console>
|
63
|
+
<input type="mouse" bus="ps2"/>
|
64
|
+
<input type="keyboard" bus="ps2"/>
|
65
|
+
<graphics type="vnc" port="-1" autoport="yes" listen="127.0.0.1" keymap="en-us">
|
66
|
+
<listen type="address" address="127.0.0.1"/>
|
67
|
+
</graphics>
|
68
|
+
<audio id="1" type="none"/>
|
69
|
+
<video>
|
70
|
+
<model type="cirrus" vram="16384" heads="1" primary="yes"/>
|
71
|
+
<address type="pci" domain="0x0000" bus="0x00" slot="0x02" function="0x0"/>
|
72
|
+
</video>
|
73
|
+
<memballoon model="virtio">
|
74
|
+
<address type="pci" domain="0x0000" bus="0x00" slot="0x04" function="0x0"/>
|
75
|
+
</memballoon>
|
76
|
+
</devices>
|
77
|
+
</domain>
|
@@ -0,0 +1,67 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'spec_helper'
|
4
|
+
require 'support/sharedcontext'
|
5
|
+
require 'support/libvirt_context'
|
6
|
+
|
7
|
+
require 'vagrant-libvirt/action/set_boot_order'
|
8
|
+
|
9
|
+
describe VagrantPlugins::ProviderLibvirt::Action::SetBootOrder do
|
10
|
+
subject { described_class.new(app, env) }
|
11
|
+
|
12
|
+
include_context 'unit'
|
13
|
+
include_context 'libvirt'
|
14
|
+
|
15
|
+
#before do
|
16
|
+
# allow(driver).to receive(:created?).and_return(true)
|
17
|
+
#end
|
18
|
+
|
19
|
+
describe '#call' do
|
20
|
+
it 'should return early' do
|
21
|
+
expect(connection).to_not receive(:client)
|
22
|
+
|
23
|
+
expect(subject.call(env)).to be_nil
|
24
|
+
end
|
25
|
+
|
26
|
+
context 'with boot_order defined' do
|
27
|
+
let(:domain_xml) { File.read(File.join(File.dirname(__FILE__), File.basename(__FILE__, '.rb'), test_file)) }
|
28
|
+
let(:updated_domain_xml) { File.read(File.join(File.dirname(__FILE__), File.basename(__FILE__, '.rb'), updated_test_file)) }
|
29
|
+
let(:test_file) { 'default.xml' }
|
30
|
+
let(:updated_test_file) { 'explicit_boot_order.xml' }
|
31
|
+
let(:vagrantfile_providerconfig) do
|
32
|
+
<<-EOF
|
33
|
+
libvirt.boot "hd"
|
34
|
+
libvirt.boot "cdrom"
|
35
|
+
libvirt.boot "network" => 'vagrant-libvirt'
|
36
|
+
EOF
|
37
|
+
end
|
38
|
+
|
39
|
+
before do
|
40
|
+
allow(connection).to receive(:client).and_return(libvirt_client)
|
41
|
+
allow(libvirt_client).to receive(:lookup_domain_by_uuid).and_return(libvirt_domain)
|
42
|
+
allow(libvirt_domain).to receive(:xml_desc).and_return(domain_xml)
|
43
|
+
allow(logger).to receive(:debug)
|
44
|
+
end
|
45
|
+
|
46
|
+
it 'should configure the boot order' do
|
47
|
+
expect(libvirt_client).to receive(:define_domain_xml).with(updated_domain_xml)
|
48
|
+
expect(subject.call(env)).to be_nil
|
49
|
+
end
|
50
|
+
|
51
|
+
context 'with multiple networks in bootorder' do
|
52
|
+
let(:vagrantfile_providerconfig) do
|
53
|
+
<<-EOF
|
54
|
+
libvirt.boot "hd"
|
55
|
+
libvirt.boot "cdrom"
|
56
|
+
libvirt.boot "network" => 'vagrant-libvirt'
|
57
|
+
libvirt.boot "network" => 'vagrant-libvirt'
|
58
|
+
EOF
|
59
|
+
end
|
60
|
+
|
61
|
+
it 'should raise an exception' do
|
62
|
+
expect { subject.call(env) }.to raise_error('Defined only for 1 network for boot')
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|
@@ -72,7 +72,33 @@ describe VagrantPlugins::ProviderLibvirt::Action::StartDomain do
|
|
72
72
|
|
73
73
|
expect(subject.call(env)).to be_nil
|
74
74
|
end
|
75
|
+
end
|
75
76
|
|
77
|
+
context 'when xml not applied' do
|
78
|
+
let(:test_file) { 'default_with_different_formatting.xml' }
|
79
|
+
let(:updated_domain_xml) {
|
80
|
+
new_xml = domain_xml.dup
|
81
|
+
new_xml.gsub!(/<cpu .*<\/cpu>/m, '<cpu mode="host-passthrough"/>')
|
82
|
+
new_xml
|
83
|
+
}
|
84
|
+
let(:vagrantfile_providerconfig) do
|
85
|
+
<<-EOF
|
86
|
+
libvirt.cpu_mode = "host-passthrough"
|
87
|
+
EOF
|
88
|
+
end
|
89
|
+
|
90
|
+
it 'should error and revert the update' do
|
91
|
+
expect(ui).to receive(:warn).with(/\+ <cpu mode="host-passthrough" \/>.*Typically this means there is a bug in the XML being sent, please log an issue/m)
|
92
|
+
expect(connection).to receive(:define_domain).and_return(libvirt_domain)
|
93
|
+
#expect(connection).to receive(:define_domain).with(domain_xml) # undo
|
94
|
+
expect(libvirt_domain).to receive(:xml_desc).and_return(domain_xml, updated_domain_xml)
|
95
|
+
#expect(domain).to_not receive(:start)
|
96
|
+
|
97
|
+
#expect { subject.call(env) }.to raise_error(VagrantPlugins::ProviderLibvirt::Errors::UpdateServerError)
|
98
|
+
expect(libvirt_domain).to receive(:autostart=)
|
99
|
+
expect(domain).to receive(:start)
|
100
|
+
expect(subject.call(env)).to be_nil
|
101
|
+
end
|
76
102
|
end
|
77
103
|
|
78
104
|
context 'when any setting changed' do
|