-
Notifications
You must be signed in to change notification settings - Fork 62
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
139 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
52 changes: 52 additions & 0 deletions
52
app/models/manageiq/providers/ovirt/infra_manager/iso_datastore.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
class ManageIQ::Providers::Ovirt::InfraManager::IsoDatastore < ManageIQ::Providers::Ovirt::InfraManager::Storage | ||
belongs_to :ext_management_system, :foreign_key => :ems_id | ||
|
||
virtual_delegate :name, :to => :ext_management_system, :allow_nil => true, :type => :string | ||
|
||
# Synchronize advertised images as a queued task. The | ||
# queue name and the queue zone are derived from the EMS. | ||
# | ||
def synchronize_advertised_images_queue | ||
MiqQueue.put_unless_exists( | ||
:class_name => self.class.name, | ||
:instance_id => id, | ||
:method_name => "synchronize_advertised_images", | ||
:queue_name => ext_management_system.queue_name_for_ems_operations, | ||
:zone => ext_management_system.try(:my_zone), | ||
:role => "ems_operations" | ||
) | ||
end | ||
|
||
def advertised_images | ||
return [] unless ext_management_system.kind_of?(ManageIQ::Providers::Ovirt::InfraManager) | ||
|
||
ext_management_system.ovirt_services.advertised_images | ||
end | ||
|
||
def synchronize_advertised_images | ||
log_for = "ISO Datastore on Management System <#{name}>" | ||
|
||
_log.info("Synchronizing images on #{log_for}...") | ||
db_image_hash = iso_images.index_by(&:name) | ||
|
||
advertised_images.each do |image_name| | ||
if db_image_hash.include?(image_name) | ||
db_image_hash.delete(image_name) | ||
else | ||
iso_images.create(:name => image_name) | ||
end | ||
end | ||
|
||
db_image_hash.each_value(&:destroy) | ||
|
||
clear_association_cache | ||
update_attribute(:last_refresh_on, Time.now.utc) | ||
|
||
_log.info("Synchronizing images on #{log_for}...Complete") | ||
rescue ManageIQ::Providers::Ovirt::InfraManager::OvirtServices::Error | ||
end | ||
|
||
def self.display_name(number = 1) | ||
n_('ISO Datastore', 'ISO Datastores', number) | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
FactoryBot.define do | ||
factory :iso_datastore, :class => 'ManageIQ::Providers::Ovirt::InfraManager::IsoDatastore' | ||
end |
53 changes: 53 additions & 0 deletions
53
spec/models/manageiq/providers/ovirt/infra_manager/iso_datastore_spec.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
RSpec.describe ManageIQ::Providers::Ovirt::InfraManager::IsoDatastore do | ||
include Spec::Support::ArelHelper | ||
|
||
let(:ems) { FactoryBot.create(:ems_redhat) } | ||
let(:iso_datastore) { FactoryBot.create(:iso_datastore, :ext_management_system => ems, :name => ems.name) } | ||
|
||
context "queued methods" do | ||
it 'queues a sync task with synchronize_advertised_images_queue' do | ||
queue = iso_datastore.synchronize_advertised_images_queue | ||
|
||
expect(queue).to have_attributes( | ||
:class_name => described_class.name, | ||
:method_name => 'synchronize_advertised_images', | ||
:role => 'ems_operations', | ||
:queue_name => 'generic', | ||
:zone => ems.my_zone, | ||
:args => [] | ||
) | ||
end | ||
end | ||
|
||
describe "#advertised_images" do | ||
subject(:advertised_images) { iso_datastore.advertised_images } | ||
|
||
context "ems is not rhv" do | ||
let(:ems) { FactoryBot.create(:ems_vmware) } | ||
it "returns empty array" do | ||
expect(advertised_images).to eq([]) | ||
end | ||
end | ||
|
||
context "ems is rhv" do | ||
context "supports api4" do | ||
it "send the method to ovirt services v4" do | ||
expect_any_instance_of(ManageIQ::Providers::Redhat::InfraManager::OvirtServices::V4) | ||
.to receive(:advertised_images) | ||
advertised_images | ||
end | ||
end | ||
end | ||
|
||
describe "#name" do | ||
it "has a name" do | ||
expect(iso_datastore.name).to eq(ems.name) | ||
end | ||
|
||
it "fetches name via sql" do | ||
iso_datastore | ||
expect(virtual_column_sql_value(Storage, "name")).to eq(ems.name) | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters