func (s *DestroySuite) TestIgnoreNoVolumeSupport(c *gc.C) { staticProvider := &dummy.StorageProvider{ IsDynamic: true, StorageScope: storage.ScopeEnviron, SupportsFunc: func(storage.StorageKind) bool { return false }, } env := &mockEnviron{ config: configGetter(c), allInstances: func() ([]instance.Instance, error) { return nil, environs.ErrNoInstances }, storageProviders: storage.StaticProviderRegistry{ map[storage.ProviderType]storage.Provider{ "static": staticProvider, }, }, } err := common.Destroy(env) c.Assert(err, jc.ErrorIsNil) // common.Destroy will ignore storage providers that don't support // volumes (until we have persistent filesystems, that is). staticProvider.CheckCallNames(c, "Dynamic", "Scope", "Supports") }
func (e *Environ) Destroy() error { err := common.Destroy(e) if err != nil { return errors.Trace(err) } return e.firewaller.DeleteGlobalGroups() }
func (s *DestroySuite) TestDestroyVolumeErrors(c *gc.C) { volumeSource := &dummy.VolumeSource{ ListVolumesFunc: func() ([]string, error) { return []string{"vol-0", "vol-1", "vol-2"}, nil }, DestroyVolumesFunc: func(ids []string) []error { return []error{ nil, errors.New("cannot destroy vol-1"), errors.New("cannot destroy vol-2"), } }, } staticProvider := &dummy.StorageProvider{ IsDynamic: true, StorageScope: storage.ScopeEnviron, VolumeSourceFunc: func(*config.Config, *storage.Config) (storage.VolumeSource, error) { return volumeSource, nil }, } registry.RegisterProvider("environ", staticProvider) defer registry.RegisterProvider("environ", nil) registry.RegisterEnvironStorageProviders("anything, really", "environ") defer registry.ResetEnvironStorageProviders("anything, really") env := &mockEnviron{ config: configGetter(c), allInstances: func() ([]instance.Instance, error) { return nil, environs.ErrNoInstances }, } err := common.Destroy(env) c.Assert(err, gc.ErrorMatches, "destroying storage: destroying volumes: cannot destroy vol-1, cannot destroy vol-2") }
func (s *DestroySuite) TestSuccess(c *gc.C) { s.PatchValue(&jujuversion.Current, testing.FakeVersionNumber) stor := newStorage(s, c) err := stor.Put("somewhere", strings.NewReader("stuff"), 5) c.Assert(err, jc.ErrorIsNil) env := &mockEnviron{ storage: stor, allInstances: func() ([]instance.Instance, error) { return []instance.Instance{ &mockInstance{id: "one"}, }, nil }, stopInstances: func(ids []instance.Id) error { c.Assert(ids, gc.HasLen, 1) c.Assert(ids[0], gc.Equals, instance.Id("one")) return nil }, config: configGetter(c), } err = common.Destroy(env) c.Assert(err, jc.ErrorIsNil) // common.Destroy doesn't touch provider/object storage anymore. r, err := stor.Get("somewhere") c.Assert(err, jc.ErrorIsNil) r.Close() }
func (e *Environ) Destroy() error { err := common.Destroy(e) if err != nil { return errors.Trace(err) } // Delete all security groups remaining in the model. return e.firewaller.DeleteAllModelGroups() }
func (s *DestroySuite) TestCannotGetInstances(c *gc.C) { env := &mockEnviron{ allInstances: func() ([]instance.Instance, error) { return nil, fmt.Errorf("nope") }, } err := common.Destroy(env) c.Assert(err, gc.ErrorMatches, "nope") }
func (s *DestroySuite) TestCannotTrashStorageWhenNoInstances(c *gc.C) { env := &mockEnviron{ storage: &mockStorage{removeAllErr: fmt.Errorf("noes!")}, allInstances: func() ([]instance.Instance, error) { return nil, environs.ErrNoInstances }, } err := common.Destroy(env) c.Assert(err, gc.ErrorMatches, "noes!") }
func (s *DestroySuite) TestSuccessWhenNoInstances(c *gc.C) { stor := newStorage(s, c) err := stor.Put("elsewhere", strings.NewReader("stuff"), 5) c.Assert(err, jc.ErrorIsNil) env := &mockEnviron{ storage: stor, allInstances: func() ([]instance.Instance, error) { return nil, environs.ErrNoInstances }, config: configGetter(c), } err = common.Destroy(env) c.Assert(err, jc.ErrorIsNil) }
func (s *DestroySuite) TestSuccessWhenNoInstances(c *gc.C) { stor := newStorage(s, c) err := stor.Put("elsewhere", strings.NewReader("stuff"), 5) c.Assert(err, gc.IsNil) env := &mockEnviron{ storage: stor, allInstances: func() ([]instance.Instance, error) { return nil, environs.ErrNoInstances }, } err = common.Destroy(env) c.Assert(err, gc.IsNil) _, err = stor.Get("elsewhere") c.Assert(err, jc.Satisfies, errors.IsNotFound) }
func (e *Environ) Destroy() error { err := common.Destroy(e) if err != nil { return errors.Trace(err) } cfg := e.Config() if cfg.UUID() == cfg.ControllerUUID() { // In case any hosted environment hasn't been cleaned up yet, // we also attempt to delete their resources when the controller // environment is destroyed. if err := e.destroyControllerManagedEnvirons(); err != nil { return errors.Annotate(err, "destroying managed environs") } } // Delete all security groups remaining in the model. return e.firewaller.DeleteAllGroups() }
func (s *DestroySuite) TestCannotStopInstances(c *gc.C) { env := &mockEnviron{ allInstances: func() ([]instance.Instance, error) { return []instance.Instance{ &mockInstance{id: "one"}, &mockInstance{id: "another"}, }, nil }, stopInstances: func(ids []instance.Id) error { c.Assert(ids, gc.HasLen, 2) c.Assert(ids[0], gc.Equals, instance.Id("one")) c.Assert(ids[1], gc.Equals, instance.Id("another")) return fmt.Errorf("nah") }, } err := common.Destroy(env) c.Assert(err, gc.ErrorMatches, "nah") }
func (s *DestroySuite) TestCannotTrashStorage(c *gc.C) { env := &mockEnviron{ storage: &mockStorage{removeAllErr: fmt.Errorf("noes!")}, allInstances: func() ([]instance.Instance, error) { return []instance.Instance{ &mockInstance{id: "one"}, &mockInstance{id: "another"}, }, nil }, stopInstances: func(ids []instance.Id) error { c.Assert(ids, gc.HasLen, 2) c.Assert(ids[0], gc.Equals, instance.Id("one")) c.Assert(ids[1], gc.Equals, instance.Id("another")) return nil }, config: configGetter(c), } err := common.Destroy(env) c.Assert(err, gc.ErrorMatches, "noes!") }
func (s *DestroySuite) TestSuccessWhenStorageErrors(c *gc.C) { // common.Destroy doesn't touch provider/object storage anymore, // so failing storage should not affect success. env := &mockEnviron{ storage: &mockStorage{removeAllErr: fmt.Errorf("noes!")}, allInstances: func() ([]instance.Instance, error) { return []instance.Instance{ &mockInstance{id: "one"}, &mockInstance{id: "another"}, }, nil }, stopInstances: func(ids []instance.Id) error { c.Assert(ids, gc.HasLen, 2) c.Assert(ids[0], gc.Equals, instance.Id("one")) c.Assert(ids[1], gc.Equals, instance.Id("another")) return nil }, config: configGetter(c), } err := common.Destroy(env) c.Assert(err, jc.ErrorIsNil) }
func (s *DestroySuite) TestIgnoreMachineScopedVolumes(c *gc.C) { staticProvider := &dummy.StorageProvider{ IsDynamic: true, StorageScope: storage.ScopeMachine, } registry.RegisterProvider("machine", staticProvider) defer registry.RegisterProvider("machine", nil) registry.RegisterEnvironStorageProviders("anything, really", "machine") defer registry.ResetEnvironStorageProviders("anything, really") env := &mockEnviron{ config: configGetter(c), allInstances: func() ([]instance.Instance, error) { return nil, environs.ErrNoInstances }, } err := common.Destroy(env) c.Assert(err, jc.ErrorIsNil) // common.Destroy will ignore machine-scoped storage providers. staticProvider.CheckCallNames(c, "Dynamic", "Scope") }
func (s *DestroySuite) TestDestroyEnvScopedVolumes(c *gc.C) { volumeSource := &dummy.VolumeSource{ ListVolumesFunc: func() ([]string, error) { return []string{"vol-0", "vol-1", "vol-2"}, nil }, DestroyVolumesFunc: func(ids []string) ([]error, error) { return make([]error, len(ids)), nil }, } storageProvider := &dummy.StorageProvider{ IsDynamic: true, StorageScope: storage.ScopeEnviron, VolumeSourceFunc: func(*storage.Config) (storage.VolumeSource, error) { return volumeSource, nil }, } env := &mockEnviron{ config: configGetter(c), allInstances: func() ([]instance.Instance, error) { return nil, environs.ErrNoInstances }, storageProviders: storage.StaticProviderRegistry{ map[storage.ProviderType]storage.Provider{ "environ": storageProvider, }, }, } err := common.Destroy(env) c.Assert(err, jc.ErrorIsNil) // common.Destroy will ignore machine-scoped storage providers. storageProvider.CheckCallNames(c, "Dynamic", "Scope", "Supports", "VolumeSource") volumeSource.CheckCalls(c, []gitjujutesting.StubCall{ {"ListVolumes", nil}, {"DestroyVolumes", []interface{}{[]string{"vol-0", "vol-1", "vol-2"}}}, }) }
func (s *DestroySuite) TestIgnoreMachineScopedVolumes(c *gc.C) { staticProvider := &dummy.StorageProvider{ IsDynamic: true, StorageScope: storage.ScopeMachine, } env := &mockEnviron{ config: configGetter(c), allInstances: func() ([]instance.Instance, error) { return nil, environs.ErrNoInstances }, storageProviders: storage.StaticProviderRegistry{ map[storage.ProviderType]storage.Provider{ "static": staticProvider, }, }, } err := common.Destroy(env) c.Assert(err, jc.ErrorIsNil) // common.Destroy will ignore machine-scoped storage providers. staticProvider.CheckCallNames(c, "Dynamic", "Scope") }
func (s *DestroySuite) TestSuccess(c *gc.C) { stor := newStorage(s, c) err := stor.Put("somewhere", strings.NewReader("stuff"), 5) c.Assert(err, gc.IsNil) env := &mockEnviron{ storage: stor, allInstances: func() ([]instance.Instance, error) { return []instance.Instance{ &mockInstance{id: "one"}, }, nil }, stopInstances: func(ids []instance.Id) error { c.Assert(ids, gc.HasLen, 1) c.Assert(ids[0], gc.Equals, instance.Id("one")) return nil }, } err = common.Destroy(env) c.Assert(err, gc.IsNil) _, err = stor.Get("somewhere") c.Assert(err, jc.Satisfies, errors.IsNotFound) }
func (s *DestroySuite) TestDestroyVolumeErrors(c *gc.C) { volumeSource := &dummy.VolumeSource{ ListVolumesFunc: func() ([]string, error) { return []string{"vol-0", "vol-1", "vol-2"}, nil }, DestroyVolumesFunc: func(ids []string) ([]error, error) { return []error{ nil, errors.New("cannot destroy vol-1"), errors.New("cannot destroy vol-2"), }, nil }, } storageProvider := &dummy.StorageProvider{ IsDynamic: true, StorageScope: storage.ScopeEnviron, VolumeSourceFunc: func(*storage.Config) (storage.VolumeSource, error) { return volumeSource, nil }, } env := &mockEnviron{ config: configGetter(c), allInstances: func() ([]instance.Instance, error) { return nil, environs.ErrNoInstances }, storageProviders: storage.StaticProviderRegistry{ map[storage.ProviderType]storage.Provider{ "environ": storageProvider, }, }, } err := common.Destroy(env) c.Assert(err, gc.ErrorMatches, "destroying storage: destroying volumes: cannot destroy vol-1, cannot destroy vol-2") }
func (env *joyentEnviron) Destroy() error { return errors.Trace(common.Destroy(env)) }
func (env *joyentEnviron) Destroy() error { return common.Destroy(env) }
// Destroy shuts down all known machines and destroys the // rest of the environment. Note that on some providers, // very recently started instances may not be destroyed // because they are not yet visible. // // When Destroy has been called, any Environ referring to the // same remote environment may become invalid func (env *environ) Destroy() error { // You can probably ignore this method; the common implementation should work. return common.Destroy(env) }
func (env *joyentEnviron) Destroy() error { if err := common.Destroy(env); err != nil { return errors.Trace(err) } return env.Storage().RemoveAll() }