Skip to content

Commit

Permalink
Fix the issue that user can't add alerts.
Browse files Browse the repository at this point in the history
When seeded from the fixture file, default events in miq_event_definitions table always belong to certain event set.
However there are some appliances from 5.6 fresh installation that have some deleted old events showed up in the DB and not belong to any event set.
UI for Add a New Alert would not open due to these ghost and orphaned events.

So far we can't find out why these deleted events still showed up in a fresh appliance. It is strange.
This commit would skip these orphaned events so users can access the Add a New Alert page.

https://bugzilla.redhat.com/show_bug.cgi?id=1379854
  • Loading branch information
lfu committed Oct 13, 2016
1 parent bdf3c9b commit 2e19531
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 5 deletions.
3 changes: 1 addition & 2 deletions app/controllers/miq_policy_controller/alerts.rb
Expand Up @@ -274,8 +274,7 @@ def alert_build_edit_screen

# Build hash of arrays of all events by event type
@edit[:events] = {}
MiqEventDefinition.all_events.each do |e|
next if e.name.ends_with?("compliance_check")
MiqEventDefinition.all_control_events.each do |e|
@edit[:events][e.id] = (e.etype.description + ": " + e.description)
end

Expand Down
8 changes: 5 additions & 3 deletions app/models/miq_event_definition.rb
Expand Up @@ -21,6 +21,10 @@ def self.all_events
where(:event_type => "Default")
end

def self.all_control_events
all_events.where.not("name like ?", "%compliance_check").select { |e| e.etype }
end

def miq_policies
p_ids = MiqPolicyContent.where(:miq_event_definition_id => id).uniq.pluck(:miq_policy_id)
MiqPolicy.where(:id => p_ids).to_a
Expand Down Expand Up @@ -63,9 +67,7 @@ def self.import_from_hash(event, options = {})
end

def etype
set = memberof.first
raise "unexpected error, no type found for event #{name}" if set.nil?
set
memberof.first.tap { |set| _log.error("No type found for event #{name}") if set.nil? }
end

def self.etypes
Expand Down
44 changes: 44 additions & 0 deletions spec/models/miq_event_definition_spec.rb
Expand Up @@ -55,4 +55,48 @@ def create_set!(name)
end
end
end

describe '#etype' do
it "returns event set type" do
set_type = 'set_testing'
set = MiqEventDefinitionSet.create(:name => set_type, :description => "Set testing")
event = FactoryGirl.create(:miq_event_definition, :name => "vm_start")
set.add_member(event)

expect(event.etype.name).to eq(set_type)
end

it "returns nil when not belong to any event set" do
event = FactoryGirl.create(:miq_event_definition, :name => "test_event")
expect(event.etype).to be_nil
end
end

describe '.all_control_events' do
subject { MiqEventDefinition.all_control_events }

before do
com_set = MiqEventDefinitionSet.create(:name => "compliance", :description => "Compliance Events")
FactoryGirl.create(:miq_event_definition,
:name => "host_compliance_check",
:event_type => "Default").tap { |e| com_set.add_member(e) }
end

it 'has all default control policy events with set type' do
event = FactoryGirl.create(:miq_event_definition, :name => "some_event", :event_type => "Default")
set = MiqEventDefinitionSet.create(:name => "evm_operations", :description => "EVM Events")
set.add_member(event)

expect(subject.include?(event)).to be true
end

it 'has not the events for compliance policy' do
expect(subject.any? { |e| e.name.ends_with?("compliance_check") }).to be false
end

it 'has not the events without a set type' do
event = FactoryGirl.create(:miq_event_definition, :name => "test_event", :event_type => "Default")
expect(subject.include?(event)).to be false
end
end
end

0 comments on commit 2e19531

Please sign in to comment.