// Clean up all pod networking (clear OVS flows, release IPAM lease, remove host/container veth) func (m *podManager) teardown(req *cniserver.PodRequest) error { if err := ns.IsNSorErr(req.Netns); err != nil { if _, ok := err.(ns.NSPathNotExistErr); ok { glog.V(3).Infof("teardown called on already-destroyed pod %s/%s", req.PodNamespace, req.PodName) return nil } } hostVethName, contVethMac, podIP, err := getVethInfo(req.Netns, podInterfaceName) if err != nil { return err } // The script's teardown functionality doesn't need the VNID out, err := exec.Command(sdnScript, tearDownCmd, hostVethName, contVethMac, podIP, "-1").CombinedOutput() glog.V(5).Infof("TearDownPod network plugin output: %s, %v", string(out), err) if isScriptError(err) { return fmt.Errorf("error running network teardown script: %s", getScriptError(out)) } else if err != nil { return err } if _, err := m.runIPAM(req.Netns, cniserver.CNI_DEL, req.ContainerId); err != nil { return err } if err := m.hostportHandler.SyncHostports(TUN, m.getRunningPods()); err != nil { return err } return nil }
createdNetNS, err := ns.NewNS() Expect(err).NotTo(HaveOccurred()) err = createdNetNS.Close() Expect(err).NotTo(HaveOccurred()) err = createdNetNS.Close() Expect(err).To(HaveOccurred()) }) }) }) Describe("IsNSorErr", func() { It("should detect a namespace", func() { createdNetNS, err := ns.NewNS() err = ns.IsNSorErr(createdNetNS.Path()) Expect(err).NotTo(HaveOccurred()) }) It("should refuse other paths", func() { tempFile, err := ioutil.TempFile("", "nstest") Expect(err).NotTo(HaveOccurred()) defer tempFile.Close() nspath := tempFile.Name() defer os.Remove(nspath) err = ns.IsNSorErr(nspath) Expect(err).To(HaveOccurred()) Expect(err).To(BeAssignableToTypeOf(ns.NSPathNotNSErr{})) Expect(err).NotTo(BeAssignableToTypeOf(ns.NSPathNotExistErr{}))