Exemplo n.º 1
0
func (s *AptSuite) TestAptProxyContentPartial(c *gc.C) {
	proxySettings := proxy.Settings{
		Http: "[email protected]",
	}
	output := apt.ProxyContent(proxySettings)
	expected := `Acquire::http::Proxy "[email protected]";`
	c.Assert(output, gc.Equals, expected)
}
func (s *MachineEnvironmentWatcherSuite) TestInitialStateLocalMachine1(c *gc.C) {
	proxySettings, aptProxySettings := s.updateConfig(c)

	agentConfig := agentConfig(names.NewMachineTag("1"), provider.Local)
	envWorker := s.makeWorker(c, agentConfig)
	defer worker.Stop(envWorker)

	s.waitProxySettings(c, proxySettings)
	s.waitForFile(c, s.proxyFile, proxySettings.AsScriptEnvironment()+"\n")
	s.waitForFile(c, apt.ConfFile, apt.ProxyContent(aptProxySettings)+"\n")
}
func (s *MachineEnvironmentWatcherSuite) TestRespondsToEvents(c *gc.C) {
	agentConfig := agentConfig(names.NewMachineTag("0"), "ec2")
	envWorker := s.makeWorker(c, agentConfig)
	defer worker.Stop(envWorker)
	s.waitForPostSetup(c)

	proxySettings, aptProxySettings := s.updateConfig(c)

	s.waitProxySettings(c, proxySettings)
	s.waitForFile(c, s.proxyFile, proxySettings.AsScriptEnvironment()+"\n")
	s.waitForFile(c, apt.ConfFile, apt.ProxyContent(aptProxySettings)+"\n")
}
Exemplo n.º 4
0
func (w *MachineEnvironmentWorker) handleAptProxyValues(aptSettings proxyutils.Settings) {
	if w.writeSystemFiles && (aptSettings != w.aptProxy || w.first) {
		logger.Debugf("new apt proxy settings %#v", aptSettings)
		w.aptProxy = aptSettings
		// Always finish with a new line.
		content := apt.ProxyContent(w.aptProxy) + "\n"
		err := ioutil.WriteFile(apt.ConfFile, []byte(content), 0644)
		if err != nil {
			// It isn't really fatal, but we should record it.
			logger.Errorf("error writing apt proxy config file: %v", err)
		}
	}
}
Exemplo n.º 5
0
func (s *AptSuite) TestAptProxyContentRoundtrip(c *gc.C) {
	proxySettings := proxy.Settings{
		Http:  "http://[email protected]",
		Https: "https://[email protected]",
		Ftp:   "ftp://[email protected]",
	}
	output := apt.ProxyContent(proxySettings)

	s.HookCommandOutput(&apt.CommandOutput, []byte(output), nil)

	detected, err := apt.DetectProxies()
	c.Assert(err, gc.IsNil)
	c.Assert(detected, gc.DeepEquals, proxySettings)
}
Exemplo n.º 6
0
// AddAptCommands update the cloudinit.Config instance with the necessary
// packages, the request to do the apt-get update/upgrade on boot, and adds
// the apt proxy settings if there are any.
func AddAptCommands(proxySettings proxy.Settings, c *cloudinit.Config) {
	// Bring packages up-to-date.
	c.SetAptUpdate(true)
	c.SetAptUpgrade(true)

	// juju requires git for managing charm directories.
	c.AddPackage("git")
	c.AddPackage("curl")
	c.AddPackage("cpu-checker")
	c.AddPackage("bridge-utils")
	c.AddPackage("rsyslog-gnutls")

	// Write out the apt proxy settings
	if (proxySettings != proxy.Settings{}) {
		filename := apt.ConfFile
		c.AddBootCmd(fmt.Sprintf(
			`[ -f %s ] || (printf '%%s\n' %s > %s)`,
			filename,
			shquote(apt.ProxyContent(proxySettings)),
			filename))
	}
}
Exemplo n.º 7
0
// AddAptCommands update the cloudinit.Config instance with the necessary
// packages, the request to do the apt-get update/upgrade on boot, and adds
// the apt proxy settings if there are any.
func AddAptCommands(
	proxySettings proxy.Settings,
	c *cloudinit.Config,
	addUpdateScripts bool,
	addUpgradeScripts bool,
) {
	// Check preconditions
	if c == nil {
		panic("c is nil")
	}

	// Bring packages up-to-date.
	c.SetAptUpdate(addUpdateScripts)
	c.SetAptUpgrade(addUpgradeScripts)
	c.SetAptGetWrapper("eatmydata")

	// If we're not doing an update, adding these packages is
	// meaningless.
	if addUpdateScripts {
		c.AddPackage("curl")
		c.AddPackage("cpu-checker")
		// TODO(axw) 2014-07-02 #1277359
		// Don't install bridge-utils in cloud-init;
		// leave it to the networker worker.
		c.AddPackage("bridge-utils")
		c.AddPackage("rsyslog-gnutls")
	}

	// Write out the apt proxy settings
	if (proxySettings != proxy.Settings{}) {
		filename := apt.ConfFile
		c.AddBootCmd(fmt.Sprintf(
			`[ -f %s ] || (printf '%%s\n' %s > %s)`,
			filename,
			shquote(apt.ProxyContent(proxySettings)),
			filename))
	}
}
Exemplo n.º 8
0
// AddAptCommands update the cloudinit.Config instance with the necessary
// packages, the request to do the apt-get update/upgrade on boot, and adds
// the apt proxy settings if there are any.
func AddAptCommands(proxySettings proxy.Settings, c *cloudinit.Config) {
	// Bring packages up-to-date.
	c.SetAptUpdate(true)
	c.SetAptUpgrade(true)
	c.SetAptGetWrapper("eatmydata")

	c.AddPackage("curl")
	c.AddPackage("cpu-checker")
	// TODO(axw) 2014-07-02 #1277359
	// Don't install bridge-utils in cloud-init;
	// leave it to the networker worker.
	c.AddPackage("bridge-utils")
	c.AddPackage("rsyslog-gnutls")

	// Write out the apt proxy settings
	if (proxySettings != proxy.Settings{}) {
		filename := apt.ConfFile
		c.AddBootCmd(fmt.Sprintf(
			`[ -f %s ] || (printf '%%s\n' %s > %s)`,
			filename,
			shquote(apt.ProxyContent(proxySettings)),
			filename))
	}
}
Exemplo n.º 9
0
func (s *AptSuite) TestAptProxyContentEmpty(c *gc.C) {
	output := apt.ProxyContent(proxy.Settings{})
	c.Assert(output, gc.Equals, "")
}