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

Ems event groups - allow provider settings (deeper_merge edition) #14177

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
11 changes: 10 additions & 1 deletion app/models/ems_event.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,16 @@ def self.task_final_events
end

def self.event_groups
::Settings.event_handling.event_groups.to_hash
core_event_groups = ::Settings.event_handling.event_groups.to_hash
Settings.ems.each_with_object(core_event_groups) do |(_provider_type, provider_settings), event_groups|
provider_event_groups = provider_settings.fetch_path(:event_handling, :event_groups)
next unless provider_event_groups
DeepMerge.deep_merge!(
provider_event_groups.to_hash, event_groups,
Copy link
Member

Choose a reason for hiding this comment

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

Should this be core_event_groups?

Copy link
Member Author

Choose a reason for hiding this comment

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

nope, its each_with_object(core_event_groups) and event_groups is the memo object...

Copy link
Member

Choose a reason for hiding this comment

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

Ah ok, I missed that bit

:preserve_unmergeables => false,
:overwrite_arrays => false
)
end
end

def self.bottleneck_event_groups
Expand Down
35 changes: 35 additions & 0 deletions spec/models/ems_event_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -198,4 +198,39 @@
end
end
end

context '.event_groups' do
let(:provider_event) { 'SomeSpecialProviderEvent' }

it 'returns a list of groups' do
event_group_names = [
:addition, :application, :configuration, :console, :deletion, :general, :import_export, :migration, :network,
:power, :snapshot, :status, :storage
]
expect(described_class.event_groups.keys).to match_array(event_group_names)
expect(described_class.event_groups[:addition]).to include(:name => 'Creation/Addition')
expect(described_class.event_groups[:addition][:critical]).to include('CloneTaskEvent')
expect(described_class.event_groups[:addition][:critical]).not_to include(provider_event)
end

it 'returns the provider event if configured' do
stub_settings_merge(
:ems => {
:some_provider => {
:event_handling => {
:event_groups => {
:addition => {
:critical => [provider_event]
}
}
}
}
}
)
allow(Vmdb::Plugins.instance).to receive(:registered_provider_plugin_names).and_return([:some_provider])

expect(described_class.event_groups[:addition][:critical]).to include('CloneTaskEvent')
expect(described_class.event_groups[:addition][:critical]).to include(provider_event)
end
end
end
5 changes: 5 additions & 0 deletions spec/support/settings_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,11 @@ def stub_settings(hash)
allow(Vmdb::Settings).to receive(:for_resource) { settings }
end

def stub_settings_merge(hash)
hash = Settings.to_hash.deep_merge(hash)
stub_settings(hash)
end

def stub_template_settings(hash)
settings = Config::Options.new.merge!(hash)
allow(Vmdb::Settings).to receive(:template_settings) { settings }
Expand Down