prepare_mock.return_value = rpcapi.client
rpcapi.security_group_rules_for_devices('context', ['fake_device'])
- rpc_mock.assert_called_once_with(
- 'context',
- 'security_group_rules_for_devices',
- devices=['fake_device'])
+ rpc_mock.assert_called_once_with(
+ 'context',
+ 'security_group_rules_for_devices',
+ devices=['fake_device'])
class SGAgentRpcCallBackMixinTestCase(base.BaseTestCase):
with contextlib.nested(
self.subnet(network=n1, cidr='10.0.0.0/24'),
self.subnet(network=n2, cidr='10.1.0.0/24')) as (s1, s2):
- body = self._router_interface_action(
- 'add',
- r['router']['id'],
- s2['subnet']['id'],
- None)
- self.assertIn('port_id', body)
- self._router_interface_action(
- 'add',
- r['router']['id'],
- s1['subnet']['id'],
- None,
- tenant_id=tenant_id)
- self.assertIn('port_id', body)
+ body = self._router_interface_action(
+ 'add',
+ r['router']['id'],
+ s2['subnet']['id'],
+ None)
+ self.assertIn('port_id', body)
+ self._router_interface_action(
+ 'add',
+ r['router']['id'],
+ s1['subnet']['id'],
+ None,
+ tenant_id=tenant_id)
+ self.assertIn('port_id', body)
def test_router_add_interface_port(self):
with self.router() as r:
self.router(),
self.subnet(),
mock.patch.object(registry, 'notify')) as (r, s, notify):
- errors = [
- exceptions.NotificationError(
- 'foo_callback_id', n_exc.InUse()),
- ]
- # we fail the first time, but not the second, when
- # the clean-up takes place
- notify.side_effect = [
- exceptions.CallbackFailure(errors=errors), None
- ]
- self._router_interface_action('add',
- r['router']['id'],
- s['subnet']['id'],
- None)
- self._router_interface_action(
- 'remove',
- r['router']['id'],
- s['subnet']['id'],
- None,
- exc.HTTPConflict.code)
+ errors = [
+ exceptions.NotificationError(
+ 'foo_callback_id', n_exc.InUse()),
+ ]
+ # we fail the first time, but not the second, when
+ # the clean-up takes place
+ notify.side_effect = [
+ exceptions.CallbackFailure(errors=errors), None
+ ]
+ self._router_interface_action('add',
+ r['router']['id'],
+ s['subnet']['id'],
+ None)
+ self._router_interface_action(
+ 'remove',
+ r['router']['id'],
+ s['subnet']['id'],
+ None,
+ exc.HTTPConflict.code)
def test_router_clear_gateway_callback_failure_returns_409(self):
with contextlib.nested(
self.router(),
self.subnet(),
mock.patch.object(registry, 'notify')) as (r, s, notify):
- errors = [
- exceptions.NotificationError(
- 'foo_callback_id', n_exc.InUse()),
- ]
- notify.side_effect = exceptions.CallbackFailure(errors=errors)
- self._set_net_external(s['subnet']['network_id'])
- self._add_external_gateway_to_router(
- r['router']['id'],
- s['subnet']['network_id'])
- self._remove_external_gateway_from_router(
+ errors = [
+ exceptions.NotificationError(
+ 'foo_callback_id', n_exc.InUse()),
+ ]
+ notify.side_effect = exceptions.CallbackFailure(errors=errors)
+ self._set_net_external(s['subnet']['network_id'])
+ self._add_external_gateway_to_router(
r['router']['id'],
- s['subnet']['network_id'],
- external_gw_info={},
- expected_code=exc.HTTPConflict.code)
+ s['subnet']['network_id'])
+ self._remove_external_gateway_from_router(
+ r['router']['id'],
+ s['subnet']['network_id'],
+ external_gw_info={},
+ expected_code=exc.HTTPConflict.code)
def test_router_remove_interface_wrong_subnet_returns_400(self):
with self.router() as r:
mock.patch.object(
ip_lib, 'iproute_arg_supported',
return_value=iproute_arg_supported)):
- self.assertEqual(expected, self.lbm.vxlan_ucast_supported())
+ self.assertEqual(expected, self.lbm.vxlan_ucast_supported())
def test_vxlan_ucast_supported(self):
self._check_vxlan_ucast_supported(
self.agent.treat_devices_added_or_updated([{}], False))
# The function should not raise
self.assertFalse(skip_devs)
- return func.called
+ return func.called
def test_treat_devices_added_updated_ignores_invalid_ofport(self):
port = mock.Mock()
except Exception:
pass
- scan_ports.assert_has_calls([
- mock.call(set(), set()),
- mock.call(set(), set())
- ])
- process_network_ports.assert_has_calls([
- mock.call(reply2, False),
- mock.call(reply3, True)
- ])
- self.assertTrue(update_stale.called)
- # Verify the OVS restart we triggered in the loop
- # re-setup the bridges
- setup_int_br.assert_has_calls([mock.call()])
- setup_phys_br.assert_has_calls([mock.call({})])
+ scan_ports.assert_has_calls([
+ mock.call(set(), set()),
+ mock.call(set(), set())
+ ])
+ process_network_ports.assert_has_calls([
+ mock.call(reply2, False),
+ mock.call(reply3, True)
+ ])
+ self.assertTrue(update_stale.called)
+ # Verify the OVS restart we triggered in the loop
+ # re-setup the bridges
+ setup_int_br.assert_has_calls([mock.call()])
+ setup_phys_br.assert_has_calls([mock.call({})])
def test_ovs_status(self):
self._test_ovs_status(constants.OVS_NORMAL,
mock.patch.object(self.agent.dvr_agent, 'int_br', new=int_br),
mock.patch.object(self.agent.dvr_agent, 'tun_br', new=tun_br),
) as (reclaim_vlan_fn, update_dev_down_fn, _, _, _, _):
- self.agent.treat_devices_removed([self._port.vif_id])
- if ip_version == 4:
- expected = [
- mock.call.delete_dvr_process_ipv4(
- vlan_tag=lvid,
- gateway_ip=gateway_ip),
- ]
- else:
- expected = [
- mock.call.delete_dvr_process_ipv6(
- vlan_tag=lvid,
- gateway_mac=gateway_mac),
- ]
- expected.extend([
- mock.call.delete_dvr_process(
+ self.agent.treat_devices_removed([self._port.vif_id])
+ if ip_version == 4:
+ expected = [
+ mock.call.delete_dvr_process_ipv4(
+ vlan_tag=lvid,
+ gateway_ip=gateway_ip),
+ ]
+ else:
+ expected = [
+ mock.call.delete_dvr_process_ipv6(
vlan_tag=lvid,
- vif_mac=self._port.vif_mac),
- ])
- self.assertEqual([], int_br.mock_calls)
- self.assertEqual(expected, tun_br.mock_calls)
+ gateway_mac=gateway_mac),
+ ]
+ expected.extend([
+ mock.call.delete_dvr_process(
+ vlan_tag=lvid,
+ vif_mac=self._port.vif_mac),
+ ])
+ self.assertEqual([], int_br.mock_calls)
+ self.assertEqual(expected, tun_br.mock_calls)
def _test_treat_devices_removed_for_dvr(self, device_owner, ip_version=4):
self._setup_for_dvr_test()
mock.patch.object(self.agent.dvr_agent, 'int_br', new=int_br),
mock.patch.object(self.agent.dvr_agent, 'tun_br', new=tun_br),
) as (reclaim_vlan_fn, update_dev_down_fn, _, _, _, _):
- self.agent.treat_devices_removed([self._compute_port.vif_id])
- int_br.assert_has_calls([
- mock.call.delete_dvr_to_src_mac(
- network_type='vxlan',
- vlan_tag=lvid,
- dst_mac=self._compute_port.vif_mac,
- ),
- ])
- self.assertEqual([], tun_br.mock_calls)
+ self.agent.treat_devices_removed([self._compute_port.vif_id])
+ int_br.assert_has_calls([
+ mock.call.delete_dvr_to_src_mac(
+ network_type='vxlan',
+ vlan_tag=lvid,
+ dst_mac=self._compute_port.vif_mac,
+ ),
+ ])
+ self.assertEqual([], tun_br.mock_calls)
def test_treat_devices_removed_for_dvr_with_compute_ports(self):
self._test_treat_devices_removed_for_dvr(
mock.patch.object(self.agent.dvr_agent, 'int_br', new=int_br),
mock.patch.object(self.agent.dvr_agent, 'tun_br', new=tun_br),
) as (reclaim_vlan_fn, update_dev_down_fn, _, _, _, _):
- self.agent.treat_devices_removed([self._port.vif_id])
- expected_on_int_br = [
- mock.call.delete_dvr_to_src_mac(
- network_type='vxlan',
- dst_mac=self._port.vif_mac,
- vlan_tag=lvid,
- ),
- ]
- self.assertEqual(expected_on_int_br, int_br.mock_calls)
- expected_on_tun_br = []
- self.assertEqual(expected_on_tun_br, tun_br.mock_calls)
+ self.agent.treat_devices_removed([self._port.vif_id])
+ expected_on_int_br = [
+ mock.call.delete_dvr_to_src_mac(
+ network_type='vxlan',
+ dst_mac=self._port.vif_mac,
+ vlan_tag=lvid,
+ ),
+ ]
+ self.assertEqual(expected_on_int_br, int_br.mock_calls)
+ expected_on_tun_br = []
+ self.assertEqual(expected_on_tun_br, tun_br.mock_calls)
def test_setup_dvr_flows_on_int_br(self):
self._setup_for_dvr_test()
except Exception:
pass
- # FIXME(salv-orlando): There should not be assertions on log messages
- log_exception.assert_called_once_with(
- "Error while processing VIF ports")
- scan_ports.assert_has_calls([
- mock.call(set(), set()),
- mock.call(set(['tap0']), set())
- ])
- process_network_ports.assert_has_calls([
- mock.call({'current': set(['tap0']),
- 'removed': set([]),
- 'added': set(['tap2'])}, False),
- mock.call({'current': set(['tap2']),
- 'removed': set(['tap0']),
- 'added': set([])}, False)
- ])
- self.assertTrue(update_stale.called)
- self._verify_mock_calls()
+ # FIXME(salv-orlando): There should not be assertions on log
+ # messages
+ log_exception.assert_called_once_with(
+ "Error while processing VIF ports")
+ scan_ports.assert_has_calls([
+ mock.call(set(), set()),
+ mock.call(set(['tap0']), set())
+ ])
+ process_network_ports.assert_has_calls([
+ mock.call({'current': set(['tap0']),
+ 'removed': set([]),
+ 'added': set(['tap2'])}, False),
+ mock.call({'current': set(['tap2']),
+ 'removed': set(['tap0']),
+ 'added': set([])}, False)
+ ])
+ self.assertTrue(update_stale.called)
+ self._verify_mock_calls()
class TunnelTestOFCtl(TunnelTest, ovs_test_base.OVSOFCtlTestBase):
) as (gs, gr):
result = self.scheduler.auto_schedule_routers(
self.plugin, mock.ANY, mock.ANY, mock.ANY)
- self.assertTrue(self.plugin.get_enabled_agent_on_host.called)
- self.assertTrue(result)
- self.assertTrue(gs.called)
- self.assertTrue(gr.called)
+ self.assertTrue(self.plugin.get_enabled_agent_on_host.called)
+ self.assertTrue(result)
+ self.assertTrue(gs.called)
+ self.assertTrue(gr.called)
def test_auto_schedule_routers_no_agents(self):
self.plugin.get_enabled_agent_on_host.return_value = None
) as (
mock_has_binding, mock_bind):
self.scheduler._bind_routers(mock.ANY, mock.ANY, routers, agent)
- mock_has_binding.assert_called_once_with(mock.ANY, 'foo_router',
- 'foo_agent')
- self.assertEqual(not has_binding, mock_bind.called)
+ mock_has_binding.assert_called_once_with(mock.ANY, 'foo_router',
+ 'foo_agent')
+ self.assertEqual(not has_binding, mock_bind.called)
def test__bind_routers_ha_has_binding(self):
self._test__bind_routers_ha(has_binding=True)
with contextlib.nested(
mock.patch.object(scheduler, 'bind_router'),
mock.patch.object(
- plugin, 'get_snat_bindings', return_value=False)
- ):
- scheduler._schedule_router(
- plugin, self.adminContext, 'foo_router_id', None)
+ plugin, 'get_snat_bindings', return_value=False)):
+ scheduler._schedule_router(
+ plugin, self.adminContext, 'foo_router_id', None)
expected_calls = [
mock.call.get_router(mock.ANY, 'foo_router_id'),
mock.call.get_l3_agents_hosting_routers(
mock.patch.object(self.dut, 'bind_dvr_router_servicenode')
) as (mock_gl3, mock_snat_canidates, mock_bind_snat, mock_bind_dvr):
self.dut.schedule_snat_router(self.adminContext, 'foo', 'bar')
- self.assertTrue(mock_bind_snat.called)
- self.assertFalse(mock_bind_dvr.called)
+ self.assertTrue(mock_bind_snat.called)
+ self.assertFalse(mock_bind_dvr.called)
def test_schedule_snat_router_return_value(self):
agent, router = self._prepare_schedule_snat_tests()
mock_snat_bind.return_value = False
self.dut.schedule_snat_router(
self.adminContext, 'foo_router_id', router)
- self.assertFalse(mock_unbind.called)
+ self.assertFalse(mock_unbind.called)
def test_schedule_snat_router_with_snat_candidates(self):
agent, router = self._prepare_schedule_snat_tests()
mock_candidates.return_value = [agent]
self.dut.schedule_snat_router(
self.adminContext, 'foo_router_id', mock.ANY)
- mock_bind.assert_called_once_with(
- self.adminContext, 'foo_router_id', [agent])
+ mock_bind.assert_called_once_with(
+ self.adminContext, 'foo_router_id', [agent])
def test_unbind_snat_servicenode(self):
router_id = 'foo_router_id'
mock_query.return_value = binding
mock_get_subnets.return_value = ['foo_subnet_id']
self.dut.unbind_snat_servicenode(self.adminContext, router_id)
- mock_get_subnets.assert_called_with(self.adminContext, router_id)
- self.assertTrue(mock_session.call_count)
- self.assertTrue(mock_delete.call_count)
+ mock_get_subnets.assert_called_with(self.adminContext, router_id)
+ self.assertTrue(mock_session.call_count)
+ self.assertTrue(mock_delete.call_count)
core_plugin.assert_called_once_with()
l3_notifier.assert_called_once_with()