'network_id': 'net_id',
'mac_address': 'mac_addr',
'fixed_ips': [{'ip_address': '10.0.0.2',
- 'subnet': {'cidr': 'cidr'}}]}
+ 'subnet': {'cidr': '10.0.0.0/24',
+ 'gateway_ip': '10.0.0.1'}}]}
with contextlib.nested(
mock.patch('quantum.agent.linux.ip_lib.device_exists'),
mock.patch('netaddr.IPNetwork'),
- ) as (dev_exists, ip_net):
+ mock.patch('quantum.agent.linux.ip_lib.IPWrapper'),
+ ) as (dev_exists, ip_net, ip_wrap):
self.vif_driver.get_device_name.return_value = 'test_interface'
dev_exists.return_value = False
ip_net.return_value = ip_net
['10.0.0.2/24'],
namespace=
'test_ns')
+ cmd = ['route', 'add', 'default', 'gw', '10.0.0.1']
+ ip_wrap.assert_has_calls([
+ mock.call('sudo', namespace='test_ns'),
+ mock.call().netns.execute(cmd, check_exit_code=False),
+ ])
+
+ dev_exists.return_value = True
+ self.assertRaises(exceptions.PreexistingDeviceFailure,
+ self.driver._plug, 'test_ns', test_port, False)
+ def test_plug_no_gw(self):
+ test_port = {'id': 'port_id',
+ 'network_id': 'net_id',
+ 'mac_address': 'mac_addr',
+ 'fixed_ips': [{'ip_address': '10.0.0.2',
+ 'subnet': {'cidr': '10.0.0.0/24'}}]}
+ with contextlib.nested(
+ mock.patch('quantum.agent.linux.ip_lib.device_exists'),
+ mock.patch('netaddr.IPNetwork'),
+ mock.patch('quantum.agent.linux.ip_lib.IPWrapper'),
+ ) as (dev_exists, ip_net, ip_wrap):
+ self.vif_driver.get_device_name.return_value = 'test_interface'
+ dev_exists.return_value = False
+ ip_net.return_value = ip_net
+ ip_net.prefixlen = 24
+
+ self.driver._plug('test_ns', test_port)
+ self.vip_plug_callback.assert_called_once_with('plug', test_port)
+ self.assertTrue(dev_exists.called)
+ self.vif_driver.plug.assert_called_once_with('net_id', 'port_id',
+ 'test_interface',
+ 'mac_addr',
+ namespace='test_ns')
+ self.vif_driver.init_l3.assert_called_once_with('test_interface',
+ ['10.0.0.2/24'],
+ namespace=
+ 'test_ns')
+ self.assertFalse(ip_wrap.called)
dev_exists.return_value = True
self.assertRaises(exceptions.PreexistingDeviceFailure,
self.driver._plug, 'test_ns', test_port, False)