fog-libvirt 0.0.1

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 (73) hide show
  1. checksums.yaml +7 -0
  2. data/CONTRIBUTORS.md +23 -0
  3. data/Gemfile +9 -0
  4. data/LICENSE.md +20 -0
  5. data/README.md +29 -0
  6. data/Rakefile +122 -0
  7. data/fog-libvirt.gemspec +49 -0
  8. data/lib/fog/bin/libvirt.rb +58 -0
  9. data/lib/fog/libvirt/compute.rb +136 -0
  10. data/lib/fog/libvirt/models/compute/README.md +76 -0
  11. data/lib/fog/libvirt/models/compute/interface.rb +25 -0
  12. data/lib/fog/libvirt/models/compute/interfaces.rb +20 -0
  13. data/lib/fog/libvirt/models/compute/network.rb +29 -0
  14. data/lib/fog/libvirt/models/compute/networks.rb +20 -0
  15. data/lib/fog/libvirt/models/compute/nic.rb +50 -0
  16. data/lib/fog/libvirt/models/compute/nics.rb +12 -0
  17. data/lib/fog/libvirt/models/compute/node.rb +29 -0
  18. data/lib/fog/libvirt/models/compute/nodes.rb +20 -0
  19. data/lib/fog/libvirt/models/compute/pool.rb +84 -0
  20. data/lib/fog/libvirt/models/compute/pools.rb +20 -0
  21. data/lib/fog/libvirt/models/compute/server.rb +401 -0
  22. data/lib/fog/libvirt/models/compute/servers.rb +21 -0
  23. data/lib/fog/libvirt/models/compute/templates/network.xml.erb +6 -0
  24. data/lib/fog/libvirt/models/compute/templates/pool.xml.erb +6 -0
  25. data/lib/fog/libvirt/models/compute/templates/server.xml.erb +54 -0
  26. data/lib/fog/libvirt/models/compute/templates/volume.xml.erb +26 -0
  27. data/lib/fog/libvirt/models/compute/util/uri.rb +138 -0
  28. data/lib/fog/libvirt/models/compute/util/util.rb +32 -0
  29. data/lib/fog/libvirt/models/compute/volume.rb +122 -0
  30. data/lib/fog/libvirt/models/compute/volumes.rb +20 -0
  31. data/lib/fog/libvirt/requests/compute/clone_volume.rb +18 -0
  32. data/lib/fog/libvirt/requests/compute/create_domain.rb +17 -0
  33. data/lib/fog/libvirt/requests/compute/create_volume.rb +16 -0
  34. data/lib/fog/libvirt/requests/compute/define_domain.rb +17 -0
  35. data/lib/fog/libvirt/requests/compute/define_pool.rb +16 -0
  36. data/lib/fog/libvirt/requests/compute/destroy_interface.rb +18 -0
  37. data/lib/fog/libvirt/requests/compute/destroy_network.rb +17 -0
  38. data/lib/fog/libvirt/requests/compute/get_node_info.rb +37 -0
  39. data/lib/fog/libvirt/requests/compute/list_domains.rb +105 -0
  40. data/lib/fog/libvirt/requests/compute/list_interfaces.rb +57 -0
  41. data/lib/fog/libvirt/requests/compute/list_networks.rb +55 -0
  42. data/lib/fog/libvirt/requests/compute/list_pool_volumes.rb +19 -0
  43. data/lib/fog/libvirt/requests/compute/list_pools.rb +71 -0
  44. data/lib/fog/libvirt/requests/compute/list_volumes.rb +88 -0
  45. data/lib/fog/libvirt/requests/compute/mock_files/domain.xml +40 -0
  46. data/lib/fog/libvirt/requests/compute/pool_action.rb +19 -0
  47. data/lib/fog/libvirt/requests/compute/update_display.rb +31 -0
  48. data/lib/fog/libvirt/requests/compute/vm_action.rb +19 -0
  49. data/lib/fog/libvirt/requests/compute/volume_action.rb +18 -0
  50. data/lib/fog/libvirt/version.rb +5 -0
  51. data/lib/fog/libvirt.rb +18 -0
  52. data/tests/helper.rb +17 -0
  53. data/tests/helpers/formats_helper.rb +98 -0
  54. data/tests/helpers/formats_helper_tests.rb +110 -0
  55. data/tests/helpers/mock_helper.rb +14 -0
  56. data/tests/helpers/succeeds_helper.rb +9 -0
  57. data/tests/libvirt/compute_tests.rb +17 -0
  58. data/tests/libvirt/models/compute/interface_tests.rb +27 -0
  59. data/tests/libvirt/models/compute/interfaces_tests.rb +14 -0
  60. data/tests/libvirt/models/compute/network_tests.rb +27 -0
  61. data/tests/libvirt/models/compute/networks_tests.rb +13 -0
  62. data/tests/libvirt/models/compute/nic_tests.rb +31 -0
  63. data/tests/libvirt/models/compute/nics_tests.rb +10 -0
  64. data/tests/libvirt/models/compute/pool_tests.rb +27 -0
  65. data/tests/libvirt/models/compute/pools_tests.rb +13 -0
  66. data/tests/libvirt/models/compute/server_tests.rb +58 -0
  67. data/tests/libvirt/models/compute/servers_tests.rb +14 -0
  68. data/tests/libvirt/models/compute/volume_tests.rb +38 -0
  69. data/tests/libvirt/models/compute/volumes_tests.rb +14 -0
  70. data/tests/libvirt/requests/compute/create_domain_tests.rb +21 -0
  71. data/tests/libvirt/requests/compute/define_domain_tests.rb +11 -0
  72. data/tests/libvirt/requests/compute/update_display.rb +13 -0
  73. metadata +355 -0
@@ -0,0 +1,19 @@
1
+ module Fog
2
+ module Compute
3
+ class Libvirt
4
+ class Real
5
+ def list_pool_volumes(uuid)
6
+ pool = client.lookup_storage_pool_by_uuid uuid
7
+ pool.list_volumes.map do |volume_name|
8
+ volume_to_attributes(pool.lookup_volume_by_name(volume_name))
9
+ end
10
+ end
11
+ end
12
+
13
+ class Mock
14
+ def list_pool_volumes(uuid)
15
+ end
16
+ end
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,71 @@
1
+ module Fog
2
+ module Compute
3
+ class Libvirt
4
+ class Real
5
+ def list_pools(filter = { })
6
+ data=[]
7
+ if filter.key?(:name)
8
+ data << find_pool_by_name(filter[:name])
9
+ elsif filter.key?(:uuid)
10
+ data << find_pool_by_uuid(filter[:uuid])
11
+ else
12
+ (client.list_storage_pools + client.list_defined_storage_pools).each do |name|
13
+ data << find_pool_by_name(name)
14
+ end
15
+ end
16
+ data.compact
17
+ end
18
+
19
+ private
20
+ def pool_to_attributes(pool)
21
+ states=[:inactive, :building, :running, :degrated, :inaccessible]
22
+ {
23
+ :uuid => pool.uuid,
24
+ :persistent => pool.persistent?,
25
+ :autostart => pool.autostart?,
26
+ :active => pool.active?,
27
+ :name => pool.name,
28
+ :allocation => pool.info.allocation,
29
+ :capacity => pool.info.capacity,
30
+ :num_of_volumes => pool.num_of_volumes,
31
+ :state => states[pool.info.state]
32
+ }
33
+ end
34
+
35
+ def find_pool_by_name name
36
+ pool_to_attributes(client.lookup_storage_pool_by_name(name))
37
+ rescue ::Libvirt::RetrieveError
38
+ nil
39
+ end
40
+
41
+ def find_pool_by_uuid uuid
42
+ pool_to_attributes(client.lookup_storage_pool_by_uuid(uuid))
43
+ rescue ::Libvirt::RetrieveError
44
+ nil
45
+ end
46
+ end
47
+
48
+ class Mock
49
+ def list_pools(filter = { })
50
+ pool1 = mock_pool 'pool1'
51
+ pool2 = mock_pool 'pool1'
52
+ [pool1, pool2]
53
+ end
54
+
55
+ def mock_pool name
56
+ {
57
+ :uuid => 'pool.uuid',
58
+ :persistent => true,
59
+ :autostart => true,
60
+ :active => true,
61
+ :name => name,
62
+ :allocation => 123456789,
63
+ :capacity => 123456789,
64
+ :num_of_volumes => 3,
65
+ :state => :running
66
+ }
67
+ end
68
+ end
69
+ end
70
+ end
71
+ end
@@ -0,0 +1,88 @@
1
+ module Fog
2
+ module Compute
3
+ class Libvirt
4
+ class Real
5
+ def list_volumes(filter = { })
6
+ data = []
7
+ if filter.keys.empty?
8
+ raw_volumes do |pool|
9
+ pool.list_volumes.each do |volume_name|
10
+ data << volume_to_attributes(pool.lookup_volume_by_name(volume_name))
11
+ end
12
+ end
13
+ else
14
+ return [get_volume(filter)]
15
+ end
16
+ data.compact
17
+ end
18
+
19
+ private
20
+
21
+ def volume_to_attributes(vol)
22
+ format_type = xml_element(vol.xml_desc, "/volume/target/format", "type") rescue nil # not all volumes have types, e.g. LVM
23
+ return nil if format_type == "dir"
24
+
25
+ {
26
+ :pool_name => vol.pool.name,
27
+ :key => vol.key,
28
+ :id => vol.key,
29
+ :path => vol.path,
30
+ :name => vol.name,
31
+ :format_type => format_type,
32
+ :allocation => bytes_to_gb(vol.info.allocation),
33
+ :capacity => bytes_to_gb(vol.info.capacity),
34
+ }
35
+ end
36
+
37
+ def bytes_to_gb bytes
38
+ bytes / 1024**3
39
+ end
40
+
41
+ def raw_volumes
42
+ client.list_storage_pools.each do |pool_name|
43
+ pool = client.lookup_storage_pool_by_name(pool_name)
44
+ yield(pool)
45
+ end
46
+ end
47
+
48
+ def get_volume filter = { }, raw = false
49
+ raw_volumes do |pool|
50
+ vol = case filter.keys.first
51
+ when :name
52
+ pool.lookup_volume_by_name(filter[:name]) rescue nil
53
+ when :key
54
+ pool.lookup_volume_by_key(filter[:key]) rescue nil
55
+ when :path
56
+ pool.lookup_volume_by_path(filter[:path]) rescue nil
57
+ end
58
+ if vol
59
+ return raw ? vol : volume_to_attributes(vol)
60
+ end
61
+ end
62
+ { }
63
+ end
64
+ end
65
+
66
+ class Mock
67
+ def list_volumes(filters={ })
68
+ vol1 = mock_volume 'vol1'
69
+ vol2 = mock_volume 'vol2'
70
+ [vol1, vol2]
71
+ end
72
+
73
+ def mock_volume name
74
+ {
75
+ :pool_name => 'vol.pool.name',
76
+ :key => 'vol.key',
77
+ :id => 'vol.key',
78
+ :path => 'vol.path',
79
+ :name => name,
80
+ :format_type => 'raw',
81
+ :allocation => 123,
82
+ :capacity => 123,
83
+ }
84
+ end
85
+ end
86
+ end
87
+ end
88
+ end
@@ -0,0 +1,40 @@
1
+ <domain type='kvm'>
2
+ <name>fog-449765558356062</name>
3
+ <memory>262144</memory>
4
+ <vcpu>1</vcpu>
5
+ <os>
6
+ <type arch='x86_64'>hvm</type>
7
+ <boot dev='hd'/>
8
+ <boot dev='cdrom'/>
9
+ <boot dev='network'/>
10
+ </os>
11
+ <features>
12
+ <acpi/>
13
+ <apic/>
14
+ <pae/>
15
+ </features>
16
+ <clock offset='utc'/>
17
+ <devices>
18
+ <interface type='network'>
19
+ <mac address="aa:bb:cc:dd:ee:ff" />
20
+ <source network='net1' />
21
+ <model type='virtio'/>
22
+ </interface>
23
+ <serial type='pty'>
24
+ <target port='0'/>
25
+ </serial>
26
+ <console type='pty'>
27
+ <target port='0'/>
28
+ </console>
29
+ <input type='mouse' bus='ps2'/>
30
+ <graphics type='vnc' port='-1' autoport='yes'/>
31
+ <video>
32
+ <model type='cirrus' vram='9216' heads='1'/>
33
+ </video>
34
+ <disk type='file' device='disk'>
35
+ <driver name='qemu' type='raw'/>
36
+ <source file='path/to/disk'/>
37
+ <target dev='vda' bus='virtio'/>
38
+ </disk>
39
+ </devices>
40
+ </domain>
@@ -0,0 +1,19 @@
1
+ module Fog
2
+ module Compute
3
+ class Libvirt
4
+ class Real
5
+ def pool_action(uuid, action)
6
+ pool = client.lookup_storage_pool_by_uuid uuid
7
+ pool.send(action)
8
+ true
9
+ end
10
+ end
11
+
12
+ class Mock
13
+ def pool_action(uuid, action)
14
+ true
15
+ end
16
+ end
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,31 @@
1
+ module Fog
2
+ module Compute
3
+ class Libvirt
4
+ class Real
5
+ def update_display(options = { })
6
+ raise ArgumentError, "uuid is a required parameter" unless options.key? :uuid
7
+ display = { }
8
+ display[:type] = options[:type] || 'vnc'
9
+ display[:port] = (options[:port] || -1).to_s
10
+ display[:listen] = options[:listen].to_s if options[:listen]
11
+ display[:passwd] = options[:password].to_s if options[:password]
12
+ display[:autoport] = 'yes' if display[:port] == '-1'
13
+
14
+ builder = Nokogiri::XML::Builder.new { graphics_ (display) }
15
+ xml = Nokogiri::XML(builder.to_xml).root.to_s
16
+
17
+ client.lookup_domain_by_uuid(options[:uuid]).update_device(xml, 0)
18
+ # if we got no exceptions, then we're good'
19
+ true
20
+ end
21
+ end
22
+
23
+ class Mock
24
+ def update_display(options = { })
25
+ raise ArgumentError, "uuid is a required parameter" unless options.key? :uuid
26
+ true
27
+ end
28
+ end
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,19 @@
1
+ module Fog
2
+ module Compute
3
+ class Libvirt
4
+ class Real
5
+ def vm_action(uuid, action)
6
+ domain = client.lookup_domain_by_uuid(uuid)
7
+ domain.send(action)
8
+ true
9
+ end
10
+ end
11
+
12
+ class Mock
13
+ def vm_action(uuid, action)
14
+ true
15
+ end
16
+ end
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,18 @@
1
+ module Fog
2
+ module Compute
3
+ class Libvirt
4
+ class Real
5
+ def volume_action(key, action, options={})
6
+ get_volume({:key => key}, true).send(action)
7
+ true
8
+ end
9
+ end
10
+
11
+ class Mock
12
+ def volume_action(action, options={})
13
+ true
14
+ end
15
+ end
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,5 @@
1
+ module Fog
2
+ module Libvirt
3
+ VERSION = '0.0.1'
4
+ end
5
+ end
@@ -0,0 +1,18 @@
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
+ module Compute
13
+ autoload :Libvirt, File.expand_path('../libvirt/compute', __FILE__)
14
+ end
15
+
16
+ service(:compute, 'Compute')
17
+ end
18
+ end
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,98 @@
1
+ require "fog/schema/data_validator"
2
+
3
+ # format related hackery
4
+ # allows both true.is_a?(Fog::Boolean) and false.is_a?(Fog::Boolean)
5
+ # allows both nil.is_a?(Fog::Nullable::String) and ''.is_a?(Fog::Nullable::String)
6
+ module Fog
7
+ module Boolean; end
8
+ module Nullable
9
+ module Boolean; end
10
+ module Integer; end
11
+ module String; end
12
+ module Time; end
13
+ module Float; end
14
+ module Hash; end
15
+ module Array; end
16
+ end
17
+ end
18
+ [FalseClass, TrueClass].each {|klass| klass.send(:include, Fog::Boolean)}
19
+ [FalseClass, TrueClass, NilClass, Fog::Boolean].each {|klass| klass.send(:include, Fog::Nullable::Boolean)}
20
+ [NilClass, String].each {|klass| klass.send(:include, Fog::Nullable::String)}
21
+ [NilClass, Time].each {|klass| klass.send(:include, Fog::Nullable::Time)}
22
+ [Integer, NilClass].each {|klass| klass.send(:include, Fog::Nullable::Integer)}
23
+ [Float, NilClass].each {|klass| klass.send(:include, Fog::Nullable::Float)}
24
+ [Hash, NilClass].each {|klass| klass.send(:include, Fog::Nullable::Hash)}
25
+ [Array, NilClass].each {|klass| klass.send(:include, Fog::Nullable::Array)}
26
+
27
+ module Shindo
28
+ class Tests
29
+ # Generates a Shindo test that compares a hash schema to the result
30
+ # of the passed in block returning true if they match.
31
+ #
32
+ # The schema that is passed in is a Hash or Array of hashes that
33
+ # have Classes in place of values. When checking the schema the
34
+ # value should match the Class.
35
+ #
36
+ # Strict mode will fail if the data has additional keys. Setting
37
+ # +strict+ to +false+ will allow additional keys to appear.
38
+ #
39
+ # @param [Hash] schema A Hash schema
40
+ # @param [Hash] options Options to change validation rules
41
+ # @option options [Boolean] :allow_extra_keys
42
+ # If +true+ does not fail when keys are in the data that are
43
+ # not specified in the schema. This allows new values to
44
+ # appear in API output without breaking the check.
45
+ # @option options [Boolean] :allow_optional_rules
46
+ # If +true+ does not fail if extra keys are in the schema
47
+ # that do not match the data. Not recommended!
48
+ # @yield Data to check with schema
49
+ #
50
+ # @example Using in a test
51
+ # Shindo.tests("comparing welcome data against schema") do
52
+ # data = {:welcome => "Hello" }
53
+ # data_matches_schema(:welcome => String) { data }
54
+ # end
55
+ #
56
+ # comparing welcome data against schema
57
+ # + data matches schema
58
+ #
59
+ # @example Example schema
60
+ # {
61
+ # "id" => String,
62
+ # "ram" => Integer,
63
+ # "disks" => [
64
+ # {
65
+ # "size" => Float
66
+ # }
67
+ # ],
68
+ # "dns_name" => Fog::Nullable::String,
69
+ # "active" => Fog::Boolean,
70
+ # "created" => DateTime
71
+ # }
72
+ #
73
+ # @return [Boolean]
74
+ def data_matches_schema(schema, options = {})
75
+ test('data matches schema') do
76
+ validator = Fog::Schema::DataValidator.new
77
+ valid = validator.validate(yield, schema, options)
78
+ @message = validator.message unless valid
79
+ valid
80
+ end
81
+ end
82
+
83
+ # @deprecated #formats is deprecated. Use #data_matches_schema instead
84
+ def formats(format, strict = true)
85
+ test('has proper format') do
86
+ if strict
87
+ options = {:allow_extra_keys => false, :allow_optional_rules => true}
88
+ else
89
+ options = {:allow_extra_keys => true, :allow_optional_rules => true}
90
+ end
91
+ validator = Fog::Schema::DataValidator.new
92
+ valid = validator.validate(yield, format, options)
93
+ @message = validator.message unless valid
94
+ valid
95
+ end
96
+ end
97
+ end
98
+ end
@@ -0,0 +1,110 @@
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
+
60
+ tests('when value matches schema expectation') do
61
+ formats({"key" => String}) { {"key" => "Value"} }
62
+ end
63
+
64
+ tests('when values within an array all match schema expectation') do
65
+ formats({"key" => [Integer]}) { {"key" => [1, 2]} }
66
+ end
67
+
68
+ tests('when nested values match schema expectation') do
69
+ formats({"key" => {:nested_key => String}}) { {"key" => {:nested_key => "Value"}} }
70
+ end
71
+
72
+ tests('when collection of values all match schema expectation') do
73
+ formats([{"key" => String}]) { [{"key" => "Value"}, {"key" => "Value"}] }
74
+ end
75
+
76
+ tests('when collection is empty although schema covers optional members') do
77
+ formats([{"key" => String}]) { [] }
78
+ end
79
+
80
+ tests('when additional keys are passed and not strict') do
81
+ formats({"key" => String}, false) { {"key" => "Value", :extra => "Bonus"} }
82
+ end
83
+
84
+ tests('when value is nil and schema expects NilClass') do
85
+ formats({"key" => NilClass}) { {"key" => nil} }
86
+ end
87
+
88
+ tests('when value and schema match as hashes') do
89
+ formats({}) { {} }
90
+ end
91
+
92
+ tests('when value and schema match as arrays') do
93
+ formats([]) { [] }
94
+ end
95
+
96
+ tests('when value is a Time') do
97
+ formats({"time" => Time}) { {"time" => Time.now} }
98
+ end
99
+
100
+ tests('when key is missing but value should be NilClass (#1477)') do
101
+ formats({"key" => NilClass}) { {} }
102
+ end
103
+
104
+ tests('when key is missing but value is nullable (#1477)') do
105
+ formats({"key" => Fog::Nullable::String}) { {} }
106
+ end
107
+
108
+ end
109
+
110
+ 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,9 @@
1
+ module Shindo
2
+ class Tests
3
+ def succeeds
4
+ test('succeeds') do
5
+ !!instance_eval(&Proc.new)
6
+ end
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,17 @@
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 list_domains
13
+ list_interfaces list_networks list_pools list_pool_volumes list_volumes pool_action vm_action volume_action }.each do |request|
14
+ test("it should respond to #{request}") { compute.respond_to? request }
15
+ end
16
+ end
17
+ 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::Compute::Libvirt::Interface') { interface.kind_of? Fog::Compute::Libvirt::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::Compute::Libvirt::Interfaces') { interfaces.kind_of? Fog::Compute::Libvirt::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,27 @@
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
+ end
10
+ tests('have attributes') do
11
+ model_attribute_hash = network.attributes
12
+ attributes = [ :name, :uuid, :bridge_name]
13
+ tests("The network model should respond to") do
14
+ attributes.each do |attribute|
15
+ test("#{attribute}") { network.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::Compute::Libvirt::Network') { network.kind_of? Fog::Compute::Libvirt::Network }
25
+ end
26
+
27
+ end