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:
parent
ad7b299d20
commit
3fe91ca26f
2 changed files with 28 additions and 32 deletions
|
@ -11,6 +11,18 @@ class Ninefold
|
||||||
ZONE_ID = 1
|
ZONE_ID = 1
|
||||||
# Max time to wait for job completion (2 mins)
|
# Max time to wait for job completion (2 mins)
|
||||||
MAXWAIT = 2 * 60
|
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
|
end
|
||||||
module Formats
|
module Formats
|
||||||
module Lists
|
module Lists
|
||||||
|
@ -156,8 +168,6 @@ class Ninefold
|
||||||
|
|
||||||
module_function :fill_virtual_machine_data
|
module_function :fill_virtual_machine_data
|
||||||
|
|
||||||
PENDING_VIRTUAL_MACHINE = {"id" => Integer, "jobid" => Integer}
|
|
||||||
ASYNC_VIRTUAL_MACHINE = {"jobid" => Integer}
|
|
||||||
VIRTUAL_MACHINE = {
|
VIRTUAL_MACHINE = {
|
||||||
"id"=>Integer,
|
"id"=>Integer,
|
||||||
"name"=>String,
|
"name"=>String,
|
||||||
|
|
|
@ -3,7 +3,7 @@ Shindo.tests('Ninefold::Compute | server requests', ['ninefold']) do
|
||||||
tests('success') 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?
|
pending if Fog.mocking?
|
||||||
networks = Ninefold[:compute].list_networks
|
networks = Ninefold[:compute].list_networks
|
||||||
|
|
||||||
|
@ -16,12 +16,9 @@ Shindo.tests('Ninefold::Compute | server requests', ['ninefold']) do
|
||||||
:zoneid => Ninefold::Compute::TestSupport::ZONE_ID,
|
:zoneid => Ninefold::Compute::TestSupport::ZONE_ID,
|
||||||
:networkids => networks[0]['id'])
|
:networkids => networks[0]['id'])
|
||||||
# wait for deployment, stash the job id.
|
# wait for deployment, stash the job id.
|
||||||
@jobid = newvm['jobid']
|
|
||||||
@newvmid = newvm['id']
|
@newvmid = newvm['id']
|
||||||
while Ninefold[:compute].query_async_job_result(:jobid => @jobid)['jobstatus'] == 0
|
result = Ninefold::Compute::TestSupport.wait_for_job(newvm['jobid'])['jobresult']['virtualmachine']
|
||||||
sleep 1
|
Ninefold::Compute::Formats::VirtualMachines::fill_virtual_machine_data(result)
|
||||||
end
|
|
||||||
newvm
|
|
||||||
end
|
end
|
||||||
|
|
||||||
tests("#list_virtual_machines()").formats(Ninefold::Compute::Formats::VirtualMachines::VIRTUAL_MACHINES) do
|
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)
|
Ninefold::Compute::Formats::VirtualMachines::fill_virtual_machine_data(vms)
|
||||||
end
|
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?
|
pending if Fog.mocking?
|
||||||
job = Ninefold[:compute].reboot_virtual_machine(:id => @newvmid)
|
job = Ninefold[:compute].reboot_virtual_machine(:id => @newvmid)
|
||||||
while Ninefold[:compute].query_async_job_result(:jobid => job['jobid'])['jobstatus'] == 0
|
result = Ninefold::Compute::TestSupport.wait_for_job(job)['jobresult']['virtualmachine']
|
||||||
sleep 1
|
Ninefold::Compute::Formats::VirtualMachines::fill_virtual_machine_data(result)
|
||||||
end
|
|
||||||
job
|
|
||||||
end
|
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?
|
pending if Fog.mocking?
|
||||||
job = Ninefold[:compute].stop_virtual_machine(:id => @newvmid)
|
job = Ninefold[:compute].stop_virtual_machine(:id => @newvmid)
|
||||||
while Ninefold[:compute].query_async_job_result(:jobid => job['jobid'])['jobstatus'] == 0
|
result = Ninefold::Compute::TestSupport.wait_for_job(job)['jobresult']['virtualmachine']
|
||||||
sleep 1
|
Ninefold::Compute::Formats::VirtualMachines::fill_virtual_machine_data(result)
|
||||||
end
|
|
||||||
job
|
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
|
@ -57,25 +50,18 @@ Shindo.tests('Ninefold::Compute | server requests', ['ninefold']) do
|
||||||
Ninefold::Compute::Formats::VirtualMachines::fill_virtual_machine_data(vms)
|
Ninefold::Compute::Formats::VirtualMachines::fill_virtual_machine_data(vms)
|
||||||
end
|
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?
|
pending if Fog.mocking?
|
||||||
job = Ninefold[:compute].start_virtual_machine(:id => @newvmid)
|
job = Ninefold[:compute].start_virtual_machine(:id => @newvmid)
|
||||||
while Ninefold[:compute].query_async_job_result(:jobid => job['jobid'])['jobstatus'] == 0
|
result = Ninefold::Compute::TestSupport.wait_for_job(job)['jobresult']['virtualmachine']
|
||||||
sleep 1
|
Ninefold::Compute::Formats::VirtualMachines::fill_virtual_machine_data(result)
|
||||||
end
|
|
||||||
job
|
|
||||||
end
|
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?
|
pending if Fog.mocking?
|
||||||
destvm = Ninefold[:compute].destroy_virtual_machine(:id => @newvmid)
|
job = Ninefold[:compute].destroy_virtual_machine(:id => @newvmid)
|
||||||
|
result = Ninefold::Compute::TestSupport.wait_for_job(job)['jobresult']['virtualmachine']
|
||||||
# wait for destroy, stash the job id.
|
Ninefold::Compute::Formats::VirtualMachines::fill_virtual_machine_data(result)
|
||||||
@jobid = destvm['jobid']
|
|
||||||
while Ninefold[:compute].query_async_job_result(:jobid => @jobid)['jobstatus'] == 0
|
|
||||||
sleep 1
|
|
||||||
end
|
|
||||||
destvm
|
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
Loading…
Add table
Reference in a new issue