vagrant-libvirt 0.6.3 → 0.8.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (61) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +65 -13
  3. data/lib/vagrant-libvirt/action/cleanup_on_failure.rb +76 -0
  4. data/lib/vagrant-libvirt/action/create_domain.rb +56 -10
  5. data/lib/vagrant-libvirt/action/create_network_interfaces.rb +5 -1
  6. data/lib/vagrant-libvirt/action/create_networks.rb +24 -0
  7. data/lib/vagrant-libvirt/action/destroy_domain.rb +106 -21
  8. data/lib/vagrant-libvirt/action/destroy_networks.rb +1 -1
  9. data/lib/vagrant-libvirt/action/forward_ports.rb +12 -11
  10. data/lib/vagrant-libvirt/action/prepare_nfs_settings.rb +1 -1
  11. data/lib/vagrant-libvirt/action/start_domain.rb +36 -0
  12. data/lib/vagrant-libvirt/action/wait_till_up.rb +6 -32
  13. data/lib/vagrant-libvirt/action.rb +72 -83
  14. data/lib/vagrant-libvirt/config.rb +85 -30
  15. data/lib/vagrant-libvirt/driver.rb +11 -9
  16. data/lib/vagrant-libvirt/errors.rb +12 -0
  17. data/lib/vagrant-libvirt/templates/domain.xml.erb +228 -218
  18. data/lib/vagrant-libvirt/templates/private_network.xml.erb +4 -1
  19. data/lib/vagrant-libvirt/util/network_util.rb +15 -3
  20. data/lib/vagrant-libvirt/util/nfs.rb +2 -0
  21. data/lib/vagrant-libvirt/util/resolvers.rb +80 -0
  22. data/lib/vagrant-libvirt/version +1 -1
  23. data/locales/en.yml +17 -0
  24. data/spec/spec_helper.rb +36 -23
  25. data/spec/support/libvirt_context.rb +7 -4
  26. data/spec/support/sharedcontext.rb +1 -1
  27. data/spec/unit/action/cleanup_on_failure_spec.rb +131 -0
  28. data/spec/unit/action/create_domain_spec/additional_disks_domain.xml +6 -18
  29. data/spec/unit/action/create_domain_spec/custom_disk_settings.xml +43 -0
  30. data/spec/unit/action/create_domain_spec/default_domain.xml +6 -18
  31. data/spec/unit/action/create_domain_spec/two_disk_settings.xml +49 -0
  32. data/spec/unit/action/create_domain_spec.rb +51 -7
  33. data/spec/unit/action/create_domain_volume_spec.rb +5 -3
  34. data/spec/unit/action/destroy_domain_spec/additional_disks_domain.xml +47 -0
  35. data/spec/unit/action/destroy_domain_spec/box_multiple_disks.xml +55 -0
  36. data/spec/unit/action/destroy_domain_spec/box_multiple_disks_and_additional_and_custom_disks.xml +72 -0
  37. data/spec/unit/action/destroy_domain_spec/box_multiple_disks_and_additional_and_custom_disks_no_aliases.xml +67 -0
  38. data/spec/unit/action/destroy_domain_spec/box_multiple_disks_and_additional_disks.xml +67 -0
  39. data/spec/unit/action/destroy_domain_spec/cdrom_domain.xml +48 -0
  40. data/spec/unit/action/destroy_domain_spec.rb +134 -30
  41. data/spec/unit/action/forward_ports_spec.rb +10 -2
  42. data/spec/unit/action/prepare_nfs_settings_spec.rb +59 -0
  43. data/spec/unit/action/shutdown_domain_spec.rb +1 -1
  44. data/spec/unit/action/start_domain_spec/clock_timer_rtc.xml +6 -18
  45. data/spec/unit/action/start_domain_spec/default.xml +6 -18
  46. data/spec/unit/action/start_domain_spec/default_added_tpm_path.xml +6 -18
  47. data/spec/unit/action/start_domain_spec/default_added_tpm_version.xml +6 -18
  48. data/spec/unit/action/start_domain_spec/existing.xml +1 -1
  49. data/spec/unit/action/wait_till_up_spec.rb +4 -43
  50. data/spec/unit/action_spec.rb +2 -0
  51. data/spec/unit/config_spec.rb +133 -26
  52. data/spec/unit/driver_spec.rb +154 -10
  53. data/spec/unit/templates/domain_all_settings.xml +56 -77
  54. data/spec/unit/templates/domain_cpu_mode_passthrough.xml +39 -0
  55. data/spec/unit/templates/domain_custom_cpu_model.xml +6 -18
  56. data/spec/unit/templates/domain_defaults.xml +6 -18
  57. data/spec/unit/templates/domain_spec.rb +39 -13
  58. data/spec/unit/templates/tpm/version_1.2.xml +6 -18
  59. data/spec/unit/templates/tpm/version_2.0.xml +6 -18
  60. data/spec/unit/util/resolvers_spec.rb +116 -0
  61. metadata +40 -41
@@ -1,5 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require 'fog/libvirt/requests/compute/dhcp_leases'
4
+
3
5
  require 'spec_helper'
4
6
  require 'support/binding_proc'
5
7
  require 'support/sharedcontext'
@@ -8,6 +10,7 @@ require 'vagrant-libvirt/driver'
8
10
 
9
11
  describe VagrantPlugins::ProviderLibvirt::Driver do
10
12
  include_context 'unit'
13
+ include_context 'libvirt'
11
14
 
12
15
  subject { described_class.new(machine) }
13
16
 
@@ -27,14 +30,23 @@ describe VagrantPlugins::ProviderLibvirt::Driver do
27
30
  end
28
31
  EOF
29
32
  end
33
+
30
34
  # need to override the default package iso_env as using a different
31
35
  # name for the test machines above.
32
36
  let(:machine) { iso_env.machine(:test1, :libvirt) }
33
37
  let(:machine2) { iso_env.machine(:test2, :libvirt) }
34
- let(:connection1) { double("connection 1") }
35
- let(:connection2) { double("connection 2") }
36
- let(:system_connection1) { double("system connection 1") }
37
- let(:system_connection2) { double("system connection 2") }
38
+ let(:connection1) { double("connection 1") }
39
+ let(:connection2) { double("connection 2") }
40
+ let(:system_connection1) { double("system connection 1") }
41
+ let(:system_connection2) { double("system connection 2") }
42
+
43
+ # make it easier for distros that want to switch the default value for
44
+ # qemu_use_session to true by ensuring it is explicitly false for tests.
45
+ before do
46
+ allow(machine.provider_config).to receive(:qemu_use_session).and_return(false)
47
+ allow(logger).to receive(:info)
48
+ allow(logger).to receive(:debug)
49
+ end
38
50
 
39
51
  describe '#connection' do
40
52
  it 'should configure a separate connection per machine' do
@@ -68,15 +80,15 @@ describe VagrantPlugins::ProviderLibvirt::Driver do
68
80
  # system_uri should be 'qemu+ssh://user@remote1/system'
69
81
  # and not 'qemu:///system'.
70
82
  it 'should configure a separate connection per machine' do
71
- expect(Libvirt).to receive(:open).with('qemu:///system').and_return(system_connection1)
72
- expect(Libvirt).to receive(:open).with('qemu:///system').and_return(system_connection2)
83
+ expect(Libvirt).to receive(:open_read_only).with('qemu+ssh://user@remote1/system').and_return(system_connection1)
84
+ expect(Libvirt).to receive(:open_read_only).with('qemu+ssh://vms@remote2/system').and_return(system_connection2)
73
85
 
74
86
  expect(machine.provider.driver.system_connection).to eq(system_connection1)
75
87
  expect(machine2.provider.driver.system_connection).to eq(system_connection2)
76
88
  end
77
89
 
78
90
  it 'should configure the connection once' do
79
- expect(Libvirt).to receive(:open).with('qemu:///system').and_return(system_connection1)
91
+ expect(Libvirt).to receive(:open_read_only).with('qemu+ssh://user@remote1/system').and_return(system_connection1)
80
92
 
81
93
  expect(machine.provider.driver.system_connection).to eq(system_connection1)
82
94
  expect(machine.provider.driver.system_connection).to eq(system_connection1)
@@ -84,6 +96,129 @@ describe VagrantPlugins::ProviderLibvirt::Driver do
84
96
  end
85
97
  end
86
98
 
99
+ describe '#get_ipaddress' do
100
+ context 'when domain exists' do
101
+ # not used yet, but this is the form that is returned from addresses
102
+ let(:addresses) { {
103
+ :public => ["192.168.122.111"],
104
+ :private => ["192.168.122.111"],
105
+ } }
106
+
107
+ before do
108
+ allow(subject).to receive(:get_domain).and_return(domain)
109
+ end
110
+
111
+ it 'should retrieve the address via domain fog-libvirt API' do
112
+ # ideally should be able to yield a block to wait_for and check that
113
+ # the 'addresses' function on the domain is called correctly.
114
+ expect(domain).to receive(:wait_for).and_return(nil)
115
+ expect(subject.get_ipaddress(machine)).to eq(nil)
116
+ end
117
+
118
+ context 'when qemu_use_agent is enabled' do
119
+ let(:qemu_agent_interfaces) {
120
+ <<-EOF
121
+ {
122
+ "return": [
123
+ {
124
+ "name": "lo",
125
+ "ip-addresses": [
126
+ {
127
+ "ip-address-type": "ipv4",
128
+ "ip-address": "127.0.0.1",
129
+ "prefix": 8
130
+ }
131
+ ],
132
+ "hardware-address": "00:00:00:00:00:00"
133
+ },
134
+ {
135
+ "name": "eth0",
136
+ "ip-addresses": [
137
+ {
138
+ "ip-address-type": "ipv4",
139
+ "ip-address": "192.168.122.42",
140
+ "prefix": 24
141
+ }
142
+ ],
143
+ "hardware-address": "52:54:00:f8:67:98"
144
+ }
145
+ ]
146
+ }
147
+ EOF
148
+ }
149
+
150
+ before do
151
+ allow(machine.provider_config).to receive(:qemu_use_agent).and_return(true)
152
+ end
153
+
154
+ it 'should retrieve the address via the agent' do
155
+ expect(subject).to receive(:connection).and_return(connection)
156
+ expect(libvirt_client).to receive(:lookup_domain_by_uuid).and_return(libvirt_domain)
157
+ expect(libvirt_domain).to receive(:qemu_agent_command).and_return(qemu_agent_interfaces)
158
+ expect(domain).to receive(:mac).and_return("52:54:00:f8:67:98").exactly(2).times
159
+
160
+ expect(subject.get_ipaddress(machine)).to eq("192.168.122.42")
161
+ end
162
+
163
+ context 'when qemu_use_session is enabled' do
164
+ before do
165
+ allow(machine.provider_config).to receive(:qemu_use_session).and_return(true)
166
+ end
167
+
168
+ it 'should still retrieve the address via the agent' do
169
+ expect(subject).to receive(:connection).and_return(connection)
170
+ expect(libvirt_client).to receive(:lookup_domain_by_uuid).and_return(libvirt_domain)
171
+ expect(libvirt_domain).to receive(:qemu_agent_command).and_return(qemu_agent_interfaces)
172
+ expect(domain).to receive(:mac).and_return("52:54:00:f8:67:98").exactly(2).times
173
+
174
+ expect(subject.get_ipaddress(machine)).to eq("192.168.122.42")
175
+ end
176
+ end
177
+ end
178
+
179
+ context 'when qemu_use_session is enabled' do
180
+ let(:networks) { [instance_double(::Fog::Libvirt::Compute::Real)] }
181
+ let(:dhcp_leases) {
182
+ {
183
+ "iface" =>"virbr0",
184
+ "expirytime" =>1636287162,
185
+ "type" =>0,
186
+ "mac" =>"52:54:00:8b:dc:5f",
187
+ "ipaddr" =>"192.168.122.43",
188
+ "prefix" =>24,
189
+ "hostname" =>"vagrant-default_test",
190
+ "clientid" =>"ff:00:8b:dc:5f:00:01:00:01:29:1a:65:42:52:54:00:8b:dc:5f",
191
+ }
192
+ }
193
+
194
+ before do
195
+ allow(machine.provider_config).to receive(:qemu_use_session).and_return(true)
196
+ end
197
+
198
+ it 'should retreive the address via the system dhcp-leases API' do
199
+ expect(domain).to receive(:mac).and_return("52:54:00:8b:dc:5f")
200
+ expect(subject).to receive(:system_connection).and_return(system_connection1)
201
+ expect(system_connection1).to receive(:list_all_networks).and_return(networks)
202
+ expect(networks[0]).to receive(:dhcp_leases).and_return([dhcp_leases])
203
+
204
+ expect(subject.get_ipaddress(machine)).to eq("192.168.122.43")
205
+ end
206
+
207
+ context 'when qemu_use_agent is enabled' do
208
+ before do
209
+ allow(machine.provider_config).to receive(:qemu_use_agent).and_return(true)
210
+ end
211
+
212
+ it 'should retrieve the address via the agent' do
213
+ expect(subject).to receive(:get_ipaddress_from_qemu_agent).and_return("192.168.122.44")
214
+
215
+ expect(subject.get_ipaddress(machine)).to eq("192.168.122.44")
216
+ end
217
+ end
218
+ end
219
+ end
220
+ end
221
+
87
222
  describe '#state' do
88
223
  let(:domain) { double('domain') }
89
224
 
@@ -110,12 +245,21 @@ describe VagrantPlugins::ProviderLibvirt::Driver do
110
245
  end,
111
246
  }
112
247
  ],
248
+ [
249
+ nil,
250
+ :unknown,
251
+ {
252
+ :setup => ProcWithBinding.new do
253
+ expect(domain).to receive(:state).and_return('unknown').at_least(:once)
254
+ end,
255
+ }
256
+ ],
113
257
  [
114
258
  'terminated',
115
259
  :not_created,
116
260
  {
117
261
  :setup => ProcWithBinding.new do
118
- expect(domain).to receive(:state).and_return('terminated')
262
+ expect(domain).to receive(:state).and_return('terminated').at_least(:once)
119
263
  end,
120
264
  }
121
265
  ],
@@ -124,7 +268,7 @@ describe VagrantPlugins::ProviderLibvirt::Driver do
124
268
  :inaccessible,
125
269
  {
126
270
  :setup => ProcWithBinding.new do
127
- expect(domain).to receive(:state).and_return('running').twice()
271
+ expect(domain).to receive(:state).and_return('running').at_least(:once)
128
272
  expect(subject).to receive(:get_domain_ipaddress).and_raise(Fog::Errors::TimeoutError)
129
273
  end,
130
274
  }
@@ -134,7 +278,7 @@ describe VagrantPlugins::ProviderLibvirt::Driver do
134
278
  :running,
135
279
  {
136
280
  :setup => ProcWithBinding.new do
137
- expect(domain).to receive(:state).and_return('running').twice()
281
+ expect(domain).to receive(:state).and_return('running').at_least(:once)
138
282
  expect(subject).to receive(:get_domain_ipaddress).and_return('192.168.121.2')
139
283
  end,
140
284
  }
@@ -5,25 +5,21 @@
5
5
  <uuid></uuid>
6
6
  <memory></memory>
7
7
  <vcpu cpuset='1-4,^3,6'>1</vcpu>
8
-
9
-
10
8
  <cpu mode='custom'>
11
- <model fallback='allow'>qemu64</model>
12
- <feature name='AAA' policy='required'/>
13
- <topology sockets='1' cores='3' threads='2'/>
9
+ <model fallback='allow'>qemu64</model>
10
+ <feature name='AAA' policy='required'/>
11
+ <topology sockets='1' cores='3' threads='2'/>
14
12
  </cpu>
15
-
16
13
  <numatune>
17
14
  <memory nodeset='1-4,^3,6'/>
18
15
  </numatune>
19
16
  <cputune>
20
17
  <shares>1024</shares>
21
18
  </cputune>
22
-
23
19
  <os>
24
- <type arch='x86_64' machine='pc-compatible'>hvm</type>
25
- <loader readonly='yes' type='rom'>/efi/loader</loader>
26
- <bootmenu enable='yes'/>
20
+ <type arch='x86_64' machine='pc-compatible'>hvm</type>
21
+ <loader readonly='yes' type='rom'>/efi/loader</loader>
22
+ <bootmenu enable='yes'/>
27
23
  <kernel></kernel>
28
24
  <initrd></initrd>
29
25
  <cmdline></cmdline>
@@ -59,15 +55,14 @@
59
55
  <alias name='ua-disk-volume-0'/>
60
56
  <driver name='qemu' type='qcow2' cache='default'/>
61
57
  <source file='/var/lib/libvirt/images/test-disk1.qcow2'/>
62
- <target dev='vdb' bus='virtio'/>
58
+ <target dev='vdc' bus='virtio'/>
63
59
  </disk>
64
60
  <disk type='file' device='disk'>
65
61
  <alias name='ua-disk-volume-1'/>
66
62
  <driver name='qemu' type='qcow2' cache='default' io='threads' copy_on_read='on' discard='unmap' detect_zeroes='on'/>
67
63
  <source file='/var/lib/libvirt/images/test-disk2.qcow2'/>
68
- <target dev='vdc' bus='virtio'/>
64
+ <target dev='vdd' bus='virtio'/>
69
65
  </disk>
70
-
71
66
  <disk type='file' device='cdrom'>
72
67
  <driver name='qemu' type='raw' />
73
68
  <source file=''/>
@@ -80,75 +75,60 @@
80
75
  <target dev='hdb' bus='ide'/>
81
76
  <readonly/>
82
77
  </disk>
83
-
84
- <serial type='pty'>
78
+ <serial type='file'>
79
+ <source path='/var/log/vm_consoles/machine.log'/>
85
80
  <target port='0'/>
86
81
  </serial>
87
- <console type='pty'>
82
+ <console type='file'>
83
+ <source path='/var/log/vm_consoles/machine.log'/>
88
84
  <target port='0'/>
89
85
  </console>
90
-
91
- <channel type='unix' >
92
- <target type='virtio'
93
- name="org.qemu.guest_agent.0"
94
- />
95
- </channel>
96
- <channel type='spicevmc' >
97
- <target type='virtio'
98
- name="com.redhat.spice.0"
99
- />
100
- </channel>
101
- <channel type='unix' >
102
- <source
103
- path="/tmp/foo"
104
- />
105
- <target type='guestfwd'
106
- address="192.0.2.42"
107
- port="4242"
108
- />
109
- </channel>
110
-
86
+ <channel type='unix' >
87
+ <target type='virtio' name='org.qemu.guest_agent.0'/>
88
+ </channel>
89
+ <channel type='spicevmc' >
90
+ <target type='virtio' name='com.redhat.spice.0'/>
91
+ </channel>
92
+ <channel type='unix' >
93
+ <source path='/tmp/foo'/>
94
+ <target type='guestfwd' address='192.0.2.42' port='4242'/>
95
+ </channel>
111
96
  <input type='mouse' bus='ps2'/>
112
-
113
- <graphics type='vnc' port='-1' autoport='yes' listen='127.0.0.1' keymap='en-us' />
114
- <video>
115
- <model type='cirrus' vram='9216' heads='1'/>
116
- </video>
117
- <rng model='virtio'>
118
- <backend model='random'>/dev/random</backend>
119
- </rng>
120
- <hostdev mode='subsystem' type='pci' managed='yes'>
121
- <source>
122
- <address domain='0x0000'
123
- bus='0x06'
124
- slot='0x12'
125
- function='0x5'/>
126
- </source>
127
- </hostdev>
128
- <hostdev mode='subsystem' type='pci' managed='yes'>
129
- <source>
130
- <address domain='0x0001'
131
- bus='0x03'
132
- slot='0x00'
133
- function='0x0'/>
134
- </source>
135
- </hostdev>
136
- <hostdev mode='subsystem' type='usb'>
137
- <source startupPolicy='mandatory'>
138
- <vendor id='0x1234'/>
139
- <product id='0xabcd'/>
140
- <address bus='1' device='2'/>
141
- </source>
142
- </hostdev>
143
- <redirdev bus='usb' type='tcp'>
144
- </redirdev>
145
- <redirfilter>
146
- <usbdev class='0x0b' vendor='0x08e6' product='0x3437' version='2.00' allow='yes'/>
147
- </redirfilter>
97
+ <graphics type='vnc' port='-1' autoport='yes' listen='127.0.0.1' keymap='en-us'>
98
+ <gl enable='yes'/>
99
+ </graphics>
100
+ <video>
101
+ <model type='cirrus' vram='16384' heads='1'>
102
+ <acceleration accel3d='yes'/>
103
+ </model>
104
+ </video>
105
+ <rng model='virtio'>
106
+ <backend model='random'>/dev/random</backend>
107
+ </rng>
108
+ <hostdev mode='subsystem' type='pci' managed='yes'>
109
+ <source>
110
+ <address domain='0x0000' bus='0x06' slot='0x12' function='0x5'/>
111
+ </source>
112
+ </hostdev>
113
+ <hostdev mode='subsystem' type='pci' managed='yes'>
114
+ <source>
115
+ <address domain='0x0001' bus='0x03' slot='0x00' function='0x0'/>
116
+ </source>
117
+ </hostdev>
118
+ <hostdev mode='subsystem' type='usb'>
119
+ <source startupPolicy='mandatory'>
120
+ <vendor id='0x1234'/>
121
+ <product id='0xabcd'/>
122
+ <address bus='1' device='2'/>
123
+ </source>
124
+ </hostdev>
125
+ <redirdev bus='usb' type='tcp'>
126
+ </redirdev>
127
+ <redirfilter>
128
+ <usbdev class='0x0b' vendor='0x08e6' product='0x3437' version='2.00' allow='yes'/>
129
+ </redirfilter>
148
130
  <watchdog model='i6300esb' action='reset'/>
149
-
150
- <smartcard mode='passthrough' type='spicevmc'/>
151
-
131
+ <smartcard mode='passthrough' type='spicevmc'/>
152
132
  <tpm model='tpm-tis'>
153
133
  <backend type='passthrough'>
154
134
  <device path='/dev/tpm0'/>
@@ -156,7 +136,6 @@
156
136
  </tpm>
157
137
  <controller type='usb' model='nec-xhci' ports="4" />
158
138
  </devices>
159
-
160
139
  <qemu:commandline>
161
140
  <qemu:arg value='-device'/>
162
141
  <qemu:arg value='dummy-device'/>
@@ -0,0 +1,39 @@
1
+ <domain type='' xmlns:qemu='http://libvirt.org/schemas/domain/qemu/1.0'>
2
+ <name></name>
3
+ <title></title>
4
+ <description></description>
5
+ <uuid></uuid>
6
+ <memory></memory>
7
+ <vcpu>1</vcpu>
8
+ <cpu mode='host-passthrough'>
9
+ <feature policy='optional' name='vmx'/>
10
+ <feature policy='optional' name='svm'/>
11
+ <topology sockets='1' cores='2' threads='1'/>
12
+ </cpu>
13
+ <os>
14
+ <type>hvm</type>
15
+ <kernel></kernel>
16
+ <initrd></initrd>
17
+ <cmdline></cmdline>
18
+ </os>
19
+ <features>
20
+ <acpi/>
21
+ <apic/>
22
+ <pae/>
23
+ </features>
24
+ <clock offset='utc'>
25
+ </clock>
26
+ <devices>
27
+ <serial type='pty'>
28
+ <target port='0'/>
29
+ </serial>
30
+ <console type='pty'>
31
+ <target port='0'/>
32
+ </console>
33
+ <input type='mouse' bus='ps2'/>
34
+ <graphics type='vnc' port='-1' autoport='yes' listen='127.0.0.1' keymap='en-us'/>
35
+ <video>
36
+ <model type='cirrus' vram='16384' heads='1'/>
37
+ </video>
38
+ </devices>
39
+ </domain>
@@ -5,15 +5,11 @@
5
5
  <uuid></uuid>
6
6
  <memory></memory>
7
7
  <vcpu>1</vcpu>
8
-
9
-
10
8
  <cpu mode='custom'>
11
- <model fallback='allow'>SandyBridge</model>
9
+ <model fallback='allow'>SandyBridge</model>
12
10
  </cpu>
13
-
14
-
15
11
  <os>
16
- <type>hvm</type>
12
+ <type>hvm</type>
17
13
  <kernel></kernel>
18
14
  <initrd></initrd>
19
15
  <cmdline></cmdline>
@@ -26,24 +22,16 @@
26
22
  <clock offset='utc'>
27
23
  </clock>
28
24
  <devices>
29
-
30
-
31
25
  <serial type='pty'>
32
26
  <target port='0'/>
33
27
  </serial>
34
28
  <console type='pty'>
35
29
  <target port='0'/>
36
30
  </console>
37
-
38
-
39
31
  <input type='mouse' bus='ps2'/>
40
-
41
- <graphics type='vnc' port='-1' autoport='yes' listen='127.0.0.1' keymap='en-us' />
42
- <video>
43
- <model type='cirrus' vram='9216' heads='1'/>
44
- </video>
45
-
46
-
32
+ <graphics type='vnc' port='-1' autoport='yes' listen='127.0.0.1' keymap='en-us'/>
33
+ <video>
34
+ <model type='cirrus' vram='16384' heads='1'/>
35
+ </video>
47
36
  </devices>
48
-
49
37
  </domain>
@@ -5,15 +5,11 @@
5
5
  <uuid></uuid>
6
6
  <memory></memory>
7
7
  <vcpu>1</vcpu>
8
-
9
-
10
8
  <cpu mode='host-model'>
11
- <model fallback='allow'></model>
9
+ <model fallback='allow'></model>
12
10
  </cpu>
13
-
14
-
15
11
  <os>
16
- <type>hvm</type>
12
+ <type>hvm</type>
17
13
  <kernel></kernel>
18
14
  <initrd></initrd>
19
15
  <cmdline></cmdline>
@@ -26,24 +22,16 @@
26
22
  <clock offset='utc'>
27
23
  </clock>
28
24
  <devices>
29
-
30
-
31
25
  <serial type='pty'>
32
26
  <target port='0'/>
33
27
  </serial>
34
28
  <console type='pty'>
35
29
  <target port='0'/>
36
30
  </console>
37
-
38
-
39
31
  <input type='mouse' bus='ps2'/>
40
-
41
- <graphics type='vnc' port='-1' autoport='yes' listen='127.0.0.1' keymap='en-us' />
42
- <video>
43
- <model type='cirrus' vram='9216' heads='1'/>
44
- </video>
45
-
46
-
32
+ <graphics type='vnc' port='-1' autoport='yes' listen='127.0.0.1' keymap='en-us'/>
33
+ <video>
34
+ <model type='cirrus' vram='16384' heads='1'/>
35
+ </video>
47
36
  </devices>
48
-
49
37
  </domain>
@@ -59,13 +59,13 @@ describe 'templates/domain' do
59
59
  domain.disk_device = 'vda'
60
60
  domain.disk_driver(:cache => 'unsafe', :io => 'threads', :copy_on_read => 'on', :discard => 'unmap', :detect_zeroes => 'on')
61
61
  domain.domain_volumes.push({
62
- :dev => 1.vdev.to_s,
62
+ :dev => 'vda',
63
63
  :cache => 'unsafe',
64
64
  :bus => domain.disk_bus,
65
65
  :path => '/var/lib/libvirt/images/test.qcow2'
66
66
  })
67
67
  domain.domain_volumes.push({
68
- :dev => 2.vdev.to_s,
68
+ :dev => 'vdb',
69
69
  :cache => 'unsafe',
70
70
  :bus => domain.disk_bus,
71
71
  :path => '/var/lib/libvirt/images/test2.qcow2'
@@ -89,6 +89,7 @@ describe 'templates/domain' do
89
89
  target_port: '4242',
90
90
  source_path: '/tmp/foo')
91
91
  domain.random(model: 'random')
92
+ domain.serial(:type => 'file', :source => {:path => '/var/log/vm_consoles/machine.log'})
92
93
  domain.pci(bus: '0x06', slot: '0x12', function: '0x5')
93
94
  domain.pci(domain: '0x0001', bus: '0x03', slot: '0x00', function: '0x0')
94
95
  domain.usb_controller(model: 'nec-xhci', ports: '4')
@@ -111,23 +112,48 @@ describe 'templates/domain' do
111
112
  domain.shares = '1024'
112
113
  domain.cpuset = '1-4,^3,6'
113
114
  domain.nodeset = '1-4,^3,6'
115
+
116
+ domain.video_accel3d = true
114
117
  end
115
118
  let(:test_file) { 'domain_all_settings.xml' }
116
119
  it 'renders template' do
117
120
  domain.finalize!
121
+ # resolving is now done during create domain, so need to recreate
122
+ # the same behaviour before calling the template until that
123
+ # is separated out from create domain.
124
+ resolver = ::VagrantPlugins::ProviderLibvirt::Util::DiskDeviceResolver.new(prefix=domain.disk_device[0..1])
125
+ resolver.resolve!(domain.domain_volumes.dup.each { |volume| volume[:device] = volume[:dev] })
126
+ resolver.resolve!(domain.disks)
127
+
118
128
  expect(domain.to_xml('domain')).to eq xml_expected
119
129
  end
120
130
  end
121
131
 
122
- context 'when custom cpu model enabled' do
123
- before do
124
- domain.cpu_mode = 'custom'
125
- domain.cpu_model = 'SandyBridge'
132
+ context 'when cpu mode is set' do
133
+ context 'to host-passthrough' do
134
+ before do
135
+ domain.cpu_mode = 'host-passthrough'
136
+ domain.cpu_model = 'SandyBridge'
137
+ domain.cputopology :sockets => '1', :cores => '2', :threads => '1'
138
+ domain.nested = true
139
+ end
140
+ let(:test_file) { 'domain_cpu_mode_passthrough.xml' }
141
+ it 'should allow features and topology and ignore model' do
142
+ domain.finalize!
143
+ expect(domain.to_xml('domain')).to eq xml_expected
144
+ end
126
145
  end
127
- let(:test_file) { 'domain_custom_cpu_model.xml' }
128
- it 'renders template' do
129
- domain.finalize!
130
- expect(domain.to_xml('domain')).to eq xml_expected
146
+
147
+ context 'to custom and model is set' do
148
+ before do
149
+ domain.cpu_mode = 'custom'
150
+ domain.cpu_model = 'SandyBridge'
151
+ end
152
+ let(:test_file) { 'domain_custom_cpu_model.xml' }
153
+ it 'renders template' do
154
+ domain.finalize!
155
+ expect(domain.to_xml('domain')).to eq xml_expected
156
+ end
131
157
  end
132
158
  end
133
159
 
@@ -164,12 +190,12 @@ describe 'templates/domain' do
164
190
  end
165
191
  end
166
192
 
167
- context 'memballon enabled' do
193
+ context 'memballoon enabled' do
168
194
  before do
169
195
  domain.memballoon_enabled = true
170
196
  end
171
197
 
172
- it 'renders with memballon element' do
198
+ it 'renders with memballoon element' do
173
199
  domain.finalize!
174
200
 
175
201
  expect(domain.to_xml('domain')).to match(/<memballoon model='virtio'>/)
@@ -192,7 +218,7 @@ describe 'templates/domain' do
192
218
  end
193
219
  end
194
220
 
195
- context 'memballon disabled' do
221
+ context 'memballoon disabled' do
196
222
  before do
197
223
  domain.memballoon_enabled = false
198
224
  end