func setupTestStorageSupport(c *gc.C, s *state.State) { stsetts := state.NewStateSettings(s) poolManager := poolmanager.New(stsetts) _, err := poolManager.Create(testPool, provider.LoopProviderType, map[string]interface{}{"it": "works"}) c.Assert(err, jc.ErrorIsNil) registry.RegisterEnvironStorageProviders("dummy", ec2.EBS_ProviderType) registry.RegisterEnvironStorageProviders("dummyenv", ec2.EBS_ProviderType) }
func (s *providerRegistrySuite) TestRegisterEnvironProvidersMultipleCalls(c *gc.C) { ptypeFoo := storage.ProviderType("foo") ptypeBar := storage.ProviderType("bar") registry.RegisterEnvironStorageProviders("ec2", ptypeFoo) registry.RegisterEnvironStorageProviders("ec2", ptypeBar) registry.RegisterEnvironStorageProviders("ec2", ptypeBar) c.Assert(registry.IsProviderSupported("ec2", ptypeFoo), jc.IsTrue) c.Assert(registry.IsProviderSupported("ec2", ptypeBar), jc.IsTrue) }
func (s *DestroySuite) TestIgnoreNoVolumeSupport(c *gc.C) { staticProvider := &dummy.StorageProvider{ IsDynamic: true, StorageScope: storage.ScopeEnviron, SupportsFunc: func(storage.StorageKind) bool { return false }, } registry.RegisterProvider("filesystem", staticProvider) defer registry.RegisterProvider("filesystem", nil) registry.RegisterEnvironStorageProviders("anything, really", "filesystem") 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 storage providers that don't support // volumes (until we have persistent filesystems, that is). staticProvider.CheckCallNames(c, "Dynamic", "Scope", "Supports") }
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 *assignCleanSuite) TestAssignUnitWithNonDynamicStorageCleanAvailable(c *gc.C) { registry.RegisterProvider("static", &dummy.StorageProvider{ IsDynamic: false, }) registry.RegisterEnvironStorageProviders("someprovider", "static") defer registry.RegisterProvider("static", nil) _, unit, _ := s.setupSingleStorage(c, "filesystem", "static") storageAttachments, err := s.State.UnitStorageAttachments(unit.UnitTag()) c.Assert(err, jc.ErrorIsNil) c.Assert(storageAttachments, gc.HasLen, 1) // Add a clean machine. clean, err := s.State.AddMachine("quantal", state.JobHostUnits) c.Assert(err, jc.ErrorIsNil) // assign the unit to a machine, requesting clean/empty. Since // the unit has non dynamic storage instances associated, // it will be forced onto a new machine. err = s.State.AssignUnit(unit, state.AssignCleanEmpty) c.Assert(err, jc.ErrorIsNil) // Check the machine on the unit is set. machineId, err := unit.AssignedMachineId() c.Assert(err, jc.ErrorIsNil) // Check that the machine isn't our clean one. c.Assert(machineId, gc.Not(gc.Equals), clean.Id()) }
func (s *EnvironSuite) TestDestroyEnvironmentWithPersistentVolumesFails(c *gc.C) { // Create a persistent volume. // TODO(wallyworld) - consider moving this to factory registry.RegisterEnvironStorageProviders("someprovider", ec2.EBS_ProviderType) pm := poolmanager.New(state.NewStateSettings(s.State)) _, err := pm.Create("persistent-block", ec2.EBS_ProviderType, map[string]interface{}{"persistent": "true"}) c.Assert(err, jc.ErrorIsNil) ch := s.AddTestingCharm(c, "storage-block2") storage := map[string]state.StorageConstraints{ "multi1to10": makeStorageCons("persistent-block", 1024, 1), } service := s.AddTestingServiceWithStorage(c, "storage-block2", ch, storage) unit, err := service.AddUnit() c.Assert(err, jc.ErrorIsNil) err = s.State.AssignUnit(unit, state.AssignCleanEmpty) c.Assert(err, jc.ErrorIsNil) volume1, err := s.State.StorageInstanceVolume(names.NewStorageTag("multi1to10/0")) c.Assert(err, jc.ErrorIsNil) volumeInfoSet := state.VolumeInfo{Size: 123, Persistent: true, VolumeId: "vol-ume"} err = s.State.SetVolumeInfo(volume1.VolumeTag(), volumeInfoSet) c.Assert(err, jc.ErrorIsNil) env, err := s.State.Environment() c.Assert(err, jc.ErrorIsNil) // TODO(wallyworld) when we can destroy/remove volume, ensure env can then be destroyed c.Assert(errors.Cause(env.Destroy()), gc.Equals, state.ErrPersistentVolumesExist) }
func (s *StorageStateSuiteBase) SetUpSuite(c *gc.C) { s.ConnSuite.SetUpSuite(c) registry.RegisterProvider("environscoped", &dummy.StorageProvider{ StorageScope: storage.ScopeEnviron, IsDynamic: true, }) registry.RegisterProvider("machinescoped", &dummy.StorageProvider{ StorageScope: storage.ScopeMachine, IsDynamic: true, }) registry.RegisterProvider("environscoped-block", &dummy.StorageProvider{ StorageScope: storage.ScopeEnviron, SupportsFunc: func(k storage.StorageKind) bool { return k == storage.StorageKindBlock }, IsDynamic: true, }) registry.RegisterProvider("static", &dummy.StorageProvider{ IsDynamic: false, }) registry.RegisterEnvironStorageProviders( "someprovider", "environscoped", "machinescoped", "environscoped-block", "static", ) s.AddSuiteCleanup(func(c *gc.C) { registry.RegisterProvider("environscoped", nil) registry.RegisterProvider("machinescoped", nil) registry.RegisterProvider("environscoped-block", nil) registry.RegisterProvider("static", nil) }) }
func setupMachineBoundStorageTests(c *gc.C, st *State) (*Machine, Volume, Filesystem, func() error) { registry.RegisterEnvironStorageProviders("someprovider", provider.LoopProviderType, provider.RootfsProviderType) // Make an unprovisioned machine with storage for tests to use. // TODO(axw) extend testing/factory to allow creating unprovisioned // machines. m, err := st.AddOneMachine(MachineTemplate{ Series: "quantal", Jobs: []MachineJob{JobHostUnits}, Volumes: []MachineVolumeParams{ {Volume: VolumeParams{Pool: "loop", Size: 2048}}, }, Filesystems: []MachineFilesystemParams{ {Filesystem: FilesystemParams{Pool: "rootfs", Size: 2048}}, }, }) c.Assert(err, jc.ErrorIsNil) va, err := m.VolumeAttachments() c.Assert(err, jc.ErrorIsNil) c.Assert(va, gc.HasLen, 1) v, err := st.Volume(va[0].Volume()) c.Assert(err, jc.ErrorIsNil) fa, err := st.MachineFilesystemAttachments(m.MachineTag()) c.Assert(err, jc.ErrorIsNil) c.Assert(fa, gc.HasLen, 1) f, err := st.Filesystem(fa[0].Filesystem()) c.Assert(err, jc.ErrorIsNil) return m, v, f, m.Destroy }
func init() { environs.RegisterProvider(providerType, azureEnvironProvider{}) // Register the Azure storage provider. registry.RegisterProvider(storageProviderType, &azureStorageProvider{}) registry.RegisterEnvironStorageProviders(providerType, storageProviderType) }
func init() { environs.RegisterProvider(providerType, maasEnvironProvider{}) //Register the MAAS specific storage providers. registry.RegisterProvider(maasStorageProviderType, &maasStorageProvider{}) registry.RegisterEnvironStorageProviders(providerType, maasStorageProviderType) }
func (s *watcherSuite) TestWatchMachineStorage(c *gc.C) { registry.RegisterProvider( "envscoped", &dummy.StorageProvider{ StorageScope: storage.ScopeEnviron, }, ) registry.RegisterEnvironStorageProviders("dummy", "envscoped") defer registry.RegisterProvider("envscoped", nil) f := factory.NewFactory(s.BackingState) f.MakeMachine(c, &factory.MachineParams{ Volumes: []state.MachineVolumeParams{{ Volume: state.VolumeParams{ Pool: "envscoped", Size: 1024, }, }}, }) var results params.MachineStorageIdsWatchResults args := params.Entities{Entities: []params.Entity{{ Tag: s.State.EnvironTag().String(), }}} err := s.stateAPI.APICall( "StorageProvisioner", s.stateAPI.BestFacadeVersion("StorageProvisioner"), "", "WatchVolumeAttachments", args, &results) c.Assert(err, jc.ErrorIsNil) c.Assert(results.Results, gc.HasLen, 1) result := results.Results[0] c.Assert(result.Error, gc.IsNil) w := watcher.NewVolumeAttachmentsWatcher(s.stateAPI, result) select { case changes, ok := <-w.Changes(): c.Assert(ok, jc.IsTrue) c.Assert(changes, jc.SameContents, []params.MachineStorageId{{ MachineTag: "machine-1", AttachmentTag: "volume-0", }}) case <-time.After(coretesting.LongWait): c.Fatalf("timed out waiting for change") } select { case <-w.Changes(): c.Fatalf("received unexpected change") case <-time.After(coretesting.ShortWait): } statetesting.AssertStop(c, w) select { case _, ok := <-w.Changes(): c.Assert(ok, jc.IsFalse) case <-time.After(coretesting.LongWait): c.Fatalf("timed out waiting for watcher channel to be closed") } }
func init() { environs.RegisterProvider(providerType, providerInstance) // Register the GCE specific providers. registry.RegisterProvider(storageProviderType, &storageProvider{}) // Inform the storage provider registry about the GCE providers. registry.RegisterEnvironStorageProviders(providerType, storageProviderType) }
func init() { // This will only happen in binaries that actually import this provider // somewhere. To enable a provider, import it in the "providers/all" // package; please do *not* import individual providers anywhere else, // except in direct tests for that provider. environs.RegisterProvider("cloudsigma", providerInstance) environs.RegisterImageDataSourceFunc("cloud sigma image source", getImageSource) registry.RegisterEnvironStorageProviders(providerType) }
func init() { environs.RegisterProvider(providerType, environProvider{}) //Register the AWS specific providers. registry.RegisterProvider(EBS_ProviderType, &ebsProvider{}) // Inform the storage provider registry about the AWS providers. registry.RegisterEnvironStorageProviders(providerType, EBS_ProviderType) }
func (s *providerRegistrySuite) TestSupportedEnvironProviders(c *gc.C) { ptypeFoo := storage.ProviderType("foo") ptypeBar := storage.ProviderType("bar") registry.RegisterEnvironStorageProviders("ec2", ptypeFoo, ptypeBar) c.Assert(registry.IsProviderSupported("ec2", ptypeFoo), jc.IsTrue) c.Assert(registry.IsProviderSupported("ec2", ptypeBar), jc.IsTrue) c.Assert(registry.IsProviderSupported("ec2", storage.ProviderType("foobar")), jc.IsFalse) c.Assert(registry.IsProviderSupported("openstack", ptypeBar), jc.IsFalse) }
func init() { osProvider := openstack.EnvironProvider{&rackspaceConfigurator{}, &firewallerFactory{}} providerInstance = &environProvider{ osProvider, } environs.RegisterProvider(providerType, providerInstance) registry.RegisterEnvironStorageProviders(providerType, openstack.CinderProviderType) }
func init() { environs.RegisterProvider(providerType, providerInstance) // TODO(wallyworld) - sort out policy for allowing loop provider registry.RegisterEnvironStorageProviders( providerType, storageprovider.HostLoopProviderType, ) }
func (s *assignCleanSuite) SetUpTest(c *gc.C) { c.Logf("assignment policy for this test: %q", s.policy) s.ConnSuite.SetUpTest(c) wordpress := s.AddTestingService(c, "wordpress", s.AddTestingCharm(c, "wordpress")) s.wordpress = wordpress pm := poolmanager.New(state.NewStateSettings(s.State)) _, err := pm.Create("loop-pool", provider.LoopProviderType, map[string]interface{}{}) c.Assert(err, jc.ErrorIsNil) registry.RegisterEnvironStorageProviders("someprovider", provider.LoopProviderType) }
func (s *withoutControllerSuite) registerStorageProviders(c *gc.C, names ...string) { types := make([]storage.ProviderType, len(names)) for i, name := range names { types[i] = storage.ProviderType(name) if name == "dynamic" { s.registerDynamicStorageProvider(c) } else if name == "static" { s.registerStaticStorageProvider(c) } else { c.Fatalf("unknown storage provider type: %q, expected static or dynamic", name) } } registry.RegisterEnvironStorageProviders("dummy", types...) }
func init() { environs.RegisterProvider(providerType, providerInstance) environs.RegisterImageDataSourceFunc("keystone catalog", getKeystoneImageSource) tools.RegisterToolsDataSourceFunc("keystone catalog", getKeystoneToolsSource) // Register the Openstack specific providers. registry.RegisterProvider( CinderProviderType, &cinderProvider{newOpenstackStorageAdapter}, ) // Register the Cinder provider with the Openstack provider. registry.RegisterEnvironStorageProviders(providerType, CinderProviderType) }
func (s *StorageStateSuiteBase) SetUpTest(c *gc.C) { s.ConnSuite.SetUpTest(c) // Create a default pool for block devices. pm := poolmanager.New(state.NewStateSettings(s.State)) _, err := pm.Create("loop-pool", provider.LoopProviderType, map[string]interface{}{}) c.Assert(err, jc.ErrorIsNil) registry.RegisterEnvironStorageProviders("someprovider", provider.LoopProviderType) // Create a pool that creates persistent block devices. _, err = pm.Create("persistent-block", "environscoped-block", map[string]interface{}{ "persistent": true, }) c.Assert(err, jc.ErrorIsNil) }
func (s *providerRegistrySuite) TestListEnvProviderKnownEnv(c *gc.C) { ptypeFoo := storage.ProviderType("foo") registry.RegisterEnvironStorageProviders("ec2", ptypeFoo) all, exists := registry.EnvironStorageProviders("ec2") c.Assert(exists, jc.IsTrue) c.Assert(len(all) > 0, jc.IsTrue) found := false for _, one := range all { if one == ptypeFoo { found = true break } } c.Assert(found, jc.IsTrue) }
func (s *ProvisionerSuite) TestProvisioningMachinesWithRequestedVolumes(c *gc.C) { // Set up a persistent pool. registry.RegisterProvider("static", &dummystorage.StorageProvider{IsDynamic: false}) registry.RegisterEnvironStorageProviders("dummy", "static") defer registry.RegisterProvider("static", nil) poolManager := poolmanager.New(state.NewStateSettings(s.State)) _, err := poolManager.Create("persistent-pool", "static", map[string]interface{}{"persistent": true}) c.Assert(err, jc.ErrorIsNil) p := s.newEnvironProvisioner(c) defer stop(c, p) // Add and provision a machine with volumes specified. requestedVolumes := []state.MachineVolumeParams{{ Volume: state.VolumeParams{Pool: "static", Size: 1024}, Attachment: state.VolumeAttachmentParams{}, }, { Volume: state.VolumeParams{Pool: "persistent-pool", Size: 2048}, Attachment: state.VolumeAttachmentParams{}, }} expectVolumeInfo := []storage.Volume{{ names.NewVolumeTag("1"), storage.VolumeInfo{ Size: 1024, }, }, { names.NewVolumeTag("2"), storage.VolumeInfo{ Size: 2048, Persistent: true, }, }} m, err := s.addMachineWithRequestedVolumes(requestedVolumes, s.defaultConstraints) c.Assert(err, jc.ErrorIsNil) inst := s.checkStartInstanceCustom( c, m, "pork", s.defaultConstraints, nil, nil, nil, expectVolumeInfo, false, nil, true, ) // Cleanup. c.Assert(m.EnsureDead(), gc.IsNil) s.checkStopInstances(c, inst) s.waitRemoved(c, m) }
func (s *provisionerSuite) SetUpSuite(c *gc.C) { s.JujuConnSuite.SetUpSuite(c) registry.RegisterProvider("environscoped", &dummy.StorageProvider{ StorageScope: storage.ScopeEnviron, }) registry.RegisterProvider("machinescoped", &dummy.StorageProvider{ StorageScope: storage.ScopeMachine, }) registry.RegisterEnvironStorageProviders( "dummy", "environscoped", "machinescoped", ) s.AddCleanup(func(c *gc.C) { registry.RegisterProvider("environscoped", nil) registry.RegisterProvider("machinescoped", nil) }) }
func init() { environProvider, storageProvider, err := NewProviders(ProviderConfig{ NewStorageClient: azurestorage.NewClient, StorageAccountNameGenerator: RandomStorageAccountName, }) if err != nil { panic(err) } environs.RegisterProvider(providerType, environProvider) registry.RegisterProvider(storageProviderType, storageProvider) registry.RegisterEnvironStorageProviders(providerType, storageProviderType) // TODO(axw) register an image metadata data source that queries // the Azure image registry, and introduce a way to disable the // common simplestreams source. }
func (s *CleanupSuite) TestCleanupStorageInstances(c *gc.C) { ch := s.AddTestingCharm(c, "storage-block") registry.RegisterEnvironStorageProviders("someprovider", provider.LoopProviderType) storage := map[string]state.StorageConstraints{ "data": makeStorageCons("loop", 1024, 1), } service := s.AddTestingServiceWithStorage(c, "storage-block", ch, storage) u, err := service.AddUnit() c.Assert(err, jc.ErrorIsNil) // check no cleanups s.assertDoesNotNeedCleanup(c) // this tag matches the storage instance created for the unit above. storageTag := names.NewStorageTag("data/0") si, err := s.State.StorageInstance(storageTag) c.Assert(err, jc.ErrorIsNil) c.Assert(si.Life(), gc.Equals, state.Alive) // destroy storage instance and run cleanups err = s.State.DestroyStorageInstance(storageTag) c.Assert(err, jc.ErrorIsNil) si, err = s.State.StorageInstance(storageTag) c.Assert(err, jc.ErrorIsNil) c.Assert(si.Life(), gc.Equals, state.Dying) sa, err := s.State.UnitStorageAttachments(u.UnitTag()) c.Assert(err, jc.ErrorIsNil) c.Assert(sa, gc.HasLen, 1) c.Assert(sa[0].Life(), gc.Equals, state.Alive) s.assertCleanupRuns(c) // After running the cleanup, the attachment should be dying. sa, err = s.State.UnitStorageAttachments(u.UnitTag()) c.Assert(err, jc.ErrorIsNil) c.Assert(sa, gc.HasLen, 1) c.Assert(sa[0].Life(), gc.Equals, state.Dying) // check no cleanups s.assertDoesNotNeedCleanup(c) }
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 { return make([]error, len(ids)) }, } 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, jc.ErrorIsNil) // common.Destroy will ignore machine-scoped storage providers. staticProvider.CheckCallNames(c, "Dynamic", "Scope", "Supports", "VolumeSource") volumeSource.CheckCalls(c, []gitjujutesting.StubCall{ {"ListVolumes", nil}, {"DestroyVolumes", []interface{}{[]string{"vol-0", "vol-1", "vol-2"}}}, }) }
func (s *assignCleanSuite) TestAssignToMachineErrors(c *gc.C) { registry.RegisterProvider("static", &dummy.StorageProvider{ IsDynamic: false, }) registry.RegisterEnvironStorageProviders("someprovider", "static") defer registry.RegisterProvider("static", nil) _, unit, _ := s.setupSingleStorage(c, "filesystem", "static") machine, err := s.State.AddMachine("quantal", state.JobHostUnits) c.Assert(err, jc.ErrorIsNil) err = unit.AssignToMachine(machine) c.Assert( err, gc.ErrorMatches, `cannot assign unit "storage-filesystem/0" to machine 0: "static" storage provider does not support dynamic storage`, ) container, err := s.State.AddMachineInsideMachine(state.MachineTemplate{ Series: "quantal", Jobs: []state.MachineJob{state.JobHostUnits}, }, machine.Id(), instance.LXC) c.Assert(err, jc.ErrorIsNil) err = unit.AssignToMachine(container) c.Assert(err, gc.ErrorMatches, `cannot assign unit "storage-filesystem/0" to machine 0/lxc/0: adding storage to lxc container not supported`) }
func (s *CleanupSuite) SetUpSuite(c *gc.C) { s.ConnSuite.SetUpSuite(c) registry.RegisterEnvironStorageProviders("someprovider", provider.LoopProviderType) }