本文整理汇总了Golang中github.com/juju/juju/instance.MustParseHardware函数的典型用法代码示例。如果您正苦于以下问题:Golang MustParseHardware函数的具体用法?Golang MustParseHardware怎么用?Golang MustParseHardware使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了MustParseHardware函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。
示例1: TestSecureConnectionDisallowed
func (s *machineConfigSuite) TestSecureConnectionDisallowed(c *gc.C) {
// StateServingInfo without CAPrivateKey will not allow secure connections.
servingInfo := state.StateServingInfo{
PrivateKey: jujutesting.ServerKey,
Cert: jujutesting.ServerCert,
SharedSecret: "really, really secret",
APIPort: 4321,
StatePort: 1234,
}
s.State.SetStateServingInfo(servingInfo)
hc := instance.MustParseHardware("mem=4G arch=amd64")
apiParams := params.AddMachineParams{
Jobs: []multiwatcher.MachineJob{multiwatcher.JobHostUnits},
InstanceId: instance.Id("1234"),
Nonce: "foo",
HardwareCharacteristics: hc,
}
machines, err := s.APIState.Client().AddMachines([]params.AddMachineParams{apiParams})
c.Assert(err, jc.ErrorIsNil)
c.Assert(len(machines), gc.Equals, 1)
machineId := machines[0].Machine
instanceConfig, err := client.InstanceConfig(s.State, machineId, apiParams.Nonce, "")
c.Assert(err, jc.ErrorIsNil)
c.Assert(instanceConfig.AgentEnvironment[agent.AllowsSecureConnection], gc.Equals, "false")
}
开发者ID:imoapps,项目名称:juju,代码行数:26,代码来源:instanceconfig_test.go
示例2: TestAssignUsingConstraintsToMachine
func (s *assignCleanSuite) TestAssignUsingConstraintsToMachine(c *gc.C) {
for i, t := range assignUsingConstraintsTests {
c.Logf("test %d", i)
cons := constraints.MustParse(t.unitConstraints)
err := s.State.SetModelConstraints(cons)
c.Assert(err, jc.ErrorIsNil)
unit, err := s.wordpress.AddUnit()
c.Assert(err, jc.ErrorIsNil)
m, err := s.State.AddMachine("quantal", state.JobHostUnits)
c.Assert(err, jc.ErrorIsNil)
if t.hardwareCharacteristics != "none" {
hc := instance.MustParseHardware(t.hardwareCharacteristics)
err = m.SetProvisioned("inst-id", "fake_nonce", &hc)
c.Assert(err, jc.ErrorIsNil)
}
um, err := s.assignUnit(unit)
if t.assignOk {
c.Assert(err, jc.ErrorIsNil)
c.Assert(um.Id(), gc.Equals, m.Id())
} else {
c.Assert(um, gc.IsNil)
c.Assert(err, gc.ErrorMatches, eligibleMachinesInUse)
// Destroy the machine so it can't be used for the next test.
err = m.Destroy()
c.Assert(err, jc.ErrorIsNil)
}
}
}
开发者ID:makyo,项目名称:juju,代码行数:31,代码来源:assign_test.go
示例3: TestKeepBrokenDoesNoStop
func (s *BootstrapSuite) TestKeepBrokenDoesNoStop(c *gc.C) {
innerStorage := newStorage(s, c)
stor := &mockStorage{Storage: innerStorage}
checkHardware := instance.MustParseHardware("arch=ppc64el mem=2T")
startInstance := func(
_ string, _ constraints.Value, _ []string, _ tools.List, mcfg *cloudinit.MachineConfig,
) (
instance.Instance, *instance.HardwareCharacteristics, []network.Info, error,
) {
stor.putErr = fmt.Errorf("suddenly a wild blah")
return &mockInstance{id: "i-blah"}, &checkHardware, nil, nil
}
stopInstances := func(instances []instance.Id) error {
c.Errorf("unexpected call to StopInstances")
return nil
}
env := &mockEnviron{
storage: stor,
startInstance: startInstance,
stopInstances: stopInstances,
config: configGetter(c),
}
ctx := coretesting.Context(c)
_, _, _, err := common.Bootstrap(ctx, env, environs.BootstrapParams{
KeepBroken: true,
AvailableTools: tools.List{&tools.Tools{Version: version.Current}},
})
c.Assert(err, gc.ErrorMatches, "cannot save state: suddenly a wild blah")
}
开发者ID:zhouqt,项目名称:juju,代码行数:32,代码来源:bootstrap_test.go
示例4: TestMachineConfig
func (s *machineConfigSuite) TestMachineConfig(c *gc.C) {
addrs := network.NewAddresses("1.2.3.4")
hc := instance.MustParseHardware("mem=4G arch=amd64")
apiParams := params.AddMachineParams{
Jobs: []multiwatcher.MachineJob{multiwatcher.JobHostUnits},
InstanceId: instance.Id("1234"),
Nonce: "foo",
HardwareCharacteristics: hc,
Addrs: params.FromNetworkAddresses(addrs),
}
machines, err := s.APIState.Client().AddMachines([]params.AddMachineParams{apiParams})
c.Assert(err, jc.ErrorIsNil)
c.Assert(len(machines), gc.Equals, 1)
machineId := machines[0].Machine
instanceConfig, err := client.InstanceConfig(s.State, machineId, apiParams.Nonce, "")
c.Assert(err, jc.ErrorIsNil)
envConfig, err := s.State.EnvironConfig()
c.Assert(err, jc.ErrorIsNil)
mongoAddrs := s.State.MongoConnectionInfo().Addrs
apiAddrs := []string{net.JoinHostPort("localhost", strconv.Itoa(envConfig.APIPort()))}
c.Check(instanceConfig.MongoInfo.Addrs, gc.DeepEquals, mongoAddrs)
c.Check(instanceConfig.APIInfo.Addrs, gc.DeepEquals, apiAddrs)
toolsURL := fmt.Sprintf("https://%s/environment/%s/tools/%s",
apiAddrs[0], jujutesting.EnvironmentTag.Id(), instanceConfig.Tools.Version)
c.Assert(instanceConfig.Tools.URL, gc.Equals, toolsURL)
c.Assert(instanceConfig.AgentEnvironment[agent.AllowsSecureConnection], gc.Equals, "true")
}
开发者ID:imoapps,项目名称:juju,代码行数:30,代码来源:instanceconfig_test.go
示例5: TestMachineConfig
func (s *machineConfigSuite) TestMachineConfig(c *gc.C) {
addrs := network.NewAddresses("1.2.3.4")
hc := instance.MustParseHardware("mem=4G arch=amd64")
apiParams := params.AddMachineParams{
Jobs: []multiwatcher.MachineJob{multiwatcher.JobHostUnits},
InstanceId: instance.Id("1234"),
Nonce: "foo",
HardwareCharacteristics: hc,
Addrs: params.FromNetworkAddresses(addrs...),
}
machines, err := s.APIState.Client().AddMachines([]params.AddMachineParams{apiParams})
c.Assert(err, jc.ErrorIsNil)
c.Assert(len(machines), gc.Equals, 1)
machineId := machines[0].Machine
instanceConfig, err := client.InstanceConfig(s.State, machineId, apiParams.Nonce, "")
c.Assert(err, jc.ErrorIsNil)
cfg, err := s.State.ControllerConfig()
c.Assert(err, jc.ErrorIsNil)
apiAddrs := []string{net.JoinHostPort("localhost", strconv.Itoa(cfg.APIPort()))}
c.Check(instanceConfig.APIInfo.Addrs, gc.DeepEquals, apiAddrs)
toolsURL := fmt.Sprintf("https://%s/model/%s/tools/%s",
apiAddrs[0], jujutesting.ModelTag.Id(), instanceConfig.AgentVersion())
c.Assert(instanceConfig.ToolsList().URLs(), jc.DeepEquals, map[version.Binary][]string{
instanceConfig.AgentVersion(): []string{toolsURL},
})
}
开发者ID:bac,项目名称:juju,代码行数:29,代码来源:instanceconfig_test.go
示例6: TestMachineConfig
func (s *machineConfigSuite) TestMachineConfig(c *gc.C) {
addrs := []network.Address{network.NewAddress("1.2.3.4", network.ScopeUnknown)}
hc := instance.MustParseHardware("mem=4G arch=amd64")
apiParams := params.AddMachineParams{
Jobs: []params.MachineJob{params.JobHostUnits},
InstanceId: instance.Id("1234"),
Nonce: "foo",
HardwareCharacteristics: hc,
Addrs: addrs,
}
machines, err := s.APIState.Client().AddMachines([]params.AddMachineParams{apiParams})
c.Assert(err, gc.IsNil)
c.Assert(len(machines), gc.Equals, 1)
machineId := machines[0].Machine
machineConfig, err := client.MachineConfig(s.State, machineId, apiParams.Nonce, "")
c.Assert(err, gc.IsNil)
envConfig, err := s.State.EnvironConfig()
c.Assert(err, gc.IsNil)
env, err := environs.New(envConfig)
c.Assert(err, gc.IsNil)
stateInfo, apiInfo, err := env.StateInfo()
c.Assert(err, gc.IsNil)
c.Check(machineConfig.StateInfo.Addrs, gc.DeepEquals, stateInfo.Addrs)
c.Check(machineConfig.APIInfo.Addrs, gc.DeepEquals, apiInfo.Addrs)
c.Assert(machineConfig.Tools.URL, gc.Not(gc.Equals), "")
}
开发者ID:rogpeppe,项目名称:juju,代码行数:28,代码来源:machineconfig_test.go
示例7: TestMachineConfig
func (s *machineConfigSuite) TestMachineConfig(c *gc.C) {
addrs := []network.Address{network.NewAddress("1.2.3.4", network.ScopeUnknown)}
hc := instance.MustParseHardware("mem=4G arch=amd64")
apiParams := params.AddMachineParams{
Jobs: []params.MachineJob{params.JobHostUnits},
InstanceId: instance.Id("1234"),
Nonce: "foo",
HardwareCharacteristics: hc,
Addrs: addrs,
}
machines, err := s.APIState.Client().AddMachines([]params.AddMachineParams{apiParams})
c.Assert(err, gc.IsNil)
c.Assert(len(machines), gc.Equals, 1)
machineId := machines[0].Machine
machineConfig, err := client.MachineConfig(s.State, machineId, apiParams.Nonce, "")
c.Assert(err, gc.IsNil)
envConfig, err := s.State.EnvironConfig()
c.Assert(err, gc.IsNil)
mongoAddrs := s.State.MongoConnectionInfo().Addrs
apiAddrs := []string{net.JoinHostPort("localhost", strconv.Itoa(envConfig.APIPort()))}
c.Check(machineConfig.MongoInfo.Addrs, gc.DeepEquals, mongoAddrs)
c.Check(machineConfig.APIInfo.Addrs, gc.DeepEquals, apiAddrs)
toolsURL := fmt.Sprintf("https://%s/environment/90168e4c-2f10-4e9c-83c2-feedfacee5a9/tools/%s", apiAddrs[0], machineConfig.Tools.Version)
c.Assert(machineConfig.Tools.URL, gc.Equals, toolsURL)
}
开发者ID:zhouqt,项目名称:juju,代码行数:28,代码来源:machineconfig_test.go
示例8: TestInstanceId
func (s *withoutStateServerSuite) TestInstanceId(c *gc.C) {
// Provision 2 machines first.
err := s.machines[0].SetProvisioned("i-am", "fake_nonce", nil)
c.Assert(err, gc.IsNil)
hwChars := instance.MustParseHardware("arch=i386", "mem=4G")
err = s.machines[1].SetProvisioned("i-am-not", "fake_nonce", &hwChars)
c.Assert(err, gc.IsNil)
args := params.Entities{Entities: []params.Entity{
{Tag: s.machines[0].Tag()},
{Tag: s.machines[1].Tag()},
{Tag: s.machines[2].Tag()},
{Tag: "machine-42"},
{Tag: "unit-foo-0"},
{Tag: "service-bar"},
}}
result, err := s.provisioner.InstanceId(args)
c.Assert(err, gc.IsNil)
c.Assert(result, gc.DeepEquals, params.StringResults{
Results: []params.StringResult{
{Result: "i-am"},
{Result: "i-am-not"},
{Error: apiservertesting.NotProvisionedError("2")},
{Error: apiservertesting.NotFoundError("machine 42")},
{Error: apiservertesting.ErrUnauthorized},
{Error: apiservertesting.ErrUnauthorized},
},
})
}
开发者ID:rogpeppe,项目名称:juju,代码行数:29,代码来源:provisioner_test.go
示例9: TestMachinesWithTransientErrors
func (s *withoutStateServerSuite) TestMachinesWithTransientErrors(c *gc.C) {
err := s.machines[0].SetStatus(params.StatusStarted, "blah", nil)
c.Assert(err, gc.IsNil)
err = s.machines[1].SetStatus(params.StatusError, "transient error",
params.StatusData{"transient": true, "foo": "bar"})
c.Assert(err, gc.IsNil)
err = s.machines[2].SetStatus(params.StatusError, "error", params.StatusData{"transient": false})
c.Assert(err, gc.IsNil)
err = s.machines[3].SetStatus(params.StatusError, "error", nil)
c.Assert(err, gc.IsNil)
// Machine 4 is provisioned but error not reset yet.
err = s.machines[4].SetStatus(params.StatusError, "transient error",
params.StatusData{"transient": true, "foo": "bar"})
c.Assert(err, gc.IsNil)
hwChars := instance.MustParseHardware("arch=i386", "mem=4G")
err = s.machines[4].SetProvisioned("i-am", "fake_nonce", &hwChars)
c.Assert(err, gc.IsNil)
result, err := s.provisioner.MachinesWithTransientErrors()
c.Assert(err, gc.IsNil)
c.Assert(result, gc.DeepEquals, params.StatusResults{
Results: []params.StatusResult{
{Id: "1", Life: "alive", Status: "error", Info: "transient error",
Data: params.StatusData{"transient": true, "foo": "bar"}},
},
})
}
开发者ID:rogpeppe,项目名称:juju,代码行数:27,代码来源:provisioner_test.go
示例10: TestClientAddMachinesWithInstanceIdSomeErrors
func (s *clientSuite) TestClientAddMachinesWithInstanceIdSomeErrors(c *gc.C) {
apiParams := make([]params.AddMachineParams, 3)
addrs := network.NewAddresses("1.2.3.4")
hc := instance.MustParseHardware("mem=4G")
for i := 0; i < 3; i++ {
apiParams[i] = params.AddMachineParams{
Jobs: []multiwatcher.MachineJob{multiwatcher.JobHostUnits},
InstanceId: instance.Id(fmt.Sprintf("1234-%d", i)),
Nonce: "foo",
HardwareCharacteristics: hc,
Addrs: params.FromNetworkAddresses(addrs...),
}
}
// This will cause the last add-machine to fail.
apiParams[2].Nonce = ""
machines, err := s.APIState.Client().AddMachines(apiParams)
c.Assert(err, jc.ErrorIsNil)
c.Assert(len(machines), gc.Equals, 3)
for i, machineResult := range machines {
if i == 2 {
c.Assert(machineResult.Error, gc.NotNil)
c.Assert(machineResult.Error, gc.ErrorMatches, "cannot add a new machine: cannot add a machine with an instance id and no nonce")
} else {
c.Assert(machineResult.Machine, gc.DeepEquals, strconv.Itoa(i))
s.checkMachine(c, machineResult.Machine, series.LatestLts(), apiParams[i].Constraints.String())
instanceId := fmt.Sprintf("1234-%d", i)
s.checkInstance(c, machineResult.Machine, instanceId, "foo", hc, addrs)
}
}
}
开发者ID:bac,项目名称:juju,代码行数:30,代码来源:client_test.go
示例11: setUpMachine
// Create a machine to use.
func (s *networkerSuite) setUpMachine(c *gc.C) {
var err error
s.machine, err = s.State.AddMachine("quantal", state.JobHostUnits)
c.Assert(err, gc.IsNil)
hwChars := instance.MustParseHardware("arch=i386", "mem=4G")
s.machineIfaces = []state.NetworkInterfaceInfo{{
MACAddress: "aa:bb:cc:dd:ee:f0",
InterfaceName: "eth0",
NetworkName: "net1",
IsVirtual: false,
}, {
MACAddress: "aa:bb:cc:dd:ee:f1",
InterfaceName: "eth1",
NetworkName: "net1",
IsVirtual: false,
}, {
MACAddress: "aa:bb:cc:dd:ee:f1",
InterfaceName: "eth1.42",
NetworkName: "vlan42",
IsVirtual: true,
}, {
MACAddress: "aa:bb:cc:dd:ee:f0",
InterfaceName: "eth0.69",
NetworkName: "vlan69",
IsVirtual: true,
}, {
MACAddress: "aa:bb:cc:dd:ee:f2",
InterfaceName: "eth2",
NetworkName: "net2",
IsVirtual: false,
Disabled: true,
}}
err = s.machine.SetInstanceInfo("i-am", "fake_nonce", &hwChars, s.networks, s.machineIfaces)
c.Assert(err, gc.IsNil)
}
开发者ID:klyachin,项目名称:juju,代码行数:36,代码来源:networker_test.go
示例12: TestInitializeEnvironmentInvalidOplogSize
func (s *BootstrapSuite) TestInitializeEnvironmentInvalidOplogSize(c *gc.C) {
s.mongoOplogSize = "NaN"
hw := instance.MustParseHardware("arch=amd64 mem=8G")
_, cmd, err := s.initBootstrapCommand(c, nil, "--env-config", s.b64yamlEnvcfg, "--instance-id", string(s.instanceId), "--hardware", hw.String())
c.Assert(err, jc.ErrorIsNil)
err = cmd.Run(nil)
c.Assert(err, gc.ErrorMatches, `invalid oplog size: "NaN"`)
}
开发者ID:ktsakalozos,项目名称:juju,代码行数:8,代码来源:bootstrap_test.go
示例13: TestInitializeEnvironment
func (s *BootstrapSuite) TestInitializeEnvironment(c *gc.C) {
hw := instance.MustParseHardware("arch=amd64 mem=8G")
machConf, cmd, err := s.initBootstrapCommand(c, nil, "--env-config", s.envcfg, "--instance-id", string(s.instanceId), "--hardware", hw.String())
c.Assert(err, gc.IsNil)
err = cmd.Run(nil)
c.Assert(err, gc.IsNil)
c.Assert(s.fakeEnsureMongo.dataDir, gc.Equals, s.dataDir)
c.Assert(s.fakeEnsureMongo.initiateCount, gc.Equals, 1)
c.Assert(s.fakeEnsureMongo.ensureCount, gc.Equals, 1)
c.Assert(s.fakeEnsureMongo.dataDir, gc.Equals, s.dataDir)
c.Assert(s.fakeEnsureMongo.oplogSize, gc.Equals, 1234)
expectInfo, exists := machConf.StateServingInfo()
c.Assert(exists, jc.IsTrue)
c.Assert(expectInfo.SharedSecret, gc.Equals, "")
servingInfo := s.fakeEnsureMongo.info
c.Assert(len(servingInfo.SharedSecret), gc.Not(gc.Equals), 0)
servingInfo.SharedSecret = ""
c.Assert(servingInfo, jc.DeepEquals, expectInfo)
expectDialAddrs := []string{fmt.Sprintf("127.0.0.1:%d", expectInfo.StatePort)}
gotDialAddrs := s.fakeEnsureMongo.initiateParams.DialInfo.Addrs
c.Assert(gotDialAddrs, gc.DeepEquals, expectDialAddrs)
memberHost := fmt.Sprintf("%s:%d", s.bootstrapName, expectInfo.StatePort)
c.Assert(s.fakeEnsureMongo.initiateParams.MemberHostPort, gc.Equals, memberHost)
c.Assert(s.fakeEnsureMongo.initiateParams.User, gc.Equals, "")
c.Assert(s.fakeEnsureMongo.initiateParams.Password, gc.Equals, "")
st, err := state.Open(&authentication.MongoInfo{
Info: mongo.Info{
Addrs: []string{gitjujutesting.MgoServer.Addr()},
CACert: testing.CACert,
},
Password: testPasswordHash(),
}, mongo.DefaultDialOpts(), environs.NewStatePolicy())
c.Assert(err, gc.IsNil)
defer st.Close()
machines, err := st.AllMachines()
c.Assert(err, gc.IsNil)
c.Assert(machines, gc.HasLen, 1)
instid, err := machines[0].InstanceId()
c.Assert(err, gc.IsNil)
c.Assert(instid, gc.Equals, instance.Id(string(s.instanceId)))
stateHw, err := machines[0].HardwareCharacteristics()
c.Assert(err, gc.IsNil)
c.Assert(stateHw, gc.NotNil)
c.Assert(*stateHw, gc.DeepEquals, hw)
cons, err := st.EnvironConstraints()
c.Assert(err, gc.IsNil)
c.Assert(&cons, jc.Satisfies, constraints.IsEmpty)
}
开发者ID:jiasir,项目名称:juju,代码行数:56,代码来源:bootstrap_test.go
示例14: TestMachinesWithTransientErrors
func (s *withoutControllerSuite) TestMachinesWithTransientErrors(c *gc.C) {
now := time.Now()
sInfo := status.StatusInfo{
Status: status.Started,
Message: "blah",
Since: &now,
}
err := s.machines[0].SetStatus(sInfo)
c.Assert(err, jc.ErrorIsNil)
sInfo = status.StatusInfo{
Status: status.Error,
Message: "transient error",
Data: map[string]interface{}{"transient": true, "foo": "bar"},
Since: &now,
}
err = s.machines[1].SetStatus(sInfo)
c.Assert(err, jc.ErrorIsNil)
sInfo = status.StatusInfo{
Status: status.Error,
Message: "error",
Data: map[string]interface{}{"transient": false},
Since: &now,
}
err = s.machines[2].SetStatus(sInfo)
c.Assert(err, jc.ErrorIsNil)
sInfo = status.StatusInfo{
Status: status.Error,
Message: "error",
Since: &now,
}
err = s.machines[3].SetStatus(sInfo)
c.Assert(err, jc.ErrorIsNil)
// Machine 4 is provisioned but error not reset yet.
sInfo = status.StatusInfo{
Status: status.Error,
Message: "transient error",
Data: map[string]interface{}{"transient": true, "foo": "bar"},
Since: &now,
}
err = s.machines[4].SetStatus(sInfo)
c.Assert(err, jc.ErrorIsNil)
hwChars := instance.MustParseHardware("arch=i386", "mem=4G")
err = s.machines[4].SetProvisioned("i-am", "fake_nonce", &hwChars)
c.Assert(err, jc.ErrorIsNil)
result, err := s.provisioner.MachinesWithTransientErrors()
c.Assert(err, jc.ErrorIsNil)
c.Assert(result, gc.DeepEquals, params.StatusResults{
Results: []params.StatusResult{
{Id: "1", Life: "alive", Status: "error", Info: "transient error",
Data: map[string]interface{}{"transient": true, "foo": "bar"}},
},
})
}
开发者ID:bac,项目名称:juju,代码行数:54,代码来源:provisioner_test.go
示例15: TestInitializeStateFailsSecondTime
func (s *bootstrapSuite) TestInitializeStateFailsSecondTime(c *gc.C) {
dataDir := c.MkDir()
configParams := agent.AgentConfigParams{
Paths: agent.Paths{DataDir: dataDir},
Tag: names.NewMachineTag("0"),
UpgradedToVersion: jujuversion.Current,
StateAddresses: []string{s.mgoInst.Addr()},
CACert: testing.CACert,
Password: testing.DefaultMongoPassword,
Model: testing.ModelTag,
}
cfg, err := agent.NewAgentConfig(configParams)
c.Assert(err, jc.ErrorIsNil)
cfg.SetStateServingInfo(params.StateServingInfo{
APIPort: 5555,
StatePort: s.mgoInst.Port(),
Cert: "foo",
PrivateKey: "bar",
SharedSecret: "baz",
SystemIdentity: "qux",
})
expectHW := instance.MustParseHardware("mem=2048M")
mcfg := agentbootstrap.BootstrapMachineConfig{
BootstrapConstraints: constraints.MustParse("mem=1024M"),
Jobs: []multiwatcher.MachineJob{multiwatcher.JobManageModel},
InstanceId: "i-bootstrap",
Characteristics: expectHW,
}
envAttrs := dummy.SampleConfig().Delete("admin-secret").Merge(testing.Attrs{
"agent-version": jujuversion.Current.String(),
})
envCfg, err := config.New(config.NoDefaults, envAttrs)
c.Assert(err, jc.ErrorIsNil)
hostedModelConfigAttrs := map[string]interface{}{
"name": "hosted",
"uuid": utils.MustNewUUID().String(),
}
adminUser := names.NewLocalUserTag("agent-admin")
st, _, err := agentbootstrap.InitializeState(
adminUser, cfg, envCfg, hostedModelConfigAttrs, mcfg,
mongo.DefaultDialOpts(), state.Policy(nil),
)
c.Assert(err, jc.ErrorIsNil)
st.Close()
st, _, err = agentbootstrap.InitializeState(adminUser, cfg, envCfg, nil, mcfg, mongo.DefaultDialOpts(), environs.NewStatePolicy())
if err == nil {
st.Close()
}
c.Assert(err, gc.ErrorMatches, "failed to initialize mongo admin user: cannot set admin password: not authorized .*")
}
开发者ID:AlexisBruemmer,项目名称:juju,代码行数:54,代码来源:bootstrap_test.go
示例16: TestSuccess
func (s *BootstrapSuite) TestSuccess(c *gc.C) {
s.PatchValue(&jujuversion.Current, coretesting.FakeVersionNumber)
stor := newStorage(s, c)
checkInstanceId := "i-success"
checkHardware := instance.MustParseHardware("arch=ppc64el mem=2T")
startInstance := func(
_ string, _ constraints.Value, _ []string, _ tools.List, icfg *instancecfg.InstanceConfig,
) (
instance.Instance, *instance.HardwareCharacteristics, []network.InterfaceInfo, error,
) {
return &mockInstance{id: checkInstanceId}, &checkHardware, nil, nil
}
var mocksConfig = minimalConfig(c)
var getConfigCalled int
getConfig := func() *config.Config {
getConfigCalled++
return mocksConfig
}
setConfig := func(c *config.Config) error {
mocksConfig = c
return nil
}
env := &mockEnviron{
storage: stor,
startInstance: startInstance,
config: getConfig,
setConfig: setConfig,
}
inner := coretesting.Context(c)
ctx := modelcmd.BootstrapContext(inner)
result, err := common.Bootstrap(ctx, env, environs.BootstrapParams{
ControllerConfig: coretesting.FakeControllerConfig(),
AvailableTools: tools.List{
&tools.Tools{
Version: version.Binary{
Number: jujuversion.Current,
Arch: arch.HostArch(),
Series: series.HostSeries(),
},
},
}})
c.Assert(err, jc.ErrorIsNil)
c.Assert(result.Arch, gc.Equals, "ppc64el") // based on hardware characteristics
c.Assert(result.Series, gc.Equals, config.PreferredSeries(mocksConfig))
output := inner.Stderr.(*bytes.Buffer)
lines := strings.Split(output.String(), "\n")
c.Assert(len(lines), jc.GreaterThan, 1)
c.Assert(lines[0], gc.Equals, "Some message")
}
开发者ID:bac,项目名称:juju,代码行数:51,代码来源:bootstrap_test.go
示例17: TestInitializeStateFailsSecondTime
func (s *bootstrapSuite) TestInitializeStateFailsSecondTime(c *gc.C) {
dataDir := c.MkDir()
pwHash := utils.UserPasswordHash(testing.DefaultMongoPassword, utils.CompatSalt)
configParams := agent.AgentConfigParams{
DataDir: dataDir,
Tag: "machine-0",
UpgradedToVersion: version.Current.Number,
StateAddresses: []string{gitjujutesting.MgoServer.Addr()},
CACert: testing.CACert,
Password: pwHash,
}
cfg, err := agent.NewAgentConfig(configParams)
c.Assert(err, gc.IsNil)
cfg.SetStateServingInfo(params.StateServingInfo{
APIPort: 5555,
StatePort: gitjujutesting.MgoServer.Port(),
Cert: "foo",
PrivateKey: "bar",
SharedSecret: "baz",
SystemIdentity: "qux",
})
expectConstraints := constraints.MustParse("mem=1024M")
expectHW := instance.MustParseHardware("mem=2048M")
mcfg := agent.BootstrapMachineConfig{
Constraints: expectConstraints,
Jobs: []params.MachineJob{params.JobHostUnits},
InstanceId: "i-bootstrap",
Characteristics: expectHW,
}
envAttrs := dummy.SampleConfig().Delete("admin-secret").Merge(testing.Attrs{
"agent-version": version.Current.Number.String(),
"state-id": "1", // needed so policy can Open config
})
envCfg, err := config.New(config.NoDefaults, envAttrs)
c.Assert(err, gc.IsNil)
st, _, err := agent.InitializeState(cfg, envCfg, mcfg, mongo.DialOpts{}, environs.NewStatePolicy())
c.Assert(err, gc.IsNil)
err = st.SetAdminMongoPassword("")
c.Check(err, gc.IsNil)
st.Close()
st, _, err = agent.InitializeState(cfg, envCfg, mcfg, mongo.DialOpts{}, environs.NewStatePolicy())
if err == nil {
st.Close()
}
c.Assert(err, gc.ErrorMatches, "failed to initialize state: cannot create log collection: unauthorized mongo access: unauthorized")
}
开发者ID:rogpeppe,项目名称:juju,代码行数:49,代码来源:bootstrap_test.go
示例18: TestInitializeStateFailsSecondTime
func (s *bootstrapSuite) TestInitializeStateFailsSecondTime(c *gc.C) {
dataDir := c.MkDir()
pwHash := utils.UserPasswordHash(testing.DefaultMongoPassword, utils.CompatSalt)
configParams := agent.AgentConfigParams{
Paths: agent.Paths{DataDir: dataDir},
Tag: names.NewMachineTag("0"),
UpgradedToVersion: version.Current.Number,
StateAddresses: []string{s.mgoInst.Addr()},
CACert: testing.CACert,
Password: pwHash,
Environment: testing.EnvironmentTag,
}
cfg, err := agent.NewAgentConfig(configParams)
c.Assert(err, jc.ErrorIsNil)
cfg.SetStateServingInfo(params.StateServingInfo{
APIPort: 5555,
StatePort: s.mgoInst.Port(),
Cert: "foo",
PrivateKey: "bar",
SharedSecret: "baz",
SystemIdentity: "qux",
})
expectConstraints := constraints.MustParse("mem=1024M")
expectHW := instance.MustParseHardware("mem=2048M")
mcfg := agent.BootstrapMachineConfig{
Constraints: expectConstraints,
Jobs: []multiwatcher.MachineJob{multiwatcher.JobManageEnviron},
InstanceId: "i-bootstrap",
Characteristics: expectHW,
}
envAttrs := dummy.SampleConfig().Delete("admin-secret").Merge(testing.Attrs{
"agent-version": version.Current.Number.String(),
"state-id": "1", // needed so policy can Open config
})
envCfg, err := config.New(config.NoDefaults, envAttrs)
c.Assert(err, jc.ErrorIsNil)
adminUser := names.NewLocalUserTag("agent-admin")
st, _, err := agent.InitializeState(adminUser, cfg, envCfg, mcfg, mongo.DefaultDialOpts(), environs.NewStatePolicy())
c.Assert(err, jc.ErrorIsNil)
st.Close()
st, _, err = agent.InitializeState(adminUser, cfg, envCfg, mcfg, mongo.DefaultDialOpts(), environs.NewStatePolicy())
if err == nil {
st.Close()
}
c.Assert(err, gc.ErrorMatches, "failed to initialize mongo admin user: cannot set admin password: not authorized .*")
}
开发者ID:kakamessi99,项目名称:juju,代码行数:49,代码来源:bootstrap_test.go
示例19: TestBootstrapSeries
func (s *BootstrapSuite) TestBootstrapSeries(c *gc.C) {
s.PatchValue(&jujuversion.Current, coretesting.FakeVersionNumber)
s.PatchValue(&series.HostSeries, func() string { return "precise" })
stor := newStorage(s, c)
checkInstanceId := "i-success"
checkHardware := instance.MustParseHardware("arch=ppc64el mem=2T")
startInstance := func(_ string, _ constraints.Value, _ []string, _ tools.List, icfg *instancecfg.InstanceConfig) (instance.Instance,
*instance.HardwareCharacteristics, []network.InterfaceInfo, error) {
return &mockInstance{id: checkInstanceId}, &checkHardware, nil, nil
}
var mocksConfig = minimalConfig(c)
var numGetConfigCalled int
getConfig := func() *config.Config {
numGetConfigCalled++
return mocksConfig
}
setConfig := func(c *config.Config) error {
mocksConfig = c
return nil
}
env := &mockEnviron{
storage: stor,
startInstance: startInstance,
config: getConfig,
setConfig: setConfig,
}
ctx := envtesting.BootstrapContext(c)
bootstrapSeries := "utopic"
result, err := common.Bootstrap(ctx, env, environs.BootstrapParams{
ControllerConfig: coretesting.FakeControllerConfig(),
BootstrapSeries: bootstrapSeries,
AvailableTools: tools.List{
&tools.Tools{
Version: version.Binary{
Number: jujuversion.Current,
Arch: arch.HostArch(),
Series: bootstrapSeries,
},
},
}})
c.Assert(err, jc.ErrorIsNil)
c.Check(result.Arch, gc.Equals, "ppc64el") // based on hardware characteristics
c.Check(result.Series, gc.Equals, bootstrapSeries)
}
开发者ID:bac,项目名称:juju,代码行数:46,代码来源:bootstrap_test.go
示例20: TestMachineConfigNoTools
func (s *machineConfigSuite) TestMachineConfigNoTools(c *gc.C) {
s.PatchValue(&envtools.DefaultBaseURL, "")
addrs := network.NewAddresses("1.2.3.4")
hc := instance.MustParseHardware("mem=4G arch=amd64")
apiParams := params.AddMachineParams{
Series: "quantal",
Jobs: []multiwatcher.MachineJob{multiwatcher.JobHostUnits},
InstanceId: instance.Id("1234"),
Nonce: "foo",
HardwareCharacteristics: hc,
Addrs: params.FromNetworkAddresses(addrs),
}
machines, err := s.APIState.Client().AddMachines([]params.AddMachineParams{apiParams})
c.Assert(err, jc.ErrorIsNil)
_, err = client.InstanceConfig(s.State, machines[0].Machine, apiParams.Nonce, "")
c.Assert(err, gc.ErrorMatches, coretools.ErrNoMatches.Error())
}
开发者ID:imoapps,项目名称:juju,代码行数:17,代码来源:instanceconfig_test.go
注:本文中的github.com/juju/juju/instance.MustParseHardware函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论