Host snapshot rspec tests

This commit is contained in:
Scott Schneider 2015-07-14 11:04:58 -07:00
parent 1c3045fd65
commit 93acc8327b
2 changed files with 95 additions and 0 deletions

View file

@ -432,6 +432,33 @@ describe Vmpooler::API::V1 do
end
end
end
describe 'POST /vm/:hostname/snapshot' do
it 'creates a snapshot' do
expect(redis).to receive(:sadd)
post "#{prefix}/vm/testhost/snapshot"
expect(last_response.header['Content-Type']).to eq('application/json')
expect(JSON.parse(last_response.body)['ok']).to eq(true)
expect(JSON.parse(last_response.body)['testhost']['snapshot'].length).to be(32)
expect(last_response.status).to eq(202)
end
end
describe 'POST /vm/:hostname/snapshot/:snapshot' do
it 'reverts to a snapshot' do
expect(redis).to receive(:exists).with('vmpooler__vm__testhost').and_return(1)
expect(redis).to receive(:hget).with('vmpooler__vm__testhost', 'snapshot:testsnapshot').and_return(1)
expect(redis).to receive(:sadd)
post "#{prefix}/vm/testhost/snapshot/testsnapshot"
expect(last_response.header['Content-Type']).to eq('application/json')
expect(last_response.body).to include('"ok": true')
expect(last_response.status).to eq(202)
end
end
end
end

View file

@ -211,4 +211,72 @@ describe 'Pool Manager' do
end
end
describe '#_create_vm_snapshot' do
let(:snapshot_manager) { 'snapshot_manager' }
let(:pool_helper) { double('snapshot_manager') }
let(:vsphere) { {snapshot_manager => pool_helper} }
before do
expect(subject).not_to be_nil
$vsphere = vsphere
end
context '(valid host)' do
let(:vm_host) { double('vmhost') }
it 'creates a snapshot' do
expect(pool_helper).to receive(:find_vm).and_return vm_host
expect(logger).to receive(:log)
expect(vm_host).to receive_message_chain(:CreateSnapshot_Task, :wait_for_completion)
expect(redis).to receive(:hset).with('vmpooler__vm__testvm', 'snapshot:testsnapshot', Time.now.to_s)
expect(logger).to receive(:log)
subject._create_vm_snapshot('testvm', 'testsnapshot')
end
end
end
describe '#_revert_vm_snapshot' do
let(:snapshot_manager) { 'snapshot_manager' }
let(:pool_helper) { double('snapshot_manager') }
let(:vsphere) { {snapshot_manager => pool_helper} }
before do
expect(subject).not_to be_nil
$vsphere = vsphere
end
context '(valid host)' do
let(:vm_host) { double('vmhost') }
let(:vm_snapshot) { double('vmsnapshot') }
it 'reverts a snapshot' do
expect(pool_helper).to receive(:find_vm).and_return vm_host
expect(pool_helper).to receive(:find_snapshot).and_return vm_snapshot
expect(logger).to receive(:log)
expect(vm_snapshot).to receive_message_chain(:RevertToSnapshot_Task, :wait_for_completion)
expect(logger).to receive(:log)
subject._revert_vm_snapshot('testvm', 'testsnapshot')
end
end
end
describe '#_check_snapshot_queue' do
let(:pool_helper) { double('pool') }
let(:vsphere) { {pool => pool_helper} }
before do
expect(subject).not_to be_nil
$vsphere = vsphere
end
it 'checks appropriate redis queues' do
expect(redis).to receive(:spop).with('vmpooler__tasks__snapshot')
expect(redis).to receive(:spop).with('vmpooler__tasks__snapshot-revert')
subject._check_snapshot_queue
end
end
end