Skip to content

Commit 28e7181

Browse files
authored
Merge pull request #124 from vfebvre/templates
Restrict supported functionalities for archived VMs & Templates
2 parents a490a07 + d8539c0 commit 28e7181

File tree

4 files changed

+28
-8
lines changed

4 files changed

+28
-8
lines changed

app/models/manageiq/providers/ibm_power_hmc/infra_manager/lpar.rb

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
class ManageIQ::Providers::IbmPowerHmc::InfraManager::Lpar < ManageIQ::Providers::IbmPowerHmc::InfraManager::Vm
2-
supports :publish
2+
supports :publish do
3+
unsupported_reason_add(:provisioning, _('Not connected to ems')) if ext_management_system.nil?
4+
end
35

46
def provider_object(connection = nil)
57
connection ||= ext_management_system.connect

app/models/manageiq/providers/ibm_power_hmc/infra_manager/template.rb

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,15 @@
11
class ManageIQ::Providers::IbmPowerHmc::InfraManager::Template < ManageIQ::Providers::InfraManager::Template
2-
supports :provisioning
3-
supports :clone
2+
supports :provisioning do
3+
if ext_management_system
4+
unsupported_reason_add(:provisioning, ext_management_system.unsupported_reason(:provisioning)) unless ext_management_system.supports?(:provisioning)
5+
else
6+
unsupported_reason_add(:provisioning, _('Not connected to ems'))
7+
end
8+
end
9+
10+
supports :clone do
11+
unsupported_reason_add(:clone, _('Not connected to ems')) if ext_management_system.nil?
12+
end
413

514
def do_request(request_type, options)
615
case request_type

spec/models/manageiq/providers/ibm_power_hmc/infra_manager/lpar_spec.rb

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,14 +20,17 @@
2020
end
2121

2222
context "lpar" do
23+
let(:archived_vm) { FactoryBot.create(:ibm_power_hmc_lpar, :ext_management_system => nil, :ems_ref => "3F3D399B-DFF3-4977-8881-C194AA47CD3A", :host => host) }
24+
2325
it "supports clone" do
24-
expect(described_class.supports?(:clone)).to be false
26+
expect(vm.supports?(:clone)).to be false
2527
end
2628
it "supports publish" do
27-
expect(described_class.supports?(:publish)).to (be true), "unsupported reason: #{described_class.unsupported_reason(:publish)}"
29+
expect(vm.supports?(:publish)).to (be true), "unsupported reason: #{described_class.unsupported_reason(:publish)}"
30+
expect(archived_vm.supports?(:publish)).to be false
2831
end
2932
it "supports migrate" do
30-
expect(described_class.supports?(:migrate)).to be false
33+
expect(vm.supports?(:migrate)).to be false
3134
end
3235
it "supports power operations" do
3336
host.advanced_settings.create!(:name => "hmc_managed", :value => "true")
Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,16 @@
11
describe ManageIQ::Providers::IbmPowerHmc::InfraManager::Template do
2+
let(:ems) { FactoryBot.create(:ems_ibm_power_hmc_infra_with_authentication) }
3+
let(:template) { FactoryBot.create(:ibm_power_hmc_template, :ext_management_system => ems, :ems_ref => "template1_uuid", :name => "template1") }
4+
let(:archived_template) { FactoryBot.create(:ibm_power_hmc_template, :ext_management_system => nil, :ems_ref => "template2_uuid", :name => "template2") }
5+
26
context "template" do
37
it "supports clone" do
4-
expect(described_class.supports?(:clone)).to be true
8+
expect(template.supports?(:clone)).to (be true), "unsupported reason: #{described_class.unsupported_reason(:clone)}"
9+
expect(archived_template.supports?(:clone)).to be false
510
end
611
it "supports provisioning" do
7-
expect(described_class.supports?(:provisioning)).to be true
12+
expect(template.supports?(:provisioning)).to (be true), "unsupported reason: #{described_class.unsupported_reason(:provisioning)}"
13+
expect(archived_template.supports?(:provisioning)).to be false
814
end
915
end
1016
end

0 commit comments

Comments
 (0)