Beispiel #1
0
			})

			It("executes the nstar command with the right arguments", func() {
				Expect(fakeCommandRunner).To(HaveExecutedSerially(fake_command_runner.CommandSpec{
					Path: "path-to-nstar",
					Args: []string{
						"path-to-tar",
						"12",
						"some-user",
						"some-path",
					},
				}))
			})

			It("attaches the tarStream reader to stdin", func() {
				Expect(fakeCommandRunner.ExecutedCommands()[0].Stdin).To(Equal(someStream))
			})
		})

		Context("when it fails", func() {
			It("returns the contents of stdout and error on failure", func() {
				fakeCommandRunner.WhenRunning(fake_command_runner.CommandSpec{}, func(cmd *exec.Cmd) error {
					cmd.Stderr.Write([]byte("some error output"))
					cmd.Stdout.Write([]byte("some std output"))
					return errors.New("someerror")
				})

				Expect(nstar.StreamIn(lagertest.NewTestLogger("test"), 12, "some-path", "some-user", someStream)).To(
					MatchError(ContainSubstring("some error output")),
				)
Beispiel #2
0
	JustBeforeEach(func() {
		commandRunner.WhenRunning(fake_command_runner.CommandSpec{
			Path: "funC",
		}, func(cmd *exec.Cmd) error {
			logFile, err := os.Create(cmd.Args[3])
			Expect(err).NotTo(HaveOccurred())
			_, err = io.Copy(logFile, bytes.NewReader([]byte(logs)))
			Expect(err).NotTo(HaveOccurred())
			return runcExitStatus
		})
	})

	It("creates the container with runC create", func() {
		Expect(runner.Create(logger, bundlePath, "some-id", garden.ProcessIO{})).To(Succeed())

		Expect(commandRunner.ExecutedCommands()[0].Path).To(Equal("funC"))
		Expect(commandRunner.ExecutedCommands()[0].Args).To(ConsistOf(
			"funC", "--debug", "--log", logFilePath, "create", "--no-new-keyring", "--bundle", bundlePath, "--pid-file", pidFilePath, "some-id",
		))
	})

	Context("when running runc fails", func() {
		BeforeEach(func() {
			runcExitStatus = errors.New("some-error")
		})

		It("returns runc's exit status", func() {
			Expect(runner.Create(logger, bundlePath, "some-id", garden.ProcessIO{})).To(MatchError("runc create: some-error: "))
		})
	})
	})

	Describe("Create", func() {
		BeforeEach(func() {
			fakeCmdRunnerStdout = "/this-is/your\n"
		})

		It("uses the correct external-image-manager binary", func() {
			_, _, err := externalImageManager.Create(
				logger, "hello", rootfs_provider.Spec{
					RootFS: baseImage,
				},
			)
			Expect(err).ToNot(HaveOccurred())

			Expect(len(fakeCommandRunner.ExecutedCommands())).To(Equal(1))
			imageManagerCmd := fakeCommandRunner.ExecutedCommands()[0]

			Expect(imageManagerCmd.Path).To(Equal("/external-image-manager-bin"))
		})

		It("returns the env variables defined in the image configuration", func() {
			imagePath, err := ioutil.TempDir("", "")
			Expect(err).NotTo(HaveOccurred())
			fakeCmdRunnerStdout = imagePath

			imageConfig := imageplugin.Image{
				Config: imageplugin.ImageConfig{
					Env: []string{"HELLO=there", "PATH=/my-path/bin"},
				},
			}
					Context("when a multiple destination networks are specified", func() {
						It("opens only that IP", func() {
							Expect(subject.PrependFilterRule(garden.NetOutRule{
								Networks: []garden.IPRange{
									{
										Start: net.ParseIP("1.2.3.4"),
									},
									{
										Start: net.ParseIP("2.2.3.4"),
										End:   net.ParseIP("2.2.3.9"),
									},
								},
							})).To(Succeed())

							Expect(fakeRunner.ExecutedCommands()).To(HaveLen(2))
							Expect(fakeRunner).To(HaveExecutedSerially(
								fake_command_runner.CommandSpec{
									Path: "/sbin/iptables",
									Args: []string{"-w", "-I", "foo-bar-baz", "1", "--protocol", "all", "--destination", "1.2.3.4", "--jump", "RETURN"},
								},
								fake_command_runner.CommandSpec{
									Path: "/sbin/iptables",
									Args: []string{"-w", "-I", "foo-bar-baz", "1", "--protocol", "all", "-m", "iprange", "--dst-range", "2.2.3.4-2.2.3.9", "--jump", "RETURN"},
								},
							))
						})
					})

					Context("when a EndIP is specified without a StartIP", func() {
						It("opens only that IP", func() {