vagrant-libvirt 0.0.45 → 0.4.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.
Files changed (74) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +542 -167
  3. data/lib/vagrant-libvirt/action.rb +2 -2
  4. data/lib/vagrant-libvirt/action/create_domain.rb +112 -42
  5. data/lib/vagrant-libvirt/action/create_domain_volume.rb +14 -10
  6. data/lib/vagrant-libvirt/action/create_network_interfaces.rb +8 -5
  7. data/lib/vagrant-libvirt/action/create_networks.rb +2 -2
  8. data/lib/vagrant-libvirt/action/destroy_domain.rb +1 -1
  9. data/lib/vagrant-libvirt/action/forward_ports.rb +10 -8
  10. data/lib/vagrant-libvirt/action/halt_domain.rb +1 -1
  11. data/lib/vagrant-libvirt/action/handle_box_image.rb +28 -60
  12. data/lib/vagrant-libvirt/action/handle_storage_pool.rb +4 -4
  13. data/lib/vagrant-libvirt/action/package_domain.rb +64 -12
  14. data/lib/vagrant-libvirt/action/prepare_nfs_settings.rb +3 -9
  15. data/lib/vagrant-libvirt/action/prune_nfs_exports.rb +19 -9
  16. data/lib/vagrant-libvirt/action/remove_libvirt_image.rb +2 -2
  17. data/lib/vagrant-libvirt/action/remove_stale_volume.rb +17 -11
  18. data/lib/vagrant-libvirt/action/set_boot_order.rb +2 -2
  19. data/lib/vagrant-libvirt/action/set_name_of_domain.rb +6 -9
  20. data/lib/vagrant-libvirt/action/start_domain.rb +87 -30
  21. data/lib/vagrant-libvirt/action/wait_till_up.rb +10 -32
  22. data/lib/vagrant-libvirt/cap/public_address.rb +16 -0
  23. data/lib/vagrant-libvirt/cap/synced_folder.rb +3 -3
  24. data/lib/vagrant-libvirt/config.rb +294 -42
  25. data/lib/vagrant-libvirt/driver.rb +49 -34
  26. data/lib/vagrant-libvirt/errors.rb +5 -5
  27. data/lib/vagrant-libvirt/plugin.rb +7 -2
  28. data/lib/vagrant-libvirt/provider.rb +2 -9
  29. data/lib/vagrant-libvirt/templates/domain.xml.erb +52 -10
  30. data/lib/vagrant-libvirt/templates/public_interface.xml.erb +5 -1
  31. data/lib/vagrant-libvirt/util.rb +1 -0
  32. data/lib/vagrant-libvirt/util/erb_template.rb +6 -7
  33. data/lib/vagrant-libvirt/util/network_util.rb +6 -1
  34. data/lib/vagrant-libvirt/util/nfs.rb +17 -0
  35. data/lib/vagrant-libvirt/util/ui.rb +23 -0
  36. data/lib/vagrant-libvirt/version +1 -0
  37. data/lib/vagrant-libvirt/version.rb +72 -1
  38. data/locales/en.yml +6 -6
  39. data/spec/spec_helper.rb +28 -2
  40. data/spec/support/libvirt_context.rb +3 -1
  41. data/spec/support/sharedcontext.rb +7 -3
  42. data/spec/unit/action/create_domain_spec.rb +160 -0
  43. data/spec/unit/action/create_domain_spec/default_system_storage_pool.xml +17 -0
  44. data/spec/unit/action/create_domain_spec/default_user_storage_pool.xml +17 -0
  45. data/spec/unit/action/destroy_domain_spec.rb +2 -2
  46. data/spec/unit/action/set_name_of_domain_spec.rb +3 -3
  47. data/spec/unit/action/start_domain_spec.rb +231 -0
  48. data/spec/unit/action/start_domain_spec/clock_timer_rtc.xml +50 -0
  49. data/spec/unit/action/start_domain_spec/default.xml +48 -0
  50. data/spec/unit/action/start_domain_spec/default_added_tpm_path.xml +48 -0
  51. data/spec/unit/action/start_domain_spec/default_added_tpm_version.xml +48 -0
  52. data/spec/unit/action/wait_till_up_spec.rb +14 -9
  53. data/spec/unit/config_spec.rb +438 -0
  54. data/spec/unit/provider_spec.rb +11 -0
  55. data/spec/unit/templates/domain_all_settings.xml +20 -5
  56. data/spec/unit/templates/domain_custom_cpu_model.xml +4 -1
  57. data/spec/unit/templates/domain_defaults.xml +4 -1
  58. data/spec/unit/templates/domain_spec.rb +92 -4
  59. data/spec/unit/templates/tpm/version_1.2.xml +54 -0
  60. data/spec/unit/templates/tpm/version_2.0.xml +53 -0
  61. metadata +91 -36
  62. data/.coveralls.yml +0 -1
  63. data/.github/issue_template.md +0 -37
  64. data/.gitignore +0 -21
  65. data/.travis.yml +0 -24
  66. data/Gemfile +0 -26
  67. data/Rakefile +0 -8
  68. data/example_box/README.md +0 -29
  69. data/example_box/Vagrantfile +0 -60
  70. data/example_box/metadata.json +0 -5
  71. data/lib/vagrant-libvirt/templates/default_storage_volume.xml.erb +0 -14
  72. data/tools/create_box.sh +0 -130
  73. data/tools/prepare_redhat_for_box.sh +0 -119
  74. data/vagrant-libvirt.gemspec +0 -51
@@ -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.should_not eq(second)
13
+ expect(first).to_not eq(second)
14
14
  end
15
15
 
16
16
  it 'builds simple domain name' do
17
- @env.default_prefix = 'pre'
17
+ @env.default_prefix = 'pre_'
18
18
  dmn = VagrantPlugins::ProviderLibvirt::Action::SetNameOfDomain.new(Object.new, @env)
19
- dmn.build_domain_name(@env).should eq('pre_')
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
@@ -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
+ </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-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>