github.phpd.cn/cilium/cilium@v1.6.12/test/runtime/assertionHelpers.go (about) 1 // Copyright 2018-2019 Authors of Cilium 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 RuntimeTest 16 17 import ( 18 . "github.com/cilium/cilium/test/ginkgo-ext" 19 "github.com/cilium/cilium/test/helpers" 20 21 . "github.com/onsi/gomega" 22 ) 23 24 // ExpectPolicyEnforcementUpdated sets PolicyEnforcement mode on the provided vm 25 // running Cilium to policyEnforcementType, and waits for endpoints on vm to 26 // be in 'ready' state. It asserts whether the configuration update was successful, 27 // and if the endpoints are ready. 28 func ExpectPolicyEnforcementUpdated(vm *helpers.SSHMeta, policyEnforcementType string) { 29 By("Setting PolicyEnforcement=%s", policyEnforcementType) 30 areEndpointsReady := vm.SetPolicyEnforcementAndWait(policyEnforcementType) 31 ExpectWithOffset(1, areEndpointsReady).Should(BeTrue(), "unable to set PolicyEnforcement=%s", policyEnforcementType) 32 } 33 34 // ExpectEndpointSummary asserts whether the amount of endpoints managed by 35 // Cilium running on vm with PolicyEnforcement equal to policyEnforcementType 36 // is equal to numWithPolicyEnforcementType. 37 func ExpectEndpointSummary(vm *helpers.SSHMeta, policyEnforcementType string, numWithPolicyEnforcementType int) { 38 endpoints, err := vm.PolicyEndpointsSummary() 39 ExpectWithOffset(1, err).Should(BeNil(), "error getting endpoint summary") 40 ExpectWithOffset(1, endpoints[policyEnforcementType]).To(Equal(numWithPolicyEnforcementType), "number of endpoints with %s=%s does not match", helpers.PolicyEnforcement, policyEnforcementType) 41 } 42 43 // ExpectCiliumReady asserts that cilium status is ready 44 func ExpectCiliumReady(vm *helpers.SSHMeta) { 45 err := vm.WaitUntilReady(helpers.CiliumStartTimeout) 46 ExpectWithOffset(1, err).To(BeNil(), "Cilium-agent cannot be started") 47 48 vm.NetworkCreate(helpers.CiliumDockerNetwork, "") 49 res := vm.NetworkGet(helpers.CiliumDockerNetwork) 50 ExpectWithOffset(1, res).To(helpers.CMDSuccess(), "Cilium docker network is not created") 51 52 res = vm.SetPolicyEnforcement(helpers.PolicyEnforcementDefault) 53 ExpectWithOffset(1, res).To(helpers.CMDSuccess(), "Cannot set policy enforcement default") 54 } 55 56 // ExpectCiliumNotRunning checks that cilium has stopped with a grace period. 57 func ExpectCiliumNotRunning(vm *helpers.SSHMeta) { 58 body := func() bool { 59 res := vm.Exec("systemctl is-active cilium") 60 return !res.WasSuccessful() 61 } 62 err := helpers.WithTimeout(body, "Cilium is still running after timeout", &helpers.TimeoutConfig{Timeout: helpers.CiliumStartTimeout}) 63 ExpectWithOffset(1, err).To(BeNil(), "Cilium is still running after timeout") 64 } 65 66 // ExpectDockerContainersMatchCiliumEndpoints asserts that docker containers in 67 // Cilium network match with the endpoint list 68 func ExpectDockerContainersMatchCiliumEndpoints(vm *helpers.SSHMeta) { 69 ExpectWithOffset(1, vm.ValidateEndpointsAreCorrect(helpers.CiliumDockerNetwork)).To(BeNil(), 70 "Docker containers mistmach with Cilium Endpoints") 71 }