Пример #1
0
func (s *BootstrapSuite) SetUpTest(c *gc.C) {
	s.BaseSuite.SetUpTest(c)
	s.PatchValue(&sshGenerateKey, func(name string) (string, string, error) {
		return "private-key", "public-key", nil
	})

	s.MgoSuite.SetUpTest(c)
	s.dataDir = c.MkDir()
	s.logDir = c.MkDir()
	s.mongoOplogSize = "1234"
	s.fakeEnsureMongo = agenttesting.InstallFakeEnsureMongo(s)
	s.PatchValue(&maybeInitiateMongoServer, s.fakeEnsureMongo.InitiateMongo)

	// Create fake tools.tar.gz and downloaded-tools.txt.
	current := version.Binary{
		Number: version.Current,
		Arch:   arch.HostArch(),
		Series: series.HostSeries(),
	}
	toolsDir := filepath.FromSlash(agenttools.SharedToolsDir(s.dataDir, current))
	err := os.MkdirAll(toolsDir, 0755)
	c.Assert(err, jc.ErrorIsNil)
	err = ioutil.WriteFile(filepath.Join(toolsDir, "tools.tar.gz"), nil, 0644)
	c.Assert(err, jc.ErrorIsNil)
	s.writeDownloadedTools(c, &tools.Tools{Version: current})
}
Пример #2
0
func (s *leadershipSuite) SetUpTest(c *gc.C) {
	s.AgentSuite.SetUpTest(c)

	leaseManager, err := lease.NewLeaseManager(s.State)
	c.Assert(err, jc.ErrorIsNil)
	s.AddCleanup(func(c *gc.C) {
		leaseManager.Kill()
		c.Assert(leaseManager.Wait(), jc.ErrorIsNil)
	})

	file, _ := ioutil.TempFile("", "juju-run")
	defer file.Close()
	s.AgentSuite.PatchValue(&agentcmd.JujuRun, file.Name())

	agenttesting.InstallFakeEnsureMongo(s)
	s.PatchValue(&agentcmd.ProductionMongoWriteConcern, false)

	// Create a machine to manage the environment.
	stateServer, password := s.Factory.MakeMachineReturningPassword(c, &factory.MachineParams{
		InstanceId: "id-1",
		Nonce:      agent.BootstrapNonce,
		Jobs:       []state.MachineJob{state.JobManageEnviron},
	})
	c.Assert(stateServer.PasswordValid(password), gc.Equals, true)
	c.Assert(stateServer.SetMongoPassword(password), jc.ErrorIsNil)

	// Create a machine to host some units.
	unitHostMachine := s.Factory.MakeMachine(c, &factory.MachineParams{
		Nonce:    agent.BootstrapNonce,
		Password: password,
	})

	// Create a service and an instance of that service so that we can
	// create a client.
	service := s.Factory.MakeService(c, &factory.ServiceParams{})
	s.serviceId = service.Tag().Id()

	unit := s.Factory.MakeUnit(c, &factory.UnitParams{Machine: unitHostMachine, Service: service})
	s.unitId = unit.UnitTag().Id()

	c.Assert(unit.SetPassword(password), jc.ErrorIsNil)
	s.apiState = s.OpenAPIAs(c, unit.Tag(), password)

	// Tweak and write out the config file for the state server.
	writeStateAgentConfig(
		c,
		s.MongoInfo(c),
		s.DataDir(),
		stateServer.Tag(),
		s.State.EnvironTag(),
		password,
		version.Current,
	)

	// Create & start a machine agent so the tests have something to call into.
	agentConf := agentcmd.NewAgentConf(s.DataDir())
	machineAgentFactory := agentcmd.MachineAgentFactoryFn(agentConf, agentConf, nil, nil)
	s.machineAgent = machineAgentFactory(stateServer.Id())

	// See comment in createMockJujudExecutable
	if runtime.GOOS == "windows" {
		dirToRemove := createMockJujudExecutable(c, s.DataDir(), s.machineAgent.Tag().String())
		s.AddCleanup(func(*gc.C) { os.RemoveAll(dirToRemove) })
	}

	c.Log("Starting machine agent...")
	go func() {
		err := s.machineAgent.Run(coretesting.Context(c))
		c.Assert(err, jc.ErrorIsNil)
	}()
}