1
0
Fork 0
mirror of https://github.com/fog/fog.git synced 2022-11-09 13:51:43 -05:00
fog--fog/tests/vcloud/models/compute/server_tests.rb
Peter Meier 750fb59f25 [vcloud|compute] improve models add tests
Improve the models to work with the current api version. add tests
that use fake-data, that was captured from a real vCloud.

Also removed a couple of dead code. Tests have been added for
everything that changed or have been added. All the existing but
untouched parts have not been tested.
2011-11-29 11:37:18 +01:00

131 lines
4.3 KiB
Ruby

require "#{File.dirname(__FILE__)}/conn_helper.rb"
require 'fog/vcloud/models/compute/servers'
Shindo.tests("Vcloud::Compute | server", ['vcloud']) do
instance = Fog::Vcloud::Compute::Servers.new(
:connection => Fog::Vcloud::Compute.new(:vcloud_host => 'vcloud.example.com', :vcloud_username => 'username', :vcloud_password => 'password'),
:href => "https://vcloud.example.com/api/v1.0/vApp/vapp-1"
).first
instance.reload
tests("#href").returns("https://vcloud.example.com/api/v1.0/vApp/vm-2") { instance.href }
tests("#name").returns("vm2") { instance.name }
tests("#description").returns("Some VM Description") { instance.description }
tests("#status").returns('8') { instance.status }
tests("#deployed").returns(true) { instance.deployed }
tests("#os_desc").returns("Red Hat Enterprise Linux 5 (64-bit)") { instance.os_desc }
tests("#os_type").returns("rhel5_64Guest") { instance.os_type }
tests("#computer_name").returns("vm2") { instance.computer_name }
tests("cpu count").returns(1) { instance.cpus[:count] }
tests("amount of memory").returns(512){ instance.memory[:amount] }
tests("#disks") do
tests("#size").returns(2){ instance.disks.size }
tests("#size").returns(0){ instance.disks.first[:number] }
tests("#size").returns(1600){ instance.disks.first[:size] }
end
tests("#vapp_scoped_local_id").returns("vmware_RHEL5-U5-64-small_v02") { instance.vapp_scoped_local_id }
tests("#friendly_status").returns('off') { instance.friendly_status }
tests("#on?").returns(false) { instance.on? }
tests("#off?").returns(true) { instance.off? }
#old tests
tests("#server.new('#{Vcloud::Compute::TestSupport::template}')").returns(true) do
pending if Fog.mocking?
@svr = Vcloud.servers.create :catalog_item_uri => Vcloud::Compute::TestSupport::template, :name => 'fog_test_run', :password => 'password'
print "Waiting for server to be ready"
@svr.wait_for(1200) { print '.' ; ready? }
puts ""
@svr.ready?
end
tests("#svr.power_on()").returns(true) do
pending if Fog.mocking?
@svr.power_on
@svr.wait_for { on? }
@svr.wait_for { ready? }
@svr.on?
end
tests("#svr.description(\"testing\")").returns("testing") do
pending if Fog.mocking?
@svr.wait_for { ready? }
@svr.description = "testing"
@svr.save
@svr.wait_for { ready? }
@svr.description
end
# Power off only stops the OS, doesn't free up resources. #undeploy is for this.
tests("#svr.undeploy()").returns(true) do
pending if Fog.mocking?
@svr.undeploy
@svr.wait_for { off? }
@svr.wait_for { ready? }
@svr.off?
end
tests("#svr.memory(384)").returns(384) do
pending if Fog.mocking?
raise 'Server template memory already 384m - change to something different' if @svr.memory[:amount] == 384
@svr.wait_for { ready? }
@svr.memory = 384
@svr.save
@svr.wait_for { ready? }
# Can take a little while for the VM to know it has different ram, and not tied to a task..
(1..20).each do |i|
break if @svr.reload.memory[:amount] == '384'
sleep 1
end
@svr.reload.memory[:amount]
end
tests("#svr.add_disk(4096)").returns([2, "4096"]) do
pending if Fog.mocking?
raise 'Server template already has two disks' if @svr.disks.size == 2
@svr.wait_for { ready? }
@svr.add_disk(4096)
@svr.save
@svr.wait_for { ready? }
# Can take a little while for the VM to know it has different ram, and not tied to a task..
(1..20).each do |i|
break if @svr.reload.disks.size == 2
sleep 1
end
[
@svr.disks.size,
@svr.disks[1][:resource][:vcloud_capacity]
]
end
tests("#svr.delete_disk(1)").returns(1) do
pending if Fog.mocking?
raise "Server doesn't have two disks - did previous step fail? " if @svr.disks.size != 2
@svr.wait_for { ready? }
sleep 5 # otherwise complains about being busy
@svr.delete_disk 1
@svr.save
@svr.wait_for { ready? }
# Can take a little while for the VM to know it has different ram, and not tied to a task..
(1..20).each do |i|
break if @svr.reload.disks.size == 1
sleep 1
end
@svr.disks.size
end
tests("#svr.destroy").raises(Excon::Errors::Forbidden) do
pending if Fog.mocking?
@svr.destroy
sleep 5 # allow cleanup..
Vcloud.servers.get(@svr.href) == nil
end
end