示例#1
0
    def test_atomicity_of_unset_external_gateway(self, mock_KaloomL3Driver):
        #patch super class, which has mocked certain methods
        patcher = patch.object(plugin.KaloomL3ServicePlugin, '__bases__',
                               (test_helper.MockParent, ))
        with patcher:
            patcher.is_local = True  #avoids delattr error
            l3_plugin = plugin.KaloomL3ServicePlugin()
            mock_KaloomL3Driver_instance = mock_KaloomL3Driver.return_value
            net_id, subnet_id, router = self.create_network_subnet_router(
                l3_plugin, mock_KaloomL3Driver_instance, ext_net=True)

            #set --external-gateway
            router_set_ext = {
                'router': {
                    'external_gateway_info': {
                        'network_id': net_id,
                        'enable_snat': False,
                        'external_fixed_ips': [{
                            'ip_address': '192.168.10.3'
                        }]
                    }
                }
            }
            _call_update_router(l3_plugin,
                                self.ctx,
                                router['router']['id'],
                                router_set_ext,
                                with_hold=False)
            mock_KaloomL3Driver_instance.reset_mock()

            #concurrent "unset --external-gateway", that holds for certain time
            with_hold = True
            router_unset_ext = {'router': {'external_gateway_info': {}}}
            concurrent_unset_external_gateway = threading.Thread(
                target=_call_update_router,
                args=(l3_plugin, self.ctx, router['router']['id'],
                      router_unset_ext, with_hold))
            concurrent_unset_external_gateway.start()

            #set --external-gateway, runs when above "unset --external-gateway" is in critical section.
            time.sleep(2)
            l3_plugin_1 = plugin.KaloomL3ServicePlugin()
            _call_update_router(l3_plugin_1,
                                self.ctx,
                                router['router']['id'],
                                router_set_ext,
                                with_hold=False)

            #wait for thread
            concurrent_unset_external_gateway.join()
            # atomicity rule: while unset_external_gateway is running, set_external_gateway should get blocked until
            # unset_external_gateway completes.
            assert mock_KaloomL3Driver_instance.method_calls[
                0] == call.remove_router_interface(ANY, ANY)
            assert mock_KaloomL3Driver_instance.method_calls[
                1] == call.add_router_interface(ANY, ANY)
示例#2
0
    def test_atomicity_of_sync_router_interfaces(self, mock_KaloomL3Driver):
        #patch super class, which has mocked certain methods
        patcher = patch.object(plugin.KaloomL3ServicePlugin, '__bases__',
                               (test_helper.MockParent, ))
        with patcher:
            patcher.is_local = True  #avoids delattr error
            l3_plugin = plugin.KaloomL3ServicePlugin()
            mock_KaloomL3Driver_instance = mock_KaloomL3Driver.return_value
            net_id, subnet_id, router = self.create_network_subnet_router(
                l3_plugin, mock_KaloomL3Driver_instance)

            #concurrent "sync router interfaces", that holds for certain time
            routers = [router['router']]
            concurrent_sync_router_interfaces = threading.Thread(
                target=_test_sync_router_interfaces, args=(
                    routers,
                    'hold',
                ))
            concurrent_sync_router_interfaces.start()

            #concurrent "add_router_interface": runs when above "sync router interfaces" is in critical section.
            interface_info = {'subnet_id': subnet_id}
            _call_add_router_interface(l3_plugin,
                                       self.ctx,
                                       router['router']['id'],
                                       interface_info,
                                       with_hold=False)

            #wait for thread
            concurrent_sync_router_interfaces.join()
            #sync_router_interfaces should not see router interfaces (that came once it called)
            mock_KaloomL3Driver_instance.router_l2node_link_exists.assert_not_called(
            )
示例#3
0
    def test_concurrent_add_interfaces(self, mock_KaloomL3Driver):
        #patch super class, which has mocked certain methods
        patcher = patch.object(plugin.KaloomL3ServicePlugin, '__bases__',
                               (test_helper.MockParent, ))
        with patcher:
            patcher.is_local = True  #avoids delattr error
            l3_plugin = plugin.KaloomL3ServicePlugin()
            mock_KaloomL3Driver_instance = mock_KaloomL3Driver.return_value
            net_id, subnet_id, router = self.create_network_subnet_router(
                l3_plugin, mock_KaloomL3Driver_instance)

            #concurrent "sync router interfaces": loops until loop_time seconds to make sure "sync router interfaces"
            # runs before, in-between and after "add_router_interface"
            loop_time = 4
            routers = [router['router']]
            concurrent_sync_router_interfaces = threading.Thread(
                target=_test_sync_router_interfaces,
                args=(routers, 'loop_time', loop_time))
            concurrent_sync_router_interfaces.start()

            #concurrent "add_router_interface"
            time.sleep(2)
            interface_info = {'subnet_id': subnet_id}
            _call_add_router_interface(l3_plugin,
                                       self.ctx,
                                       router['router']['id'],
                                       interface_info,
                                       with_hold=False)

            #wait for thread
            concurrent_sync_router_interfaces.join()
            # atomicity rule: Once L3Driver.add_router_interface get called (by plugin.add_router_interface), then only
            # L3Driver.router_l2node_link_exists should be called (by plugin.sync_router_interfaces).
            assert mock_KaloomL3Driver_instance.method_calls[
                0] == call.add_router_interface(ANY, ANY)
示例#4
0
    def test_atomicity_of_remove_router_interface(self, mock_KaloomL3Driver):
        #patch super class, which has mocked certain methods
        patcher = patch.object(plugin.KaloomL3ServicePlugin, '__bases__',
                               (test_helper.MockParent, ))
        with patcher:
            patcher.is_local = True  #avoids delattr error
            l3_plugin = plugin.KaloomL3ServicePlugin()
            mock_KaloomL3Driver_instance = mock_KaloomL3Driver.return_value
            net_id, subnet_id, router = self.create_network_subnet_router(
                l3_plugin, mock_KaloomL3Driver_instance)

            #add router_interface
            interface_info = {'subnet_id': subnet_id}
            _call_add_router_interface(l3_plugin,
                                       self.ctx,
                                       router['router']['id'],
                                       interface_info,
                                       with_hold=False)
            mock_KaloomL3Driver_instance.reset_mock()

            #concurrent "remove_router_interface", that holds for certain time
            with_hold = True
            concurrent_remove_router_interface = threading.Thread(
                target=_call_remove_router_interface,
                args=(l3_plugin, self.ctx, router['router']['id'],
                      interface_info, with_hold))
            concurrent_remove_router_interface.start()

            #add router_interface, runs when above "delete_router_interface" is in critical section.
            time.sleep(2)
            l3_plugin_1 = plugin.KaloomL3ServicePlugin()
            _call_add_router_interface(l3_plugin_1,
                                       self.ctx,
                                       router['router']['id'],
                                       interface_info,
                                       with_hold=False)

            #wait for thread
            concurrent_remove_router_interface.join()
            # atomicity rule: while remove_router_interface is running, add_router_interface should get blocked until
            # remove_router_interface completes.
            assert mock_KaloomL3Driver_instance.method_calls[
                0] == call.remove_router_interface(ANY, ANY)
            assert mock_KaloomL3Driver_instance.method_calls[
                1] == call.add_router_interface(ANY, ANY)
示例#5
0
    def test_router_create_delete_sync_interface(self, mock_KaloomNetconf):
        #patch super class, which has mocked certain methods
        patcher = patch.object(plugin.KaloomL3ServicePlugin, '__bases__',
                               (test_helper.MockParent, ))
        with patcher:
            patcher.is_local = True  #avoids delattr error
            l3_plugin = plugin.KaloomL3ServicePlugin()
            mock_KaloomNetconf_instance = mock_KaloomNetconf.return_value

            router = test_helper.get_mock_router_kwargs()
            # creates a router
            method = getattr(l3_plugin, 'create_router')
            method(self.ctx, router)
            mock_KaloomNetconf_instance.create_router.assert_called_once()

            # l3_sync atomic read between neutron_db and vfabric
            # starts a thread that will take the write lock and hold it for a while
            read_time = 4
            routers = [router['router']]
            vfabric_routers = []
            concurrent_test_fake_synchronize_read = threading.Thread(
                target=_test_fake_synchronize_read,
                args=(read_time, routers, vfabric_routers))
            concurrent_test_fake_synchronize_read.start()

            # meanwhile try to delete the router
            method = getattr(l3_plugin, 'delete_router')
            method(self.ctx, router['router']['id'])
            mock_KaloomNetconf_instance.delete_router.assert_called_once()

            # once the router is deleted, invokes sync_router_interfaces which should simply
            # complain that the router does not exist but still return gracefully
            _test_sync_router_interfaces(routers)
            LOG.warning.assert_called_with(
                test_helper.SubstringMatcher(
                    containing=LOG_MESSAGE_SYNC_INTERFACES_LOCK_WARNING), ANY)

            #wait for threads
            concurrent_test_fake_synchronize_read.join()
示例#6
0
    def test_atomicity_of_add_router_interface(self, mock_KaloomL3Driver):
        #patch super class, which has mocked certain methods
        patcher = patch.object(plugin.KaloomL3ServicePlugin, '__bases__',
                               (test_helper.MockParent, ))
        with patcher:
            patcher.is_local = True  #avoids delattr error
            l3_plugin = plugin.KaloomL3ServicePlugin()
            mock_KaloomL3Driver_instance = mock_KaloomL3Driver.return_value
            net_id, subnet_id, router = self.create_network_subnet_router(
                l3_plugin, mock_KaloomL3Driver_instance)

            #concurrent "sync router interfaces", runs when below "add_router_interface" is in critical section.
            routers = [router['router']]
            delay_start = 3
            concurrent_sync_router_interfaces = threading.Thread(
                target=_test_sync_router_interfaces,
                args=(routers, 'delay_start', delay_start))
            concurrent_sync_router_interfaces.start()

            #concurrent "add_router_interface": that holds for certain time
            interface_info = {'subnet_id': subnet_id}
            _call_add_router_interface(l3_plugin,
                                       self.ctx,
                                       router['router']['id'],
                                       interface_info,
                                       with_hold=True)

            #wait for thread
            concurrent_sync_router_interfaces.join()
            #sync_router_interfaces should not see router interfaces (before add_router_interface completes)
            # atomicity rule: Once L3Driver.add_router_interface get called (by plugin.add_router_interface), then only
            # L3Driver.router_l2node_link_exists should be called (by plugin.sync_router_interfaces).
            assert mock_KaloomL3Driver_instance.method_calls[
                0] == call.add_router_interface(ANY, ANY)
            assert mock_KaloomL3Driver_instance.method_calls[
                1] == call.router_l2node_link_exists(ANY, ANY, ANY)