diff --git a/app/models/manageiq/providers/ibm_power_hmc/infra_manager/event_target_parser.rb b/app/models/manageiq/providers/ibm_power_hmc/infra_manager/event_target_parser.rb index 97119d2b..daf41ebc 100644 --- a/app/models/manageiq/providers/ibm_power_hmc/infra_manager/event_target_parser.rb +++ b/app/models/manageiq/providers/ibm_power_hmc/infra_manager/event_target_parser.rb @@ -20,35 +20,37 @@ def parse case ems_event.event_type when "MODIFY_URI", "ADD_URI", "DELETE_URI" # Damien: INVALID_URI? $ibm_power_hmc_log.info("#{self.class}##{__method__} #{ems_event.event_type} #{ems_event.full_data}") - elems = elem(raw_event[:data]) - case elems[:type] + elems = raw_event[:data] + .match(%r{/rest/api/uom/(?:ManagedSystem/(?[^/]+)/)?(?[^/]+)/(?[^/]+)$}) + &.named_captures || {} + case elems["type"] when "ManagedSystem" - new_targets << {:assoc => :hosts, :ems_ref => elems[:uuid]} + new_targets << {:assoc => :hosts, :ems_ref => elems["uuid"]} when "LogicalPartition", "VirtualIOServer" # raw_event[:detail] contains information about the properties that # have changed (e.g. RMCState, PartitionName, PartitionState etc...) # This may be used to perform quick property REST API calls to the HMC # instead of querying the full LPAR data. - if elems[:uuid] == NO_UUID_VALUE - $ibm_power_hmc_log.info("#{self.class}##{__method__} #{elems[:type]} Missing LPAR UUID. Escalating to full refresh for EMS: [#{ems.name}], id: [#{ems.id}].") + if elems["uuid"] == NO_UUID_VALUE + $ibm_power_hmc_log.info("#{self.class}##{__method__} #{elems["type"]} Missing LPAR UUID. Escalating to full refresh for EMS: [#{ems.name}], id: [#{ems.id}].") target_collection << ems else - new_targets << {:assoc => :vms, :ems_ref => elems[:uuid]} + new_targets << {:assoc => :vms, :ems_ref => elems["uuid"]} end when "VirtualSwitch", "VirtualNetwork" - if elems.key?(:manager_uuid) - new_targets << {:assoc => :hosts, :ems_ref => elems[:manager_uuid]} + if elems["manager_uuid"] + new_targets << {:assoc => :hosts, :ems_ref => elems["manager_uuid"]} end when "UserTask" new_targets.concat(handle_usertask(raw_event[:usertask])) when "Cluster" - new_targets << {:assoc => :storages, :ems_ref => elems[:uuid]} + new_targets << {:assoc => :storages, :ems_ref => elems["uuid"]} when "SharedProcessorPool", "SharedMemoryPool" - new_targets << {:assoc => :resource_pools, :ems_ref => "#{elems[:manager_uuid]}_#{elems[:uuid]}"} + new_targets << {:assoc => :resource_pools, :ems_ref => "#{elems["manager_uuid"]}_#{elems["uuid"]}"} end new_targets.each do |t| - $ibm_power_hmc_log.info("#{self.class}##{__method__} #{elems[:type]} uuid #{t[:ems_ref]}") + $ibm_power_hmc_log.info("#{self.class}##{__method__} #{elems["type"]} uuid #{t[:ems_ref]}") target_collection.add_target( :association => t[:assoc], :manager_ref => {:ems_ref => t[:ems_ref]} @@ -63,19 +65,6 @@ def parse private - def elem(url) - uri = URI(url) - tokens = uri.path.split('/') - elems = { - :type => tokens[-2], - :uuid => tokens[-1] - } - if tokens.length >= 4 && tokens[-4] == "ManagedSystem" - elems[:manager_uuid] = tokens[-3] - end - elems - end - def handle_usertask(usertask) return [] unless usertask["status"].eql?("Completed") diff --git a/spec/models/manageiq/providers/ibm_power_hmc/infra_manager/event_target_parser_spec.rb b/spec/models/manageiq/providers/ibm_power_hmc/infra_manager/event_target_parser_spec.rb index ab57a66d..0e859313 100644 --- a/spec/models/manageiq/providers/ibm_power_hmc/infra_manager/event_target_parser_spec.rb +++ b/spec/models/manageiq/providers/ibm_power_hmc/infra_manager/event_target_parser_spec.rb @@ -28,6 +28,15 @@ expect(parsed_targets).to eq([@ems]) end end + + context "with an invalid EventData url" do + it "returns an empty target set" do + ems_event = create_ems_event("test_data/logical_partition_invalid_event_data.xml") + parsed_targets = described_class.new(ems_event).parse + + expect(parsed_targets).to be_empty + end + end end it "VirtualIOServer" do assert_event_triggers_target( diff --git a/spec/models/manageiq/providers/ibm_power_hmc/infra_manager/test_data/logical_partition_invalid_event_data.xml b/spec/models/manageiq/providers/ibm_power_hmc/infra_manager/test_data/logical_partition_invalid_event_data.xml new file mode 100644 index 00000000..b2ac8f22 --- /dev/null +++ b/spec/models/manageiq/providers/ibm_power_hmc/infra_manager/test_data/logical_partition_invalid_event_data.xml @@ -0,0 +1,26 @@ + + + 1afb3833-8a85-369f-977a-bb8741b1a15a + Event + 2022-02-02T15:05:12.772Z + + + IBM Power Systems Management Console + + -83524495 + + + + + 1afb3833-8a85-369f-977a-bb8741b1a15a + 1639561179310 + + + ADD_URI + 1639561179310 + https://te.st:12443/rest/api/uom/ManagedSyste/e4acf909-6d0b-3c03-b75a-4d8495e5fc49/LogicalPartition/ + Other + + + +