From f9846b307b8aef2c1326f05598a008bad740ff36 Mon Sep 17 00:00:00 2001 From: Keenan Brock Date: Wed, 8 May 2024 09:17:28 -0400 Subject: [PATCH 1/2] Make SupportsAttribute mixin available to all models --- .../{ext_management_system => mixins}/supports_attribute.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) rename app/models/{ext_management_system => mixins}/supports_attribute.rb (96%) 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 From 82c37c43e598eee08cb81cecd35032f2cadccb71 Mon Sep 17 00:00:00 2001 From: Keenan Brock Date: Wed, 8 May 2024 09:26:34 -0400 Subject: [PATCH 2/2] add supports attributes - add 2 supports attributes for vm infra reconfigure field form - convert a manually defined attribute to using the plugin --- app/models/cloud_volume.rb | 7 ++----- app/models/vm_or_template.rb | 6 ++++++ spec/models/vm_or_template_spec.rb | 30 ++++++++++++++++++++++++++++++ 3 files changed, 38 insertions(+), 5 deletions(-) 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/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) }