func (s *watchStorageAttachmentSuite) SetUpTest(c *gc.C) { s.storageTag = names.NewStorageTag("osd-devices/0") s.machineTag = names.NewMachineTag("0") s.unitTag = names.NewUnitTag("ceph/0") s.storageInstance = &fakeStorageInstance{ tag: s.storageTag, owner: s.machineTag, kind: state.StorageKindBlock, } s.volume = &fakeVolume{tag: names.NewVolumeTag("0")} s.volumeAttachmentWatcher = apiservertesting.NewFakeNotifyWatcher() s.volumeAttachmentWatcher.C <- struct{}{} s.blockDevicesWatcher = apiservertesting.NewFakeNotifyWatcher() s.blockDevicesWatcher.C <- struct{}{} s.storageAttachmentWatcher = apiservertesting.NewFakeNotifyWatcher() s.storageAttachmentWatcher.C <- struct{}{} s.st = &fakeStorage{ storageInstance: func(tag names.StorageTag) (state.StorageInstance, error) { return s.storageInstance, nil }, storageInstanceVolume: func(tag names.StorageTag) (state.Volume, error) { return s.volume, nil }, watchVolumeAttachment: func(names.MachineTag, names.VolumeTag) state.NotifyWatcher { return s.volumeAttachmentWatcher }, watchBlockDevices: func(names.MachineTag) state.NotifyWatcher { return s.blockDevicesWatcher }, watchStorageAttachment: func(names.StorageTag, names.UnitTag) state.NotifyWatcher { return s.storageAttachmentWatcher }, } }
func (*multiNotifyWatcherSuite) TestMultiNotifyWatcherStop(c *gc.C) { w0 := apiservertesting.NewFakeNotifyWatcher() w1 := apiservertesting.NewFakeNotifyWatcher() mw := common.NewMultiNotifyWatcher(w0, w1) wc := statetesting.NewNotifyWatcherC(c, nopSyncStarter{}, mw) wc.AssertOneChange() statetesting.AssertCanStopWhenSending(c, mw) wc.AssertClosed() }
func (s *watcherSuite) TestMigrationNotModelManager(c *gc.C) { id := s.resources.Register(apiservertesting.NewFakeNotifyWatcher()) s.authorizer.EnvironManager = false factory, err := common.Facades.GetFactory("MigrationMasterWatcher", 1) c.Assert(err, jc.ErrorIsNil) _, err = factory(s.st, s.resources, s.authorizer, id) c.Assert(err, gc.Equals, common.ErrPerm) }
func (s *watcherSuite) TestMigrationStatusWatcherNotAgent(c *gc.C) { id := s.resources.Register(apiservertesting.NewFakeNotifyWatcher()) s.authorizer.Tag = names.NewUserTag("frogdog") factory, err := common.Facades.GetFactory("MigrationStatusWatcher", 1) c.Assert(err, jc.ErrorIsNil) _, err = factory(nil, s.resources, s.authorizer, id) c.Assert(err, gc.Equals, common.ErrPerm) }
func (*multiNotifyWatcherSuite) TestMultiNotifyWatcher(c *gc.C) { w0 := apiservertesting.NewFakeNotifyWatcher() w1 := apiservertesting.NewFakeNotifyWatcher() mw := common.NewMultiNotifyWatcher(w0, w1) defer statetesting.AssertStop(c, mw) wc := statetesting.NewNotifyWatcherC(c, nopSyncStarter{}, mw) wc.AssertOneChange() w0.C <- struct{}{} wc.AssertOneChange() w1.C <- struct{}{} wc.AssertOneChange() w0.C <- struct{}{} w1.C <- struct{}{} wc.AssertOneChange() }
func (s *watcherSuite) TestMigrationStatusWatcherNoMigration(c *gc.C) { w := apiservertesting.NewFakeNotifyWatcher() id := s.resources.Register(w) s.authorizer.Tag = names.NewMachineTag("12") apiserver.PatchGetMigrationBackend(s, &fakeMigrationBackend{noMigration: true}) facade := s.getFacade(c, "MigrationStatusWatcher", 1, id).(migrationStatusWatcher) defer c.Check(facade.Stop(), jc.ErrorIsNil) result, err := facade.Next() c.Assert(err, jc.ErrorIsNil) c.Assert(result, jc.DeepEquals, params.MigrationStatus{ Phase: "NONE", }) }
func (s *watcherSuite) TestMigrationMasterWatcher(c *gc.C) { w := apiservertesting.NewFakeNotifyWatcher() id := s.resources.Register(w) s.authorizer.EnvironManager = true apiserver.PatchMigrationGetter(s, new(fakeModelMigrationGetter)) w.C <- struct{}{} facade := s.getFacade(c, "MigrationMasterWatcher", 1, id).(migrationMasterWatcher) result, err := facade.Next() c.Assert(err, jc.ErrorIsNil) defer c.Check(facade.Stop(), jc.ErrorIsNil) c.Assert(result, jc.DeepEquals, params.ModelMigrationTargetInfo{ ControllerTag: "model-uuid", Addrs: []string{"1.2.3.4:5555"}, CACert: "trust me", AuthTag: "user-admin", Password: "******", }) }
func (s *watcherSuite) TestMigrationStatusWatcher(c *gc.C) { w := apiservertesting.NewFakeNotifyWatcher() id := s.resources.Register(w) s.authorizer.Tag = names.NewMachineTag("12") apiserver.PatchGetMigrationBackend(s, new(fakeMigrationBackend)) apiserver.PatchGetControllerCACert(s, "no worries") facade := s.getFacade(c, "MigrationStatusWatcher", 1, id).(migrationStatusWatcher) defer c.Check(facade.Stop(), jc.ErrorIsNil) result, err := facade.Next() c.Assert(err, jc.ErrorIsNil) c.Assert(result, jc.DeepEquals, params.MigrationStatus{ MigrationId: "id", Attempt: 2, Phase: "IMPORT", SourceAPIAddrs: []string{"1.2.3.4:5", "2.3.4.5:6", "3.4.5.6:7"}, SourceCACert: "no worries", TargetAPIAddrs: []string{"1.2.3.4:5555"}, TargetCACert: "trust me", }) }
func (b *stubBackend) WatchMigrationStatus() (state.NotifyWatcher, error) { if b.watchError != nil { return nil, b.watchError } return apiservertesting.NewFakeNotifyWatcher(), nil }
func (m *stubMigration) WatchMinionReports() (state.NotifyWatcher, error) { m.stub.AddCall("ModelMigration.WatchMinionReports") return apiservertesting.NewFakeNotifyWatcher(), nil }
func (b *stubBackend) WatchForMigration() state.NotifyWatcher { b.stub.AddCall("WatchForMigration") return apiservertesting.NewFakeNotifyWatcher() }
func (a *fakeAgentEntityWatcher) Watch() state.NotifyWatcher { w := apiservertesting.NewFakeNotifyWatcher() // Simulate initial event. w.C <- struct{}{} return w }
func (a *fakeAgentEntityWatcher) Watch() state.NotifyWatcher { return apiservertesting.NewFakeNotifyWatcher() }
func (*fakeModelAccessor) WatchForModelConfigChanges() state.NotifyWatcher { return apiservertesting.NewFakeNotifyWatcher() }
func (*fakeModelAccessor) WatchForModelConfigChanges() state.NotifyWatcher { w := apiservertesting.NewFakeNotifyWatcher() // Simulate initial event. w.C <- struct{}{} return w }