Example #1
0
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
}
Example #2
0
func (*CurrentSuite) TestCurrentSeries(c *C) {
	s := version.CurrentSeries()
	if s == "unknown" {
		s = "n/a"
	}
	out, err := exec.Command("lsb_release", "-c").CombinedOutput()
	if err != nil {
		// If the command fails (for instance if we're running on some other
		// platform) then CurrentSeries should be unknown.
		c.Assert(s, Equals, "n/a")
	} else {
		c.Assert(string(out), Equals, "Codename:\t"+s+"\n")
	}
}
Example #3
0
func (s *StorageSuite) TestUploadFakeSeries(c *gc.C) {
	t, err := tools.Upload(s.env.Storage(), nil, "sham", "fake")
	c.Assert(err, gc.IsNil)
	c.Assert(t.Version, gc.Equals, version.Current)
	expectRaw := downloadToolsRaw(c, t)

	list, err := tools.ReadList(s.env.Storage(), version.Current.Major)
	c.Assert(err, gc.IsNil)
	c.Assert(list, gc.HasLen, 3)
	expectSeries := []string{"fake", "sham", version.CurrentSeries()}
	sort.Strings(expectSeries)
	c.Assert(list.Series(), gc.DeepEquals, expectSeries)
	for _, t := range list {
		c.Logf("checking %s", t.URL)
		c.Assert(t.Version.Number, gc.Equals, version.CurrentNumber())
		actualRaw := downloadToolsRaw(c, t)
		c.Assert(string(actualRaw), gc.Equals, string(expectRaw))
	}
}
Example #4
0
func currentMongoPath() string {
	return environs.MongoStoragePath(version.CurrentSeries(), version.CurrentArch())
}
Example #5
0
	summary        string   // a summary of the test purpose.
	contents       []string // names in private storage.
	publicContents []string // names in public storage.
	expect         string   // the name we expect to find (if no error).
	urlpart        string   // part of the url we expect to find (if not blank).
}{{
	summary:  "grab mongo from private storage if it exists there",
	contents: []string{currentMongoPath()},
	expect:   currentMongoPath(),
}, {
	summary: "fall back to public storage when nothing found in private",
	contents: []string{
		environs.MongoStoragePath("foo", version.CurrentArch()),
	},
	publicContents: []string{
		currentMongoPath(),
	},
	expect: "public-" + currentMongoPath(),
}, {
	summary: "if nothing in public or private storage, fall back to copy in ec2",
	contents: []string{
		environs.MongoStoragePath("foo", version.CurrentArch()),
		environs.MongoStoragePath(version.CurrentSeries(), "foo"),
	},
	publicContents: []string{
		environs.MongoStoragePath("foo", version.CurrentArch()),
	},
	urlpart: "http://juju-dist.s3.amazonaws.com",
},
}