Esempio n. 1
0
				config.HostIntf = "host"
				config.BridgeName = "bridge"
				config.Mtu = 123
				Expect(configurer.Apply(config, netnsFD)).To(Succeed())

				Expect(linkConfigurer.SetMTUCalledWith.Interface).To(Equal(vethCreator.CreateReturns.Host))
				Expect(linkConfigurer.SetMTUCalledWith.MTU).To(Equal(123))
			})

			Context("When setting the mtu fails", func() {
				It("returns a wrapped error", func() {
					config.HostIntf = "host"
					config.BridgeName = "bridge"
					config.ContainerIntf = "container"
					config.Mtu = 14
					linkConfigurer.SetMTUReturns = errors.New("o no")
					err := configurer.Apply(config, netnsFD)
					Expect(err).To(MatchError(&configure.MTUError{Cause: linkConfigurer.SetMTUReturns, Intf: vethCreator.CreateReturns.Host, MTU: 14}))
				})
			})

			It("should move the container interface in to the container's namespace", func() {
				f, err := ioutil.TempFile("", "")
				Expect(err).NotTo(HaveOccurred())

				config.BridgeName = "bridge"

				Expect(configurer.Apply(config, netnsFD)).To(Succeed())
				Expect(linkConfigurer.SetNsCalledWith.Fd).To(Equal(int(netnsFD.Fd())))

				os.RemoveAll(f.Name())
Esempio n. 2
0
				err := configurer.Apply(config)
				Expect(err).To(MatchError(&configure.LinkUpError{Cause: cause, Link: &net.Interface{Name: "foo"}, Role: "container"}))
			})
		})

		It("sets the mtu", func() {
			config.ContainerIntf = "foo"
			config.Mtu = 1234
			Expect(configurer.Apply(config)).To(Succeed())
			Expect(linkApplyr.SetMTUCalledWith.Interface).To(Equal(&net.Interface{Name: "foo"}))
			Expect(linkApplyr.SetMTUCalledWith.MTU).To(Equal(1234))
		})

		Context("when setting the mtu fails", func() {
			It("returns a wrapped error", func() {
				linkApplyr.SetMTUReturns = errors.New("this is NOT the right potato")

				config.ContainerIntf = "foo"
				config.Mtu = 1234
				err := configurer.Apply(config)
				Expect(err).To(MatchError(&configure.MTUError{Cause: linkApplyr.SetMTUReturns, Intf: &net.Interface{Name: "foo"}, MTU: 1234}))
			})
		})

		It("adds a default gateway with the requested IP", func() {
			config.ContainerIntf = "foo"
			config.BridgeIP = net.ParseIP("2.3.4.5")
			Expect(configurer.Apply(config)).To(Succeed())
			Expect(linkApplyr.AddDefaultGWCalledWith.Interface).To(Equal(&net.Interface{Name: "foo"}))
			Expect(linkApplyr.AddDefaultGWCalledWith.IP).To(Equal(net.ParseIP("2.3.4.5")))
		})