-
Notifications
You must be signed in to change notification settings - Fork 17
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
Parse the event url with Regex not split #167
Conversation
35935f5
to
6b905be
Compare
app/models/manageiq/providers/ibm_power_hmc/infra_manager/event_target_parser.rb
Outdated
Show resolved
Hide resolved
end | ||
when "VirtualSwitch", "VirtualNetwork" | ||
if elems.key?(:manager_uuid) | ||
new_targets << {:assoc => :hosts, :ems_ref => elems[:manager_uuid]} | ||
if elems["manager_uuid"] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This changed from .key?
to truthy because if it isn't matched the payload will have {"manager_uuid" => nil}
app/models/manageiq/providers/ibm_power_hmc/infra_manager/event_target_parser.rb
Outdated
Show resolved
Hide resolved
Is there specs for this? I thought I saw a spec PR come through but I can't find it |
Yes this method is well covered by specs each type has a spec associated with it. I only added a test for the invalid LPAR uuid case. |
6b905be
to
72222ab
Compare
app/models/manageiq/providers/ibm_power_hmc/infra_manager/event_target_parser.rb
Outdated
Show resolved
Hide resolved
72222ab
to
54de5f3
Compare
@Fryguy let me check if there is a spec for an invalid url first |
54de5f3
to
123d5f0
Compare
</Metadata> | ||
<EventType kb="ROR" kxe="false">ADD_URI</EventType> | ||
<EventID kb="ROR" kxe="false">1639561179310</EventID> | ||
<EventData kxe="false" kb="ROR">https://te.st:12443/rest/api/uom/ManagedSyste/e4acf909-6d0b-3c03-b75a-4d8495e5fc49/LogicalPartition/</EventData> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
With this the regular expression returns nil to exercise that case
(byebug) raw_event[:data].match(%r{/rest/api/uom/(?:ManagedSystem/(?<manager_uuid>[^/]+)/)?(?<type>[^/]+)/(?<uuid>[^/]+)$})
nil
This isn't the greatest regular expression of all time :D but it passes the specs.
The URLs for events that we get from the specs are:
Critically we have to handle the optional
ManagedSystem/d47a585d-eaa8-3a54-b4dc-93346276ea37
at the start of the url path, but if that is the whole path then we need it to match on type/uuid not manager_uuid