Skip to content

Conversation

@niccoloalfredo
Copy link

Fix NetworkManager EventTargetParser for Neutron event payload structure

Summary

Fixes the EventTargetParser in NetworkManager to correctly extract resource IDs from Neutron events. The current implementation assumes a flat payload structure with a direct resource_id field, but Neutron uses nested payloads where resources are contained in type-specific objects.

Problem

Current behavior:

resource_id = event_payload['resource_id']  # Always returns nil for Neutron events

Actual Neutron payload structure:

{
  "payload": {
    "network": {
      "id": "b39598c6-e36e-4d8c-82c9-d295addcf82c",
      "tenant_id": "fd2f0bf534504696a8fb62ca84f4e191",
      ...
    }
  }
}

Solution

Key Changes

1. Added resource_type helper:

def resource_type
  @resource_type ||= ems_event.event_type.split(".").first
end

Extracts "network" from "network.create.end" automatically.

2. Added intelligent resource_id extraction:

def resource_id
  @resource_id ||= event_payload.dig(resource_type, "id") || event_payload["resource_id"]
end
  • First tries nested structure: payload.dig("network", "id")
  • Falls back to direct field for backwards compatibility

3. Replaced if/elsif chain with case statement:

target_type = case resource_type
              when "floatingip" then :floating_ips
              when "router" then :network_routers
              when "network" then :cloud_networks
              ...

4. Enhanced tenant ID extraction:

tenant_id = event_payload['tenant_id'] || 
            event_payload['project_id'] || 
            event_payload.dig(resource_type, 'tenant_id') ||
            event_payload.dig(resource_type, 'project_id') ||
            event_payload.dig('initiator', 'project_id')

Searches multiple locations for tenant/project ID in nested structures.

Testing

Manual testing with real Neutron events via AMQP:

  • ✅ Networks, Subnets, Routers, Floating IPs, Security Groups, Ports
  • ✅ Resource IDs correctly extracted from nested payloads
  • ✅ Tenant IDs correctly extracted from nested structures
  • ✅ Targeted refresh working as intended
  • ✅ Security group rules (without IDs) correctly trigger full refresh

Updated spec tests:

  • Payloads now reflect real Neutron structure (nested objects)
  • Added tests for security group rules, fallback scenarios, and tenant extraction

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants