Пример #1
0
func TestServiceLinkBadChainWithoutChainInDefinition(t *testing.T) {
	defer tests.RemoveAllContainers()

	if err := tests.FakeServiceDefinition(erisDir, "fake", `
[service]
name = "fake"
image = "quay.io/eris/ipfs"
`); err != nil {
		t.Fatalf("can't create a fake service definition: %v", err)
	}

	do := def.NowDo()
	do.Operations.Args = []string{"fake"}
	do.Operations.ContainerNumber = 1
	do.ChainName = "non-existent-chain"

	// [pv]: is this a bug? the service which doesn't have a
	// "chain" in its definition file doesn't care about linking at all.
	if err := services.StartService(do); err != nil {
		t.Fatalf("expect service to start, got %v", err)
	}

	if n := util.HowManyContainersRunning("fake", def.TypeService); n != 1 {
		t.Fatalf("expecting 1 service containers, got %v", n)
	}
	if n := util.HowManyContainersExisting("fake", def.TypeData); n != 0 {
		t.Fatalf("expecting 0 data containers, got %v", n)
	}
}
Пример #2
0
func TestServiceLinkKeys(t *testing.T) {
	defer tests.RemoveAllContainers()

	do := def.NowDo()
	do.Name = chainName
	do.Operations.ContainerNumber = 1
	if err := NewChain(do); err != nil {
		t.Fatalf("could not start a new chain, got %v", err)
	}

	if n := util.HowManyContainersExisting(chainName, def.TypeChain); n != 1 {
		t.Fatalf("expecting 1 test chain containers, got %v", n)
	}

	do = def.NowDo()
	do.Operations.Args = []string{"keys"}
	do.Operations.ContainerNumber = 1
	do.ChainName = chainName
	if err := services.StartService(do); err != nil {
		t.Fatalf("expecting service to start, got %v", err)
	}

	if n := util.HowManyContainersExisting("keys", def.TypeService); n != 1 {
		t.Fatalf("expecting 1 test chain containers, got %v", n)
	}

	links := tests.Links("keys", def.TypeService, 1)
	if len(links) != 0 {
		t.Fatalf("expected service links be empty, got %v", links)
	}
}
Пример #3
0
func StartServicesAndChains(do *definitions.Do) error {
	// start the services and chains
	doSrvs := definitions.NowDo()
	if do.Action.Dependencies == nil || len(do.Action.Dependencies.Services) == 0 {
		log.Debug("No services to start")
	} else {
		doSrvs.Operations.Args = do.Action.Dependencies.Services
		log.WithField("args", doSrvs.Operations.Args).Debug("Starting services")
		if err := services.StartService(doSrvs); err != nil {
			return err
		}
	}

	doChns := definitions.NowDo()
	doChns.Name = do.Action.Chain
	if doChns.Name == "" {
		log.Debug("No chain to start")
	} else {
		log.WithField("=>", doChns.Name).Debug("Starting chain")
		if err := chains.StartChain(do); err != nil {
			return err
		}
	}

	return nil
}
Пример #4
0
func StartServicesAndChains(do *definitions.Do) error {
	// start the services and chains
	doSrvs := definitions.NowDo()
	doSrvs.Args = do.Action.ServiceDeps
	if len(doSrvs.Args) == 0 {
		logger.Debugf("No services to start.\n")
	} else {
		logger.Debugf("Starting Services. Args =>\t%v\n", doSrvs.Args)
		if err := services.StartService(doSrvs); err != nil {
			return err
		}
	}

	doChns := definitions.NowDo()
	doChns.Name = do.Action.Chain
	if doChns.Name == "" {
		logger.Debugf("No chain to start.\n")
	} else {
		logger.Debugf("Starting Chain. Name =>\t\t%v\n", doChns.Name)
		if err := chains.StartChain(do); err != nil {
			return err
		}
	}

	return nil
}
Пример #5
0
func TestServiceLinkWithDataContainer(t *testing.T) {
	defer tests.RemoveAllContainers()

	do := def.NowDo()
	do.Name = chainName
	do.Operations.ContainerNumber = 1
	if err := NewChain(do); err != nil {
		t.Fatalf("could not start a new chain, got %v", err)
	}

	if err := tests.FakeServiceDefinition(erisDir, "fake", `
chain = "$chain:fake"

[service]
name = "fake"
image = "quay.io/eris/ipfs"
data_container = true
`); err != nil {
		t.Fatalf("can't create a fake service definition: %v", err)
	}

	if n := util.HowManyContainersExisting(chainName, def.TypeChain); n != 1 {
		t.Fatalf("expecting 1 test chain containers, got %v", n)
	}

	if n := util.HowManyContainersExisting("fake", def.TypeService); n != 0 {
		t.Fatalf("expecting 0 service containers, got %v", n)
	}
	if n := util.HowManyContainersExisting("fake", def.TypeData); n != 0 {
		t.Fatalf("expecting 0 data containers, got %v", n)
	}

	do = def.NowDo()
	do.Operations.Args = []string{"fake"}
	do.Operations.ContainerNumber = 1
	do.ChainName = chainName
	if err := services.StartService(do); err != nil {
		t.Fatalf("expecting service to start, got %v", err)
	}

	if n := util.HowManyContainersRunning("fake", def.TypeService); n != 1 {
		t.Fatalf("expecting 1 service containers, got %v", n)
	}
	if n := util.HowManyContainersExisting("fake", def.TypeData); n != 1 {
		t.Fatalf("expecting 1 data containers, got %v", n)
	}

	links := tests.Links("fake", def.TypeService, 1)
	if len(links) != 1 || !strings.Contains(links[0], chainName) {
		t.Fatalf("expected service be linked to a test chain, got %v", links)
	}
}
Пример #6
0
func testStartKeys(t *testing.T) {
	serviceName := "keys"
	do := def.NowDo()
	do.Operations.Args = []string{serviceName}
	do.Operations.ContainerNumber = 1
	log.WithField("=>", fmt.Sprintf("%s:%d", serviceName, do.Operations.ContainerNumber)).Debug("Starting service (via tests)")
	e := srv.StartService(do)
	if e != nil {
		log.Infof("Error starting service: %v", e)
		t.Fail()
	}

	testExistAndRun(t, serviceName, 1, true, true)
	testNumbersExistAndRun(t, serviceName, 1, 1)
}
Пример #7
0
func testStartKeys(t *testing.T) {
	serviceName := "keys"
	do := def.NowDo()
	do.Operations.Args = []string{serviceName}
	do.Operations.ContainerNumber = 1
	logger.Debugf("Starting service (via tests) =>\t%s:%d\n", serviceName, do.Operations.ContainerNumber)
	e := srv.StartService(do)
	if e != nil {
		logger.Infof("Error starting service =>\t%v\n", e)
		t.Fail()
	}

	testExistAndRun(t, serviceName, 1, true, true)
	testNumbersExistAndRun(t, serviceName, 1, 1)
}
Пример #8
0
//from /services/services_test.go
func testStartService(t *testing.T, serviceName string, publishAll bool) {
	do := def.NowDo()
	do.Operations.Args = []string{serviceName}
	do.Operations.ContainerNumber = 1 //util.AutoMagic(0, "service", true)
	do.Operations.PublishAllPorts = publishAll
	logger.Debugf("Starting service (via tests) =>\t%s:%d\n", serviceName, do.Operations.ContainerNumber)
	e := srv.StartService(do)
	if e != nil {
		logger.Infof("Error starting service =>\t%v\n", e)
		fatal(t, e)
	}

	testExistAndRun(t, serviceName, 1, true, true)
	testNumbersExistAndRun(t, serviceName, 1, 1)
}
Пример #9
0
//from /services/services_test.go
func testStartService(t *testing.T, serviceName string, publishAll bool) {
	do := def.NowDo()
	do.Operations.Args = []string{serviceName}
	do.Operations.ContainerNumber = 1 //util.AutoMagic(0, "service", true)
	do.Operations.PublishAllPorts = publishAll
	log.WithField("=>", fmt.Sprintf("%s:%d", serviceName, do.Operations.ContainerNumber)).Debug("Starting service (from tests)")
	e := srv.StartService(do)
	if e != nil {
		log.Infof("Error starting service: %v", e)
		fatal(t, e)
	}

	testExistAndRun(t, serviceName, 1, true, true)
	testNumbersExistAndRun(t, serviceName, 1, 1)
}
Пример #10
0
func testsInit() error {
	if err := tests.TestsInit("files"); err != nil {
		return err
	}

	f, err := os.Create(file)
	tests.IfExit(err)
	f.Write([]byte(content))

	do1 := definitions.NowDo()
	do1.Operations.Args = []string{"ipfs"}
	err = services.StartService(do1)
	tests.IfExit(err)
	time.Sleep(5 * time.Second) // boot time

	return nil
}
Пример #11
0
func TestServiceLinkBadChain(t *testing.T) {
	defer tests.RemoveAllContainers()

	if err := tests.FakeServiceDefinition(erisDir, "fake", `
chain = "$chain:fake"

[service]
name = "fake"
image = "quay.io/eris/ipfs"
`); err != nil {
		t.Fatalf("can't create a fake service definition: %v", err)
	}

	do := def.NowDo()
	do.Operations.Args = []string{"fake"}
	do.Operations.ContainerNumber = 1
	do.ChainName = "non-existent-chain"
	if err := services.StartService(do); err == nil {
		t.Fatalf("expect start service to fail, got nil")
	}
}
Пример #12
0
func TestServiceLinkNoChain(t *testing.T) {
	defer tests.RemoveAllContainers()

	if err := tests.FakeServiceDefinition(erisDir, "fake", `
chain = "$chain:fake"

[service]
name = "fake"
image = "`+path.Join(ver.ERIS_REG_DEF, ver.ERIS_IMG_IPFS)+`"
data_container = true
`); err != nil {
		t.Fatalf("can't create a fake service definition: %v", err)
	}

	do := def.NowDo()
	do.Operations.Args = []string{"fake"}
	do.Operations.ContainerNumber = 1
	if err := services.StartService(do); err == nil {
		t.Fatalf("expect start service to fail, got nil")
	}
}
Пример #13
0
func TestServiceLinkBadLiteral(t *testing.T) {
	defer tests.RemoveAllContainers()

	do := def.NowDo()
	do.Name = chainName
	do.Operations.ContainerNumber = 1
	if err := NewChain(do); err != nil {
		t.Fatalf("could not start a new chain, got %v", err)
	}

	if err := tests.FakeServiceDefinition(erisDir, "fake", `
chain = "blah-blah:blah"

[service]
name = "fake"
image = "quay.io/eris/ipfs"
`); err != nil {
		t.Fatalf("can't create a fake service definition: %v", err)
	}

	if n := util.HowManyContainersExisting(chainName, def.TypeChain); n != 1 {
		t.Fatalf("expecting 1 test chain containers, got %v", n)
	}

	do = def.NowDo()
	do.Operations.Args = []string{"fake"}
	do.Operations.ContainerNumber = 1
	do.ChainName = chainName
	// [pv]: probably a bug. Bad literal chain link in a definition
	// file doesn't affect the service start. Links is not nil.
	if err := services.StartService(do); err != nil {
		t.Fatalf("expecting service to start, got %v", err)
	}

	links := tests.Links("fake", def.TypeService, 1)
	if len(links) != 1 || !strings.Contains(links[0], chainName) {
		t.Fatalf("expected service be linked to a test chain, got %v", links)
	}
}
Пример #14
0
func bootChain(name string, do *definitions.Do) error {
	do.Chain.ChainType = "service" // setting this for tear down purposes
	startChain := definitions.NowDo()
	startChain.Name = name
	startChain.Operations = do.Operations
	err := chains.StartChain(startChain)
	// errors *could* be because the chain was actually a service.
	if err != nil {
		if util.IsServiceContainer(name, do.Operations.ContainerNumber, true) {
			startService := definitions.NowDo()
			startService.Operations = do.Operations
			startService.Operations.Args = []string{name}
			err = services.StartService(startService)
			if err != nil {
				return err
			}
		}
	} else {
		do.Chain.ChainType = "chain" // setting this for tear down purposes
	}
	do.Chain.Name = name // setting this for tear down purposes
	return nil
}
Пример #15
0
func testsInit() error {
	var err error
	// TODO: make a reader/pipe so we can see what is written from tests.
	config.GlobalConfig, err = config.SetGlobalObject(os.Stdout, os.Stderr)
	ifExit(err)

	// common is initialized on import so
	// we have to manually override these
	// variables to ensure that the tests
	// run correctly.
	config.ChangeErisDir(erisDir)

	// init dockerClient
	util.DockerConnect(false, "eris")

	// this dumps the ipfs service def into the temp dir which
	// has been set as the erisRoot
	do := definitions.NowDo()
	do.Pull = true
	do.Services = true
	do.Actions = true
	ifExit(ini.Initialize(do))

	// dump a test file with some stuff
	f, err := os.Create(file)
	ifExit(err)
	f.Write([]byte(content))

	do1 := definitions.NowDo()
	do1.Args = []string{"ipfs"}
	err = services.StartService(do1)
	ifExit(err)
	time.Sleep(5 * time.Second)

	return nil
}
Пример #16
0
func StartService(cmd *cobra.Command, args []string) {
	IfExit(ArgCheck(1, "ge", cmd, args))
	do.Args = args
	IfExit(srv.StartService(do))
}
Пример #17
0
func TestServiceLinkChainedService(t *testing.T) {
	defer tests.RemoveAllContainers()

	do := def.NowDo()
	do.Name = chainName
	do.Operations.ContainerNumber = 1
	if err := NewChain(do); err != nil {
		t.Fatalf("could not start a new chain, got %v", err)
	}

	if err := tests.FakeServiceDefinition(erisDir, "fake", `
chain = "$chain:fake"

[service]
name = "fake"
image = "quay.io/eris/ipfs"

[dependencies]
services = [ "sham" ]
`); err != nil {
		t.Fatalf("can't create a fake service definition: %v", err)
	}

	if err := tests.FakeServiceDefinition(erisDir, "sham", `
chain = "$chain:sham"

[service]
name = "sham"
image = "quay.io/eris/keys"
data_container = true
`); err != nil {
		t.Fatalf("can't create a sham service definition: %v", err)
	}

	if n := util.HowManyContainersExisting(chainName, def.TypeChain); n != 1 {
		t.Fatalf("expecting 1 test chain containers, got %v", n)
	}

	do = def.NowDo()
	do.Operations.Args = []string{"fake"}
	do.Operations.ContainerNumber = 1
	do.ChainName = chainName
	if err := services.StartService(do); err != nil {
		t.Fatalf("expecting service to start, got %v", err)
	}

	if n := util.HowManyContainersRunning("fake", def.TypeService); n != 1 {
		t.Fatalf("expecting 1 fake service containers, got %v", n)
	}
	if n := util.HowManyContainersExisting("fake", def.TypeData); n != 0 {
		t.Fatalf("expecting 0 fake data containers, got %v", n)
	}
	if n := util.HowManyContainersRunning("sham", def.TypeService); n != 1 {
		t.Fatalf("expecting 1 sham service containers, got %v", n)
	}
	if n := util.HowManyContainersExisting("sham", def.TypeData); n != 1 {
		t.Fatalf("expecting 1 sham data containers, got %v", n)
	}

	// [pv]: second service doesn't reference the chain.
	links := tests.Links("fake", def.TypeService, 1)
	if len(links) != 2 || (!strings.Contains(links[1], chainName) && !strings.Contains(links[0], chainName)) {
		t.Fatalf("expected service be linked to a test chain, got %v", links)
	}
}