Skip to content

Commit

Permalink
Parse Cloud Volume refresh events
Browse files Browse the repository at this point in the history
  • Loading branch information
mansam committed Jan 16, 2018
1 parent 194af7d commit 39f2ec3
Show file tree
Hide file tree
Showing 2 changed files with 74 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,29 @@ def parse_ems_event_targets(ems_event)
# there's almost always a tenant id regardless of event type
collect_identity_tenant_references!(target_collection, ems_event)

# WIP
target_type = if ems_event.event_type.start_with?("volume.")
collect_volume_references!(target_collection, ems_event)
elsif ems_event.event_type.start_with?("snapshot.")
collect_snapshot_references!(target_collection, ems_event)
end

target_collection.targets
end

def collect_volume_references!(target_collection, ems_event)
resource_id = ems_event.full_data.fetch_path(:content, 'payload', 'volume_id') || ems_event.full_data.fetch_path(:content, 'payload', 'resource_id')
add_target(target_collection, :cloud_volumes, resource_id) if resource_id
end

def collect_snapshot_references!(target_collection, ems_event)
resource_id = ems_event.full_data.fetch_path(:content, 'payload', 'snapshot_id') || ems_event.full_data.fetch_path(:content, 'payload', 'resource_id')
add_target(target_collection, :cloud_volume_snapshots, resource_id) if resource_id
volume_id = ems_event.full_data.fetch_path(:content, 'payload', 'volume_id')
add_target(target_collection, :cloud_volumes, volume_id) if volume_id
end

def collect_identity_tenant_references!(target_collection, ems_event)
tenant_id = ems_event.full_data.fetch_path(:payload, 'tenant_id') || ems_event.full_data.fetch_path(:payload, 'project_id') || ems_event.full_data.fetch_path(:payload, 'initiator', 'project_id')
tenant_id = ems_event.full_data.fetch_path(:content, 'payload', 'tenant_id') || ems_event.full_data.fetch_path(:content, 'payload', 'project_id') || ems_event.full_data.fetch_path(:content, 'payload', 'initiator', 'project_id')
add_target(target_collection, :cloud_tenants, tenant_id) if tenant_id
end

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
describe ManageIQ::Providers::Openstack::StorageManager::CinderManager::EventTargetParser do
before :each do
_guid, _server, zone = EvmSpecHelper.create_guid_miq_server_zone
@ems = FactoryGirl.create(:ems_openstack, :zone => zone)

allow_any_instance_of(EmsEvent).to receive(:handle_event)
allow(EmsEvent).to receive(:create_completed_event)
end

context "Openstack Event Parsing" do
it "parses volume events" do
ems_event = create_ems_event("volume.create.end", "resource_id" => "volume_id_test",)
parsed_targets = described_class.new(ems_event).parse
expect(parsed_targets.size).to eq(1)
expect(target_references(parsed_targets)).to(
match_array(
[
[:cloud_volumes, {:ems_ref => "volume_id_test"}]
]
)
)
end

it "parses snapshot events" do
ems_event = create_ems_event("snapshot.create.end", "resource_id" => "snapshot_id_test",
"volume_id" => "volume_id_test")
parsed_targets = described_class.new(ems_event).parse
expect(parsed_targets.size).to eq(2)
expect(target_references(parsed_targets)).to(
match_array(
[
[:cloud_volume_snapshots, {:ems_ref => "snapshot_id_test"}],
[:cloud_volumes, {:ems_ref => "volume_id_test"}]
]
)
)
end
end

def target_references(parsed_targets)
parsed_targets.map { |x| [x.association, x.manager_ref] }.uniq
end

def create_ems_event(event_type, payload)
event_hash = {
:event_type => event_type,
:source => "OPENSTACK",
:message => payload,
:timestamp => "2016-03-13T16:59:01.760000",
:username => "",
:full_data => {:content => {'payload' => payload}},
:ems_id => @ems.cinder_manager.id
}
EmsEvent.add(@ems.cinder_manager.id, event_hash)
end
end

0 comments on commit 39f2ec3

Please sign in to comment.