Esempio n. 1
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(config, netnsFD)).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(config, netnsFD)
				Expect(err).To(HaveOccurred())
				Expect(err).To(MatchError(&configure.VethPairCreationError{Cause: vethCreator.CreateReturns.Err, HostIfcName: "host", ContainerIfcName: "container"}))
Esempio n. 2
0
		})
	})

	Context("when the container interface does not exist", func() {
		BeforeEach(func() {
			linkApplyr.InterfaceByNameFunc = func(name string) (*net.Interface, bool, error) {
				if name == "lo" {
					return &net.Interface{Name: name}, true, nil
				}

				return nil, false, nil
			}
		})

		It("returns a wrapped error", func() {
			config.ContainerIntf = "foo"
			err := configurer.Apply(config)
			Expect(err).To(MatchError(&configure.FindLinkError{Cause: nil, Role: "container", Name: "foo"}))
		})
	})

	Context("when the container interface exists", func() {
		BeforeEach(func() {
			linkApplyr.InterfaceByNameFunc = func(name string) (*net.Interface, bool, error) {
				return &net.Interface{Name: name}, true, nil
			}
		})

		It("Adds the requested IP", func() {
			config.ContainerIntf = "foo"
			config.ContainerIP, config.Subnet, _ = net.ParseCIDR("2.3.4.5/6")