예제 #1
0
func (s *steps124Suite) TestMoveSyslogConfigDefault(c *gc.C) {
	logdir := c.MkDir()
	datadir := c.MkDir()
	data := []byte("data!")
	files := []string{
		"ca-cert.pem",
		"rsyslog-cert.pem",
		"rsyslog-key.pem",
		"logrotate.conf",
		"logrotate.run",
	}
	for _, f := range files {
		err := ioutil.WriteFile(filepath.Join(logdir, f), data, 0644)
		c.Assert(err, jc.ErrorIsNil)
	}

	ctx := fakeContext{cfg: fakeConfig{logdir: logdir, datadir: datadir}}
	err := upgrades.MoveSyslogConfig(ctx)
	c.Assert(err, jc.ErrorIsNil)

	for _, f := range files {
		_, err := os.Stat(filepath.Join(datadir, f))
		c.Assert(err, jc.ErrorIsNil)
		_, err = os.Stat(filepath.Join(logdir, f))
		c.Assert(err, jc.Satisfies, os.IsNotExist)
	}
}
예제 #2
0
func (s *steps124Suite) TestMoveSyslogConfig(c *gc.C) {
	logdir := c.MkDir()
	datadir := c.MkDir()
	data := []byte("data!")
	files := []string{
		"logrotate.conf",
		"logrotate.run",
	}

	// ensure that we don't overwrite an existing file in datadir, and don't
	// error out if one of the files exists in datadir but not logdir.

	err := ioutil.WriteFile(filepath.Join(logdir, "logrotate.conf"), data, 0644)
	c.Assert(err, jc.ErrorIsNil)

	err = ioutil.WriteFile(filepath.Join(datadir, "logrotate.run"), data, 0644)
	c.Assert(err, jc.ErrorIsNil)

	differentData := []byte("different")
	existing := filepath.Join(datadir, "logrotate.conf")
	err = ioutil.WriteFile(existing, differentData, 0644)
	c.Assert(err, jc.ErrorIsNil)

	ctx := fakeContext{cfg: fakeConfig{logdir: logdir, datadir: datadir}}
	err = upgrades.MoveSyslogConfig(ctx)
	c.Assert(err, jc.ErrorIsNil)

	for _, f := range files {
		_, err := os.Stat(filepath.Join(datadir, f))
		c.Assert(err, jc.ErrorIsNil)
		_, err = os.Stat(filepath.Join(logdir, f))
		c.Assert(err, jc.Satisfies, os.IsNotExist)
	}

	b, err := ioutil.ReadFile(existing)
	c.Assert(err, jc.ErrorIsNil)
	// convert to string because we'll get a better failure message
	c.Assert(string(b), gc.Not(gc.Equals), string(existing))

}
예제 #3
0
func (s *steps124Suite) TestMoveSyslogConfigCantDeleteOld(c *gc.C) {
	logdir := c.MkDir()
	datadir := c.MkDir()
	file := filepath.Join(logdir, "logrotate.conf")

	// ensure that we don't error out if we can't remove the old file.
	// error out if one of the files exists in datadir but not logdir.
	s.PatchValue(upgrades.OsRemove, func(string) error { return os.ErrPermission })

	err := ioutil.WriteFile(file, []byte("data!"), 0644)
	c.Assert(err, jc.ErrorIsNil)

	ctx := fakeContext{cfg: fakeConfig{logdir: logdir, datadir: datadir}}
	err = upgrades.MoveSyslogConfig(ctx)
	c.Assert(err, jc.ErrorIsNil)

	// should still exist in both places (i.e. check we didn't screw up the test)
	_, err = os.Stat(file)
	c.Assert(err, jc.ErrorIsNil)
	_, err = os.Stat(filepath.Join(datadir, "logrotate.conf"))
	c.Assert(err, jc.ErrorIsNil)
}