1
0
Fork 0
mirror of https://github.com/fog/fog.git synced 2022-11-09 13:51:43 -05:00

[ninefold|compute] Refactor out job waiting functionality, test correct data.

This commit is contained in:
Lincoln Stoll 2011-05-11 15:06:08 -07:00
parent ad7b299d20
commit 3fe91ca26f
2 changed files with 28 additions and 32 deletions

View file

@ -11,6 +11,18 @@ class Ninefold
ZONE_ID = 1
# Max time to wait for job completion (2 mins)
MAXWAIT = 2 * 60
## Waits for a job, returning the completed jobs payload.
## Accepts an integer jobid, or a hash containing a jobid or id.
def wait_for_job(job)
job = job['jobid'] || job['id'] unless job.kind_of? Integer
while Ninefold[:compute].query_async_job_result(:jobid => job)['jobstatus'] == 0
sleep 1
end
Ninefold[:compute].query_async_job_result(:jobid => job)
end
module_function :wait_for_job
end
module Formats
module Lists
@ -156,8 +168,6 @@ class Ninefold
module_function :fill_virtual_machine_data
PENDING_VIRTUAL_MACHINE = {"id" => Integer, "jobid" => Integer}
ASYNC_VIRTUAL_MACHINE = {"jobid" => Integer}
VIRTUAL_MACHINE = {
"id"=>Integer,
"name"=>String,

View file

@ -3,7 +3,7 @@ Shindo.tests('Ninefold::Compute | server requests', ['ninefold']) do
tests('success') do
tests("#deploy_virtual_machine()").formats(Ninefold::Compute::Formats::VirtualMachines::PENDING_VIRTUAL_MACHINE) do
tests("#deploy_virtual_machine()").formats(Ninefold::Compute::Formats::VirtualMachines::VIRTUAL_MACHINE) do
pending if Fog.mocking?
networks = Ninefold[:compute].list_networks
@ -16,12 +16,9 @@ Shindo.tests('Ninefold::Compute | server requests', ['ninefold']) do
:zoneid => Ninefold::Compute::TestSupport::ZONE_ID,
:networkids => networks[0]['id'])
# wait for deployment, stash the job id.
@jobid = newvm['jobid']
@newvmid = newvm['id']
while Ninefold[:compute].query_async_job_result(:jobid => @jobid)['jobstatus'] == 0
sleep 1
end
newvm
result = Ninefold::Compute::TestSupport.wait_for_job(newvm['jobid'])['jobresult']['virtualmachine']
Ninefold::Compute::Formats::VirtualMachines::fill_virtual_machine_data(result)
end
tests("#list_virtual_machines()").formats(Ninefold::Compute::Formats::VirtualMachines::VIRTUAL_MACHINES) do
@ -31,22 +28,18 @@ Shindo.tests('Ninefold::Compute | server requests', ['ninefold']) do
Ninefold::Compute::Formats::VirtualMachines::fill_virtual_machine_data(vms)
end
tests("#reboot_virtual_machine()").formats(Ninefold::Compute::Formats::VirtualMachines::ASYNC_VIRTUAL_MACHINE) do
tests("#reboot_virtual_machine()").formats(Ninefold::Compute::Formats::VirtualMachines::VIRTUAL_MACHINE) do
pending if Fog.mocking?
job = Ninefold[:compute].reboot_virtual_machine(:id => @newvmid)
while Ninefold[:compute].query_async_job_result(:jobid => job['jobid'])['jobstatus'] == 0
sleep 1
end
job
result = Ninefold::Compute::TestSupport.wait_for_job(job)['jobresult']['virtualmachine']
Ninefold::Compute::Formats::VirtualMachines::fill_virtual_machine_data(result)
end
tests("#stop_virtual_machine()").formats(Ninefold::Compute::Formats::VirtualMachines::ASYNC_VIRTUAL_MACHINE) do
tests("#stop_virtual_machine()").formats(Ninefold::Compute::Formats::VirtualMachines::VIRTUAL_MACHINE) do
pending if Fog.mocking?
job = Ninefold[:compute].stop_virtual_machine(:id => @newvmid)
while Ninefold[:compute].query_async_job_result(:jobid => job['jobid'])['jobstatus'] == 0
sleep 1
end
job
result = Ninefold::Compute::TestSupport.wait_for_job(job)['jobresult']['virtualmachine']
Ninefold::Compute::Formats::VirtualMachines::fill_virtual_machine_data(result)
end
@ -57,25 +50,18 @@ Shindo.tests('Ninefold::Compute | server requests', ['ninefold']) do
Ninefold::Compute::Formats::VirtualMachines::fill_virtual_machine_data(vms)
end
tests("#start_virtual_machine()").formats(Ninefold::Compute::Formats::VirtualMachines::ASYNC_VIRTUAL_MACHINE) do
tests("#start_virtual_machine()").formats(Ninefold::Compute::Formats::VirtualMachines::VIRTUAL_MACHINE) do
pending if Fog.mocking?
job = Ninefold[:compute].start_virtual_machine(:id => @newvmid)
while Ninefold[:compute].query_async_job_result(:jobid => job['jobid'])['jobstatus'] == 0
sleep 1
end
job
result = Ninefold::Compute::TestSupport.wait_for_job(job)['jobresult']['virtualmachine']
Ninefold::Compute::Formats::VirtualMachines::fill_virtual_machine_data(result)
end
tests("#destroy_virtual_machine()").formats(Ninefold::Compute::Formats::VirtualMachines::ASYNC_VIRTUAL_MACHINE) do
tests("#destroy_virtual_machine()").formats(Ninefold::Compute::Formats::VirtualMachines::VIRTUAL_MACHINE) do
pending if Fog.mocking?
destvm = Ninefold[:compute].destroy_virtual_machine(:id => @newvmid)
# wait for destroy, stash the job id.
@jobid = destvm['jobid']
while Ninefold[:compute].query_async_job_result(:jobid => @jobid)['jobstatus'] == 0
sleep 1
end
destvm
job = Ninefold[:compute].destroy_virtual_machine(:id => @newvmid)
result = Ninefold::Compute::TestSupport.wait_for_job(job)['jobresult']['virtualmachine']
Ninefold::Compute::Formats::VirtualMachines::fill_virtual_machine_data(result)
end
end