summaryrefslogtreecommitdiffstats
path: root/extras/hs-test/vppinstance.go
diff options
context:
space:
mode:
authorMaros Ondrejicka <maros.ondrejicka@pantheon.tech>2022-12-14 16:30:04 +0100
committerFlorin Coras <florin.coras@gmail.com>2022-12-19 17:11:52 +0000
commitdb823ed6e9543741f6969ff160314093002e037e (patch)
treebf046f85d1052058da38192687874e361c684e4c /extras/hs-test/vppinstance.go
parentaff4d320f0fe9ce68fcb83ee9ab0abc2d8612644 (diff)
hs-test: abstract away topology from test cases
Definition of shared volumes and containers has been moved to yaml files to be together with network topology. Containers are automatically run at the beginning of each test case and stopped afterward. Type: test Signed-off-by: Maros Ondrejicka <maros.ondrejicka@pantheon.tech> Change-Id: I264cbb4f1355f8bd7aade221e9609fb5b9bd693e
Diffstat (limited to 'extras/hs-test/vppinstance.go')
-rw-r--r--extras/hs-test/vppinstance.go47
1 files changed, 32 insertions, 15 deletions
diff --git a/extras/hs-test/vppinstance.go b/extras/hs-test/vppinstance.go
index c6d3935cc60..6194ce88106 100644
--- a/extras/hs-test/vppinstance.go
+++ b/extras/hs-test/vppinstance.go
@@ -40,6 +40,10 @@ plugins {
`
+const (
+ defaultCliSocketFilePath = "/var/run/vpp/cli.sock"
+)
+
type VppInstance struct {
container *Container
config VppConfig
@@ -65,28 +69,30 @@ func (vpp *VppInstance) set2VethsClient() {
vpp.config.Variant = "cln"
}
+func (vpp *VppInstance) setVppProxy() {
+ vpp.actionFuncName = "ConfigureVppProxy"
+}
+
+func (vpp *VppInstance) setEnvoyProxy() {
+ vpp.actionFuncName = "ConfigureEnvoyProxy"
+}
+
func (vpp *VppInstance) setCliSocket(filePath string) {
vpp.config.CliSocketFilePath = filePath
}
func (vpp *VppInstance) getCliSocket() string {
- return fmt.Sprintf("/tmp/%s/%s", vpp.actionFuncName, vpp.config.CliSocketFilePath)
+ return fmt.Sprintf("%s%s", vpp.container.workDir, vpp.config.CliSocketFilePath)
}
func (vpp *VppInstance) start() error {
- if vpp.config.Variant == "" {
- return fmt.Errorf("vpp start failed: variant must not be blank")
- }
if vpp.actionFuncName == "" {
return fmt.Errorf("vpp start failed: action function name must not be blank")
}
- serializedConfig, err := json.Marshal(vpp.config)
- if err != nil {
- return fmt.Errorf("vpp start failed: serializing configuration failed: %s", err)
- }
- args := fmt.Sprintf("%s '%s'", vpp.actionFuncName, string(serializedConfig))
- _, err = hstExec(args, vpp.container.name)
+ serializedConfig, err := serializeVppConfig(vpp.config)
+ args := fmt.Sprintf("%s '%s'", vpp.actionFuncName, serializedConfig)
+ _, err = vpp.container.execAction(args)
if err != nil {
return fmt.Errorf("vpp start failed: %s", err)
}
@@ -95,9 +101,9 @@ func (vpp *VppInstance) start() error {
}
func (vpp *VppInstance) vppctl(command string) (string, error) {
- dockerExecCommand := fmt.Sprintf("docker exec --detach=false %[1]s vppctl -s %[2]s %[3]s",
+ cliExecCommand := fmt.Sprintf("docker exec --detach=false %[1]s vppctl -s %[2]s %[3]s",
vpp.container.name, vpp.getCliSocket(), command)
- output, err := exechelper.CombinedOutput(dockerExecCommand)
+ output, err := exechelper.CombinedOutput(cliExecCommand)
if err != nil {
return "", fmt.Errorf("vppctl failed: %s", err)
}
@@ -106,19 +112,30 @@ func (vpp *VppInstance) vppctl(command string) (string, error) {
}
func NewVppInstance(c *Container) *VppInstance {
+ var vppConfig VppConfig
+ vppConfig.CliSocketFilePath = defaultCliSocketFilePath
vpp := new(VppInstance)
vpp.container = c
+ vpp.config = vppConfig
return vpp
}
-func DeserializeVppConfig(input string) (VppConfig, error) {
+func serializeVppConfig(vppConfig VppConfig) (string, error) {
+ serializedConfig, err := json.Marshal(vppConfig)
+ if err != nil {
+ return "", fmt.Errorf("vpp start failed: serializing configuration failed: %s", err)
+ }
+ return string(serializedConfig), nil
+}
+
+func deserializeVppConfig(input string) (VppConfig, error) {
var vppConfig VppConfig
err := json.Unmarshal([]byte(input), &vppConfig)
if err != nil {
- // Since input is not a valid JSON it is going be used as variant value
+ // Since input is not a valid JSON it is going be used as a variant value
// for compatibility reasons
vppConfig.Variant = input
- vppConfig.CliSocketFilePath = "/var/run/vpp/cli.sock"
+ vppConfig.CliSocketFilePath = defaultCliSocketFilePath
}
return vppConfig, nil
}