Rest API plug network interface handling

On a plug network the rest api code was trying to bring up an interface
appended by :0 which is only meant for multiple ips on the same link.  When
post network plug is called on the amphora driver, this is because a member
got added that is on a different subnet.

This change also checks to see if there are any network changes before calling
post_plug_network of the amphora driver.  It didn't make sense to call this
method if there weren't any networks plugged.

Change-Id: I76548a8c82a7a495f909b5b8ac3932a661731293
This commit is contained in:
Brandon Logan 2015-09-03 19:05:17 -05:00
parent 3fb9ffd364
commit f8af6bef7d
5 changed files with 13 additions and 10 deletions

View File

@ -118,8 +118,8 @@ def plug_network():
text = template_port.render(interface=interface)
text_file.write(text)
_bring_if_down("{interface}:0".format(interface=interface))
_bring_if_up("{interface}:0".format(interface=interface), 'network')
_bring_if_down(interface)
_bring_if_up(interface, 'network')
return flask.make_response(flask.jsonify(dict(
message="OK",

View File

@ -36,7 +36,7 @@ class MemberFlows(object):
create_member_flow.add(network_tasks.HandleNetworkDeltas(
requires=constants.DELTAS))
create_member_flow.add(amphora_driver_tasks.AmphoraePostNetworkPlug(
requires=constants.LOADBALANCER
requires=(constants.LOADBALANCER, constants.DELTAS)
))
create_member_flow.add(amphora_driver_tasks.ListenerUpdate(
requires=(constants.LISTENER, constants.VIP)))

View File

@ -165,13 +165,14 @@ class AmphoraPostNetworkPlug(BaseAmphoraTask):
class AmphoraePostNetworkPlug(BaseAmphoraTask):
"""Task to notify the amphorae post network plug."""
def execute(self, loadbalancer):
def execute(self, loadbalancer, deltas):
"""Execute post_network_plug routine."""
for amphora in loadbalancer.amphorae:
self.amphora_driver.post_network_plug(amphora)
LOG.debug("Posted network plug for the compute instance")
if amphora.id in deltas and deltas[amphora.id].add_nics:
self.amphora_driver.post_network_plug(amphora)
LOG.debug("Posted network plug for the compute instance")
def revert(self, result, loadbalancer, *args, **kwargs):
def revert(self, result, loadbalancer, deltas, *args, **kwargs):
"""Handle a failed post network plug."""
if isinstance(result, failure.Failure):
return

View File

@ -505,7 +505,7 @@ class ServerTestCase(base.TestCase):
'auto blah blah:0\n'
'iface blah inet dhcp')
mock_check_output.assert_called_with(
['ifup', 'blah:0'], stderr=-2)
['ifup', 'blah'], stderr=-2)
# same as above but ifup fails
mock_interfaces.side_effect = [['blah']]

View File

@ -230,13 +230,15 @@ class TestAmphoraDriverTasks(base.TestCase):
_LB_mock.amphorae = [_amphora_mock]
amphora_post_network_plug_obj = (amphora_driver_tasks.
AmphoraePostNetworkPlug())
amphora_post_network_plug_obj.execute(_LB_mock)
_deltas_mock = {_amphora_mock.id: mock.Mock()}
amphora_post_network_plug_obj.execute(_LB_mock, _deltas_mock)
(mock_driver.post_network_plug.
assert_called_once_with(_amphora_mock))
# Test revert
amp = amphora_post_network_plug_obj.revert(None, _LB_mock)
amp = amphora_post_network_plug_obj.revert(None, _LB_mock,
_deltas_mock)
repo.AmphoraRepository.update.assert_called_once_with(
'TEST',
id=AMP_ID,