Skip to content

Commit

Permalink
Fix supports_shutdown_guest bug and added specs
Browse files Browse the repository at this point in the history
  • Loading branch information
jameswnl committed Dec 15, 2016
1 parent fb15bf9 commit 05b905b
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 17 deletions.
Expand Up @@ -9,10 +9,12 @@ module ManageIQ::Providers::Vmware::InfraManager::Vm::Operations::Guest

supports :shutdown_guest do
unsupported_reason_add(:shutdown_guest, unsupported_reason(:control)) unless supports_control?
unless tools_status && tools_status == 'toolsNotInstalled'
if current_state != "on"
unsupported_reason_add(:shutdown_guest, _("The VM is not powered on"))
if current_state == "on"
if tools_status == 'toolsNotInstalled'
unsupported_reason_add(:shutdown_guest, _("The VM tools is not installed"))
end
else
unsupported_reason_add(:shutdown_guest, _("The VM is not powered on"))
end
end

Expand Down
58 changes: 44 additions & 14 deletions spec/models/manageiq/providers/vmware/infra_manager/vm_spec.rb
@@ -1,11 +1,11 @@
describe ManageIQ::Providers::Vmware::InfraManager::Vm do
context "#is_available?" do
let(:ems) { FactoryGirl.create(:ems_vmware) }
let(:host) { FactoryGirl.create(:host_vmware_esx, :ext_management_system => ems) }
let(:vm) { FactoryGirl.create(:vm_vmware, :ext_management_system => ems, :host => host) }
let(:power_state_on) { "poweredOn" }
let(:power_state_suspended) { "poweredOff" }
let(:ems) { FactoryGirl.create(:ems_vmware) }
let(:host) { FactoryGirl.create(:host_vmware_esx, :ext_management_system => ems) }
let(:vm) { FactoryGirl.create(:vm_vmware, :ext_management_system => ems, :host => host) }
let(:power_state_on) { "poweredOn" }
let(:power_state_suspended) { "poweredOff" }

context "#is_available?" do
context("with :start") do
let(:state) { :start }
include_examples "Vm operation is available when not powered on"
Expand All @@ -21,11 +21,6 @@
include_examples "Vm operation is available when powered on"
end

context("with :shutdown_guest") do
let(:state) { :shutdown_guest }
include_examples "Vm operation is available when powered on"
end

context("with :standby_guest") do
let(:state) { :standby_guest }
include_examples "Vm operation is available when powered on"
Expand All @@ -43,14 +38,49 @@
end

context "supports_clone?" do
let(:ems) { FactoryGirl.create(:ems_vmware) }
let(:vm) { FactoryGirl.create(:vm_vmware, :ext_management_system => ems) }

it "returns true" do
expect(vm.supports?(:clone)).to eq(true)
end
end

context "supports_shutdown_guest?" do
let(:op) { 'shutdown_guest' }

context "when powered off" do
let(:vm_status) { {:raw_power_state => power_state_suspended} }

it 'is not available if tools is not installed' do
vm_status[:tools_status] = 'toolsNotInstalled'
vm.update_attributes(vm_status)
expect(vm.public_send("supports_#{op}?")).to be false
expect(vm.unsupported_reason(op)).to include("power")
end

it 'is not available even if tools is installed' do
vm_status[:tools_status] = nil
vm.update_attributes(vm_status)
expect(vm.public_send("supports_#{op}?")).to be false
expect(vm.unsupported_reason(op)).to include("power")
end
end

context "when powered on" do
let(:vm_status) { {:raw_power_state => power_state_on} }

it 'is not available if tools not installed' do
vm_status[:tools_status] = 'toolsNotInstalled'
vm.update_attributes(vm_status)
expect(vm.public_send("supports_#{op}?")).to be false
expect(vm.unsupported_reason(op)).to include("tools")
end

it 'is available if tools installed' do
vm_status[:tools_status] = nil
expect(vm.public_send("supports_#{op}?")).to be true
end
end
end

context "vim" do
let(:ems) { FactoryGirl.create(:ems_vmware) }
let(:provider_object) do
Expand Down

0 comments on commit 05b905b

Please sign in to comment.