示例#1
0
    def test_should_comment_unused_tags(self):
        vcl_renderer = VclRenderer()
        vcl_template_with_unused_director = VclTemplate.objects.create(
            name='template-with-unused-director',
            content='<DIRECTOR_first_service/>\n<DIRECTOR_disabled_service/>',
            version='4.0')
        expected_content = '''\
## START director first_service ###
probe first_service_test_probe_1 {
    .url = "/status";
    .expected_response = 200;
    .interval = 3s;
    .timeout = 1.0s;
    .window = 5;
    .threshold = 3;
}

backend first_service_1_dc2_1_1_80 {
    .host = "127.0.1.1";
    .port = "80";
    .max_connections = 1;
    .connect_timeout = 0.50s;
    .first_byte_timeout = 0.10s;
    .between_bytes_timeout = 1.00s;
    .probe = first_service_test_probe_1;
}

## END director first_service ###
#<DIRECTOR_disabled_service/>\
'''

        self.varnish.template = vcl_template_with_unused_director
        vcl = vcl_renderer.render(self.varnish, '1', VclRendererInput())

        assert_equals(expected_content, vcl.content)
示例#2
0
    def test_should_prepare_default_vcl_version4_with_canary_backend(self):
        vcl_renderer = VclRenderer()
        vcl = vcl_renderer.render(self.varnish4_canary, '1',
                                  VclRendererInput())

        assert_equals('new-v4-1', vcl.name[:-10])
        self._assert_vcl_content('expected-vcl-4.0-canary.vcl', vcl.content)
示例#3
0
    def test_should_prepare_default_vcl_version4(self):
        vcl_renderer = VclRenderer()
        vcl = vcl_renderer.render(self.varnish4, '1', VclRendererInput())
        with open(os.path.join(os.path.dirname(__file__)) + os.sep + 'expected-vcl-4.0.vcl', 'r') as f:
            expected_content = f.read()

        assert_equals('new-v4-1', vcl.name[:-10])
        assert_equals(expected_content, vcl.content)
示例#4
0
    def test_should_prepare_default_vcl_version5_with_mesh_service(self):
        vcl_renderer = VclRenderer()
        vcl = vcl_renderer.render(self.varnish5_with_mesh_service, '1',
                                  VclRendererInput())

        assert_equals('new-v4-1', vcl.name[:-10])
        self._assert_vcl_content('expected-vcl-4.0-with-mesh_service.vcl',
                                 vcl.content)
示例#5
0
    def test_should_prepare_default_vcl_version4(self):
        vcl_renderer = VclRenderer()
        vcl = vcl_renderer.render(self.varnish4, '1', VclRendererInput())
        with open(
                os.path.join(os.path.dirname(__file__)) + os.sep +
                'expected-vcl-4.0.vcl', 'r') as f:
            expected_content = f.read()

        assert_equals('new-v4-1', vcl.name[:-10])
        assert_equals(expected_content, vcl.content)
示例#6
0
    def test_should_prepare_default_vcl_version5_with_mesh_service_with_attached_backend(
            self):
        vcl_renderer = VclRenderer()
        BackendFactory.create(
            address='127.11.2.10',
            dc=self.dc2,
            director=self.active_active_with_mesh_service_support)
        vcl = vcl_renderer.render(self.varnish5_with_mesh_service, '1',
                                  VclRendererInput())

        assert_equals('new-v4-1', vcl.name[:-10])
        self._assert_vcl_content('expected-vcl-4.0-with-mesh_service.vcl',
                                 vcl.content)
示例#7
0
    def test_should_replace_empty_or_disabled_director_with_information_in_error_response_varnish4(
            self):
        vcl_renderer = VclRenderer()
        vcl_template_with_unused_director = VclTemplate.objects.create(
            name='template-with-unused-director',
            content='<SET_BACKEND_ningth_director_without_backends/>',
            version='4.0')
        expected_content = '''\
return(synth(404, "<!--Director ningth_director_without_backends has no backends or is disabled-->"));\
'''

        self.varnish.template = vcl_template_with_unused_director
        vcl = vcl_renderer.render(self.varnish, '1', VclRendererInput())

        assert_equals(expected_content, vcl.content)
示例#8
0
    def test_should_comment_unused_tags(self):
        vcl_renderer = VclRenderer()
        vcl_template_with_unused_director = VclTemplate.objects.create(
            name='template-with-unused-director',
            content='<DIRECTOR_first_service/>\n<DIRECTOR_disabled_service/>',
            version='3.0'
        )
        expected_content = '''\
## START director first_service ###
probe first_service_test_probe_1 {
    .url = "/status";
    .expected_response = 200;
    .interval = 3s;
    .timeout = 1s;
    .window = 5;
    .threshold = 3;
}

backend first_service_1_dc2_1_1_80 {
    .host = "127.0.1.1";
    .port = "80";
    .max_connections = 1;
    .connect_timeout = 0.5s;
    .first_byte_timeout = 0.1s;
    .between_bytes_timeout = 1s;
    .probe = first_service_test_probe_1;
}

director first_service_dc2 round-robin {
    {
      .backend = first_service_1_dc2_1_1_80;
    }

}
## END director first_service ###
#<DIRECTOR_disabled_service/>\
'''

        self.varnish.template = vcl_template_with_unused_director
        vcl = vcl_renderer.render(self.varnish, '1', VclRendererInput())

        assert_equals(expected_content, vcl.content)
示例#9
0
文件: cluster.py 项目: sshyran/vaas
 def __init__(self, max_workers=10):
     ParallelExecutor.__init__(self, max_workers)
     self.renderer = VclRenderer()
示例#10
0
 def __init__(self, varnish_api, suppress_load_errors=False):
     self.varnish_api = varnish_api
     self.vcl_renderer = VclRenderer()
     self.suppress_load_errors = suppress_load_errors
     self.logger = logging.getLogger('vaas')