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 (s *SimpleStreamsToolsSuite) resetEnv(c *gc.C, attrs map[string]interface{}) { version.Current = s.origCurrentVersion dummy.Reset() cfg, err := config.New(config.NoDefaults, dummy.SampleConfig().Merge(attrs)) c.Assert(err, gc.IsNil) env, err := environs.Prepare(cfg, testing.Context(c), configstore.NewMem()) c.Assert(err, gc.IsNil) s.env = env s.removeTools(c) }
// makeEmptyFakeHome creates a faked home without envtools. func makeEmptyFakeHome(c *gc.C) (environs.Environ, *coretesting.FakeHome) { fake := coretesting.MakeFakeHome(c, envConfig) dummy.Reset() store, err := configstore.Default() c.Assert(err, gc.IsNil) env, err := environs.PrepareFromName("peckham", nullContext(c), store) c.Assert(err, gc.IsNil) envtesting.RemoveAllTools(c, env) return env, fake }
func (s *bootstrapSuite) TestBootstrapTools(c *gc.C) { allTests := append(envtesting.BootstrapToolsTests, bootstrapSetAgentVersionTests...) // version.Current is set in the loop so ensure it is restored later. s.PatchValue(&version.Current, version.Current) for i, test := range allTests { c.Logf("\ntest %d: %s", i, test.Info) dummy.Reset() attrs := dummy.SampleConfig().Merge(coretesting.Attrs{ "state-server": false, "development": test.Development, "default-series": test.DefaultSeries, }) if test.AgentVersion != version.Zero { attrs["agent-version"] = test.AgentVersion.String() } cfg, err := config.New(config.NoDefaults, attrs) c.Assert(err, gc.IsNil) env, err := environs.Prepare(cfg, coretesting.Context(c), configstore.NewMem()) c.Assert(err, gc.IsNil) envtesting.RemoveAllTools(c, env) version.Current = test.CliVersion envtesting.AssertUploadFakeToolsVersions(c, env.Storage(), test.Available...) // Remove the default tools URL from the search path, just look in cloud storage. s.PatchValue(&envtools.DefaultBaseURL, "") cons := constraints.Value{} if test.Arch != "" { cons = constraints.MustParse("arch=" + test.Arch) } err = bootstrap.Bootstrap(coretesting.Context(c), env, environs.BootstrapParams{Constraints: cons}) if test.Err != "" { c.Check(err, gc.NotNil) if err != nil { stripped := strings.Replace(err.Error(), "\n", "", -1) c.Check(stripped, gc.Matches, ".*"+stripped) } continue } else { c.Check(err, gc.IsNil) } unique := map[version.Number]bool{} for _, expected := range test.Expect { unique[expected.Number] = true } for expectAgentVersion := range unique { agentVersion, ok := env.Config().AgentVersion() c.Check(ok, gc.Equals, true) c.Check(agentVersion, gc.Equals, expectAgentVersion) } } }
func (s *ImageMetadataSuite) TestImageMetadataBadArgs(c *gc.C) { home := testing.MakeSampleHome(c) s.AddCleanup(func(*gc.C) { home.Restore() dummy.Reset() }) for i, t := range errTests { c.Logf("test: %d", i) ctx := testing.Context(c) code := cmd.Main(&ImageMetadataCommand{}, ctx, t.args) c.Check(code, gc.Equals, 1) } }
func (s *ConnSuite) TearDownTest(c *gc.C) { if s.conn == nil { return } err := s.conn.State.SetAdminMongoPassword("") c.Assert(err, gc.IsNil) err = s.conn.Environ.Destroy() c.Check(err, gc.IsNil) assertClose(c, s.conn) s.conn = nil dummy.Reset() s.ToolsFixture.TearDownTest(c) s.MgoSuite.TearDownTest(c) s.LoggingSuite.TearDownTest(c) }
func (s *ToolsMetadataSuite) SetUpTest(c *gc.C) { s.LoggingSuite.SetUpTest(c) s.home = coretesting.MakeSampleHome(c) s.AddCleanup(func(*gc.C) { s.home.Restore() dummy.Reset() loggo.ResetLoggers() }) env, err := environs.PrepareFromName("erewhemos", coretesting.Context(c), configstore.NewMem()) c.Assert(err, gc.IsNil) s.env = env envtesting.RemoveAllTools(c, s.env) loggo.GetLogger("").SetLogLevel(loggo.INFO) // Switch the default tools location. s.publicStorageDir = c.MkDir() s.PatchValue(&tools.DefaultBaseURL, s.publicStorageDir) }
func (s *APIEndpointForEnvSuite) TestAPIEndpointNotCached(c *gc.C) { defer coretesting.MakeMultipleEnvHome(c).Restore() store, err := configstore.Default() c.Assert(err, gc.IsNil) ctx := coretesting.Context(c) env, err := environs.PrepareFromName("erewhemos", ctx, store) c.Assert(err, gc.IsNil) defer dummy.Reset() envtesting.UploadFakeTools(c, env.Storage()) err = bootstrap.Bootstrap(ctx, env, environs.BootstrapParams{}) c.Assert(err, gc.IsNil) // Note: if we get Bootstrap to start caching the API endpoint // immediately, we'll still want to have this test for compatibility. // We can just write blank info instead of reading and checking it is empty. savedInfo, err := store.ReadInfo("erewhemos") c.Assert(err, gc.IsNil) // Ensure that the data isn't cached c.Check(savedInfo.APIEndpoint().Addresses, gc.HasLen, 0) called := 0 expectState := &mockAPIState{ apiHostPorts: [][]instance.HostPort{ instance.AddressesWithPort([]instance.Address{instance.NewAddress("0.1.2.3", instance.NetworkUnknown)}, 1234), }, } apiOpen := func(apiInfo *api.Info, opts api.DialOpts) (juju.APIState, error) { c.Check(apiInfo.Tag, gc.Equals, "user-admin") c.Check(string(apiInfo.CACert), gc.Equals, coretesting.CACert) c.Check(apiInfo.Password, gc.Equals, coretesting.DefaultMongoPassword) c.Check(opts, gc.DeepEquals, api.DefaultDialOpts()) called++ return expectState, nil } endpoint, err := juju.APIEndpointInStore("erewhemos", false, store, apiOpen) c.Assert(err, gc.IsNil) c.Assert(called, gc.Equals, 1) c.Check(endpoint.Addresses, gc.DeepEquals, []string{"0.1.2.3:1234"}) }
func (s *suite) TearDownTest(c *gc.C) { dummy.Reset() s.LoggingSuite.TearDownTest(c) }
func (s *checkEnvironmentSuite) TearDownTest(c *gc.C) { dummy.Reset() }
func (s *SimpleStreamsToolsSuite) TearDownTest(c *gc.C) { dummy.Reset() version.Current = s.origCurrentVersion s.ToolsFixture.TearDownTest(c) s.LoggingSuite.TearDownTest(c) }
func (s *URLsSuite) TearDownTest(c *gc.C) { dummy.Reset() s.home.Restore() }
func (s *ConfigSuite) TearDownTest(c *gc.C) { s.LoggingSuite.TearDownTest(c) dummy.Reset() }
func (s *BootstrapSuite) TearDownTest(c *gc.C) { s.ToolsFixture.TearDownTest(c) s.MgoSuite.TearDownTest(c) s.LoggingSuite.TearDownTest(c) dummy.Reset() }
func (s *BootstrapSuite) TearDownSuite(c *gc.C) { s.MgoSuite.TearDownSuite(c) s.LoggingSuite.TearDownSuite(c) dummy.Reset() }
func (*OpenSuite) TearDownTest(c *gc.C) { dummy.Reset() }
func (s *syncToolsSuite) TearDownTest(c *gc.C) { syncTools = s.origSyncTools dummy.Reset() s.home.Restore() s.LoggingSuite.TearDownTest(c) }
func (s *environWatcherSuite) TearDownTest(c *gc.C) { dummy.Reset() s.LoggingSuite.TearDownTest(c) }
func (s *suite) TearDownTest(c *gc.C) { s.Tests.TearDownTest(c) dummy.Reset() }
func (cs *NewAPIConnSuite) TearDownTest(c *gc.C) { dummy.Reset() cs.ToolsFixture.TearDownTest(c) cs.LoggingSuite.TearDownTest(c) }
func (s *uploadSuite) TearDownTest(c *gc.C) { dummy.Reset() s.ToolsFixture.TearDownTest(c) s.LoggingSuite.TearDownTest(c) }
func (cs *NewAPIClientSuite) TearDownTest(c *gc.C) { dummy.Reset() cs.LoggingSuite.TearDownTest(c) }
func (s *syncSuite) tearDownTest(c *gc.C) { dummy.Reset() version.Current = s.origVersion s.ToolsFixture.TearDownTest(c) s.LoggingSuite.TearDownTest(c) }
func (s *datasourceSuite) TearDownTest(c *gc.C) { dummy.Reset() s.home.Restore() }
func (s *verifyStorageSuite) TearDownTest(c *gc.C) { dummy.Reset() s.LoggingSuite.TearDownTest(c) }