diff --git a/fog.gemspec b/fog.gemspec index 8994f0f6e..5c98c3de3 100644 --- a/fog.gemspec +++ b/fog.gemspec @@ -57,6 +57,7 @@ Gem::Specification.new do |s| s.add_development_dependency('shindo', '~>0.3.4') s.add_development_dependency('virtualbox', '~>0.9.1') # s.add_development_dependency('ruby-libvirt','~>0.4.0') + s.add_development_dependency('rbovirt', '>=0.0.5') s.files = `git ls-files`.split("\n") s.test_files = `git ls-files -- {spec,tests}/*`.split("\n") diff --git a/lib/fog/bin.rb b/lib/fog/bin.rb index 08d1f0db3..0e52761e7 100644 --- a/lib/fog/bin.rb +++ b/lib/fog/bin.rb @@ -71,6 +71,7 @@ require 'fog/bin/new_servers' require 'fog/bin/ninefold' require 'fog/bin/rackspace' require 'fog/bin/openstack' +require 'fog/bin/ovirt' require 'fog/bin/slicehost' require 'fog/bin/stormondemand' require 'fog/bin/terremark' diff --git a/lib/fog/bin/ovirt.rb b/lib/fog/bin/ovirt.rb new file mode 100644 index 000000000..62df5d764 --- /dev/null +++ b/lib/fog/bin/ovirt.rb @@ -0,0 +1,30 @@ +class Ovirt < Fog::Bin + class << self + + def class_for(key) + case key + when :compute + Fog::Compute::Ovirt + else + raise ArgumentError, "Unrecognized service: #{key}" + end + end + + def [](service) + @@connections ||= Hash.new do |hash, key| + hash[key] = case key + when :compute + Fog::Compute.new(:provider => 'Ovirt') + else + raise ArgumentError, "Unrecognized service: #{key.inspect}" + end + end + @@connections[service] + end + + def services + Fog::Ovirt.services + end + + end +end diff --git a/lib/fog/ovirt/compute.rb b/lib/fog/ovirt/compute.rb index b01789d27..3397d02d4 100644 --- a/lib/fog/ovirt/compute.rb +++ b/lib/fog/ovirt/compute.rb @@ -22,11 +22,13 @@ module Fog request :storage_domains class Mock - + attr_reader :client def initialize(options={}) username = options[:ovirt_username] - password = options[:password] + password = options[:ovirt_password] url = options[:ovirt_url] + + #@client = OVIRT::Client.new(username, password, url) end end @@ -41,7 +43,7 @@ module Fog server = options[:ovirt_server] port = options[:ovirt_port] || 8080 api_path = options[:ovirt_api_path] || '/api' - url = options[:ovirt_url] || "#{@scheme}://#{@ovirt_server}:#{@ovirt_port}#{@ovirt_api_path}" + url = options[:ovirt_url] || "#{@scheme}://#{server}:#{port}#{api_path}" datacenter = options[:ovirt_datacenter] @client = OVIRT::Client.new(username, password, url, datacenter) diff --git a/tests/helper.rb b/tests/helper.rb index 71b4dc3ce..a5f209678 100644 --- a/tests/helper.rb +++ b/tests/helper.rb @@ -12,7 +12,7 @@ def array_differences(array_a, array_b) end # check to see which credentials are available and add others to the skipped tags list -all_providers = ['aws', 'bluebox', 'brightbox', 'dnsimple', 'dnsmadeeasy', 'dynect', 'ecloud', 'glesys', 'gogrid', 'google', 'linode', 'local', 'ninefold', 'newservers', 'openstack', 'rackspace', 'slicehost', 'stormondemand', 'voxel', 'vsphere', 'zerigo'] +all_providers = ['aws', 'bluebox', 'brightbox', 'dnsimple', 'dnsmadeeasy', 'dynect', 'ecloud', 'glesys', 'gogrid', 'google', 'linode', 'local', 'ninefold', 'newservers', 'openstack', 'ovirt', 'rackspace', 'slicehost', 'stormondemand', 'voxel', 'vsphere', 'zerigo'] available_providers = Fog.available_providers.map {|provider| provider.downcase} for provider in (all_providers - available_providers) Formatador.display_line("[yellow]Skipping tests for [bold]#{provider}[/] [yellow]due to lacking credentials (add some to '~/.fog' to run them)[/]") diff --git a/tests/helpers/mock_helper.rb b/tests/helpers/mock_helper.rb index 549c23d2e..252e7d81c 100644 --- a/tests/helpers/mock_helper.rb +++ b/tests/helpers/mock_helper.rb @@ -44,6 +44,9 @@ if Fog.mock? :openstack_username => 'openstack_username', :openstack_tenant => 'openstack_tenant', :openstack_auth_url => 'openstack_auth_url', + :ovirt_url => 'http://ovirt:8080/api', + :ovirt_username => 'admin@internal', + :ovirt_password => '123123', :rackspace_api_key => 'rackspace_api_key', :rackspace_username => 'rackspace_username', :slicehost_password => 'slicehost_password', diff --git a/tests/ovirt/compute_tests.rb b/tests/ovirt/compute_tests.rb new file mode 100644 index 000000000..5d066c410 --- /dev/null +++ b/tests/ovirt/compute_tests.rb @@ -0,0 +1,22 @@ +Shindo.tests('Fog::Compute[:ovirt]', ['ovirt']) do + + compute = Fog::Compute[:ovirt] + + tests("Compute attributes") do + %w{ client }.each do |attr| + test("it should respond to #{attr}") { compute.respond_to? attr } + end + end + + tests("Compute collections") do + %w{ servers templates clusters }.each do |collection| + test("it should respond to #{collection}") { compute.respond_to? collection } + end + end + + tests("Compute requests") do + %w{ datacenters storage_domains vm_action destroy_vm }.each do |collection| + test("it should respond to #{collection}") { compute.respond_to? collection } + end + end +end diff --git a/tests/ovirt/models/compute/server_tests.rb b/tests/ovirt/models/compute/server_tests.rb new file mode 100644 index 000000000..86c147ebc --- /dev/null +++ b/tests/ovirt/models/compute/server_tests.rb @@ -0,0 +1,45 @@ +Shindo.tests('Fog::Compute[:ovirt] | server model', ['ovirt']) do + + servers = Fog::Compute[:ovirt].servers + server = servers.last + + tests('The server model should') do + tests('have the action') do + test('reload') { server.respond_to? 'reload' } + %w{ stop start destroy reboot }.each do |action| + test(action) { server.respond_to? action } + end + end + tests('have attributes') do + model_attribute_hash = server.attributes + attributes = [ :id, + :name, + :description, + :profile, + :display, + :storage, + :creation_time, + :os, + :ip, + :status, + :cores, + :memory, + :host, + :cluster, + :template] + tests("The server model should respond to") do + attributes.each do |attribute| + test("#{attribute}") { server.respond_to? attribute } + end + end + tests("The attributes hash should have key") do + attributes.each do |attribute| + test("#{attribute}") { model_attribute_hash.has_key? attribute } + end + end + end + test('be a kind of Fog::Compute::Ovirt::Server') { server.kind_of? Fog::Compute::Ovirt::Server } + end + + # currently not mock is not working.. +end if false diff --git a/tests/ovirt/models/compute/servers_tests.rb b/tests/ovirt/models/compute/servers_tests.rb new file mode 100644 index 000000000..3da71fa85 --- /dev/null +++ b/tests/ovirt/models/compute/servers_tests.rb @@ -0,0 +1,9 @@ +Shindo.tests('Fog::Compute[:ovirt] | servers collection', ['ovirt']) do + + servers = Fog::Compute[:ovirt].servers + + tests('The servers collection') do + test('should be a kind of Fog::Compute::Ovirt::Servers') { servers.kind_of? Fog::Compute::Ovirt::Servers } + end + +end