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

Add target to event existence check #15719

Merged
merged 1 commit into from
Sep 29, 2017
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
10 changes: 6 additions & 4 deletions app/models/ems_event.rb
Original file line number Diff line number Diff line change
Expand Up @@ -234,10 +234,12 @@ def self.create_event(event)
event.delete_if { |k,| k.to_s.ends_with?("_ems_ref") }

new_event = EmsEvent.create(event) unless EmsEvent.exists?(
:event_type => event[:event_type],
:timestamp => event[:timestamp],
:chain_id => event[:chain_id],
:ems_id => event[:ems_id]
:event_type => event[:event_type],
:timestamp => event[:timestamp],
:chain_id => event[:chain_id],
:ems_id => event[:ems_id],
:target_id => event[:target_id],
:target_type => event[:target_type],
)
new_event.handle_event if new_event
new_event
Expand Down
35 changes: 31 additions & 4 deletions spec/models/ems_event_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -169,10 +169,12 @@
context ".add" do
before :each do
@event_hash = {
:event_type => "event_with_availability_zone",
:vm_ems_ref => @vm.ems_ref,
:timestamp => Time.now,
:ems_id => @ems.id
:event_type => "event_with_availability_zone",
:target_type => @vm.class.name,
:target_id => @vm.id,
:vm_ems_ref => @vm.ems_ref,
:timestamp => Time.now,
:ems_id => @ems.id
}
end

Expand All @@ -196,6 +198,31 @@
expect(new_event.availability_zone_id).to eq @availability_zone.id
end
end

Copy link
Author

Choose a reason for hiding this comment

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

".add" context is nested under "with availability zones"
Not sure if it's less confusing to add the new context here or create another top level ".add" context

context "when an event was previously added" do
before do
EmsEvent.add(@ems.id, @event_hash)
end

it "should reject duplicates" do
ems_event = EmsEvent.add(@ems.id, @event_hash)
expect(
EmsEvent.where(@event_hash.except(:target_id)).count
).to eq(1)
expect(ems_event).to be_nil
end

it "should add an identical event if it is for a different target" do
ems_event = EmsEvent.add(
@ems.id,
@event_hash.merge(:target_id => FactoryGirl.build(:vm_openstack).id)
)
expect(
EmsEvent.where(@event_hash.except(:target_id)).count
).to eq(2)
expect(ems_event).to_not be_nil
end
end
end
end

Expand Down