Ejemplo n.º 1
0
func RegisterHooks(hs hook.HookSet, runner Runner, config process.Env, configurer network.Configurer) {
	hs.Register(hook.PARENT_BEFORE_CLONE, func() {
		must(runner.Run(exec.Command("./hook-parent-before-clone.sh")))
	})

	hs.Register(hook.PARENT_AFTER_CLONE, func() {
		must(runner.Run(exec.Command("./hook-parent-after-clone.sh")))
		must(configureHostNetwork(config, configurer))
	})
}
Ejemplo n.º 2
0
	"github.com/cloudfoundry-incubator/garden-linux/linux_backend"
	"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",
Ejemplo n.º 3
0
package hook_test

import (
	"github.com/cloudfoundry-incubator/garden-linux/hook"

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

var _ = Describe("HookSet", func() {
	var registry hook.HookSet

	BeforeEach(func() {
		registry = make(hook.HookSet)
	})

	Context("when the first argument names a registered hook", func() {
		It("runs the hook", func() {
			wasRun := false
			registry.Register("a-hook", func() {
				wasRun = true
			})

			registry.Main("a-hook")
			Expect(wasRun).To(BeTrue())
		})
	})

	Context("when the first argument does not name a registered hook", func() {
		It("panics", func() {
			Expect(func() { registry.Main("does-not-hook") }).To(Panic())