func (s *MachineEnvironmentWatcherSuite) updateConfig(c *gc.C) (osenv.ProxySettings, osenv.ProxySettings) { proxySettings := osenv.ProxySettings{ Http: "http proxy", Https: "https proxy", Ftp: "ftp proxy", NoProxy: "no proxy", } attrs := map[string]interface{}{} for k, v := range config.ProxyConfigMap(proxySettings) { attrs[k] = v } // We explicitly set apt proxy settings as well to show that it is the apt // settings that are used for the apt config, and not just the normal // proxy settings which is what we would get if we don't explicitly set // apt values. aptProxySettings := osenv.ProxySettings{ Http: "apt http proxy", Https: "apt https proxy", Ftp: "apt ftp proxy", } for k, v := range config.AptProxyConfigMap(aptProxySettings) { attrs[k] = v } err := s.State.UpdateEnvironConfig(attrs, nil, nil) c.Assert(err, gc.IsNil) return proxySettings, aptProxySettings }
func (s *MachineSuite) TestMachineEnvironWorker(c *gc.C) { proxyDir := c.MkDir() s.PatchValue(&machineenvironmentworker.ProxyDirectory, proxyDir) s.PatchValue(&utils.AptConfFile, filepath.Join(proxyDir, "juju-apt-proxy")) s.primeAgent(c, version.Current, state.JobHostUnits) // Make sure there are some proxy settings to write. proxySettings := osenv.ProxySettings{ Http: "http proxy", Https: "https proxy", Ftp: "ftp proxy", } updateAttrs := config.ProxyConfigMap(proxySettings) err := s.State.UpdateEnvironConfig(updateAttrs, nil, nil) c.Assert(err, gc.IsNil) s.assertJobWithAPI(c, state.JobHostUnits, func(conf agent.Config, st *api.State) { for { select { case <-time.After(coretesting.LongWait): c.Fatalf("timeout while waiting for proxy settings to change") case <-time.After(10 * time.Millisecond): _, err := os.Stat(utils.AptConfFile) if os.IsNotExist(err) { continue } c.Assert(err, gc.IsNil) return } } }) }
func (*ConfigSuite) TestProxyConfigMap(c *gc.C) { defer makeFakeHome(c).Restore() cfg := newTestConfig(c, testing.Attrs{}) proxy := osenv.ProxySettings{ Http: "http proxy", Https: "https proxy", Ftp: "ftp proxy", NoProxy: "no proxy", } cfg, err := cfg.Apply(config.ProxyConfigMap(proxy)) c.Assert(err, gc.IsNil) c.Assert(cfg.ProxySettings(), gc.DeepEquals, proxy) // Apt proxy and proxy differ by the content of the no-proxy values. proxy.NoProxy = "" c.Assert(cfg.AptProxySettings(), gc.DeepEquals, proxy) }