Skip to content

Commit

Permalink
Azure LoadBalancer networking
Browse files Browse the repository at this point in the history
  • Loading branch information
Bronagh Sorota committed Jan 16, 2017
1 parent 5369c7d commit 0e30064
Show file tree
Hide file tree
Showing 6 changed files with 1,130 additions and 955 deletions.
2 changes: 2 additions & 0 deletions app/models/manageiq/providers/azure/network_manager.rb
Expand Up @@ -17,6 +17,8 @@ class ManageIQ::Providers::Azure::NetworkManager < ManageIQ::Providers::NetworkM

include ManageIQ::Providers::Azure::ManagerMixin

has_many :floating_ips, :foreign_key => :ems_id, :dependent => :destroy, :class_name => ManageIQ::Providers::Azure::NetworkManager::FloatingIp

# Auth and endpoints delegations, editing of this type of manager must be disabled
delegate :authentication_check,
:authentication_status,
Expand Down
@@ -1,2 +1,5 @@
class ManageIQ::Providers::Azure::NetworkManager::FloatingIp < ::FloatingIp
def self.available
joins(:network_port).where({ "network_ports.device_id" => nil })
end
end
Expand Up @@ -31,11 +31,12 @@ def ems_inv_to_hashes
get_security_groups
get_cloud_networks
get_network_ports
get_floating_ips
get_load_balancers
get_load_balancer_pools
get_load_balancer_listeners
get_load_balancer_health_checks
get_floating_ips

_log.info("#{log_header}...Complete")

@data
Expand Down Expand Up @@ -338,22 +339,55 @@ def parse_floating_ip(ip)
uid = ip.id

new_result = {
:type => self.class.floating_ip_type,
:ems_ref => uid,
:status => ip.properties.try(:provisioning_state),
:address => ip.properties.try(:ip_address) || ip.name,
# TODO(lsmola) get :fixed_ip_address from the correct related cloud_subnet_network_port
:fixed_ip_address => @data_index.fetch_path(:network_ports,
floating_ip_network_port_id(ip),
:cloud_subnet_network_ports).try(:first).try(:[], :address),
:network_port => @data_index.fetch_path(:network_ports, floating_ip_network_port_id(ip)),
:vm => @data_index.fetch_path(:network_ports,
floating_ip_network_port_id(ip),
:device),
:type => self.class.floating_ip_type,
:ems_ref => uid,
:status => ip.properties.try(:provisioning_state),
:address => ip.properties.try(:ip_address) || ip.name,
}

network_port_id = floating_ip_network_port_id(ip)
network_port = @data_index.fetch_path(:network_ports, network_port_id)

if network_port
new_result.merge!(floating_ip_for_vm(network_port))
else
new_result.merge!(floating_ip_for_load_balancer(network_port_id))
end

return uid, new_result
end

def floating_ip_for_load_balancer(network_port_id)
load_balancer = @data_index.fetch_path(:load_balancers, network_port_id)
load_balancer.nil? ? {} : {:network_port => create_network_port(load_balancer)}
end

def floating_ip_for_vm(network_port)
# TODO(lsmola) get :fixed_ip_address from the correct related cloud_subnet_network_port

{
:network_port => network_port,
:fixed_ip_address => network_port[:cloud_subnet_network_ports].try(:first).try(:[], :address),
:vm => network_port[:device]
}
end

def create_network_port(load_balancer)
uid = "#{load_balancer[:ems_ref]}/nic1"

new_result = {
:device_ref => load_balancer[:ems_ref],
:device => load_balancer,
:ems_ref => uid,
:name => uid,
:status => "Succeeded",
:type => self.class.network_port_type,
}

@data[:network_ports] << new_result
@data_index.store_path(:network_ports, uid, new_result)
end

def parse_cloud_subnet_network_port(network_port)
{
:address => network_port.properties.private_ip_address,
Expand Down
Expand Up @@ -53,6 +53,29 @@
end
end
end

context "floating ips" do
context "not attached to a VM or Load Balancer"
it "#get_targets_for_ems" do
f_ip = FactoryGirl.create(:floating_ip_azure, :ext_management_system => ems.network_manager, :load_balancer_id => nil, :vm_id => nil)
ems.floating_ips << f_ip
expect(workflow.allowed_floating_ip_addresses.length).to eq(1)
end

context "already attached to a VM"
it "#get_targets_for_ems" do
f_ip = FactoryGirl.create(:floating_ip_azure, :ext_management_system => ems.network_manager, :load_balancer_id => nil, :vm_id => 123)
ems.floating_ips << f_ip
expect(workflow.allowed_floating_ip_addresses.length).to eq(0)
end

context "already attached to a Load Balancer"
it "#get_targets_for_ems" do
f_ip = FactoryGirl.create(:floating_ip_azure, :ext_management_system => ems.network_manager, :load_balancer_id => 456, :vm_id => nil)
ems.floating_ips << f_ip
expect(workflow.allowed_floating_ip_addresses.length).to eq(0)
end
end
end

context "with applied tags" do
Expand Down
Expand Up @@ -13,10 +13,10 @@

@resource_group = 'miq-azure-test1'
@device_name = 'miq-test-rhel1' # Make sure this is running if generating a new cassette.
@ip_address = '13.82.103.106' # This will change if you had to restart the @device_name.
@mismatch_ip = '40.71.84.41' # This will change if you had to restart the 'miqmismatch' VM.
@template = nil
@avail_zone = nil
@ip_address = '13.82.226.29' # This will change if you had to restart the @device_name.
@mismatch_ip = '13.90.255.238' # This will change if you had to restart the 'miqmismatch' VM.
@template = nil
@avail_zone = nil

cred = {
:userid => @client_id,
Expand Down Expand Up @@ -92,6 +92,7 @@ def setup_ems_and_cassette
assert_specific_orchestration_stack
assert_specific_nic_and_ip
assert_specific_load_balancers
assert_specific_load_balancer_networking
assert_specific_load_balancer_listeners
assert_specific_load_balancer_health_checks
end
Expand All @@ -113,12 +114,12 @@ def expected_table_counts
:relationship => 0,
:miq_queue => 13,
:orchestration_template => 4,
:orchestration_stack => 18,
:orchestration_stack_parameter => 188,
:orchestration_stack => 20,
:orchestration_stack_parameter => 196,
:orchestration_stack_output => 9,
:orchestration_stack_resource => 77,
:orchestration_stack_resource => 79,
:security_group => 11,
:network_port => 11,
:network_port => 14,
:cloud_network => 6,
:floating_ip => 13,
:network_router => 0,
Expand Down Expand Up @@ -175,7 +176,7 @@ def assert_ems
expect(@ems.miq_templates.size).to eq(expected_table_counts[:miq_template])

expect(@ems.orchestration_stacks.size).to eql(expected_table_counts[:orchestration_stack])
expect(@ems.direct_orchestration_stacks.size).to eql(17)
expect(@ems.direct_orchestration_stacks.size).to eql(19)
end

def assert_specific_load_balancers
Expand Down Expand Up @@ -210,6 +211,12 @@ def assert_specific_load_balancers
expect(@lb_no_members.load_balancer_pool_members.count).to eq 0
end

def assert_specific_load_balancer_networking
floating_ip = FloatingIp.where(:address => "40.71.82.83").first

expect(@lb).to eq floating_ip.network_port.device
end

def assert_specific_load_balancer_listeners
lb_listener_ems_ref = "/subscriptions/#{@subscription_id}/resourceGroups/"\
"miq-azure-test1/providers/Microsoft.Network/loadBalancers/rspec-lb1/"\
Expand Down

0 comments on commit 0e30064

Please sign in to comment.