Exemple #1
0
func (suite) TestCheckNoDataDir(c *C) {
	conf := agent.Conf{
		StateInfo: &state.Info{
			Addrs:      []string{"x:4"},
			CACert:     []byte("xxx"),
			EntityName: "bar",
			Password:   "******",
		},
	}
	c.Assert(conf.Check(), ErrorMatches, "data directory not found in configuration")
}
Exemple #2
0
func (s *openSuite) TestOpenStateNormal(c *C) {
	conf := agent.Conf{
		StateInfo: s.StateInfo(c),
	}
	conf.OldPassword = "******"

	st, changed, err := conf.OpenState()
	c.Assert(err, IsNil)
	defer st.Close()
	c.Assert(changed, Equals, false)
	c.Assert(st, NotNil)
}
Exemple #3
0
func (suite) TestConfFile(c *C) {
	conf := agent.Conf{
		DataDir: "/foo",
		StateInfo: &state.Info{
			Addrs:      []string{"x:4"},
			CACert:     []byte("xxx"),
			EntityName: "bar",
			Password:   "******",
		},
	}
	c.Assert(conf.File("x/y"), Equals, "/foo/agents/bar/x/y")
}
Exemple #4
0
func (s *openSuite) TestOpenStateNoPassword(c *C) {
	conf := agent.Conf{
		StateInfo: s.StateInfo(c),
	}
	conf.OldPassword = conf.StateInfo.Password
	conf.StateInfo.Password = ""

	st, changed, err := conf.OpenState()
	c.Assert(err, IsNil)
	defer st.Close()
	c.Assert(changed, Equals, true)
	c.Assert(st, NotNil)
	p, err := trivial.RandomPassword()
	c.Assert(err, IsNil)
	c.Assert(conf.StateInfo.Password, HasLen, len(p))
	c.Assert(conf.OldPassword, Equals, s.StateInfo(c).Password)
}
Exemple #5
0
func runOnce(c *agent.Conf, a Agent) error {
	st, passwordChanged, err := c.OpenState()
	if err != nil {
		return err
	}
	defer st.Close()
	entity, err := a.Entity(st)
	if state.IsNotFound(err) || err == nil && entity.Life() == state.Dead {
		return worker.ErrDead
	}
	if err != nil {
		return err
	}
	if passwordChanged {
		if err := c.Write(); err != nil {
			return err
		}
		if err := entity.SetMongoPassword(c.StateInfo.Password); err != nil {
			return err
		}
	}
	return a.RunOnce(st, entity)
}