Skip to content

Commit

Permalink
add supports attributes
Browse files Browse the repository at this point in the history
- add 2 supports attributes for vm infra reconfigure field form
- convert a manually defined attribute to using the plugin
  • Loading branch information
kbrock committed May 8, 2024
1 parent 2d226fb commit 2efb732
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 5 deletions.
7 changes: 2 additions & 5 deletions app/models/cloud_volume.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ class CloudVolume < ApplicationRecord
include CustomActionsMixin
include EmsRefreshMixin
include Operations
include SupportsAttribute

belongs_to :ext_management_system, :foreign_key => :ems_id, :class_name => "ExtManagementSystem"
belongs_to :availability_zone
Expand All @@ -24,11 +25,7 @@ class CloudVolume < ApplicationRecord
has_many :host_initiators, :through => :volume_mappings

delegate :queue_name_for_ems_operations, :to => :ext_management_system, :allow_nil => true
virtual_column :supports_safe_delete, :type => :boolean

def supports_safe_delete
supports?(:safe_delete)
end
supports_attribute :feature => :safe_delete

acts_as_miq_taggable

Expand Down
4 changes: 4 additions & 0 deletions app/models/vm_or_template.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ class VmOrTemplate < ApplicationRecord
include RetirementMixin
include ScanningMixin
include SupportsFeatureMixin
include SupportsAttribute
include EmsRefreshMixin

self.table_name = 'vms'
Expand Down Expand Up @@ -200,6 +201,9 @@ class VmOrTemplate < ApplicationRecord
delegate :connect_lans, :disconnect_lans, :to => :hardware, :allow_nil => true
delegate :queue_name_for_ems_operations, :to => :ext_management_system, :allow_nil => true

supports_attribute :feature => :reconfigure_network_adapters
supports_attribute :feature => :reconfigure_cdroms

after_save :save_genealogy_information

scope :active, -> { where.not(:ems_id => nil) }
Expand Down
30 changes: 30 additions & 0 deletions spec/models/vm_or_template_spec.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
RSpec.describe VmOrTemplate do
include Spec::Support::SupportsHelper

subject { vm }

include_examples "MiqPolicyMixin"
Expand Down Expand Up @@ -723,6 +725,34 @@
end
end

context "virtual column :supports_reconfigure_network_adapters" do
it "returns false if reconfigure_network_adapters is not supported" do
ems = FactoryBot.create(:vm_infra)
stub_supports_not(ems.class, :reconfigure_network_adapters)
expect(ems.supports_reconfigure_network_adapters).to eq(false)
end

it "returns true if reconfigure_network_adapters is supported" do
ems = FactoryBot.create(:vm_infra)
stub_supports(ems.class, :reconfigure_network_adapters)
expect(ems.supports_reconfigure_network_adapters).to eq(true)
end
end

context "virtual column :supports_reconfigure_cdroms" do
it "returns false if reconfigure_cdroms is not supported" do
ems = FactoryBot.create(:vm_infra)
stub_supports_not(ems.class, :reconfigure_cdroms)
expect(ems.supports_reconfigure_cdroms).to eq(false)
end

it "returns true if reconfigure_cdroms is supported" do
ems = FactoryBot.create(:vm_infra)
stub_supports(ems.class, :reconfigure_cdroms)
expect(ems.supports_reconfigure_cdroms).to eq(true)
end
end

context ".set_tenant_from_group" do
before { Tenant.seed }
let(:tenant1) { FactoryBot.create(:tenant) }
Expand Down

0 comments on commit 2efb732

Please sign in to comment.