vagrant-libvirt 0.0.36 → 0.0.37

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 (66) hide show
  1. checksums.yaml +4 -4
  2. data/.coveralls.yml +1 -0
  3. data/Gemfile +1 -0
  4. data/README.md +171 -13
  5. data/lib/vagrant-libvirt/action/create_domain.rb +44 -19
  6. data/lib/vagrant-libvirt/action/create_domain_volume.rb +12 -12
  7. data/lib/vagrant-libvirt/action/create_network_interfaces.rb +37 -39
  8. data/lib/vagrant-libvirt/action/create_networks.rb +34 -34
  9. data/lib/vagrant-libvirt/action/destroy_domain.rb +7 -8
  10. data/lib/vagrant-libvirt/action/destroy_networks.rb +12 -13
  11. data/lib/vagrant-libvirt/action/forward_ports.rb +21 -23
  12. data/lib/vagrant-libvirt/action/halt_domain.rb +8 -9
  13. data/lib/vagrant-libvirt/action/handle_box_image.rb +28 -27
  14. data/lib/vagrant-libvirt/action/handle_storage_pool.rb +8 -8
  15. data/lib/vagrant-libvirt/action/is_created.rb +1 -1
  16. data/lib/vagrant-libvirt/action/is_running.rb +2 -2
  17. data/lib/vagrant-libvirt/action/is_suspended.rb +4 -4
  18. data/lib/vagrant-libvirt/action/message_already_created.rb +2 -2
  19. data/lib/vagrant-libvirt/action/message_not_created.rb +2 -2
  20. data/lib/vagrant-libvirt/action/message_not_running.rb +2 -2
  21. data/lib/vagrant-libvirt/action/message_not_suspended.rb +2 -2
  22. data/lib/vagrant-libvirt/action/package_domain.rb +6 -5
  23. data/lib/vagrant-libvirt/action/prepare_nfs_settings.rb +7 -6
  24. data/lib/vagrant-libvirt/action/prepare_nfs_valid_ids.rb +2 -2
  25. data/lib/vagrant-libvirt/action/prune_nfs_exports.rb +3 -3
  26. data/lib/vagrant-libvirt/action/read_mac_addresses.rb +8 -10
  27. data/lib/vagrant-libvirt/action/remove_libvirt_image.rb +4 -4
  28. data/lib/vagrant-libvirt/action/remove_stale_volume.rb +8 -7
  29. data/lib/vagrant-libvirt/action/resume_domain.rb +5 -5
  30. data/lib/vagrant-libvirt/action/set_boot_order.rb +70 -27
  31. data/lib/vagrant-libvirt/action/set_name_of_domain.rb +10 -12
  32. data/lib/vagrant-libvirt/action/share_folders.rb +16 -18
  33. data/lib/vagrant-libvirt/action/start_domain.rb +59 -64
  34. data/lib/vagrant-libvirt/action/suspend_domain.rb +5 -5
  35. data/lib/vagrant-libvirt/action/wait_till_up.rb +24 -26
  36. data/lib/vagrant-libvirt/action.rb +18 -23
  37. data/lib/vagrant-libvirt/cap/mount_p9.rb +11 -10
  38. data/lib/vagrant-libvirt/cap/nic_mac_addresses.rb +1 -1
  39. data/lib/vagrant-libvirt/cap/synced_folder.rb +20 -19
  40. data/lib/vagrant-libvirt/config.rb +164 -136
  41. data/lib/vagrant-libvirt/driver.rb +10 -13
  42. data/lib/vagrant-libvirt/errors.rb +4 -3
  43. data/lib/vagrant-libvirt/plugin.rb +4 -6
  44. data/lib/vagrant-libvirt/provider.rb +23 -24
  45. data/lib/vagrant-libvirt/templates/domain.xml.erb +14 -1
  46. data/lib/vagrant-libvirt/templates/private_network.xml.erb +4 -0
  47. data/lib/vagrant-libvirt/util/collection.rb +0 -3
  48. data/lib/vagrant-libvirt/util/erb_template.rb +6 -10
  49. data/lib/vagrant-libvirt/util/error_codes.rb +32 -33
  50. data/lib/vagrant-libvirt/util/network_util.rb +29 -21
  51. data/lib/vagrant-libvirt/util.rb +3 -4
  52. data/lib/vagrant-libvirt/version.rb +1 -1
  53. data/locales/en.yml +3 -0
  54. data/spec/spec_helper.rb +3 -0
  55. data/spec/support/environment_helper.rb +5 -7
  56. data/spec/support/libvirt_context.rb +13 -11
  57. data/spec/support/sharedcontext.rb +9 -10
  58. data/spec/unit/action/destroy_domain_spec.rb +38 -37
  59. data/spec/unit/action/set_name_of_domain_spec.rb +4 -4
  60. data/spec/unit/action/wait_till_up_spec.rb +45 -46
  61. data/spec/unit/config_spec.rb +106 -0
  62. data/spec/unit/templates/domain_all_settings.xml +125 -0
  63. data/spec/unit/templates/domain_defaults.xml +44 -0
  64. data/spec/unit/templates/domain_spec.rb +69 -0
  65. data/tools/create_box.sh +8 -2
  66. metadata +12 -3
@@ -1,51 +1,51 @@
1
- require "spec_helper"
2
- require "support/sharedcontext"
3
- require "support/libvirt_context"
1
+ require 'spec_helper'
2
+ require 'support/sharedcontext'
3
+ require 'support/libvirt_context'
4
4
 
5
- require "vagrant-libvirt/action/destroy_domain"
5
+ require 'vagrant-libvirt/action/destroy_domain'
6
6
 
7
7
  describe VagrantPlugins::ProviderLibvirt::Action::DestroyDomain do
8
-
9
8
  subject { described_class.new(app, env) }
10
9
 
11
- include_context "unit"
12
- include_context "libvirt"
10
+ include_context 'unit'
11
+ include_context 'libvirt'
13
12
 
14
- let(:libvirt_domain) { double("libvirt_domain") }
15
- let(:libvirt_client) { double("libvirt_client") }
16
- let(:servers) { double("servers") }
13
+ let(:libvirt_domain) { double('libvirt_domain') }
14
+ let(:libvirt_client) { double('libvirt_client') }
15
+ let(:servers) { double('servers') }
17
16
 
18
- describe "#call" do
17
+ describe '#call' do
19
18
  before do
20
- allow_any_instance_of(VagrantPlugins::ProviderLibvirt::Driver).
21
- to receive(:connection).and_return(connection)
19
+ allow_any_instance_of(VagrantPlugins::ProviderLibvirt::Driver)
20
+ .to receive(:connection).and_return(connection)
22
21
  allow(connection).to receive(:client).and_return(libvirt_client)
23
- allow(libvirt_client).to receive(:lookup_domain_by_uuid).
24
- and_return(libvirt_domain)
22
+ allow(libvirt_client).to receive(:lookup_domain_by_uuid)
23
+ .and_return(libvirt_domain)
25
24
  allow(connection).to receive(:servers).and_return(servers)
26
25
  allow(servers).to receive(:get).and_return(domain)
27
26
  # always see this at the start of #call
28
- expect(ui).to receive(:info).with("Removing domain...")
27
+ expect(ui).to receive(:info).with('Removing domain...')
29
28
  end
30
29
 
31
- context "when no snapshots" do
32
- let(:root_disk) { double("libvirt_root_disk") }
30
+ context 'when no snapshots' do
31
+ let(:root_disk) { double('libvirt_root_disk') }
33
32
 
34
33
  before do
35
34
  allow(libvirt_domain).to receive(:list_snapshots).and_return([])
36
35
  allow(libvirt_domain).to receive(:has_managed_save?).and_return(nil)
37
- root_disk.stub(:name => "test.img")
36
+ root_disk.stub(name: 'test.img')
38
37
  end
39
38
 
40
- context "when only has root disk" do
41
- it "calls fog to destroy volumes" do
42
- expect(domain).to receive(:destroy).with(:destroy_volumes => true)
39
+ context 'when only has root disk' do
40
+ it 'calls fog to destroy volumes' do
41
+ expect(domain).to receive(:destroy).with(destroy_volumes: true)
43
42
  expect(subject.call(env)).to be_nil
44
43
  end
45
44
  end
46
45
 
47
- context "when has additional disks" do
48
- let(:vagrantfile) { <<-EOF
46
+ context 'when has additional disks' do
47
+ let(:vagrantfile) do
48
+ <<-EOF
49
49
  Vagrant.configure('2') do |config|
50
50
  config.vm.define :test
51
51
  config.vm.provider :libvirt do |libvirt|
@@ -53,26 +53,27 @@ describe VagrantPlugins::ProviderLibvirt::Action::DestroyDomain do
53
53
  end
54
54
  end
55
55
  EOF
56
- }
56
+ end
57
57
 
58
- let(:extra_disk) { double("libvirt_extra_disk") }
58
+ let(:extra_disk) { double('libvirt_extra_disk') }
59
59
  before do
60
- extra_disk.stub(:name => "test-vdb.qcow2")
60
+ extra_disk.stub(name: 'test-vdb.qcow2')
61
61
  end
62
62
 
63
- it "destroys disks individually" do
64
- allow(libvirt_domain).to receive(:name).and_return("test")
63
+ it 'destroys disks individually' do
64
+ allow(libvirt_domain).to receive(:name).and_return('test')
65
65
  allow(domain).to receive(:volumes).and_return([extra_disk], [root_disk])
66
66
 
67
- expect(domain).to receive(:destroy).with(:destroy_volumes => false)
68
- expect(extra_disk).to receive(:destroy) # extra disk remove
67
+ expect(domain).to receive(:destroy).with(destroy_volumes: false)
68
+ expect(extra_disk).to receive(:destroy) # extra disk remove
69
69
  expect(root_disk).to receive(:destroy) # root disk remove
70
70
  expect(subject.call(env)).to be_nil
71
71
  end
72
72
  end
73
73
 
74
- context "when has CDROMs attached" do
75
- let(:vagrantfile) { <<-EOF
74
+ context 'when has CDROMs attached' do
75
+ let(:vagrantfile) do
76
+ <<-EOF
76
77
  Vagrant.configure('2') do |config|
77
78
  config.vm.define :test
78
79
  config.vm.provider :libvirt do |libvirt|
@@ -80,13 +81,13 @@ describe VagrantPlugins::ProviderLibvirt::Action::DestroyDomain do
80
81
  end
81
82
  end
82
83
  EOF
83
- }
84
+ end
84
85
 
85
- it "uses explicit removal of disks" do
86
- allow(libvirt_domain).to receive(:name).and_return("test")
86
+ it 'uses explicit removal of disks' do
87
+ allow(libvirt_domain).to receive(:name).and_return('test')
87
88
  allow(domain).to receive(:volumes).and_return([root_disk])
88
89
 
89
- expect(domain).to_not receive(:destroy).with(:destroy_volumes => true)
90
+ expect(domain).to_not receive(:destroy).with(destroy_volumes: true)
90
91
  expect(root_disk).to receive(:destroy) # root disk remove
91
92
  expect(subject.call(env)).to be_nil
92
93
  end
@@ -1,11 +1,11 @@
1
- require "spec_helper"
1
+ require 'spec_helper'
2
2
 
3
3
  describe VagrantPlugins::ProviderLibvirt::Action::SetNameOfDomain do
4
4
  before :each do
5
5
  @env = EnvironmentHelper.new
6
6
  end
7
7
 
8
- it "builds unique domain name" do
8
+ it 'builds unique domain name' do
9
9
  @env.random_hostname = true
10
10
  dmn = VagrantPlugins::ProviderLibvirt::Action::SetNameOfDomain.new(Object.new, @env)
11
11
  first = dmn.build_domain_name(@env)
@@ -13,8 +13,8 @@ describe VagrantPlugins::ProviderLibvirt::Action::SetNameOfDomain do
13
13
  first.should_not eq(second)
14
14
  end
15
15
 
16
- it "builds simple domain name" do
17
- @env.default_prefix= 'pre'
16
+ it 'builds simple domain name' do
17
+ @env.default_prefix = 'pre'
18
18
  dmn = VagrantPlugins::ProviderLibvirt::Action::SetNameOfDomain.new(Object.new, @env)
19
19
  dmn.build_domain_name(@env).should eq('pre_')
20
20
  end
@@ -1,65 +1,64 @@
1
- require "vagrant-libvirt/action/wait_till_up"
2
- require "vagrant-libvirt/errors"
1
+ require 'vagrant-libvirt/action/wait_till_up'
2
+ require 'vagrant-libvirt/errors'
3
3
 
4
- require "spec_helper"
5
- require "support/sharedcontext"
6
- require "support/libvirt_context"
4
+ require 'spec_helper'
5
+ require 'support/sharedcontext'
6
+ require 'support/libvirt_context'
7
7
 
8
8
  describe VagrantPlugins::ProviderLibvirt::Action::WaitTillUp do
9
-
10
9
  subject { described_class.new(app, env) }
11
10
 
12
- include_context "vagrant-unit"
13
- include_context "libvirt"
14
- include_context "unit"
11
+ include_context 'vagrant-unit'
12
+ include_context 'libvirt'
13
+ include_context 'unit'
15
14
 
16
- describe "#call" do
15
+ describe '#call' do
17
16
  before do
18
- allow_any_instance_of(VagrantPlugins::ProviderLibvirt::Driver).
19
- to receive(:get_domain).and_return(domain)
20
- allow_any_instance_of(VagrantPlugins::ProviderLibvirt::Driver).to receive(:state).
21
- and_return(:running)
17
+ allow_any_instance_of(VagrantPlugins::ProviderLibvirt::Driver)
18
+ .to receive(:get_domain).and_return(domain)
19
+ allow_any_instance_of(VagrantPlugins::ProviderLibvirt::Driver).to receive(:state)
20
+ .and_return(:running)
22
21
  end
23
22
 
24
- context "when machine does not exist" do
23
+ context 'when machine does not exist' do
25
24
  before do
26
- allow_any_instance_of(VagrantPlugins::ProviderLibvirt::Driver).
27
- to receive(:get_domain).and_return(nil)
25
+ allow_any_instance_of(VagrantPlugins::ProviderLibvirt::Driver)
26
+ .to receive(:get_domain).and_return(nil)
28
27
  end
29
28
 
30
- it "raises exception" do
29
+ it 'raises exception' do
31
30
  expect(app).to_not receive(:call)
32
- expect{subject.call(env)}.to raise_error(::VagrantPlugins::ProviderLibvirt::Errors::NoDomainError,
33
- /No domain found. Domain dummy-vagrant_dummy not found/)
31
+ expect { subject.call(env) }.to raise_error(::VagrantPlugins::ProviderLibvirt::Errors::NoDomainError,
32
+ /No domain found. Domain dummy-vagrant_dummy not found/)
34
33
  end
35
34
  end
36
35
 
37
- context "when machine is booting" do
38
- context "if interrupted looking for IP" do
36
+ context 'when machine is booting' do
37
+ context 'if interrupted looking for IP' do
39
38
  before do
40
39
  env[:interrupted] = true
41
40
  end
42
- it "should exit" do
41
+ it 'should exit' do
43
42
  expect(app).to_not receive(:call)
44
- expect(ui).to receive(:info).with("Waiting for domain to get an IP address...")
43
+ expect(ui).to receive(:info).with('Waiting for domain to get an IP address...')
45
44
  expect(subject.call(env)).to be_nil
46
45
  end
47
46
  end
48
47
 
49
- context "if interrupted waiting for SSH" do
48
+ context 'if interrupted waiting for SSH' do
50
49
  before do
51
50
  allow(domain).to receive(:wait_for).and_return(true)
52
51
  allow(env).to receive(:[]).and_call_original
53
52
  allow(env).to receive(:[]).with(:interrupted).and_return(false, true, true)
54
- allow(env).to receive(:[]).with(:ip_address).and_return("192.168.121.2")
53
+ allow(env).to receive(:[]).with(:ip_address).and_return('192.168.121.2')
55
54
  end
56
- it "should exit after getting IP" do
55
+ it 'should exit after getting IP' do
57
56
  expect(app).to_not receive(:call)
58
- expect(ui).to receive(:info).with("Waiting for domain to get an IP address...")
59
- expect(ui).to receive(:info).with("Waiting for SSH to become available...")
57
+ expect(ui).to receive(:info).with('Waiting for domain to get an IP address...')
58
+ expect(ui).to receive(:info).with('Waiting for SSH to become available...')
60
59
  logger = subject.instance_variable_get(:@logger)
61
60
  expect(logger).to receive(:debug).with(/Searching for IP for MAC address: .*/)
62
- expect(logger).to receive(:info).with("Got IP address 192.168.121.2")
61
+ expect(logger).to receive(:info).with('Got IP address 192.168.121.2')
63
62
  expect(logger).to receive(:info).with(/Time for getting IP: .*/)
64
63
  expect(env[:machine].communicate).to_not receive(:ready?)
65
64
  expect(subject.call(env)).to be_nil
@@ -67,57 +66,57 @@ describe VagrantPlugins::ProviderLibvirt::Action::WaitTillUp do
67
66
  end
68
67
  end
69
68
 
70
- context "when machine boots and ssh available" do
69
+ context 'when machine boots and ssh available' do
71
70
  before do
72
71
  allow(domain).to receive(:wait_for).and_return(true)
73
72
  allow(env).to receive(:[]).and_call_original
74
73
  allow(env).to receive(:[]).with(:interrupted).and_return(false)
75
- allow(env).to receive(:[]).with(:ip_address).and_return("192.168.121.2")
74
+ allow(env).to receive(:[]).with(:ip_address).and_return('192.168.121.2')
76
75
  end
77
- it "should call the next hook" do
76
+ it 'should call the next hook' do
78
77
  expect(app).to receive(:call)
79
- expect(ui).to receive(:info).with("Waiting for domain to get an IP address...")
80
- expect(ui).to receive(:info).with("Waiting for SSH to become available...")
78
+ expect(ui).to receive(:info).with('Waiting for domain to get an IP address...')
79
+ expect(ui).to receive(:info).with('Waiting for SSH to become available...')
81
80
  expect(env[:machine].communicate).to receive(:ready?).and_return(true)
82
81
  expect(subject.call(env)).to be_nil
83
82
  end
84
83
  end
85
84
  end
86
85
 
87
- describe "#recover" do
86
+ describe '#recover' do
88
87
  before do
89
88
  allow_any_instance_of(VagrantPlugins::ProviderLibvirt::Driver).to receive(:get_domain).and_return(machine)
90
- allow_any_instance_of(VagrantPlugins::ProviderLibvirt::Driver).to receive(:state).
91
- and_return(:not_created)
89
+ allow_any_instance_of(VagrantPlugins::ProviderLibvirt::Driver).to receive(:state)
90
+ .and_return(:not_created)
92
91
  allow(env).to receive(:[]).and_call_original
93
92
  end
94
93
 
95
- it "should do nothing by default" do
94
+ it 'should do nothing by default' do
96
95
  expect(env).to_not receive(:[]).with(:action_runner) # cleanup
97
96
  expect(subject.recover(env)).to be_nil
98
97
  end
99
98
 
100
- context "with machine coming up" do
99
+ context 'with machine coming up' do
101
100
  before do
102
- allow_any_instance_of(VagrantPlugins::ProviderLibvirt::Driver).to receive(:state).
103
- and_return(:running)
101
+ allow_any_instance_of(VagrantPlugins::ProviderLibvirt::Driver).to receive(:state)
102
+ .and_return(:running)
104
103
  env[:destroy_on_error] = true
105
104
  end
106
105
 
107
- context "and user has disabled destroy on failure" do
106
+ context 'and user has disabled destroy on failure' do
108
107
  before do
109
108
  env[:destroy_on_error] = false
110
109
  end
111
110
 
112
- it "skips terminate on failure" do
111
+ it 'skips terminate on failure' do
113
112
  expect(env).to_not receive(:[]).with(:action_runner) # cleanup
114
113
  expect(subject.recover(env)).to be_nil
115
114
  end
116
115
  end
117
116
 
118
- context "and using default settings" do
117
+ context 'and using default settings' do
119
118
  let(:runner) { double('runner') }
120
- it "deletes VM on failure" do
119
+ it 'deletes VM on failure' do
121
120
  expect(env).to receive(:[]).with(:action_runner).and_return(runner) # cleanup
122
121
  expect(runner).to receive(:run)
123
122
  expect(subject.recover(env)).to be_nil
@@ -0,0 +1,106 @@
1
+ require 'spec_helper'
2
+ require 'support/sharedcontext'
3
+
4
+ require 'vagrant-libvirt/config'
5
+
6
+ describe VagrantPlugins::ProviderLibvirt::Config do
7
+ include_context 'unit'
8
+
9
+ def assert_invalid
10
+ errors = subject.validate(machine)
11
+ raise "No errors: #{errors.inspect}" if errors.values.any? { |v| !v.empty? }
12
+ end
13
+
14
+ def assert_valid
15
+ errors = subject.validate(machine)
16
+ raise "Errors: #{errors.inspect}" unless errors.values.all?(&:empty?)
17
+ end
18
+
19
+ describe '#validate' do
20
+ it 'is valid with defaults' do
21
+ assert_valid
22
+ end
23
+
24
+ it 'is valid if relative path used for disk' do
25
+ subject.storage :file, path: '../path/to/file.qcow2'
26
+ assert_valid
27
+ end
28
+
29
+ it 'should be invalid if absolute path used for disk' do
30
+ subject.storage :file, path: '/absolute/path/to/file.qcow2'
31
+ assert_invalid
32
+ end
33
+
34
+ context 'with mac defined' do
35
+ let (:vm) { double('vm') }
36
+ let (:networks) { double('networks') }
37
+ before do
38
+ allow(vm).to receive(:networks).and_return(networks)
39
+ allow(machine.config).to receive(:vm).and_return(vm)
40
+ end
41
+
42
+ it 'is valid with valid mac' do
43
+ allow(networks).to receive(:each).and_return([:public, { mac: 'aa:bb:cc:dd:ee:ff' }])
44
+ assert_valid
45
+ end
46
+
47
+ it 'should be invalid if MAC not formatted correctly' do
48
+ allow(networks).to receive(:each).and_return([:public, { mac: 'aabbccddeeff' }])
49
+ assert_invalid
50
+ end
51
+ end
52
+ end
53
+
54
+ describe '#merge' do
55
+ let(:one) { described_class.new }
56
+ let(:two) { described_class.new }
57
+
58
+ subject { one.merge(two) }
59
+
60
+ context 'storage' do
61
+ context 'with disks' do
62
+ context 'assigned specific devices' do
63
+ it 'should merge disks with specific devices' do
64
+ one.storage(:file, device: 'vdb')
65
+ two.storage(:file, device: 'vdc')
66
+ subject.finalize!
67
+ expect(subject.disks).to include(include(device: 'vdb'),
68
+ include(device: 'vdc'))
69
+ end
70
+ end
71
+
72
+ context 'without devices given' do
73
+ it 'should merge disks with different devices assigned automatically' do
74
+ one.storage(:file)
75
+ two.storage(:file)
76
+ subject.finalize!
77
+ expect(subject.disks).to include(include(device: 'vdb'),
78
+ include(device: 'vdc'))
79
+ end
80
+ end
81
+ end
82
+
83
+ context 'with cdroms only' do
84
+ context 'assigned specific devs' do
85
+ it 'should merge disks with specific devices' do
86
+ one.storage(:file, device: :cdrom, dev: 'hda')
87
+ two.storage(:file, device: :cdrom, dev: 'hdb')
88
+ subject.finalize!
89
+ expect(subject.cdroms).to include(include(dev: 'hda'),
90
+ include(dev: 'hdb'))
91
+ end
92
+ end
93
+
94
+ context 'without devs given' do
95
+ it 'should merge cdroms with different devs assigned automatically' do
96
+ one.storage(:file, device: :cdrom)
97
+ two.storage(:file, device: :cdrom)
98
+ subject.finalize!
99
+ expect(subject.cdroms).to include(include(dev: 'hda'),
100
+ include(dev: 'hdb'))
101
+ end
102
+ end
103
+ end
104
+ end
105
+ end
106
+ end
@@ -0,0 +1,125 @@
1
+ <domain type='kvm'>
2
+ <name></name>
3
+ <uuid></uuid>
4
+ <memory></memory>
5
+ <vcpu>1</vcpu>
6
+
7
+
8
+ <cpu mode='custom'>
9
+ <model fallback='allow'>qemu64</model>
10
+ <feature name='AAA' policy='required'/>
11
+ </cpu>
12
+
13
+
14
+ <os>
15
+ <type arch='x86_64' machine='pc-compatible'>hvm</type>
16
+ <loader readonly='yes' type='rom'>/efi/loader</loader>
17
+ <bootmenu enable='yes'/>
18
+ <kernel></kernel>
19
+ <initrd></initrd>
20
+ <cmdline></cmdline>
21
+ </os>
22
+ <features>
23
+ <acpi/>
24
+ <apic/>
25
+ <pae/>
26
+ </features>
27
+ <clock offset='utc'/>
28
+ <devices>
29
+ <emulator>/usr/bin/kvm-spice</emulator>
30
+ <disk type='file' device='disk'>
31
+ <driver name='qemu' type='qcow2' cache='unsafe'/>
32
+ <source file='/var/lib/libvirt/images/test.qcow2'/>
33
+ <target dev='vda' bus='ide'/>
34
+ </disk>
35
+ <disk type='file' device='disk'>
36
+ <driver name='qemu' type='qcow2' cache='default'/>
37
+ <source file='/var/lib/libvirt/images/test-disk1.qcow2'/>
38
+ <target dev='vdb' bus='virtio'/>
39
+ </disk>
40
+ <disk type='file' device='disk'>
41
+ <driver name='qemu' type='qcow2' cache='default'/>
42
+ <source file='/var/lib/libvirt/images/test-disk2.qcow2'/>
43
+ <target dev='vdc' bus='virtio'/>
44
+ </disk>
45
+
46
+ <disk type='file' device='cdrom'>
47
+ <source file=''/>
48
+ <target dev='hda' bus='ide'/>
49
+ <readonly/>
50
+ </disk>
51
+ <disk type='file' device='cdrom'>
52
+ <source file=''/>
53
+ <target dev='hdb' bus='ide'/>
54
+ <readonly/>
55
+ </disk>
56
+
57
+ <serial type='pty'>
58
+ <target port='0'/>
59
+ </serial>
60
+ <console type='pty'>
61
+ <target port='0'/>
62
+ </console>
63
+
64
+ <channel type='unix' >
65
+ <source mode=''
66
+ />
67
+ <target type='virtio'
68
+ name="org.qemu.guest_agent.0"
69
+ />
70
+ </channel>
71
+ <channel type='unix' >
72
+ <source mode=''
73
+ path="/tmp/foo"
74
+ />
75
+ <target type='guestfwd'
76
+ address="192.0.2.42"
77
+ port="4242"
78
+ />
79
+ </channel>
80
+
81
+ <input type='mouse' bus='ps2'/>
82
+
83
+ <graphics type='vnc' port='5900' autoport='yes' listen='127.0.0.1' keymap='en-us' />
84
+ <video>
85
+ <model type='cirrus' vram='9216' heads='1'/>
86
+ </video>
87
+ <rng model='virtio'>
88
+ <backend model='random'>/dev/random</backend>
89
+ </rng>
90
+ <hostdev mode='subsystem' type='pci' managed='yes'>
91
+ <source>
92
+ <address domain='0x0000'
93
+ bus='0x06'
94
+ slot='0x12'
95
+ function='0x5'/>
96
+ </source>
97
+ </hostdev>
98
+ <hostdev mode='subsystem' type='pci' managed='yes'>
99
+ <source>
100
+ <address domain='0x0000'
101
+ bus='0x03'
102
+ slot='0x00'
103
+ function='0x0'/>
104
+ </source>
105
+ </hostdev>
106
+ <hostdev mode='subsystem' type='usb'>
107
+ <source startupPolicy='mandatory'>
108
+ <vendor id='0x1234'/>
109
+ <product id='0xabcd'/>
110
+ <address bus='1' device='2'/>
111
+ </source>
112
+ </hostdev>
113
+ <redirdev bus='usb' type='tcp'>
114
+ </redirdev>
115
+ <redirfilter>
116
+ <usbdev class='0x0b' vendor='0x0b' product='0x0b' version='0x0b' allow='yes'/>
117
+ </redirfilter>
118
+
119
+ <tpm model='tpm-tis'>
120
+ <backend type='passthrough'>
121
+ <device path='/dev/tpm0'/>
122
+ </backend>
123
+ </tpm>
124
+ </devices>
125
+ </domain>
@@ -0,0 +1,44 @@
1
+ <domain type=''>
2
+ <name></name>
3
+ <uuid></uuid>
4
+ <memory></memory>
5
+ <vcpu>1</vcpu>
6
+
7
+
8
+ <cpu mode='host-model'>
9
+ <model fallback='allow'></model>
10
+ </cpu>
11
+
12
+
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
+ <devices>
26
+
27
+
28
+ <serial type='pty'>
29
+ <target port='0'/>
30
+ </serial>
31
+ <console type='pty'>
32
+ <target port='0'/>
33
+ </console>
34
+
35
+
36
+ <input type='mouse' bus='ps2'/>
37
+
38
+ <graphics type='vnc' port='5900' autoport='yes' listen='127.0.0.1' keymap='en-us' />
39
+ <video>
40
+ <model type='cirrus' vram='9216' heads='1'/>
41
+ </video>
42
+
43
+ </devices>
44
+ </domain>
@@ -0,0 +1,69 @@
1
+ require 'support/sharedcontext'
2
+
3
+ require 'vagrant-libvirt/config'
4
+ require 'vagrant-libvirt/util/erb_template'
5
+
6
+ describe 'templates/domain' do
7
+ include_context 'unit'
8
+
9
+ class DomainTemplateHelper < VagrantPlugins::ProviderLibvirt::Config
10
+ include VagrantPlugins::ProviderLibvirt::Util::ErbTemplate
11
+ end
12
+
13
+ let(:domain) { DomainTemplateHelper.new }
14
+ let(:xml_expected) { File.read(File.join(File.dirname(__FILE__), test_file)) }
15
+
16
+ context 'when only defaults used' do
17
+ let(:test_file) { 'domain_defaults.xml' }
18
+ it 'renders template' do
19
+ domain.finalize!
20
+ expect(domain.to_xml('domain')).to eq xml_expected
21
+ end
22
+ end
23
+
24
+ context 'when all settings enabled' do
25
+ before do
26
+ domain.instance_variable_set('@domain_type', 'kvm')
27
+ domain.cpu_mode = 'custom'
28
+ domain.cpu_feature(name: 'AAA', policy: 'required')
29
+ domain.machine_type = 'pc-compatible'
30
+ domain.machine_arch = 'x86_64'
31
+ domain.loader = '/efi/loader'
32
+ domain.boot('network')
33
+ domain.boot('cdrom')
34
+ domain.boot('hd')
35
+ domain.emulator_path = '/usr/bin/kvm-spice'
36
+ domain.instance_variable_set('@domain_volume_path', '/var/lib/libvirt/images/test.qcow2')
37
+ domain.instance_variable_set('@domain_volume_cache', 'unsafe')
38
+ domain.disk_bus = 'ide'
39
+ domain.storage(:file, path: 'test-disk1.qcow2')
40
+ domain.storage(:file, path: 'test-disk2.qcow2')
41
+ domain.disks.each do |disk|
42
+ disk[:absolute_path] = '/var/lib/libvirt/images/' + disk[:path]
43
+ end
44
+ domain.storage(:file, device: :cdrom)
45
+ domain.storage(:file, device: :cdrom)
46
+ domain.channel(type: 'unix',
47
+ target_name: 'org.qemu.guest_agent.0',
48
+ target_type: 'virtio')
49
+ domain.channel(type: 'unix',
50
+ target_type: 'guestfwd',
51
+ target_address: '192.0.2.42',
52
+ target_port: '4242',
53
+ source_path: '/tmp/foo')
54
+ domain.random(model: 'random')
55
+ domain.pci(bus: '0x06', slot: '0x12', function: '0x5')
56
+ domain.pci(bus: '0x03', slot: '0x00', function: '0x0')
57
+ domain.usb(bus: '1', device: '2', vendor: '0x1234', product: '0xabcd')
58
+ domain.redirdev(type: 'tcp', host: 'localhost', port: '4000')
59
+ domain.redirfilter(class: '0x0b', vendor: '0x08e6',
60
+ product: '0x3437', version: '2.00', allow: 'yes')
61
+ domain.tpm_path = '/dev/tpm0'
62
+ end
63
+ let(:test_file) { 'domain_all_settings.xml' }
64
+ it 'renders template' do
65
+ domain.finalize!
66
+ expect(domain.to_xml('domain')).to eq xml_expected
67
+ end
68
+ end
69
+ end