hs-test: fill configuration files at runtime

Treat certain configuration files, which contain runtime-dependent
information, as templates. The information is filled at runtime and the
files are copied into containers.
This allows to avoid hard-coding IP addresses into configuration files.

Type: test
Signed-off-by: Maros Ondrejicka <mondreji@cisco.com>
Change-Id: I1dae8f15f4f76c0bf1779d7c68b7f3859bf5a861
This commit is contained in:
Maros Ondrejicka
2023-02-28 12:49:43 +01:00
committed by Florin Coras
parent 729b9c94f8
commit 85396a5488
6 changed files with 56 additions and 18 deletions

View File

@@ -5,6 +5,7 @@ import (
"os"
"os/exec"
"strings"
"text/template"
"github.com/edwarnicke/exechelper"
)
@@ -301,3 +302,19 @@ func (c *Container) stop() error {
c.saveLogs()
return exechelper.Run("docker stop " + c.name + " -t 0")
}
func (c *Container) createConfig(targetConfigName string, templateName string, values any) {
template := template.Must(template.ParseFiles(templateName))
f, err := os.CreateTemp("/tmp/hs-test/", "hst-config")
c.Suite().assertNil(err)
defer os.Remove(f.Name())
err = template.Execute(f, values)
c.Suite().assertNil(err)
err = f.Close()
c.Suite().assertNil(err)
c.copy(f.Name(), targetConfigName)
}

View File

@@ -49,7 +49,7 @@ func testProxyHttpTcp(s *NsSuite) error {
return nil
}
func configureVppProxy(s *NsSuite) error {
func configureVppProxy(s *NsSuite) {
serverVeth := s.netInterfaces[serverInterface]
clientVeth := s.netInterfaces[clientInterface]
@@ -60,24 +60,35 @@ func configureVppProxy(s *NsSuite) error {
serverVeth.Peer().IP4AddressString(),
)
s.log("proxy configured...", output)
return nil
}
func (s *NsSuite) TestVppProxyHttpTcp() {
err := configureVppProxy(s)
s.assertNil(err)
err = testProxyHttpTcp(s)
configureVppProxy(s)
err := testProxyHttpTcp(s)
s.assertNil(err)
}
func configureEnvoyProxy(s *NsSuite) error {
func configureEnvoyProxy(s *NsSuite) {
envoyContainer := s.getContainerByName("envoy")
return envoyContainer.run()
envoyContainer.create()
serverVeth := s.netInterfaces[serverInterface]
address := struct {
Server string
}{
Server: serverVeth.Peer().IP4AddressString(),
}
envoyContainer.createConfig(
"/etc/envoy/envoy.yaml",
"resources/envoy/proxy.yaml",
address,
)
envoyContainer.start()
}
func (s *NsSuite) TestEnvoyProxyHttpTcp() {
err := configureEnvoyProxy(s)
s.assertNil(err)
err = testProxyHttpTcp(s)
configureEnvoyProxy(s)
err := testProxyHttpTcp(s)
s.assertNil(err)
}

View File

@@ -44,7 +44,7 @@ static_resources:
address:
socket_address:
# following address will be generated by Addresser during test run
address: 10.10.2.1
address: {{.Server}}
port_value: 666
bootstrap_extensions:
- name: envoy.extensions.vcl.vcl_socket_interface

View File

@@ -29,21 +29,21 @@ http {
gzip on;
upstream bk {
server 10.10.2.1:8091;
server {{.Server}}:8091;
keepalive 30000;
}
upstream bk1 {
server 10.10.2.1:8092;
server {{.Server}}:8092;
keepalive 30000;
}
upstream bk2 {
server 10.10.2.1:8093;
server {{.Server}}:8093;
keepalive 30000;
}
server {
listen 80;
server_name 10.10.1.2;
server_name {{.Proxy}};
server_tokens off;

View File

@@ -45,7 +45,19 @@ func (s *NginxSuite) SetupTest() {
nginxContainer := s.getTransientContainerByName(nginxProxyContainerName)
nginxContainer.create()
nginxContainer.copy("./resources/nginx/nginx_proxy_mirroring.conf", "/nginx.conf")
values := struct {
Proxy string
Server string
}{
Proxy: clientInterface.Peer().IP4AddressString(),
Server: serverInterface.IP4AddressString(),
}
nginxContainer.createConfig(
"/nginx.conf",
"./resources/nginx/nginx_proxy_mirroring.conf",
values,
)
nginxContainer.start()
proxyVpp.waitForApp("-app", 5)

View File

@@ -12,8 +12,6 @@ containers:
is-default-work-dir: true
- name: "envoy"
volumes:
- host-dir: "$HST_DIR/resources/envoy/proxy.yaml"
container-dir: "/etc/envoy/envoy.yaml"
- <<: *shared-vol
container-dir: "/tmp/vpp-envoy"
is-default-work-dir: true