go.ligato.io/vpp-agent/v3@v3.5.0/tests/e2e/001_init_config_test.go (about) 1 // Copyright (c) 2022 Cisco and/or its affiliates. 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"); 4 // you may not use this file except in compliance with the License. 5 // You may obtain a copy of the License at: 6 // 7 // http://www.apache.org/licenses/LICENSE-2.0 8 // 9 // Unless required by applicable law or agreed to in writing, software 10 // distributed under the License is distributed on an "AS IS" BASIS, 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 // See the License for the specific language governing permissions and 13 // limitations under the License. 14 15 package e2e 16 17 import ( 18 "fmt" 19 "testing" 20 21 . "github.com/onsi/gomega" 22 23 "go.ligato.io/vpp-agent/v3/proto/ligato/kvscheduler" 24 . "go.ligato.io/vpp-agent/v3/tests/e2e/e2etest" 25 ) 26 27 // TestInitFromFile tests configuring initial state of NB from file 28 func TestInitFromFile(t *testing.T) { 29 ctx := Setup(t, WithoutVPPAgent()) 30 defer ctx.Teardown() // will teardown also VPP-Agent created later 31 32 // create init file content 33 initialConfig := ` 34 netallocConfig: {} 35 linuxConfig: {} 36 vppConfig: 37 interfaces: 38 - name: loop-test-from-init-file 39 type: SOFTWARE_LOOPBACK 40 enabled: true 41 ipAddresses: 42 - 10.10.1.1/24 43 mtu: 9000 44 ` 45 initialConfigFileName := CreateFileOnSharedVolume(ctx, "initial-config.yaml", initialConfig) 46 47 // create config content for init file usage 48 initFileRegistryConfig := ` 49 disable-initial-configuration: false 50 initial-configuration-file-path: %v 51 ` 52 initFileRegistryConfig = fmt.Sprintf(initFileRegistryConfig, initialConfigFileName) 53 54 // create VPP-Agent 55 ctx.StartAgent( 56 DefaultMainAgentName, 57 WithAdditionalAgentCmdParams(WithPluginConfigArg(ctx, "initfileregistry", initFileRegistryConfig)), 58 WithoutManualInitialAgentResync(), 59 ) 60 61 // check whether initial configuration inside file is correctly loaded in running VPP-Agent 62 initInterfaceConfigState := func() kvscheduler.ValueState { 63 return ctx.GetValueStateByKey("vpp/interface/loop-test-from-init-file/address/static/10.10.1.1/24") 64 } 65 ctx.Eventually(initInterfaceConfigState).Should(Equal(kvscheduler.ValueState_CONFIGURED), 66 "loopback from init file was not properly created") 67 } 68 69 // TestInitFromEtcd tests configuring initial state of NB from Etcd 70 func TestInitFromEtcd(t *testing.T) { 71 ctx := Setup(t, 72 WithEtcd(), 73 WithoutVPPAgent(), 74 ) 75 defer ctx.Teardown() // will teardown also VPP-Agent created later 76 77 // put NB config into Etcd 78 ctx.Expect(ctx.Etcd.Put( 79 fmt.Sprintf("/vnf-agent/%v/config/vpp/v2/interfaces/loop-test-from-etcd", AgentInstanceName(ctx)), 80 `{"name":"loop-test-from-etcd","type":"SOFTWARE_LOOPBACK","enabled":true,"ip_addresses":["10.10.1.2/24"], "mtu":9000}`)). 81 To(Succeed(), "can't insert data into ETCD") 82 83 // prepare Etcd config for VPP-Agent 84 etcdConfig := `insecure-transport: true 85 dial-timeout: 1s 86 endpoints: 87 - "%v:2379" 88 ` 89 etcdIPAddress := ctx.Etcd.IPAddress() 90 ctx.Expect(etcdIPAddress).ShouldNot(BeNil()) 91 etcdConfig = fmt.Sprintf(etcdConfig, etcdIPAddress) 92 93 // create VPP-Agent 94 ctx.StartAgent( 95 DefaultMainAgentName, 96 WithAdditionalAgentCmdParams(WithPluginConfigArg(ctx, "etcd", etcdConfig)), 97 WithoutManualInitialAgentResync(), 98 ) 99 100 // check whether NB initial configuration is correctly loaded from Etcd in running VPP-Agent 101 initInterfaceConfigState := func() kvscheduler.ValueState { 102 return ctx.GetValueStateByKey("vpp/interface/loop-test-from-etcd/address/static/10.10.1.2/24") 103 } 104 ctx.Eventually(initInterfaceConfigState).Should(Equal(kvscheduler.ValueState_CONFIGURED), 105 "loopback from etcd was not properly created") 106 } 107 108 // TestInitFromFileAndEtcd tests configuring initial state of NB from Etcd and from file 109 func TestInitFromFileAndEtcd(t *testing.T) { 110 ctx := Setup(t, 111 WithEtcd(), 112 WithoutVPPAgent(), 113 ) 114 defer ctx.Teardown() // will teardown also VPP-Agent created later 115 116 // put NB config into Etcd 117 ctx.Expect(ctx.Etcd.Put( 118 fmt.Sprintf("/vnf-agent/%v/config/vpp/v2/interfaces/memif-from-etcd", AgentInstanceName(ctx)), 119 `{ 120 "name":"memif-from-etcd", 121 "type":"MEMIF", 122 "enabled":true, 123 "ip_addresses":["10.10.1.1/32"], 124 "mtu":1500, 125 "memif": { 126 "master": false, 127 "id": 1, 128 "socket_filename": "/run/vpp/default.sock" 129 } 130 }`)).To(Succeed(), "can't insert data1 into ETCD") 131 ctx.Expect(ctx.Etcd.Put( 132 fmt.Sprintf("/vnf-agent/%v/config/vpp/v2/interfaces/memif-from-both-sources", AgentInstanceName(ctx)), 133 `{ 134 "name":"memif-from-both-sources", 135 "type":"MEMIF", 136 "enabled":true, 137 "ip_addresses":["10.10.1.3/32"], 138 "mtu":1500, 139 "memif": { 140 "master": false, 141 "id": 3, 142 "socket_filename": "/run/vpp/default.sock" 143 } 144 }`)).To(Succeed(), "can't insert data2 into ETCD") 145 146 // create init file content 147 initialConfig := ` 148 netallocConfig: {} 149 linuxConfig: {} 150 vppConfig: 151 interfaces: 152 - name: memif-from-init-file 153 type: MEMIF 154 enabled: true 155 ipAddresses: 156 - 10.10.1.2/32 157 mtu: 1500 158 memif: 159 master: false 160 id: 2 161 socketFilename: /run/vpp/default.sock 162 - name: memif-from-both-sources 163 type: MEMIF 164 enabled: true 165 ipAddresses: 166 - 10.10.1.4/32 167 mtu: 1500 168 memif: 169 master: false 170 id: 4 171 socketFilename: /run/vpp/default.sock 172 ` 173 initialConfigFileName := CreateFileOnSharedVolume(ctx, "initial-config.yaml", initialConfig) 174 175 // create config content for NB init file usage 176 initFileRegistryConfig := ` 177 disable-initial-configuration: false 178 initial-configuration-file-path: %v 179 ` 180 initFileRegistryConfig = fmt.Sprintf(initFileRegistryConfig, initialConfigFileName) 181 182 // create config content for etcd connection 183 etcdConfig := `insecure-transport: true 184 dial-timeout: 1s 185 endpoints: 186 - "%v:2379" 187 ` 188 etcdIPAddress := ctx.Etcd.IPAddress() 189 ctx.Expect(etcdIPAddress).ShouldNot(BeNil()) 190 etcdConfig = fmt.Sprintf(etcdConfig, etcdIPAddress) 191 192 // create VPP-Agent 193 ctx.StartAgent( 194 DefaultMainAgentName, 195 WithAdditionalAgentCmdParams(WithPluginConfigArg(ctx, "etcd", etcdConfig), 196 WithPluginConfigArg(ctx, "initfileregistry", initFileRegistryConfig)), 197 WithoutManualInitialAgentResync(), 198 ) 199 200 // check whether initial configuration is correctly loaded from Etcd and file in running VPP-Agent 201 initInterfaceConfigStateClb := func(interfaceName string, ipAddress string) func() kvscheduler.ValueState { 202 return func() kvscheduler.ValueState { 203 return ctx.GetValueStateByKey( 204 fmt.Sprintf("vpp/interface/%v/address/static/%v/32", interfaceName, ipAddress)) 205 } 206 } 207 ctx.Eventually(initInterfaceConfigStateClb("memif-from-etcd", "10.10.1.1")). 208 Should(Equal(kvscheduler.ValueState_CONFIGURED), 209 "unique memif from etcd was not properly created") 210 ctx.Eventually(initInterfaceConfigStateClb("memif-from-init-file", "10.10.1.2")). 211 Should(Equal(kvscheduler.ValueState_CONFIGURED), 212 "unique memif from init file was not properly created") 213 ctx.Eventually(initInterfaceConfigStateClb("memif-from-both-sources", "10.10.1.3")). 214 Should(Equal(kvscheduler.ValueState_CONFIGURED), 215 "conflicting memif (defined in init file and etcd) was either not correctly "+ 216 "merged (etcd data should have priority) or other things prevented its proper creation") 217 }