예제 #1
0
	Context("when the netns path is invalid", func() {
		BeforeEach(func() {
			var err error
			netNsFd, err = ioutil.TempFile("", "")
			Expect(err).NotTo(HaveOccurred())
		})

		It("returns the error", func() {
			err := configurer.Apply(logger, networkConfig, 42)
			Expect(err).To(MatchError(ContainSubstring("set netns")))
		})
	})

	Context("when the container interface does not exist", func() {
		BeforeEach(func() {
			networkConfig.ContainerIntf = "not-a-link"
		})

		It("returns the error", func() {
			err := configurer.Apply(logger, networkConfig, 42)
			Expect(err).To(MatchError("interface `not-a-link` was not found"))
		})
	})
})

func linkIP(netNsName, linkName string) string {
	cmd := exec.Command("ip", "netns", "exec", netNsName, "ifconfig", linkName)

	buffer := gbytes.NewBuffer()
	sess, err := gexec.Start(cmd, buffer, GinkgoWriter)
	Expect(err).NotTo(HaveOccurred())
예제 #2
0
				if name == "bridge" {
					return existingBridge, true, nil
				}

				return nil, false, nil
			}
		})

		AfterEach(func() {
			Expect(os.Remove(netnsFD.Name())).To(Succeed())
		})

		It("creates a virtual ethernet pair", func() {
			config.HostIntf = "host"
			config.BridgeName = "bridge"
			config.ContainerIntf = "container"
			Expect(configurer.Apply(logger, config, 42)).To(Succeed())

			Expect(vethCreator.CreateCalledWith.HostIfcName).To(Equal("host"))
			Expect(vethCreator.CreateCalledWith.ContainerIfcName).To(Equal("container"))
		})

		Context("when creating the pair fails", func() {
			It("returns a wrapped error", func() {
				config.HostIntf = "host"
				config.BridgeName = "bridge"
				config.ContainerIntf = "container"
				vethCreator.CreateReturns.Err = errors.New("foo bar baz")
				err := configurer.Apply(logger, config, 42)
				Expect(err).To(HaveOccurred())
				Expect(err).To(MatchError(&configure.VethPairCreationError{Cause: vethCreator.CreateReturns.Err, HostIfcName: "host", ContainerIfcName: "container"}))