Merge "Added function for create routes for the router uplink port"

This commit is contained in:
Jaume Devesa 2015-08-06 10:41:16 +02:00 committed by Gerrit Code Review
commit 825aed2c93
3 changed files with 30 additions and 1 deletions

View File

@ -41,6 +41,18 @@ Puppet::Type.type(:midonet_gateway).provide(:midonet_api_caller) do
call_add_bgp_to_port(port_id, message)
end
# Add route for 'MidoNet Provider Router' uplink port
message = Hash.new
message['type'] = "normal"
message['srcNetworkAddr'] = "0.0.0.0"
message['srcNetworkLength'] = 0
message['dstNetworkAddr'] = resource[:bgp_port]["net_prefix"]
message['dstNetworkLength'] = resource[:bgp_port]["net_length"].to_i
message['weight'] = 100
message['nextHopPort'] = port_id
call_add_route_for_uplink_port(router_id, message)
# In order to provide external connectivity for hosted
# virtual machines, the floating IP network has to be
# advertised to the BGP peers. BGP connection is assumed created
@ -223,6 +235,14 @@ Puppet::Type.type(:midonet_gateway).provide(:midonet_api_caller) do
end
end
def call_add_route_for_uplink_port(router_id, message)
res = @connection.post do |req|
req.url "/midonet-api/routers/#{router_id}/routes"
req.headers['Content-Type'] = "application/vnd.org.midonet.Route-v1+json"
req.body = message.to_json
end
end
def call_get_bgp_connections(port_id)
res = @connection.get do |req|
req.url "/midonet-api/ports/#{port_id}/bgps"
@ -272,6 +292,7 @@ Puppet::Type.type(:midonet_gateway).provide(:midonet_api_caller) do
private :call_add_bgp_to_port
:call_add_ports_to_port_group
:call_add_route_for_uplink_port
:call_advertise_route_to_bgp
:call_bind_port_to_interface
:call_create_stateful_port_group

View File

@ -17,7 +17,7 @@ Puppet::Type.newtype(:midonet_gateway) do
remote_peers => [ { 'as' => '64513', 'ip' => '198.51.100.1' },
{ 'as' => '64513', 'ip' => '203.0.113.1' } ],
advertise_net => [ { 'net_prefix' => '192.0.2.0', 'net_length' => '24' } ]
}
}
}
ensurable

View File

@ -102,6 +102,7 @@ describe Puppet::Type.type(:midonet_gateway).provider(:midonet_api_caller) do
allow(provider).to receive(:call_unbind_port_from_interface)
allow(provider).to receive(:call_remove_ports_from_port_group)
allow(provider).to receive(:call_get_uplink_port).and_return(ports)
allow(provider).to receive(:call_add_route_for_uplink_port)
allow(provider).to receive(:call_get_token).and_return('thisisafaketoken')
allow(provider).to receive(:call_get_tenant).and_return(tenants)
end
@ -121,6 +122,13 @@ describe Puppet::Type.type(:midonet_gateway).provider(:midonet_api_caller) do
expect(provider).to receive(:call_add_bgp_to_port).with(ports[0]['id'], {'localAS' => resource[:local_as],
'peerAS' => resource[:remote_peers][1]['as'],
'peerAddr' => resource[:remote_peers][1]['ip']}).once
expect(provider).to receive(:call_add_route_for_uplink_port).with(routers[0]['id'], {'type' => 'normal',
'srcNetworkAddr' => '0.0.0.0',
'srcNetworkLength' => 0,
'dstNetworkAddr' => resource[:bgp_port]['net_prefix'],
'dstNetworkLength' => resource[:bgp_port]['net_length'].to_i,
'weight' => 100,
'nextHopPort' => ports[0]['id']})
expect(provider).to receive(:call_advertise_route_to_bgp).with(bgps[0]['id'], {'nwPrefix' => resource[:advertise_net][0]['net_prefix'],
'prefixLength' => resource[:advertise_net][0]['net_length']}).once
expect(provider).to receive(:call_bind_port_to_interface).with(hosts[0]['id'], {'interfaceName' => resource[:interface],