hs-test: use anchors in yaml config files 45/37845/4
authorMaros Ondrejicka <maros.ondrejicka@pantheon.tech>
Tue, 20 Dec 2022 14:10:50 +0000 (15:10 +0100)
committerFlorin Coras <florin.coras@gmail.com>
Wed, 11 Jan 2023 19:21:49 +0000 (19:21 +0000)
Volumes can be referenced with anchors to reduce text duplication
and to explicitly show which containers share a volume.

Type: test
Signed-off-by: Maros Ondrejicka <maros.ondrejicka@pantheon.tech>
Change-Id: Id408a78262573b3faf2257c32bfa569eca2e2049

extras/hs-test/framework_test.go
extras/hs-test/go.mod
extras/hs-test/go.sum
extras/hs-test/topo-containers/2peerVeth.yaml
extras/hs-test/topo-containers/ns.yaml
extras/hs-test/topo-containers/single.yaml
extras/hs-test/topo.go

index 056be13..76d8e58 100644 (file)
@@ -131,7 +131,9 @@ func (s *HstSuite) loadContainerTopology(topologyName string) {
        }
 
        for _, elem := range yamlTopo.Volumes {
-               s.volumes = append(s.volumes, elem)
+               volumeMap := elem["volume"].(VolumeConfig)
+               hostDir := volumeMap["host-dir"].(string)
+               s.volumes = append(s.volumes, hostDir)
        }
 
        s.containers = make(map[string]*Container)
index 0674b58..3b11dd2 100644 (file)
@@ -8,7 +8,7 @@ require (
        github.com/edwarnicke/govpp v0.0.0-20220311182453-f32f292e0e91
        github.com/edwarnicke/vpphelper v0.0.0-20210617172001-3e6797de32c3
        github.com/stretchr/testify v1.7.0
-       gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b
+       gopkg.in/yaml.v3 v3.0.1
 )
 
 require (
index 13cd56c..e08a0d5 100644 (file)
@@ -141,3 +141,5 @@ gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ=
 gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
 gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b h1:h8qDotaEPuJATrMmW04NCwg7v22aHH28wwpauUhK9Oo=
 gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
+gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
+gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
index 8262232..246e5ca 100644 (file)
@@ -1,31 +1,33 @@
 ---
 volumes:
-  - server-share
-  - client-share
+  - volume: &server-vol
+      host-dir: server-share
+  - volume: &client-vol
+      host-dir: client-share
 
 containers:
   - name: "server-vpp"
     volumes:
-      - host-dir: "server-share"
+      - <<: *server-vol
         container-dir: "/tmp/server-share"
         is-default-work-dir: true
       - host-dir: "/tmp/server"
         container-dir: "/tmp/server"
   - name: "client-vpp"
     volumes:
-      - host-dir: "client-share"
+      - <<: *client-vol
         container-dir: "/tmp/client-share"
         is-default-work-dir: true
       - host-dir: "/tmp/client"
         container-dir: "/tmp/client"
   - name: "server-application"
     volumes:
-      - host-dir: "server-share"
+      - <<: *server-vol
         container-dir: "/tmp/server-share"
         is-default-work-dir: true
   - name: "client-application"
     volumes:
-      - host-dir: "client-share"
+      - <<: *client-vol
         container-dir: "/tmp/client-share"
         is-default-work-dir: true
 
index 2cb4fdc..bdba560 100644 (file)
@@ -1,19 +1,20 @@
 ---
 volumes:
-  - shared-vol
+  - volume: &shared-vol
+      host-dir: shared-vol
 
 # $HST_DIR will be replaced during runtime by path to hs-test directory
 containers:
   - name: "vpp"
     volumes:
-      - host-dir: "shared-vol"
+      - <<: *shared-vol
         container-dir: "/tmp/vpp"
         is-default-work-dir: true
   - name: "envoy"
     volumes:
       - host-dir: "$HST_DIR/envoy/proxy.yaml"
         container-dir: "/etc/envoy/envoy.yaml"
-      - host-dir: "shared-vol"
+      - <<: *shared-vol
         container-dir: "/tmp/vpp-envoy"
         is-default-work-dir: true
       - host-dir: "$HST_DIR/envoy"
index e0fea70..9ecdc90 100644 (file)
@@ -1,17 +1,18 @@
 ---
 volumes:
-  - shared-vol
+  - volume: &shared-vol
+      host-dir: shared-vol
 
 containers:
   - name: "vpp"
     volumes:
-      - host-dir: "shared-vol"
+      - <<: *shared-vol
         container-dir: "/tmp/vpp"
         is-default-work-dir: true
   - name: "nginx"
     volumes:
-      - host-dir: "shared-vol"
+      - <<: *shared-vol
         container-dir: "/tmp/nginx"
         is-default-work-dir: true
     image: "hs-test/nginx-ldp"
-    is-optional: true
\ No newline at end of file
+    is-optional: true
index cf50dad..b7e883b 100644 (file)
@@ -11,11 +11,12 @@ import (
 
 type NetDevConfig map[string]interface{}
 type ContainerConfig map[string]interface{}
+type VolumeConfig map[string]interface{}
 
 type YamlTopology struct {
        Devices    []NetDevConfig    `yaml:"devices"`
        Containers []ContainerConfig `yaml:"containers"`
-       Volumes    []string          `yaml:"volumes"`
+       Volumes    []VolumeConfig    `yaml:"volumes"`
 }
 
 func AddAddress(device, address, ns string) error {