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

Fix case-sensitive events ems_ref parsing #225

Merged
merged 1 commit into from
Mar 19, 2018
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
Original file line number Diff line number Diff line change
Expand Up @@ -64,14 +64,20 @@ def parse_event_target(target_collection, event_data)

def transform_resource_id(association, resource_id)
case association
when :network_ports, :security_groups, :load_balancers, :floating_ips, :cloud_networks, :resource_groups, :__unused
when :network_ports, :load_balancers, :resource_groups, :__unused
fix_down_cased_resource_groups(resource_id)
when :orchestration_stacks
resource_id_for_stack_id(resource_id)
when :vms
resource_id_for_instance_id(resource_id)
when :miq_templates
resource_id.try(:downcase)
when :floating_ips
resource_id_for_floating_ips(resource_id)
when :cloud_networks
resource_id_for_cloud_networks(resource_id)
when :security_groups
resource_id_for_security_groups(resource_id)
else
resource_id
end
Expand Down Expand Up @@ -113,6 +119,22 @@ def resource_id_for_instance_id(id)
name)
end

def resource_id_for_cloud_networks(id)
id.gsub!("virtualnetworks", "virtualNetworks")
id = id.split("/subnets/").first
fix_down_cased_resource_groups(id)
end

def resource_id_for_floating_ips(id)
id.gsub!("publicIpAddresses", "publicIPAddresses")
fix_down_cased_resource_groups(id)
end

def resource_id_for_security_groups(id)
id = id.split("/securityRules/").first
fix_down_cased_resource_groups(id)
end

def resource_uid(*keys)
keys.join('\\')
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,29 +55,18 @@

context "CloudNetwork events" do
let(:klass) { :cloud_networks }
let(:expected_ems_ref) { "/subscriptions/#{@ems.subscription}/resourceGroups/#{resource_group}/providers/Microsoft.Network/virtualNetworks/test-vnet" }

context do
let(:expected_ems_ref) { "/subscriptions/#{@ems.subscription}/resourceGroups/#{resource_group}/providers/Microsoft.Network/virtualNetworks/test-vnet" }

it_behaves_like "parses_event", "virtualNetworks_delete_EndRequest"
it_behaves_like "parses_event", "virtualNetworks_write_EndRequest"
end
it_behaves_like "parses_event", "virtualNetworks_delete_EndRequest"
it_behaves_like "parses_event", "virtualNetworks_write_EndRequest"
it_behaves_like "parses_event", "virtualNetworks_subnets_EndRequest"

context do
let(:expected_ems_ref) { "/subscriptions/#{@ems.subscription}/resourceGroups/#{resource_group}/providers/Microsoft.Network/virtualnetworks/test-vnet" }
let(:event_variant) { :downcase }

it_behaves_like "parses_event", "virtualnetworks_delete_EndRequest"
it_behaves_like "parses_event", "virtualnetworks_write_EndRequest"
end

it_behaves_like "parses_event", "virtualNetworks_subnets_EndRequest" do
let(:expected_ems_ref) { "/subscriptions/#{@ems.subscription}/resourceGroups/#{resource_group}/providers/Microsoft.Network/virtualNetworks/test-vnet/subnets/test-vnet-subnet" }
end

it_behaves_like "parses_event", "virtualnetworks_subnets_EndRequest" do
let(:expected_ems_ref) { "/subscriptions/#{@ems.subscription}/resourceGroups/#{resource_group}/providers/Microsoft.Network/virtualnetworks/test-vnet/subnets/test-vnet-subnet" }
let(:event_variant) { :downcase }
it_behaves_like "parses_event", "virtualnetworks_subnets_EndRequest"
end
end

Expand All @@ -87,9 +76,7 @@

it_behaves_like "parses_event", "networkSecurityGroups_delete_EndRequest"
it_behaves_like "parses_event", "networkSecurityGroups_write_EndRequest"
it_behaves_like "parses_event", "networkSecurityGroups_securityRules_EndRequest" do
let(:expected_ems_ref) { "/subscriptions/#{@ems.subscription}/resourceGroups/#{resource_group}/providers/Microsoft.Network/networkSecurityGroups/test-nsg/securityRules/test-rule" }
end
it_behaves_like "parses_event", "networkSecurityGroups_securityRules_EndRequest"
end

context "LoadBalancer events" do
Expand All @@ -113,16 +100,12 @@

context "FloatingIp events" do
let(:klass) { :floating_ips }
let(:expected_ems_ref) { "/subscriptions/#{@ems.subscription}/resourceGroups/#{resource_group}/providers/Microsoft.Network/publicIPAddresses/test-ip" }

context do
let(:expected_ems_ref) { "/subscriptions/#{@ems.subscription}/resourceGroups/#{resource_group}/providers/Microsoft.Network/publicIPAddresses/test-ip" }

it_behaves_like "parses_event", "publicIPAddresses_delete_EndRequest"
it_behaves_like "parses_event", "publicIPAddresses_write_EndRequest"
end
it_behaves_like "parses_event", "publicIPAddresses_delete_EndRequest"
it_behaves_like "parses_event", "publicIPAddresses_write_EndRequest"

context do
let(:expected_ems_ref) { "/subscriptions/#{@ems.subscription}/resourceGroups/#{resource_group}/providers/Microsoft.Network/publicIpAddresses/test-ip" }
let(:event_variant) { :downcase }

it_behaves_like "parses_event", "publicIpAddresses_delete_EndRequest"
Expand Down