Ejemplo n.º 1
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
}
Ejemplo n.º 2
0
func TestNewService(t *testing.T) {
	defer tests.RemoveAllContainers()

	do := def.NowDo()
	servName := "keys"
	do.Name = servName
	do.Operations.Args = []string{path.Join(ver.ERIS_REG_DEF, ver.ERIS_IMG_KEYS)}
	if err := NewService(do); err != nil {
		t.Fatalf("expected a new service to be created, got %v", err)
	}

	do = def.NowDo()
	do.Operations.Args = []string{servName}
	if err := StartService(do); err != nil {
		t.Fatalf("expected service to be started, got %v", err)
	}

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

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

}
Ejemplo n.º 3
0
func TestInspectService(t *testing.T) {
	testStartService(t, servName, false)
	defer testKillService(t, servName, true)

	do := def.NowDo()
	do.Name = servName
	do.Operations.Args = []string{"name"}
	do.Operations.ContainerNumber = 1
	log.WithFields(log.Fields{
		"=>":   fmt.Sprintf("%s:%d", servName, do.Operations.ContainerNumber),
		"args": do.Operations.Args,
	}).Debug("Inspect service (from tests)")

	e := InspectService(do)
	if e != nil {
		log.Infof("Error inspecting service: %v", e)
		tests.IfExit(e)
	}

	do = def.NowDo()
	do.Name = servName
	do.Operations.Args = []string{"config.user"}
	do.Operations.ContainerNumber = 1
	log.WithFields(log.Fields{
		"=>":   servName,
		"args": do.Operations.Args,
	}).Debug("Inspect service (from tests)")
	e = InspectService(do)
	if e != nil {
		log.Infof("Error inspecting service: %v", e)
		tests.IfExit(e)
	}
}
Ejemplo n.º 4
0
func TestKillRmService(t *testing.T) {
	testStartService(t, servName, false)
	do := def.NowDo()
	do.Name = servName
	do.Rm = false
	do.RmD = false
	do.Operations.Args = []string{servName}
	log.WithField("=>", servName).Debug("Stopping service (from tests)")
	if e := KillService(do); e != nil {
		log.Error(e)
		tests.IfExit(e)
	}

	testExistAndRun(t, servName, 1, true, false)
	testNumbersExistAndRun(t, servName, 1, 0)

	if os.Getenv("TEST_IN_CIRCLE") == "true" {
		log.Warn("Testing in Circle where we don't have rm privileges. Skipping test")
		return
	}

	do = def.NowDo()
	do.Name = servName
	do.Operations.Args = []string{servName}
	do.File = false
	do.RmD = true
	log.WithField("=>", servName).Debug("Removing service (from tests)")
	if e := RmService(do); e != nil {
		log.Error(e)
		tests.IfExit(e)
	}

	testExistAndRun(t, servName, 1, false, false)
	testNumbersExistAndRun(t, servName, 0, 0)
}
Ejemplo n.º 5
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
}
Ejemplo n.º 6
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)
	}
}
Ejemplo n.º 7
0
func TestRenameChain(t *testing.T) {
	aChain := "hichain"
	rename1 := "niahctset"
	rename2 := chainName
	testNewChain(aChain)
	defer testKillChain(t, rename2)

	do := def.NowDo()
	do.Name = aChain
	do.NewName = rename1
	log.WithFields(log.Fields{
		"from": do.Name,
		"to":   do.NewName,
	}).Info("Renaming chain (from tests)")

	if e := RenameChain(do); e != nil {
		tests.IfExit(e)
	}

	testExistAndRun(t, rename1, true, true)

	do = def.NowDo()
	do.Name = rename1
	do.NewName = rename2
	log.WithFields(log.Fields{
		"from": do.Name,
		"to":   do.NewName,
	}).Info("Renaming chain (from tests)")
	if e := RenameChain(do); e != nil {
		tests.IfExit(e)
	}

	testExistAndRun(t, chainName, true, true)
}
Ejemplo n.º 8
0
func TestGetPubKey(t *testing.T) {
	testStartKeys(t)
	defer testKillService(t, "keys", true)

	doPub := def.NowDo()
	doPub.Address = testsGenAKey()

	pub := new(bytes.Buffer)
	config.GlobalConfig.Writer = pub
	if err := GetPubKey(doPub); err != nil {
		fatal(t, err)
	}

	pubBytes := pub.Bytes()
	pubkey := trimString(string(pubBytes))

	key := new(bytes.Buffer)
	config.GlobalConfig.Writer = key
	doKey := def.NowDo()
	doKey.Address = doPub.Address
	if err := ConvertKey(doKey); err != nil {
		fatal(t, err)
	}

	converted := regexp.MustCompile(`"pub_key":\[1,"([^"]+)"\]`).FindStringSubmatch(key.String())[1]

	if converted != pubkey {
		fatal(t, fmt.Errorf("Expected (%s), got (%s)\n", pubkey, converted))
	}
}
Ejemplo n.º 9
0
func TestRenameChain(t *testing.T) {
	aChain := "hichain"
	rename1 := "niahctset"
	rename2 := chainName
	testNewChain(aChain)
	defer testKillChain(t, rename2)

	do := def.NowDo()
	do.Name = aChain
	do.NewName = rename1
	logger.Infof("Renaming chain (from tests) =>\t%s:%s\n", do.Name, do.NewName)

	if e := RenameChain(do); e != nil {
		tests.IfExit(e)
	}

	testExistAndRun(t, rename1, true, true)

	do = def.NowDo()
	do.Name = rename1
	do.NewName = rename2
	logger.Infof("Renaming chain (from tests) =>\t%s:%s\n", do.Name, do.NewName)
	if e := RenameChain(do); e != nil {
		tests.IfExit(e)
	}

	testExistAndRun(t, chainName, true, true)
}
Ejemplo n.º 10
0
func TestInspectData(t *testing.T) {
	testCreateDataByImport(t, dataName)
	defer testKillDataCont(t, dataName)

	do := definitions.NowDo()
	do.Name = dataName
	do.Operations.Args = []string{"name"}
	do.Operations.ContainerNumber = 1
	log.WithFields(log.Fields{
		"data container": do.Name,
		"args":           do.Operations.Args,
	}).Info("Inspecting data (from tests)")
	if err := InspectData(do); err != nil {
		log.Error(err)
		t.FailNow()
	}

	do = definitions.NowDo()
	do.Name = dataName
	do.Operations.Args = []string{"config.network_disabled"}
	do.Operations.ContainerNumber = 1
	log.WithFields(log.Fields{
		"data container": do.Name,
		"args":           do.Operations.Args,
	}).Info("Inspecting data (from tests)")
	if err := InspectData(do); err != nil {
		log.Error(err)
		t.Fail()
	}
}
Ejemplo n.º 11
0
//------- helpers --------
func checkIPFSnotRunning() {
	//os.Setenv("ERIS_IPFS_HOST", "http://0.0.0.0") //conflicts with docker-machine
	do := def.NowDo()
	do.Known = false
	do.Existing = false
	do.Running = true
	do.Quiet = true
	log.Debug("Finding the running services")
	if err := list.ListAll(do, "services"); err != nil {
		IfExit(err)
	}
	res := strings.Split(do.Result, "\n")
	for _, r := range res {
		if r == "ipfs" {
			IfExit(fmt.Errorf("IPFS service is running.\nPlease stop it with.\neris services stop -rx ipfs\n"))
		}
	}
	// make sure ipfs container does not exist
	do = def.NowDo()
	do.Known = false
	do.Existing = true
	do.Running = false
	do.Quiet = true
	log.Debug("Finding the existing services")
	if err := list.ListAll(do, "services"); err != nil {
		IfExit(err)
	}
	res = strings.Split(do.Result, "\n")
	for _, r := range res {
		if r == "ipfs" {
			IfExit(fmt.Errorf("IPFS service exists.\nPlease remove it with\neris services rm ipfs\n"))
		}
	}
}
Ejemplo n.º 12
0
func TestRenameChain(t *testing.T) {
	do := def.NowDo()
	do.Name = chainName
	do.NewName = "niahctset"
	logger.Infof("Renaming chain (from tests) =>\t%s:%s\n", do.Name, do.NewName)
	e := RenameChain(do)
	if e != nil {
		logger.Errorln(e)
		t.Fail()
	}

	testExistAndRun(t, "niahctset", true, true)

	do = def.NowDo()
	do.Name = "niahctset"
	do.NewName = chainName
	logger.Infof("Renaming chain (from tests) =>\t%s:%s\n", do.Name, do.NewName)
	e = RenameChain(do)
	if e != nil {
		logger.Errorln(e)
		t.Fail()
	}

	testExistAndRun(t, chainName, true, true)
}
Ejemplo n.º 13
0
func TestRmChain(t *testing.T) {
	start(t, chainName)

	do := def.NowDo()
	do.Operations.Args, do.Rm, do.RmD = []string{"keys"}, true, true
	if err := services.KillService(do); err != nil {
		t.Fatalf("expected service to be stopped, got %v", err)
	}

	do = def.NowDo()
	do.Name, do.Rm, do.RmD = chainName, false, false
	log.WithField("=>", do.Name).Info("Stopping chain (from tests)")
	if err := KillChain(do); err != nil {
		t.Fatalf("expected chain to be stopped, got %v", err)
	}
	if n := util.HowManyContainersExisting(chainName, def.TypeChain); n != 1 {
		t.Fatalf("expecting 1 chain containers, got %v", n)
	}

	do = def.NowDo()
	do.Name = chainName
	do.RmD = true
	log.WithField("=>", do.Name).Info("Removing chain (from tests)")
	if err := RmChain(do); err != nil {
		t.Fatalf("expected chain to be removed, got %v", err)
	}
	if n := util.HowManyContainersExisting(chainName, def.TypeChain); n != 0 {
		t.Fatalf("expecting 0 chain containers, got %v", n)
	}
}
Ejemplo n.º 14
0
func TestChainsNewConfigOpts(t *testing.T) {
	defer tests.RemoveAllContainers()
	const (
		chain = "test-config-opts"
	)

	do := def.NowDo()
	do.Name = chain
	do.ConfigOpts = []string{"moniker=satoshi", "p2p=1.1.1.1:42", "fast-sync=true"}
	do.Operations.ContainerNumber = 1
	do.Operations.PublishAllPorts = true
	if err := NewChain(do); err != nil {
		t.Fatalf("expected to create a new chain, got %v", err)
	}

	do = def.NowDo()
	do.Name = chain
	do.Operations.Args = []string{"cat", fmt.Sprintf("/home/eris/.eris/chains/%s/config.toml", chain)}
	if err := ExecChain(do); err != nil {
		t.Fatalf("expected chain to execute, got %v", err)
	}

	args := []string{"cat", fmt.Sprintf("/home/eris/.eris/chains/%s/config.toml", chain)}
	if out := exec(t, chain, args); !strings.Contains(out, "satoshi") || !strings.Contains(out, "1.1.1.1:42") {
		t.Fatalf("expected to find set options in config file, got %v", out)
	}
}
Ejemplo n.º 15
0
func TestRmChain(t *testing.T) {
	testStartChain(t, chainName)

	do := def.NowDo()
	do.Operations.Args, do.Rm, do.RmD = []string{"keys"}, true, true
	log.WithField("=>", do.Name).Info("Removing keys (from tests)")
	if e := services.KillService(do); e != nil {
		tests.IfExit(e)
	}

	do = def.NowDo()
	do.Name, do.Rm, do.RmD = chainName, false, false
	log.WithField("=>", do.Name).Info("Stopping chain (from tests)")
	if e := KillChain(do); e != nil {
		tests.IfExit(e)
	}
	testExistAndRun(t, chainName, true, false)

	do = def.NowDo()
	do.Name = chainName
	do.RmD = true
	log.WithField("=>", do.Name).Info("Removing chain (from tests)")
	if e := RmChain(do); e != nil {
		tests.IfExit(e)
	}

	testExistAndRun(t, chainName, false, false)
}
Ejemplo n.º 16
0
func TestRenameData(t *testing.T) {
	testExist(t, dataName, true)
	testExist(t, newName, false)

	do := definitions.NowDo()
	do.Name = dataName
	do.NewName = newName
	do.Operations.ContainerNumber = 1
	logger.Infof("Renaming Data (from tests) =>\t%s:%s\n", do.Name, do.NewName)
	if err := RenameData(do); err != nil {
		logger.Errorln(err)
		t.FailNow()
	}

	testExist(t, dataName, false)
	testExist(t, newName, true)

	do = definitions.NowDo()
	do.Name = newName
	do.NewName = dataName
	do.Operations.ContainerNumber = 1
	logger.Infof("Renaming Data (from tests) =>\t%s:%s\n", do.Name, do.NewName)
	if err := RenameData(do); err != nil {
		logger.Errorln(err)
		t.FailNow()
	}

	testExist(t, dataName, true)
	testExist(t, newName, false)
}
Ejemplo n.º 17
0
func TestNewService(t *testing.T) {
	do := def.NowDo()
	servName := "keys"
	do.Name = servName
	do.Operations.Args = []string{"quay.io/eris/keys"}

	log.WithFields(log.Fields{
		"=>":   do.Name,
		"args": do.Operations.Args,
	}).Debug("Creating a new service (from tests)")
	e := NewService(do)
	if e != nil {
		log.Error(e)
		tests.IfExit(e)
	}

	do = def.NowDo()
	do.Operations.Args = []string{servName}
	log.WithFields(log.Fields{
		"container number": do.Operations.ContainerNumber,
		"args":             do.Operations.Args,
	}).Debug("Starting service (from tests)")
	e = StartService(do)
	if e != nil {
		log.Error(e)
		tests.IfExit(e)
	}

	testExistAndRun(t, servName, 1, true, true)
	testNumbersExistAndRun(t, servName, 1, 1)
	testKillService(t, servName, true)
	testExistAndRun(t, servName, 1, false, false)
}
Ejemplo n.º 18
0
func TestRenameAction(t *testing.T) {
	testExist(t, newName, false)
	testExist(t, oldName, true)

	do := definitions.NowDo()
	do.Name = oldName
	do.NewName = newName
	logger.Infof("Renaming Action (from tests) =>\t%s:%s\n", do.Name, do.NewName)
	if err := RenameAction(do); err != nil {
		logger.Errorln(err)
		t.Fail()
	}
	testExist(t, newName, true)
	testExist(t, oldName, false)

	do = definitions.NowDo()
	do.Name = newName
	do.NewName = oldName
	logger.Infof("Renaming Action (from tests) =>\t%s:%s\n", do.Name, do.NewName)
	if err := RenameAction(do); err != nil {
		logger.Errorln(err)
		t.Fail()
	}
	testExist(t, newName, false)
	testExist(t, oldName, true)
}
Ejemplo n.º 19
0
func TestNewService(t *testing.T) {
	do := def.NowDo()
	do.Name = "keys"
	do.Args = []string{"eris/keys"}
	logger.Debugf("New-ing serv (via tests) =>\t%s:%v\n", do.Name, do.Args)
	e := NewService(do)
	if e != nil {
		logger.Errorln(e)
		t.FailNow()
	}

	do = def.NowDo()
	do.Args = []string{"keys"}
	// do.Operations.ContainerNumber = util.AutoMagic(0, "service")
	//do.Operations.ContainerNumber = 1
	logger.Debugf("Stating serv (via tests) =>\t%v:%d\n", do.Args, do.Operations.ContainerNumber)
	e = StartService(do)
	if e != nil {
		logger.Errorln(e)
		t.Fail()
	}

	testExistAndRun(t, "keys", 1, true, true)
	testNumbersExistAndRun(t, "keys", 1, 1)
}
Ejemplo n.º 20
0
func TestNewService(t *testing.T) {
	do := def.NowDo()
	servName := "keys"
	do.Name = servName
	do.Operations.Args = []string{"quay.io/eris/keys"}
	logger.Debugf("New-ing serv (via tests) =>\t%s:%v\n", do.Name, do.Operations.Args)
	e := NewService(do)
	if e != nil {
		logger.Errorln(e)
		tests.IfExit(e)
	}

	do = def.NowDo()
	do.Operations.Args = []string{servName}
	// do.Operations.ContainerNumber = util.AutoMagic(0, "service")
	//do.Operations.ContainerNumber = 1
	logger.Debugf("Starting serv (via tests) =>\t%v:%d\n", do.Operations.Args, do.Operations.ContainerNumber)
	e = StartService(do)
	if e != nil {
		logger.Errorln(e)
		tests.IfExit(e)
	}

	testExistAndRun(t, servName, 1, true, true)
	testNumbersExistAndRun(t, servName, 1, 1)
	testKillService(t, servName, true)
	testExistAndRun(t, servName, 1, false, false)
}
Ejemplo n.º 21
0
func TestInspectService(t *testing.T) {
	testStartService(t, servName, false)
	defer testKillService(t, servName, true)

	do := def.NowDo()
	do.Name = servName
	do.Operations.Args = []string{"name"}
	do.Operations.ContainerNumber = 1
	logger.Debugf("Inspect service (via tests) =>\t%s:%v:%d\n", servName, do.Operations.Args, do.Operations.ContainerNumber)
	e := InspectService(do)
	if e != nil {
		logger.Infof("Error inspecting service =>\t%v\n", e)
		tests.IfExit(e)
	}

	do = def.NowDo()
	do.Name = servName
	do.Operations.Args = []string{"config.user"}
	do.Operations.ContainerNumber = 1
	logger.Debugf("Inspect service (via tests) =>\t%s:%v\n", servName, do.Operations.Args)
	e = InspectService(do)
	if e != nil {
		logger.Infof("Error inspecting service =>\t%v\n", e)
		tests.IfExit(e)
	}
}
Ejemplo n.º 22
0
func TestKillRmService(t *testing.T) {
	testStartService(t, servName, false)
	do := def.NowDo()
	do.Name = servName
	do.Rm = false
	do.RmD = false
	do.Operations.Args = []string{servName}
	logger.Debugf("Stopping serv (via tests) =>\t%s\n", servName)
	if e := KillService(do); e != nil {
		logger.Errorln(e)
		tests.IfExit(e)
	}

	testExistAndRun(t, servName, 1, true, false)
	testNumbersExistAndRun(t, servName, 1, 0)

	if os.Getenv("TEST_IN_CIRCLE") == "true" {
		logger.Println("Testing in Circle. Where we don't have rm privileges (due to their driver). Skipping test.")
		return
	}

	do = def.NowDo()
	do.Name = servName
	do.Operations.Args = []string{servName}
	do.File = false
	do.RmD = true
	logger.Debugf("Removing serv (via tests) =>\t%s\n", servName)
	if e := RmService(do); e != nil {
		logger.Errorln(e)
		tests.IfExit(e)
	}

	testExistAndRun(t, servName, 1, false, false)
	testNumbersExistAndRun(t, servName, 0, 0)
}
Ejemplo n.º 23
0
func TestRenameAction(t *testing.T) {
	testExist(t, newName, false)
	testExist(t, oldName, true)

	do := definitions.NowDo()
	do.Name = oldName
	do.NewName = newName
	log.WithFields(log.Fields{
		"from": do.Name,
		"to":   do.NewName,
	}).Info("Renaming action (from tests)")
	if err := RenameAction(do); err != nil {
		log.Error(err)
		t.Fail()
	}
	testExist(t, newName, true)
	testExist(t, oldName, false)

	do = definitions.NowDo()
	do.Name = newName
	do.NewName = oldName
	log.WithFields(log.Fields{
		"from": do.Name,
		"to":   do.NewName,
	}).Info("Renaming action (from tests)")
	if err := RenameAction(do); err != nil {
		log.Error(err)
		t.Fail()
	}
	testExist(t, newName, false)
	testExist(t, oldName, true)
}
Ejemplo n.º 24
0
func TestRmChain(t *testing.T) {
	testStartChain(t, chainName)

	do := def.NowDo()
	do.Args, do.Rm, do.RmD = []string{"keys"}, true, true
	logger.Infof("Removing keys (from tests) =>\n%s\n", do.Name)
	if e := services.KillService(do); e != nil {
		fatal(t, e)
	}

	do = def.NowDo()
	do.Name, do.Rm, do.RmD = chainName, false, false
	logger.Infof("Stopping chain (from tests) =>\t%s\n", do.Name)
	if e := KillChain(do); e != nil {
		fatal(t, e)
	}
	testExistAndRun(t, chainName, true, false)

	do = def.NowDo()
	do.Name = chainName
	do.RmD = true
	logger.Infof("Removing chain (from tests) =>\n%s\n", do.Name)
	if e := RmChain(do); e != nil {
		fatal(t, e)
	}

	testExistAndRun(t, chainName, false, false)
}
Ejemplo n.º 25
0
func TestRenameChain(t *testing.T) {
	oldName := chainName
	newName := "niahctset"
	testStartChain(t, oldName)
	defer testKillChain(t, oldName)

	do := def.NowDo()
	do.Name = oldName
	do.NewName = newName
	logger.Infof("Renaming chain (from tests) =>\t%s:%s\n", do.Name, do.NewName)
	if e := RenameChain(do); e != nil {
		fatal(t, e)
	}

	testExistAndRun(t, newName, true, true)

	do = def.NowDo()
	do.Name = newName
	do.NewName = chainName
	logger.Infof("Renaming chain (from tests) =>\t%s:%s\n", do.Name, do.NewName)
	if e := RenameChain(do); e != nil {
		fatal(t, e)
	}

	testExistAndRun(t, chainName, true, true)
}
Ejemplo n.º 26
0
func testExistAndRun(t *testing.T, servName string, containerNumber int, toExist, toRun bool) {
	var exist, run bool
	logger.Infof("\nTesting whether (%s) is running? (%t) and existing? (%t)\n", servName, toRun, toExist)
	servName = util.ServiceContainersName(servName, containerNumber)

	do := def.NowDo()
	do.Quiet = true
	do.Args = []string{"testing"}
	if err := ListExisting(do); err != nil {
		logger.Errorln(err)
		fatal(t, err)
	}
	res := strings.Split(do.Result, "\n")
	for _, r := range res {
		logger.Debugf("Existing =>\t\t\t%s\n", r)
		if r == util.ContainersShortName(servName) {
			exist = true
		}
	}

	do = def.NowDo()
	do.Quiet = true
	do.Args = []string{"testing"}
	if err := ListRunning(do); err != nil {
		logger.Errorln(err)
		fatal(t, err)
	}
	res = strings.Split(do.Result, "\n")
	for _, r := range res {
		logger.Debugf("Running =>\t\t\t%s\n", r)
		if r == util.ContainersShortName(servName) {
			run = true
		}
	}

	if toExist != exist {
		if toExist {
			logger.Printf("Could not find an existing =>\t%s\n", servName)
		} else {
			logger.Printf("Found an existing instance of %s when I shouldn't have\n", servName)
		}
		fatal(t, nil)
	}

	if toRun != run {
		if toRun {
			logger.Printf("Could not find a running =>\t%s\n", servName)
		} else {
			logger.Printf("Found a running instance of %s when I shouldn't have\n", servName)
		}
		fatal(t, nil)
	}

	logger.Infoln("All good.\n")
}
Ejemplo n.º 27
0
func testExistAndRun(t *testing.T, chainName string, toExist, toRun bool) {
	var exist, run bool
	logger.Infof("\nTesting whether (%s) is running? (%t) and existing? (%t)\n", chainName, toRun, toExist)
	chainName = util.ChainContainersName(chainName, 1) // not worried about containerNumbers, deal with multiple containers in services tests

	do := def.NowDo()
	do.Quiet = true
	do.Args = []string{"testing"}
	if err := ListExisting(do); err != nil {
		logger.Errorln(err)
		t.FailNow()
	}
	res := strings.Split(do.Result, "\n")
	for _, r := range res {
		logger.Debugf("Existing =>\t\t\t%s\n", r)
		if r == util.ContainersShortName(chainName) {
			exist = true
		}
	}

	do = def.NowDo()
	do.Quiet = true
	do.Args = []string{"testing"}
	if err := ListRunning(do); err != nil {
		logger.Errorln(err)
		t.FailNow()
	}
	res = strings.Split(do.Result, "\n")
	for _, r := range res {
		logger.Debugf("Running =>\t\t\t%s\n", r)
		if r == util.ContainersShortName(chainName) {
			run = true
		}
	}

	if toExist != exist {
		if toExist {
			logger.Infof("Could not find an existing =>\t%s\n", chainName)
		} else {
			logger.Infof("Found an existing instance of %s when I shouldn't have\n", chainName)
		}
		t.Fail()
	}

	if toRun != run {
		if toRun {
			logger.Infof("Could not find a running =>\t%s\n", chainName)
		} else {
			logger.Infof("Found a running instance of %s when I shouldn't have\n", chainName)
		}
		t.Fail()
	}

	logger.Debugln("")
}
Ejemplo n.º 28
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 := def.NowDo()
	do.Pull = true
	do.Services = true
	do.Actions = true
	ifExit(ini.Initialize(do))

	// set ipfs endpoint
	//os.Setenv("ERIS_IPFS_HOST", "http://0.0.0.0") //conflicts with docker-machine

	// make sure ipfs not running
	do = def.NowDo()
	do.Quiet = true
	logger.Debugln("Finding the running services.")
	if err := ListRunning(do); err != nil {
		ifExit(err)
	}
	res := strings.Split(do.Result, "\n")
	for _, r := range res {
		if r == "ipfs" {
			ifExit(fmt.Errorf("IPFS service is running.\nPlease stop it with.\neris services stop -rx ipfs\n"))
		}
	}
	// make sure ipfs container does not exist
	do = def.NowDo()
	do.Quiet = true
	if err := ListExisting(do); err != nil {
		ifExit(err)
	}
	res = strings.Split(do.Result, "\n")
	for _, r := range res {
		if r == "ipfs" {
			ifExit(fmt.Errorf("IPFS service exists.\nPlease remove it with\neris services rm ipfs\n"))
		}
	}

	logger.Infoln("Test init completed. Starting main test sequence now.")
	return nil
}
Ejemplo n.º 29
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)
	}
}
Ejemplo n.º 30
0
func kill(t *testing.T, chain string) {
	do := def.NowDo()
	do.Operations.Args, do.Rm, do.RmD = []string{"keys"}, true, true
	if err := services.KillService(do); err != nil {
		t.Fatalf("killing keys service failed: %v", err)
	}

	do = def.NowDo()
	do.Name, do.Rm, do.RmD = chain, true, true
	if err := KillChain(do); err != nil {
		t.Fatalf("killing chain failed: %v", err)
	}
}