github.com/nmstate/kubernetes-nmstate@v0.82.0/test/e2e/handler/lldp_with_nmpolicy_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 "time" 23 24 nmstate "github.com/nmstate/kubernetes-nmstate/api/shared" 25 "github.com/nmstate/kubernetes-nmstate/test/e2e/policy" 26 . "github.com/onsi/ginkgo/v2" 27 . "github.com/onsi/gomega" 28 ) 29 30 var _ = Describe("LLDP configuration with nmpolicy", func() { 31 lldpEnabledPolicyName := "lldp-enabled" 32 lldpDisabledPolicyName := "lldp-disabled" 33 34 configureLldpOnEthernetsCapture := func(enabled string) map[string]string { 35 return map[string]string{ 36 "ethernets": `interfaces.type=="ethernet"`, 37 "ethernets-up": `capture.ethernets | interfaces.state=="up"`, 38 "ethernets-lldp": fmt.Sprintf(`capture.ethernets-up | interfaces.lldp.enabled:=%s`, enabled), 39 } 40 } 41 42 interfacesWithLldpEnabledState := nmstate.NewState(`interfaces: "{{ capture.ethernets-lldp.interfaces }}"`) 43 44 BeforeEach(func() { 45 By("Enabling LLDP on up ethernet interfaces") 46 setDesiredStateWithPolicyAndCapture(lldpEnabledPolicyName, interfacesWithLldpEnabledState, configureLldpOnEthernetsCapture("true")) 47 policy.WaitForAvailablePolicy(lldpEnabledPolicyName) 48 49 DeferCleanup(func() { 50 deletePolicy(lldpEnabledPolicyName) 51 52 By("Disabling LLDP on up ethernet interfaces") 53 setDesiredStateWithPolicyAndCapture(lldpDisabledPolicyName, interfacesWithLldpEnabledState, configureLldpOnEthernetsCapture("false")) 54 policy.WaitForAvailablePolicy(lldpDisabledPolicyName) 55 deletePolicy(lldpDisabledPolicyName) 56 }) 57 }) 58 59 It("should enable LLDP on all ethernet interfaces that are up", func() { 60 Byf("Check %s has lldp enabled", primaryNic) 61 for _, node := range nodes { 62 Eventually( 63 func() string { 64 return lldpEnabled(node, primaryNic) 65 }, 66 30*time.Second, 1*time.Second, 67 ).Should(Equal("true"), fmt.Sprintf("Interface %s should have enabled lldp", primaryNic)) 68 } 69 }) 70 })