vagrant-libvirt 0.6.3 → 0.8.1
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 +65 -13
- data/lib/vagrant-libvirt/action/cleanup_on_failure.rb +76 -0
- data/lib/vagrant-libvirt/action/create_domain.rb +56 -10
- data/lib/vagrant-libvirt/action/create_network_interfaces.rb +5 -1
- data/lib/vagrant-libvirt/action/create_networks.rb +24 -0
- data/lib/vagrant-libvirt/action/destroy_domain.rb +106 -21
- data/lib/vagrant-libvirt/action/destroy_networks.rb +1 -1
- data/lib/vagrant-libvirt/action/forward_ports.rb +12 -11
- data/lib/vagrant-libvirt/action/prepare_nfs_settings.rb +1 -1
- data/lib/vagrant-libvirt/action/start_domain.rb +36 -0
- data/lib/vagrant-libvirt/action/wait_till_up.rb +6 -32
- data/lib/vagrant-libvirt/action.rb +72 -83
- data/lib/vagrant-libvirt/config.rb +85 -30
- data/lib/vagrant-libvirt/driver.rb +11 -9
- data/lib/vagrant-libvirt/errors.rb +12 -0
- data/lib/vagrant-libvirt/templates/domain.xml.erb +228 -218
- data/lib/vagrant-libvirt/templates/private_network.xml.erb +4 -1
- data/lib/vagrant-libvirt/util/network_util.rb +15 -3
- data/lib/vagrant-libvirt/util/nfs.rb +2 -0
- data/lib/vagrant-libvirt/util/resolvers.rb +80 -0
- data/lib/vagrant-libvirt/version +1 -1
- data/locales/en.yml +17 -0
- data/spec/spec_helper.rb +36 -23
- data/spec/support/libvirt_context.rb +7 -4
- data/spec/support/sharedcontext.rb +1 -1
- data/spec/unit/action/cleanup_on_failure_spec.rb +131 -0
- data/spec/unit/action/create_domain_spec/additional_disks_domain.xml +6 -18
- data/spec/unit/action/create_domain_spec/custom_disk_settings.xml +43 -0
- data/spec/unit/action/create_domain_spec/default_domain.xml +6 -18
- data/spec/unit/action/create_domain_spec/two_disk_settings.xml +49 -0
- data/spec/unit/action/create_domain_spec.rb +51 -7
- data/spec/unit/action/create_domain_volume_spec.rb +5 -3
- data/spec/unit/action/destroy_domain_spec/additional_disks_domain.xml +47 -0
- data/spec/unit/action/destroy_domain_spec/box_multiple_disks.xml +55 -0
- data/spec/unit/action/destroy_domain_spec/box_multiple_disks_and_additional_and_custom_disks.xml +72 -0
- data/spec/unit/action/destroy_domain_spec/box_multiple_disks_and_additional_and_custom_disks_no_aliases.xml +67 -0
- data/spec/unit/action/destroy_domain_spec/box_multiple_disks_and_additional_disks.xml +67 -0
- data/spec/unit/action/destroy_domain_spec/cdrom_domain.xml +48 -0
- data/spec/unit/action/destroy_domain_spec.rb +134 -30
- data/spec/unit/action/forward_ports_spec.rb +10 -2
- data/spec/unit/action/prepare_nfs_settings_spec.rb +59 -0
- data/spec/unit/action/shutdown_domain_spec.rb +1 -1
- data/spec/unit/action/start_domain_spec/clock_timer_rtc.xml +6 -18
- data/spec/unit/action/start_domain_spec/default.xml +6 -18
- data/spec/unit/action/start_domain_spec/default_added_tpm_path.xml +6 -18
- data/spec/unit/action/start_domain_spec/default_added_tpm_version.xml +6 -18
- data/spec/unit/action/start_domain_spec/existing.xml +1 -1
- data/spec/unit/action/wait_till_up_spec.rb +4 -43
- data/spec/unit/action_spec.rb +2 -0
- data/spec/unit/config_spec.rb +133 -26
- data/spec/unit/driver_spec.rb +154 -10
- data/spec/unit/templates/domain_all_settings.xml +56 -77
- data/spec/unit/templates/domain_cpu_mode_passthrough.xml +39 -0
- data/spec/unit/templates/domain_custom_cpu_model.xml +6 -18
- data/spec/unit/templates/domain_defaults.xml +6 -18
- data/spec/unit/templates/domain_spec.rb +39 -13
- data/spec/unit/templates/tpm/version_1.2.xml +6 -18
- data/spec/unit/templates/tpm/version_2.0.xml +6 -18
- data/spec/unit/util/resolvers_spec.rb +116 -0
- metadata +40 -41
@@ -4,6 +4,8 @@ require 'spec_helper'
|
|
4
4
|
require 'support/sharedcontext'
|
5
5
|
require 'support/libvirt_context'
|
6
6
|
|
7
|
+
require 'fog/libvirt/models/compute/volume'
|
8
|
+
|
7
9
|
require 'vagrant-libvirt/action/destroy_domain'
|
8
10
|
require 'vagrant-libvirt/util/byte_number'
|
9
11
|
|
@@ -14,11 +16,9 @@ describe VagrantPlugins::ProviderLibvirt::Action::CreateDomainVolume do
|
|
14
16
|
include_context 'unit'
|
15
17
|
include_context 'libvirt'
|
16
18
|
|
17
|
-
let(:libvirt_domain) { double('libvirt_domain') }
|
18
|
-
let(:libvirt_client) { double('libvirt_client') }
|
19
19
|
let(:volumes) { double('volumes') }
|
20
20
|
let(:all) { double('all') }
|
21
|
-
let(:box_volume) {
|
21
|
+
let(:box_volume) { instance_double(::Fog::Libvirt::Compute::Volume) }
|
22
22
|
|
23
23
|
def read_test_file(name)
|
24
24
|
File.read(File.join(File.dirname(__FILE__), File.basename(__FILE__, '.rb'), name))
|
@@ -35,6 +35,8 @@ describe VagrantPlugins::ProviderLibvirt::Action::CreateDomainVolume do
|
|
35
35
|
allow(box_volume).to receive(:id).and_return(nil)
|
36
36
|
env[:domain_name] = 'test'
|
37
37
|
|
38
|
+
allow(machine.provider_config).to receive(:qemu_use_session).and_return(false)
|
39
|
+
|
38
40
|
allow(logger).to receive(:debug)
|
39
41
|
end
|
40
42
|
|
@@ -0,0 +1,47 @@
|
|
1
|
+
<domain type='kvm' xmlns:qemu='http://libvirt.org/schemas/domain/qemu/1.0'>
|
2
|
+
<name>vagrant-test_default</name>
|
3
|
+
<title></title>
|
4
|
+
<description>Source: /rootpath/Vagrantfile</description>
|
5
|
+
<uuid></uuid>
|
6
|
+
<memory>524288</memory>
|
7
|
+
<vcpu>1</vcpu>
|
8
|
+
<cpu mode='host-model'>
|
9
|
+
<model fallback='allow'></model>
|
10
|
+
</cpu>
|
11
|
+
<os>
|
12
|
+
<type>hvm</type>
|
13
|
+
<kernel></kernel>
|
14
|
+
<initrd></initrd>
|
15
|
+
<cmdline></cmdline>
|
16
|
+
</os>
|
17
|
+
<features>
|
18
|
+
<acpi/>
|
19
|
+
<apic/>
|
20
|
+
<pae/>
|
21
|
+
</features>
|
22
|
+
<clock offset='utc'>
|
23
|
+
</clock>
|
24
|
+
<devices>
|
25
|
+
<disk type='file' device='disk'>
|
26
|
+
<driver name='qemu' type='qcow2' cache='default'/>
|
27
|
+
<source file='/var/lib/libvirt/images/vagrant-test_default.img'/>
|
28
|
+
<target dev='vda' bus='virtio'/>
|
29
|
+
</disk>
|
30
|
+
<disk type='file' device='disk'>
|
31
|
+
<driver name='qemu' type='qcow2' cache='default'/>
|
32
|
+
<source file='/var/lib/libvirt/images/vagrant-test_default-vdb.qcow2'/>
|
33
|
+
<target dev='vdb' bus='virtio'/>
|
34
|
+
</disk>
|
35
|
+
<serial type='pty'>
|
36
|
+
<target port='0'/>
|
37
|
+
</serial>
|
38
|
+
<console type='pty'>
|
39
|
+
<target port='0'/>
|
40
|
+
</console>
|
41
|
+
<input type='mouse' bus='ps2'/>
|
42
|
+
<graphics type='vnc' port='-1' autoport='yes' listen='127.0.0.1' keymap='en-us'/>
|
43
|
+
<video>
|
44
|
+
<model type='cirrus' vram='16384' heads='1'/>
|
45
|
+
</video>
|
46
|
+
</devices>
|
47
|
+
</domain>
|
@@ -0,0 +1,55 @@
|
|
1
|
+
<domain type='kvm' xmlns:qemu='http://libvirt.org/schemas/domain/qemu/1.0'>
|
2
|
+
<name>vagrant-test_default</name>
|
3
|
+
<title></title>
|
4
|
+
<description>Source: /rootpath/Vagrantfile</description>
|
5
|
+
<uuid></uuid>
|
6
|
+
<memory>524288</memory>
|
7
|
+
<vcpu>1</vcpu>
|
8
|
+
<cpu mode='host-model'>
|
9
|
+
<model fallback='allow'></model>
|
10
|
+
</cpu>
|
11
|
+
<os>
|
12
|
+
<type>hvm</type>
|
13
|
+
<kernel></kernel>
|
14
|
+
<initrd></initrd>
|
15
|
+
<cmdline></cmdline>
|
16
|
+
</os>
|
17
|
+
<features>
|
18
|
+
<acpi/>
|
19
|
+
<apic/>
|
20
|
+
<pae/>
|
21
|
+
</features>
|
22
|
+
<clock offset='utc'>
|
23
|
+
</clock>
|
24
|
+
<devices>
|
25
|
+
<disk type='file' device='disk'>
|
26
|
+
<alias name='ua-box-volume-0'/>
|
27
|
+
<driver name='qemu' type='qcow2' cache='default'/>
|
28
|
+
<source file='/var/lib/libvirt/images/vagrant-test_default.img'/>
|
29
|
+
<target dev='vda' bus='virtio'/>
|
30
|
+
</disk>
|
31
|
+
<disk type='file' device='disk'>
|
32
|
+
<alias name='ua-box-volume-1'/>
|
33
|
+
<driver name='qemu' type='qcow2' cache='default'/>
|
34
|
+
<source file='/var/lib/libvirt/images/vagrant-test_default_1.img'/>
|
35
|
+
<target dev='vdb' bus='virtio'/>
|
36
|
+
</disk>
|
37
|
+
<disk type='file' device='disk'>
|
38
|
+
<alias name='ua-box-volume-2'/>
|
39
|
+
<driver name='qemu' type='qcow2' cache='default'/>
|
40
|
+
<source file='/var/lib/libvirt/images/vagrant-test_default_2.img'/>
|
41
|
+
<target dev='vdc' bus='virtio'/>
|
42
|
+
</disk>
|
43
|
+
<serial type='pty'>
|
44
|
+
<target port='0'/>
|
45
|
+
</serial>
|
46
|
+
<console type='pty'>
|
47
|
+
<target port='0'/>
|
48
|
+
</console>
|
49
|
+
<input type='mouse' bus='ps2'/>
|
50
|
+
<graphics type='vnc' port='-1' autoport='yes' listen='127.0.0.1' keymap='en-us'/>
|
51
|
+
<video>
|
52
|
+
<model type='cirrus' vram='16384' heads='1'/>
|
53
|
+
</video>
|
54
|
+
</devices>
|
55
|
+
</domain>
|
data/spec/unit/action/destroy_domain_spec/box_multiple_disks_and_additional_and_custom_disks.xml
ADDED
@@ -0,0 +1,72 @@
|
|
1
|
+
<domain type='kvm' xmlns:qemu='http://libvirt.org/schemas/domain/qemu/1.0'>
|
2
|
+
<name>vagrant-test_default</name>
|
3
|
+
<title></title>
|
4
|
+
<description>Source: /rootpath/Vagrantfile</description>
|
5
|
+
<uuid></uuid>
|
6
|
+
<memory>524288</memory>
|
7
|
+
<vcpu>1</vcpu>
|
8
|
+
<cpu mode='host-model'>
|
9
|
+
<model fallback='allow'></model>
|
10
|
+
</cpu>
|
11
|
+
<os>
|
12
|
+
<type>hvm</type>
|
13
|
+
<kernel></kernel>
|
14
|
+
<initrd></initrd>
|
15
|
+
<cmdline></cmdline>
|
16
|
+
</os>
|
17
|
+
<features>
|
18
|
+
<acpi/>
|
19
|
+
<apic/>
|
20
|
+
<pae/>
|
21
|
+
</features>
|
22
|
+
<clock offset='utc'>
|
23
|
+
</clock>
|
24
|
+
<devices>
|
25
|
+
<disk type='file' device='disk'>
|
26
|
+
<alias name='ua-box-volume-0'/>
|
27
|
+
<driver name='qemu' type='qcow2' cache='default'/>
|
28
|
+
<source file='/var/lib/libvirt/images/vagrant-test_default.img'/>
|
29
|
+
<target dev='vda' bus='virtio'/>
|
30
|
+
</disk>
|
31
|
+
<disk type='file' device='disk'>
|
32
|
+
<alias name='ua-box-volume-1'/>
|
33
|
+
<driver name='qemu' type='qcow2' cache='default'/>
|
34
|
+
<source file='/var/lib/libvirt/images/vagrant-test_default_1.img'/>
|
35
|
+
<target dev='vdb' bus='virtio'/>
|
36
|
+
</disk>
|
37
|
+
<disk type='file' device='disk'>
|
38
|
+
<alias name='ua-box-volume-2'/>
|
39
|
+
<driver name='qemu' type='qcow2' cache='default'/>
|
40
|
+
<source file='/var/lib/libvirt/images/vagrant-test_default_2.img'/>
|
41
|
+
<target dev='vdc' bus='virtio'/>
|
42
|
+
</disk>
|
43
|
+
<disk type='file' device='disk'>
|
44
|
+
<alias name='ua-disk-volume-0'/>
|
45
|
+
<driver name='qemu' type='qcow2' cache='default'/>
|
46
|
+
<source file='/var/lib/libvirt/images/vagrant-test_default-vdd.qcow2'/>
|
47
|
+
<target dev='vdd' bus='virtio'/>
|
48
|
+
</disk>
|
49
|
+
<disk type='file' device='disk'>
|
50
|
+
<alias name='ua-disk-volume-1'/>
|
51
|
+
<driver name='qemu' type='qcow2' cache='default'/>
|
52
|
+
<source file='/var/lib/libvirt/images/vagrant-test_default-vde.qcow2'/>
|
53
|
+
<target dev='vde' bus='virtio'/>
|
54
|
+
</disk>
|
55
|
+
<disk type='file' device='disk'>
|
56
|
+
<driver name='qemu' type='qcow2' cache='default'/>
|
57
|
+
<source file='/var/lib/libvirt/images/vagrant-test_default-vdf.qcow2'/>
|
58
|
+
<target dev='vdf' bus='virtio'/>
|
59
|
+
</disk>
|
60
|
+
<serial type='pty'>
|
61
|
+
<target port='0'/>
|
62
|
+
</serial>
|
63
|
+
<console type='pty'>
|
64
|
+
<target port='0'/>
|
65
|
+
</console>
|
66
|
+
<input type='mouse' bus='ps2'/>
|
67
|
+
<graphics type='vnc' port='-1' autoport='yes' listen='127.0.0.1' keymap='en-us'/>
|
68
|
+
<video>
|
69
|
+
<model type='cirrus' vram='16384' heads='1'/>
|
70
|
+
</video>
|
71
|
+
</devices>
|
72
|
+
</domain>
|
@@ -0,0 +1,67 @@
|
|
1
|
+
<domain type='kvm' xmlns:qemu='http://libvirt.org/schemas/domain/qemu/1.0'>
|
2
|
+
<name>vagrant-test_default</name>
|
3
|
+
<title></title>
|
4
|
+
<description>Source: /rootpath/Vagrantfile</description>
|
5
|
+
<uuid></uuid>
|
6
|
+
<memory>524288</memory>
|
7
|
+
<vcpu>1</vcpu>
|
8
|
+
<cpu mode='host-model'>
|
9
|
+
<model fallback='allow'></model>
|
10
|
+
</cpu>
|
11
|
+
<os>
|
12
|
+
<type>hvm</type>
|
13
|
+
<kernel></kernel>
|
14
|
+
<initrd></initrd>
|
15
|
+
<cmdline></cmdline>
|
16
|
+
</os>
|
17
|
+
<features>
|
18
|
+
<acpi/>
|
19
|
+
<apic/>
|
20
|
+
<pae/>
|
21
|
+
</features>
|
22
|
+
<clock offset='utc'>
|
23
|
+
</clock>
|
24
|
+
<devices>
|
25
|
+
<disk type='file' device='disk'>
|
26
|
+
<driver name='qemu' type='qcow2' cache='default'/>
|
27
|
+
<source file='/var/lib/libvirt/images/vagrant-test_default.img'/>
|
28
|
+
<target dev='vda' bus='virtio'/>
|
29
|
+
</disk>
|
30
|
+
<disk type='file' device='disk'>
|
31
|
+
<driver name='qemu' type='qcow2' cache='default'/>
|
32
|
+
<source file='/var/lib/libvirt/images/vagrant-test_default_1.img'/>
|
33
|
+
<target dev='vdb' bus='virtio'/>
|
34
|
+
</disk>
|
35
|
+
<disk type='file' device='disk'>
|
36
|
+
<driver name='qemu' type='qcow2' cache='default'/>
|
37
|
+
<source file='/var/lib/libvirt/images/vagrant-test_default_2.img'/>
|
38
|
+
<target dev='vdc' bus='virtio'/>
|
39
|
+
</disk>
|
40
|
+
<disk type='file' device='disk'>
|
41
|
+
<driver name='qemu' type='qcow2' cache='default'/>
|
42
|
+
<source file='/var/lib/libvirt/images/vagrant-test_default-vdd.qcow2'/>
|
43
|
+
<target dev='vdd' bus='virtio'/>
|
44
|
+
</disk>
|
45
|
+
<disk type='file' device='disk'>
|
46
|
+
<driver name='qemu' type='qcow2' cache='default'/>
|
47
|
+
<source file='/var/lib/libvirt/images/vagrant-test_default-vde.qcow2'/>
|
48
|
+
<target dev='vde' bus='virtio'/>
|
49
|
+
</disk>
|
50
|
+
<disk type='file' device='disk'>
|
51
|
+
<driver name='qemu' type='qcow2' cache='default'/>
|
52
|
+
<source file='/var/lib/libvirt/images/vagrant-test_default-vdf.qcow2'/>
|
53
|
+
<target dev='vdf' bus='virtio'/>
|
54
|
+
</disk>
|
55
|
+
<serial type='pty'>
|
56
|
+
<target port='0'/>
|
57
|
+
</serial>
|
58
|
+
<console type='pty'>
|
59
|
+
<target port='0'/>
|
60
|
+
</console>
|
61
|
+
<input type='mouse' bus='ps2'/>
|
62
|
+
<graphics type='vnc' port='-1' autoport='yes' listen='127.0.0.1' keymap='en-us'/>
|
63
|
+
<video>
|
64
|
+
<model type='cirrus' vram='16384' heads='1'/>
|
65
|
+
</video>
|
66
|
+
</devices>
|
67
|
+
</domain>
|
@@ -0,0 +1,67 @@
|
|
1
|
+
<domain type='kvm' xmlns:qemu='http://libvirt.org/schemas/domain/qemu/1.0'>
|
2
|
+
<name>vagrant-test_default</name>
|
3
|
+
<title></title>
|
4
|
+
<description>Source: /rootpath/Vagrantfile</description>
|
5
|
+
<uuid></uuid>
|
6
|
+
<memory>524288</memory>
|
7
|
+
<vcpu>1</vcpu>
|
8
|
+
<cpu mode='host-model'>
|
9
|
+
<model fallback='allow'></model>
|
10
|
+
</cpu>
|
11
|
+
<os>
|
12
|
+
<type>hvm</type>
|
13
|
+
<kernel></kernel>
|
14
|
+
<initrd></initrd>
|
15
|
+
<cmdline></cmdline>
|
16
|
+
</os>
|
17
|
+
<features>
|
18
|
+
<acpi/>
|
19
|
+
<apic/>
|
20
|
+
<pae/>
|
21
|
+
</features>
|
22
|
+
<clock offset='utc'>
|
23
|
+
</clock>
|
24
|
+
<devices>
|
25
|
+
<disk type='file' device='disk'>
|
26
|
+
<alias name='ua-box-volume-0'/>
|
27
|
+
<driver name='qemu' type='qcow2' cache='default'/>
|
28
|
+
<source file='/var/lib/libvirt/images/vagrant-test_default.img'/>
|
29
|
+
<target dev='vda' bus='virtio'/>
|
30
|
+
</disk>
|
31
|
+
<disk type='file' device='disk'>
|
32
|
+
<alias name='ua-box-volume-1'/>
|
33
|
+
<driver name='qemu' type='qcow2' cache='default'/>
|
34
|
+
<source file='/var/lib/libvirt/images/vagrant-test_default_1.img'/>
|
35
|
+
<target dev='vdb' bus='virtio'/>
|
36
|
+
</disk>
|
37
|
+
<disk type='file' device='disk'>
|
38
|
+
<alias name='ua-box-volume-2'/>
|
39
|
+
<driver name='qemu' type='qcow2' cache='default'/>
|
40
|
+
<source file='/var/lib/libvirt/images/vagrant-test_default_2.img'/>
|
41
|
+
<target dev='vdc' bus='virtio'/>
|
42
|
+
</disk>
|
43
|
+
<disk type='file' device='disk'>
|
44
|
+
<alias name='ua-disk-volume-0'/>
|
45
|
+
<driver name='qemu' type='qcow2' cache='default'/>
|
46
|
+
<source file='/var/lib/libvirt/images/vagrant-test_default-vdd.qcow2'/>
|
47
|
+
<target dev='vdd' bus='virtio'/>
|
48
|
+
</disk>
|
49
|
+
<disk type='file' device='disk'>
|
50
|
+
<alias name='ua-disk-volume-1'/>
|
51
|
+
<driver name='qemu' type='qcow2' cache='default'/>
|
52
|
+
<source file='/var/lib/libvirt/images/vagrant-test_default-vde.qcow2'/>
|
53
|
+
<target dev='vde' bus='virtio'/>
|
54
|
+
</disk>
|
55
|
+
<serial type='pty'>
|
56
|
+
<target port='0'/>
|
57
|
+
</serial>
|
58
|
+
<console type='pty'>
|
59
|
+
<target port='0'/>
|
60
|
+
</console>
|
61
|
+
<input type='mouse' bus='ps2'/>
|
62
|
+
<graphics type='vnc' port='-1' autoport='yes' listen='127.0.0.1' keymap='en-us'/>
|
63
|
+
<video>
|
64
|
+
<model type='cirrus' vram='16384' heads='1'/>
|
65
|
+
</video>
|
66
|
+
</devices>
|
67
|
+
</domain>
|
@@ -0,0 +1,48 @@
|
|
1
|
+
<domain type='kvm' xmlns:qemu='http://libvirt.org/schemas/domain/qemu/1.0'>
|
2
|
+
<name>vagrant-test_default</name>
|
3
|
+
<title></title>
|
4
|
+
<description>Source: /rootpath/Vagrantfile</description>
|
5
|
+
<uuid></uuid>
|
6
|
+
<memory>524288</memory>
|
7
|
+
<vcpu>1</vcpu>
|
8
|
+
<cpu mode='host-model'>
|
9
|
+
<model fallback='allow'></model>
|
10
|
+
</cpu>
|
11
|
+
<os>
|
12
|
+
<type>hvm</type>
|
13
|
+
<kernel></kernel>
|
14
|
+
<initrd></initrd>
|
15
|
+
<cmdline></cmdline>
|
16
|
+
</os>
|
17
|
+
<features>
|
18
|
+
<acpi/>
|
19
|
+
<apic/>
|
20
|
+
<pae/>
|
21
|
+
</features>
|
22
|
+
<clock offset='utc'>
|
23
|
+
</clock>
|
24
|
+
<devices>
|
25
|
+
<disk type='file' device='disk'>
|
26
|
+
<driver name='qemu' type='qcow2' cache='default'/>
|
27
|
+
<source file='/var/lib/libvirt/images/vagrant-test_default.img'/>
|
28
|
+
<target dev='vda' bus='virtio'/>
|
29
|
+
</disk>
|
30
|
+
<disk type='file' device='cdrom'>
|
31
|
+
<driver name='qemu' type='raw'/>
|
32
|
+
<source file='/home/test/images/os.iso'/>
|
33
|
+
<target dev='hdd' bus='ide'/>
|
34
|
+
<readonly/>
|
35
|
+
</disk>
|
36
|
+
<serial type='pty'>
|
37
|
+
<target port='0'/>
|
38
|
+
</serial>
|
39
|
+
<console type='pty'>
|
40
|
+
<target port='0'/>
|
41
|
+
</console>
|
42
|
+
<input type='mouse' bus='ps2'/>
|
43
|
+
<graphics type='vnc' port='-1' autoport='yes' listen='127.0.0.1' keymap='en-us' />
|
44
|
+
<video>
|
45
|
+
<model type='cirrus' vram='16384' heads='1'/>
|
46
|
+
</video>
|
47
|
+
</devices>
|
48
|
+
</domain>
|
@@ -17,9 +17,12 @@ describe VagrantPlugins::ProviderLibvirt::Action::DestroyDomain do
|
|
17
17
|
let(:libvirt_client) { double('libvirt_client') }
|
18
18
|
let(:servers) { double('servers') }
|
19
19
|
|
20
|
+
let(:domain_xml) { File.read(File.join(File.dirname(__FILE__), File.basename(__FILE__, '.rb'), domain_xml_file)) }
|
21
|
+
|
20
22
|
before do
|
21
23
|
allow(machine.provider).to receive('driver').and_return(driver)
|
22
24
|
allow(driver).to receive(:connection).and_return(connection)
|
25
|
+
allow(logger).to receive(:info)
|
23
26
|
end
|
24
27
|
|
25
28
|
describe '#call' do
|
@@ -27,8 +30,10 @@ describe VagrantPlugins::ProviderLibvirt::Action::DestroyDomain do
|
|
27
30
|
allow(connection).to receive(:client).and_return(libvirt_client)
|
28
31
|
allow(libvirt_client).to receive(:lookup_domain_by_uuid)
|
29
32
|
.and_return(libvirt_domain)
|
33
|
+
allow(libvirt_domain).to receive(:name).and_return('vagrant-test_default')
|
30
34
|
allow(connection).to receive(:servers).and_return(servers)
|
31
35
|
allow(servers).to receive(:get).and_return(domain)
|
36
|
+
|
32
37
|
# always see this at the start of #call
|
33
38
|
expect(ui).to receive(:info).with('Removing domain...')
|
34
39
|
end
|
@@ -39,59 +44,158 @@ describe VagrantPlugins::ProviderLibvirt::Action::DestroyDomain do
|
|
39
44
|
before do
|
40
45
|
allow(libvirt_domain).to receive(:list_snapshots).and_return([])
|
41
46
|
allow(libvirt_domain).to receive(:has_managed_save?).and_return(nil)
|
42
|
-
allow(root_disk).to receive(:name).and_return('
|
47
|
+
allow(root_disk).to receive(:name).and_return('vagrant-test_default.img')
|
43
48
|
end
|
44
49
|
|
45
|
-
context 'when only has root disk' do
|
50
|
+
context 'when box only has one root disk' do
|
46
51
|
it 'calls fog to destroy volumes' do
|
47
52
|
expect(domain).to receive(:destroy).with(destroy_volumes: true)
|
48
53
|
expect(subject.call(env)).to be_nil
|
49
54
|
end
|
50
|
-
end
|
51
55
|
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
config.vm.provider :libvirt do |libvirt|
|
58
|
-
libvirt.storage :file
|
59
|
-
end
|
56
|
+
context 'when has additional disks' do
|
57
|
+
let(:vagrantfile_providerconfig) do
|
58
|
+
<<-EOF
|
59
|
+
libvirt.storage :file
|
60
|
+
EOF
|
60
61
|
end
|
61
|
-
|
62
|
-
|
62
|
+
let(:domain_xml_file) { 'additional_disks_domain.xml' }
|
63
|
+
let(:extra_disk) { double('libvirt_extra_disk') }
|
63
64
|
|
64
|
-
|
65
|
-
|
66
|
-
|
65
|
+
before do
|
66
|
+
allow(extra_disk).to receive(:name).and_return('vagrant-test_default-vdb.qcow2')
|
67
|
+
allow(domain).to receive(:volumes).and_return([root_disk, extra_disk])
|
68
|
+
expect(libvirt_domain).to receive(:xml_desc).and_return(domain_xml)
|
69
|
+
end
|
70
|
+
|
71
|
+
it 'destroys disks individually' do
|
72
|
+
expect(domain).to receive(:destroy).with(destroy_volumes: false)
|
73
|
+
expect(extra_disk).to receive(:destroy) # extra disk remove
|
74
|
+
expect(root_disk).to receive(:destroy) # root disk remove
|
75
|
+
expect(subject.call(env)).to be_nil
|
76
|
+
end
|
67
77
|
end
|
78
|
+
end
|
68
79
|
|
69
|
-
|
70
|
-
|
71
|
-
allow(domain).to receive(:volumes).and_return([extra_disk], [root_disk])
|
80
|
+
context 'when box has multiple disks' do
|
81
|
+
let(:domain_xml_file) { 'box_multiple_disks.xml' }
|
72
82
|
|
73
|
-
|
74
|
-
expect(
|
75
|
-
expect(root_disk).to receive(:destroy) # root disk remove
|
83
|
+
it 'calls fog to destroy volumes' do
|
84
|
+
expect(domain).to receive(:destroy).with(destroy_volumes: true)
|
76
85
|
expect(subject.call(env)).to be_nil
|
77
86
|
end
|
87
|
+
|
88
|
+
context 'when has additional disks' do
|
89
|
+
let(:domain_xml_file) { 'box_multiple_disks_and_additional_disks.xml' }
|
90
|
+
let(:vagrantfile_providerconfig) do
|
91
|
+
<<-EOF
|
92
|
+
libvirt.storage :file
|
93
|
+
libvirt.storage :file
|
94
|
+
EOF
|
95
|
+
end
|
96
|
+
let(:domain_disks) {[
|
97
|
+
[double('box-disk-1'), 'vagrant-test_default.img'],
|
98
|
+
[double('box-disk-2'), 'vagrant-test_default_1.img'],
|
99
|
+
[double('box-disk-3'), 'vagrant-test_default_2.img'],
|
100
|
+
[double('additional-disk-1'), 'vagrant-test_default-vdd.qcow2'],
|
101
|
+
[double('additional-disk-2'), 'vagrant-test_default-vde.qcow2'],
|
102
|
+
]}
|
103
|
+
|
104
|
+
before do
|
105
|
+
allow(libvirt_domain).to receive(:xml_desc).and_return(domain_xml)
|
106
|
+
allow(domain).to receive(:volumes).and_return(domain_disks.map { |a| a.first })
|
107
|
+
end
|
108
|
+
|
109
|
+
it 'destroys disks individually' do
|
110
|
+
domain_disks.each do |disk, name|
|
111
|
+
expect(disk).to receive(:name).and_return(name).at_least(:once)
|
112
|
+
expect(disk).to receive(:destroy)
|
113
|
+
end
|
114
|
+
expect(domain).to receive(:destroy).with(destroy_volumes: false)
|
115
|
+
expect(subject.call(env)).to be_nil
|
116
|
+
end
|
117
|
+
|
118
|
+
context 'when has disks added via custom virsh commands' do
|
119
|
+
let(:domain_xml_file) { 'box_multiple_disks_and_additional_and_custom_disks.xml' }
|
120
|
+
let(:domain_disks) {[
|
121
|
+
[double('box-disk-1'), 'vagrant-test_default.img'],
|
122
|
+
[double('box-disk-2'), 'vagrant-test_default_1.img'],
|
123
|
+
[double('box-disk-3'), 'vagrant-test_default_2.img'],
|
124
|
+
[double('additional-disk-1'), 'vagrant-test_default-vdd.qcow2'],
|
125
|
+
[double('additional-disk-2'), 'vagrant-test_default-vde.qcow2'],
|
126
|
+
[double('custom-disk-1'), 'vagrant-test_default-vdf.qcow2'],
|
127
|
+
]}
|
128
|
+
|
129
|
+
it 'only destroys expected disks' do
|
130
|
+
expect(ui).to receive(:warn).with(/Unexpected number of volumes detected.*/)
|
131
|
+
domain_disks.each do |disk, name|
|
132
|
+
expect(disk).to receive(:name).and_return(name).at_least(:once)
|
133
|
+
next if disk == domain_disks.last.first
|
134
|
+
expect(disk).to receive(:destroy)
|
135
|
+
end
|
136
|
+
expect(domain).to receive(:destroy).with(destroy_volumes: false)
|
137
|
+
expect(subject.call(env)).to be_nil
|
138
|
+
end
|
139
|
+
|
140
|
+
context 'without aliases' do
|
141
|
+
let(:domain_xml_file) { 'box_multiple_disks_and_additional_and_custom_disks_no_aliases.xml' }
|
142
|
+
|
143
|
+
it 'only destroys expected disks' do
|
144
|
+
expect(ui).to receive(:warn).with(/Destroying machine that was originally created without device aliases.*/)
|
145
|
+
expect(ui).to receive(:warn).with(/Unexpected number of volumes detected/)
|
146
|
+
expect(ui).to receive(:warn).with(/box metadata not available to get volume list during destroy, assuming inferred list/)
|
147
|
+
domain_disks.each do |disk, name|
|
148
|
+
expect(disk).to receive(:name).and_return(name).at_least(:once)
|
149
|
+
# ignore box disks 2 and 3 and the last custom disk
|
150
|
+
next if domain_disks.last.first == disk
|
151
|
+
expect(disk).to receive(:destroy)
|
152
|
+
end
|
153
|
+
expect(domain).to receive(:destroy).with(destroy_volumes: false)
|
154
|
+
expect(subject.call(env)).to be_nil
|
155
|
+
end
|
156
|
+
|
157
|
+
context 'with box metadata' do
|
158
|
+
let(:box) { instance_double(::Vagrant::Box) }
|
159
|
+
before do
|
160
|
+
allow(env[:machine]).to receive(:box).and_return(box)
|
161
|
+
allow(box).to receive(:metadata).and_return(Hash[
|
162
|
+
'disks' => [
|
163
|
+
{:name => 'box-disk-1'},
|
164
|
+
{:name => 'box-disk-2'},
|
165
|
+
{:name => 'box-disk-3'},
|
166
|
+
]
|
167
|
+
])
|
168
|
+
end
|
169
|
+
|
170
|
+
it 'only destroys expected disks' do
|
171
|
+
expect(ui).to receive(:warn).with(/Destroying machine that was originally created without device aliases.*/)
|
172
|
+
expect(ui).to receive(:warn).with(/Unexpected number of volumes detected/)
|
173
|
+
domain_disks.each do |disk, name|
|
174
|
+
expect(disk).to receive(:name).and_return(name).at_least(:once)
|
175
|
+
# ignore box disks 2 and 3 and the last custom disk
|
176
|
+
next if domain_disks.last.first == disk
|
177
|
+
expect(disk).to receive(:destroy)
|
178
|
+
end
|
179
|
+
expect(domain).to receive(:destroy).with(destroy_volumes: false)
|
180
|
+
expect(subject.call(env)).to be_nil
|
181
|
+
end
|
182
|
+
end
|
183
|
+
end
|
184
|
+
end
|
185
|
+
end
|
78
186
|
end
|
79
187
|
|
80
188
|
context 'when has CDROMs attached' do
|
81
|
-
let(:
|
189
|
+
let(:vagrantfile_providerconfig) do
|
82
190
|
<<-EOF
|
83
|
-
Vagrant.configure('2') do |config|
|
84
|
-
config.vm.define :test
|
85
|
-
config.vm.provider :libvirt do |libvirt|
|
86
191
|
libvirt.storage :file, :device => :cdrom
|
87
|
-
end
|
88
|
-
end
|
89
192
|
EOF
|
90
193
|
end
|
194
|
+
let(:domain_xml_file) { 'cdrom_domain.xml' }
|
91
195
|
|
92
196
|
it 'uses explicit removal of disks' do
|
93
|
-
|
94
|
-
|
197
|
+
expect(domain).to receive(:volumes).and_return([root_disk, nil])
|
198
|
+
expect(libvirt_domain).to receive(:xml_desc).and_return(domain_xml)
|
95
199
|
|
96
200
|
expect(domain).to_not receive(:destroy).with(destroy_volumes: true)
|
97
201
|
expect(root_disk).to receive(:destroy) # root disk remove
|
@@ -132,7 +132,11 @@ describe VagrantPlugins::ProviderLibvirt::Action::ForwardPorts do
|
|
132
132
|
it 'should spawn ssh to setup forwarding' do
|
133
133
|
expect(env).to receive(:[]).with(:forwarded_ports).and_return([port_options])
|
134
134
|
expect(ui).to receive(:info).with("#{port_options[:guest]} (guest) => #{port_options[:host]} (host) (adapter eth0)")
|
135
|
-
expect(subject).to receive(:spawn)
|
135
|
+
expect(subject).to receive(:spawn) do |*args, **kwargs|
|
136
|
+
pargs = RUBY_VERSION < "2.7" ? args[0...-1] : args
|
137
|
+
expect(pargs).to start_with('ssh', '-o', 'User=vagrant', '-o', 'Port=22')
|
138
|
+
expect(pargs).to end_with('-n', '-L', '*:8080:192.168.1.121:80', '-N', 'localhost')
|
139
|
+
end.and_return(9999)
|
136
140
|
|
137
141
|
expect(subject.forward_ports(env)).to eq([port_options])
|
138
142
|
|
@@ -148,7 +152,11 @@ describe VagrantPlugins::ProviderLibvirt::Action::ForwardPorts do
|
|
148
152
|
expect(ui).to receive(:info).with("#{port_options[:guest]} (guest) => #{port_options[:host]} (host) (adapter eth0)")
|
149
153
|
expect(ui).to receive(:info).with('Requesting sudo for host port(s) <= 1024')
|
150
154
|
expect(subject).to receive(:system).with('sudo -v').and_return(true)
|
151
|
-
expect(subject).to receive(:spawn)
|
155
|
+
expect(subject).to receive(:spawn) do |*args, **kwargs|
|
156
|
+
pargs = RUBY_VERSION < "2.7" ? args[0...-1] : args
|
157
|
+
expect(pargs).to start_with('sudo', 'ssh', '-o', 'User=vagrant', '-o', 'Port=22')
|
158
|
+
expect(pargs).to end_with('-n', '-L', '*:80:192.168.1.121:80', '-N', 'localhost')
|
159
|
+
end.and_return(10000)
|
152
160
|
|
153
161
|
expect(subject.forward_ports(env)).to eq([port_options])
|
154
162
|
|