From 25ad5d58f79eff510ed84dbc16ea148470433071 Mon Sep 17 00:00:00 2001 From: Glenn Sarti Date: Fri, 17 Feb 2017 12:57:08 -0800 Subject: [PATCH] (POOLER-73) Add spec tests for _check_snapshot_queue Add spec tests for _check_snapshot_queue --- spec/unit/pool_manager_spec.rb | 75 ++++++++++++++++++++++++++++++++++ 1 file changed, 75 insertions(+) diff --git a/spec/unit/pool_manager_spec.rb b/spec/unit/pool_manager_spec.rb index 5d1e257..dcbfac2 100644 --- a/spec/unit/pool_manager_spec.rb +++ b/spec/unit/pool_manager_spec.rb @@ -1087,6 +1087,81 @@ EOT end end + describe '#_check_snapshot_queue' do + let(:vsphere) { double('vsphere') } + + before do + expect(subject).not_to be_nil + end + + context 'vmpooler__tasks__snapshot queue' do + context 'when no VMs in the queue' do + it 'should not call create_vm_snapshot' do + expect(subject).to receive(:create_vm_snapshot).exactly(0).times + subject._check_snapshot_queue(vsphere) + end + end + + context 'when multiple VMs in the queue' do + before(:each) do + snapshot_vm('vm1','snapshot1') + snapshot_vm('vm2','snapshot2') + snapshot_vm('vm3','snapshot3') + end + + it 'should call create_vm_snapshot once' do + expect(subject).to receive(:create_vm_snapshot).exactly(1).times + subject._check_snapshot_queue(vsphere) + end + + it 'should snapshot the first VM in the queue' do + expect(subject).to receive(:create_vm_snapshot).with('vm1','snapshot1',vsphere) + subject._check_snapshot_queue(vsphere) + end + + it 'should log an error if one occurs' do + expect(subject).to receive(:create_vm_snapshot).and_raise(RuntimeError,'MockError') + expect(logger).to receive(:log).with('s', "[!] [snapshot_manager] snapshot appears to have failed") + subject._check_snapshot_queue(vsphere) + end + end + end + + context 'revert_vm_snapshot queue' do + context 'when no VMs in the queue' do + it 'should not call revert_vm_snapshot' do + expect(subject).to receive(:revert_vm_snapshot).exactly(0).times + subject._check_snapshot_queue(vsphere) + end + end + + context 'when multiple VMs in the queue' do + before(:each) do + snapshot_revert_vm('vm1','snapshot1') + snapshot_revert_vm('vm2','snapshot2') + snapshot_revert_vm('vm3','snapshot3') + end + + it 'should call revert_vm_snapshot once' do + expect(subject).to receive(:revert_vm_snapshot).exactly(1).times + subject._check_snapshot_queue(vsphere) + end + + it 'should revert snapshot the first VM in the queue' do + expect(subject).to receive(:revert_vm_snapshot).with('vm1','snapshot1',vsphere) + subject._check_snapshot_queue(vsphere) + end + + it 'should log an error if one occurs' do + expect(subject).to receive(:revert_vm_snapshot).and_raise(RuntimeError,'MockError') + expect(logger).to receive(:log).with('s', "[!] [snapshot_manager] snapshot revert appears to have failed") + subject._check_snapshot_queue(vsphere) + end + end + end + end + + describe '#migration_limit' do # This is a little confusing. Is this supposed to return a boolean # or integer type?