Beispiel #1
0
    def test_should_return_false_if_vcl_list_is_properly_used(self):
        loader_mock = Mock()
        loader_mock.use_vcl = Mock(return_value=VclStatus.ERROR)
        first_vcl = Vcl('Test-1', name='test-1')
        vcl_loaded_list = [(first_vcl, loader_mock, servers[1])]

        assert_false(ParallelLoader().use_vcl_list('test', vcl_loaded_list))
Beispiel #2
0
    def test_should_raise_custom_exception_if_error_occurred_while_connecting_to_server(
            self):
        first_vcl = Vcl('Test-1', name='test-1')
        vcl_list = [(servers[1], first_vcl)]

        with patch.object(VarnishApiProvider, 'get_api'):
            ParallelLoader().load_vcl_list(vcl_list)
Beispiel #3
0
    def test_should_return_vcl_list_without_broken_server_items(self):
        first_vcl = Vcl('Test-1', name='test-1')
        second_vcl = Vcl('Test-2', name='test-2')
        cluster_with_partial_reload = LogicalCluster(name='cluster1',
                                                     id=1,
                                                     partial_reload=True)
        server = VarnishServer(ip='127.0.0.1',
                               port='6082',
                               hostname='localhost-1',
                               secret='secret-1',
                               dc=dc,
                               cluster=cluster_with_partial_reload,
                               status='active')

        vcl_list = [(server, first_vcl), (servers[1], second_vcl)]

        with patch.object(VarnishApiProvider,
                          'get_api',
                          side_effect=[VclLoadException, None]):
            with patch.object(VclLoader,
                              'load_new_vcl',
                              return_value=VclStatus.OK):
                # as opposed to test:
                # test_should_raise_custom_exception_if_error_occurred_while_connecting_to_server
                # it DOES NOT raise any exception when cluster allow partial reloads
                # what is being tested implicitly there.
                to_use = ParallelLoader().load_vcl_list(vcl_list)
                assert_equals(len(to_use), 1)
Beispiel #4
0
    def test_should_discard_old_vcls(self):
        loader_mock = Mock()
        loader_mock.use_vcl = Mock(return_value=VclStatus.OK)
        loader_mock.discard_unused_vcls = Mock()
        first_vcl = Vcl('Test-1', name='test-1')
        vcl_loaded_list = [(first_vcl, loader_mock, servers[1])]

        ParallelLoader().use_vcl_list('test', vcl_loaded_list)
        assert_true([call()], loader_mock._discard_unused_vcls.call_args_list)
Beispiel #5
0
 def test_should_raise_custom_exception_if_error_occurred_while_loading_vcl(
         self):
     first_vcl = Vcl('Test-1', name='test-1')
     vcl_list = [(servers[1], first_vcl)]
     with patch.object(VarnishApiProvider, 'get_api'):
         with patch.object(VclLoader,
                           'load_new_vcl',
                           return_value=VclStatus.ERROR):
             ParallelLoader().load_vcl_list(vcl_list)
Beispiel #6
0
    def test_should_load_vcl_list_to_associated_servers(self):
        first_vcl = Vcl('Test-1', name='test-1')
        second_vcl = Vcl('Test-2', name='test-2')
        vcl_list = [(servers[0], first_vcl), (servers[1], second_vcl)]

        with patch.object(VarnishApiProvider, 'get_api') as get_api_mock:
            with patch.object(VclLoader, 'load_new_vcl') as load_vcl_mock:
                ParallelLoader().load_vcl_list(vcl_list)
                assert_equals(
                    [call(first_vcl), call(second_vcl)],
                    load_vcl_mock.call_args_list)
                assert_equals(
                    [call(servers[0]), call(servers[1])],
                    get_api_mock.call_args_list)
Beispiel #7
0
    def test_should_return_loaded_vcl_list_which_should_be_use_on_servers(
            self):
        first_vcl = Vcl('Test-1', name='test-1')
        second_vcl = Vcl('Test-2', name='test-2')
        vcl_list = [(servers[1], first_vcl), (servers[2], second_vcl)]

        with patch.object(VarnishApiProvider, 'get_api'):
            with patch.object(VclLoader,
                              'load_new_vcl',
                              return_value=VclStatus.OK):
                to_use = ParallelLoader().load_vcl_list(vcl_list)
                assert_equals(len(to_use), 2)
                self.assert_loaded_vcl_contains_proper_vcl_and_server(
                    to_use[0], first_vcl, servers[1])
                self.assert_loaded_vcl_contains_proper_vcl_and_server(
                    to_use[1], second_vcl, servers[2])