"github.com/cloudfoundry-incubator/garden-linux/linux_container/fake_network_statisticser"
	"github.com/cloudfoundry-incubator/garden-linux/linux_container/fake_quota_manager"
	"github.com/cloudfoundry-incubator/garden-linux/linux_container/fake_watcher"
	networkFakes "github.com/cloudfoundry-incubator/garden-linux/network/fakes"
	"github.com/cloudfoundry-incubator/garden-linux/port_pool/fake_port_pool"
	"github.com/cloudfoundry-incubator/garden-linux/process_tracker/fake_process_tracker"
	wfakes "github.com/cloudfoundry-incubator/garden/fakes"
	"github.com/cloudfoundry/gunk/command_runner/fake_command_runner"
	. "github.com/cloudfoundry/gunk/command_runner/fake_command_runner/matchers"
)

var _ = Describe("Linux containers", func() {
	var fakeCgroups *fake_cgroups_manager.FakeCgroupsManager
	var fakeQuotaManager *fake_quota_manager.FakeQuotaManager
	var fakeBandwidthManager *fake_bandwidth_manager.FakeBandwidthManager
	var fakeRunner *fake_command_runner.FakeCommandRunner
	var containerResources *linux_backend.Resources
	var container *linux_container.LinuxContainer
	var fakePortPool *fake_port_pool.FakePortPool
	var fakeProcessTracker *fake_process_tracker.FakeProcessTracker
	var fakeFilter *networkFakes.FakeFilter
	var fakeOomWatcher *fake_watcher.FakeWatcher
	var containerDir string
	var containerProps map[string]string

	BeforeEach(func() {
		fakeRunner = fake_command_runner.New()

		fakeCgroups = fake_cgroups_manager.New("/cgroups", "some-id")

		fakeQuotaManager = new(fake_quota_manager.FakeQuotaManager)
	"code.cloudfoundry.org/lager"
	"code.cloudfoundry.org/lager/lagertest"
	"github.com/cloudfoundry/gunk/command_runner/fake_command_runner"

	. "github.com/cloudfoundry/gunk/command_runner/fake_command_runner/matchers"
	. "github.com/onsi/ginkgo"
	. "github.com/onsi/ginkgo/extensions/table"
	. "github.com/onsi/gomega"
)

var _ = Describe("Create", func() {
	var (
		fakeRunner *fake_command_runner.FakeCommandRunner
		creator    *iptables.InstanceChainCreator
		bridgeName string
		ip         net.IP
		network    *net.IPNet
		logger     lager.Logger
		handle     string
	)

	BeforeEach(func() {
		var err error

		fakeRunner = fake_command_runner.New()
		logger = lagertest.NewTestLogger("test")

		handle = "some-handle-that-is-longer-than-29-characters-long"
		bridgeName = "some-bridge"
		ip, network, err = net.ParseCIDR("1.2.3.4/28")
		Expect(err).NotTo(HaveOccurred())
Exemple #3
0
	"code.cloudfoundry.org/lager/lagertest"
	"github.com/cloudfoundry/gunk/command_runner/fake_command_runner"
	. "github.com/cloudfoundry/gunk/command_runner/fake_command_runner/matchers"
	. "github.com/onsi/ginkgo"
	. "github.com/onsi/gomega"
)

var _ = Describe("RunAndLog", func() {
	const logs string = `time="2016-03-02T13:56:38Z" level=warning msg="signal: potato"
				time="2016-03-02T13:56:38Z" level=error msg="fork/exec POTATO: no such file or directory"
				time="2016-03-02T13:56:38Z" level=fatal msg="Container start failed: [10] System error: fork/exec POTATO: no such file or directory"`

	var (
		commandRunner *fake_command_runner.FakeCommandRunner
		logRunner     runrunc.RuncCmdRunner
		logger        *lagertest.TestLogger

		logFile *os.File
	)

	BeforeEach(func() {
		commandRunner = fake_command_runner.New()
		logger = lagertest.NewTestLogger("test")

		var err error
		logFile, err = ioutil.TempFile("", "runandlog")
		Expect(err).NotTo(HaveOccurred())

		logRunner = runrunc.NewLogRunner(commandRunner, func() (*os.File, error) {
			return logFile, nil
		})
Exemple #4
0
	"io"
	"io/ioutil"
	"os/exec"

	"code.cloudfoundry.org/guardian/rundmc"
	"code.cloudfoundry.org/lager/lagertest"
	"github.com/cloudfoundry/gunk/command_runner/fake_command_runner"
	. "github.com/cloudfoundry/gunk/command_runner/fake_command_runner/matchers"
	. "github.com/onsi/ginkgo"
	. "github.com/onsi/gomega"
	"github.com/onsi/gomega/gbytes"
)

var _ = Describe("Nstar", func() {
	var (
		fakeCommandRunner *fake_command_runner.FakeCommandRunner
		nstar             rundmc.NstarRunner
	)

	BeforeEach(func() {
		fakeCommandRunner = fake_command_runner.New()
		nstar = rundmc.NewNstarRunner(
			"path-to-nstar",
			"path-to-tar",
			fakeCommandRunner,
		)
	})

	Describe("StreamIn", func() {
		var someStream io.Reader

		BeforeEach(func() {
Exemple #5
0
	"code.cloudfoundry.org/lager/lagertest"
	. "github.com/onsi/ginkgo"
	. "github.com/onsi/gomega"

	"code.cloudfoundry.org/garden"
	"code.cloudfoundry.org/guardian/rundmc/runrunc"
	fakes "code.cloudfoundry.org/guardian/rundmc/runrunc/runruncfakes"
	"github.com/cloudfoundry/gunk/command_runner/fake_command_runner"
	. "github.com/cloudfoundry/gunk/command_runner/fake_command_runner/matchers"
)

var _ = Describe("Stats", func() {
	var (
		commandRunner *fake_command_runner.FakeCommandRunner
		runner        *fakes.FakeRuncCmdRunner
		runcBinary    *fakes.FakeRuncBinary
		logger        *lagertest.TestLogger

		statser *runrunc.Statser
	)

	BeforeEach(func() {
		runcBinary = new(fakes.FakeRuncBinary)
		commandRunner = fake_command_runner.New()
		runner = new(fakes.FakeRuncCmdRunner)
		logger = lagertest.NewTestLogger("test")

		statser = runrunc.NewStatser(runner, runcBinary)

		runcBinary.StatsCommandStub = func(id string, logFile string) *exec.Cmd {
			return exec.Command("funC-stats", "--log", logFile, id)
		}
Exemple #6
0
	"os/exec"

	"code.cloudfoundry.org/lager/lagertest"
	. "github.com/onsi/ginkgo"
	. "github.com/onsi/gomega"

	"code.cloudfoundry.org/guardian/rundmc/runrunc"
	fakes "code.cloudfoundry.org/guardian/rundmc/runrunc/runruncfakes"
	"github.com/cloudfoundry/gunk/command_runner/fake_command_runner"
)

var _ = Describe("Watching for Events", func() {
	var (
		commandRunner *fake_command_runner.FakeCommandRunner
		runcBinary    *fakes.FakeRuncBinary
		logger        *lagertest.TestLogger

		runner *runrunc.OomWatcher
	)

	BeforeEach(func() {
		runcBinary = new(fakes.FakeRuncBinary)
		commandRunner = fake_command_runner.New()
		logger = lagertest.NewTestLogger("test")

		runner = runrunc.NewOomWatcher(commandRunner, runcBinary)

		runcBinary.EventsCommandStub = func(handle string) *exec.Cmd {
			return exec.Command("funC-events", "events", handle)
		}
	})
	"errors"
	"io/ioutil"
	"os"
	"os/exec"
	"path/filepath"

	"github.com/cloudfoundry-incubator/garden-linux/containerizer"

	"github.com/cloudfoundry/gunk/command_runner/fake_command_runner"
	. "github.com/cloudfoundry/gunk/command_runner/fake_command_runner/matchers"
	. "github.com/onsi/ginkgo"
	. "github.com/onsi/gomega"
)

var _ = Describe("ShellRunnerStep", func() {
	var runner *fake_command_runner.FakeCommandRunner

	BeforeEach(func() {
		runner = fake_command_runner.New()
	})

	Context("when a given path exists", func() {
		var path string

		BeforeEach(func() {
			tmpdir, err := ioutil.TempDir("", "")
			Expect(err).ToNot(HaveOccurred())

			path = filepath.Join(tmpdir, "whatever.sh")
			Expect(ioutil.WriteFile(path, []byte(""), 0700)).To(Succeed())
		})
import (
	"errors"
	"fmt"
	"os/exec"

	. "github.com/onsi/ginkgo"
	. "github.com/onsi/gomega"

	"github.com/cloudfoundry-incubator/garden/warden"
	"github.com/cloudfoundry-incubator/warden-linux/linux_backend/bandwidth_manager"
	"github.com/cloudfoundry/gunk/command_runner/fake_command_runner"
	. "github.com/cloudfoundry/gunk/command_runner/fake_command_runner/matchers"
)

var fakeRunner *fake_command_runner.FakeCommandRunner
var bandwidthManager *bandwidth_manager.ContainerBandwidthManager

var _ = Describe("setting rate limits", func() {
	BeforeEach(func() {
		fakeRunner = fake_command_runner.New()
		bandwidthManager = bandwidth_manager.New("/depot/some-id", "some-id", fakeRunner)
	})

	It("executes net_rate.sh with the appropriate environment", func() {
		limits := warden.BandwidthLimits{
			RateInBytesPerSecond:      128,
			BurstRateInBytesPerSecond: 256,
		}

		err := bandwidthManager.SetLimits(limits)
	"github.com/cloudfoundry-incubator/garden-linux/layercake/fake_cake"
	"github.com/cloudfoundry/gunk/command_runner/fake_command_runner"
	. "github.com/cloudfoundry/gunk/command_runner/fake_command_runner/matchers"
	. "github.com/onsi/ginkgo"
	. "github.com/onsi/gomega"
	"github.com/pivotal-golang/lager/lagertest"
)

var _ = Describe("BtrfsCleaningCake", func() {
	var (
		cleaner              *layercake.BtrfsCleaningCake
		runner               *fake_command_runner.FakeCommandRunner
		fakeCake             *fake_cake.FakeCake
		listSubvolumesOutput string
		layerId              = layercake.DockerImageID("the-layer")
		btrfsMountPoint      = "/absolute/btrfs_mount"

		listSubVolumeErr error
		graphDriverErr   error

		removedDirectories []string
	)

	BeforeEach(func() {
		graphDriverErr = nil
		listSubVolumeErr = nil
		removedDirectories = []string{}

		runner = fake_command_runner.New()
		fakeCake = new(fake_cake.FakeCake)
		cleaner = &layercake.BtrfsCleaningCake{
	"net"
	"os/exec"

	"github.com/cloudfoundry-incubator/garden"
	. "github.com/cloudfoundry-incubator/garden-linux/network/iptables"
	"github.com/cloudfoundry/gunk/command_runner/fake_command_runner"
	. "github.com/cloudfoundry/gunk/command_runner/fake_command_runner/matchers"
	"github.com/pivotal-golang/lager/lagertest"

	. "github.com/onsi/ginkgo"
	. "github.com/onsi/gomega"
)

var _ = Describe("Iptables", func() {
	Describe("Chain", func() {
		var fakeRunner *fake_command_runner.FakeCommandRunner
		var subject Chain
		var useKernelLogging bool

		JustBeforeEach(func() {
			fakeRunner = fake_command_runner.New()
			subject = NewLoggingChain("foo-bar-baz", useKernelLogging, fakeRunner, lagertest.NewTestLogger("test"))
		})

		Describe("Setup", func() {
			Context("when kernel logging is not enabled", func() {
				It("creates the log chain using iptables", func() {
					Expect(subject.Setup("logPrefix")).To(Succeed())
					Expect(fakeRunner).To(HaveExecutedSerially(
						fake_command_runner.CommandSpec{
							Path: "/sbin/iptables",
	"github.com/cloudfoundry-incubator/garden-linux/process_tracker"
	"github.com/cloudfoundry-incubator/garden-linux/process_tracker/fake_process_tracker"
	wfakes "github.com/cloudfoundry-incubator/garden/fakes"
	"github.com/cloudfoundry/gunk/command_runner/fake_command_runner"
	. "github.com/cloudfoundry/gunk/command_runner/fake_command_runner/matchers"
)

var _ = Describe("Linux containers", func() {
	var (
		fakeCgroups          *fake_cgroups_manager.FakeCgroupsManager
		fakeQuotaManager     *fake_quota_manager.FakeQuotaManager
		fakeBandwidthManager *fake_bandwidth_manager.FakeBandwidthManager
		fakeRunner           *fake_command_runner.FakeCommandRunner
		containerResources   *linux_backend.Resources
		container            *linux_container.LinuxContainer
		fakePortPool         *fake_port_pool.FakePortPool
		fakeProcessTracker   *fake_process_tracker.FakeProcessTracker
		fakeFilter           *networkFakes.FakeFilter
		fakeOomWatcher       *fake_watcher.FakeWatcher
		containerDir         string
		containerProps       map[string]string
		containerVersion     semver.Version
		fakeIPTablesManager  *fake_iptables_manager.FakeIPTablesManager
	)

	netOutRule1 := garden.NetOutRule{
		Protocol: garden.ProtocolUDP,
		Networks: []garden.IPRange{garden.IPRangeFromIP(net.ParseIP("1.2.3.4"))},
		Ports:    []garden.PortRange{{Start: 12, End: 24}},
		ICMPs:    &garden.ICMPControl{Type: 3, Code: garden.ICMPControlCode(12)},
		Log:      true,
	}
Exemple #12
0
				BeforeEach(func() {
					cake.PathReturns("", testError)
				})

				It("should return the error", func() {
					Expect(aufsCake.Create(namespacedChildID, parentID, "")).To(Equal(testError))
				})

				It("should not unmount the parent", func() {
					Expect(aufsCake.Create(namespacedChildID, parentID, "")).To(Equal(testError))
					Expect(cake.UnmountCallCount()).To(Equal(0))
				})
			})

			Context("when getting parent's path succeeds", func() {
				var succeedingRunner *fake_command_runner.FakeCommandRunner

				BeforeEach(func() {
					succeedingRunner = fake_command_runner.New()
					succeedingRunner.WhenRunning(fake_command_runner.CommandSpec{}, func(cmd *exec.Cmd) error {
						return nil
					})
				})

				It("should unmount the parentID", func() {
					aufsCake.Runner = succeedingRunner
					Expect(aufsCake.Create(namespacedChildID, parentID, "")).To(Succeed())
					Expect(cake.UnmountCallCount()).To(Equal(1))
					Expect(cake.UnmountArgsForCall(0)).To(Equal(parentID))
				})
	"errors"
	"fmt"
	"os"
	"os/exec"

	"code.cloudfoundry.org/guardian/kawasaki/iptables"
	"github.com/cloudfoundry/gunk/command_runner/fake_command_runner"
	. "github.com/cloudfoundry/gunk/command_runner/fake_command_runner/matchers"
	. "github.com/onsi/ginkgo"
	. "github.com/onsi/gomega"
)

var _ = Describe("Setup", func() {
	var (
		fakeRunner                 *fake_command_runner.FakeCommandRunner
		denyNetworks               []string
		destroyContainersOnStartup bool
		starter                    *iptables.Starter
	)

	BeforeEach(func() {
		fakeRunner = fake_command_runner.New()
		destroyContainersOnStartup = false
	})

	JustBeforeEach(func() {
		fakeLocksmith := NewFakeLocksmith()
		starter = iptables.NewStarter(
			iptables.New("/sbin/iptables", "/sbin/iptables-restore", fakeRunner, fakeLocksmith, "prefix-"),
			true,
			"the-nic-prefix",
			denyNetworks,
Exemple #14
0
	"github.com/cloudfoundry/gunk/command_runner/fake_command_runner"

	"os"

	"net"

	networkFakes "github.com/cloudfoundry-incubator/garden-linux/network/fakes"
	"github.com/cloudfoundry-incubator/garden-linux/process"
	. "github.com/cloudfoundry/gunk/command_runner/fake_command_runner/matchers"
	. "github.com/onsi/ginkgo"
	. "github.com/onsi/gomega"
)

var _ = Describe("Hooks", func() {
	var hooks hook.HookSet
	var fakeRunner *fake_command_runner.FakeCommandRunner
	var config process.Env
	var fakeNetworkConfigurer *networkFakes.FakeConfigurer

	BeforeEach(func() {
		hooks = make(hook.HookSet)
		fakeRunner = fake_command_runner.New()
		config = process.Env{
			"id":                      "someID",
			"network_cidr":            "1.2.3.4/8",
			"container_iface_mtu":     "5000",
			"network_container_ip":    "1.6.6.6",
			"network_host_ip":         "1.2.3.5",
			"network_host_iface":      "hostIfc",
			"network_container_iface": "containerIfc",
			"bridge_iface":            "bridgeName",
Exemple #15
0
	"path/filepath"

	"github.com/cloudfoundry-incubator/guardian/kawasaki"
	"github.com/cloudfoundry/gunk/command_runner/fake_command_runner"
	"github.com/pivotal-golang/lager"
	"github.com/pivotal-golang/lager/lagertest"

	. "github.com/cloudfoundry/gunk/command_runner/fake_command_runner/matchers"
	. "github.com/onsi/ginkgo"
	. "github.com/onsi/gomega"
)

var _ = Describe("NetnsMgr", func() {
	var (
		fakeRunner *fake_command_runner.FakeCommandRunner
		netnsDir   string
		mgr        kawasaki.NetnsMgr
		logger     lager.Logger
	)

	BeforeEach(func() {
		netnsDir = tmpDir()
		logger = lagertest.NewTestLogger("test")
	})

	JustBeforeEach(func() {
		fakeRunner = fake_command_runner.New()
		mgr = kawasaki.NewManager(fakeRunner, netnsDir)
	})

	AfterEach(func() {
		os.RemoveAll(netnsDir)
	"github.com/cloudfoundry/gunk/command_runner/fake_command_runner"
	specs "github.com/opencontainers/runtime-spec/specs-go"
	"github.com/st3v/glager"

	. "github.com/onsi/ginkgo"
	. "github.com/onsi/gomega"
	"github.com/onsi/gomega/gbytes"
)

var _ = Describe("ExternalImageManager", func() {
	var (
		fakeCommandRunner    *fake_command_runner.FakeCommandRunner
		logger               lager.Logger
		externalImageManager *imageplugin.ExternalImageManager
		baseImage            *url.URL
		idMappings           []specs.LinuxIDMapping
		defaultBaseImage     *url.URL
		fakeCmdRunnerStdout  string
		fakeCmdRunnerStderr  string
		fakeCmdRunnerErr     error
	)

	BeforeEach(func() {
		fakeCmdRunnerStdout = ""
		fakeCmdRunnerStderr = ""
		fakeCmdRunnerErr = nil

		logger = glager.NewLogger("external-image-manager")
		fakeCommandRunner = fake_command_runner.New()

		idMappings = []specs.LinuxIDMapping{
	"errors"
	"fmt"
	"os/exec"

	. "github.com/onsi/ginkgo"
	. "github.com/onsi/gomega"
	"github.com/pivotal-golang/lager/lagertest"

	"github.com/cloudfoundry-incubator/garden"
	"github.com/cloudfoundry-incubator/garden-linux/linux_container/quota_manager"
	"github.com/cloudfoundry/gunk/command_runner/fake_command_runner"
	. "github.com/cloudfoundry/gunk/command_runner/fake_command_runner/matchers"
)

var _ = Describe("btrfs quota manager", func() {
	var fakeRunner *fake_command_runner.FakeCommandRunner
	var logger *lagertest.TestLogger
	var quotaManager *quota_manager.BtrfsQuotaManager
	var subvolumePath string
	var qgroupShowResponse []byte
	var qgroupShowError error

	BeforeEach(func() {
		fakeRunner = fake_command_runner.New()
		logger = lagertest.NewTestLogger("test")
		quotaManager = &quota_manager.BtrfsQuotaManager{
			Runner:     fakeRunner,
			MountPoint: "/the/mount/point",
		}

		subvolumePath = "/some/volume/path"
Exemple #18
0
	"github.com/cloudfoundry-incubator/garden-linux/linux_container/iptables_manager"
	"github.com/cloudfoundry-incubator/garden-linux/sysconfig"
	. "github.com/cloudfoundry/gunk/command_runner/fake_command_runner/matchers"
	. "github.com/onsi/ginkgo"
	. "github.com/onsi/ginkgo/extensions/table"
	. "github.com/onsi/gomega"
	"github.com/pivotal-golang/lager/lagertest"
)

var _ = Describe("natChain", func() {
	var (
		fakeRunner  *fake_command_runner.FakeCommandRunner
		testCfg     *sysconfig.IPTablesNATConfig
		chain       iptables_manager.Chain
		containerID string
		bridgeName  string
		ip          net.IP
		network     *net.IPNet
	)

	BeforeEach(func() {
		var err error

		fakeRunner = fake_command_runner.New()
		testCfg = &sysconfig.IPTablesNATConfig{
			PreroutingChain:  "nat-prerouting-chain",
			PostroutingChain: "nat-postrouting-chain",
			InstancePrefix:   "nat-instance-prefix",
		}
Exemple #19
0
package fake_command_runner_test

import (
	"github.com/cloudfoundry/gunk/command_runner/fake_command_runner"

	"os/exec"

	. "github.com/onsi/ginkgo"
	. "github.com/onsi/gomega"
)

var _ = Describe("FakeCommandRunner", func() {

	var (
		runner    *fake_command_runner.FakeCommandRunner
		cmd, cmd2 *exec.Cmd
	)

	BeforeEach(func() {
		runner = fake_command_runner.New()
		cmd = &exec.Cmd{}
		cmd2 = &exec.Cmd{}
	})

	Describe("Kill", func() {
		It("should record Kill commands", func() {
			runner.Kill(cmd)
			Expect(runner.KilledCommands()).To(Equal([]*exec.Cmd{cmd}))
		})

		// This may seem like an odd test, but it exposed a bug.
import (
	"io/ioutil"
	"os"
	"os/exec"
	"syscall"

	"github.com/cloudfoundry-incubator/garden-linux/containerizer/system"
	"github.com/cloudfoundry/gunk/command_runner/fake_command_runner"
	. "github.com/cloudfoundry/gunk/command_runner/fake_command_runner/matchers"
	. "github.com/onsi/ginkgo"
	. "github.com/onsi/gomega"
)

var _ = Describe("Execer", func() {
	var execer *system.NamespacingExecer
	var commandRunner *fake_command_runner.FakeCommandRunner

	BeforeEach(func() {
		commandRunner = fake_command_runner.New()
		process := &os.Process{
			Pid: 12,
		}

		commandRunner.WhenRunning(fake_command_runner.CommandSpec{}, func(cmd *exec.Cmd) error {
			cmd.Process = process
			return nil
		})

		execer = &system.NamespacingExecer{
			CommandRunner: commandRunner,
		}
	. "github.com/onsi/gomega"

	"github.com/cloudfoundry-incubator/garden/warden"
	"github.com/cloudfoundry-incubator/warden-linux/linux_backend"
	"github.com/cloudfoundry-incubator/warden-linux/linux_backend/container_pool"
	"github.com/cloudfoundry-incubator/warden-linux/linux_backend/network"
	"github.com/cloudfoundry-incubator/warden-linux/linux_backend/network_pool/fake_network_pool"
	"github.com/cloudfoundry-incubator/warden-linux/linux_backend/port_pool/fake_port_pool"
	"github.com/cloudfoundry-incubator/warden-linux/linux_backend/quota_manager/fake_quota_manager"
	"github.com/cloudfoundry-incubator/warden-linux/linux_backend/uid_pool/fake_uid_pool"
	"github.com/cloudfoundry/gunk/command_runner/fake_command_runner"
	. "github.com/cloudfoundry/gunk/command_runner/fake_command_runner/matchers"
)

var _ = Describe("Container pool", func() {
	var fakeRunner *fake_command_runner.FakeCommandRunner
	var fakeUIDPool *fake_uid_pool.FakeUIDPool
	var fakeNetworkPool *fake_network_pool.FakeNetworkPool
	var fakeQuotaManager *fake_quota_manager.FakeQuotaManager
	var fakePortPool *fake_port_pool.FakePortPool
	var pool *container_pool.LinuxContainerPool

	BeforeEach(func() {
		_, ipNet, err := net.ParseCIDR("1.2.0.0/20")
		Expect(err).ToNot(HaveOccurred())

		fakeUIDPool = fake_uid_pool.New(10000)

		fakeNetworkPool = fake_network_pool.New(ipNet)
		fakeRunner = fake_command_runner.New()
		fakeQuotaManager = fake_quota_manager.New()
Exemple #22
0
	"code.cloudfoundry.org/guardian/rundmc/runrunc"
	fakes "code.cloudfoundry.org/guardian/rundmc/runrunc/runruncfakes"
	"code.cloudfoundry.org/lager"
	"code.cloudfoundry.org/lager/lagertest"
	"github.com/cloudfoundry/gunk/command_runner/fake_command_runner"
	. "github.com/cloudfoundry/gunk/command_runner/fake_command_runner/matchers"
	. "github.com/onsi/ginkgo"
	. "github.com/onsi/gomega"
)

var _ = Describe("Kill", func() {
	var (
		commandRunner *fake_command_runner.FakeCommandRunner
		runner        *fakes.FakeRuncCmdRunner
		runcBinary    *fakes.FakeRuncBinary
		logger        *lagertest.TestLogger

		killer *runrunc.Killer
	)

	BeforeEach(func() {
		runcBinary = new(fakes.FakeRuncBinary)
		commandRunner = fake_command_runner.New()
		runner = new(fakes.FakeRuncCmdRunner)
		logger = lagertest.NewTestLogger("test")

		killer = runrunc.NewKiller(runner, runcBinary)

		runcBinary.KillCommandStub = func(id, signal, logFile string) *exec.Cmd {
			return exec.Command("funC", "--log", logFile, "kill", id, signal)
		}
Exemple #23
0
	"code.cloudfoundry.org/garden"
	"code.cloudfoundry.org/guardian/rundmc/runrunc"
	"code.cloudfoundry.org/lager"
	"code.cloudfoundry.org/lager/lagertest"
	"github.com/cloudfoundry/gunk/command_runner/fake_command_runner"
	. "github.com/onsi/ginkgo"
	. "github.com/onsi/gomega"
)

var _ = Describe("Create", func() {
	var (
		commandRunner  *fake_command_runner.FakeCommandRunner
		bundlePath     string
		logFilePath    string
		pidFilePath    string
		logger         *lagertest.TestLogger
		logs           string
		runcExitStatus error

		runner *runrunc.Creator
	)

	BeforeEach(func() {
		logs = ""
		runcExitStatus = nil
		commandRunner = fake_command_runner.New()
		logger = lagertest.NewTestLogger("test")

		var err error
		bundlePath, err = ioutil.TempDir("", "bundle")
		Expect(err).NotTo(HaveOccurred())
	"github.com/cloudfoundry-incubator/garden-linux/linux_container"
	"github.com/cloudfoundry-incubator/garden-linux/linux_container/cgroups_manager/fake_cgroups_manager"
	"github.com/cloudfoundry/gunk/command_runner/fake_command_runner"
	. "github.com/cloudfoundry/gunk/command_runner/fake_command_runner/matchers"

	. "github.com/onsi/ginkgo"
	. "github.com/onsi/gomega"
	"github.com/onsi/gomega/gbytes"
)

var _ = Describe("OomNotifier", func() {
	var (
		runner         *fake_command_runner.FakeCommandRunner
		cgroupsPath    string
		cgroupsManager linux_container.CgroupsManager
		oNoom          func()
		oomChan        chan struct{}
		containerPath  string
		oomNotifier    *linux_container.OomNotifier
	)

	BeforeEach(func() {
		runner = fake_command_runner.New()

		cgroupsPath = path.Join("path", "to", "cgroups")
		cgroupsManager = fake_cgroups_manager.New(cgroupsPath, "123456")

		containerPath = path.Join("path", "to", "container")

		oomChan = make(chan struct{})
		oNoom = func() {
	"errors"
	"fmt"
	"os/exec"
	"path"
	"time"

	. "github.com/onsi/ginkgo"
	. "github.com/onsi/gomega"

	"github.com/cloudfoundry-incubator/garden/warden"
	"github.com/cloudfoundry-incubator/warden-linux/linux_backend/process_tracker"
	"github.com/cloudfoundry/gunk/command_runner/fake_command_runner"
	. "github.com/cloudfoundry/gunk/command_runner/fake_command_runner/matchers"
)

var fakeRunner *fake_command_runner.FakeCommandRunner
var processTracker *process_tracker.ProcessTracker

func binPath(bin string) string {
	return path.Join("/depot/some-id", "bin", bin)
}

func setupSuccessfulSpawn() {
	fakeRunner.WhenRunning(
		fake_command_runner.CommandSpec{
			Path: binPath("iomux-spawn"),
		},
		func(cmd *exec.Cmd) error {
			cmd.Stdout.Write([]byte("ready\n"))
			cmd.Stdout.Write([]byte("active\n"))
			return nil
import (
	"errors"
	"os/exec"

	. "github.com/onsi/ginkgo"
	. "github.com/onsi/gomega"

	"github.com/cloudfoundry-incubator/garden/warden"
	"github.com/cloudfoundry-incubator/warden-linux/linux_backend/quota_manager"
	"github.com/cloudfoundry/gunk/command_runner/fake_command_runner"
	. "github.com/cloudfoundry/gunk/command_runner/fake_command_runner/matchers"
)

var _ = Describe("Linux Quota Manager initialization", func() {
	var fakeRunner *fake_command_runner.FakeCommandRunner

	BeforeEach(func() {
		fakeRunner = fake_command_runner.New()
	})

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

		BeforeEach(func() {
			fakeRunner.WhenRunning(fake_command_runner.CommandSpec{
				Path: "df",
			}, func(*exec.Cmd) error {
				return disaster
			})
		})
				low := 10
				actual := 3000
				tolerance := 5

				tester := NewFakeBinarySearchTester(actual)
				Expect(BinarySearch(tester, low, high, tolerance)).To(BeNumerically("~", high, tolerance))

			})
		})

	})

	Describe("AppSizeBinarySearchTester", func() {

		appPath := "app-path"
		var runner *fake_command_runner.FakeCommandRunner

		BeforeEach(func() {
			runner = fake_command_runner.New()

		})

		It("returns true when it can successfully push an app", func() {

			tester := NewAppSizeBinarySearchTester(runner, appPath)

			Expect(tester.Test(100)).To(BeTrue())
		})

		It("returns false when it can't push an app", func() {
			pushCommand := fake_command_runner.CommandSpec{Path: "gcf"}
Exemple #28
0
	"os"
	"os/exec"
	"path"

	"github.com/cloudfoundry-incubator/guardian/rundmc"
	"github.com/cloudfoundry/gunk/command_runner/fake_command_runner"
	. "github.com/cloudfoundry/gunk/command_runner/fake_command_runner/matchers"
	. "github.com/onsi/ginkgo"
	. "github.com/onsi/gomega"
)

var _ = Describe("CgroupStarter", func() {
	var (
		runner      *fake_command_runner.FakeCommandRunner
		starter     *rundmc.CgroupStarter
		procCgroups *FakeReadCloser

		tmpDir string
	)

	BeforeEach(func() {
		var err error
		tmpDir, err = ioutil.TempDir("", "gdncgroup")
		Expect(err).NotTo(HaveOccurred())

		runner = fake_command_runner.New()
		procCgroups = &FakeReadCloser{Buffer: bytes.NewBufferString("")}
		starter = &rundmc.CgroupStarter{
			CgroupPath:    path.Join(tmpDir, "cgroup"),
			CommandRunner: runner,
			ProcCgroups:   procCgroups,
Exemple #29
0
	"code.cloudfoundry.org/lager"
	"code.cloudfoundry.org/lager/lagertest"
	. "github.com/onsi/ginkgo"
	. "github.com/onsi/gomega"

	"github.com/cloudfoundry/gunk/command_runner/fake_command_runner"
	. "github.com/cloudfoundry/gunk/command_runner/fake_command_runner/matchers"
)

var _ = Describe("State", func() {
	var (
		commandRunner *fake_command_runner.FakeCommandRunner
		runner        *fakes.FakeRuncCmdRunner
		runcBinary    *fakes.FakeRuncBinary
		logger        *lagertest.TestLogger

		stateCmdOutput string
		stateCmdExit   error

		stater *runrunc.Stater
	)

	BeforeEach(func() {
		runner = new(fakes.FakeRuncCmdRunner)
		runcBinary = new(fakes.FakeRuncBinary)
		commandRunner = fake_command_runner.New()
		logger = lagertest.NewTestLogger("test")

		stater = runrunc.NewStater(runner, runcBinary)

		runcBinary.StateCommandStub = func(id, logFile string) *exec.Cmd {