Exemplo n.º 1
0
// PreferredStream returns the tools stream used to search for tools, based
// on the required version, whether devel mode is required, and any user specified stream.
func PreferredStream(vers *version.Number, forceDevel bool, stream string) string {
	// If the use has already nominated a specific stream, we'll use that.
	if stream != "" && stream != ReleasedStream {
		return stream
	}
	// If we're not upgrading from a known version, we use the
	// currently running version.
	if vers == nil {
		vers = &jujuversion.Current
	}
	// Devel versions are alpha or beta etc as defined by the version tag.
	// The user can also force the use of devel streams via config.
	if forceDevel || jujuversion.IsDev(*vers) {
		return DevelStream
	}
	return ReleasedStream
}
Exemplo n.º 2
0
func (s *toolsSuite) TestFindBootstrapTools(c *gc.C) {
	var called int
	var filter tools.Filter
	var findStream string
	s.PatchValue(bootstrap.FindTools, func(_ environs.Environ, major, minor int, stream string, f tools.Filter) (tools.List, error) {
		called++
		c.Check(major, gc.Equals, jujuversion.Current.Major)
		c.Check(minor, gc.Equals, jujuversion.Current.Minor)
		findStream = stream
		filter = f
		return nil, nil
	})

	vers := version.MustParse("1.2.1")
	devVers := version.MustParse("1.2-beta1")
	arm64 := "arm64"

	type test struct {
		version *version.Number
		arch    *string
		series  *string
		dev     bool
		filter  tools.Filter
		stream  string
	}
	tests := []test{{
		version: nil,
		arch:    nil,
		series:  nil,
		dev:     true,
		filter:  tools.Filter{},
	}, {
		version: &vers,
		arch:    nil,
		series:  nil,
		dev:     false,
		filter:  tools.Filter{Number: vers},
	}, {
		version: &vers,
		arch:    &arm64,
		series:  nil,
		filter:  tools.Filter{Arch: arm64, Number: vers},
	}, {
		version: &vers,
		arch:    &arm64,
		series:  nil,
		dev:     true,
		filter:  tools.Filter{Arch: arm64, Number: vers},
	}, {
		version: &devVers,
		arch:    &arm64,
		series:  nil,
		filter:  tools.Filter{Arch: arm64, Number: devVers},
	}, {
		version: &devVers,
		arch:    &arm64,
		series:  nil,
		filter:  tools.Filter{Arch: arm64, Number: devVers},
		stream:  "devel",
	}}

	for i, test := range tests {
		c.Logf("test %d: %#v", i, test)
		extra := map[string]interface{}{"development": test.dev}
		if test.stream != "" {
			extra["agent-stream"] = test.stream
		}
		env := newEnviron("foo", useDefaultKeys, extra)
		bootstrap.FindBootstrapTools(env, test.version, test.arch, test.series)
		c.Assert(called, gc.Equals, i+1)
		c.Assert(filter, gc.Equals, test.filter)
		if test.stream != "" {
			c.Check(findStream, gc.Equals, test.stream)
		} else {
			if test.dev || jujuversion.IsDev(*test.version) {
				c.Check(findStream, gc.Equals, "devel")
			} else {
				c.Check(findStream, gc.Equals, "released")
			}
		}
	}
}