Exemplo n.º 1
0
			Ω(process.ID()).Should(Equal(uint32(42)))

			status, err := process.Wait()
			Ω(err).ShouldNot(HaveOccurred())
			Ω(status).Should(Equal(123))

			Eventually(stdout).Should(gbytes.Say("stdout data"))
			Eventually(stderr).Should(gbytes.Say("stderr data"))
		})
	})

	Describe("NetIn", func() {
		It("sends a net in request", func() {
			fakeConnection.NetInReturns(111, 222, nil)

			hostPort, containerPort, err := container.NetIn(123, 456)
			Ω(err).ShouldNot(HaveOccurred())
			Ω(hostPort).Should(Equal(uint32(111)))
			Ω(containerPort).Should(Equal(uint32(222)))

			h, hp, cp := fakeConnection.NetInArgsForCall(0)
			Ω(h).Should(Equal("some-handle"))
			Ω(hp).Should(Equal(uint32(123)))
			Ω(cp).Should(Equal(uint32(456)))
		})

		Context("when the request fails", func() {
			disaster := errors.New("oh no!")

			BeforeEach(func() {
				fakeConnection.NetInReturns(0, 0, disaster)
		It("makes a call out to an external service", func() {
			server.AppendHandlers(
				ghttp.CombineHandlers(
					ghttp.VerifyRequest("POST", "/api/containers/containerhandle/net/in"),
					ghttp.RespondWith(200, `{"hostPort":1234}`),
					func(w http.ResponseWriter, req *http.Request) {
						body, err := ioutil.ReadAll(req.Body)
						req.Body.Close()
						Expect(err).ShouldNot(HaveOccurred())
						Expect(string(body)).Should(Equal(`{"hostPort":1234,"containerPort":3456}`))
					},
				),
			)
			var hostPort uint32 = 1234
			var containerPort uint32 = 3456
			_, _, err := container.NetIn(hostPort, containerPort)
			Expect(err).NotTo(HaveOccurred())
			Expect(server.ReceivedRequests()).Should(HaveLen(1))
		})

		Context("Containerizer succeeds", func() {
			It("returns containerizers host port", func() {
				server.AppendHandlers(
					ghttp.CombineHandlers(
						ghttp.VerifyRequest("POST", "/api/containers/containerhandle/net/in"),
						ghttp.RespondWith(200, `{"hostPort":9876}`),
					),
				)
				var containerPort uint32 = 3456
				returnedHostPort, returnedContainerPort, err := container.NetIn(1234, containerPort)
				Expect(err).NotTo(HaveOccurred())
Exemplo n.º 3
0
		Describe("NetIn", func() {
			var container garden.Container

			const (
				externalPort  uint32 = 8888
				contianerPort uint32 = 8080
			)

			BeforeEach(func() {
				var err error
				container, err = gdnr.Lookup("banana")
				Expect(err).NotTo(HaveOccurred())
			})

			It("asks the netwoker to forward the correct ports", func() {
				_, _, err := container.NetIn(externalPort, contianerPort)

				Expect(err).NotTo(HaveOccurred())
				Expect(networker.NetInCallCount()).To(Equal(1))

				actualHandle, actualExtPort, actualContainerPort := networker.NetInArgsForCall(0)
				Expect(actualHandle).To(Equal(container.Handle()))
				Expect(actualExtPort).To(Equal(externalPort))
				Expect(actualContainerPort).To(Equal(contianerPort))
			})

			Context("when networker returns an error", func() {
				It("returns the error", func() {
					networker.NetInReturns(uint32(0), uint32(0), fmt.Errorf("error"))

					_, _, err := container.NetIn(externalPort, contianerPort)
Exemplo n.º 4
0
			otherContainer, err = client.Create(garden.ContainerSpec{})
			Expect(err).ToNot(HaveOccurred())
		})

		AfterEach(func() {
			Expect(client.Destroy(otherContainer.Handle())).To(Succeed())
		})

		It("reuses IP addresses", func() {
			newIpAddress := containerIP(otherContainer)

			Expect(newIpAddress).To(Equal(otherContainerIP))
		})

		It("is accessible from the outside", func() {
			hostPort, containerPort, err := otherContainer.NetIn(0, 4321)
			Expect(err).ToNot(HaveOccurred())

			Expect(listenInContainer(otherContainer, containerPort)).To(Succeed())

			externalIP := externalIP(otherContainer)
			stdout := sendRequest(externalIP, hostPort)
			Expect(stdout).To(gbytes.Say(fmt.Sprintf("%d", containerPort)))

		})
	})

	Describe("NetIn", func() {
		It("maps the provided host port to the container port", func() {
			const (
				hostPort      uint32 = 9888
Exemplo n.º 5
0
		// Put show_port.bat in container
		tarFile, err := os.Open("../bin/show_port.tgz")
		Expect(err).ShouldNot(HaveOccurred())
		defer tarFile.Close()
		err = c.StreamIn(garden.StreamInSpec{Path: "bin", TarStream: tarFile})
		Expect(err).ShouldNot(HaveOccurred())
	})

	AfterEach(func() {
		err := client.Destroy(c.Handle())
		Expect(err).ShouldNot(HaveOccurred())
	})

	It("Sets MappedPorts correctly in container's info", func() {
		httpPort, _, err := c.NetIn(0, 8080)
		Expect(err).To(BeNil())
		sshPort, _, err := c.NetIn(0, 2222)
		Expect(err).To(BeNil())
		info, err := c.Info()
		Expect(err).To(BeNil())
		mapping := map[uint32]uint32{
			8080: httpPort,
			2222: sshPort,
		}
		Expect(info.MappedPorts).To(HaveLen(2))
		Expect(info.MappedPorts[0]).ToNot(Equal(info.MappedPorts[1]))
		for _, mp := range info.MappedPorts {
			Expect(mp.HostPort).To(Equal(mapping[mp.ContainerPort]))
		}
	})
Exemplo n.º 6
0
		Expect(err).ToNot(HaveOccurred())

		info, err := container.Info()
		Expect(err).ToNot(HaveOccurred())
		externalIP = info.ExternalIP
		hostPort = 8888
		containerPort = 8080
	})

	AfterEach(func() {
		err := client.Destroy(container.Handle())
		Expect(err).ToNot(HaveOccurred())
	})

	It("maps the provided host port to the container port", func() {
		_, _, err := container.NetIn(hostPort, containerPort)
		Expect(err).ToNot(HaveOccurred())

		Expect(listenInContainer(container, containerPort)).To(Succeed())

		stdout := sendRequest(externalIP, hostPort)
		Expect(stdout).To(gbytes.Say(fmt.Sprintf("%d", containerPort)))
	})

	Context("when multiple netin calls map the same host port to distinct container ports", func() {
		var containerPort2 uint32

		BeforeEach(func() {
			containerPort2 = uint32(8081)

			_, _, err := container.NetIn(hostPort, containerPort)
Exemplo n.º 7
0
					},
				})).To(Succeed())

				// Check it worked (sanity check)
				ByAllowingTCPTo(externalIP)

				restartGarden(gardenArgs...)
				ByAllowingTCPTo(externalIP)
			})
		})

	})

	Describe("a container's mapped port", func() {
		It("does not get reused", func() {
			netInAHost, netInAContainer, err := container.NetIn(0, 0)
			Expect(err).ToNot(HaveOccurred())

			restartGarden(gardenArgs...)

			containerB, err := client.Create(garden.ContainerSpec{})
			Expect(err).ToNot(HaveOccurred())

			netInBHost, netInBContainer, err := containerB.NetIn(0, 0)
			Expect(err).ToNot(HaveOccurred())

			Expect(netInAHost).ToNot(Equal(netInBHost))
			Expect(netInAContainer).ToNot(Equal(netInBContainer))
		})
	})