本文整理汇总了Golang中github.com/juju/juju/environs/tools.FindTools函数的典型用法代码示例。如果您正苦于以下问题:Golang FindTools函数的具体用法?Golang FindTools怎么用?Golang FindTools使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了FindTools函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: TestSyncing
func (s *syncSuite) TestSyncing(c *gc.C) {
for i, test := range tests {
// Perform all tests in a "clean" environment.
func() {
s.setUpTest(c)
defer s.tearDownTest(c)
c.Logf("test %d: %s", i, test.description)
if test.source {
test.ctx.Source = s.localStorage
}
if test.version != version.Zero {
version.Current.Number = test.version
}
if test.major > 0 {
test.ctx.MajorVersion = test.major
test.ctx.MinorVersion = test.minor
}
stor := s.targetEnv.Storage()
test.ctx.TargetToolsFinder = sync.StorageToolsFinder{stor}
test.ctx.TargetToolsUploader = sync.StorageToolsUploader{stor, true, false}
err := sync.SyncTools(test.ctx)
c.Assert(err, gc.IsNil)
targetTools, err := envtools.FindTools(
s.targetEnv, test.ctx.MajorVersion, test.ctx.MinorVersion, coretools.Filter{}, envtools.DoNotAllowRetry)
c.Assert(err, gc.IsNil)
assertToolsList(c, targetTools, test.tools)
assertNoUnexpectedTools(c, s.targetEnv.Storage())
assertMirrors(c, s.targetEnv.Storage(), test.expectMirrors)
}()
}
}
示例2: TestFindToolsFiltering
func (s *SimpleStreamsToolsSuite) TestFindToolsFiltering(c *gc.C) {
var tw loggo.TestWriter
c.Assert(loggo.RegisterWriter("filter-tester", &tw, loggo.TRACE), gc.IsNil)
defer loggo.RemoveWriter("filter-tester")
logger := loggo.GetLogger("juju.environs")
defer logger.SetLogLevel(logger.LogLevel())
logger.SetLogLevel(loggo.TRACE)
_, err := envtools.FindTools(
s.env, 1, -1, "released", coretools.Filter{Number: version.Number{Major: 1, Minor: 2, Patch: 3}})
c.Assert(err, jc.Satisfies, errors.IsNotFound)
// This is slightly overly prescriptive, but feel free to change or add
// messages. This still helps to ensure that all log messages are
// properly formed.
messages := []jc.SimpleMessage{
{loggo.INFO, "reading tools with major version 1"},
{loggo.INFO, "filtering tools by version: \\d+\\.\\d+\\.\\d+"},
{loggo.TRACE, "no architecture specified when finding tools, looking for "},
{loggo.TRACE, "no series specified when finding tools, looking for \\[.*\\]"},
}
sources, err := envtools.GetMetadataSources(s.env)
c.Assert(err, jc.ErrorIsNil)
for i := 0; i < 2*len(sources); i++ {
messages = append(messages,
jc.SimpleMessage{loggo.TRACE, `fetchData failed for .*`},
jc.SimpleMessage{loggo.TRACE, `cannot load index .*`})
}
c.Check(tw.Log(), jc.LogMatches, messages)
}
示例3: TestAutoUploadAfterFailedSync
func (s *BootstrapSuite) TestAutoUploadAfterFailedSync(c *gc.C) {
s.PatchValue(&version.Current.Series, config.LatestLtsSeries())
otherSeries := "quantal"
env := s.setupAutoUploadTest(c, "1.7.3", otherSeries)
// Run command and check for that upload has been run for tools matching the current juju version.
opc, errc := runCommand(nullContext(c), envcmd.Wrap(new(BootstrapCommand)))
c.Assert(<-errc, gc.IsNil)
c.Assert((<-opc).(dummy.OpPutFile).Env, gc.Equals, "peckham")
list, err := envtools.FindTools(env, version.Current.Major, version.Current.Minor, coretools.Filter{}, false)
c.Assert(err, gc.IsNil)
c.Logf("found: " + list.String())
urls := list.URLs()
// We expect:
// supported LTS series precise, trusty,
// the specified series (quantal),
// and the environment's default series (raring).
expectedVers := []version.Binary{
version.MustParseBinary(fmt.Sprintf("1.7.3.1-%s-%s", "quantal", version.Current.Arch)),
version.MustParseBinary(fmt.Sprintf("1.7.3.1-%s-%s", "raring", version.Current.Arch)),
version.MustParseBinary(fmt.Sprintf("1.7.3.1-%s-%s", "precise", version.Current.Arch)),
version.MustParseBinary(fmt.Sprintf("1.7.3.1-%s-%s", "trusty", version.Current.Arch)),
}
c.Assert(urls, gc.HasLen, len(expectedVers))
for _, vers := range expectedVers {
c.Logf("seeking: " + vers.String())
_, found := urls[vers]
c.Check(found, gc.Equals, true)
}
}
示例4: processGet
// processGet handles a tools GET request.
func (h *toolsDownloadHandler) processGet(r *http.Request) (*tools.Tools, utils.SSLHostnameVerification, error) {
version, err := version.ParseBinary(r.URL.Query().Get(":version"))
if err != nil {
return nil, false, err
}
cfg, err := h.state.EnvironConfig()
if err != nil {
return nil, false, err
}
env, err := environs.New(cfg)
if err != nil {
return nil, false, err
}
filter := tools.Filter{
Number: version.Number,
Series: version.Series,
Arch: version.Arch,
}
tools, err := envtools.FindTools(env, version.Major, version.Minor, filter, false)
if err != nil {
return nil, false, errors.Annotate(err, "failed to find tools")
}
verify := utils.SSLHostnameVerification(cfg.SSLHostnameVerification())
return tools[0], verify, nil
}
示例5: TestFindTools
func (s *SimpleStreamsToolsSuite) TestFindTools(c *gc.C) {
for i, test := range findToolsTests {
c.Logf("\ntest %d: %s", i, test.info)
s.reset(c, nil)
custom := s.uploadCustom(c, test.custom...)
public := s.uploadPublic(c, test.public...)
stream := envtools.PreferredStream(&version.Current, s.env.Config().Development(), s.env.Config().AgentStream())
actual, err := envtools.FindTools(s.env, test.major, test.minor, stream, coretools.Filter{})
if test.err != nil {
if len(actual) > 0 {
c.Logf(actual.String())
}
c.Check(err, jc.Satisfies, errors.IsNotFound)
continue
}
expect := map[version.Binary]string{}
for _, expected := range test.expect {
// If the tools exist in custom, that's preferred.
var ok bool
if expect[expected], ok = custom[expected]; !ok {
expect[expected] = public[expected]
}
}
c.Check(actual.URLs(), gc.DeepEquals, expect)
}
}
示例6: TestFindToolsFiltering
func (s *SimpleStreamsToolsSuite) TestFindToolsFiltering(c *gc.C) {
tw := &loggo.TestWriter{}
c.Assert(loggo.RegisterWriter("filter-tester", tw, loggo.DEBUG), gc.IsNil)
defer loggo.RemoveWriter("filter-tester")
_, err := envtools.FindTools(
s.env, 1, -1, coretools.Filter{Number: version.Number{Major: 1, Minor: 2, Patch: 3}}, envtools.DoNotAllowRetry)
c.Assert(err, jc.Satisfies, errors.IsNotFound)
// This is slightly overly prescriptive, but feel free to change or add
// messages. This still helps to ensure that all log messages are
// properly formed.
messages := []jc.SimpleMessage{
{loggo.INFO, "reading tools with major version 1"},
{loggo.INFO, "filtering tools by version: \\d+\\.\\d+\\.\\d+"},
{loggo.DEBUG, "no architecture specified when finding tools, looking for any"},
{loggo.DEBUG, "no series specified when finding tools, looking for any"},
}
sources, err := envtools.GetMetadataSources(s.env)
c.Assert(err, gc.IsNil)
for i := 0; i < 2*len(sources); i++ {
messages = append(messages,
jc.SimpleMessage{loggo.DEBUG, `fetchData failed for .*`},
jc.SimpleMessage{loggo.DEBUG, `cannot load index .*`})
}
c.Check(tw.Log, jc.LogMatches, messages)
}
示例7: StartInstanceWithParams
// StartInstanceWithParams is a test helper function that starts an instance
// with the given parameters, and a plausible but invalid configuration, and
// returns the result of Environ.StartInstance. The provided params's
// InstanceConfig and Tools field values will be ignored.
func StartInstanceWithParams(
env environs.Environ, machineId string,
params environs.StartInstanceParams,
networks []string,
) (
*environs.StartInstanceResult, error,
) {
preferredSeries := config.PreferredSeries(env.Config())
agentVersion, ok := env.Config().AgentVersion()
if !ok {
return nil, errors.New("missing agent version in model config")
}
filter := coretools.Filter{
Number: agentVersion,
Series: preferredSeries,
}
if params.Constraints.Arch != nil {
filter.Arch = *params.Constraints.Arch
}
stream := tools.PreferredStream(&agentVersion, env.Config().Development(), env.Config().AgentStream())
possibleTools, err := tools.FindTools(env, -1, -1, stream, filter)
if err != nil {
return nil, errors.Trace(err)
}
if params.ImageMetadata == nil {
if err := SetImageMetadata(
env,
possibleTools.AllSeries(),
possibleTools.Arches(),
¶ms.ImageMetadata,
); err != nil {
return nil, errors.Trace(err)
}
}
machineNonce := "fake_nonce"
stateInfo := FakeStateInfo(machineId)
apiInfo := FakeAPIInfo(machineId)
instanceConfig, err := instancecfg.NewInstanceConfig(
machineId,
machineNonce,
imagemetadata.ReleasedStream,
preferredSeries,
"",
true,
networks,
stateInfo,
apiInfo,
)
if err != nil {
return nil, errors.Trace(err)
}
eUUID, _ := env.Config().UUID()
instanceConfig.Tags[tags.JujuModel] = eUUID
params.Tools = possibleTools
params.InstanceConfig = instanceConfig
return env.StartInstance(params)
}
示例8: checkTools
// checkTools check if the environment contains the passed envtools.
func checkTools(c *gc.C, env environs.Environ, expected []version.Binary) {
list, err := envtools.FindTools(
env, version.Current.Major, version.Current.Minor, "released", coretools.Filter{})
c.Check(err, jc.ErrorIsNil)
c.Logf("found: " + list.String())
urls := list.URLs()
c.Check(urls, gc.HasLen, len(expected))
}
示例9: findTools1dot17
// findTools1dot17 allows 1.17.x versions to be upgraded.
func findTools1dot17(cfg *config.Config) (coretools.List, error) {
logger.Warningf("running find tools in 1.17 compatibility mode")
env, err := environs.New(cfg)
if err != nil {
return nil, err
}
clientVersion := version.Current.Number
return envtools.FindTools(env, clientVersion.Major, -1, coretools.Filter{}, envtools.DoNotAllowRetry)
}
示例10: TestFindToolsInControlBucket
func (s *SimpleStreamsToolsSuite) TestFindToolsInControlBucket(c *gc.C) {
s.reset(c, nil)
custom := toolstesting.UploadToStorage(c, s.env.Storage(), envtesting.V110p...)
s.uploadPublic(c, envtesting.VAll...)
actual, err := envtools.FindTools(s.env, 1, 1, coretools.Filter{}, envtools.DoNotAllowRetry)
c.Assert(err, gc.IsNil)
expect := map[version.Binary]string{}
for _, expected := range envtesting.V110p {
expect[expected] = custom[expected]
}
c.Assert(actual.URLs(), gc.DeepEquals, expect)
}
示例11: TestInvalidLocalSource
func (s *BootstrapSuite) TestInvalidLocalSource(c *gc.C) {
s.PatchValue(&version.Current.Number, version.MustParse("1.2.0"))
env := resetJujuHome(c, "devenv")
// Bootstrap the environment with an invalid source.
// The command returns with an error.
_, err := coretesting.RunCommand(c, envcmd.Wrap(&BootstrapCommand{}), "--metadata-source", c.MkDir())
c.Check(err, gc.ErrorMatches, `failed to bootstrap environment: Juju cannot bootstrap because no tools are available for your environment(.|\n)*`)
// Now check that there are no tools available.
_, err = envtools.FindTools(
env, version.Current.Major, version.Current.Minor, "released", coretools.Filter{})
c.Assert(err, gc.FitsTypeOf, errors.NotFoundf(""))
}
示例12: StartInstanceWithParams
// StartInstanceWithParams is a test helper function that starts an instance
// with the given parameters, and a plausible but invalid configuration, and
// returns the result of Environ.StartInstance. The provided params's
// MachineConfig and Tools field values will be ignored.
func StartInstanceWithParams(
env environs.Environ, machineId string,
params environs.StartInstanceParams,
networks []string,
) (
instance.Instance, *instance.HardwareCharacteristics, []network.Info, error,
) {
series := config.PreferredSeries(env.Config())
agentVersion, ok := env.Config().AgentVersion()
if !ok {
return nil, nil, nil, fmt.Errorf("missing agent version in environment config")
}
filter := coretools.Filter{
Number: agentVersion,
Series: series,
}
if params.Constraints.Arch != nil {
filter.Arch = *params.Constraints.Arch
}
possibleTools, err := tools.FindTools(
env, -1, -1, filter, tools.DoNotAllowRetry,
)
if err != nil {
return nil, nil, nil, err
}
machineNonce := "fake_nonce"
stateInfo := FakeStateInfo(machineId)
apiInfo := FakeAPIInfo(machineId)
machineConfig, err := environs.NewMachineConfig(
machineId,
machineNonce,
imagemetadata.ReleasedStream,
series,
networks,
stateInfo,
apiInfo,
)
if err != nil {
return nil, nil, nil, err
}
params.Tools = possibleTools
params.MachineConfig = machineConfig
return env.StartInstance(params)
}
示例13: TestPossibleTools
func (s *ProvisionerSuite) TestPossibleTools(c *gc.C) {
storageDir := c.MkDir()
s.PatchValue(&tools.DefaultBaseURL, storageDir)
stor, err := filestorage.NewFileStorageWriter(storageDir)
c.Assert(err, jc.ErrorIsNil)
// Set a current version that does not match the
// agent-version in the environ config.
currentVersion := version.MustParseBinary("1.2.3-quantal-arm64")
s.PatchValue(&arch.HostArch, func() string { return currentVersion.Arch })
s.PatchValue(&series.HostSeries, func() string { return currentVersion.Series })
s.PatchValue(&version.Current, currentVersion.Number)
// Upload some plausible matches, and some that should be filtered out.
compatibleVersion := version.MustParseBinary("1.2.3-quantal-amd64")
ignoreVersion1 := version.MustParseBinary("1.2.4-quantal-arm64")
ignoreVersion2 := version.MustParseBinary("1.2.3-precise-arm64")
availableVersions := []version.Binary{
currentVersion, compatibleVersion, ignoreVersion1, ignoreVersion2,
}
envtesting.AssertUploadFakeToolsVersions(c, stor, s.cfg.AgentStream(), s.cfg.AgentStream(), availableVersions...)
// Extract the tools that we expect to actually match.
expectedList, err := tools.FindTools(s.Environ, -1, -1, s.cfg.AgentStream(), coretools.Filter{
Number: currentVersion.Number,
Series: currentVersion.Series,
})
c.Assert(err, jc.ErrorIsNil)
// Create the machine and check the tools that get passed into StartInstance.
machine, err := s.BackingState.AddOneMachine(state.MachineTemplate{
Series: "quantal",
Jobs: []state.MachineJob{state.JobHostUnits},
})
c.Assert(err, jc.ErrorIsNil)
provisioner := s.newEnvironProvisioner(c)
defer stop(c, provisioner)
s.checkStartInstanceCustom(
c, machine, "pork", constraints.Value{},
nil, nil, nil, nil, false, expectedList, true,
)
}
示例14: StartInstanceWithParams
// StartInstanceWithParams is a test helper function that starts an instance
// with the given parameters, and a plausible but invalid configuration, and
// returns the result of Environ.StartInstance. The provided params's
// InstanceConfig and Tools field values will be ignored.
func StartInstanceWithParams(
env environs.Environ, machineId string,
params environs.StartInstanceParams,
networks []string,
) (
*environs.StartInstanceResult, error,
) {
series := config.PreferredSeries(env.Config())
agentVersion, ok := env.Config().AgentVersion()
if !ok {
return nil, errors.New("missing agent version in environment config")
}
filter := coretools.Filter{
Number: agentVersion,
Series: series,
}
if params.Constraints.Arch != nil {
filter.Arch = *params.Constraints.Arch
}
possibleTools, err := tools.FindTools(env, -1, -1, filter)
if err != nil {
return nil, errors.Trace(err)
}
machineNonce := "fake_nonce"
stateInfo := FakeStateInfo(machineId)
apiInfo := FakeAPIInfo(machineId)
instanceConfig, err := instancecfg.NewInstanceConfig(
machineId,
machineNonce,
imagemetadata.ReleasedStream,
series,
true,
networks,
stateInfo,
apiInfo,
)
if err != nil {
return nil, errors.Trace(err)
}
params.Tools = possibleTools
params.InstanceConfig = instanceConfig
return env.StartInstance(params)
}
示例15: TestPossibleTools
func (s *ProvisionerSuite) TestPossibleTools(c *gc.C) {
// Clear out all tools, and set a current version that does not match the
// agent-version in the environ config.
envStorage := s.Environ.Storage()
envtesting.RemoveFakeTools(c, envStorage)
currentVersion := version.MustParseBinary("1.2.3-quantal-arm64")
s.PatchValue(&version.Current, currentVersion)
// Upload some plausible matches, and some that should be filtered out.
compatibleVersion := version.MustParseBinary("1.2.3-quantal-amd64")
ignoreVersion1 := version.MustParseBinary("1.2.4-quantal-arm64")
ignoreVersion2 := version.MustParseBinary("1.2.3-precise-arm64")
availableVersions := []version.Binary{
currentVersion, compatibleVersion, ignoreVersion1, ignoreVersion2,
}
envtesting.AssertUploadFakeToolsVersions(c, envStorage, availableVersions...)
// Extract the tools that we expect to actually match.
expectedList, err := tools.FindTools(s.Environ, -1, -1, coretools.Filter{
Number: currentVersion.Number,
Series: currentVersion.Series,
}, tools.DoNotAllowRetry)
c.Assert(err, gc.IsNil)
// Create the machine and check the tools that get passed into StartInstance.
machine, err := s.BackingState.AddOneMachine(state.MachineTemplate{
Series: "quantal",
Jobs: []state.MachineJob{state.JobHostUnits},
})
c.Assert(err, gc.IsNil)
provisioner := s.newEnvironProvisioner(c)
defer stop(c, provisioner)
s.checkStartInstanceCustom(
c, machine, "pork", constraints.Value{},
nil, nil, expectedList, true,
)
}