github.com/equinix-metal/virtlet@v1.5.2-0.20191204181327-1659b8a48e9b/tests/e2e/cni_test.go (about)

     1  /*
     2  Copyright 2018 Mirantis
     3  
     4  Licensed under the Apache License, Version 2.0 (the "License");
     5  you may not use this file except in compliance with the License.
     6  You may obtain a copy of the License at
     7  
     8      http://www.apache.org/licenses/LICENSE-2.0
     9  
    10  Unless required by Applicable law or agreed to in writing, software
    11  distributed under the License is distributed on an "AS IS" BASIS,
    12  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    13  See the License for the specific language governing permissions and
    14  limitations under the License.
    15  */
    16  
    17  package e2e
    18  
    19  import (
    20  	"time"
    21  
    22  	. "github.com/onsi/gomega"
    23  
    24  	"github.com/Mirantis/virtlet/tests/e2e/framework"
    25  	. "github.com/Mirantis/virtlet/tests/e2e/ginkgo-ext"
    26  )
    27  
    28  var _ = Describe("Virtlet CNI", func() {
    29  	var (
    30  		vm *framework.VMInterface
    31  	)
    32  
    33  	Context("Teardown", func() {
    34  		// Create a VM, wait for it to start and delete it, so we can check
    35  		// if network namespace was deleted
    36  		It("Should delete network namespace when VM is deleted", func() {
    37  			vm = controller.VM("cirros-vm")
    38  			err := vm.CreateAndWait(VMOptions{}.ApplyDefaults(), time.Minute*5, nil)
    39  			Expect(err).NotTo(HaveOccurred())
    40  
    41  			virtletPod, err := vm.VirtletPod()
    42  			Expect(err).NotTo(HaveOccurred())
    43  			container, err := virtletPod.Container("virtlet")
    44  			Expect(err).NotTo(HaveOccurred())
    45  
    46  			pod, err := vm.Pod()
    47  			Expect(err).NotTo(HaveOccurred())
    48  
    49  			stdout, err := getNamespaces(container)
    50  			Expect(stdout).To(ContainSubstring(string(pod.Pod.UID)))
    51  
    52  			waitSSH(vm)
    53  			deleteVM(vm)
    54  
    55  			stdout, err = getNamespaces(container)
    56  			Expect(stdout).NotTo(ContainSubstring(string(pod.Pod.UID)))
    57  		}, 3*60)
    58  	})
    59  })
    60  
    61  func getNamespaces(container framework.Executor) (string, error) {
    62  	cmd := []string{"ip", "netns"}
    63  	return framework.RunSimple(container, cmd...)
    64  }