fog-libvirt 0.15.0 → 0.16.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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 3de2f15e870acbea334029209818b107a75f7faefb83d638ef9e36a077a483c4
4
- data.tar.gz: df8b3421cc1958a0891d3bdf96cadb0bf197f9cfef79252587784dcbc971d215
3
+ metadata.gz: 941c7ea65ed8253aeab0ae1b2284d2057cf68d7db28835001c16c6b148e65584
4
+ data.tar.gz: dead71f5518e86f13f4f9d702bedb84f08614c459f96e9382d55ed54e123dab1
5
5
  SHA512:
6
- metadata.gz: 2ceae4dbf135743de2de5b8b413f7d752339699224ea1c15f4c7b560df3e7f327de54dec01010ae46fbec83efa051a28a7d77a6db0ae7798f06a8e63f1b4d731
7
- data.tar.gz: 9f749dddf5019f45ad4c4fc7672ca572157a8fdc9e0ce5024789a08261d5e30a91629832866132554930a4445bbe4ef697cb0afad9f72ec339b5b3045b277c74
6
+ metadata.gz: 9867bd44870aa6fcbf32378f8124a70b2873bdd5074bb644681a1a40be22db8546e770259b552f715944515ab724d87c5f885c71d41ba8f86262d546679635b2
7
+ data.tar.gz: 5fa4b1b63fa25a7387d8d0403c930b0134772d785cffb3660964093080fbfee5edd77f100710d07f31d228ca475ddaa1517913ac88195ac0328d43d3ce044b46
data/Rakefile CHANGED
@@ -34,6 +34,7 @@ end
34
34
  #############################################################################
35
35
 
36
36
  GEM_NAME = "#{name}"
37
+ ENV['COVERAGE'] ||= 'true'
37
38
  task :default => [:test, :minitest]
38
39
 
39
40
  Rake::TestTask.new(:minitest) do |t|
@@ -46,8 +47,7 @@ end
46
47
 
47
48
  desc 'Run tests'
48
49
  task :test do
49
- mock = ENV['FOG_MOCK'] || 'true'
50
- sh("export FOG_MOCK=#{mock} && bundle exec shindont tests")
50
+ sh("bundle exec shindont tests")
51
51
  end
52
52
 
53
53
  desc 'Run mocked tests'
@@ -60,6 +60,11 @@ task :live do
60
60
  sh("export FOG_MOCK=false && bundle exec shindont tests")
61
61
  end
62
62
 
63
+ desc 'Run live libvirt qemu:///session tests'
64
+ task :live_session do
65
+ sh("export FOG_LIBVIRT_URI=qemu:///session && bundle exec rake test minitest")
66
+ end
67
+
63
68
  desc "Open an irb session preloaded with this library"
64
69
  task :console do
65
70
  sh "irb -rubygems -r ./lib/fog/libvirt.rb"
data/fog-libvirt.gemspec CHANGED
@@ -22,7 +22,7 @@ Gem::Specification.new do |s|
22
22
  s.rdoc_options = ["--charset=UTF-8"]
23
23
  s.extra_rdoc_files = %w[README.md]
24
24
 
25
- s.required_ruby_version = '>= 2.7'
25
+ s.required_ruby_version = '>= 3.0'
26
26
 
27
27
  s.add_dependency("fog-core", ">= 1.27.4")
28
28
  s.add_dependency("fog-json")
@@ -259,11 +259,14 @@ module Fog
259
259
  user_data_path = File.join(dir_path, 'user-data')
260
260
  File.write(user_data_path, user_data)
261
261
 
262
- isofile = Tempfile.new(['init', '.iso']).path
262
+ iso_tempfile = Tempfile.new(['init', '.iso'])
263
+ isofile = iso_tempfile.path
263
264
  unless system('xorrisofs', '-output', isofile, '-volid', 'cidata', '-joliet', '-rock', user_data_path, meta_data_path)
264
265
  raise Fog::Errors::Error.new("Couldn't generate cloud-init iso disk with xorrisofs.")
265
266
  end
266
267
  blk.call(isofile)
268
+ ensure
269
+ iso_tempfile&.close!
267
270
  end
268
271
 
269
272
  def create_user_data_iso
@@ -370,7 +373,9 @@ module Fog
370
373
  else
371
374
  is_block = volume.path.start_with?("/dev/")
372
375
  xml.disk(:type => is_block ? "block" : "file", :device => "disk") do
373
- xml.driver(:name => "qemu", :type => volume.format_type)
376
+ driver = xml.driver(:name => "qemu")
377
+ driver[:type] = volume.format_type if volume.format_type
378
+
374
379
  if is_block
375
380
  xml.source(:dev => volume.path)
376
381
  else
@@ -476,7 +481,11 @@ module Fog
476
481
  # if the server has multiple network interface
477
482
  def addresses(service_arg=service, options={})
478
483
  ip_address = nil
479
- if (nic = self.nics&.first)
484
+ # Pick the first nic that actually has a network. Bridge/direct
485
+ # interfaces carry a nil network name, which can't be looked up and
486
+ # never has a libvirt-managed lease, so skip them in favour of a nic
487
+ # that can resolve to an address.
488
+ if (nic = self.nics&.find { |n| n.network })
480
489
  net = service.networks.all(:name => nic.network).first
481
490
  # Assume the lease expiring last is the current IP address
482
491
  ip_address = net&.dhcp_leases(nic.mac)&.max_by { |lse| lse["expirytime"] }&.dig("ipaddr")
@@ -91,7 +91,7 @@ module Fog
91
91
  xml.capacity(capacity_size, :unit => capacity_unit)
92
92
 
93
93
  xml.target do
94
- xml.format(:type => format_type)
94
+ xml.format(:type => format_type) if format_type
95
95
  xml_permissions(xml)
96
96
  end
97
97
 
@@ -9,7 +9,7 @@ module Fog
9
9
  data << network_to_attributes(client.lookup_network_by_name(network_name))
10
10
  end
11
11
  else
12
- data = [network_to_attributes(get_network_by_filter(filter))]
12
+ data = [network_to_attributes(get_network_by_filter(filter))].compact
13
13
  end
14
14
  data
15
15
  end
@@ -21,6 +21,8 @@ module Fog
21
21
  when :uuid
22
22
  client.lookup_network_by_uuid(filter[:uuid])
23
23
  when :name
24
+ return nil if filter[:name].nil?
25
+
24
26
  client.lookup_network_by_name(filter[:name])
25
27
  end
26
28
  end
@@ -1,5 +1,5 @@
1
1
  module Fog
2
2
  module Libvirt
3
- VERSION = '0.15.0'
3
+ VERSION = '0.16.0'
4
4
  end
5
5
  end
@@ -0,0 +1,33 @@
1
+ require_relative "../test_helper"
2
+
3
+ class NetworkTest < Minitest::Test
4
+ def setup
5
+ @network = Fog::Compute[:libvirt].networks.new(:name => "default", :uuid => "dd8fe884-6c02-601e-7551-cca97df1c5df", :bridge_name => "virbr0")
6
+ end
7
+
8
+ def test_model
9
+ assert_kind_of Fog::Libvirt::Compute::Network, @network
10
+
11
+ assert @network.respond_to? "reload"
12
+ assert @network.respond_to? "dhcp_leases"
13
+
14
+ assert_kind_of Array, @network.dhcp_leases("aa:bb:cc:dd:ee:ff", 0) if Fog.mock?
15
+
16
+ attributes = [:name, :uuid, :bridge_name]
17
+ attributes.each do |attribute|
18
+ assert @network.respond_to? attribute
19
+ assert @network.attributes.key? attribute
20
+ end
21
+ end
22
+
23
+ def test_to_xml
24
+ expected = <<~NETWORK
25
+ <?xml version="1.0"?>
26
+ <network>
27
+ <name>default</name>
28
+ <bridge name="virbr0" stp="on" delay="0"/>
29
+ </network>
30
+ NETWORK
31
+ assert_equal expected, @network.to_xml
32
+ end
33
+ end
@@ -0,0 +1,40 @@
1
+ require 'test_helper'
2
+
3
+ # Bridge and direct interfaces have a nil network name. #addresses used to
4
+ # pass that nil straight into a network lookup, which raised. It should instead
5
+ # skip network-less nics and resolve an address from a nic that has one.
6
+ class NilNetworkAddressTest < Minitest::Test
7
+ def setup
8
+ @compute = Fog::Compute[:libvirt]
9
+ @server = @compute.servers.new(:name => "test")
10
+ end
11
+
12
+ def test_returns_nil_without_raising_when_only_nic_has_no_network
13
+ bridge_nic = stub(:network => nil, :mac => "52:54:00:aa:bb:cc")
14
+ @server.stubs(:nics).returns([bridge_nic])
15
+ # No network is ever looked up, so the connection is never touched.
16
+ @server.service.expects(:networks).never
17
+
18
+ result = @server.send(:addresses)
19
+
20
+ assert_nil result[:public].first
21
+ assert_nil result[:private].first
22
+ end
23
+
24
+ def test_skips_network_less_nic_and_resolves_address_from_next
25
+ bridge_nic = stub(:network => nil, :mac => "52:54:00:aa:bb:cc")
26
+ nat_nic = stub(:network => "default", :mac => "52:54:00:01:02:03")
27
+ @server.stubs(:nics).returns([bridge_nic, nat_nic])
28
+
29
+ net = stub(:name => "default")
30
+ net.stubs(:dhcp_leases).with("52:54:00:01:02:03").returns([{ "expirytime" => 1000, "ipaddr" => "192.168.122.10" }])
31
+ networks = stub
32
+ networks.stubs(:all).with(:name => "default").returns([net])
33
+ @server.service.stubs(:networks).returns(networks)
34
+
35
+ result = @server.send(:addresses)
36
+
37
+ assert_equal "192.168.122.10", result[:public].first
38
+ assert_equal "192.168.122.10", result[:private].first
39
+ end
40
+ end
@@ -1,3 +1,8 @@
1
+ unless ['false', 'no', '0'].include?(ENV['COVERAGE'].to_s.downcase)
2
+ require 'simplecov'
3
+ SimpleCov.start
4
+ end
5
+
1
6
  require 'minitest/autorun'
2
7
  require 'mocha/minitest'
3
8
  require 'fileutils'
@@ -12,7 +17,11 @@ FileUtils.rm_f Dir.glob 'test/tmp/*.tmp'
12
17
 
13
18
  require 'fog/libvirt'
14
19
 
15
- Fog.mock!
16
- Fog.credentials = {
17
- :libvirt_uri => 'test:///default',
18
- }.merge(Fog.credentials)
20
+ Fog.credentials[:libvirt_uri] = ENV.fetch("FOG_LIBVIRT_URI", "test:///default")
21
+
22
+ def real_libvirt?
23
+ Fog.credentials[:libvirt_uri].start_with?("qemu")
24
+ end
25
+
26
+ enable_mocking = ENV.fetch("FOG_MOCK") { (!real_libvirt?).to_s }
27
+ Fog.mock! unless ["false", "no", "0"].include?(enable_mocking)
data/tests/helper.rb CHANGED
@@ -1,6 +1,12 @@
1
1
  ENV['FOG_RC'] = ENV['FOG_RC'] || File.expand_path('../.fog', __FILE__)
2
2
  ENV['FOG_CREDENTIAL'] = ENV['FOG_CREDENTIAL'] || 'default'
3
3
 
4
+ unless ['false', 'no', '0'].include?(ENV['COVERAGE'].to_s.downcase)
5
+ require 'simplecov'
6
+ SimpleCov.start
7
+ SimpleCov.command_name 'Shindo'
8
+ end
9
+
4
10
  require 'fog/libvirt'
5
11
 
6
12
  Excon.defaults.merge!(:debug_request => true, :debug_response => true)
@@ -15,3 +21,7 @@ if Fog.mocking?
15
21
  else
16
22
  FOG_TESTING_TIMEOUT = Fog.timeout
17
23
  end
24
+
25
+ Thread.current[:tags] ||= []
26
+ Thread.current[:tags] << "-requires-mocks" unless Fog.mock?
27
+ Thread.current[:tags] << (real_libvirt? ? "-requires-test-driver" : "-requires-real-libvirt")
@@ -2,13 +2,11 @@
2
2
  #
3
3
  # FOG_MOCK=true fog
4
4
 
5
- if ENV["FOG_MOCK"] == "true"
6
- Fog.mock!
7
- end
5
+ Fog.credentials[:libvirt_uri] = ENV.fetch("FOG_LIBVIRT_URI", "test:///default")
8
6
 
9
- # if in mocked mode, fill in some fake credentials for us
10
- if Fog.mock?
11
- Fog.credentials = {
12
- :libvirt_uri => 'test:///default',
13
- }.merge(Fog.credentials)
7
+ def real_libvirt?
8
+ Fog.credentials[:libvirt_uri].start_with?("qemu")
14
9
  end
10
+
11
+ enable_mocking = ENV.fetch("FOG_MOCK") { (!real_libvirt?).to_s }
12
+ Fog.mock! unless ["false", "no", "0"].include?(enable_mocking)
@@ -5,7 +5,7 @@ Shindo.tests('Fog::Compute[:libvirt] | networks collection', ['libvirt']) do
5
5
  tests('The networks collection') do
6
6
  test('should be a kind of Fog::Libvirt::Compute::Networks') { networks.kind_of? Fog::Libvirt::Compute::Networks }
7
7
  tests('should be able to reload itself').succeeds { networks.reload }
8
- tests('should be able to get a model') do
8
+ tests('should be able to get a model', 'requires-test-driver') do
9
9
  tests('by instance id').succeeds { networks.get networks.first.uuid }
10
10
  end
11
11
  end
@@ -1,6 +1,6 @@
1
1
  Shindo.tests('Fog::Compute[:libvirt] | nic model', ['libvirt']) do
2
2
 
3
- server = Fog::Compute[:libvirt].servers.create(:name => Fog::Mock.random_letters(8))
3
+ server = Fog::Compute[:libvirt].servers.create(:name => "fog-nic-test-#{Fog::Mock.random_letters(8)}")
4
4
  nic = server.nics.first
5
5
 
6
6
  tests('The nic model should') do
@@ -28,5 +28,6 @@ Shindo.tests('Fog::Compute[:libvirt] | nic model', ['libvirt']) do
28
28
  end
29
29
  test('be a kind of Fog::Libvirt::Compute::Nic') { nic.kind_of? Fog::Libvirt::Compute::Nic }
30
30
  end
31
-
31
+ ensure
32
+ server&.destroy(:destroy_volumes => true)
32
33
  end
@@ -2,8 +2,8 @@ Shindo.tests('Fog::Compute[:libvirt] | server model', ['libvirt']) do
2
2
 
3
3
  servers = Fog::Compute[:libvirt].servers
4
4
  # Match the mac in dhcp_leases mock
5
- nics = Fog.mock? ? [{ :type => 'network', :network => 'default', :mac => 'aa:bb:cc:dd:ee:ff' }] : nil
6
- server = servers.create(:name => Fog::Mock.random_letters(8), :nics => nics)
5
+ nics = Fog.mock? ? [{ :type => 'network', :network => 'default', :mac => 'aa:bb:cc:dd:ee:ff' }] : []
6
+ server = servers.create(:name => "fog-server-test-#{Fog::Mock.random_letters(8)}", :nics => nics)
7
7
 
8
8
  tests('The server model should') do
9
9
  tests('have the action') do
@@ -24,7 +24,7 @@ Shindo.tests('Fog::Compute[:libvirt] | server model', ['libvirt']) do
24
24
  }
25
25
  end
26
26
  end
27
- tests('have an ip_address action that') do
27
+ tests('have an ip_address action that', 'requires-mocks') do
28
28
  test('returns the latest IP address lease') { server.public_ip_address() == '1.2.5.6' }
29
29
  end
30
30
  tests('have attributes') do
@@ -66,7 +66,9 @@ Shindo.tests('Fog::Compute[:libvirt] | server model', ['libvirt']) do
66
66
  end
67
67
 
68
68
  test('can destroy') do
69
- servers.create(:name => Fog::Mock.random_letters(8)).destroy
69
+ server_name = "fog-test-destroy-#{Fog::Mock.random_letters(8)}"
70
+ servers.create(:name => server_name).destroy(:destroy_volumes => true)
71
+ servers.all.none? { |server| server.name == server_name }
70
72
  end
71
73
 
72
74
  test('be a kind of Fog::Libvirt::Compute::Server') { server.kind_of? Fog::Libvirt::Compute::Server }
@@ -78,7 +80,7 @@ Shindo.tests('Fog::Compute[:libvirt] | server model', ['libvirt']) do
78
80
  xml.match?(/<disk type="file" device="disk">/) && xml.match?(%r{<source file="#{server.volumes.first.path}"/>})
79
81
  end
80
82
  test("with disk of type block") do
81
- server = Fog::Libvirt::Compute::Server.new(
83
+ disk_server = Fog::Libvirt::Compute::Server.new(
82
84
  {
83
85
  :nics => [],
84
86
  :volumes => [
@@ -86,20 +88,20 @@ Shindo.tests('Fog::Compute[:libvirt] | server model', ['libvirt']) do
86
88
  ]
87
89
  }
88
90
  )
89
- xml = server.to_xml
91
+ xml = disk_server.to_xml
90
92
  xml.match?(/<disk type="block" device="disk">/) && xml.match?(%r{<source dev="/dev/sda"/>})
91
93
  end
92
- test("with q35 machine type on x86_64") { server.to_xml.match?(%r{<type arch="x86_64" machine="q35">hvm</type>}) }
94
+ test("with q35 machine type on x86_64") { server.to_xml.include?('<type arch="x86_64" machine="q35">') }
93
95
  end
94
96
  test("with efi firmware") do
95
- server = Fog::Libvirt::Compute::Server.new(
97
+ efi_server = Fog::Libvirt::Compute::Server.new(
96
98
  {
97
99
  :firmware => "efi",
98
100
  :nics => [],
99
101
  :volumes => []
100
102
  }
101
103
  )
102
- xml = server.to_xml
104
+ xml = efi_server.to_xml
103
105
 
104
106
  os_firmware = xml.include?('<os firmware="efi">')
105
107
  secure_boot = xml.include?('<feature name="secure-boot" enabled="no"/>')
@@ -108,7 +110,7 @@ Shindo.tests('Fog::Compute[:libvirt] | server model', ['libvirt']) do
108
110
  os_firmware && secure_boot && loader_attributes
109
111
  end
110
112
  test("with secure boot enabled") do
111
- server = Fog::Libvirt::Compute::Server.new(
113
+ secure_server = Fog::Libvirt::Compute::Server.new(
112
114
  {
113
115
  :firmware => "efi",
114
116
  :firmware_features => {
@@ -120,7 +122,7 @@ Shindo.tests('Fog::Compute[:libvirt] | server model', ['libvirt']) do
120
122
  :volumes => []
121
123
  }
122
124
  )
123
- xml = server.to_xml
125
+ xml = secure_server.to_xml
124
126
 
125
127
  os_firmware = xml.include?('<os firmware="efi">')
126
128
  secure_boot = xml.include?('<feature name="secure-boot" enabled="yes"/>')
@@ -129,5 +131,44 @@ Shindo.tests('Fog::Compute[:libvirt] | server model', ['libvirt']) do
129
131
 
130
132
  os_firmware && secure_boot && enrolled_keys && loader_attributes
131
133
  end
134
+
135
+ test("with volumes") do
136
+ pool = Fog::Compute[:libvirt].pools.create(
137
+ :persistent => true,
138
+ :xml => <<~XML
139
+ <pool type='logical'>
140
+ <name>fog-test-lvm-pool</name>
141
+ <source>
142
+ <name>vg_storage01</name>
143
+ <format type='lvm2'/>
144
+ </source>
145
+ <target>
146
+ <path>/dev/vg_storage01</path>
147
+ </target>
148
+ </pool>
149
+ XML
150
+ )
151
+ volume_server = Fog::Compute[:libvirt].servers.new(
152
+ :nics => [],
153
+ :volumes => [
154
+ {
155
+ :path => "/dev/vg_storage01/volume01",
156
+ :pool_name => pool.name
157
+ }
158
+ ]
159
+ )
160
+ volume_server.volumes.each do |volume|
161
+ volume.save
162
+ # mock driver doesn't simulate the real thing
163
+ # LVM doesn't have a volume type
164
+ volume.format_type = nil
165
+ end
166
+ !volume_server.save.nil?
167
+ ensure
168
+ volume_server&.destroy(:destroy_volumes => true)
169
+ pool&.destroy
170
+ end
132
171
  end
172
+ ensure
173
+ server&.destroy(:destroy_volumes => true)
133
174
  end
@@ -1,6 +1,6 @@
1
1
  Shindo.tests('Fog::Compute[:libvirt] | volume model', ['libvirt']) do
2
2
 
3
- volume = Fog::Compute[:libvirt].volumes.create(:name => 'fog_test')
3
+ volume = Fog::Compute[:libvirt].volumes.create(:name => 'fog_test', :capacity => '1G')
4
4
 
5
5
  tests('The volume model should') do
6
6
  tests('have attributes') do
@@ -29,10 +29,12 @@ Shindo.tests('Fog::Compute[:libvirt] | volume model', ['libvirt']) do
29
29
 
30
30
  tests('Cloning volumes should') do
31
31
  test('respond to clone_volume') { volume.respond_to? :clone_volume }
32
- new_vol = volume.clone_volume('new_vol')
32
+ new_vol = volume.clone_volume('fog-test-new_vol')
33
33
  # We'd like to test that the :name attr has changed, but it seems that's
34
34
  # not possible, so we can at least check the new_vol xml exists properly
35
35
  test('succeed') { volume.xml == new_vol.xml }
36
+ ensure
37
+ new_vol&.destroy
36
38
  end
37
39
 
38
40
  test('to_xml') do
@@ -42,7 +44,7 @@ Shindo.tests('Fog::Compute[:libvirt] | volume model', ['libvirt']) do
42
44
  <volume>
43
45
  <name>fog_test</name>
44
46
  <allocation unit="G">1</allocation>
45
- <capacity unit="G">10</capacity>
47
+ <capacity unit="G">1</capacity>
46
48
  <target>
47
49
  <format type="raw"/>
48
50
  <permissions>
@@ -55,4 +57,6 @@ Shindo.tests('Fog::Compute[:libvirt] | volume model', ['libvirt']) do
55
57
  volume.to_xml == expected
56
58
  end
57
59
  end
60
+ ensure
61
+ volume&.destroy
58
62
  end
@@ -2,7 +2,7 @@ Shindo.tests('Fog::Compute[:libvirt] | volumes collection', ['libvirt']) do
2
2
 
3
3
  volumes = Fog::Compute[:libvirt].volumes
4
4
 
5
- volumes.create(:name => 'test')
5
+ created_volume = volumes.create(:name => 'fog-test-volume')
6
6
 
7
7
  tests('The volumes collection') do
8
8
  test('should not be empty') { not volumes.empty? }
@@ -11,7 +11,8 @@ Shindo.tests('Fog::Compute[:libvirt] | volumes collection', ['libvirt']) do
11
11
  tests('should be able to get a model') do
12
12
  tests('by instance uuid').succeeds { volumes.get volumes.first.id }
13
13
  end
14
- test('filtered should be empty') { volumes.all(:name => "does-not-exist").empty? }
14
+ test('filtered should be empty') { volumes.all(:name => "fog-test-volume-does-not-exist").empty? }
15
15
  end
16
-
16
+ ensure
17
+ created_volume&.destroy
17
18
  end
@@ -1,7 +1,9 @@
1
1
  Shindo.tests("Fog::Compute[:libvirt] | create_domain request", 'libvirt') do
2
2
 
3
3
  compute = Fog::Compute[:libvirt]
4
- xml = compute.servers.new( :nics => [{:bridge => "br180"}]).to_xml
4
+
5
+ server = compute.servers.new(:name => "fog-test-create-server", :nics => [])
6
+ xml = server.to_xml
5
7
 
6
8
  tests("Create Domain") do
7
9
  response = compute.create_domain(xml)
@@ -17,5 +19,7 @@ Shindo.tests("Fog::Compute[:libvirt] | create_domain request", 'libvirt') do
17
19
  test("error should be a kind of Libvirt::Error") { e.kind_of? Libvirt::Error}
18
20
  end
19
21
  end
20
-
22
+ ensure
23
+ server_uuid = compute.servers.all(:name => server.name).first&.uuid
24
+ compute.servers.service.vm_action(server_uuid, :destroy) if server_uuid
21
25
  end
@@ -1,11 +1,14 @@
1
1
  Shindo.tests("Fog::Compute[:libvirt] | define_domain request", 'libvirt') do
2
2
 
3
3
  compute = Fog::Compute[:libvirt]
4
- xml = compute.servers.new().to_xml
4
+ server = compute.servers.new(:name => "fog-test-define-server", :nics => [])
5
+ xml = server.to_xml
5
6
 
6
7
  tests("Define Domain") do
7
8
  response = compute.define_domain(xml)
8
9
  test("should be a kind of Libvirt::Domain") { response.kind_of? Libvirt::Domain}
9
10
  end
10
-
11
+ ensure
12
+ server_uuid = compute.servers.all(:name => server.name).first&.uuid
13
+ compute.servers.service.vm_action(server_uuid, :undefine) if server_uuid
11
14
  end
@@ -2,7 +2,7 @@ Shindo.tests("Fog::Compute[:libvirt] | dhcp_leases request", 'libvirt') do
2
2
 
3
3
  compute = Fog::Compute[:libvirt]
4
4
 
5
- tests("DHCP leases response") do
5
+ tests("DHCP leases response", "requires-mocks") do
6
6
  response = compute.dhcp_leases("fbd4ac68-cbea-4f95-86ed-22953fd92384", "99:88:77:66:55:44", 0)
7
7
  test("should be an array") { response.kind_of? Array }
8
8
  test("should have one element") { response.length == 1 }
@@ -41,7 +41,9 @@ Shindo.tests("Fog::Compute[:libvirt] | list_pools request", 'libvirt') do
41
41
  tests("Lists Pools") do
42
42
  response = compute.list_pools
43
43
  test("should be an array") { response.kind_of? Array }
44
- test("should have two pools") { response.length == 1 }
44
+ tests("Test Driver", "requires-test-driver") do
45
+ test("should have a pool") { response.length == 1 }
46
+ end
45
47
  end
46
48
 
47
49
  tests("Handle Inactive Pools") do
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fog-libvirt
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.15.0
4
+ version: 0.16.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - geemus (Wesley Beary)
@@ -268,6 +268,8 @@ files:
268
268
  - lib/fog/libvirt/requests/compute/vm_action.rb
269
269
  - lib/fog/libvirt/requests/compute/volume_action.rb
270
270
  - lib/fog/libvirt/version.rb
271
+ - minitests/network/network_test.rb
272
+ - minitests/server/nil_network_address_test.rb
271
273
  - minitests/server/user_data_iso_test.rb
272
274
  - minitests/test_helper.rb
273
275
  - tests/helper.rb
@@ -278,7 +280,6 @@ files:
278
280
  - tests/libvirt/compute_tests.rb
279
281
  - tests/libvirt/models/compute/interface_tests.rb
280
282
  - tests/libvirt/models/compute/interfaces_tests.rb
281
- - tests/libvirt/models/compute/network_tests.rb
282
283
  - tests/libvirt/models/compute/networks_tests.rb
283
284
  - tests/libvirt/models/compute/nic_tests.rb
284
285
  - tests/libvirt/models/compute/nics_tests.rb
@@ -306,14 +307,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
306
307
  requirements:
307
308
  - - ">="
308
309
  - !ruby/object:Gem::Version
309
- version: '2.7'
310
+ version: '3.0'
310
311
  required_rubygems_version: !ruby/object:Gem::Requirement
311
312
  requirements:
312
313
  - - ">="
313
314
  - !ruby/object:Gem::Version
314
315
  version: '0'
315
316
  requirements: []
316
- rubygems_version: 3.6.9
317
+ rubygems_version: 4.0.22
317
318
  specification_version: 2
318
319
  summary: Module for the 'fog' gem to support libvirt
319
320
  test_files:
@@ -325,7 +326,6 @@ test_files:
325
326
  - tests/libvirt/compute_tests.rb
326
327
  - tests/libvirt/models/compute/interface_tests.rb
327
328
  - tests/libvirt/models/compute/interfaces_tests.rb
328
- - tests/libvirt/models/compute/network_tests.rb
329
329
  - tests/libvirt/models/compute/networks_tests.rb
330
330
  - tests/libvirt/models/compute/nic_tests.rb
331
331
  - tests/libvirt/models/compute/nics_tests.rb
@@ -1,43 +0,0 @@
1
- Shindo.tests('Fog::Compute[:libvirt] | network model', ['libvirt']) do
2
-
3
- networks = Fog::Compute[:libvirt].networks
4
- network = networks.first
5
-
6
- tests('The network model should') do
7
- tests('have the action') do
8
- test('reload') { network.respond_to? 'reload' }
9
- test('dhcp_leases') { network.respond_to? 'dhcp_leases' }
10
- end
11
- tests('have a dhcp_leases action that') do
12
- test('returns an array') { network.dhcp_leases('aa:bb:cc:dd:ee:ff', 0).kind_of? Array }
13
- end
14
- tests('have attributes') do
15
- model_attribute_hash = network.attributes
16
- attributes = [ :name, :uuid, :bridge_name]
17
- tests("The network model should respond to") do
18
- attributes.each do |attribute|
19
- test("#{attribute}") { network.respond_to? attribute }
20
- end
21
- end
22
- tests("The attributes hash should have key") do
23
- attributes.each do |attribute|
24
- test("#{attribute}") { model_attribute_hash.key? attribute }
25
- end
26
- end
27
- end
28
- test('be a kind of Fog::Libvirt::Compute::Network') { network.kind_of? Fog::Libvirt::Compute::Network }
29
- end
30
-
31
- tests("to_xml") do
32
- test("default") do
33
- expected = <<~NETWORK
34
- <?xml version="1.0"?>
35
- <network>
36
- <name>default</name>
37
- <bridge name="virbr0" stp="on" delay="0"/>
38
- </network>
39
- NETWORK
40
- network.to_xml == expected
41
- end
42
- end
43
- end