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

Host targeted refresh deleting and re-creating storage, switch, and lan records #336

Merged
merged 8 commits into from
Feb 8, 2019
Merged
Original file line number Diff line number Diff line change
Expand Up @@ -213,16 +213,21 @@ def infer_related_host_ems_refs_db!
changed_hosts.each do |host|
add_simple_target!(:ems_clusters, uuid_from_target(host.ems_cluster))
host.storages.each do |storage|
add_simple_target!(:storagedomains, uuid_from_target(storage))
add_simple_target!(:storagedomains, storage.ems_ref)
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was comparing the wrong property:

references(:storagedomains)
["cd4cf9b7-e1d4-4ef6-a3ed-06adf72c8031"]
Storage.pluck(:ems_ref)
["/api/storagedomains/072fbaa1-08f3-4a40-9f34-a5ca22dd1d74", "/api/storagedomains/cd4cf9b7-e1d4-4ef6-a3ed-06adf72c8031"]

end
host.switches.each do |switch|
add_simple_target!(:switches, switch.uid_ems)
end
end
end

def infer_related_host_ems_refs_api!
hosts.each do |host|
add_simple_target!(:ems_clusters, host.cluster.id)
host.network_attachments.each do |attachement|
add_simple_target!(:networks, attachement.network.id)
manager.with_provider_connection(VERSION_HASH) do |connection|
connection.follow_link(host.network_attachments).each do |attachment|
add_simple_target!(:switches, attachment.network.id)
end
end
end
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ def add_switches
# TODO are switches shared across emses? Seems like we weren't filling ems_id
builder.add_targeted_arel(
lambda do |_inventory_collection|
::Switch.where(:uid_ems => references(:networks))
::Switch.where(:uid_ems => references(:switches))
end
)
end
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
module OvirtRefresherSpecCommon
extend ActiveSupport::Concern

def serialize_inventory(models = [])
skip_attributes = %w(updated_on last_refresh_date updated_at last_updated finish_time)
inventory = {}
models.each do |model|
inventory[model.name] = model.all.collect do |rec|
rec.attributes.except(*skip_attributes)
end.sort { |rec| rec["id"] }
end
inventory
end
end
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
require_relative 'ovirt_refresher_spec_common'

describe ManageIQ::Providers::Redhat::InfraManager::Refresh::Refresher do
include OvirtRefresherSpecCommon

describe ManageIQ::Providers::Redhat::InfraManager::Refresh::Refresher do
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@borod108 why are these describe blocks duplicated?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For no good reason I can think off.

before(:each) do
_guid, _server, zone = EvmSpecHelper.create_guid_miq_server_zone
Expand Down Expand Up @@ -26,8 +30,6 @@
stub_const("OvirtSDK4::Connection", Spec::Support::OvirtSDK::ConnectionVCR)
end

COUNTED_MODELS = [CustomAttribute, EmsFolder, EmsCluster, Datacenter].freeze

before(:each) do
@inventory_wrapper_class = ManageIQ::Providers::Redhat::InfraManager::Inventory::Strategies::V4

Expand All @@ -42,29 +44,29 @@ def load_response_mock_for(filename)
YAML.load_file(File.join('spec', 'models', prefix, 'response_yamls', filename + '.yml'))
end

let(:models_for_host_target) { [ExtManagementSystem, EmsFolder, EmsCluster, Storage, HostStorage, Switch, HostSwitch, Lan, CustomAttribute] }

it 'does not change the host when target refresh after full refresh' do
stub_settings_merge(:ems_refresh => { :rhevm => {:inventory_object_refresh => true }})

EmsRefresh.refresh(@ems)
@ems.reload

saved_inventory = serialize_inventory(models_for_host_target)

host = @ems.hosts.find_by(:ems_ref => "/api/hosts/f9dbfd16-3c79-4028-9304-9acf3b8857ba")
saved_host = host_to_comparable_hash(host)
saved_counted_models = COUNTED_MODELS.map { |m| [m.name, m.count] }
saved_switches = host.switches.map { |switch| [switch.uid_ems, switch.name] }
expect(host.networks.count).to eq(2)
EmsRefresh.refresh(host)
host.reload
expect(host.networks.count).to eq(2)
expect(saved_switches).to contain_exactly(*host.switches.map { |switch| a_collection_containing_exactly(switch.uid_ems, switch.name) })

expect(serialize_inventory(models_for_host_target)).to eq(saved_inventory)

EmsRefresh.refresh(host)
host.reload

expect(host.switches.map { |switch| [switch.uid_ems, switch.name] }).to contain_exactly(
a_collection_containing_exactly("00000000-0000-0000-0000-000000000009", "ovirtmgmt"),
a_collection_containing_exactly("5c42817f-03fb-460e-a3ab-a8770553aeee", "vlan123t")
)
expect(host.networks.count).to eq(2)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just wondering, if we removed this maybe we should also remove the second refresh - (line 63-64)

counted_models = COUNTED_MODELS.map { |m| [m.name, m.count] }
expect(saved_host).to eq(host_to_comparable_hash(host))
expect(saved_counted_models).to eq(counted_models)
end

def host_to_comparable_hash(host)
Expand Down
Loading