Permalink
Browse files

oVirt: Added tests to work on both real and mock.

Signed-off-by: Ohad Levy <ohadlevy@gmail.com>
  • Loading branch information...
1 parent 4a9bfe5 commit 905c69d424e4f187178dd8cdab55154045c1a37f @abenari abenari committed with geemus Feb 8, 2012
Showing with 842 additions and 69 deletions.
  1. +1 −0 .gitignore
  2. +1 −1 fog.gemspec
  3. +3 −0 lib/fog/core/errors.rb
  4. +40 −2 lib/fog/ovirt/compute.rb
  5. +2 −5 lib/fog/ovirt/models/compute/clusters.rb
  6. +0 −32 lib/fog/ovirt/models/compute/helpers/collection_helper.rb
  7. +13 −6 lib/fog/ovirt/models/compute/server.rb
  8. +2 −5 lib/fog/ovirt/models/compute/servers.rb
  9. +2 −5 lib/fog/ovirt/models/compute/templates.rb
  10. +20 −0 lib/fog/ovirt/requests/compute/create_vm.rb
  11. +7 −4 lib/fog/ovirt/requests/compute/datacenters.rb
  12. +18 −0 lib/fog/ovirt/requests/compute/get_cluster.rb
  13. +18 −0 lib/fog/ovirt/requests/compute/get_template.rb
  14. +18 −0 lib/fog/ovirt/requests/compute/get_virtual_machine.rb
  15. +20 −0 lib/fog/ovirt/requests/compute/list_clusters.rb
  16. +20 −0 lib/fog/ovirt/requests/compute/list_templates.rb
  17. +20 −0 lib/fog/ovirt/requests/compute/list_virtual_machines.rb
  18. +20 −0 lib/fog/ovirt/requests/compute/mock_files/cluster.xml
  19. +39 −0 lib/fog/ovirt/requests/compute/mock_files/clusters.xml
  20. +17 −0 lib/fog/ovirt/requests/compute/mock_files/data_centers.xml
  21. +36 −0 lib/fog/ovirt/requests/compute/mock_files/storage_domains.xml
  22. +39 −0 lib/fog/ovirt/requests/compute/mock_files/template.xml
  23. +110 −0 lib/fog/ovirt/requests/compute/mock_files/templates.xml
  24. +54 −0 lib/fog/ovirt/requests/compute/mock_files/vm.xml
  25. +152 −0 lib/fog/ovirt/requests/compute/mock_files/vms.xml
  26. +6 −3 lib/fog/ovirt/requests/compute/storage_domains.rb
  27. +31 −0 tests/ovirt/models/compute/cluster_tests.rb
  28. +9 −0 tests/ovirt/models/compute/clusters_tests.rb
  29. +12 −6 tests/ovirt/models/compute/server_tests.rb
  30. +5 −0 tests/ovirt/models/compute/servers_tests.rb
  31. +28 −0 tests/ovirt/models/compute/template_tests.rb
  32. +9 −0 tests/ovirt/models/compute/templates_tests.rb
  33. +26 −0 tests/ovirt/requests/compute/create_vm_tests.rb
  34. +18 −0 tests/ovirt/requests/compute/destroy_vm_tests.rb
  35. +13 −0 tests/ovirt/requests/compute/list_datacenters_tests.rb
  36. +13 −0 tests/ovirt/requests/compute/list_storage_domains_tests.rb
View
1 .gitignore
@@ -5,6 +5,7 @@
.rvmrc
.bundle
.DS_Store
+.idea
coverage
doc/*
docs/_site/*
View
2 fog.gemspec
@@ -54,10 +54,10 @@ Gem::Specification.new do |s|
s.add_development_dependency('rdoc')
s.add_development_dependency('thor')
s.add_development_dependency('rspec', '~>1.3.1')
+ s.add_development_dependency('rbovirt', '>=0.0.5')
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")
View
3 lib/fog/core/errors.rb
@@ -54,6 +54,9 @@ def self.missing_credentials
:openstack_username:
:openstack_auth_url:
:openstack_tenant:
+ :ovirt_username:
+ :ovirt_password:
+ :ovirt_url:
:rackspace_api_key:
:rackspace_username:
:rackspace_servicenet:
View
42 lib/fog/ovirt/compute.rb
@@ -18,22 +18,60 @@ class Ovirt < Fog::Service
request :vm_action
request :destroy_vm
+ request :create_vm
request :datacenters
request :storage_domains
+ request :list_virtual_machines
+ request :get_virtual_machine
+ request :list_templates
+ request :get_template
+ request :list_clusters
+ request :get_cluster
+
+ module Shared
+ # converts an OVIRT object into an hash for fog to consume.
+ def ovirt_attrs obj
+ opts = {:raw => obj}
+ obj.instance_variables.each do |v|
+ key = v.gsub("@","").to_sym
+ value = obj.instance_variable_get(v)
+ #ignore nil values
+ next if value.nil?
+
+ opts[key] = case value.class
+ when OVIRT::Link
+ value.id
+ when Hash
+ value
+ else
+ value.to_s.strip
+ end
+ end
+ opts
+ end
+ end
class Mock
+ include Shared
attr_reader :client
+
def initialize(options={})
+ require 'rbovirt'
username = options[:ovirt_username]
password = options[:ovirt_password]
url = options[:ovirt_url]
-
- #@client = OVIRT::Client.new(username, password, url)
end
+ private
+ #read mocks xml
+ def read_xml(file_name)
+ file_path = File.join(File.dirname(__FILE__),"requests","compute","mock_files",file_name)
+ File.read(file_path)
+ end
end
class Real
+ include Shared
attr_reader :client
def initialize(options={})
View
7 lib/fog/ovirt/models/compute/clusters.rb
@@ -1,23 +1,20 @@
require 'fog/core/collection'
require 'fog/ovirt/models/compute/cluster'
-require 'fog/ovirt/models/compute/helpers/collection_helper'
module Fog
module Compute
class Ovirt
class Clusters < Fog::Collection
- include Fog::Compute::Ovirt::Helpers::CollectionHelper
model Fog::Compute::Ovirt::Cluster
def all(filters = {})
- attrs = connection.client.clusters(filters).map { |cluster| ovirt_attrs(cluster) }
- load attrs
+ load connection.list_clusters(filters)
end
def get(id)
- new ovirt_attrs(connection.client.cluster(id))
+ new connection.get_cluster(id)
end
end
View
32 lib/fog/ovirt/models/compute/helpers/collection_helper.rb
@@ -1,32 +0,0 @@
-module Fog
- module Compute
- class Ovirt
- module Helpers
- module CollectionHelper
-
- # converts an OVIRT object into an hash for fog to consume.
- def ovirt_attrs obj
- opts = {:raw => obj}
- obj.instance_variables.each do |v|
- key = v.gsub("@","").to_sym
- value = obj.instance_variable_get(v)
- #ignore nil values
- next if value.nil?
-
- opts[key] = case value.class
- when OVIRT::Link
- value.id
- when Hash
- value
- else
- value.to_s.strip
- end
- end
- opts
- end
-
- end
- end
- end
- end
-end
View
19 lib/fog/ovirt/models/compute/server.rb
@@ -39,29 +39,36 @@ def mac
end
def start(options = {})
- connection.client.vm_action(id, :start)
+ connection.vm_action(:id =>id, :action => :start)
reload
end
def stop(options = {})
- connection.client.vm_action(id, :stop)
+ connection.vm_action(:id =>id, :action => :stop)
reload
end
def reboot(options = {})
- connection.client.vm_action(id, :reboot)
+ stop unless stopped?
+ wait_for { stopped? }
+ connection.vm_action(:id =>id, :action => :start)
+ reload
+ end
+
+ def suspend(options = {})
+ connection.vm_action(:id =>id, :action => :suspend)
reload
end
def destroy(options = {})
- stop unless stopped?
+ (stop unless stopped?) rescue nil #ignore failure, destroy the machine anyway.
wait_for { stopped? }
- connection.client.destroy_vm(id)
+ connection.destroy_vm(:id => id)
end
def save
raise Fog::Errors::Error.new('Resaving an existing object may create a duplicate') if identity
- self.id = connection.client.create_vm(attributes).id
+ self.id = connection.create_vm(attributes).id
reload
end
View
7 lib/fog/ovirt/models/compute/servers.rb
@@ -1,23 +1,20 @@
require 'fog/core/collection'
require 'fog/ovirt/models/compute/server'
-require 'fog/ovirt/models/compute/helpers/collection_helper'
module Fog
module Compute
class Ovirt
class Servers < Fog::Collection
- include Fog::Compute::Ovirt::Helpers::CollectionHelper
model Fog::Compute::Ovirt::Server
def all(filters = {})
- attrs = connection.client.vms(filters).map { |server| ovirt_attrs(server) }
- load attrs
+ load connection.list_virtual_machines(filters)
end
def get(id)
- new ovirt_attrs(connection.client.vm(id))
+ new connection.get_virtual_machine(id)
end
def bootstrap(new_attributes = {})
View
7 lib/fog/ovirt/models/compute/templates.rb
@@ -1,23 +1,20 @@
require 'fog/core/collection'
require 'fog/ovirt/models/compute/template'
-require 'fog/ovirt/models/compute/helpers/collection_helper'
module Fog
module Compute
class Ovirt
class Templates < Fog::Collection
- include Fog::Compute::Ovirt::Helpers::CollectionHelper
model Fog::Compute::Ovirt::Template
def all(filters = {})
- attrs = connection.client.templates(filters).map { |template| ovirt_attrs(template) }
- load attrs
+ load connection.list_templates(filters)
end
def get(id)
- new ovirt_attrs(connection.client.template(id))
+ new connection.get_template(id)
end
end
View
20 lib/fog/ovirt/requests/compute/create_vm.rb
@@ -0,0 +1,20 @@
+module Fog
+ module Compute
+ class Ovirt
+
+ class Real
+ def create_vm(attrs)
+ client.create_vm(attrs)
+ end
+ end
+
+ class Mock
+ def create_vm(attrs)
+ xml = read_xml('vm.xml')
+ OVIRT::VM::new(self, Nokogiri::XML(xml).root)
+ end
+
+ end
+ end
+ end
+end
View
11 lib/fog/ovirt/requests/compute/datacenters.rb
@@ -4,14 +4,17 @@ class Ovirt
class Real
def datacenters filter={}
- client.datacenters(filter)
+ client.datacenters(filter).map {|ovirt_obj| ovirt_attrs ovirt_obj}
end
end
- class Mock
- def datacenters filter={}
- [ "Solutions", "Solutions2", "Solutions3" ]
+ class Mock
+ def datacenters(filters = {})
+ xml = read_xml 'data_centers.xml'
+ Nokogiri::XML(xml).xpath('/data_centers/data_center').collect do |dc|
+ ovirt_attrs OVIRT::DataCenter::new(self, dc)
+ end
end
end
end
View
18 lib/fog/ovirt/requests/compute/get_cluster.rb
@@ -0,0 +1,18 @@
+module Fog
+ module Compute
+ class Ovirt
+ class Real
+ def get_cluster(id)
+ ovirt_attrs client.cluster(id)
+ end
+
+ end
+ class Mock
+ def get_cluster(id)
+ xml = read_xml('cluster.xml')
+ ovirt_attrs OVIRT::Cluster::new(self, Nokogiri::XML(xml).root)
+ end
+ end
+ end
+ end
+end
View
18 lib/fog/ovirt/requests/compute/get_template.rb
@@ -0,0 +1,18 @@
+module Fog
+ module Compute
+ class Ovirt
+ class Real
+ def get_template(id)
+ ovirt_attrs client.template(id)
+ end
+
+ end
+ class Mock
+ def get_template(id)
+ xml = read_xml 'template.xml'
+ ovirt_attrs OVIRT::Template::new(self, Nokogiri::XML(xml).root)
+ end
+ end
+ end
+ end
+end
View
18 lib/fog/ovirt/requests/compute/get_virtual_machine.rb
@@ -0,0 +1,18 @@
+module Fog
+ module Compute
+ class Ovirt
+ class Real
+ def get_virtual_machine(id)
+ ovirt_attrs client.vm(id)
+ end
+
+ end
+ class Mock
+ def get_virtual_machine(id)
+ xml = read_xml 'vm.xml'
+ ovirt_attrs OVIRT::VM::new(self, Nokogiri::XML(xml).root)
+ end
+ end
+ end
+ end
+end
View
20 lib/fog/ovirt/requests/compute/list_clusters.rb
@@ -0,0 +1,20 @@
+module Fog
+ module Compute
+ class Ovirt
+ class Real
+ def list_clusters(filters = {})
+ client.clusters(filters).map {|ovirt_obj| ovirt_attrs ovirt_obj}
+ end
+
+ end
+ class Mock
+ def list_clusters(filters = {})
+ xml = read_xml 'clusters.xml'
+ Nokogiri::XML(xml).xpath('/clusters/cluster').collect do |cl|
+ ovirt_attrs OVIRT::Cluster::new(self, cl)
+ end
+ end
+ end
+ end
+ end
+end
View
20 lib/fog/ovirt/requests/compute/list_templates.rb
@@ -0,0 +1,20 @@
+module Fog
+ module Compute
+ class Ovirt
+ class Real
+ def list_templates(filters = {})
+ client.templates(filters).map {|ovirt_obj| ovirt_attrs ovirt_obj}
+ end
+
+ end
+ class Mock
+ def list_templates(filters = {})
+ xml = read_xml 'templates.xml'
+ Nokogiri::XML(xml).xpath('/templates/template').collect do |t|
+ ovirt_attrs OVIRT::Template::new(self, t)
+ end
+ end
+ end
+ end
+ end
+end
View
20 lib/fog/ovirt/requests/compute/list_virtual_machines.rb
@@ -0,0 +1,20 @@
+module Fog
+ module Compute
+ class Ovirt
+ class Real
+ def list_virtual_machines(filters = {})
+ client.vms(filters).map {|ovirt_obj| ovirt_attrs ovirt_obj}
+ end
+
+ end
+ class Mock
+ def list_virtual_machines(filters = {})
+ xml = read_xml 'vms.xml'
+ Nokogiri::XML(xml).xpath('/vms/vm').collect do |vm|
+ ovirt_attrs OVIRT::VM::new(self, vm)
+ end
+ end
+ end
+ end
+ end
+end
View
20 lib/fog/ovirt/requests/compute/mock_files/cluster.xml
@@ -0,0 +1,20 @@
+<clusters>
+<cluster href="/api/clusters/9ce445e8-4c03-11e1-b3c8-5254009970cc" id="9ce445e8-4c03-11e1-b3c8-5254009970cc">
+<name>cluster1</name>
+<link href="/api/clusters/9ce445e8-4c03-11e1-b3c8-5254009970cc/networks" rel="networks"/>
+<link href="/api/clusters/9ce445e8-4c03-11e1-b3c8-5254009970cc/permissions" rel="permissions"/>
+<cpu id="Intel Conroe Family"/>
+<data_center href="/api/datacenters/c0645886-4b4b-11e1-a0ae-5254009970cc" id="c0645886-4b4b-11e1-a0ae-5254009970cc"/>
+<memory_policy>
+<overcommit percent="200"/>
+<transparent_hugepages>
+<enabled>true</enabled>
+</transparent_hugepages>
+</memory_policy>
+<scheduling_policy/>
+<version major="3" minor="0"/>
+<error_handling>
+<on_error>migrate_highly_available</on_error>
+</error_handling>
+</cluster>
+</clusters>
View
39 lib/fog/ovirt/requests/compute/mock_files/clusters.xml
@@ -0,0 +1,39 @@
+<clusters>
+<cluster href="/api/clusters/99408929-82cf-4dc7-a532-9d998063fa95" id="99408929-82cf-4dc7-a532-9d998063fa95">
+<name>Cluster1</name>
+<description>The default server cluster</description>
+<link href="/api/clusters/99408929-82cf-4dc7-a532-9d998063fa95/networks" rel="networks"/>
+<link href="/api/clusters/99408929-82cf-4dc7-a532-9d998063fa95/permissions" rel="permissions"/>
+<cpu id="Intel Conroe Family"/>
+<data_center href="/api/datacenters/c0645886-4b4b-11e1-a0ae-5254009970cc" id="c0645886-4b4b-11e1-a0ae-5254009970cc"/>
+<memory_policy>
+<overcommit percent="100"/>
+<transparent_hugepages>
+<enabled>true</enabled>
+</transparent_hugepages>
+</memory_policy>
+<scheduling_policy/>
+<version major="3" minor="0"/>
+<error_handling>
+<on_error>migrate</on_error>
+</error_handling>
+</cluster>
+<cluster href="/api/clusters/9ce445e8-4c03-11e1-b3c8-5254009970cc" id="9ce445e8-4c03-11e1-b3c8-5254009970cc">
+<name>Cluster2</name>
+<link href="/api/clusters/9ce445e8-4c03-11e1-b3c8-5254009970cc/networks" rel="networks"/>
+<link href="/api/clusters/9ce445e8-4c03-11e1-b3c8-5254009970cc/permissions" rel="permissions"/>
+<cpu id="Intel Conroe Family"/>
+<data_center href="/api/datacenters/c0645886-4b4b-11e1-a0ae-5254009970cc" id="c0645886-4b4b-11e1-a0ae-5254009970cc"/>
+<memory_policy>
+<overcommit percent="200"/>
+<transparent_hugepages>
+<enabled>true</enabled>
+</transparent_hugepages>
+</memory_policy>
+<scheduling_policy/>
+<version major="3" minor="0"/>
+<error_handling>
+<on_error>migrate_highly_available</on_error>
+</error_handling>
+</cluster>
+</clusters>
View
17 lib/fog/ovirt/requests/compute/mock_files/data_centers.xml
@@ -0,0 +1,17 @@
+<data_centers>
+<data_center href="/api/datacenters/c0645886-4b4b-11e1-a0ae-5254009970cc" id="c0645886-4b4b-11e1-a0ae-5254009970cc">
+<name>Datacenter1</name>
+<description>The first Data Center</description>
+<link href="/api/datacenters/c0645886-4b4b-11e1-a0ae-5254009970cc/storagedomains" rel="storagedomains"/>
+<link href="/api/datacenters/c0645886-4b4b-11e1-a0ae-5254009970cc/permissions" rel="permissions"/>
+<storage_type>nfs</storage_type>
+<storage_format>v1</storage_format>
+<version major="3" minor="0"/>
+<supported_versions>
+<version major="3" minor="0"/>
+</supported_versions>
+<status>
+<state>up</state>
+</status>
+</data_center>
+</data_centers>
View
36 lib/fog/ovirt/requests/compute/mock_files/storage_domains.xml
@@ -0,0 +1,36 @@
+<storage_domains>
+<storage_domain href="/api/storagedomains/382ec55a-f886-4fa1-b880-0a9fa778aa5b" id="382ec55a-f886-4fa1-b880-0a9fa778aa5b">
+<name>covirt</name>
+<link href="/api/storagedomains/382ec55a-f886-4fa1-b880-0a9fa778aa5b/permissions" rel="permissions"/>
+<link href="/api/storagedomains/382ec55a-f886-4fa1-b880-0a9fa778aa5b/files" rel="files"/>
+<type>iso</type>
+<status>
+<state>unattached</state>
+</status>
+<master>false</master>
+<storage>
+<type>nfs</type>
+<address>ovirt.server.com</address>
+<path>/mnt/nfs</path>
+</storage>
+<available>0</available>
+<used>0</used>
+<committed>0</committed>
+<storage_format>v1</storage_format>
+</storage_domain>
+<storage_domain href="/api/storagedomains/312f6445-79da-4ce4-907d-9a871125e3ca" id="312f6445-79da-4ce4-907d-9a871125e3ca">
+<name>nfs</name>
+<link href="/api/storagedomains/312f6445-79da-4ce4-907d-9a871125e3ca/permissions" rel="permissions"/>
+<type>data</type>
+<master>true</master>
+<storage>
+<type>nfs</type>
+<address>storage.server.com</address>
+<path>/volumes/path/for/ovirt</path>
+</storage>
+<available>40802189312</available>
+<used>66571993088</used>
+<committed>75161927680</committed>
+<storage_format>v1</storage_format>
+</storage_domain>
+</storage_domains>
View
39 lib/fog/ovirt/requests/compute/mock_files/template.xml
@@ -0,0 +1,39 @@
+<templates>
+<template href="/api/templates/2a08ba05-f3b1-4e5a-ade9-496466a8b323" id="2a08ba05-f3b1-4e5a-ade9-496466a8b323">
+<name>hwp_small</name>
+<description>hardware profile small</description>
+<link href="/api/templates/2a08ba05-f3b1-4e5a-ade9-496466a8b323/disks" rel="disks"/>
+<link href="/api/templates/2a08ba05-f3b1-4e5a-ade9-496466a8b323/nics" rel="nics"/>
+<link href="/api/templates/2a08ba05-f3b1-4e5a-ade9-496466a8b323/cdroms" rel="cdroms"/>
+<link href="/api/templates/2a08ba05-f3b1-4e5a-ade9-496466a8b323/permissions" rel="permissions"/>
+<type>server</type>
+<status>
+<state>ok</state>
+</status>
+<memory>536870912</memory>
+<cpu>
+<topology sockets="1" cores="1"/>
+</cpu>
+<os type="unassigned">
+<boot dev="network"/>
+<kernel/>
+<initrd/>
+<cmdline/>
+</os>
+<cluster href="/api/clusters/99408929-82cf-4dc7-a532-9d998063fa95" id="99408929-82cf-4dc7-a532-9d998063fa95"/>
+<creation_time>2012-01-31T07:47:03.811Z</creation_time>
+<origin>rhev</origin>
+<high_availability>
+<enabled>false</enabled>
+<priority>1</priority>
+</high_availability>
+<display>
+<type>spice</type>
+<monitors>1</monitors>
+</display>
+<stateless>false</stateless>
+<usb>
+<enabled>true</enabled>
+</usb>
+</template>
+</templates>
View
110 lib/fog/ovirt/requests/compute/mock_files/templates.xml
@@ -0,0 +1,110 @@
+<templates>
+<template href="/api/templates/00000000-0000-0000-0000-000000000000" id="00000000-0000-0000-0000-000000000000">
+<name>Blank</name>
+<description>Blank template</description>
+<link href="/api/templates/00000000-0000-0000-0000-000000000000/disks" rel="disks"/>
+<link href="/api/templates/00000000-0000-0000-0000-000000000000/nics" rel="nics"/>
+<link href="/api/templates/00000000-0000-0000-0000-000000000000/cdroms" rel="cdroms"/>
+<link href="/api/templates/00000000-0000-0000-0000-000000000000/permissions" rel="permissions"/>
+<type>desktop</type>
+<status>
+<state>ok</state>
+</status>
+<memory>536870912</memory>
+<cpu>
+<topology sockets="1" cores="1"/>
+</cpu>
+<os type="unassigned">
+<boot dev="hd"/>
+</os>
+<cluster href="/api/clusters/99408929-82cf-4dc7-a532-9d998063fa95" id="99408929-82cf-4dc7-a532-9d998063fa95"/>
+<creation_time>2008-04-01T00:00:00.000+01:00</creation_time>
+<origin>rhev</origin>
+<high_availability>
+<enabled>false</enabled>
+<priority>0</priority>
+</high_availability>
+<display>
+<type>spice</type>
+<monitors>1</monitors>
+</display>
+<stateless>false</stateless>
+<usb>
+<enabled>true</enabled>
+</usb>
+</template>
+<template href="/api/templates/05a5144f-8ef7-4151-b7f9-5014510b489e" id="05a5144f-8ef7-4151-b7f9-5014510b489e">
+<name>hwp_large</name>
+<description>hardware profile large</description>
+<link href="/api/templates/05a5144f-8ef7-4151-b7f9-5014510b489e/disks" rel="disks"/>
+<link href="/api/templates/05a5144f-8ef7-4151-b7f9-5014510b489e/nics" rel="nics"/>
+<link href="/api/templates/05a5144f-8ef7-4151-b7f9-5014510b489e/cdroms" rel="cdroms"/>
+<link href="/api/templates/05a5144f-8ef7-4151-b7f9-5014510b489e/permissions" rel="permissions"/>
+<type>server</type>
+<status>
+<state>ok</state>
+</status>
+<memory>1073741824</memory>
+<cpu>
+<topology sockets="4" cores="1"/>
+</cpu>
+<os type="unassigned">
+<boot dev="network"/>
+<kernel/>
+<initrd/>
+<cmdline/>
+</os>
+<cluster href="/api/clusters/99408929-82cf-4dc7-a532-9d998063fa95" id="99408929-82cf-4dc7-a532-9d998063fa95"/>
+<creation_time>2012-01-31T07:53:19.047Z</creation_time>
+<origin>rhev</origin>
+<high_availability>
+<enabled>false</enabled>
+<priority>1</priority>
+</high_availability>
+<display>
+<type>spice</type>
+<monitors>1</monitors>
+</display>
+<stateless>false</stateless>
+<usb>
+<enabled>true</enabled>
+</usb>
+</template>
+<template href="/api/templates/2a08ba05-f3b1-4e5a-ade9-496466a8b323" id="2a08ba05-f3b1-4e5a-ade9-496466a8b323">
+<name>hwp_small</name>
+<description>hardware profile small</description>
+<link href="/api/templates/2a08ba05-f3b1-4e5a-ade9-496466a8b323/disks" rel="disks"/>
+<link href="/api/templates/2a08ba05-f3b1-4e5a-ade9-496466a8b323/nics" rel="nics"/>
+<link href="/api/templates/2a08ba05-f3b1-4e5a-ade9-496466a8b323/cdroms" rel="cdroms"/>
+<link href="/api/templates/2a08ba05-f3b1-4e5a-ade9-496466a8b323/permissions" rel="permissions"/>
+<type>server</type>
+<status>
+<state>ok</state>
+</status>
+<memory>536870912</memory>
+<cpu>
+<topology sockets="1" cores="1"/>
+</cpu>
+<os type="unassigned">
+<boot dev="network"/>
+<kernel/>
+<initrd/>
+<cmdline/>
+</os>
+<cluster href="/api/clusters/99408929-82cf-4dc7-a532-9d998063fa95" id="99408929-82cf-4dc7-a532-9d998063fa95"/>
+<creation_time>2012-01-31T07:47:03.811Z</creation_time>
+<origin>rhev</origin>
+<high_availability>
+<enabled>false</enabled>
+<priority>1</priority>
+</high_availability>
+<display>
+<type>spice</type>
+<monitors>1</monitors>
+</display>
+<stateless>false</stateless>
+<usb>
+<enabled>true</enabled>
+</usb>
+</template>
+</templates>
View
54 lib/fog/ovirt/requests/compute/mock_files/vm.xml
@@ -0,0 +1,54 @@
+<vms>
+<vm href="/api/vms/52b9406e-cf66-4867-8655-719a094e324c" id="52b9406e-cf66-4867-8655-719a094e324c">
+<name>vm01</name>
+<link href="/api/vms/52b9406e-cf66-4867-8655-719a094e324c/disks" rel="disks"/>
+<link href="/api/vms/52b9406e-cf66-4867-8655-719a094e324c/nics" rel="nics"/>
+<link href="/api/vms/52b9406e-cf66-4867-8655-719a094e324c/cdroms" rel="cdroms"/>
+<link href="/api/vms/52b9406e-cf66-4867-8655-719a094e324c/snapshots" rel="snapshots"/>
+<link href="/api/vms/52b9406e-cf66-4867-8655-719a094e324c/tags" rel="tags"/>
+<link href="/api/vms/52b9406e-cf66-4867-8655-719a094e324c/permissions" rel="permissions"/>
+<link href="/api/vms/52b9406e-cf66-4867-8655-719a094e324c/statistics" rel="statistics"/>
+<type>server</type>
+<status>
+<state>down</state>
+</status>
+<memory>805306368</memory>
+<cpu>
+<topology sockets="1" cores="1"/>
+</cpu>
+<os type="unassigned">
+<boot dev="network"/>
+<boot dev="hd"/>
+<kernel/>
+<initrd/>
+<cmdline/>
+</os>
+<high_availability>
+<enabled>false</enabled>
+<priority>1</priority>
+</high_availability>
+<display>
+<type>spice</type>
+<address>host</address>
+<port>5900</port>
+<secure_port>5901</secure_port>
+<monitors>1</monitors>
+</display>
+<host href="/api/hosts/3690fafa-4b4c-11e1-8b7b-5254009970cc" id="3690fafa-4b4c-11e1-8b7b-5254009970cc"/>
+<cluster href="/api/clusters/99408929-82cf-4dc7-a532-9d998063fa95" id="99408929-82cf-4dc7-a532-9d998063fa95"/>
+<template href="/api/templates/00000000-0000-0000-0000-000000000000" id="00000000-0000-0000-0000-000000000000"/>
+<start_time>2012-02-05T11:00:33.222Z</start_time>
+<creation_time>2012-01-31T07:21:10.667Z</creation_time>
+<origin>rhev</origin>
+<stateless>false</stateless>
+<placement_policy>
+<affinity>migratable</affinity>
+</placement_policy>
+<memory_policy>
+<guaranteed>536870912</guaranteed>
+</memory_policy>
+<usb>
+<enabled>true</enabled>
+</usb>
+</vm>
+</vms>
View
152 lib/fog/ovirt/requests/compute/mock_files/vms.xml
@@ -0,0 +1,152 @@
+<vms>
+<vm href="/api/vms/5ee86332-7b19-465b-8801-2a12ed0d6c1b" id="5ee86332-7b19-465b-8801-2a12ed0d6c1b">
+<name>test-vm1</name>
+<link href="/api/vms/5ee86332-7b19-465b-8801-2a12ed0d6c1b/disks" rel="disks"/>
+<link href="/api/vms/5ee86332-7b19-465b-8801-2a12ed0d6c1b/nics" rel="nics"/>
+<link href="/api/vms/5ee86332-7b19-465b-8801-2a12ed0d6c1b/cdroms" rel="cdroms"/>
+<link href="/api/vms/5ee86332-7b19-465b-8801-2a12ed0d6c1b/snapshots" rel="snapshots"/>
+<link href="/api/vms/5ee86332-7b19-465b-8801-2a12ed0d6c1b/tags" rel="tags"/>
+<link href="/api/vms/5ee86332-7b19-465b-8801-2a12ed0d6c1b/permissions" rel="permissions"/>
+<link href="/api/vms/5ee86332-7b19-465b-8801-2a12ed0d6c1b/statistics" rel="statistics"/>
+<type>server</type>
+<status>
+<state>down</state>
+</status>
+<memory>1073741824</memory>
+<cpu>
+<topology sockets="1" cores="4"/>
+</cpu>
+<os type="unassigned">
+<boot dev="network"/>
+<kernel/>
+<initrd/>
+<cmdline/>
+</os>
+<high_availability>
+<enabled>false</enabled>
+<priority>1</priority>
+</high_availability>
+<display>
+<type>spice</type>
+<monitors>1</monitors>
+</display>
+<cluster href="/api/clusters/99408929-82cf-4dc7-a532-9d998063fa95" id="99408929-82cf-4dc7-a532-9d998063fa95"/>
+<template href="/api/templates/00000000-0000-0000-0000-000000000000" id="00000000-0000-0000-0000-000000000000"/>
+<start_time>2012-02-06T10:47:32.214Z</start_time>
+<creation_time>2012-01-31T07:45:13.068Z</creation_time>
+<origin>rhev</origin>
+<stateless>false</stateless>
+<placement_policy>
+<affinity>migratable</affinity>
+</placement_policy>
+<memory_policy>
+<guaranteed>536870912</guaranteed>
+</memory_policy>
+<usb>
+<enabled>true</enabled>
+</usb>
+</vm>
+<vm href="/api/vms/349764bb-eba3-4466-abef-f18f4c40c9f1" id="349764bb-eba3-4466-abef-f18f4c40c9f1">
+<name>fosdem</name>
+<link href="/api/vms/349764bb-eba3-4466-abef-f18f4c40c9f1/disks" rel="disks"/>
+<link href="/api/vms/349764bb-eba3-4466-abef-f18f4c40c9f1/nics" rel="nics"/>
+<link href="/api/vms/349764bb-eba3-4466-abef-f18f4c40c9f1/cdroms" rel="cdroms"/>
+<link href="/api/vms/349764bb-eba3-4466-abef-f18f4c40c9f1/snapshots" rel="snapshots"/>
+<link href="/api/vms/349764bb-eba3-4466-abef-f18f4c40c9f1/tags" rel="tags"/>
+<link href="/api/vms/349764bb-eba3-4466-abef-f18f4c40c9f1/permissions" rel="permissions"/>
+<link href="/api/vms/349764bb-eba3-4466-abef-f18f4c40c9f1/statistics" rel="statistics"/>
+<type>server</type>
+<status>
+<state>down</state>
+</status>
+<memory>536870912</memory>
+<cpu>
+<topology sockets="1" cores="1"/>
+</cpu>
+<os type="unassigned">
+<boot dev="hd"/>
+<kernel/>
+<initrd/>
+<cmdline/>
+</os>
+<high_availability>
+<enabled>false</enabled>
+<priority>1</priority>
+</high_availability>
+<display>
+<type>spice</type>
+<address>host</address>
+<port>5902</port>
+<secure_port>5903</secure_port>
+<monitors>1</monitors>
+</display>
+<host href="/api/hosts/3690fafa-4b4c-11e1-8b7b-5254009970cc" id="3690fafa-4b4c-11e1-8b7b-5254009970cc"/>
+<cluster href="/api/clusters/99408929-82cf-4dc7-a532-9d998063fa95" id="99408929-82cf-4dc7-a532-9d998063fa95"/>
+<template href="/api/templates/00000000-0000-0000-0000-000000000000" id="00000000-0000-0000-0000-000000000000"/>
+<start_time>2012-02-05T11:04:39.217Z</start_time>
+<creation_time>2012-02-05T10:53:30.484Z</creation_time>
+<origin>rhev</origin>
+<stateless>false</stateless>
+<placement_policy>
+<affinity>migratable</affinity>
+</placement_policy>
+<memory_policy>
+<guaranteed>536870912</guaranteed>
+</memory_policy>
+<usb>
+<enabled>true</enabled>
+</usb>
+</vm>
+<vm href="/api/vms/52b9406e-cf66-4867-8655-719a094e324c" id="52b9406e-cf66-4867-8655-719a094e324c">
+<name>vm01</name>
+<link href="/api/vms/52b9406e-cf66-4867-8655-719a094e324c/disks" rel="disks"/>
+<link href="/api/vms/52b9406e-cf66-4867-8655-719a094e324c/nics" rel="nics"/>
+<link href="/api/vms/52b9406e-cf66-4867-8655-719a094e324c/cdroms" rel="cdroms"/>
+<link href="/api/vms/52b9406e-cf66-4867-8655-719a094e324c/snapshots" rel="snapshots"/>
+<link href="/api/vms/52b9406e-cf66-4867-8655-719a094e324c/tags" rel="tags"/>
+<link href="/api/vms/52b9406e-cf66-4867-8655-719a094e324c/permissions" rel="permissions"/>
+<link href="/api/vms/52b9406e-cf66-4867-8655-719a094e324c/statistics" rel="statistics"/>
+<type>server</type>
+<status>
+<state>down</state>
+</status>
+<memory>805306368</memory>
+<cpu>
+<topology sockets="1" cores="1"/>
+</cpu>
+<os type="unassigned">
+<boot dev="network"/>
+<boot dev="hd"/>
+<kernel/>
+<initrd/>
+<cmdline/>
+</os>
+<high_availability>
+<enabled>false</enabled>
+<priority>1</priority>
+</high_availability>
+<display>
+<type>spice</type>
+<address>host</address>
+<port>5900</port>
+<secure_port>5901</secure_port>
+<monitors>1</monitors>
+</display>
+<host href="/api/hosts/3690fafa-4b4c-11e1-8b7b-5254009970cc" id="3690fafa-4b4c-11e1-8b7b-5254009970cc"/>
+<cluster href="/api/clusters/99408929-82cf-4dc7-a532-9d998063fa95" id="99408929-82cf-4dc7-a532-9d998063fa95"/>
+<template href="/api/templates/00000000-0000-0000-0000-000000000000" id="00000000-0000-0000-0000-000000000000"/>
+<start_time>2012-02-05T11:00:33.222Z</start_time>
+<creation_time>2012-01-31T07:21:10.667Z</creation_time>
+<origin>rhev</origin>
+<stateless>false</stateless>
+<placement_policy>
+<affinity>migratable</affinity>
+</placement_policy>
+<memory_policy>
+<guaranteed>536870912</guaranteed>
+</memory_policy>
+<usb>
+<enabled>true</enabled>
+</usb>
+</vm>
+</vms>
View
9 lib/fog/ovirt/requests/compute/storage_domains.rb
@@ -4,14 +4,17 @@ class Ovirt
class Real
def storage_domains filter={}
- client.storage_domains(filter)
+ client.storagedomains(filter).map {|ovirt_obj| ovirt_attrs ovirt_obj}
end
end
class Mock
- def storage_domains filter={}
- [ "Storage", "Storage2", "Storage3" ]
+ def storage_domains(filters = {})
+ xml = read_xml 'storage_domains.xml'
+ Nokogiri::XML(xml).xpath('/storage_domains/storage_domain').collect do |sd|
+ ovirt_attrs OVIRT::StorageDomain::new(self, sd)
+ end
end
end
end
View
31 tests/ovirt/models/compute/cluster_tests.rb
@@ -0,0 +1,31 @@
+Shindo.tests('Fog::Compute[:ovirt] | cluster model', ['ovirt']) do
+
+ clusters = Fog::Compute[:ovirt].clusters
+ cluster = clusters.last
+
+ tests('The cluster model should') do
+ tests('have the action') do
+ test('reload') { cluster.respond_to? 'reload' }
+ %w{ networks }.each do |action|
+ test(action) { cluster.respond_to? action }
+ end
+ end
+ tests('have attributes') do
+ model_attribute_hash = cluster.attributes
+ attributes = [ :id,
+ :name]
+ tests("The cluster model should respond to") do
+ attributes.each do |attribute|
+ test("#{attribute}") { cluster.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::Cluster') { cluster.kind_of? Fog::Compute::Ovirt::Cluster }
+ end
+
+end
View
9 tests/ovirt/models/compute/clusters_tests.rb
@@ -0,0 +1,9 @@
+Shindo.tests('Fog::Compute[:ovirt] | clusters collection', ['ovirt']) do
+
+ clusters = Fog::Compute[:ovirt].clusters
+
+ tests('The clusters collection') do
+ test('should be a kind of Fog::Compute::Ovirt::Clusters') { clusters.kind_of? Fog::Compute::Ovirt::Clusters }
+ end
+
+end
View
18 tests/ovirt/models/compute/server_tests.rb
@@ -6,9 +6,19 @@
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|
+ %w{ start stop destroy reboot suspend }.each do |action|
test(action) { server.respond_to? action }
end
+ %w{ start reboot suspend stop }.each do |action|
+ test("#{action} returns successfully") {
+ begin
+ server.send(action.to_sym) ? true : false
+ rescue OVIRT::OvirtException
+ #ovirt exceptions are acceptable for the above actions.
+ true
+ end
+ }
+ end
end
tests('have attributes') do
model_attribute_hash = server.attributes
@@ -17,14 +27,11 @@
:description,
:profile,
:display,
- :storage,
:creation_time,
:os,
- :ip,
:status,
:cores,
:memory,
- :host,
:cluster,
:template]
tests("The server model should respond to") do
@@ -41,5 +48,4 @@
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
+end
View
5 tests/ovirt/models/compute/servers_tests.rb
@@ -3,7 +3,12 @@
servers = Fog::Compute[:ovirt].servers
tests('The servers collection') do
+ test('should not be empty') { not servers.empty? }
test('should be a kind of Fog::Compute::Ovirt::Servers') { servers.kind_of? Fog::Compute::Ovirt::Servers }
+ tests('should be able to reload itself').succeeds { servers.reload }
+ tests('should be able to get a model') do
+ tests('by instance uuid').succeeds { servers.get servers.first.id }
+ end
end
end
View
28 tests/ovirt/models/compute/template_tests.rb
@@ -0,0 +1,28 @@
+Shindo.tests('Fog::Compute[:ovirt] | template model', ['ovirt']) do
+
+ templates = Fog::Compute[:ovirt].templates
+ template = templates.last
+
+ tests('The template model should') do
+ tests('have the action') do
+ test('reload') { template.respond_to? 'reload' }
+ end
+ tests('have attributes') do
+ model_attribute_hash = template.attributes
+ attributes = [ :id,
+ :name]
+ tests("The template model should respond to") do
+ attributes.each do |attribute|
+ test("#{attribute}") { template.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::Template') { template.kind_of? Fog::Compute::Ovirt::Template }
+ end
+
+end
View
9 tests/ovirt/models/compute/templates_tests.rb
@@ -0,0 +1,9 @@
+Shindo.tests('Fog::Compute[:ovirt] | templates collection', ['ovirt']) do
+
+ templates = Fog::Compute[:ovirt].templates
+
+ tests('The templates collection') do
+ test('should be a kind of Fog::Compute::Ovirt::Templates') { templates.kind_of? Fog::Compute::Ovirt::Templates }
+ end
+
+end
View
26 tests/ovirt/requests/compute/create_vm_tests.rb
@@ -0,0 +1,26 @@
+Shindo.tests("Fog::Compute[:ovirt] | vm_create request", 'ovirt') do
+
+ compute = Fog::Compute[:ovirt]
+ name_base = Time.now.to_i
+
+ tests("Create VM") do
+ response = compute.create_vm(:name => 'fog-'+name_base.to_s, :cluster_name => 'Default')
+ test("should be a kind of OVIRT::VM") { response.kind_of? OVIRT::VM}
+ end
+
+ tests("Create VM from template (clone)") do
+ response = compute.create_vm(:name => 'fog-'+(name_base+ 1).to_s, :template_name => 'hwp_small', :cluster_name => 'Default')
+ test("should be a kind of OVIRT::VM") { response.kind_of? OVIRT::VM}
+ end
+
+ tests("Fail Creating VM") do
+ begin
+ response = compute.create_vm(:name => 'fog-'+name_base.to_s, :cluster_name => 'Default')
+ test("should be a kind of OVIRT::VM") { response.kind_of? OVIRT::VM} #mock never raise exceptions
+ rescue => e
+ #should raise vm name already exist exception.
+ test("error should be a kind of OVIRT::OvirtException") { e.kind_of? OVIRT::OvirtException}
+ end
+ end
+
+end
View
18 tests/ovirt/requests/compute/destroy_vm_tests.rb
@@ -0,0 +1,18 @@
+Shindo.tests('Fog::Compute[:ovirt] | vm_destroy request', ['ovirt']) do
+
+ compute = Fog::Compute[:ovirt]
+ if compute.servers.all(:search => 'fog-*').empty?
+ compute.create_vm(:name => 'fog-'+Time.now.to_i.to_s, :cluster_name => 'Default')
+ end
+ vm_id = compute.servers.all(:search => 'fog-*').last.id
+
+ tests('The response should') do
+ response = compute.destroy_vm(:id => vm_id)
+ test('be a success') { response ? true: false }
+ end
+
+ tests('The expected options') do
+ raises(ArgumentError, 'raises ArgumentError when id option is missing') { compute.destroy_vm }
+ end
+
+end
View
13 tests/ovirt/requests/compute/list_datacenters_tests.rb
@@ -0,0 +1,13 @@
+Shindo.tests('Fog::Compute[:ovirt] | datacenters request', ['ovirt']) do
+
+ compute = Fog::Compute[:ovirt]
+
+ tests("When listing all datacenters") do
+
+ response = compute.datacenters
+ tests("The response data format ...") do
+ test("it should be a kind of Array") { response.kind_of? Array }
+ test("be a kind of Hash") { response.first.kind_of? Hash }
+ end
+ end
+end
View
13 tests/ovirt/requests/compute/list_storage_domains_tests.rb
@@ -0,0 +1,13 @@
+Shindo.tests('Fog::Compute[:ovirt] | storage_domains request', ['ovirt']) do
+
+ compute = Fog::Compute[:ovirt]
+
+ tests("When listing all storage_domains") do
+
+ response = compute.storage_domains
+ tests("The response data format ...") do
+ test("it should be a kind of Array") { response.kind_of? Array }
+ test("be a kind of Hash") { response.first.kind_of? Hash }
+ end
+ end
+end

0 comments on commit 905c69d

Please sign in to comment.