func runContainer(t *testing.T, name string, args []string) []byte { oldWriter := config.GlobalConfig.Writer newWriter := new(bytes.Buffer) config.GlobalConfig.Writer = newWriter b, err := perform.DockerRunVolumesFromContainer(name, false, args, nil) if err != nil { fatal(t, err) } logger.Debugf("Container ran =>\t\t%s:%v\n", name, args) config.GlobalConfig.Writer = oldWriter return b }
func ExecData(do *definitions.Do) error { if util.IsDataContainer(do.Name, do.Operations.ContainerNumber) { do.Name = util.DataContainersName(do.Name, do.Operations.ContainerNumber) logger.Infoln("Running exec on container with volumes from data container " + do.Name) if err := perform.DockerRunVolumesFromContainer(do.Name, do.Interactive, do.Args); err != nil { return err } } else { return fmt.Errorf("I cannot find that data container. Please check the data container name you sent me.") } do.Result = "success" return nil }
func RegisterChain(do *definitions.Do) error { // do.Name is mandatory if do.Name == "" { return fmt.Errorf("RegisterChain requires a chainame") } etcbChain := do.ChainID do.ChainID = do.Name // NOTE: registration expects you to have the data container if !data.IsKnown(do.Name) { return fmt.Errorf("Registration requires you to have a data container for the chain. Could not find data for %s", do.Name) } chain, err := loaders.LoadChainDefinition(do.Name, false, do.Operations.ContainerNumber) if err != nil { return err } logger.Debugf("Chain Loaded. Image =>\t\t%v\n", chain.Service.Image) // set chainid and other vars envVars := []string{ fmt.Sprintf("CHAIN_ID=%s", do.ChainID), // of the etcb chain fmt.Sprintf("PUBKEY=%s", do.Pubkey), // pubkey to register chain with fmt.Sprintf("ETCB_CHAIN_ID=%s", etcbChain), // chain id of the etcb chain fmt.Sprintf("NODE_ADDR=%s", do.Gateway), // etcb node to send the register tx to fmt.Sprintf("NEW_P2P_SEEDS=%s", do.Args[0]), // seeds to register for the chain // TODO: deal with multi seed (needs support in tendermint) } envVars = append(envVars, do.Env...) logger.Debugf("Set env vars from RegisterChain =>\t%v\n", envVars) chain.Service.Environment = append(chain.Service.Environment, envVars...) logger.Debugf("Set links from RegisterChain =>\t%v\n", do.Links) chain.Service.Links = append(chain.Service.Links, do.Links...) if err := bootDependencies(chain, do); err != nil { return err } logger.Debugf("Starting chain container via Docker =>\t%s\n", chain.Service.Name) logger.Debugf("\twith Image =>\t\t%s\n", chain.Service.Image) cmd := []string{loaders.ErisChainRegister} dataContainerName := util.DataContainersName(chain.Name, chain.Operations.ContainerNumber) _, err = perform.DockerRunVolumesFromContainer(dataContainerName, false, cmd, chain.Service) return err }
// eris chains new --dir _ -g _ // the default chain_id is my_tests, so should be overwritten func TestChainsNewDirGen(t *testing.T) { chainID := "testChainsNewDirGen" myDir := path.Join(common.DataContainersPath, chainID) if err := os.MkdirAll(myDir, 0700); err != nil { fatal(t, err) } contents := "this is a file in the directory\n" if err := ioutil.WriteFile(path.Join(myDir, "file.file"), []byte(contents), 0600); err != nil { fatal(t, err) } do := def.NowDo() do.GenesisFile = path.Join(common.BlockchainsPath, "default", "genesis.json") do.Name = chainID do.Path = myDir do.Operations.ContainerNumber = 1 logger.Infof("Creating chain (from tests) =>\t%s\n", do.Name) ifExit(NewChain(do)) // remove the data container defer removeChainContainer(t, chainID, do.Operations.ContainerNumber) // verify the contents of file.file - swap config writer with bytes.Buffer // TODO: functions for facilitating this do.Name = util.DataContainersName(do.Name, do.Operations.ContainerNumber) oldWriter := config.GlobalConfig.Writer newWriter := new(bytes.Buffer) config.GlobalConfig.Writer = newWriter args := []string{"cat", fmt.Sprintf("/home/eris/.eris/blockchains/%s/file.file", chainID)} b, err := perform.DockerRunVolumesFromContainer(do.Name, false, args, nil) if err != nil { fatal(t, err) } config.GlobalConfig.Writer = oldWriter result := trimResult(string(b)) contents = trimResult(contents) if result != contents { fatal(t, fmt.Errorf("file not faithfully copied. Got: %s \n Expected: %s", result, contents)) } // verify the chain_id got swapped in the genesis.json // TODO: functions for facilitating this oldWriter = config.GlobalConfig.Writer newWriter = new(bytes.Buffer) config.GlobalConfig.Writer = newWriter args = []string{"cat", fmt.Sprintf("/home/eris/.eris/blockchains/%s/genesis.json", chainID)} //, "|", "jq", ".chain_id"} b, err = perform.DockerRunVolumesFromContainer(do.Name, false, args, nil) if err != nil { fatal(t, err) } config.GlobalConfig.Writer = oldWriter result = string(b) s := struct { ChainID string `json:"chain_id"` }{} if err := json.Unmarshal([]byte(result), &s); err != nil { fatal(t, err) } if s.ChainID != chainID { fatal(t, fmt.Errorf("ChainID mismatch: got %s, expected %s", s.ChainID, chainID)) } }