diff --git a/app/models/cloud_volume.rb b/app/models/cloud_volume.rb index 795de34d31f..96db05ba9ba 100644 --- a/app/models/cloud_volume.rb +++ b/app/models/cloud_volume.rb @@ -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 @@ -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 diff --git a/app/models/ext_management_system/supports_attribute.rb b/app/models/mixins/supports_attribute.rb similarity index 96% rename from app/models/ext_management_system/supports_attribute.rb rename to app/models/mixins/supports_attribute.rb index a5927e18eab..2c37bfbca91 100644 --- a/app/models/ext_management_system/supports_attribute.rb +++ b/app/models/mixins/supports_attribute.rb @@ -1,4 +1,4 @@ -module ExtManagementSystem::SupportsAttribute +module SupportsAttribute extend ActiveSupport::Concern class_methods do diff --git a/app/models/vm_or_template.rb b/app/models/vm_or_template.rb index f160596d8d2..b5a2acd55c9 100644 --- a/app/models/vm_or_template.rb +++ b/app/models/vm_or_template.rb @@ -8,6 +8,7 @@ class VmOrTemplate < ApplicationRecord include RetirementMixin include ScanningMixin include SupportsFeatureMixin + include SupportsAttribute include EmsRefreshMixin self.table_name = 'vms' @@ -200,6 +201,11 @@ 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_disks + supports_attribute :feature => :reconfigure_disksize + supports_attribute :feature => :reconfigure_cdroms + supports_attribute :feature => :reconfigure_network_adapters + after_save :save_genealogy_information scope :active, -> { where.not(:ems_id => nil) } diff --git a/spec/models/vm_or_template_spec.rb b/spec/models/vm_or_template_spec.rb index cb3f8ca66ab..15c793778be 100644 --- a/spec/models/vm_or_template_spec.rb +++ b/spec/models/vm_or_template_spec.rb @@ -1,4 +1,6 @@ RSpec.describe VmOrTemplate do + include Spec::Support::SupportsHelper + subject { vm } include_examples "MiqPolicyMixin" @@ -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) }