vagrant-libvirt 0.1.0 → 0.4.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 +321 -76
- data/lib/vagrant-libvirt/action.rb +1 -1
- data/lib/vagrant-libvirt/action/create_domain.rb +54 -14
- data/lib/vagrant-libvirt/action/create_domain_volume.rb +0 -2
- data/lib/vagrant-libvirt/action/create_network_interfaces.rb +1 -0
- data/lib/vagrant-libvirt/action/forward_ports.rb +4 -3
- data/lib/vagrant-libvirt/action/handle_box_image.rb +6 -3
- data/lib/vagrant-libvirt/action/package_domain.rb +10 -4
- data/lib/vagrant-libvirt/action/prune_nfs_exports.rb +4 -3
- data/lib/vagrant-libvirt/action/start_domain.rb +86 -29
- data/lib/vagrant-libvirt/action/wait_till_up.rb +7 -27
- data/lib/vagrant-libvirt/cap/public_address.rb +16 -0
- data/lib/vagrant-libvirt/config.rb +233 -32
- data/lib/vagrant-libvirt/driver.rb +49 -32
- data/lib/vagrant-libvirt/plugin.rb +6 -0
- data/lib/vagrant-libvirt/provider.rb +2 -9
- data/lib/vagrant-libvirt/templates/domain.xml.erb +34 -5
- 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/ui.rb +23 -0
- data/lib/vagrant-libvirt/version +1 -0
- data/lib/vagrant-libvirt/version.rb +72 -1
- data/spec/spec_helper.rb +28 -2
- data/spec/support/binding_proc.rb +24 -0
- data/spec/support/libvirt_context.rb +3 -1
- data/spec/support/sharedcontext.rb +7 -3
- data/spec/unit/action/create_domain_spec.rb +160 -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/destroy_domain_spec.rb +2 -2
- 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 +32 -9
- data/spec/unit/config_spec.rb +438 -0
- data/spec/unit/provider_spec.rb +11 -0
- data/spec/unit/templates/domain_all_settings.xml +8 -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 +82 -2
- data/spec/unit/templates/tpm/version_1.2.xml +54 -0
- data/spec/unit/templates/tpm/version_2.0.xml +53 -0
- metadata +62 -6
@@ -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
|
@@ -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,160 @@
|
|
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
|
+
# should be ignored for system session and used for user session
|
35
|
+
allow(Process).to receive(:uid).and_return(9999)
|
36
|
+
allow(Process).to receive(:gid).and_return(9999)
|
37
|
+
end
|
38
|
+
|
39
|
+
context 'connection => qemu:///system' do
|
40
|
+
context 'default pool' do
|
41
|
+
let(:test_file) { 'default_system_storage_pool.xml' }
|
42
|
+
|
43
|
+
it 'should execute correctly' do
|
44
|
+
expect(libvirt_client).to receive(:lookup_storage_pool_by_name).and_return(libvirt_storage_pool)
|
45
|
+
expect(libvirt_storage_pool).to receive(:xml_desc).and_return(storage_pool_xml)
|
46
|
+
expect(servers).to receive(:create).and_return(machine)
|
47
|
+
expect(volumes).to_not receive(:create) # additional disks only
|
48
|
+
|
49
|
+
expect(subject.call(env)).to be_nil
|
50
|
+
end
|
51
|
+
|
52
|
+
context 'additional disks' do
|
53
|
+
let(:vagrantfile) do
|
54
|
+
<<-EOF
|
55
|
+
Vagrant.configure('2') do |config|
|
56
|
+
config.vm.define :test
|
57
|
+
config.vm.provider :libvirt do |libvirt|
|
58
|
+
libvirt.storage :file, :size => '20G'
|
59
|
+
end
|
60
|
+
end
|
61
|
+
EOF
|
62
|
+
end
|
63
|
+
|
64
|
+
context 'volume create failed' do
|
65
|
+
it 'should raise an exception' 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).and_raise(Libvirt::Error)
|
69
|
+
|
70
|
+
expect{ subject.call(env) }.to raise_error(VagrantPlugins::ProviderLibvirt::Errors::FogCreateDomainVolumeError)
|
71
|
+
end
|
72
|
+
end
|
73
|
+
|
74
|
+
context 'volume create succeeded' do
|
75
|
+
it 'should complete' do
|
76
|
+
expect(libvirt_client).to receive(:lookup_storage_pool_by_name).and_return(libvirt_storage_pool)
|
77
|
+
expect(libvirt_storage_pool).to receive(:xml_desc).and_return(storage_pool_xml)
|
78
|
+
expect(volumes).to receive(:create).with(
|
79
|
+
hash_including(
|
80
|
+
:path => "/var/lib/libvirt/images/vagrant-test_default-vdb.qcow2",
|
81
|
+
:owner => 0,
|
82
|
+
:group => 0,
|
83
|
+
:pool_name => "default",
|
84
|
+
)
|
85
|
+
)
|
86
|
+
expect(servers).to receive(:create).and_return(machine)
|
87
|
+
|
88
|
+
expect(subject.call(env)).to be_nil
|
89
|
+
end
|
90
|
+
end
|
91
|
+
end
|
92
|
+
end
|
93
|
+
|
94
|
+
context 'no default pool' do
|
95
|
+
it 'should raise an exception' do
|
96
|
+
expect(libvirt_client).to receive(:lookup_storage_pool_by_name).and_return(nil)
|
97
|
+
|
98
|
+
expect{ subject.call(env) }.to raise_error(VagrantPlugins::ProviderLibvirt::Errors::NoStoragePool)
|
99
|
+
end
|
100
|
+
end
|
101
|
+
end
|
102
|
+
|
103
|
+
context 'connection => qemu:///session' do
|
104
|
+
let(:vagrantfile) do
|
105
|
+
<<-EOF
|
106
|
+
Vagrant.configure('2') do |config|
|
107
|
+
config.vm.define :test
|
108
|
+
config.vm.provider :libvirt do |libvirt|
|
109
|
+
libvirt.qemu_use_session = true
|
110
|
+
end
|
111
|
+
end
|
112
|
+
EOF
|
113
|
+
end
|
114
|
+
|
115
|
+
context 'default pool' do
|
116
|
+
let(:test_file) { 'default_user_storage_pool.xml' }
|
117
|
+
|
118
|
+
it 'should execute correctly' do
|
119
|
+
expect(libvirt_client).to receive(:lookup_storage_pool_by_name).and_return(libvirt_storage_pool)
|
120
|
+
expect(libvirt_storage_pool).to receive(:xml_desc).and_return(storage_pool_xml)
|
121
|
+
expect(servers).to receive(:create).and_return(machine)
|
122
|
+
|
123
|
+
expect(subject.call(env)).to be_nil
|
124
|
+
end
|
125
|
+
|
126
|
+
context 'additional disks' do
|
127
|
+
let(:vagrantfile) do
|
128
|
+
<<-EOF
|
129
|
+
Vagrant.configure('2') do |config|
|
130
|
+
config.vm.define :test
|
131
|
+
config.vm.provider :libvirt do |libvirt|
|
132
|
+
libvirt.qemu_use_session = true
|
133
|
+
libvirt.storage :file, :size => '20G'
|
134
|
+
end
|
135
|
+
end
|
136
|
+
EOF
|
137
|
+
end
|
138
|
+
|
139
|
+
context 'volume create succeeded' do
|
140
|
+
it 'should complete' do
|
141
|
+
expect(libvirt_client).to receive(:lookup_storage_pool_by_name).and_return(libvirt_storage_pool)
|
142
|
+
expect(libvirt_storage_pool).to receive(:xml_desc).and_return(storage_pool_xml)
|
143
|
+
expect(volumes).to receive(:create).with(
|
144
|
+
hash_including(
|
145
|
+
:path => "/var/lib/libvirt/images/vagrant-test_default-vdb.qcow2",
|
146
|
+
:owner => 9999,
|
147
|
+
:group => 9999,
|
148
|
+
:pool_name => "default",
|
149
|
+
)
|
150
|
+
)
|
151
|
+
expect(servers).to receive(:create).and_return(machine)
|
152
|
+
|
153
|
+
expect(subject.call(env)).to be_nil
|
154
|
+
end
|
155
|
+
end
|
156
|
+
end
|
157
|
+
end
|
158
|
+
end
|
159
|
+
end
|
160
|
+
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>
|
@@ -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
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,231 @@
|
|
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
|
+
let(:updated_domain_xml) { File.read(File.join(File.dirname(__FILE__), File.basename(__FILE__, '.rb'), updated_test_file)) }
|
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
|
+
allow(libvirt_client).to receive(:lookup_domain_by_uuid).and_return(libvirt_domain)
|
27
|
+
|
28
|
+
allow(connection).to receive(:servers).and_return(servers)
|
29
|
+
allow(servers).to receive(:get).and_return(domain)
|
30
|
+
|
31
|
+
expect(logger).to receive(:info)
|
32
|
+
expect(ui).to_not receive(:error)
|
33
|
+
end
|
34
|
+
|
35
|
+
context 'default config' do
|
36
|
+
let(:test_file) { 'default.xml' }
|
37
|
+
|
38
|
+
before do
|
39
|
+
allow(libvirt_domain).to receive(:xml_desc).and_return(domain_xml)
|
40
|
+
|
41
|
+
allow(libvirt_domain).to receive(:max_memory).and_return(512*1024)
|
42
|
+
allow(libvirt_domain).to receive(:num_vcpus).and_return(1)
|
43
|
+
end
|
44
|
+
|
45
|
+
it 'should execute without changing' do
|
46
|
+
allow(libvirt_domain).to receive(:undefine)
|
47
|
+
expect(logger).to_not receive(:debug)
|
48
|
+
expect(libvirt_domain).to receive(:autostart=)
|
49
|
+
expect(domain).to receive(:start)
|
50
|
+
|
51
|
+
expect(subject.call(env)).to be_nil
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
context 'tpm' do
|
56
|
+
let(:test_file) { 'default.xml' }
|
57
|
+
|
58
|
+
before do
|
59
|
+
allow(libvirt_domain).to receive(:xml_desc).and_return(domain_xml)
|
60
|
+
|
61
|
+
allow(libvirt_domain).to receive(:max_memory).and_return(512*1024)
|
62
|
+
allow(libvirt_domain).to receive(:num_vcpus).and_return(1)
|
63
|
+
end
|
64
|
+
|
65
|
+
context 'passthrough tpm added' do
|
66
|
+
let(:updated_test_file) { 'default_added_tpm_path.xml' }
|
67
|
+
let(:vagrantfile_providerconfig) do
|
68
|
+
<<-EOF
|
69
|
+
libvirt.tpm_path = '/dev/tpm0'
|
70
|
+
libvirt.tpm_type = 'passthrough'
|
71
|
+
libvirt.tpm_model = 'tpm-tis'
|
72
|
+
EOF
|
73
|
+
end
|
74
|
+
|
75
|
+
it 'should modify the domain tpm_path' do
|
76
|
+
expect(libvirt_domain).to receive(:undefine)
|
77
|
+
expect(logger).to receive(:debug).with('tpm config changed')
|
78
|
+
expect(servers).to receive(:create).with(xml: updated_domain_xml)
|
79
|
+
expect(libvirt_domain).to receive(:autostart=)
|
80
|
+
expect(domain).to receive(:start)
|
81
|
+
|
82
|
+
expect(subject.call(env)).to be_nil
|
83
|
+
end
|
84
|
+
end
|
85
|
+
|
86
|
+
context 'emulated tpm added' do
|
87
|
+
let(:updated_test_file) { 'default_added_tpm_version.xml' }
|
88
|
+
let(:vagrantfile_providerconfig) do
|
89
|
+
<<-EOF
|
90
|
+
libvirt.tpm_type = 'emulator'
|
91
|
+
libvirt.tpm_model = 'tpm-crb'
|
92
|
+
libvirt.tpm_version = '2.0'
|
93
|
+
EOF
|
94
|
+
end
|
95
|
+
|
96
|
+
it 'should modify the domain tpm_path' do
|
97
|
+
expect(libvirt_domain).to receive(:undefine)
|
98
|
+
expect(logger).to receive(:debug).with('tpm config changed')
|
99
|
+
expect(servers).to receive(:create).with(xml: updated_domain_xml)
|
100
|
+
expect(libvirt_domain).to receive(:autostart=)
|
101
|
+
expect(domain).to receive(:start)
|
102
|
+
|
103
|
+
expect(subject.call(env)).to be_nil
|
104
|
+
end
|
105
|
+
end
|
106
|
+
|
107
|
+
context 'same passthrough tpm config' do
|
108
|
+
let(:test_file) { 'default_added_tpm_path.xml' }
|
109
|
+
let(:updated_test_file) { 'default_added_tpm_path.xml' }
|
110
|
+
let(:vagrantfile_providerconfig) do
|
111
|
+
<<-EOF
|
112
|
+
libvirt.tpm_path = '/dev/tpm0'
|
113
|
+
libvirt.tpm_type = 'passthrough'
|
114
|
+
libvirt.tpm_model = 'tpm-tis'
|
115
|
+
EOF
|
116
|
+
end
|
117
|
+
|
118
|
+
it 'should execute without changing' do
|
119
|
+
expect(logger).to_not receive(:debug)
|
120
|
+
expect(libvirt_domain).to receive(:autostart=)
|
121
|
+
expect(domain).to receive(:start)
|
122
|
+
|
123
|
+
expect(subject.call(env)).to be_nil
|
124
|
+
end
|
125
|
+
end
|
126
|
+
|
127
|
+
context 'same emulated tpm config' do
|
128
|
+
let(:test_file) { 'default_added_tpm_version.xml' }
|
129
|
+
let(:updated_test_file) { 'default_added_tpm_version.xml' }
|
130
|
+
let(:vagrantfile_providerconfig) do
|
131
|
+
<<-EOF
|
132
|
+
libvirt.tpm_type = 'emulator'
|
133
|
+
libvirt.tpm_model = 'tpm-crb'
|
134
|
+
libvirt.tpm_version = '2.0'
|
135
|
+
EOF
|
136
|
+
end
|
137
|
+
|
138
|
+
it 'should execute without changing' do
|
139
|
+
expect(logger).to_not receive(:debug)
|
140
|
+
expect(libvirt_domain).to receive(:autostart=)
|
141
|
+
expect(domain).to receive(:start)
|
142
|
+
|
143
|
+
expect(subject.call(env)).to be_nil
|
144
|
+
end
|
145
|
+
end
|
146
|
+
|
147
|
+
context 'change from passthrough to emulated' do
|
148
|
+
let(:test_file) { 'default_added_tpm_path.xml' }
|
149
|
+
let(:updated_test_file) { 'default_added_tpm_version.xml' }
|
150
|
+
let(:vagrantfile_providerconfig) do
|
151
|
+
<<-EOF
|
152
|
+
libvirt.tpm_type = 'emulator'
|
153
|
+
libvirt.tpm_model = 'tpm-crb'
|
154
|
+
libvirt.tpm_version = '2.0'
|
155
|
+
EOF
|
156
|
+
end
|
157
|
+
|
158
|
+
it 'should modify the domain' do
|
159
|
+
expect(libvirt_domain).to receive(:undefine)
|
160
|
+
expect(logger).to receive(:debug).with('tpm config changed')
|
161
|
+
expect(servers).to receive(:create).with(xml: updated_domain_xml)
|
162
|
+
expect(libvirt_domain).to receive(:autostart=)
|
163
|
+
expect(domain).to receive(:start)
|
164
|
+
|
165
|
+
expect(subject.call(env)).to be_nil
|
166
|
+
end
|
167
|
+
end
|
168
|
+
end
|
169
|
+
|
170
|
+
context 'clock_timers' do
|
171
|
+
let(:test_file) { 'clock_timer_rtc.xml' }
|
172
|
+
|
173
|
+
before do
|
174
|
+
allow(libvirt_domain).to receive(:xml_desc).and_return(domain_xml)
|
175
|
+
|
176
|
+
allow(libvirt_domain).to receive(:max_memory).and_return(512*1024)
|
177
|
+
allow(libvirt_domain).to receive(:num_vcpus).and_return(1)
|
178
|
+
end
|
179
|
+
|
180
|
+
context 'timers unchanged' do
|
181
|
+
let(:vagrantfile_providerconfig) do
|
182
|
+
<<-EOF
|
183
|
+
libvirt.clock_timer(:name => "rtc")
|
184
|
+
EOF
|
185
|
+
end
|
186
|
+
|
187
|
+
it 'should not modify the domain' do
|
188
|
+
expect(logger).to_not receive(:debug).with('clock timers config changed')
|
189
|
+
expect(servers).to_not receive(:create)
|
190
|
+
expect(libvirt_domain).to receive(:autostart=)
|
191
|
+
expect(domain).to receive(:start)
|
192
|
+
|
193
|
+
expect(subject.call(env)).to be_nil
|
194
|
+
end
|
195
|
+
end
|
196
|
+
|
197
|
+
context 'timers added' do
|
198
|
+
let(:vagrantfile_providerconfig) do
|
199
|
+
<<-EOF
|
200
|
+
libvirt.clock_timer(:name => "rtc")
|
201
|
+
libvirt.clock_timer(:name => "tsc")
|
202
|
+
EOF
|
203
|
+
end
|
204
|
+
|
205
|
+
it 'should modify the domain' do
|
206
|
+
expect(libvirt_domain).to receive(:undefine)
|
207
|
+
expect(logger).to receive(:debug).with('clock timers config changed')
|
208
|
+
expect(servers).to receive(:create).with(xml: match(/<clock offset='utc'>\s*<timer name='rtc'\/>\s*<timer name='tsc'\/>\s*<\/clock>/))
|
209
|
+
expect(libvirt_domain).to receive(:autostart=)
|
210
|
+
expect(domain).to receive(:start)
|
211
|
+
|
212
|
+
expect(subject.call(env)).to be_nil
|
213
|
+
end
|
214
|
+
end
|
215
|
+
|
216
|
+
context 'timers removed' do
|
217
|
+
let(:updated_test_file) { 'default.xml' }
|
218
|
+
|
219
|
+
it 'should modify the domain' do
|
220
|
+
expect(libvirt_domain).to receive(:undefine)
|
221
|
+
expect(logger).to receive(:debug).with('clock timers config changed')
|
222
|
+
expect(servers).to receive(:create).with(xml: match(/<clock offset='utc'>\s*<\/clock>/))
|
223
|
+
expect(libvirt_domain).to receive(:autostart=)
|
224
|
+
expect(domain).to receive(:start)
|
225
|
+
|
226
|
+
expect(subject.call(env)).to be_nil
|
227
|
+
end
|
228
|
+
end
|
229
|
+
end
|
230
|
+
end
|
231
|
+
end
|