Skip to content

Commit

Permalink
Merge pull request #14177 from durandom/ems_event_allow_provider_sett…
Browse files Browse the repository at this point in the history
…ings_deeper_merge

Ems event groups - allow provider settings (deeper_merge edition)
  • Loading branch information
Fryguy authored Mar 6, 2017
2 parents 17cdff5 + afb3b91 commit acb8c76
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 1 deletion.
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,
: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

0 comments on commit acb8c76

Please sign in to comment.