mirror of
https://github.com/fog/fog.git
synced 2022-11-09 13:51:43 -05:00
[opennebula] add vm_allocate and network tests
This commit is contained in:
parent
8bcf2467cf
commit
be29b214f3
4 changed files with 108 additions and 0 deletions
16
tests/opennebula/compute_tests.rb
Normal file
16
tests/opennebula/compute_tests.rb
Normal file
|
@ -0,0 +1,16 @@
|
|||
Shindo.tests('Fog::Compute[:opennebula]', ['opennebula']) do
|
||||
|
||||
compute = Fog::Compute[:opennebula]
|
||||
|
||||
tests("Compute collections") do
|
||||
%w{networks}.each do |collection|
|
||||
test("it should respond to #{collection}") { compute.respond_to? collection }
|
||||
end
|
||||
end
|
||||
|
||||
tests("Compute requests") do
|
||||
%w{list_networks}.each do |request|
|
||||
test("it should respond to #{request}") { compute.respond_to? request }
|
||||
end
|
||||
end
|
||||
end
|
27
tests/opennebula/models/compute/network_tests.rb
Normal file
27
tests/opennebula/models/compute/network_tests.rb
Normal file
|
@ -0,0 +1,27 @@
|
|||
Shindo.tests('Fog::Compute[:opennebula] | network model', ['opennebula']) do
|
||||
|
||||
networks = Fog::Compute[:opennebula].networks
|
||||
network = networks.last
|
||||
|
||||
tests('The network model should') do
|
||||
tests('have the action') do
|
||||
test('reload') { network.respond_to? 'reload' }
|
||||
end
|
||||
tests('have attributes') do
|
||||
model_attribute_hash = network.attributes
|
||||
attributes =
|
||||
tests("The network model should respond to") do
|
||||
[:name, :id, :vlan, :uid, :gid, :description].each do |attribute|
|
||||
test("#{attribute}") { network.respond_to? attribute }
|
||||
end
|
||||
end
|
||||
tests("The attributes hash should have key") do
|
||||
[:name, :id, :uid, :gid].each do |attribute|
|
||||
test("#{attribute}") { model_attribute_hash.has_key? attribute }
|
||||
end
|
||||
end
|
||||
end
|
||||
test('be a kind of Fog::Compute::OpenNebula::Network') { network.kind_of? Fog::Compute::OpenNebula::Network }
|
||||
end
|
||||
|
||||
end
|
13
tests/opennebula/models/compute/networks_tests.rb
Normal file
13
tests/opennebula/models/compute/networks_tests.rb
Normal file
|
@ -0,0 +1,13 @@
|
|||
Shindo.tests('Fog::Compute[:opennebula] | networks collection', ['opennebula']) do
|
||||
|
||||
networks = Fog::Compute[:opennebula].networks
|
||||
|
||||
tests('The networks collection') do
|
||||
test('should be a kind of Fog::Compute::OpenNebula::Networks') { networks.kind_of? Fog::Compute::OpenNebula::Networks }
|
||||
tests('should be able to reload itself').succeeds { networks.reload }
|
||||
tests('should be able to get a model') do
|
||||
tests('by instance id').succeeds { networks.get networks.first.uuid }
|
||||
end
|
||||
end
|
||||
|
||||
end
|
52
tests/opennebula/requests/compute/vm_allocate_tests.rb
Normal file
52
tests/opennebula/requests/compute/vm_allocate_tests.rb
Normal file
|
@ -0,0 +1,52 @@
|
|||
Shindo.tests("Fog::Compute[:opennebula] | vm_create and destroy request", 'opennebula') do
|
||||
|
||||
compute = Fog::Compute[:opennebula]
|
||||
name_base = Time.now.to_i
|
||||
f = compute.flavors.get 4
|
||||
response = {}
|
||||
|
||||
tests("Allocate VM") do
|
||||
response = compute.vm_allocate({:name => 'fog-'+name_base.to_s, :flavor => f})
|
||||
test("response should be a kind of Hash") { response.kind_of? Hash}
|
||||
test("id should be a one-id (interger)") { response['id'].is_a? Fixnum}
|
||||
end
|
||||
tests("Destroy VM") do
|
||||
compute.vm_destroy(response['id'])
|
||||
vms = compute.list_vms({:id => response['id']})
|
||||
test("get vm should be empty") { compute.list_vms({:id => response['id']}).empty?}
|
||||
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 - no flavor") do
|
||||
begin
|
||||
response = compute.vm_allocate({:name => 'fog-'+name_base.to_s, :flavor => nil})
|
||||
test("should be a kind of Hash") { response.kind_of? Hash} #mock never raise exceptions
|
||||
rescue => e
|
||||
#should raise vm name already exist exception.
|
||||
test("error should be a kind of ArgumentError") { e.kind_of? ArgumentError}
|
||||
end
|
||||
end
|
||||
tests("Fail Creating VM - nil name") do
|
||||
begin
|
||||
response = compute.vm_allocate({:name => nil, :flavor => f})
|
||||
test("should be a kind of Hash") { response.kind_of? Hash} #mock never raise exceptions
|
||||
rescue => e
|
||||
#should raise vm name already exist exception.
|
||||
test("error should be a kind of ArgumentError") { e.kind_of? ArgumentError}
|
||||
end
|
||||
end
|
||||
tests("Fail Creating VM - empty name") do
|
||||
begin
|
||||
response = compute.vm_allocate({:name => "", :flavor => f})
|
||||
test("should be a kind of Hash") { response.kind_of? Hash} #mock never raise exceptions
|
||||
rescue => e
|
||||
#should raise vm name already exist exception.
|
||||
test("error should be a kind of ArgumentError") { e.kind_of? ArgumentError}
|
||||
end
|
||||
end
|
||||
|
||||
end
|
Loading…
Add table
Reference in a new issue