Example #1
0
func (s *stateSuite) TestReadAllStateFilesOneBadApple(c *gc.C) {
	dir := c.MkDir()
	writeFile(c, filepath.Join(dir, "data-0"), "rubbish")
	_, err := storage.ReadAllStateFiles(dir)
	c.Assert(err, gc.ErrorMatches, `cannot load storage state from ".*": cannot load storage "data/0" state from ".*": invalid storage state file ".*": yaml: unmarshal errors:
`+"  line 1: cannot unmarshal !!str `rubbish` into storage.diskInfo")
}
Example #2
0
func (s *stateSuite) TestReadAllStateFilesJunk(c *gc.C) {
	dir := c.MkDir()
	writeFile(c, filepath.Join(dir, "data-0"), "attached: true")
	// data-extra-1 is not a valid storage ID, so it will
	// be ignored by ReadAllStateFiles.
	writeFile(c, filepath.Join(dir, "data-extra-1"), "attached: false")
	// subdirs are ignored.
	err := os.Mkdir(filepath.Join(dir, "data-1"), 0755)
	c.Assert(err, jc.ErrorIsNil)

	states, err := storage.ReadAllStateFiles(dir)
	c.Assert(err, jc.ErrorIsNil)
	c.Assert(states, gc.HasLen, 1)
	_, ok := states[names.NewStorageTag("data/0")]
	c.Assert(ok, jc.IsTrue)
}
Example #3
0
func (s *stateSuite) TestReadAllStateFiles(c *gc.C) {
	dir := c.MkDir()
	writeFile(c, filepath.Join(dir, "data-0"), "attached: true")
	// We don't currently ever write a file with attached=false,
	// but test it for coverage in case of required changes.
	writeFile(c, filepath.Join(dir, "data-1"), "attached: false")

	states, err := storage.ReadAllStateFiles(dir)
	c.Assert(err, jc.ErrorIsNil)
	c.Assert(states, gc.HasLen, 2)

	state, ok := states[names.NewStorageTag("data/0")]
	c.Assert(ok, jc.IsTrue)
	c.Assert(storage.StateAttached(state), jc.IsTrue)

	state, ok = states[names.NewStorageTag("data/1")]
	c.Assert(ok, jc.IsTrue)
	c.Assert(storage.StateAttached(state), jc.IsFalse)
}
Example #4
0
func (s *stateSuite) TestReadAllStateFilesDirEmpty(c *gc.C) {
	dir := c.MkDir()
	states, err := storage.ReadAllStateFiles(dir)
	c.Assert(err, jc.ErrorIsNil)
	c.Assert(states, gc.HasLen, 0)
}
Example #5
0
func (s *stateSuite) TestReadAllStateFilesDirNotExist(c *gc.C) {
	dir := filepath.Join(c.MkDir(), "doesnotexist")
	states, err := storage.ReadAllStateFiles(dir)
	c.Assert(err, jc.ErrorIsNil)
	c.Assert(states, gc.HasLen, 0)
}
Example #6
0
func (s *stateSuite) TestReadAllStateFilesOneBadApple(c *gc.C) {
	dir := c.MkDir()
	writeFile(c, filepath.Join(dir, "data-0"), "rubbish")
	_, err := storage.ReadAllStateFiles(dir)
	c.Assert(err, gc.ErrorMatches, `cannot load storage state from ".*": cannot load storage "data/0" state from ".*": invalid storage state file ".*": missing 'attached'`)
}