本文整理汇总了Golang中github.com/juju/juju/apiserver/common.NewResources函数的典型用法代码示例。如果您正苦于以下问题:Golang NewResources函数的具体用法?Golang NewResources怎么用?Golang NewResources使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了NewResources函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: SetUpTest
func (s *networkerSuite) SetUpTest(c *gc.C) {
s.JujuConnSuite.SetUpTest(c)
s.setUpNetworks(c)
s.setUpMachine(c)
s.setUpContainers(c)
// Create a FakeAuthorizer so we can check permissions,
// set up assuming we logged in as a machine agent.
s.authorizer = apiservertesting.FakeAuthorizer{
Tag: s.machine.Tag(),
}
// Create the resource registry separately to track invocations to
// Register.
s.resources = common.NewResources()
// Create a networker API for the machine.
var err error
s.networker, err = networker.NewNetworkerAPI(
s.State,
s.resources,
s.authorizer,
)
c.Assert(err, jc.ErrorIsNil)
}
示例2: SetUpTest
func (s *destroyControllerSuite) SetUpTest(c *gc.C) {
s.JujuConnSuite.SetUpTest(c)
s.BlockHelper = commontesting.NewBlockHelper(s.APIState)
s.AddCleanup(func(*gc.C) { s.BlockHelper.Close() })
resources := common.NewResources()
s.AddCleanup(func(_ *gc.C) { resources.StopAll() })
authoriser := apiservertesting.FakeAuthorizer{
Tag: s.AdminUserTag(c),
}
controller, err := controller.NewControllerAPI(s.State, resources, authoriser)
c.Assert(err, jc.ErrorIsNil)
s.controller = controller
s.otherEnvOwner = names.NewUserTag("[email protected]")
s.otherState = factory.NewFactory(s.State).MakeModel(c, &factory.ModelParams{
Name: "dummytoo",
Owner: s.otherEnvOwner,
Prepare: true,
ConfigAttrs: testing.Attrs{
"state-server": false,
},
})
s.AddCleanup(func(c *gc.C) { s.otherState.Close() })
s.otherModelUUID = s.otherState.ModelUUID()
}
示例3: SetUpTest
func (s *Suite) SetUpTest(c *gc.C) {
// Set up InitialConfig with a dummy provider configuration. This
// is required to allow model import test to work.
env, err := environs.Prepare(
modelcmd.BootstrapContext(testing.Context(c)),
jujuclienttesting.NewMemStore(),
environs.PrepareParams{
ControllerName: "dummycontroller",
BaseConfig: dummy.SampleConfig(),
CloudName: "dummy",
},
)
c.Assert(err, jc.ErrorIsNil)
s.InitialConfig = testing.CustomModelConfig(c, env.Config().AllAttrs())
// The call up to StateSuite's SetUpTest uses s.InitialConfig so
// it has to happen here.
s.StateSuite.SetUpTest(c)
s.resources = common.NewResources()
s.AddCleanup(func(*gc.C) { s.resources.StopAll() })
s.authorizer = apiservertesting.FakeAuthorizer{
Tag: s.Owner,
}
}
示例4: TestNewStorageProvisionerAPINonMachine
func (s *provisionerSuite) TestNewStorageProvisionerAPINonMachine(c *gc.C) {
tag := names.NewUnitTag("mysql/0")
authorizer := &apiservertesting.FakeAuthorizer{Tag: tag}
backend := storageprovisioner.NewStateBackend(s.State)
_, err := storageprovisioner.NewStorageProvisionerAPI(backend, common.NewResources(), authorizer, nil, nil)
c.Assert(err, gc.ErrorMatches, "permission denied")
}
示例5: SetUpTest
func (s *clientSuite) SetUpTest(c *gc.C) {
s.JujuConnSuite.SetUpTest(c)
s.resources = common.NewResources()
s.AddCleanup(func(_ *gc.C) { s.resources.StopAll() })
s.authoriser = apiservertesting.FakeAuthorizer{
Tag: s.AdminUserTag(c),
EnvironManager: true,
}
var err error
s.haServer, err = highavailability.NewHighAvailabilityAPI(s.State, s.resources, s.authoriser)
c.Assert(err, jc.ErrorIsNil)
_, err = s.State.AddMachines(state.MachineTemplate{
Series: "quantal",
Jobs: []state.MachineJob{state.JobManageModel},
Constraints: controllerCons,
})
c.Assert(err, jc.ErrorIsNil)
// We have to ensure the agents are alive, or EnableHA will
// create more to replace them.
s.pingers = []*presence.Pinger{s.setAgentPresence(c, "0")}
s.BlockHelper = commontesting.NewBlockHelper(s.APIState)
s.AddCleanup(func(*gc.C) { s.BlockHelper.Close() })
}
示例6: SetUpTest
func (s *destroyTwoEnvironmentsSuite) SetUpTest(c *gc.C) {
s.JujuConnSuite.SetUpTest(c)
_, err := s.State.AddUser("jess", "jess", "", "test")
c.Assert(err, jc.ErrorIsNil)
s.otherEnvOwner = names.NewUserTag("jess")
s.otherState = factory.NewFactory(s.State).MakeEnvironment(c, &factory.EnvParams{
Owner: s.otherEnvOwner,
Prepare: true,
ConfigAttrs: jujutesting.Attrs{
"state-server": false,
},
})
s.AddCleanup(func(*gc.C) { s.otherState.Close() })
// get the client for the other environment
auth := apiservertesting.FakeAuthorizer{
Tag: s.otherEnvOwner,
EnvironManager: false,
}
s.otherEnvClient, err = client.NewClient(s.otherState, common.NewResources(), auth)
c.Assert(err, jc.ErrorIsNil)
s.metricSender = &testMetricSender{}
s.PatchValue(common.SendMetrics, s.metricSender.SendMetrics)
}
示例7: TestWatchSuccess
func (*FacadeSuite) TestWatchSuccess(c *gc.C) {
stub := &testing.Stub{}
backend := newMockBackend(stub)
resources := common.NewResources()
facade, err := migrationflag.New(backend, resources, authOK)
c.Assert(err, jc.ErrorIsNil)
results := facade.Watch(entities(
coretesting.ModelTag.String(),
coretesting.ModelTag.String(),
))
c.Assert(results.Results, gc.HasLen, 2)
stub.CheckCallNames(c, "WatchMigrationPhase", "WatchMigrationPhase")
check := func(result params.NotifyWatchResult) {
c.Check(result.Error, gc.IsNil)
resource := resources.Get(result.NotifyWatcherId)
c.Check(resource, gc.NotNil)
}
first := results.Results[0]
second := results.Results[1]
check(first)
check(second)
c.Check(first.NotifyWatcherId, gc.Not(gc.Equals), second.NotifyWatcherId)
}
示例8: SetUpTest
func (s *baseSuite) SetUpTest(c *gc.C) {
s.JujuConnSuite.SetUpTest(c)
var err error
s.machine0, err = s.State.AddMachine("quantal", state.JobManageEnviron)
c.Assert(err, jc.ErrorIsNil)
s.machine1, err = s.State.AddMachine("quantal", state.JobHostUnits)
c.Assert(err, jc.ErrorIsNil)
template := state.MachineTemplate{
Series: "quantal",
Jobs: []state.MachineJob{state.JobHostUnits},
}
s.container, err = s.State.AddMachineInsideMachine(template, s.machine1.Id(), instance.LXC)
c.Assert(err, jc.ErrorIsNil)
s.resources = common.NewResources()
s.AddCleanup(func(*gc.C) { s.resources.StopAll() })
// Create a FakeAuthorizer so we can check permissions,
// set up assuming machine 1 has logged in.
s.authorizer = apiservertesting.FakeAuthorizer{
Tag: s.machine1.Tag(),
}
}
示例9: SetUpTest
func (s *userManagerSuite) SetUpTest(c *gc.C) {
s.JujuConnSuite.SetUpTest(c)
s.createLocalLoginMacaroon = func(tag names.UserTag) (*macaroon.Macaroon, error) {
return nil, errors.NotSupportedf("CreateLocalLoginMacaroon")
}
s.resources = common.NewResources()
s.resources.RegisterNamed("createLocalLoginMacaroon", common.ValueResource{
func(tag names.UserTag) (*macaroon.Macaroon, error) {
return s.createLocalLoginMacaroon(tag)
},
})
adminTag := s.AdminUserTag(c)
s.adminName = adminTag.Name()
s.authorizer = apiservertesting.FakeAuthorizer{
Tag: adminTag,
}
var err error
s.usermanager, err = usermanager.NewUserManagerAPI(s.State, s.resources, s.authorizer)
c.Assert(err, jc.ErrorIsNil)
s.BlockHelper = commontesting.NewBlockHelper(s.APIState)
s.AddCleanup(func(*gc.C) { s.BlockHelper.Close() })
}
示例10: TestWatchErrors
func (*FacadeSuite) TestWatchErrors(c *gc.C) {
stub := &testing.Stub{}
stub.SetErrors(errors.New("blort"), nil, errors.New("squish"))
backend := newMockBackend(stub)
resources := common.NewResources()
facade, err := migrationflag.New(backend, resources, authOK)
c.Assert(err, jc.ErrorIsNil)
// 4 entities: unparseable, unauthorized, watch error, closed chan.
results := facade.Watch(entities(
"urgle",
unknownModel,
coretesting.ModelTag.String(),
coretesting.ModelTag.String(),
))
c.Assert(results.Results, gc.HasLen, 4)
stub.CheckCallNames(c, "WatchMigrationPhase", "WatchMigrationPhase")
c.Check(results.Results, jc.DeepEquals, []params.NotifyWatchResult{{
Error: ¶ms.Error{
Message: `"urgle" is not a valid tag`,
}}, {
Error: ¶ms.Error{
Message: "permission denied",
Code: "unauthorized access",
}}, {
Error: ¶ms.Error{
Message: "blort",
}}, {
Error: ¶ms.Error{
Message: "squish",
},
}})
c.Check(resources.Count(), gc.Equals, 0)
}
示例11: TestDestroyUnitStorageAttachments
func (s *storageSuite) TestDestroyUnitStorageAttachments(c *gc.C) {
resources := common.NewResources()
getCanAccess := func() (common.AuthFunc, error) {
return func(names.Tag) bool {
return true
}, nil
}
unitTag := names.NewUnitTag("mysql/0")
var calls []string
state := &mockStorageState{
destroyUnitStorageAttachments: func(u names.UnitTag) error {
calls = append(calls, "DestroyUnitStorageAttachments")
c.Assert(u, gc.DeepEquals, unitTag)
return nil
},
}
storage, err := uniter.NewStorageAPI(state, resources, getCanAccess)
c.Assert(err, jc.ErrorIsNil)
errors, err := storage.DestroyUnitStorageAttachments(params.Entities{
Entities: []params.Entity{{
Tag: unitTag.String(),
}},
})
c.Assert(err, jc.ErrorIsNil)
c.Assert(calls, jc.DeepEquals, []string{"DestroyUnitStorageAttachments"})
c.Assert(errors, jc.DeepEquals, params.ErrorResults{
[]params.ErrorResult{{}},
})
}
示例12: TestWatchUnitStorageAttachments
func (s *storageSuite) TestWatchUnitStorageAttachments(c *gc.C) {
resources := common.NewResources()
getCanAccess := func() (common.AuthFunc, error) {
return func(names.Tag) bool {
return true
}, nil
}
unitTag := names.NewUnitTag("mysql/0")
watcher := &mockStringsWatcher{
changes: make(chan []string, 1),
}
watcher.changes <- []string{"storage/0", "storage/1"}
state := &mockStorageState{
watchStorageAttachments: func(u names.UnitTag) state.StringsWatcher {
c.Assert(u, gc.DeepEquals, unitTag)
return watcher
},
}
storage, err := uniter.NewStorageAPI(state, resources, getCanAccess)
c.Assert(err, jc.ErrorIsNil)
watches, err := storage.WatchUnitStorageAttachments(params.Entities{
Entities: []params.Entity{{unitTag.String()}},
})
c.Assert(err, jc.ErrorIsNil)
c.Assert(watches, gc.DeepEquals, params.StringsWatchResults{
Results: []params.StringsWatchResult{{
StringsWatcherId: "1",
Changes: []string{"storage/0", "storage/1"},
}},
})
c.Assert(resources.Get("1"), gc.Equals, watcher)
}
示例13: TestWatch
func (*agentEntityWatcherSuite) TestWatch(c *gc.C) {
st := &fakeState{
entities: map[names.Tag]entityWithError{
u("x/0"): &fakeAgentEntityWatcher{fetchError: "x0 fails"},
u("x/1"): &fakeAgentEntityWatcher{},
u("x/2"): &fakeAgentEntityWatcher{},
},
}
getCanWatch := func() (common.AuthFunc, error) {
x0 := u("x/0")
x1 := u("x/1")
return func(tag names.Tag) bool {
return tag == x0 || tag == x1
}, nil
}
resources := common.NewResources()
a := common.NewAgentEntityWatcher(st, resources, getCanWatch)
entities := params.Entities{[]params.Entity{
{"unit-x-0"}, {"unit-x-1"}, {"unit-x-2"}, {"unit-x-3"},
}}
result, err := a.Watch(entities)
c.Assert(err, jc.ErrorIsNil)
c.Assert(result, gc.DeepEquals, params.NotifyWatchResults{
Results: []params.NotifyWatchResult{
{Error: ¶ms.Error{Message: "x0 fails"}},
{"1", nil},
{Error: apiservertesting.ErrUnauthorized},
{Error: apiservertesting.ErrUnauthorized},
},
})
}
示例14: newWatchFixture
func newWatchFixture(c *gc.C, working bool) *watchFixture {
backend := &watchBackend{working: working}
resources := common.NewResources()
facade, err := applicationscaler.NewFacade(backend, resources, auth(true))
c.Assert(err, jc.ErrorIsNil)
return &watchFixture{facade, resources}
}
示例15: SetUpTest
func (s *deployerSuite) SetUpTest(c *gc.C) {
s.JujuConnSuite.SetUpTest(c)
// The two known machines now contain the following units:
// machine 0 (not authorized): mysql/1 (principal1)
// machine 1 (authorized): mysql/0 (principal0), logging/0 (subordinate0)
var err error
s.machine0, err = s.State.AddMachine("quantal", state.JobManageEnviron, state.JobHostUnits)
c.Assert(err, jc.ErrorIsNil)
s.machine1, err = s.State.AddMachine("quantal", state.JobHostUnits)
c.Assert(err, jc.ErrorIsNil)
s.service0 = s.AddTestingService(c, "mysql", s.AddTestingCharm(c, "mysql"))
s.service1 = s.AddTestingService(c, "logging", s.AddTestingCharm(c, "logging"))
eps, err := s.State.InferEndpoints("mysql", "logging")
c.Assert(err, jc.ErrorIsNil)
rel, err := s.State.AddRelation(eps...)
c.Assert(err, jc.ErrorIsNil)
s.principal0, err = s.service0.AddUnit()
c.Assert(err, jc.ErrorIsNil)
err = s.principal0.AssignToMachine(s.machine1)
c.Assert(err, jc.ErrorIsNil)
s.principal1, err = s.service0.AddUnit()
c.Assert(err, jc.ErrorIsNil)
err = s.principal1.AssignToMachine(s.machine0)
c.Assert(err, jc.ErrorIsNil)
relUnit0, err := rel.Unit(s.principal0)
c.Assert(err, jc.ErrorIsNil)
err = relUnit0.EnterScope(nil)
c.Assert(err, jc.ErrorIsNil)
s.subordinate0, err = s.State.Unit("logging/0")
c.Assert(err, jc.ErrorIsNil)
// Create a FakeAuthorizer so we can check permissions,
// set up assuming machine 1 has logged in.
s.authorizer = apiservertesting.FakeAuthorizer{
Tag: s.machine1.Tag(),
}
// Create the resource registry separately to track invocations to
// Register.
s.resources = common.NewResources()
s.AddCleanup(func(_ *gc.C) { s.resources.StopAll() })
// Create a deployer API for machine 1.
deployer, err := deployer.NewDeployerAPI(
s.State,
s.resources,
s.authorizer,
)
c.Assert(err, jc.ErrorIsNil)
s.deployer = deployer
}