def test_create404_triggers_background_sync(self):
     # allow the async background thread to run for this test
     self.spawn_p.stop()
     with contextlib.nested(
             mock.patch(SERVER_POOL + '.rest_create_port',
                        side_effect=servermanager.RemoteRestError(
                            reason=servermanager.NXNETWORK, status=404)),
             mock.patch(DRIVER + '._send_all_data'),
             self.port(
                 **{
                     'device_id': 'devid',
                     'binding:host_id': 'host',
                     'arg_list': ('binding:host_id', )
                 })) as (mock_http, mock_send_all, p):
         # wait for thread to finish
         mm = manager.NeutronManager.get_plugin().mechanism_manager
         bigdriver = mm.mech_drivers['bsn_ml2'].obj
         bigdriver.evpool.waitall()
         mock_send_all.assert_has_calls([
             mock.call(send_routers=True,
                       send_floating_ips=True,
                       timeout=None,
                       triggered_by_tenant=p['port']['tenant_id'])
         ])
     self.spawn_p.start()
 def test_dont_bind_non_ivs_port(self):
     host_arg = {portbindings.HOST_ID: 'hostname'}
     with contextlib.nested(
             mock.patch(SERVER_POOL + '.rest_get_switch',
                        side_effect=servermanager.RemoteRestError(
                            reason='No such switch', status=404)),
             self.port(arg_list=(portbindings.HOST_ID, ),
                       **host_arg)) as (rmock, port):
         rmock.assert_called_with('hostname')
         p = port['port']
         self.assertNotEqual(pl_config.VIF_TYPE_IVS,
                             p[portbindings.VIF_TYPE])
         self.assertNotEqual(portbindings.VIF_TYPE_VHOST_USER,
                             p[portbindings.VIF_TYPE])
Exemple #3
0
 def test_consistency_watchdog(self):
     pl = directory.get_plugin()
     pl.servers.capabilities = []
     self.watch_p.stop()
     with contextlib.nested(
             mock.patch('eventlet.sleep'),
             mock.patch(SERVERMANAGER + '.ServerPool.rest_call',
                        side_effect=servermanager.RemoteRestError(
                            reason='Failure to trigger except clause.')),
             mock.patch(
                 SERVERMANAGER + '.LOG.exception',
                 side_effect=KeyError('Failure to break loop'))) as (smock,
                                                                     rmock,
                                                                     lmock):
         # should return immediately without consistency capability
         pl.servers._consistency_watchdog()
         self.assertFalse(smock.called)
         pl.servers.capabilities = ['consistency']
         self.assertRaises(KeyError, pl.servers._consistency_watchdog)
         rmock.assert_called_with('GET', '/health', '', {}, [], False)
         self.assertEqual(1, len(lmock.mock_calls))
 def test_udpate404_triggers_background_sync(self):
     with contextlib.nested(
             mock.patch(DRIVER + '.async_port_create',
                        side_effect=servermanager.RemoteRestError(
                            reason=servermanager.NXNETWORK, status=404)),
             mock.patch(DRIVER + '._send_all_data'),
             self.port()) as (mock_update, mock_send_all, p):
         plugin = manager.NeutronManager.get_plugin()
         context = neutron_context.get_admin_context()
         plugin.update_port(
             context, p['port']['id'],
             {'port': {
                 'device_id': 'devid',
                 'binding:host_id': 'host'
             }})
         # BSN L3 plugin is loaded.
         mock_send_all.assert_has_calls([
             mock.call(send_routers=True,
                       send_floating_ips=True,
                       timeout=None,
                       triggered_by_tenant=p['port']['tenant_id'])
         ])