func (s *AuthKeysSuite) SetUpTest(c *gc.C) { s.LoggingSuite.SetUpTest(c) old := osenv.Home() newhome := c.MkDir() osenv.SetHome(newhome) s.AddCleanup(func(*gc.C) { osenv.SetHome(old) }) s.dotssh = filepath.Join(newhome, ".ssh") err := os.Mkdir(s.dotssh, 0755) c.Assert(err, gc.IsNil) }
func (s *JujuConnSuite) tearDownConn(c *gc.C) { serverAlive := testing.MgoServer.Addr() != "" // Bootstrap will set the admin password, and render non-authorized use // impossible. s.State may still hold the right password, so try to reset // the password so that the MgoSuite soft-resetting works. If that fails, // it will still work, but it will take a while since it has to kill the // whole database and start over. if err := s.State.SetAdminMongoPassword(""); err != nil && serverAlive { c.Logf("cannot reset admin password: %v", err) } err := s.Conn.Close() if serverAlive { c.Assert(err, gc.IsNil) } err = s.APIConn.Close() if serverAlive { c.Assert(err, gc.IsNil) } dummy.Reset() s.Conn = nil s.State = nil osenv.SetHome(s.oldHome) osenv.SetJujuHome(s.oldJujuHome) s.oldHome = "" s.RootDir = "" }
func (h *FakeHome) Restore() { osenv.SetJujuHome(h.oldJujuHome) for name, value := range h.oldEnvironment { os.Setenv(name, value) } osenv.SetHome(h.oldHomeEnv) }
func (s *ConfigSuite) TearDownTest(c *gc.C) { osenv.SetHome(s.savedHome) os.Setenv("AWS_ACCESS_KEY_ID", s.savedAccessKey) os.Setenv("AWS_SECRET_ACCESS_KEY", s.savedSecretKey) delete(aws.Regions, "configtest") s.LoggingSuite.TearDownTest(c) }
func (s *TestingEnvironSuite) SetUpTest(c *gc.C) { s.home = osenv.Home() s.jujuHome = os.Getenv("JUJU_HOME") osenv.SetHome("/home/eric") os.Setenv("JUJU_HOME", "/home/eric/juju") osenv.SetJujuHome("/home/eric/juju") }
func (s *InitJujuHomeSuite) TestHome(c *gc.C) { osHome := c.MkDir() os.Setenv("JUJU_HOME", "") osenv.SetHome(osHome) err := juju.InitJujuHome() c.Assert(err, gc.IsNil) c.Assert(osenv.JujuHome(), gc.Equals, filepath.Join(osHome, ".juju")) }
func (s *importSuite) TestHome(c *gc.C) { s.PatchEnvironment("HOMEPATH", "") s.PatchEnvironment("HOMEDRIVE", "") drive := "P:" path := `\home\foo\bar` h := drive + path osenv.SetHome(h) c.Check(os.Getenv("HOMEPATH"), gc.Equals, path) c.Check(os.Getenv("HOMEDRIVE"), gc.Equals, drive) c.Check(osenv.Home(), gc.Equals, h) // now test that if we only set the path, we don't mess with the drive path2 := `\home\someotherfoo\bar` osenv.SetHome(path2) c.Check(os.Getenv("HOMEPATH"), gc.Equals, path2) c.Check(os.Getenv("HOMEDRIVE"), gc.Equals, drive) c.Check(osenv.Home(), gc.Equals, drive+path2) }
func (s *ConfigSuite) SetUpTest(c *gc.C) { s.LoggingSuite.SetUpTest(c) s.savedHome = osenv.Home() s.savedAccessKey = os.Getenv("AWS_ACCESS_KEY_ID") s.savedSecretKey = os.Getenv("AWS_SECRET_ACCESS_KEY") home := c.MkDir() sshDir := filepath.Join(home, ".ssh") err := os.Mkdir(sshDir, 0777) c.Assert(err, gc.IsNil) err = ioutil.WriteFile(filepath.Join(sshDir, "id_rsa.pub"), []byte("sshkey\n"), 0666) c.Assert(err, gc.IsNil) osenv.SetHome(home) os.Setenv("AWS_ACCESS_KEY_ID", testAuth.AccessKey) os.Setenv("AWS_SECRET_ACCESS_KEY", testAuth.SecretKey) aws.Regions["configtest"] = configTestRegion }
func MakeEmptyFakeHomeWithoutJuju(c *gc.C) *FakeHome { oldHomeEnv := osenv.Home() oldEnvironment := make(map[string]string) for _, name := range []string{ osenv.JujuHomeEnvKey, osenv.JujuEnvEnvKey, osenv.JujuLoggingConfigEnvKey, } { oldEnvironment[name] = os.Getenv(name) } fakeHome := c.MkDir() osenv.SetHome(fakeHome) os.Setenv(osenv.JujuHomeEnvKey, "") os.Setenv(osenv.JujuEnvEnvKey, "") os.Setenv(osenv.JujuLoggingConfigEnvKey, "") jujuHome := filepath.Join(fakeHome, ".juju") oldJujuHome := osenv.SetJujuHome(jujuHome) return &FakeHome{ oldHomeEnv: oldHomeEnv, oldEnvironment: oldEnvironment, oldJujuHome: oldJujuHome, files: []TestFile{}, } }
func (s *fileSuite) TearDownTest(c *gc.C) { err := osenv.SetHome(s.oldHome) c.Assert(err, gc.IsNil) }
func (s *fileSuite) SetUpTest(c *gc.C) { s.oldHome = osenv.Home() err := osenv.SetHome("/home/test-user") c.Assert(err, gc.IsNil) }
func (s *TestingEnvironSuite) TearDownTest(c *gc.C) { osenv.SetHome(s.home) os.Setenv("JUJU_HOME", s.jujuHome) }
func (s *JujuConnSuite) setUpConn(c *gc.C) { if s.RootDir != "" { panic("JujuConnSuite.setUpConn without teardown") } s.RootDir = c.MkDir() s.oldHome = osenv.Home() home := filepath.Join(s.RootDir, "/home/ubuntu") err := os.MkdirAll(home, 0777) c.Assert(err, gc.IsNil) osenv.SetHome(home) s.oldJujuHome = osenv.SetJujuHome(filepath.Join(home, ".juju")) err = os.Mkdir(osenv.JujuHome(), 0777) c.Assert(err, gc.IsNil) err = os.MkdirAll(s.DataDir(), 0777) c.Assert(err, gc.IsNil) s.PatchEnvironment(osenv.JujuEnvEnvKey, "") // TODO(rog) remove these files and add them only when // the tests specifically need them (in cmd/juju for example) s.writeSampleConfig(c, osenv.JujuHomePath("environments.yaml")) err = ioutil.WriteFile(osenv.JujuHomePath("dummyenv-cert.pem"), []byte(testing.CACert), 0666) c.Assert(err, gc.IsNil) err = ioutil.WriteFile(osenv.JujuHomePath("dummyenv-private-key.pem"), []byte(testing.CAKey), 0600) c.Assert(err, gc.IsNil) store, err := configstore.Default() c.Assert(err, gc.IsNil) s.ConfigStore = store ctx := testing.Context(c) environ, err := environs.PrepareFromName("dummyenv", ctx, s.ConfigStore) c.Assert(err, gc.IsNil) // sanity check we've got the correct environment. c.Assert(environ.Name(), gc.Equals, "dummyenv") s.PatchValue(&dummy.DataDir, s.DataDir()) s.LogDir = c.MkDir() s.PatchValue(&dummy.LogDir, s.LogDir) versions := PreferredDefaultVersions(environ.Config(), version.Binary{Number: version.Current.Number, Series: "precise", Arch: "amd64"}) versions = append(versions, version.Current) // Upload tools for both preferred and fake default series envtesting.MustUploadFakeToolsVersions(environ.Storage(), versions...) c.Assert(bootstrap.Bootstrap(ctx, environ, environs.BootstrapParams{}), gc.IsNil) s.BackingState = environ.(GetStater).GetStateInAPIServer() conn, err := juju.NewConn(environ) c.Assert(err, gc.IsNil) s.Conn = conn s.State = conn.State apiConn, err := juju.NewAPIConn(environ, api.DialOpts{}) c.Assert(err, gc.IsNil) s.APIConn = apiConn s.APIState = apiConn.State s.environ = environ }
func (s *InitJujuHomeSuite) TestError(c *gc.C) { os.Setenv("JUJU_HOME", "") osenv.SetHome("") err := juju.InitJujuHome() c.Assert(err, gc.ErrorMatches, "cannot determine juju home.*") }
func (s *InitJujuHomeSuite) TearDownTest(c *gc.C) { osenv.SetHome(s.originalHome) os.Setenv("JUJU_HOME", s.originalJujuHome) s.LoggingSuite.TearDownTest(c) }