Esempio n. 1
0
// populateGUIArchive stores the uploaded Juju GUI archive in provider storage,
// updates the GUI metadata and set the current Juju GUI version.
func (c *BootstrapCommand) populateGUIArchive(st *state.State, env environs.Environ) error {
	agentConfig := c.CurrentConfig()
	dataDir := agentConfig.DataDir()
	guistorage, err := st.GUIStorage()
	if err != nil {
		return errors.Trace(err)
	}
	defer guistorage.Close()
	gui, err := agenttools.ReadGUIArchive(dataDir)
	if err != nil {
		return errors.Annotate(err, "cannot fetch GUI info")
	}
	f, err := os.Open(filepath.Join(agenttools.SharedGUIDir(dataDir), "gui.tar.bz2"))
	if err != nil {
		return errors.Annotate(err, "cannot read GUI archive")
	}
	defer f.Close()
	if err := guistorage.Add(f, binarystorage.Metadata{
		Version: gui.Version.String(),
		Size:    gui.Size,
		SHA256:  gui.SHA256,
	}); err != nil {
		return errors.Annotate(err, "cannot store GUI archive")
	}
	if err = st.GUISetVersion(gui.Version); err != nil {
		return errors.Annotate(err, "cannot set current GUI version")
	}
	return nil
}
Esempio n. 2
0
func (t *ToolsSuite) TestReadGUIArchiveErrorNotValid(c *gc.C) {
	dir := agenttools.SharedGUIDir(t.dataDir)
	err := os.MkdirAll(dir, agenttools.DirPerm)
	c.Assert(err, jc.ErrorIsNil)

	err = ioutil.WriteFile(filepath.Join(dir, agenttools.GUIArchiveFile), []byte(" \t\n"), 0644)
	c.Assert(err, jc.ErrorIsNil)

	gui, err := agenttools.ReadGUIArchive(t.dataDir)
	c.Assert(err, gc.ErrorMatches, "invalid GUI metadata in tools directory .*")
	c.Assert(gui, gc.IsNil)
}
Esempio n. 3
0
func (t *ToolsSuite) TestReadGUIArchiveSuccess(c *gc.C) {
	dir := agenttools.SharedGUIDir(t.dataDir)
	err := os.MkdirAll(dir, agenttools.DirPerm)
	c.Assert(err, jc.ErrorIsNil)

	expectGUI := coretest.GUIArchive{
		Version: version.MustParse("2.0.42"),
		URL:     "file:///path/to/gui",
		SHA256:  "hash",
		Size:    47,
	}
	b, err := json.Marshal(expectGUI)
	c.Assert(err, jc.ErrorIsNil)
	err = ioutil.WriteFile(filepath.Join(dir, agenttools.GUIArchiveFile), b, 0644)
	c.Assert(err, jc.ErrorIsNil)

	gui, err := agenttools.ReadGUIArchive(t.dataDir)
	c.Assert(err, jc.ErrorIsNil)
	c.Assert(*gui, gc.Equals, expectGUI)
}
Esempio n. 4
0
func (t *ToolsSuite) TestReadGUIArchiveErrorNotFound(c *gc.C) {
	gui, err := agenttools.ReadGUIArchive(t.dataDir)
	c.Assert(err, gc.ErrorMatches, "GUI metadata not found")
	c.Assert(err, jc.Satisfies, errors.IsNotFound)
	c.Assert(gui, gc.IsNil)
}