github.com/nmstate/kubernetes-nmstate@v0.82.0/test/e2e/handler/nncp_parallel_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 "time" 22 23 . "github.com/onsi/ginkgo/v2" 24 . "github.com/onsi/gomega" 25 26 nmstate "github.com/nmstate/kubernetes-nmstate/api/shared" 27 policyconditions "github.com/nmstate/kubernetes-nmstate/test/e2e/policy" 28 corev1 "k8s.io/api/core/v1" 29 ) 30 31 func enactmentsInProgress(policy string) int { 32 progressingEnactments := 0 33 for _, node := range nodes { 34 enactment := policyconditions.EnactmentConditionsStatus(node, policy) 35 if cond := enactment.Find(nmstate.NodeNetworkConfigurationEnactmentConditionProgressing); cond != nil { 36 if cond.Status == corev1.ConditionTrue { 37 progressingEnactments++ 38 } 39 } 40 } 41 return progressingEnactments 42 } 43 44 var _ = Describe("NNCP with maxUnavailable", func() { 45 duration := 15 * time.Second 46 interval := 500 * time.Millisecond 47 Context("when applying a policy to matching nodes", func() { 48 BeforeEach(func() { 49 By("Create a policy") 50 updateDesiredState(linuxBrUp(bridge1)) 51 }) 52 AfterEach(func() { 53 By("Remove the bridge") 54 updateDesiredStateAndWait(linuxBrAbsent(bridge1)) 55 By("Remove the policy") 56 deletePolicy(TestPolicy) 57 By("Reset desired state at all nodes") 58 resetDesiredStateForNodes() 59 }) 60 It("should be progressing on multiple nodes", func() { 61 Eventually(func() int { 62 return enactmentsInProgress(TestPolicy) 63 }, duration, interval).Should(BeNumerically("==", maxUnavailableNodes())) 64 policyconditions.WaitForAvailablePolicy(TestPolicy) 65 }) 66 It("should never exceed maxUnavailable nodes", func() { 67 Consistently(func() int { 68 return enactmentsInProgress(TestPolicy) 69 }, duration, interval).Should(BeNumerically("<=", maxUnavailableNodes())) 70 policyconditions.WaitForAvailablePolicy(TestPolicy) 71 }) 72 }) 73 })