Exemplo n.º 1
0
func (s *backupsSuite) checkFailure(c *gc.C, expected string) {
	dbInfo := db.ConnInfo{"a", "b", "c"}
	origin := metadata.NewOrigin("<env ID>", "<machine ID>", "<hostname>")
	_, err := s.api.Create(dbInfo, *origin, "some notes")

	c.Check(err, gc.ErrorMatches, expected)
}
Exemplo n.º 2
0
func (s *backupsSuite) TestCreateOkay(c *gc.C) {

	// Patch the internals.
	archiveFile := ioutil.NopCloser(bytes.NewBufferString("<compressed tarball>"))
	result := backups.NewTestCreateResult(archiveFile, 10, "<checksum>")
	received, testCreate := backups.NewTestCreate(result)
	s.PatchValue(backups.RunCreate, testCreate)

	rootDir := "<was never set>"
	s.PatchValue(backups.GetFilesToBackUp, func(root string) ([]string, error) {
		rootDir = root
		return []string{"<some file>"}, nil
	})

	var receivedDBInfo *db.ConnInfo
	s.PatchValue(backups.GetDBDumper, func(info db.ConnInfo) db.Dumper {
		receivedDBInfo = &info
		return nil
	})

	// Run the backup.
	dbInfo := db.ConnInfo{"a", "b", "c"}
	origin := metadata.NewOrigin("<env ID>", "<machine ID>", "<hostname>")
	meta, err := s.api.Create(dbInfo, *origin, "some notes")

	// Test the call values.
	filesToBackUp, _ := backups.ExposeCreateArgs(received)
	c.Check(filesToBackUp, jc.SameContents, []string{"<some file>"})

	err = receivedDBInfo.Validate()
	c.Assert(err, gc.IsNil)
	c.Check(receivedDBInfo.Address, gc.Equals, "a")
	c.Check(receivedDBInfo.Username, gc.Equals, "b")
	c.Check(receivedDBInfo.Password, gc.Equals, "c")

	c.Check(rootDir, gc.Equals, "")

	// Check the resulting metadata.
	c.Check(meta.ID(), gc.Not(gc.Equals), "")
	c.Check(meta.Size(), gc.Equals, int64(10))
	c.Check(meta.Checksum(), gc.Equals, "<checksum>")
	c.Check(meta.Stored(), gc.Equals, true)
	metaOrigin := meta.Origin()
	c.Check(metaOrigin.Environment(), gc.Equals, "<env ID>")
	c.Check(metaOrigin.Machine(), gc.Equals, "<machine ID>")
	c.Check(metaOrigin.Hostname(), gc.Equals, "<hostname>")
	c.Check(meta.Notes(), gc.Equals, "some notes")

	// Check the file storage.
	storedMeta, storedFile, err := s.storage.Get(meta.ID())
	c.Check(err, gc.IsNil)
	c.Check(storedMeta, gc.DeepEquals, meta)
	data, err := ioutil.ReadAll(storedFile)
	c.Assert(err, gc.IsNil)
	c.Check(string(data), gc.Equals, "<compressed tarball>")
}
Exemplo n.º 3
0
func (s *backupSuite) metadata(c *gc.C) *metadata.Metadata {
	origin := metadata.NewOrigin(
		s.State.EnvironTag().Id(),
		"0",
		"localhost",
	)
	meta := metadata.NewMetadata(*origin, "", nil)
	err := meta.Finish(int64(42), "some hash", "", nil)
	c.Assert(err, gc.IsNil)
	return meta
}
Exemplo n.º 4
0
// NewBackupsOrigin returns a snapshot of where backup was run.  That
// snapshot is a new backup Origin value, for use in a backup's
// metadata.  Every value except for the machine name is populated
// either from juju state or some other implicit mechanism.
func NewBackupsOrigin(st *State, machine string) *metadata.Origin {
	// hostname could be derived from the environment...
	hostname, err := os.Hostname()
	if err != nil {
		// If os.Hostname() is not working, something is woefully wrong.
		// Run for the hills.
		panic(fmt.Sprintf("could not get hostname (system unstable?): %v", err))
	}
	origin := metadata.NewOrigin(
		st.EnvironTag().Id(),
		machine,
		hostname,
	)
	return origin
}
Exemplo n.º 5
0
func (s *backupsSuite) newMeta(notes string) *metadata.Metadata {
	origin := metadata.NewOrigin("<env ID>", "<machine ID>", "<hostname>")
	return metadata.NewMetadata(*origin, notes, nil)
}