github.com/nmstate/kubernetes-nmstate@v0.82.0/test/e2e/handler/simple_vlan_and_ip_test.go (about) 1 /* 2 Copyright The Kubernetes NMState Authors. 3 4 5 Licensed under the Apache License, Version 2.0 (the "License"); 6 you may not use this file except in compliance with the License. 7 You may obtain a copy of the License at 8 9 http://www.apache.org/licenses/LICENSE-2.0 10 11 Unless required by applicable law or agreed to in writing, software 12 distributed under the License is distributed on an "AS IS" BASIS, 13 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 See the License for the specific language governing permissions and 15 limitations under the License. 16 */ 17 18 package handler 19 20 import ( 21 "fmt" 22 23 . "github.com/onsi/ginkgo/v2" 24 . "github.com/onsi/gomega" 25 ) 26 27 var _ = Describe("NodeNetworkState", func() { 28 Context("when vlan configured", func() { 29 var ( 30 vlanID = "102" 31 ) 32 33 BeforeEach(func() { 34 updateDesiredStateAndWait(ifaceUpWithVlanUp(firstSecondaryNic, vlanID)) 35 }) 36 AfterEach(func() { 37 updateDesiredStateAndWait(vlanAbsent(firstSecondaryNic, vlanID)) 38 resetDesiredStateForNodes() 39 }) 40 It("should have the vlan interface configured", func() { 41 for _, node := range nodes { 42 vlanForNodeInterfaceEventually(node, fmt.Sprintf(`%s.%s`, firstSecondaryNic, vlanID)).Should(Equal(vlanID)) 43 } 44 }) 45 }) 46 //TODO: change static IP to DHCP once we have a DHCP server running on a VLAN. 47 Context("when static address is configured on top of vlan interface", func() { 48 var ( 49 ipAddressTemplate = "62.76.47.%d" 50 vlanID = "102" 51 ) 52 BeforeEach(func() { 53 updateDesiredStateAndWait(ifaceUpWithVlanUp(firstSecondaryNic, vlanID)) 54 for index, node := range nodes { 55 ipAddress := fmt.Sprintf(ipAddressTemplate, index) 56 Byf("applying static IP %s on node %s", ipAddress, node) 57 updateDesiredStateAtNodeAndWait(node, vlanUpWithStaticIP(fmt.Sprintf("%s.%s", firstSecondaryNic, vlanID), ipAddress)) 58 } 59 60 }) 61 62 AfterEach(func() { 63 updateDesiredStateAndWait(vlanAbsent(firstSecondaryNic, vlanID)) 64 resetDesiredStateForNodes() 65 }) 66 67 It("should have the vlan interface configured and IP configured", func() { 68 for index, node := range nodes { 69 vlanForNodeInterfaceEventually(node, fmt.Sprintf(`%s.%s`, firstSecondaryNic, vlanID)). 70 Should(Equal(vlanID)) 71 ipAddressForNodeInterfaceEventually(node, fmt.Sprintf(`%s.%s`, firstSecondaryNic, vlanID)). 72 Should(Equal(fmt.Sprintf(ipAddressTemplate, index))) 73 } 74 }) 75 }) 76 })