Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
Automate - Infrastructure - Added tests for microsoft retirement meth…
- Loading branch information
1 parent
90f36a6
commit 49aa23e
Showing
2 changed files
with
64 additions
and
0 deletions.
There are no files selected for viewing
34 changes: 34 additions & 0 deletions
34
spec/automation/unit/method_validation/check_pre_retirement_spec.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -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
30
spec/automation/unit/method_validation/pre_retirement_spec.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -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 |