Пример #1
0
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
		},
	}
}
Пример #2
0
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()
}
Пример #3
0
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)
}
Пример #4
0
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)
}
Пример #5
0
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()
}
Пример #6
0
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",
	})
}
Пример #7
0
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:      "******",
	})
}
Пример #8
0
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",
	})
}
Пример #9
0
func (b *stubBackend) WatchMigrationStatus() (state.NotifyWatcher, error) {
	if b.watchError != nil {
		return nil, b.watchError
	}
	return apiservertesting.NewFakeNotifyWatcher(), nil
}
Пример #10
0
func (m *stubMigration) WatchMinionReports() (state.NotifyWatcher, error) {
	m.stub.AddCall("ModelMigration.WatchMinionReports")
	return apiservertesting.NewFakeNotifyWatcher(), nil
}
Пример #11
0
func (b *stubBackend) WatchForMigration() state.NotifyWatcher {
	b.stub.AddCall("WatchForMigration")
	return apiservertesting.NewFakeNotifyWatcher()
}
Пример #12
0
func (a *fakeAgentEntityWatcher) Watch() state.NotifyWatcher {
	w := apiservertesting.NewFakeNotifyWatcher()
	// Simulate initial event.
	w.C <- struct{}{}
	return w
}
Пример #13
0
func (a *fakeAgentEntityWatcher) Watch() state.NotifyWatcher {
	return apiservertesting.NewFakeNotifyWatcher()
}
Пример #14
0
func (*fakeModelAccessor) WatchForModelConfigChanges() state.NotifyWatcher {
	return apiservertesting.NewFakeNotifyWatcher()
}
Пример #15
0
func (*fakeModelAccessor) WatchForModelConfigChanges() state.NotifyWatcher {
	w := apiservertesting.NewFakeNotifyWatcher()
	// Simulate initial event.
	w.C <- struct{}{}
	return w
}