def test_create404_triggers_background_sync(self):
        # allow the async background thread to run for this test
        self.spawn_p.stop()
        with\
            mock.patch(
                SERVER_POOL + '.rest_create_port',
                side_effect=servermanager.RemoteRestError(
                    reason=servermanager.NXNETWORK, status=404)),\
            mock.patch(DRIVER + '._send_all_data') as mock_send_all,\
            self.port(**{'device_id': 'devid', 'binding:host_id': 'host',
                         'arg_list': ('binding:host_id',)}) as p:

            # wait for thread to finish
            mm = directory.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()
Ejemplo n.º 2
0
    def test_dont_bind_non_ivs_port(self):
        host_arg = {portbindings.HOST_ID: 'hostname'}
        with mock.patch(SERVER_POOL + '.rest_get_switch',
                        side_effect=servermanager.RemoteRestError(
                            reason='No such switch', status=404)) as rmock,\
                self.port(arg_list=(portbindings.HOST_ID,),
                          **host_arg) as 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])
Ejemplo n.º 3
0
 def test_consistency_watchdog(self):
     pl = directory.get_plugin()
     pl.servers.capabilities = []
     self.watch_p.stop()
     with mock.patch('eventlet.sleep') as smock,\
             mock.patch(
                 SERVERMANAGER + '.ServerPool.rest_call',
                 side_effect=servermanager.RemoteRestError(
                     reason='Failure to trigger except clause.'))\
             as rmock,\
             mock.patch(
                 SERVERMANAGER + '.LOG.exception',
                 side_effect=KeyError('Failure to break loop'))\
             as 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 mock.patch(DRIVER + '.async_port_create',
                        side_effect=servermanager.RemoteRestError(
                            reason=servermanager.NXNETWORK,
                            status=404)),\
                mock.patch(DRIVER + '._send_all_data') as mock_send_all,\
                self.port() as p:

            plugin = directory.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']
                )
            ])