From 12aaadd9ca38a75d4028b7a88a234051428c6c7d Mon Sep 17 00:00:00 2001 From: Adam Grare Date: Thu, 28 May 2020 16:17:13 -0400 Subject: [PATCH] Add supports terminate feature --- .../openstack/cloud_manager/vm/operations.rb | 6 ++++++ .../openstack/cloud_manager/vm_spec.rb | 17 +++++++++++++++++ 2 files changed, 23 insertions(+) diff --git a/app/models/manageiq/providers/openstack/cloud_manager/vm/operations.rb b/app/models/manageiq/providers/openstack/cloud_manager/vm/operations.rb index 2a8d8c756..c8ab18d22 100644 --- a/app/models/manageiq/providers/openstack/cloud_manager/vm/operations.rb +++ b/app/models/manageiq/providers/openstack/cloud_manager/vm/operations.rb @@ -7,6 +7,12 @@ module ManageIQ::Providers::Openstack::CloudManager::Vm::Operations include_concern 'Relocation' include_concern 'Snapshot' + included do + supports :terminate do + unsupported_reason_add(:terminate, unsupported_reason(:control)) unless supports_control? + end + end + def raw_destroy raise "VM has no #{ui_lookup(:table => "ext_management_systems")}, unable to destroy VM" unless ext_management_system with_notification(:vm_destroy, diff --git a/spec/models/manageiq/providers/openstack/cloud_manager/vm_spec.rb b/spec/models/manageiq/providers/openstack/cloud_manager/vm_spec.rb index 9202216c7..75bf743f5 100644 --- a/spec/models/manageiq/providers/openstack/cloud_manager/vm_spec.rb +++ b/spec/models/manageiq/providers/openstack/cloud_manager/vm_spec.rb @@ -276,4 +276,21 @@ expect(vm.raw_power_state).to eq("ACTIVE") end end + + describe "#supports_terminate?" do + context "when connected to a provider" do + it "returns true" do + expect(vm.supports_terminate?).to be_truthy + end + end + + context "when not connected to a provider" do + let(:archived_vm) { FactoryBot.create(:vm_openstack) } + + it "returns false" do + expect(archived_vm.supports_terminate?).to be_falsey + expect(archived_vm.unsupported_reason(:terminate)).to eq("The VM is not connected to an active Provider") + end + end + end end