vagrant-libvirt 0.0.43 → 0.3.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 +5 -5
- data/README.md +434 -150
- data/lib/vagrant-libvirt/action.rb +2 -2
- data/lib/vagrant-libvirt/action/create_domain.rb +103 -38
- data/lib/vagrant-libvirt/action/create_domain_volume.rb +19 -14
- data/lib/vagrant-libvirt/action/create_network_interfaces.rb +10 -5
- data/lib/vagrant-libvirt/action/create_networks.rb +7 -2
- data/lib/vagrant-libvirt/action/destroy_domain.rb +1 -1
- data/lib/vagrant-libvirt/action/destroy_networks.rb +5 -0
- data/lib/vagrant-libvirt/action/forward_ports.rb +9 -7
- data/lib/vagrant-libvirt/action/halt_domain.rb +1 -1
- data/lib/vagrant-libvirt/action/handle_box_image.rb +32 -18
- data/lib/vagrant-libvirt/action/handle_storage_pool.rb +9 -4
- data/lib/vagrant-libvirt/action/package_domain.rb +63 -12
- data/lib/vagrant-libvirt/action/prepare_nfs_settings.rb +3 -9
- data/lib/vagrant-libvirt/action/prune_nfs_exports.rb +19 -9
- data/lib/vagrant-libvirt/action/remove_libvirt_image.rb +2 -2
- data/lib/vagrant-libvirt/action/remove_stale_volume.rb +17 -11
- data/lib/vagrant-libvirt/action/set_boot_order.rb +2 -2
- data/lib/vagrant-libvirt/action/set_name_of_domain.rb +6 -9
- data/lib/vagrant-libvirt/action/start_domain.rb +3 -3
- data/lib/vagrant-libvirt/action/wait_till_up.rb +31 -16
- data/lib/vagrant-libvirt/cap/public_address.rb +16 -0
- data/lib/vagrant-libvirt/cap/synced_folder.rb +3 -3
- data/lib/vagrant-libvirt/config.rb +178 -29
- data/lib/vagrant-libvirt/driver.rb +31 -2
- data/lib/vagrant-libvirt/errors.rb +5 -1
- data/lib/vagrant-libvirt/plugin.rb +7 -2
- data/lib/vagrant-libvirt/templates/default_storage_pool.xml.erb +3 -3
- data/lib/vagrant-libvirt/templates/domain.xml.erb +48 -8
- data/lib/vagrant-libvirt/templates/public_interface.xml.erb +5 -1
- data/lib/vagrant-libvirt/util.rb +2 -0
- data/lib/vagrant-libvirt/util/erb_template.rb +6 -7
- data/lib/vagrant-libvirt/util/network_util.rb +33 -13
- data/lib/vagrant-libvirt/util/nfs.rb +17 -0
- data/lib/vagrant-libvirt/util/storage_util.rb +27 -0
- data/lib/vagrant-libvirt/util/ui.rb +23 -0
- data/lib/vagrant-libvirt/version +1 -0
- data/lib/vagrant-libvirt/version.rb +24 -1
- data/locales/en.yml +8 -4
- data/spec/support/environment_helper.rb +1 -1
- data/spec/support/libvirt_context.rb +1 -1
- data/spec/support/sharedcontext.rb +3 -3
- data/spec/unit/action/create_domain_spec.rb +85 -0
- data/spec/unit/action/create_domain_spec/default_storage_pool.xml +17 -0
- data/spec/unit/action/destroy_domain_spec.rb +2 -2
- data/spec/unit/action/set_name_of_domain_spec.rb +3 -3
- data/spec/unit/action/start_domain_spec.rb +49 -0
- data/spec/unit/action/start_domain_spec/default.xml +48 -0
- data/spec/unit/config_spec.rb +173 -0
- data/spec/unit/templates/domain_all_settings.xml +20 -4
- data/spec/unit/templates/domain_custom_cpu_model.xml +48 -0
- data/spec/unit/templates/domain_defaults.xml +2 -0
- data/spec/unit/templates/domain_spec.rb +26 -2
- metadata +34 -32
- data/.coveralls.yml +0 -1
- data/.github/issue_template.md +0 -37
- data/.gitignore +0 -21
- data/.travis.yml +0 -24
- data/Gemfile +0 -26
- data/Rakefile +0 -8
- data/example_box/README.md +0 -29
- data/example_box/Vagrantfile +0 -60
- data/example_box/metadata.json +0 -5
- data/tools/create_box.sh +0 -130
- data/tools/prepare_redhat_for_box.sh +0 -119
- data/vagrant-libvirt.gemspec +0 -54
@@ -0,0 +1 @@
|
|
1
|
+
0.3.0
|
@@ -1,5 +1,28 @@
|
|
1
1
|
module VagrantPlugins
|
2
2
|
module ProviderLibvirt
|
3
|
-
|
3
|
+
VERSION_FILE = File.dirname(__FILE__) + "/version"
|
4
|
+
|
5
|
+
def self.get_version
|
6
|
+
if File.exist?(VERSION_FILE)
|
7
|
+
version = File.read(VERSION_FILE)
|
8
|
+
else
|
9
|
+
git_version = `git describe --tags`
|
10
|
+
version_parts = git_version.split('-').first(2) # drop the git sha if it exists
|
11
|
+
if version_parts.length > 1
|
12
|
+
# increment the patch number so that this is marked as a pre-release of the
|
13
|
+
# next possible release
|
14
|
+
main_version_parts = Gem::Version.new(version_parts[0]).segments
|
15
|
+
main_version_parts[-1] = main_version_parts.last + 1
|
16
|
+
version_parts = main_version_parts + ["pre", version_parts[1]]
|
17
|
+
end
|
18
|
+
version = version_parts.join(".")
|
19
|
+
end
|
20
|
+
|
21
|
+
return version.freeze
|
22
|
+
end
|
23
|
+
|
24
|
+
def self.write_version
|
25
|
+
File.write(VERSION_FILE, self.get_version)
|
26
|
+
end
|
4
27
|
end
|
5
28
|
end
|
data/locales/en.yml
CHANGED
@@ -16,7 +16,7 @@ en:
|
|
16
16
|
Created volume larger than box defaults, will require manual resizing of
|
17
17
|
filesystems to utilize.
|
18
18
|
uploading_volume: |-
|
19
|
-
Uploading base box image as volume into
|
19
|
+
Uploading base box image as volume into Libvirt storage...
|
20
20
|
creating_domain_volume: |-
|
21
21
|
Creating image (snapshot of base box volume).
|
22
22
|
removing_domain_volume: |-
|
@@ -35,6 +35,8 @@ en:
|
|
35
35
|
Resuming domain...
|
36
36
|
suspending_domain: |-
|
37
37
|
Suspending domain...
|
38
|
+
package_domain: |-
|
39
|
+
Packaging domain...
|
38
40
|
waiting_for_ready: |-
|
39
41
|
Waiting for domain to become "ready"...
|
40
42
|
waiting_for_ip: |-
|
@@ -58,7 +60,7 @@ en:
|
|
58
60
|
Forwarding UDP ports is not supported. Ignoring.
|
59
61
|
|
60
62
|
errors:
|
61
|
-
package_not_supported: No support for package with
|
63
|
+
package_not_supported: No support for package with Libvirt. Create box manually.
|
62
64
|
fog_error: |-
|
63
65
|
There was an error talking to Libvirt. The error message is shown
|
64
66
|
below:
|
@@ -95,7 +97,7 @@ en:
|
|
95
97
|
wrong_box_format: |-
|
96
98
|
Wrong image format specified for box.
|
97
99
|
fog_libvirt_connection_error: |-
|
98
|
-
Error while connecting to
|
100
|
+
Error while connecting to Libvirt: %{error_message}
|
99
101
|
fog_create_volume_error: |-
|
100
102
|
Error while creating a storage pool volume: %{error_message}
|
101
103
|
fog_create_domain_volume_error: |-
|
@@ -106,9 +108,11 @@ en:
|
|
106
108
|
Name `%{domain_name}` of domain about to create is already taken. Please try to run
|
107
109
|
`vagrant up` command again.
|
108
110
|
creating_storage_pool_error: |-
|
109
|
-
There was error while creating
|
111
|
+
There was error while creating Libvirt storage pool: %{error_message}
|
110
112
|
image_upload_error: |-
|
111
113
|
Error while uploading image to storage pool: %{error_message}
|
114
|
+
image_download_error: |-
|
115
|
+
Error while downloading volume '%{volume_name}' from storage pool '%{pool_name}': %{error_message}
|
112
116
|
no_domain_error: |-
|
113
117
|
No domain found. %{error_message}
|
114
118
|
attach_device_error: |-
|
@@ -18,7 +18,7 @@ class EnvironmentHelper
|
|
18
18
|
1024
|
19
19
|
end
|
20
20
|
|
21
|
-
%w(cpus cpu_mode loader boot_order machine_type disk_bus disk_device nested volume_cache kernel cmd_line initrd graphics_type graphics_autoport graphics_port graphics_ip graphics_passwd video_type video_vram keymap storage_pool_name disks cdroms driver).each do |name|
|
21
|
+
%w(cpus cpu_mode loader nvram boot_order machine_type disk_bus disk_device nested volume_cache kernel cmd_line initrd graphics_type graphics_autoport graphics_port graphics_ip graphics_passwd video_type video_vram keymap storage_pool_name disks cdroms driver).each do |name|
|
22
22
|
define_method(name.to_sym) do
|
23
23
|
nil
|
24
24
|
end
|
@@ -17,7 +17,7 @@ shared_context 'unit' do
|
|
17
17
|
end
|
18
18
|
let(:env) { { env: iso_env, machine: machine, ui: ui, root_path: '/rootpath' } }
|
19
19
|
let(:conf) { Vagrant::Config::V2::DummyConfig.new }
|
20
|
-
let(:ui) { Vagrant::UI::
|
20
|
+
let(:ui) { Vagrant::UI::Silent.new }
|
21
21
|
let(:iso_env) { test_env.create_vagrant_env ui_class: Vagrant::UI::Basic }
|
22
22
|
let(:machine) { iso_env.machine(:test, :libvirt) }
|
23
23
|
# Mock the communicator to prevent SSH commands for being executed.
|
@@ -28,7 +28,7 @@ shared_context 'unit' do
|
|
28
28
|
let(:plugin) { register_plugin }
|
29
29
|
|
30
30
|
before (:each) do
|
31
|
-
machine.
|
32
|
-
machine.
|
31
|
+
allow(machine).to receive(:guest).and_return(guest)
|
32
|
+
allow(machine).to receive(:communicator).and_return(communicator)
|
33
33
|
end
|
34
34
|
end
|
@@ -0,0 +1,85 @@
|
|
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
|
+
end
|
30
|
+
|
31
|
+
context 'default pool' do
|
32
|
+
let(:test_file) { 'default_storage_pool.xml' }
|
33
|
+
|
34
|
+
it 'should execute correctly' do
|
35
|
+
expect(libvirt_client).to receive(:lookup_storage_pool_by_name).and_return(libvirt_storage_pool)
|
36
|
+
expect(libvirt_storage_pool).to receive(:xml_desc).and_return(storage_pool_xml)
|
37
|
+
expect(servers).to receive(:create).and_return(machine)
|
38
|
+
|
39
|
+
expect(subject.call(env)).to be_nil
|
40
|
+
end
|
41
|
+
|
42
|
+
context 'additional disks' do
|
43
|
+
let(:vagrantfile) do
|
44
|
+
<<-EOF
|
45
|
+
Vagrant.configure('2') do |config|
|
46
|
+
config.vm.define :test
|
47
|
+
config.vm.provider :libvirt do |libvirt|
|
48
|
+
libvirt.storage :file, :size => '20G'
|
49
|
+
end
|
50
|
+
end
|
51
|
+
EOF
|
52
|
+
end
|
53
|
+
|
54
|
+
context 'volume create failed' do
|
55
|
+
it 'should raise an exception' do
|
56
|
+
expect(libvirt_client).to receive(:lookup_storage_pool_by_name).and_return(libvirt_storage_pool)
|
57
|
+
expect(libvirt_storage_pool).to receive(:xml_desc).and_return(storage_pool_xml)
|
58
|
+
expect(volumes).to receive(:create).and_raise(Libvirt::Error)
|
59
|
+
|
60
|
+
expect{ subject.call(env) }.to raise_error(VagrantPlugins::ProviderLibvirt::Errors::FogCreateDomainVolumeError)
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
context 'volume create succeeded' do
|
65
|
+
it 'should complete' do
|
66
|
+
expect(libvirt_client).to receive(:lookup_storage_pool_by_name).and_return(libvirt_storage_pool)
|
67
|
+
expect(libvirt_storage_pool).to receive(:xml_desc).and_return(storage_pool_xml)
|
68
|
+
expect(volumes).to receive(:create)
|
69
|
+
expect(servers).to receive(:create).and_return(machine)
|
70
|
+
|
71
|
+
expect(subject.call(env)).to be_nil
|
72
|
+
end
|
73
|
+
end
|
74
|
+
end
|
75
|
+
end
|
76
|
+
|
77
|
+
context 'no default pool' do
|
78
|
+
it 'should raise an exception' do
|
79
|
+
expect(libvirt_client).to receive(:lookup_storage_pool_by_name).and_return(nil)
|
80
|
+
|
81
|
+
expect{ subject.call(env) }.to raise_error(VagrantPlugins::ProviderLibvirt::Errors::NoStoragePool)
|
82
|
+
end
|
83
|
+
end
|
84
|
+
end
|
85
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
<pool type='dir'>
|
2
|
+
<name>default</name>
|
3
|
+
<uuid>434e1b75-4a72-45d7-8a98-ebd90c125d22</uuid>
|
4
|
+
<capacity unit='bytes'>10737418240</capacity>
|
5
|
+
<allocation unit='bytes'>10737418240</allocation>
|
6
|
+
<available unit='bytes'>10737418240</available>
|
7
|
+
<source>
|
8
|
+
</source>
|
9
|
+
<target>
|
10
|
+
<path>/var/lib/libvirt/images</path>
|
11
|
+
<permissions>
|
12
|
+
<mode>0755</mode>
|
13
|
+
<owner>0</owner>
|
14
|
+
<group>0</group>
|
15
|
+
</permissions>
|
16
|
+
</target>
|
17
|
+
</pool>
|
@@ -33,7 +33,7 @@ describe VagrantPlugins::ProviderLibvirt::Action::DestroyDomain do
|
|
33
33
|
before do
|
34
34
|
allow(libvirt_domain).to receive(:list_snapshots).and_return([])
|
35
35
|
allow(libvirt_domain).to receive(:has_managed_save?).and_return(nil)
|
36
|
-
root_disk.
|
36
|
+
allow(root_disk).to receive(:name).and_return('test.img')
|
37
37
|
end
|
38
38
|
|
39
39
|
context 'when only has root disk' do
|
@@ -57,7 +57,7 @@ describe VagrantPlugins::ProviderLibvirt::Action::DestroyDomain do
|
|
57
57
|
|
58
58
|
let(:extra_disk) { double('libvirt_extra_disk') }
|
59
59
|
before do
|
60
|
-
extra_disk.
|
60
|
+
allow(extra_disk).to receive(:name).and_return('test-vdb.qcow2')
|
61
61
|
end
|
62
62
|
|
63
63
|
it 'destroys disks individually' do
|
@@ -10,12 +10,12 @@ describe VagrantPlugins::ProviderLibvirt::Action::SetNameOfDomain do
|
|
10
10
|
dmn = VagrantPlugins::ProviderLibvirt::Action::SetNameOfDomain.new(Object.new, @env)
|
11
11
|
first = dmn.build_domain_name(@env)
|
12
12
|
second = dmn.build_domain_name(@env)
|
13
|
-
first.
|
13
|
+
expect(first).to_not eq(second)
|
14
14
|
end
|
15
15
|
|
16
16
|
it 'builds simple domain name' do
|
17
|
-
@env.default_prefix = '
|
17
|
+
@env.default_prefix = 'pre_'
|
18
18
|
dmn = VagrantPlugins::ProviderLibvirt::Action::SetNameOfDomain.new(Object.new, @env)
|
19
|
-
dmn.build_domain_name(@env).
|
19
|
+
expect(dmn.build_domain_name(@env)).to eq('pre_')
|
20
20
|
end
|
21
21
|
end
|
@@ -0,0 +1,49 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'support/sharedcontext'
|
3
|
+
require 'support/libvirt_context'
|
4
|
+
|
5
|
+
require 'vagrant-libvirt/errors'
|
6
|
+
require 'vagrant-libvirt/action/start_domain'
|
7
|
+
|
8
|
+
describe VagrantPlugins::ProviderLibvirt::Action::StartDomain do
|
9
|
+
subject { described_class.new(app, env) }
|
10
|
+
|
11
|
+
include_context 'unit'
|
12
|
+
include_context 'libvirt'
|
13
|
+
|
14
|
+
let(:libvirt_domain) { double('libvirt_domain') }
|
15
|
+
let(:libvirt_client) { double('libvirt_client') }
|
16
|
+
let(:servers) { double('servers') }
|
17
|
+
|
18
|
+
let(:domain_xml) { File.read(File.join(File.dirname(__FILE__), File.basename(__FILE__, '.rb'), test_file)) }
|
19
|
+
|
20
|
+
describe '#call' do
|
21
|
+
before do
|
22
|
+
allow_any_instance_of(VagrantPlugins::ProviderLibvirt::Driver)
|
23
|
+
.to receive(:connection).and_return(connection)
|
24
|
+
allow(connection).to receive(:client).and_return(libvirt_client)
|
25
|
+
allow(libvirt_client).to receive(:lookup_domain_by_uuid).and_return(libvirt_domain)
|
26
|
+
|
27
|
+
allow(connection).to receive(:servers).and_return(servers)
|
28
|
+
allow(servers).to receive(:get).and_return(domain)
|
29
|
+
end
|
30
|
+
|
31
|
+
context 'default config' do
|
32
|
+
let(:test_file) { 'default.xml' }
|
33
|
+
|
34
|
+
before do
|
35
|
+
allow(libvirt_domain).to receive(:xml_desc).and_return(domain_xml)
|
36
|
+
|
37
|
+
allow(libvirt_domain).to receive(:max_memory).and_return(512*1024)
|
38
|
+
allow(libvirt_domain).to receive(:num_vcpus).and_return(1)
|
39
|
+
end
|
40
|
+
|
41
|
+
it 'should execute correctly' do
|
42
|
+
expect(libvirt_domain).to receive(:autostart=)
|
43
|
+
expect(domain).to receive(:start)
|
44
|
+
|
45
|
+
expect(subject.call(env)).to be_nil
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
@@ -0,0 +1,48 @@
|
|
1
|
+
<domain xmlns:qemu='http://libvirt.org/schemas/domain/qemu/1.0' type=''>
|
2
|
+
<name/>
|
3
|
+
<title/>
|
4
|
+
<description/>
|
5
|
+
<uuid/>
|
6
|
+
<memory/>
|
7
|
+
<vcpu>1</vcpu>
|
8
|
+
|
9
|
+
|
10
|
+
<cpu mode='host-model'>
|
11
|
+
<model fallback='allow'></model>
|
12
|
+
</cpu>
|
13
|
+
|
14
|
+
|
15
|
+
<os>
|
16
|
+
<type>hvm</type>
|
17
|
+
<kernel/>
|
18
|
+
<initrd></initrd>
|
19
|
+
<cmdline/>
|
20
|
+
</os>
|
21
|
+
<features>
|
22
|
+
<acpi/>
|
23
|
+
<apic/>
|
24
|
+
<pae/>
|
25
|
+
</features>
|
26
|
+
<clock offset='utc'/>
|
27
|
+
<devices>
|
28
|
+
|
29
|
+
|
30
|
+
<serial type='pty'>
|
31
|
+
<target port='0'/>
|
32
|
+
</serial>
|
33
|
+
<console type='pty'>
|
34
|
+
<target port='0'/>
|
35
|
+
</console>
|
36
|
+
|
37
|
+
|
38
|
+
<input bus='ps2' type='mouse'/>
|
39
|
+
|
40
|
+
<graphics autoport='yes' keymap='en-us' listen='127.0.0.1' port='-1' type='vnc'/>
|
41
|
+
<video>
|
42
|
+
<model heads='1' type='cirrus' vram='9216'/>
|
43
|
+
</video>
|
44
|
+
|
45
|
+
|
46
|
+
</devices>
|
47
|
+
|
48
|
+
</domain>
|
data/spec/unit/config_spec.rb
CHANGED
@@ -6,12 +6,185 @@ require 'vagrant-libvirt/config'
|
|
6
6
|
describe VagrantPlugins::ProviderLibvirt::Config do
|
7
7
|
include_context 'unit'
|
8
8
|
|
9
|
+
let(:fake_env) { Hash.new }
|
10
|
+
|
11
|
+
describe '#finalize!' do
|
12
|
+
it 'is valid with defaults' do
|
13
|
+
subject.finalize!
|
14
|
+
end
|
15
|
+
|
16
|
+
context '@uri' do
|
17
|
+
before(:example) do
|
18
|
+
stub_const("ENV", fake_env)
|
19
|
+
end
|
20
|
+
|
21
|
+
context 'when LIBVIRT_DEFAULT_URI is defined' do
|
22
|
+
it 'should always use this value' do
|
23
|
+
fake_env['LIBVIRT_DEFAULT_URI'] = "custom:///custom_path"
|
24
|
+
|
25
|
+
subject.finalize!
|
26
|
+
expect(subject.uri).to eq("custom:///custom_path")
|
27
|
+
expect(subject.qemu_use_session).to eq(false)
|
28
|
+
end
|
29
|
+
|
30
|
+
context 'when LIBVIRT_DEFAULT_URI contains "qemu"' do
|
31
|
+
[
|
32
|
+
[
|
33
|
+
'set qemu_use_session if "session" present',
|
34
|
+
'qemu:///session',
|
35
|
+
true,
|
36
|
+
],
|
37
|
+
[
|
38
|
+
'handle different protocol additions',
|
39
|
+
'qemu+ssh:///session',
|
40
|
+
true,
|
41
|
+
],
|
42
|
+
[
|
43
|
+
'handle options before and after path',
|
44
|
+
'qemu://remote/session?keyfile=my_id_rsa',
|
45
|
+
true,
|
46
|
+
],
|
47
|
+
[
|
48
|
+
'identify when session not set',
|
49
|
+
'qemu://remote/system',
|
50
|
+
false,
|
51
|
+
],
|
52
|
+
[
|
53
|
+
'handle session appearing elsewhere',
|
54
|
+
'qemu://remote/system?keyfile=my_session_id',
|
55
|
+
false,
|
56
|
+
],
|
57
|
+
].each do |title, uri, session|
|
58
|
+
it "should #{title}" do
|
59
|
+
fake_env['LIBVIRT_DEFAULT_URI'] = uri
|
60
|
+
|
61
|
+
subject.finalize!
|
62
|
+
expect(subject.uri).to eq(uri)
|
63
|
+
expect(subject.qemu_use_session).to eq(session)
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
69
|
+
context 'when @driver is defined' do
|
70
|
+
defaults = {'id_ssh_key_file' => nil}
|
71
|
+
[
|
72
|
+
[
|
73
|
+
{'driver' => 'kvm'},
|
74
|
+
'qemu:///system?no_verify=1',
|
75
|
+
false,
|
76
|
+
],
|
77
|
+
[
|
78
|
+
{'driver' => 'qemu'},
|
79
|
+
'qemu:///system?no_verify=1',
|
80
|
+
false,
|
81
|
+
],
|
82
|
+
[
|
83
|
+
{'driver' => 'qemu', 'qemu_use_session' => true},
|
84
|
+
'qemu:///session?no_verify=1',
|
85
|
+
true,
|
86
|
+
],
|
87
|
+
[
|
88
|
+
{'driver' => 'openvz'},
|
89
|
+
'openvz:///system?no_verify=1',
|
90
|
+
false,
|
91
|
+
],
|
92
|
+
[
|
93
|
+
{'driver' => 'vbox'},
|
94
|
+
'vbox:///session?no_verify=1',
|
95
|
+
false,
|
96
|
+
],
|
97
|
+
].each do |inputs, output_uri, output_session|
|
98
|
+
it "should detect #{inputs}" do
|
99
|
+
inputs.merge(defaults).each do |k, v|
|
100
|
+
subject.instance_variable_set("@#{k}", v)
|
101
|
+
end
|
102
|
+
|
103
|
+
subject.finalize!
|
104
|
+
expect(subject.uri).to eq(output_uri)
|
105
|
+
expect(subject.qemu_use_session).to eq(output_session)
|
106
|
+
end
|
107
|
+
end
|
108
|
+
|
109
|
+
it "should raise exception for unrecognized" do
|
110
|
+
subject.driver = "bad-driver"
|
111
|
+
|
112
|
+
expect { subject.finalize! }.to raise_error("Require specify driver bad-driver")
|
113
|
+
end
|
114
|
+
end
|
115
|
+
|
116
|
+
context 'when @connect_via_ssh defined' do
|
117
|
+
defaults = {'driver' => 'qemu', 'id_ssh_key_file' => nil}
|
118
|
+
[
|
119
|
+
[
|
120
|
+
{'connect_via_ssh' => true},
|
121
|
+
'qemu+ssh://localhost/system?no_verify=1',
|
122
|
+
],
|
123
|
+
[
|
124
|
+
{'connect_via_ssh' => true, 'username' => 'my_user'},
|
125
|
+
'qemu+ssh://my_user@localhost/system?no_verify=1',
|
126
|
+
],
|
127
|
+
[
|
128
|
+
{'connect_via_ssh' => true, 'host' => 'remote_server'},
|
129
|
+
'qemu+ssh://remote_server/system?no_verify=1',
|
130
|
+
],
|
131
|
+
].each do |inputs, output_uri|
|
132
|
+
it "should detect #{inputs}" do
|
133
|
+
inputs.merge(defaults).each do |k, v|
|
134
|
+
subject.instance_variable_set("@#{k}", v)
|
135
|
+
end
|
136
|
+
|
137
|
+
subject.finalize!
|
138
|
+
expect(subject.uri).to eq(output_uri)
|
139
|
+
end
|
140
|
+
end
|
141
|
+
end
|
142
|
+
|
143
|
+
context 'when @id_ssh_key_file defined' do
|
144
|
+
defaults = {'driver' => 'qemu'}
|
145
|
+
[
|
146
|
+
[
|
147
|
+
{},
|
148
|
+
'qemu:///system?no_verify=1&keyfile=/home/user/.ssh/id_rsa',
|
149
|
+
],
|
150
|
+
[
|
151
|
+
{'id_ssh_key_file' => '/path/to/keyfile'},
|
152
|
+
'qemu:///system?no_verify=1&keyfile=/path/to/keyfile',
|
153
|
+
],
|
154
|
+
].each do |inputs, output_uri|
|
155
|
+
it "should detect #{inputs}" do
|
156
|
+
inputs.merge(defaults).each do |k, v|
|
157
|
+
subject.instance_variable_set("@#{k}", v)
|
158
|
+
end
|
159
|
+
|
160
|
+
fake_env['HOME'] = '/home/user'
|
161
|
+
|
162
|
+
subject.finalize!
|
163
|
+
expect(subject.uri).to eq(output_uri)
|
164
|
+
end
|
165
|
+
end
|
166
|
+
end
|
167
|
+
|
168
|
+
context 'when @socket defined' do
|
169
|
+
it "should detect @socket set" do
|
170
|
+
subject.socket = '/var/run/libvirt/libvirt-sock'
|
171
|
+
subject.id_ssh_key_file = false
|
172
|
+
|
173
|
+
subject.finalize!
|
174
|
+
expect(subject.uri).to eq('qemu:///system?no_verify=1&socket=/var/run/libvirt/libvirt-sock')
|
175
|
+
end
|
176
|
+
end
|
177
|
+
end
|
178
|
+
end
|
179
|
+
|
9
180
|
def assert_invalid
|
181
|
+
subject.finalize!
|
10
182
|
errors = subject.validate(machine)
|
11
183
|
raise "No errors: #{errors.inspect}" if errors.values.all?(&:empty?)
|
12
184
|
end
|
13
185
|
|
14
186
|
def assert_valid
|
187
|
+
subject.finalize!
|
15
188
|
errors = subject.validate(machine)
|
16
189
|
raise "Errors: #{errors.inspect}" unless errors.values.all?(&:empty?)
|
17
190
|
end
|