fog-libvirt-csem 0.9.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/CONTRIBUTORS.md +24 -0
- data/Gemfile +9 -0
- data/LICENSE.md +20 -0
- data/README.md +83 -0
- data/Rakefile +127 -0
- data/fog-libvirt-csem.gemspec +49 -0
- data/lib/fog/bin/libvirt.rb +58 -0
- data/lib/fog/libvirt/compute.rb +140 -0
- data/lib/fog/libvirt/models/compute/README.md +92 -0
- data/lib/fog/libvirt/models/compute/interface.rb +25 -0
- data/lib/fog/libvirt/models/compute/interfaces.rb +20 -0
- data/lib/fog/libvirt/models/compute/network.rb +33 -0
- data/lib/fog/libvirt/models/compute/networks.rb +20 -0
- data/lib/fog/libvirt/models/compute/nic.rb +50 -0
- data/lib/fog/libvirt/models/compute/nics.rb +12 -0
- data/lib/fog/libvirt/models/compute/node.rb +29 -0
- data/lib/fog/libvirt/models/compute/nodes.rb +20 -0
- data/lib/fog/libvirt/models/compute/pool.rb +84 -0
- data/lib/fog/libvirt/models/compute/pools.rb +20 -0
- data/lib/fog/libvirt/models/compute/server.rb +514 -0
- data/lib/fog/libvirt/models/compute/servers.rb +21 -0
- data/lib/fog/libvirt/models/compute/templates/network.xml.erb +6 -0
- data/lib/fog/libvirt/models/compute/templates/pool.xml.erb +6 -0
- data/lib/fog/libvirt/models/compute/templates/server.xml.erb +155 -0
- data/lib/fog/libvirt/models/compute/templates/volume.xml.erb +30 -0
- data/lib/fog/libvirt/models/compute/util/uri.rb +138 -0
- data/lib/fog/libvirt/models/compute/util/util.rb +32 -0
- data/lib/fog/libvirt/models/compute/volume.rb +129 -0
- data/lib/fog/libvirt/models/compute/volumes.rb +20 -0
- data/lib/fog/libvirt/requests/compute/clone_volume.rb +18 -0
- data/lib/fog/libvirt/requests/compute/create_domain.rb +17 -0
- data/lib/fog/libvirt/requests/compute/create_volume.rb +16 -0
- data/lib/fog/libvirt/requests/compute/define_domain.rb +17 -0
- data/lib/fog/libvirt/requests/compute/define_pool.rb +16 -0
- data/lib/fog/libvirt/requests/compute/destroy_interface.rb +18 -0
- data/lib/fog/libvirt/requests/compute/destroy_network.rb +17 -0
- data/lib/fog/libvirt/requests/compute/dhcp_leases.rb +37 -0
- data/lib/fog/libvirt/requests/compute/get_node_info.rb +37 -0
- data/lib/fog/libvirt/requests/compute/libversion.rb +18 -0
- data/lib/fog/libvirt/requests/compute/list_domains.rb +128 -0
- data/lib/fog/libvirt/requests/compute/list_interfaces.rb +57 -0
- data/lib/fog/libvirt/requests/compute/list_networks.rb +63 -0
- data/lib/fog/libvirt/requests/compute/list_pool_volumes.rb +19 -0
- data/lib/fog/libvirt/requests/compute/list_pools.rb +71 -0
- data/lib/fog/libvirt/requests/compute/list_volumes.rb +106 -0
- data/lib/fog/libvirt/requests/compute/mock_files/domain.xml +40 -0
- data/lib/fog/libvirt/requests/compute/pool_action.rb +19 -0
- data/lib/fog/libvirt/requests/compute/update_autostart.rb +18 -0
- data/lib/fog/libvirt/requests/compute/update_display.rb +36 -0
- data/lib/fog/libvirt/requests/compute/upload_volume.rb +31 -0
- data/lib/fog/libvirt/requests/compute/vm_action.rb +19 -0
- data/lib/fog/libvirt/requests/compute/volume_action.rb +18 -0
- data/lib/fog/libvirt/version.rb +5 -0
- data/lib/fog/libvirt.rb +16 -0
- data/minitests/server/server_test.rb +64 -0
- data/minitests/server/user_data_iso_test.rb +77 -0
- data/minitests/test_helper.rb +18 -0
- data/tests/helper.rb +17 -0
- data/tests/helpers/formats_helper.rb +100 -0
- data/tests/helpers/formats_helper_tests.rb +107 -0
- data/tests/helpers/mock_helper.rb +14 -0
- data/tests/helpers/succeeds_helper.rb +9 -0
- data/tests/libvirt/compute_tests.rb +19 -0
- data/tests/libvirt/models/compute/interface_tests.rb +27 -0
- data/tests/libvirt/models/compute/interfaces_tests.rb +14 -0
- data/tests/libvirt/models/compute/network_tests.rb +31 -0
- data/tests/libvirt/models/compute/networks_tests.rb +13 -0
- data/tests/libvirt/models/compute/nic_tests.rb +31 -0
- data/tests/libvirt/models/compute/nics_tests.rb +10 -0
- data/tests/libvirt/models/compute/pool_tests.rb +27 -0
- data/tests/libvirt/models/compute/pools_tests.rb +13 -0
- data/tests/libvirt/models/compute/server_tests.rb +63 -0
- data/tests/libvirt/models/compute/servers_tests.rb +14 -0
- data/tests/libvirt/models/compute/volume_tests.rb +38 -0
- data/tests/libvirt/models/compute/volumes_tests.rb +15 -0
- data/tests/libvirt/requests/compute/create_domain_tests.rb +21 -0
- data/tests/libvirt/requests/compute/define_domain_tests.rb +11 -0
- data/tests/libvirt/requests/compute/dhcp_leases_tests.rb +15 -0
- data/tests/libvirt/requests/compute/update_autostart_tests.rb +12 -0
- data/tests/libvirt/requests/compute/update_display.rb +13 -0
- metadata +335 -0
data/lib/fog/libvirt.rb
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
require 'fog/core'
|
2
|
+
require 'fog/xml'
|
3
|
+
require 'fog/json'
|
4
|
+
require 'libvirt'
|
5
|
+
|
6
|
+
require File.expand_path('../libvirt/version', __FILE__)
|
7
|
+
|
8
|
+
module Fog
|
9
|
+
module Libvirt
|
10
|
+
extend Fog::Provider
|
11
|
+
|
12
|
+
autoload :Compute, File.expand_path('../libvirt/compute', __FILE__)
|
13
|
+
|
14
|
+
service(:compute, 'Compute')
|
15
|
+
end
|
16
|
+
end
|
@@ -0,0 +1,64 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
class ServerTest < Minitest::Test
|
4
|
+
def setup
|
5
|
+
@compute = Fog::Compute[:libvirt]
|
6
|
+
@server = @compute.servers.new(:name => "test")
|
7
|
+
end
|
8
|
+
|
9
|
+
def test_addresses_calls_compat_version_for_no_dhcp_leases_support
|
10
|
+
network = Libvirt::Network.new
|
11
|
+
@compute.expects(:networks).returns([network])
|
12
|
+
network.expects(:dhcp_leases).raises(NoMethodError)
|
13
|
+
@server.expects(:addresses_ip_command).returns(true)
|
14
|
+
|
15
|
+
@server.send(:addresses)
|
16
|
+
end
|
17
|
+
|
18
|
+
def test_addresses_calls_compat_version_for_older_libvirt
|
19
|
+
network = Libvirt::Network.new
|
20
|
+
@compute.expects(:libversion).returns(1002007)
|
21
|
+
@compute.expects(:networks).returns([network])
|
22
|
+
network.expects(:dhcp_leases).returns(true)
|
23
|
+
@server.expects(:addresses_ip_command).returns(true)
|
24
|
+
|
25
|
+
@server.send(:addresses)
|
26
|
+
end
|
27
|
+
|
28
|
+
def test_addresses_calls_compat_version_for_newer_libvirt
|
29
|
+
network = Libvirt::Network.new
|
30
|
+
@compute.expects(:libversion).returns(1002008)
|
31
|
+
@compute.expects(:networks).returns([network])
|
32
|
+
network.expects(:dhcp_leases).returns(true)
|
33
|
+
@server.expects(:addresses_dhcp).returns(true)
|
34
|
+
|
35
|
+
@server.send(:addresses)
|
36
|
+
end
|
37
|
+
|
38
|
+
def test_ssh_ip_command_success
|
39
|
+
fog_ssh = MiniTest::Mock.new
|
40
|
+
result = MiniTest::Mock.new
|
41
|
+
result.expect(:status, 0)
|
42
|
+
result.expect(:stdout, "any_ip")
|
43
|
+
fog_ssh.expect(:run, [result], [String])
|
44
|
+
uri = ::Fog::Libvirt::Util::URI.new('qemu+ssh://localhost:22?keyfile=nofile')
|
45
|
+
Fog::SSH.stub(:new, fog_ssh) do
|
46
|
+
@server.send(:ssh_ip_command, "test command", uri)
|
47
|
+
end
|
48
|
+
fog_ssh.verify
|
49
|
+
end
|
50
|
+
|
51
|
+
def test_local_ip_command_success
|
52
|
+
proc_info = MiniTest::Mock.new
|
53
|
+
proc_info.expect(:each_line, "127.0.0.1")
|
54
|
+
proc_info.expect(:pid, 0)
|
55
|
+
status = MiniTest::Mock.new
|
56
|
+
status.expect(:exitstatus, 0)
|
57
|
+
Process.stubs(:waitpid2).returns([0, status])
|
58
|
+
IO.stub(:popen, true, proc_info) do
|
59
|
+
@server.send(:local_ip_command, "test command")
|
60
|
+
end
|
61
|
+
proc_info.verify
|
62
|
+
status.verify
|
63
|
+
end
|
64
|
+
end
|
@@ -0,0 +1,77 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
class UserDataIsoTest < Minitest::Test
|
4
|
+
def setup
|
5
|
+
@compute = Fog::Compute[:libvirt]
|
6
|
+
@server = @compute.servers.new(:name => "test")
|
7
|
+
@test_data = "test data"
|
8
|
+
end
|
9
|
+
|
10
|
+
def test_contains_meta_data_file
|
11
|
+
@server.stubs(:system).returns(true)
|
12
|
+
in_a_temp_dir do |d|
|
13
|
+
@server.generate_config_iso_in_dir(d, @test_data) {|iso| assert File.exist?(File.join(d, 'meta-data')) }
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
def test_contains_user_data_file
|
18
|
+
@server.stubs(:system).returns(true)
|
19
|
+
in_a_temp_dir do |d|
|
20
|
+
@server.generate_config_iso_in_dir(d, @test_data) do |iso|
|
21
|
+
assert File.exist?(File.join(d, 'user-data'))
|
22
|
+
assert_equal @test_data, File.read(File.join(d, 'user-data'))
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
def test_iso_is_generated
|
28
|
+
in_a_temp_dir do |d|
|
29
|
+
@server.expects(:system).with(regexp_matches(/^genisoimage/)).returns(true)
|
30
|
+
@server.generate_config_iso_in_dir(d, @test_data) {|iso| }
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
def test_volume_is_created_during_user_data_iso_generation
|
35
|
+
@server.stubs(:system).returns(true)
|
36
|
+
Fog::Libvirt::Compute::Volumes.any_instance.expects(:create).
|
37
|
+
with(has_entries(:name => @server.cloud_init_volume_name)).
|
38
|
+
returns(@compute.volumes.new)
|
39
|
+
Fog::Libvirt::Compute::Volume.any_instance.stubs(:upload_image)
|
40
|
+
|
41
|
+
@server.create_user_data_iso
|
42
|
+
end
|
43
|
+
|
44
|
+
def test_volume_is_uploaded_during_user_data_iso_generation
|
45
|
+
@server.stubs(:system).returns(true)
|
46
|
+
Fog::Libvirt::Compute::Volumes.any_instance.stubs(:create).returns(@compute.volumes.new)
|
47
|
+
Fog::Libvirt::Compute::Volume.any_instance.expects(:upload_image).returns(true)
|
48
|
+
|
49
|
+
@server.create_user_data_iso
|
50
|
+
end
|
51
|
+
|
52
|
+
def test_iso_file_is_set_during_user_data_iso_generation
|
53
|
+
@server.stubs(:system).returns(true)
|
54
|
+
Fog::Libvirt::Compute::Volumes.any_instance.stubs(:create).returns(@compute.volumes.new)
|
55
|
+
Fog::Libvirt::Compute::Volume.any_instance.stubs(:upload_image)
|
56
|
+
|
57
|
+
@server.create_user_data_iso
|
58
|
+
assert_equal @server.cloud_init_volume_name, @server.iso_file
|
59
|
+
end
|
60
|
+
|
61
|
+
def test_iso_dir_is_set_during_user_data_iso_generation
|
62
|
+
@server.stubs(:system).returns(true)
|
63
|
+
volume = @compute.volumes.new
|
64
|
+
volume.stubs(:path).returns("/srv/libvirt/#{@server.cloud_init_volume_name}")
|
65
|
+
Fog::Libvirt::Compute::Volumes.any_instance.stubs(:create).returns(volume)
|
66
|
+
Fog::Libvirt::Compute::Volume.any_instance.stubs(:upload_image)
|
67
|
+
|
68
|
+
@server.create_user_data_iso
|
69
|
+
assert_equal '/srv/libvirt', @server.iso_dir
|
70
|
+
end
|
71
|
+
|
72
|
+
def in_a_temp_dir
|
73
|
+
Dir.mktmpdir('test-dir') do |d|
|
74
|
+
yield d
|
75
|
+
end
|
76
|
+
end
|
77
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
require 'minitest/autorun'
|
2
|
+
require 'mocha/minitest'
|
3
|
+
require 'fileutils'
|
4
|
+
|
5
|
+
$: << File.join(File.dirname(__FILE__), '..', 'lib')
|
6
|
+
|
7
|
+
logdir = File.join(File.dirname(__FILE__), '..', 'logs')
|
8
|
+
FileUtils.mkdir_p(logdir) unless File.exist?(logdir)
|
9
|
+
|
10
|
+
ENV['TMPDIR'] = 'test/tmp'
|
11
|
+
FileUtils.rm_f Dir.glob 'test/tmp/*.tmp'
|
12
|
+
|
13
|
+
require 'fog/libvirt'
|
14
|
+
|
15
|
+
Fog.mock!
|
16
|
+
Fog.credentials = {
|
17
|
+
:libvirt_uri => 'qemu://libvirt/system',
|
18
|
+
}.merge(Fog.credentials)
|
data/tests/helper.rb
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
ENV['FOG_RC'] = ENV['FOG_RC'] || File.expand_path('../.fog', __FILE__)
|
2
|
+
ENV['FOG_CREDENTIAL'] = ENV['FOG_CREDENTIAL'] || 'default'
|
3
|
+
|
4
|
+
require 'fog/libvirt'
|
5
|
+
|
6
|
+
Excon.defaults.merge!(debug_request: true, debug_response: true)
|
7
|
+
|
8
|
+
require File.expand_path(File.join(File.dirname(__FILE__), 'helpers', 'mock_helper'))
|
9
|
+
|
10
|
+
# This overrides the default 600 seconds timeout during live test runs
|
11
|
+
if Fog.mocking?
|
12
|
+
FOG_TESTING_TIMEOUT = ENV['FOG_TEST_TIMEOUT'] || 2000
|
13
|
+
Fog.timeout = 2000
|
14
|
+
Fog::Logger.warning "Setting default fog timeout to #{Fog.timeout} seconds"
|
15
|
+
else
|
16
|
+
FOG_TESTING_TIMEOUT = Fog.timeout
|
17
|
+
end
|
@@ -0,0 +1,100 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'fog/schema/data_validator'
|
4
|
+
|
5
|
+
# format related hackery
|
6
|
+
# allows both true.is_a?(Fog::Boolean) and false.is_a?(Fog::Boolean)
|
7
|
+
# allows both nil.is_a?(Fog::Nullable::String) and ''.is_a?(Fog::Nullable::String)
|
8
|
+
module Fog
|
9
|
+
module Boolean; end
|
10
|
+
module Nullable
|
11
|
+
module Boolean; end
|
12
|
+
module Integer; end
|
13
|
+
module String; end
|
14
|
+
module Time; end
|
15
|
+
module Float; end
|
16
|
+
module Hash; end
|
17
|
+
module Array; end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
[FalseClass, TrueClass].each { |klass| klass.send(:include, Fog::Boolean) }
|
21
|
+
[FalseClass, TrueClass, NilClass, Fog::Boolean].each { |klass| klass.send(:include, Fog::Nullable::Boolean) }
|
22
|
+
[NilClass, String].each { |klass| klass.send(:include, Fog::Nullable::String) }
|
23
|
+
[NilClass, Time].each { |klass| klass.send(:include, Fog::Nullable::Time) }
|
24
|
+
[Integer, NilClass].each { |klass| klass.send(:include, Fog::Nullable::Integer) }
|
25
|
+
[Float, NilClass].each { |klass| klass.send(:include, Fog::Nullable::Float) }
|
26
|
+
[Hash, NilClass].each { |klass| klass.send(:include, Fog::Nullable::Hash) }
|
27
|
+
[Array, NilClass].each { |klass| klass.send(:include, Fog::Nullable::Array) }
|
28
|
+
|
29
|
+
module Shindo
|
30
|
+
# Generates a Shindo test that compares a hash schema to the result
|
31
|
+
# of the passed in block returning true if they match.
|
32
|
+
#
|
33
|
+
# The schema that is passed in is a Hash or Array of hashes that
|
34
|
+
# have Classes in place of values. When checking the schema the
|
35
|
+
# value should match the Class.
|
36
|
+
#
|
37
|
+
# Strict mode will fail if the data has additional keys. Setting
|
38
|
+
# +strict+ to +false+ will allow additional keys to appear.
|
39
|
+
#
|
40
|
+
# @param [Hash] schema A Hash schema
|
41
|
+
# @param [Hash] options Options to change validation rules
|
42
|
+
# @option options [Boolean] :allow_extra_keys
|
43
|
+
# If +true+ does not fail when keys are in the data that are
|
44
|
+
# not specified in the schema. This allows new values to
|
45
|
+
# appear in API output without breaking the check.
|
46
|
+
# @option options [Boolean] :allow_optional_rules
|
47
|
+
# If +true+ does not fail if extra keys are in the schema
|
48
|
+
# that do not match the data. Not recommended!
|
49
|
+
# @yield Data to check with schema
|
50
|
+
#
|
51
|
+
# @example Using in a test
|
52
|
+
# Shindo.tests("comparing welcome data against schema") do
|
53
|
+
# data = {:welcome => "Hello" }
|
54
|
+
# data_matches_schema(:welcome => String) { data }
|
55
|
+
# end
|
56
|
+
#
|
57
|
+
# comparing welcome data against schema
|
58
|
+
# + data matches schema
|
59
|
+
#
|
60
|
+
# @example Example schema
|
61
|
+
# {
|
62
|
+
# "id" => String,
|
63
|
+
# "ram" => Integer,
|
64
|
+
# "disks" => [
|
65
|
+
# {
|
66
|
+
# "size" => Float
|
67
|
+
# }
|
68
|
+
# ],
|
69
|
+
# "dns_name" => Fog::Nullable::String,
|
70
|
+
# "active" => Fog::Boolean,
|
71
|
+
# "created" => DateTime
|
72
|
+
# }
|
73
|
+
#
|
74
|
+
# @return [Boolean]
|
75
|
+
class Tests
|
76
|
+
def data_matches_schema(schema, options = {})
|
77
|
+
test('data matches schema') do
|
78
|
+
validator = Fog::Schema::DataValidator.new
|
79
|
+
valid = validator.validate(yield, schema, options)
|
80
|
+
@message = validator.message unless valid
|
81
|
+
valid
|
82
|
+
end
|
83
|
+
end
|
84
|
+
|
85
|
+
# @deprecated #formats is deprecated. Use #data_matches_schema instead
|
86
|
+
def formats(format, strict = true)
|
87
|
+
test('has proper format') do
|
88
|
+
if strict
|
89
|
+
options = { allow_extra_keys: false, allow_optional_rules: true }
|
90
|
+
else
|
91
|
+
options = { allow_extra_keys: true, allow_optional_rules: true }
|
92
|
+
end
|
93
|
+
validator = Fog::Schema::DataValidator.new
|
94
|
+
valid = validator.validate(yield, format, options)
|
95
|
+
@message = validator.message unless valid
|
96
|
+
valid
|
97
|
+
end
|
98
|
+
end
|
99
|
+
end
|
100
|
+
end
|
@@ -0,0 +1,107 @@
|
|
1
|
+
Shindo.tests('test_helper', 'meta') do
|
2
|
+
|
3
|
+
tests('comparing welcome data against schema') do
|
4
|
+
data = { welcome: 'Hello' }
|
5
|
+
data_matches_schema(welcome: String) { data }
|
6
|
+
end
|
7
|
+
|
8
|
+
tests('#data_matches_schema') do
|
9
|
+
tests('when value matches schema expectation') do
|
10
|
+
data_matches_schema('key' => String) { { 'key' => 'Value' } }
|
11
|
+
end
|
12
|
+
|
13
|
+
tests('when values within an array all match schema expectation') do
|
14
|
+
data_matches_schema('key' => [Integer]) { { 'key' => [1, 2] } }
|
15
|
+
end
|
16
|
+
|
17
|
+
tests('when nested values match schema expectation') do
|
18
|
+
data_matches_schema('key' => { nested_key: String }) { { 'key' => { nested_key: 'Value' } } }
|
19
|
+
end
|
20
|
+
|
21
|
+
tests('when collection of values all match schema expectation') do
|
22
|
+
data_matches_schema([{ 'key' => String }]) { [{ 'key' => 'Value' }, { 'key' => 'Value' }] }
|
23
|
+
end
|
24
|
+
|
25
|
+
tests('when collection is empty although schema covers optional members') do
|
26
|
+
data_matches_schema([{ 'key' => String }], allow_optional_rules: true) { [] }
|
27
|
+
end
|
28
|
+
|
29
|
+
tests('when additional keys are passed and not strict') do
|
30
|
+
data_matches_schema({ 'key' => String }, allow_extra_keys: true) { { 'key' => 'Value', extra: 'Bonus' } }
|
31
|
+
end
|
32
|
+
|
33
|
+
tests('when value is nil and schema expects NilClass') do
|
34
|
+
data_matches_schema('key' => NilClass) { { 'key' => nil } }
|
35
|
+
end
|
36
|
+
|
37
|
+
tests('when value and schema match as hashes') do
|
38
|
+
data_matches_schema({}) { {} }
|
39
|
+
end
|
40
|
+
|
41
|
+
tests('when value and schema match as arrays') do
|
42
|
+
data_matches_schema([]) { [] }
|
43
|
+
end
|
44
|
+
|
45
|
+
tests('when value is a Time') do
|
46
|
+
data_matches_schema('time' => Time) { { 'time' => Time.now } }
|
47
|
+
end
|
48
|
+
|
49
|
+
tests('when key is missing but value should be NilClass (#1477)') do
|
50
|
+
data_matches_schema({ 'key' => NilClass }, allow_optional_rules: true) { {} }
|
51
|
+
end
|
52
|
+
|
53
|
+
tests('when key is missing but value is nullable (#1477)') do
|
54
|
+
data_matches_schema({ 'key' => Fog::Nullable::String }, allow_optional_rules: true) { {} }
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
tests('#formats backwards compatible changes') do
|
59
|
+
tests('when value matches schema expectation') do
|
60
|
+
formats('key' => String) { { 'key' => 'Value' } }
|
61
|
+
end
|
62
|
+
|
63
|
+
tests('when values within an array all match schema expectation') do
|
64
|
+
formats('key' => [Integer]) { { 'key' => [1, 2] } }
|
65
|
+
end
|
66
|
+
|
67
|
+
tests('when nested values match schema expectation') do
|
68
|
+
formats('key' => { nested_key: String }) { { 'key' => { nested_key: 'Value' } } }
|
69
|
+
end
|
70
|
+
|
71
|
+
tests('when collection of values all match schema expectation') do
|
72
|
+
formats([{ 'key' => String }]) { [{ 'key' => 'Value' }, { 'key' => 'Value' }] }
|
73
|
+
end
|
74
|
+
|
75
|
+
tests('when collection is empty although schema covers optional members') do
|
76
|
+
formats([{ 'key' => String }]) { [] }
|
77
|
+
end
|
78
|
+
|
79
|
+
tests('when additional keys are passed and not strict') do
|
80
|
+
formats({ 'key' => String }, false) { { 'key' => 'Value', :extra => 'Bonus' } }
|
81
|
+
end
|
82
|
+
|
83
|
+
tests('when value is nil and schema expects NilClass') do
|
84
|
+
formats('key' => NilClass) { { 'key' => nil } }
|
85
|
+
end
|
86
|
+
|
87
|
+
tests('when value and schema match as hashes') do
|
88
|
+
formats({}) { {} }
|
89
|
+
end
|
90
|
+
|
91
|
+
tests('when value and schema match as arrays') do
|
92
|
+
formats([]) { [] }
|
93
|
+
end
|
94
|
+
|
95
|
+
tests('when value is a Time') do
|
96
|
+
formats('time' => Time) { { 'time' => Time.now } }
|
97
|
+
end
|
98
|
+
|
99
|
+
tests('when key is missing but value should be NilClass (#1477)') do
|
100
|
+
formats('key' => NilClass) { {} }
|
101
|
+
end
|
102
|
+
|
103
|
+
tests('when key is missing but value is nullable (#1477)') do
|
104
|
+
formats('key' => Fog::Nullable::String) { {} }
|
105
|
+
end
|
106
|
+
end
|
107
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
# Use so you can run in mock mode from the command line
|
2
|
+
#
|
3
|
+
# FOG_MOCK=true fog
|
4
|
+
|
5
|
+
if ENV["FOG_MOCK"] == "true"
|
6
|
+
Fog.mock!
|
7
|
+
end
|
8
|
+
|
9
|
+
# if in mocked mode, fill in some fake credentials for us
|
10
|
+
if Fog.mock?
|
11
|
+
Fog.credentials = {
|
12
|
+
libvirt_uri: 'qemu://libvirt/system',
|
13
|
+
}.merge(Fog.credentials)
|
14
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
Shindo.tests('Fog::Compute[:libvirt]', ['libvirt']) do
|
2
|
+
|
3
|
+
compute = Fog::Compute[:libvirt]
|
4
|
+
|
5
|
+
tests("Compute collections") do
|
6
|
+
%w{ servers interfaces networks nics nodes pools volumes}.each do |collection|
|
7
|
+
test("it should respond to #{collection}") { compute.respond_to? collection }
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
11
|
+
tests("Compute requests") do
|
12
|
+
%w{ create_domain create_volume define_domain define_pool destroy_interface destroy_network get_node_info
|
13
|
+
update_autostart list_domains
|
14
|
+
list_interfaces list_networks list_pools list_pool_volumes list_volumes pool_action vm_action volume_action
|
15
|
+
dhcp_leases }.each do |request|
|
16
|
+
test("it should respond to #{request}") { compute.respond_to? request }
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
Shindo.tests('Fog::Compute[:libvirt] | interface model', ['libvirt']) do
|
2
|
+
|
3
|
+
interfaces = Fog::Compute[:libvirt].interfaces
|
4
|
+
interface = interfaces.last
|
5
|
+
|
6
|
+
tests('The interface model should') do
|
7
|
+
tests('have the action') do
|
8
|
+
test('reload') { interface.respond_to? 'reload' }
|
9
|
+
end
|
10
|
+
tests('have attributes') do
|
11
|
+
model_attribute_hash = interface.attributes
|
12
|
+
attributes = [ :name, :mac, :active]
|
13
|
+
tests("The interface model should respond to") do
|
14
|
+
attributes.each do |attribute|
|
15
|
+
test("#{attribute}") { interface.respond_to? attribute }
|
16
|
+
end
|
17
|
+
end
|
18
|
+
tests("The attributes hash should have key") do
|
19
|
+
attributes.each do |attribute|
|
20
|
+
test("#{attribute}") { model_attribute_hash.key? attribute }
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
test('be a kind of Fog::Libvirt::Compute::Interface') { interface.kind_of? Fog::Libvirt::Compute::Interface }
|
25
|
+
end
|
26
|
+
|
27
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
Shindo.tests('Fog::Compute[:libvirt] | interfaces collection', ['libvirt']) do
|
2
|
+
|
3
|
+
interfaces = Fog::Compute[:libvirt].interfaces
|
4
|
+
|
5
|
+
tests('The interfaces collection') do
|
6
|
+
test('should not be empty') { not interfaces.empty? }
|
7
|
+
test('should be a kind of Fog::Libvirt::Compute::Interfaces') { interfaces.kind_of? Fog::Libvirt::Compute::Interfaces }
|
8
|
+
tests('should be able to reload itself').succeeds { interfaces.reload }
|
9
|
+
tests('should be able to get a model') do
|
10
|
+
tests('by instance name').succeeds { interfaces.get interfaces.first.name }
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
Shindo.tests('Fog::Compute[:libvirt] | network model', ['libvirt']) do
|
2
|
+
|
3
|
+
networks = Fog::Compute[:libvirt].networks
|
4
|
+
network = networks.last
|
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('99:88:77:66:55:44', 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
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
Shindo.tests('Fog::Compute[:libvirt] | networks collection', ['libvirt']) do
|
2
|
+
|
3
|
+
networks = Fog::Compute[:libvirt].networks
|
4
|
+
|
5
|
+
tests('The networks collection') do
|
6
|
+
test('should be a kind of Fog::Libvirt::Compute::Networks') { networks.kind_of? Fog::Libvirt::Compute::Networks }
|
7
|
+
tests('should be able to reload itself').succeeds { networks.reload }
|
8
|
+
tests('should be able to get a model') do
|
9
|
+
tests('by instance id').succeeds { networks.get networks.first.uuid }
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
Shindo.tests('Fog::Compute[:libvirt] | nic model', ['libvirt']) do
|
2
|
+
|
3
|
+
nic = Fog::Compute[:libvirt].servers.all.select{|v| v.name =~ /^fog/}.first.nics.first
|
4
|
+
|
5
|
+
tests('The nic model should') do
|
6
|
+
tests('have the action') do
|
7
|
+
test('reload') { nic.respond_to? 'reload' }
|
8
|
+
end
|
9
|
+
tests('have attributes') do
|
10
|
+
model_attribute_hash = nic.attributes
|
11
|
+
attributes = [ :mac,
|
12
|
+
:model,
|
13
|
+
:type,
|
14
|
+
:network,
|
15
|
+
:bridge]
|
16
|
+
tests("The nic model should respond to") do
|
17
|
+
attributes.each do |attribute|
|
18
|
+
test("#{attribute}") { nic.respond_to? attribute }
|
19
|
+
end
|
20
|
+
end
|
21
|
+
tests("The attributes hash should have key") do
|
22
|
+
attributes.delete(:bridge)
|
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::Nic') { nic.kind_of? Fog::Libvirt::Compute::Nic }
|
29
|
+
end
|
30
|
+
|
31
|
+
end
|
@@ -0,0 +1,10 @@
|
|
1
|
+
Shindo.tests('Fog::Compute[:libvirt] | nics collection', ['libvirt']) do
|
2
|
+
|
3
|
+
nics = Fog::Compute[:libvirt].servers.first.nics
|
4
|
+
|
5
|
+
tests('The nics collection') do
|
6
|
+
test('should not be empty') { not nics.empty? }
|
7
|
+
test('should be a kind of Array') { nics.kind_of? Array }
|
8
|
+
end
|
9
|
+
|
10
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
Shindo.tests('Fog::Compute[:libvirt] | interface model', ['libvirt']) do
|
2
|
+
|
3
|
+
pools = Fog::Compute[:libvirt].pools
|
4
|
+
pool = pools.last
|
5
|
+
|
6
|
+
tests('The interface model should') do
|
7
|
+
tests('have the action') do
|
8
|
+
test('reload') { pool.respond_to? 'reload' }
|
9
|
+
end
|
10
|
+
tests('have attributes') do
|
11
|
+
model_attribute_hash = pool.attributes
|
12
|
+
attributes = [ :uuid, :name, :persistent, :active, :autostart, :allocation, :capacity, :num_of_volumes, :state]
|
13
|
+
tests("The interface model should respond to") do
|
14
|
+
attributes.each do |attribute|
|
15
|
+
test("#{attribute}") { pool.respond_to? attribute }
|
16
|
+
end
|
17
|
+
end
|
18
|
+
tests("The attributes hash should have key") do
|
19
|
+
attributes.each do |attribute|
|
20
|
+
test("#{attribute}") { model_attribute_hash.key? attribute }
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
test('be a kind of Fog::Libvirt::Compute::Pool') { pool.kind_of? Fog::Libvirt::Compute::Pool }
|
25
|
+
end
|
26
|
+
|
27
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
Shindo.tests('Fog::Compute[:libvirt] | pools request', ['libvirt']) do
|
2
|
+
|
3
|
+
pools = Fog::Compute[:libvirt].pools
|
4
|
+
|
5
|
+
tests('The pools collection') do
|
6
|
+
test('should not be empty') { not pools.empty? }
|
7
|
+
test('should be a kind of Fog::Libvirt::Compute::Pools') { pools.kind_of? Fog::Libvirt::Compute::Pools }
|
8
|
+
tests('should be able to reload itself').succeeds { pools.reload }
|
9
|
+
tests('should be able to get a model') do
|
10
|
+
tests('by instance id').succeeds { pools.get pools.first.uuid }
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|