func (s *ToolsSuite) SetUpTest(c *C) { s.dataDir = c.MkDir() s.toolsDir = tools.SharedToolsDir(s.dataDir, version.Current) err := os.MkdirAll(s.toolsDir, 0755) c.Assert(err, IsNil) err = os.Symlink(s.toolsDir, tools.ToolsDir(s.dataDir, "unit-u-123")) c.Assert(err, IsNil) }
func (env *localEnviron) setupLocalMachineAgent(cons constraints.Value) error { dataDir := env.config.rootDir() toolList, err := environs.FindBootstrapTools(env, cons) if err != nil { return err } // ensure we have at least one valid tools if len(toolList) == 0 { return fmt.Errorf("No bootstrap tools found") } // unpack the first tools into the agent dir. agentTools := toolList[0] logger.Debugf("tools: %#v", agentTools) // brutally abuse our knowledge of storage to directly open the file toolsUrl, err := url.Parse(agentTools.URL) toolsLocation := filepath.Join(env.config.storageDir(), toolsUrl.Path) logger.Infof("tools location: %v", toolsLocation) toolsFile, err := os.Open(toolsLocation) defer toolsFile.Close() // Again, brutally abuse our knowledge here. // The tools that FindBootstrapTools has returned us are based on the // default series in the config. However we are running potentially on a // different series. When the machine agent is started, it will be // looking based on the current series, so we need to override the series // returned in the tools to be the current series. agentTools.Version.Series = version.CurrentSeries() err = tools.UnpackTools(dataDir, agentTools, toolsFile) machineId := "0" // Always machine 0 tag := names.MachineTag(machineId) toolsDir := tools.SharedToolsDir(dataDir, agentTools.Version) logDir := env.config.logDir() logConfig := "--debug" // TODO(thumper): specify loggo config machineEnvironment := map[string]string{ "USER": env.config.user, "HOME": os.Getenv("HOME"), osenv.JujuProviderType: env.config.Type(), osenv.JujuStorageDir: env.config.storageDir(), osenv.JujuStorageAddr: env.config.storageAddr(), osenv.JujuSharedStorageDir: env.config.sharedStorageDir(), osenv.JujuSharedStorageAddr: env.config.sharedStorageAddr(), } agent := upstart.MachineAgentUpstartService( env.machineAgentServiceName(), toolsDir, dataDir, logDir, tag, machineId, logConfig, machineEnvironment) agent.InitDir = upstartScriptLocation logger.Infof("installing service %s to %s", env.machineAgentServiceName(), agent.InitDir) if err := agent.Install(); err != nil { logger.Errorf("could not install machine agent service: %v", err) return err } return nil }
// assertToolsContents asserts that the directory for the tools // has the given contents. func (t *ToolsSuite) assertToolsContents(c *gc.C, testTools *tools.Tools, files []*testing.TarFile) { var wantNames []string for _, f := range files { wantNames = append(wantNames, f.Header.Name) } wantNames = append(wantNames, urlFile) dir := tools.SharedToolsDir(t.dataDir, testTools.Version) assertDirNames(c, dir, wantNames) assertFileContents(c, dir, urlFile, testTools.URL, 0200) for _, f := range files { assertFileContents(c, dir, f.Header.Name, f.Contents, 0400) } gotTools, err := tools.ReadTools(t.dataDir, testTools.Version) c.Assert(err, gc.IsNil) c.Assert(*gotTools, gc.Equals, *testTools) }
func (t *ToolsSuite) TestReadToolsErrors(c *gc.C) { vers := version.MustParseBinary("1.2.3-precise-amd64") testTools, err := tools.ReadTools(t.dataDir, vers) c.Assert(testTools, gc.IsNil) c.Assert(err, gc.ErrorMatches, "cannot read URL in tools directory: .*") dir := tools.SharedToolsDir(t.dataDir, vers) err = os.MkdirAll(dir, 0755) c.Assert(err, gc.IsNil) err = ioutil.WriteFile(filepath.Join(dir, urlFile), []byte(" \t\n"), 0644) c.Assert(err, gc.IsNil) testTools, err = tools.ReadTools(t.dataDir, vers) c.Assert(testTools, gc.IsNil) c.Assert(err, gc.ErrorMatches, "empty URL in tools directory.*") }
func (s *lxcProvisionerSuite) SetUpTest(c *gc.C) { s.CommonProvisionerSuite.SetUpTest(c) s.lxcSuite.SetUpTest(c) // Write the tools file. toolsDir := tools.SharedToolsDir(s.DataDir(), version.Current) c.Assert(os.MkdirAll(toolsDir, 0755), gc.IsNil) urlPath := filepath.Join(toolsDir, "downloaded-url.txt") err := ioutil.WriteFile(urlPath, []byte("http://testing.invalid/tools"), 0644) c.Assert(err, gc.IsNil) // The lxc provisioner actually needs the machine it is being created on // to be in state, in order to get the watcher. m, err := s.State.AddMachine(config.DefaultSeries, state.JobHostUnits) c.Assert(err, gc.IsNil) s.machineId = m.Id() s.events = make(chan mock.Event, 25) s.Factory.AddListener(s.events) }
func (s *UpgraderSuite) TestUpgrader(c *C) { for i, test := range upgraderTests { c.Logf("\ntest %d: %s", i, test.about) // Note: primeTools sets version.Current... currentTools := s.primeTools(c, test.current) // ...but it also puts tools in storage we don't need, which is why we // don't clean up garbage from earlier runs first. envtesting.RemoveAllTools(c, s.Conn.Environ) uploaded := make(map[version.Binary]*tools.Tools) for _, vers := range test.available { tools := s.uploadTools(c, vers) uploaded[vers] = tools } func() { u := s.startUpgrader(c, currentTools) defer u.Stop() s.proposeVersion(c, test.propose) s.State.StartSync() if test.upgrade.Number == version.Zero { assertNothingHappens(c, u) c.Assert(u.Stop(), IsNil) return } ug := waitDeath(c, u) newTools := uploaded[test.upgrade] c.Check(ug.NewTools, DeepEquals, newTools) c.Check(ug.OldTools.Binary, Equals, version.Current) c.Check(ug.DataDir, Equals, s.DataDir()) c.Check(ug.AgentName, Equals, "testagent") // Check that the upgraded version was really downloaded. path := tools.SharedToolsDir(s.DataDir(), newTools.Binary) data, err := ioutil.ReadFile(filepath.Join(path, "jujud")) c.Check(err, IsNil) c.Check(string(data), Equals, "jujud contents "+newTools.Binary.String()) }() } }
func (fix *SimpleToolsFixture) SetUp(c *C, dataDir string) { fix.dataDir = dataDir fix.initDir = c.MkDir() fix.logDir = c.MkDir() fix.syslogConfigDir = c.MkDir() toolsDir := tools.SharedToolsDir(fix.dataDir, version.Current) err := os.MkdirAll(toolsDir, 0755) c.Assert(err, IsNil) jujudPath := filepath.Join(toolsDir, "jujud") err = ioutil.WriteFile(jujudPath, []byte(fakeJujud), 0755) c.Assert(err, IsNil) urlPath := filepath.Join(toolsDir, "downloaded-url.txt") err = ioutil.WriteFile(urlPath, []byte("http://testing.invalid/tools"), 0644) c.Assert(err, IsNil) fix.binDir = c.MkDir() fix.origPath = os.Getenv("PATH") os.Setenv("PATH", fix.binDir+":"+fix.origPath) fix.makeBin(c, "status", `echo "blah stop/waiting"`) fix.makeBin(c, "stopped-status", `echo "blah stop/waiting"`) fix.makeBin(c, "started-status", `echo "blah start/running, process 666"`) fix.makeBin(c, "start", "cp $(which started-status) $(which status)") fix.makeBin(c, "stop", "cp $(which stopped-status) $(which status)") }
func (cfg *MachineConfig) jujuTools() string { return tools.SharedToolsDir(cfg.DataDir, cfg.Tools.Binary) }
func (t *ToolsSuite) TestSharedToolsDir(c *gc.C) { dir := tools.SharedToolsDir("/var/lib/juju", version.MustParseBinary("1.2.3-precise-amd64")) c.Assert(dir, gc.Equals, "/var/lib/juju/tools/1.2.3-precise-amd64") }