func (s *DeployHelperSuite) TestResolveDepValues(c *C) {
	datamodel.Zk.RecursiveDelete(helper.GetBaseEnvPath())
	datamodel.Zk.RecursiveDelete(helper.GetBaseRouterPath(true))
	datamodel.Zk.RecursiveDelete(helper.GetBaseRouterPath(false))
	datamodel.Zk.RecursiveDelete(helper.GetBaseRouterPortsPath(true))
	datamodel.Zk.RecursiveDelete(helper.GetBaseRouterPortsPath(false))
	datamodel.CreateEnvPath()
	datamodel.CreateRouterPaths()
	datamodel.Router(true, "dev", "somehost", "1.2.3.4").Save()
	zkEnv := datamodel.Env("root")
	err := zkEnv.Save()
	c.Assert(err, IsNil)
	deps, err := ResolveDepValues("app", zkEnv, []string{"hello-go"}, false, &Task{})
	c.Assert(err, Not(IsNil))
	_, err = datamodel.CreateInstance("hello-go", "1234567890", "root", "myhost")
	c.Assert(err, IsNil)
	_, err = datamodel.CreateOrUpdateApp(false, false, "app", "ssh://github.com/ooyala/apo", "/", "*****@*****.**")
	c.Assert(err, IsNil)
	zkApp, err := datamodel.CreateOrUpdateApp(false, true, "hello-go", "ssh://github.com/ooyala/hello-go", "/", "*****@*****.**")
	c.Assert(err, IsNil)
	c.Assert(zkApp.AddDependerAppData(&DependerAppData{Name: "app", DependerEnvData: map[string]*DependerEnvData{"root": &DependerEnvData{Name: "root"}}}), IsNil)
	deps, err = ResolveDepValues("app", zkEnv, []string{"hello-go"}, false, &Task{})
	c.Assert(err, IsNil)
	c.Assert(deps["dev1"]["hello-go"].DataMap["address"], Equals, fmt.Sprintf("internal-router.1.%s.suffix.com:%d", Region, datamodel.MinRouterPort))
	deps, err = ResolveDepValues("app", zkEnv, []string{"hello-go"}, true, &Task{})
	c.Assert(err, IsNil)
	c.Assert(deps["dev1"]["hello-go"].EncryptedData, Not(Equals), "")
	c.Assert(deps["dev1"]["hello-go"].DataMap, IsNil)
	scrypto.DecryptAppDep(deps["dev1"]["hello-go"])
	c.Assert(deps["dev1"]["hello-go"].DataMap, Not(IsNil))
	c.Assert(deps["dev1"]["hello-go"].DataMap["address"], Equals, fmt.Sprintf("internal-router.1.%s.suffix.com:%d", Region, datamodel.MinRouterPort))
}
Beispiel #2
0
func (e *RegisterAppExecutor) Execute(t *Task) error {
	if e.arg.Name == "" {
		return errors.New("Please specify an app name to register")
	}
	if !AppRegexp.MatchString(e.arg.Name) {
		return errors.New("App name must be [A-Za-z0-9-]+")
	}
	if !e.arg.NonAtlantis && e.arg.Repo == "" {
		return errors.New("Please specify a repo")
	}
	if !e.arg.NonAtlantis && e.arg.Root == "" {
		return errors.New("Please specify the repo's root")
	}
	if e.arg.Email == "" {
		return errors.New("Please specify the email of the app owner")
	}
	if _, err := datamodel.GetApp(e.arg.Name); err == nil {
		return errors.New("Already Registered.")
	}
	_, err := datamodel.CreateOrUpdateApp(e.arg.NonAtlantis, e.arg.Internal, e.arg.Name, e.arg.Repo, e.arg.Root,
		e.arg.Email)
	if err != nil {
		e.reply.Status = StatusError
	}
	e.reply.Status = StatusOk
	return err
}