Varnish VTC包括 - 覆盖后端{} -

时间:2016-12-21 22:17:32

标签: varnish varnish-vcl varnish-4

我目前正在尝试为我不断增长的清漆配置文件添加一些unitests。

我设法初始化它,我认为我得到了varnishtestvtc格式的基础知识。

我需要加载我的varnish.vcl - 在那里,有几个后端。对于某些内部主机具有.host的内容,这些主机无法通过CI计算机解析。

如何覆盖后端?

我的想法基本上就像: (api01在varnish.vcl中定义,内部为dns。)

varnish v1 -vcl {
  # …some vcl to define backends… #
  include "${pwd}/varnish.vcl";
  backend api01 { .host = "127.0.0.1"; } 
} 
varnish v1 -start

失败 - Backend host '"api_loadbalancer"' could not be resolved to an IP address

但它没有继续定义上面的后端(使用127.0.0.1) - 在include之前执行后端,导致重新定义错误。

模拟后端的正确方法是什么?

1 个答案:

答案 0 :(得分:0)

我们已将VCL代码拆分为多个文件,然后"包含"所有这些都变成了一个" main.vcl"然后我们用它来开始清漆。这是一个简化的示例结构:

main.vcl
-- backends.vcl
-- directors.vcl
-- mainLogic.vcl

这使您只能将一些vcl文件包含到测试用例中,并允许您指定后端。例如,如果您想使用真正的后端:

varnish v1 -vcl {
  backend api01 { .host = "127.0.0.1"; } 
  include "${pwd}/mainLogic.vcl";
} 

或者如果你想模仿后端(我们做什么):

varnish v1 -vcl {
  backend api01 { 
    .host = "${s1_addr}";
    .port = "${s1_port}"; 
  } 
  include "${pwd}/mainLogic.vcl";
}
相关问题