vagrant-libvirt 0.3.0 → 0.4.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +170 -17
- data/lib/vagrant-libvirt/action/create_domain.rb +30 -9
- data/lib/vagrant-libvirt/action/forward_ports.rb +1 -1
- data/lib/vagrant-libvirt/action/package_domain.rb +2 -1
- 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/config.rb +202 -41
- data/lib/vagrant-libvirt/driver.rb +46 -31
- data/lib/vagrant-libvirt/provider.rb +2 -9
- data/lib/vagrant-libvirt/templates/domain.xml.erb +29 -5
- data/lib/vagrant-libvirt/version +1 -1
- data/lib/vagrant-libvirt/version.rb +57 -9
- data/spec/spec_helper.rb +28 -2
- data/spec/support/libvirt_context.rb +2 -0
- data/spec/support/sharedcontext.rb +4 -0
- data/spec/unit/action/create_domain_spec.rb +110 -35
- data/spec/unit/action/create_domain_spec/{default_storage_pool.xml → default_system_storage_pool.xml} +0 -0
- data/spec/unit/action/create_domain_spec/default_user_storage_pool.xml +17 -0
- data/spec/unit/action/start_domain_spec.rb +183 -1
- data/spec/unit/action/start_domain_spec/clock_timer_rtc.xml +50 -0
- data/spec/unit/action/start_domain_spec/default.xml +2 -2
- 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 +14 -9
- data/spec/unit/config_spec.rb +392 -127
- data/spec/unit/provider_spec.rb +11 -0
- data/spec/unit/templates/domain_all_settings.xml +6 -3
- data/spec/unit/templates/domain_custom_cpu_model.xml +2 -1
- data/spec/unit/templates/domain_defaults.xml +2 -1
- data/spec/unit/templates/domain_spec.rb +80 -2
- data/spec/unit/templates/tpm/version_1.2.xml +54 -0
- data/spec/unit/templates/tpm/version_2.0.xml +53 -0
- metadata +74 -17
File without changes
|
@@ -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>
|
@@ -16,6 +16,7 @@ describe VagrantPlugins::ProviderLibvirt::Action::StartDomain do
|
|
16
16
|
let(:servers) { double('servers') }
|
17
17
|
|
18
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)) }
|
19
20
|
|
20
21
|
describe '#call' do
|
21
22
|
before do
|
@@ -26,6 +27,9 @@ describe VagrantPlugins::ProviderLibvirt::Action::StartDomain do
|
|
26
27
|
|
27
28
|
allow(connection).to receive(:servers).and_return(servers)
|
28
29
|
allow(servers).to receive(:get).and_return(domain)
|
30
|
+
|
31
|
+
expect(logger).to receive(:info)
|
32
|
+
expect(ui).to_not receive(:error)
|
29
33
|
end
|
30
34
|
|
31
35
|
context 'default config' do
|
@@ -38,12 +42,190 @@ describe VagrantPlugins::ProviderLibvirt::Action::StartDomain do
|
|
38
42
|
allow(libvirt_domain).to receive(:num_vcpus).and_return(1)
|
39
43
|
end
|
40
44
|
|
41
|
-
it 'should execute
|
45
|
+
it 'should execute without changing' do
|
46
|
+
allow(libvirt_domain).to receive(:undefine)
|
47
|
+
expect(logger).to_not receive(:debug)
|
42
48
|
expect(libvirt_domain).to receive(:autostart=)
|
43
49
|
expect(domain).to receive(:start)
|
44
50
|
|
45
51
|
expect(subject.call(env)).to be_nil
|
46
52
|
end
|
47
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
|
48
230
|
end
|
49
231
|
end
|
@@ -0,0 +1,50 @@
|
|
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'/>
|
12
|
+
</cpu>
|
13
|
+
|
14
|
+
|
15
|
+
<os>
|
16
|
+
<type>hvm</type>
|
17
|
+
<kernel/>
|
18
|
+
<initrd/>
|
19
|
+
<cmdline/>
|
20
|
+
</os>
|
21
|
+
<features>
|
22
|
+
<acpi/>
|
23
|
+
<apic/>
|
24
|
+
<pae/>
|
25
|
+
</features>
|
26
|
+
<clock offset='utc'>
|
27
|
+
<timer name='rtc'/>
|
28
|
+
</clock>
|
29
|
+
<devices>
|
30
|
+
|
31
|
+
|
32
|
+
<serial type='pty'>
|
33
|
+
<target port='0'/>
|
34
|
+
</serial>
|
35
|
+
<console type='pty'>
|
36
|
+
<target port='0'/>
|
37
|
+
</console>
|
38
|
+
|
39
|
+
|
40
|
+
<input bus='ps2' type='mouse'/>
|
41
|
+
|
42
|
+
<graphics autoport='yes' keymap='en-us' listen='127.0.0.1' port='-1' type='vnc'/>
|
43
|
+
<video>
|
44
|
+
<model heads='1' type='cirrus' vram='9216'/>
|
45
|
+
</video>
|
46
|
+
|
47
|
+
|
48
|
+
</devices>
|
49
|
+
|
50
|
+
</domain>
|
@@ -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'/>
|
12
|
+
</cpu>
|
13
|
+
|
14
|
+
|
15
|
+
<os>
|
16
|
+
<type>hvm</type>
|
17
|
+
<kernel/>
|
18
|
+
<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
|
+
<tpm model='tpm-tis'><backend type='passthrough'><device path='/dev/tpm0'/></backend></tpm></devices>
|
47
|
+
|
48
|
+
</domain>
|
@@ -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'/>
|
12
|
+
</cpu>
|
13
|
+
|
14
|
+
|
15
|
+
<os>
|
16
|
+
<type>hvm</type>
|
17
|
+
<kernel/>
|
18
|
+
<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
|
+
<tpm model='tpm-crb'><backend type='emulator' version='2.0'/></tpm></devices>
|
47
|
+
|
48
|
+
</domain>
|
@@ -12,18 +12,19 @@ describe VagrantPlugins::ProviderLibvirt::Action::WaitTillUp do
|
|
12
12
|
include_context 'libvirt'
|
13
13
|
include_context 'unit'
|
14
14
|
|
15
|
+
let (:driver) { double('driver') }
|
16
|
+
|
15
17
|
describe '#call' do
|
16
18
|
before do
|
17
|
-
allow_any_instance_of(VagrantPlugins::ProviderLibvirt::
|
18
|
-
.
|
19
|
-
|
20
|
-
|
19
|
+
allow_any_instance_of(VagrantPlugins::ProviderLibvirt::Provider).to receive(:driver)
|
20
|
+
.and_return(driver)
|
21
|
+
allow(driver).to receive(:get_domain).and_return(domain)
|
22
|
+
allow(driver).to receive(:state).and_return(:running)
|
21
23
|
end
|
22
24
|
|
23
25
|
context 'when machine does not exist' do
|
24
26
|
before do
|
25
|
-
|
26
|
-
.to receive(:get_domain).and_return(nil)
|
27
|
+
allow(driver).to receive(:get_domain).and_return(nil)
|
27
28
|
end
|
28
29
|
|
29
30
|
it 'raises exception' do
|
@@ -41,6 +42,7 @@ describe VagrantPlugins::ProviderLibvirt::Action::WaitTillUp do
|
|
41
42
|
it 'should exit' do
|
42
43
|
expect(app).to_not receive(:call)
|
43
44
|
expect(ui).to receive(:info).with('Waiting for domain to get an IP address...')
|
45
|
+
expect(logger).to receive(:debug).with(/Searching for IP for MAC address: .*/)
|
44
46
|
expect(subject.call(env)).to be_nil
|
45
47
|
end
|
46
48
|
end
|
@@ -50,13 +52,12 @@ describe VagrantPlugins::ProviderLibvirt::Action::WaitTillUp do
|
|
50
52
|
allow(domain).to receive(:wait_for).and_return(true)
|
51
53
|
allow(env).to receive(:[]).and_call_original
|
52
54
|
allow(env).to receive(:[]).with(:interrupted).and_return(false, true, true)
|
53
|
-
allow(
|
55
|
+
allow(driver).to receive(:get_domain_ipaddress).and_return('192.168.121.2')
|
54
56
|
end
|
55
57
|
it 'should exit after getting IP' do
|
56
58
|
expect(app).to_not receive(:call)
|
57
59
|
expect(ui).to receive(:info).with('Waiting for domain to get an IP address...')
|
58
60
|
expect(ui).to receive(:info).with('Waiting for SSH to become available...')
|
59
|
-
logger = subject.instance_variable_get(:@logger)
|
60
61
|
expect(logger).to receive(:debug).with(/Searching for IP for MAC address: .*/)
|
61
62
|
expect(logger).to receive(:info).with('Got IP address 192.168.121.2')
|
62
63
|
expect(logger).to receive(:info).with(/Time for getting IP: .*/)
|
@@ -71,12 +72,16 @@ describe VagrantPlugins::ProviderLibvirt::Action::WaitTillUp do
|
|
71
72
|
allow(domain).to receive(:wait_for).and_return(true)
|
72
73
|
allow(env).to receive(:[]).and_call_original
|
73
74
|
allow(env).to receive(:[]).with(:interrupted).and_return(false)
|
74
|
-
allow(
|
75
|
+
allow(driver).to receive(:get_domain_ipaddress).and_return('192.168.121.2')
|
75
76
|
end
|
76
77
|
it 'should call the next hook' do
|
77
78
|
expect(app).to receive(:call)
|
78
79
|
expect(ui).to receive(:info).with('Waiting for domain to get an IP address...')
|
79
80
|
expect(ui).to receive(:info).with('Waiting for SSH to become available...')
|
81
|
+
expect(logger).to receive(:debug).with(/Searching for IP for MAC address: .*/)
|
82
|
+
expect(logger).to receive(:info).with('Got IP address 192.168.121.2')
|
83
|
+
expect(logger).to receive(:info).with(/Time for getting IP: .*/)
|
84
|
+
expect(logger).to receive(:info).with(/Time for SSH ready: .*/)
|
80
85
|
expect(env[:machine].communicate).to receive(:ready?).and_return(true)
|
81
86
|
expect(subject.call(env)).to be_nil
|
82
87
|
end
|