Skip to content

Commit

Permalink
Handle ENIs with multiple IP addresses.
Browse files Browse the repository at this point in the history
  • Loading branch information
Juergen Brendel committed Sep 11, 2017
1 parent 85ec6c5 commit 3bc7447
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 14 deletions.
2 changes: 1 addition & 1 deletion vpcrouter/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,4 @@
"""

__version__ = "1.8.3"
__version__ = "1.8.4"
35 changes: 24 additions & 11 deletions vpcrouter/tests/test_vpc.py
Original file line number Diff line number Diff line change
Expand Up @@ -318,8 +318,6 @@ def test_process_route_spec_config(self):

@mock_ec2_deprecated
def test_add_new_route(self):
# Testing _add_new_route

con, d, i1, eni1, i2, eni2, rt_id = self._prepare_mock_env()

self.lc.clear()
Expand All @@ -341,8 +339,6 @@ def test_add_new_route(self):

@mock_ec2_deprecated
def test_update_route(self):
# Testing _update_route

con, d, i1, eni1, i2, eni2, rt_id = self._prepare_mock_env()

vpc._add_new_route("10.9.0.0/16", self.i1ip, d, con, rt_id)
Expand Down Expand Up @@ -384,8 +380,6 @@ def test_update_route(self):

@mock_ec2_deprecated
def test_get_real_instance_if_mismatched(self):
# Testing _get_real_instance_if_mismatched

con, d, i1, eni1, i2, eni2, rt_id = self._prepare_mock_env()

self.assertFalse(vpc._get_real_instance_if_mismatch(d, None, i1, eni1))
Expand All @@ -400,8 +394,6 @@ def test_get_real_instance_if_mismatched(self):

@mock_ec2_deprecated
def test_get_host_for_route(self):
# Testing _update_route

con, d, i1, eni1, i2, eni2, rt_id = self._prepare_mock_env()

vpc._add_new_route("10.9.0.0/16", self.i1ip, d, con, rt_id)
Expand All @@ -420,7 +412,6 @@ def test_get_host_for_route(self):
self.assertEqual((i1.id, self.i1ip, eni1.id),
vpc._get_host_for_route(d, route, rt, "cidr-log"))


# Look for broken route without an instance id
route.instance_id = None
self.lc.clear()
Expand All @@ -445,7 +436,6 @@ def test_get_host_for_route(self):

@mock_ec2_deprecated
def test_update_existing_routes(self):
# Testing _update_route
con, d, i1, eni1, i2, eni2, rt_id = self._prepare_mock_env()

vpc._add_new_route("10.0.0.0/16", self.i1ip, d, con, rt_id)
Expand Down Expand Up @@ -561,7 +551,6 @@ def test_update_existing_routes(self):

@mock_ec2_deprecated
def test_add_missing_routes(self):
# Testing _update_route
con, d, i1, eni1, i2, eni2, rt_id = self._prepare_mock_env()

route_spec = {
Expand Down Expand Up @@ -613,7 +602,31 @@ def test_add_missing_routes(self):
'10.0.0.0/16! Nothing I can do...')
)

@mock_ec2_deprecated
def test_multi_address(self):
# Testing that we can find interfaces, which have the specified IP on a
# second, private IP address
con, d, i1, eni1, i2, eni2, rt_id = self._prepare_mock_env()

priv = eni1.private_ip_addresses[0]

priv = boto.ec2.networkinterface.PrivateIPAddress(
private_ip_address="10.9.9.9",
primary=False)
eni1.private_ip_addresses.append(priv)

self.lc.clear()
route_spec = {
"10.0.0.0/16" : ["10.9.9.9"]
}
self.lc.clear()
vpc._add_missing_routes(route_spec, [], [], {},
d, con, {rt_id : []})
self.lc.check(
('root', 'INFO',
"--- adding route in RT '%s' 10.0.0.0/16 -> 10.9.9.9 "
"(%s, %s)" % (rt_id, i1.id, eni1.id))
)

@mock_ec2_deprecated
def test_handle_spec(self):
Expand Down
5 changes: 3 additions & 2 deletions vpcrouter/vpc/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -134,8 +134,9 @@ def find_instance_and_eni_by_ip(vpc_info, ip):
"""
for instance in vpc_info['instances']:
for eni in instance.interfaces:
if eni.private_ip_address == ip:
return instance, eni
for pa in eni.private_ip_addresses:
if pa.private_ip_address == ip:
return instance, eni
raise VpcRouteSetError("Could not find instance/eni for '%s' "
"in VPC '%s'." % (ip, vpc_info['vpc'].id))

Expand Down

0 comments on commit 3bc7447

Please sign in to comment.