Beispiel #1
0
 def test_should_purge_active_varnishes(self, response_mock):
     expected_message = "varnish http response code: 200, url=http://example.com/modified_resource/"
     servers = [
         VarnishServer(ip='127.0.0.1'),
         VarnishServer(ip='127.0.0.2')
     ]
     response = VarnishPurger().purge_url(
         'http://example.com/modified_resource/', servers)
     self.assertEqual(2, len(response['success']))
     self.assertEqual(expected_message, response['success']['127.0.0.1'])
Beispiel #2
0
    def test_should_purge_active_varnishes(self, request_mock):
        expected_message_varnish1 = [
            "varnish http response code: 200, url=http://example.com/modified_resource/, headers=[('Host', 'example.com'), ('header1', 'value1')], server=127.0.0.1:80",  # noqa
            "varnish http response code: 200, url=http://example.com/modified_resource/, headers=[('Host', 'example.com'), ('header1', 'value2')], server=127.0.0.1:80"  # noqa
        ]
        expected_message_varnish2 = [
            "varnish http response code: 200, url=http://example.com/modified_resource/, headers=[('Host', 'example.com'), ('header1', 'value1')], server=127.0.0.2:80",  # noqa
            "varnish http response code: 200, url=http://example.com/modified_resource/, headers=[('Host', 'example.com'), ('header1', 'value2')], server=127.0.0.2:80"  # noqa
        ]
        servers = [
            VarnishServer(ip='127.0.0.1'),
            VarnishServer(ip='127.0.0.2')
        ]
        result = VarnishPurger().purge_url(
            'http://example.com/modified_resource/',
            servers,
            headers={'header1': ['value1', 'value2']})  # noqa

        calls = [
            call('PURGE',
                 '/modified_resource/',
                 body='',
                 headers={
                     'header1': 'value1',
                     'Host': 'example.com'
                 }),
            call('PURGE',
                 '/modified_resource/',
                 body='',
                 headers={
                     'header1': 'value2',
                     'Host': 'example.com'
                 }),
            call('PURGE',
                 '/modified_resource/',
                 body='',
                 headers={
                     'header1': 'value1',
                     'Host': 'example.com'
                 }),
            call('PURGE',
                 '/modified_resource/',
                 body='',
                 headers={
                     'header1': 'value2',
                     'Host': 'example.com'
                 })
        ]
        request_mock.assert_has_calls(calls, any_order=True)

        self.assertEqual(2, len(result['success']))
        self.assertCountEqual(expected_message_varnish1,
                              result['success']['127.0.0.1'])
        self.assertCountEqual(expected_message_varnish2,
                              result['success']['127.0.0.2'])
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_report_error_on_generic_exception(self):
     expected_error = "Unexpected error: Unknown error, url=http://example.com/modified_resource/"
     servers = [VarnishServer(ip='127.0.0.4')]
     response = VarnishPurger().purge_url(
         'http://example.com/modified_resource/', servers)
     self.assertEqual(1, len(response['error']))
     self.assertEqual(expected_error, response['error']['127.0.0.4'])
Beispiel #5
0
 def test_should_report_error_on_bad_status_line(self):
     expected_error = "Bad status line from varnish server, url=http://example.com/modified_resource/"
     servers = [VarnishServer(ip='127.0.0.3')]
     response = VarnishPurger().purge_url(
         'http://example.com/modified_resource/', servers)
     self.assertEqual(1, len(response['error']))
     self.assertEqual(expected_error, response['error']['127.0.0.3'])
Beispiel #6
0
 def test_should_provided_host_header_should_be_passed_tu_purged_server(
         self, request_mock):
     servers = [VarnishServer(ip='127.0.0.1')]
     response = VarnishPurger().purge_url(
         'http://example.com/modified_resource/',
         servers,
         headers={'Host': ['foo.com']})  # noqa
     request_mock.assert_called_with('PURGE',
                                     '/modified_resource/',
                                     body='',
                                     headers={'Host': 'foo.com'})
Beispiel #7
0
from vaas.cluster.cluster import VarnishCluster, ServerExtractor, ParallelRenderer, ParallelLoader, \
    VarnishApiProvider, VclLoadException, PartialParallelLoader
from vaas.vcl.loader import VclLoader, VclStatus
from vaas.vcl.renderer import VclRenderer, Vcl
from vaas.api.client import VarnishApi

dc = Dc(name='Tokyo', symbol='dc2')
cluster1 = LogicalCluster(name='cluster1')
cluster2 = LogicalCluster(name='cluster2')
cluster3 = LogicalCluster(name='cluster3')

servers = [
    VarnishServer(ip='127.0.0.1',
                  port='6082',
                  hostname='localhost-1',
                  secret='secret-1',
                  dc=dc,
                  cluster=cluster1,
                  status='active'),
    VarnishServer(ip='127.0.0.2',
                  port='6083',
                  hostname='localhost-2',
                  secret='secret-2',
                  dc=dc,
                  cluster=cluster2,
                  status='active'),
    VarnishServer(ip='127.0.0.3',
                  port='6084',
                  hostname='localhost-3',
                  secret='secret-3',
                  dc=dc,
Beispiel #8
0
from vaas.cluster.models import VarnishServer, Dc, LogicalCluster
from vaas.cluster.cluster import VarnishCluster, ServerExtractor, ParallelRenderer, ParallelLoader, \
    VarnishApiProvider, VclLoadException, PartialParallelLoader
from vaas.vcl.loader import VclLoader, VclStatus
from vaas.vcl.renderer import VclRenderer, Vcl
from vaas.api.client import VarnishApi

dc = Dc(name='Tokyo', symbol='dc2')
cluster1 = LogicalCluster(name='cluster1')
cluster2 = LogicalCluster(name='cluster2')
cluster3 = LogicalCluster(name='cluster3')

servers = [
    VarnishServer(ip='127.0.0.1',
                  port='6082',
                  hostname='localhost-1',
                  secret='secret-1',
                  dc=dc,
                  cluster=cluster1),
    VarnishServer(ip='127.0.0.2',
                  port='6083',
                  hostname='localhost-2',
                  secret='secret-2',
                  dc=dc,
                  cluster=cluster2),
    VarnishServer(ip='127.0.0.3',
                  port='6084',
                  hostname='localhost-3',
                  secret='secret-3',
                  dc=dc,
                  cluster=cluster3),
]