Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Supports feature attributes #23028

Merged
merged 2 commits into from
May 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
module ExtManagementSystem::SupportsAttribute
module SupportsAttribute
extend ActiveSupport::Concern

class_methods do
Expand Down
6 changes: 6 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,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) }
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