Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Automate - Infrastructure - Added tests for microsoft retirement meth…
  • Loading branch information
billfitzgerald0120 committed Feb 2, 2016
1 parent 90f36a6 commit 49aa23e
Show file tree
Hide file tree
Showing 2 changed files with 64 additions and 0 deletions.
@@ -0,0 +1,34 @@
describe "check_pre_retirement Method Validation" do
before(:each) { @vm = FactoryGirl.create(:vm_microsoft) }
after(:each) { @vm.destroy }

let(:user) do
FactoryGirl.create(:user_with_group)
end

let(:ws) do
MiqAeEngine.instantiate("/Infrastructure/VM/Retirement/StateMachines/Methods/CheckPreRetirement?" \
"Vm::vm=#{@vm.id}#microsoft", user)
end

it "returns 'ok' for a vm in powered_off state" do
@vm.update_attribute(:power_state, "off")

expect(ws.root['vm'].power_state).to eq("off")
expect(ws.root['ae_result']).to eq("ok")
end

it "errors for a template" do
@vm.update_attribute(:template, true)
expect(@vm.state).to eq("never")

expect { ws }.to raise_error(MiqAeException::ServiceNotFound)
end

it "retries for a vm in powered_on state" do
@vm.update_attribute(:power_state, "on")

expect(ws.root['ae_result']).to eq("retry")
expect(ws.root['vm'].power_state).to eq("on")
end
end
30 changes: 30 additions & 0 deletions spec/automation/unit/method_validation/pre_retirement_spec.rb
@@ -0,0 +1,30 @@
require File.expand_path(File.join(File.dirname(__FILE__), '..', '..',
'..', 'spec_helper'))
def run_automate_method
MiqAeEngine.instantiate("/Infrastructure/VM/Retirement/StateMachines/Methods/PreRetirement?" \
"Vm::vm=#{@vm.id}#microsoft", @user)
end

describe "pre_retirement Method Validation" do
before(:each) do
@zone = FactoryGirl.create(:zone)
@user = FactoryGirl.create(:user_with_group)
@ems = FactoryGirl.create(:ems_microsoft, :zone => @zone)
@host = FactoryGirl.create(:host)
@vm = FactoryGirl.create(:vm_microsoft, :host => @host,
:ems_id => @ems.id, :name => "testVM2", :raw_power_state => "poweredOn")
end

it "powers off a vm in a 'powered on' state" do
run_automate_method

expect(MiqQueue.exists?(:method_name => 'stop', :instance_id => @vm.id, :role => 'ems_operations')).to be_truthy
end

it "does not queue any operation for a vm in 'powered_off' state" do
@vm.update_attribute(:power_state, "off")
run_automate_method

expect(MiqQueue.exists?(:method_name => 'stop', :instance_id => @vm.id, :role => 'ems_operations')).to be_falsey
end
end

0 comments on commit 49aa23e

Please sign in to comment.