-func (s *bootstrapSuite) assertUploadTools(c *gc.C, vers version.Binary,
allowRelease bool, errMessage string) {
+func (s *bootstrapSuite) assertUploadTools(c *gc.C, vers version.Binary,
allowRelease bool,
+ extraConfig map[string]interface{}, errMessage string) {
+
s.PatchValue(&version.Current, vers)
// If we allow released tools to be uploaded, the build number is
incremented so in that case
// we need to ensure the environment is set up to allow dev tools to be
used.
- env := newEnviron("foo", useDefaultKeys,
map[string]interface{}{"development": allowRelease})
+ env := newEnviron("foo", useDefaultKeys, extraConfig)
s.setDummyStorage(c, env)
envtesting.RemoveFakeTools(c, env.Storage())
func (s *bootstrapSuite) TestUploadToolsReleaseVersionDisallowed(c *gc.C) {
vers := version.MustParseBinary("1.18.0-trusty-arm64")
- s.assertUploadTools(c, vers, false, "Juju cannot bootstrap because no
tools are available for your environment.*")
+ s.assertUploadTools(c, vers, false, nil, "Juju cannot bootstrap because
no tools are available for your environment.*")
}
// UploadTools uploads tools for the specified series and any other
relevant series to
-// the environment storage, after which it sets the agent-version.
-func UploadTools(env environs.Environ, toolsArch *string, allowRelease
bool, bootstrapSeries ...string) error {
+// the environment storage, after which it sets the agent-version. If
forceVersion is true,
+// we allow uploading release tools versions and allow uploading even when
the agent-version is
+// already set in the environment.
+func UploadTools(env environs.Environ, toolsArch *string, forceVersion
bool, bootstrapSeries ...string) error {
logger.Infof("checking that upload is possible")
// Check the series are valid.
for _, series := range bootstrapSeries {
@@ -37,15 +39,15 @@
}
}
// See that we are allowed to upload the tools.
- if err := validateUploadAllowed(env, toolsArch, allowRelease); err != nil
{
+ if err := validateUploadAllowed(env, toolsArch, forceVersion); err != nil
{
return err
}
// validateUploadAllowed returns an error if an attempt to upload tools
should
// not be allowed.
-func validateUploadAllowed(env environs.Environ, toolsArch *string,
allowRelease bool) error {
- // First, check that there isn't already an agent version specified, and
that we
- // are running a development version.
- if _, hasAgentVersion := env.Config().AgentVersion(); hasAgentVersion ||
(!allowRelease && !version.Current.IsDev()) {
- return fmt.Errorf(noToolsNoUploadMessage)
+func validateUploadAllowed(env environs.Environ, toolsArch *string,
forceVersion bool) error {
+ if !forceVersion {
+ // First, check that there isn't already an agent version specified, and
that we
+ // are running a development version.
+ if _, hasAgentVersion := env.Config().AgentVersion(); hasAgentVersion |
| !version.Current.IsDev() {
+ return fmt.Errorf(noToolsNoUploadMessage)
+ }
}
-
// Now check that the architecture for which we are setting up an
// environment matches that from which we are bootstrapping.
hostArch := arch.HostArch()
Reviewers: mp+211831_ code.launchpad. net,
Message:
Please take a look.
Description:
Fix tools upload for local provider.
Local provider inserts agent-version into config
when the environment is opened and this was
preventing tools from being uploaded.
https:/ /code.launchpad .net/~wallyworl d/juju- core/fix- local-bootstrap -tools/ +merge/ 211831
(do not edit description out of merge proposal)
Please review this at https:/ /codereview. appspot. com/77960043/
Affected files (+34, -20 lines): bootstrap/ bootstrap_ test.go bootstrap/ synctools. go
A [revision details]
M environs/
M environs/
Index: [revision details] 20140319193533- t6r49574qjs0jkq w
=== added file '[revision details]'
--- [revision details] 2012-01-01 00:00:00 +0000
+++ [revision details] 2012-01-01 00:00:00 +0000
@@ -0,0 +1,2 @@
+Old revision: tarmac-
+New revision: <email address hidden>
Index: environs/ bootstrap/ bootstrap_ test.go bootstrap/ bootstrap_ test.go' bootstrap/ bootstrap_ test.go 2014-03-19 01:20:14 +0000 bootstrap/ bootstrap_ test.go 2014-03-19 22:02:00 +0000 bootstrap. SeriesToUpload( cfg, nil), gc.DeepEquals,
=== modified file 'environs/
--- environs/
+++ environs/
@@ -331,11 +331,13 @@
c.Assert(
[]string{"quantal", "precise", "lucid"})
}
-func (s *bootstrapSuite) assertUploadTools(c *gc.C, vers version.Binary, interface{ }, errMessage string) { (&version. Current, vers) interface{ }{"development" : allowRelease}) orage(c, env) RemoveFakeTools (c, env.Storage())
allowRelease bool, errMessage string) {
+func (s *bootstrapSuite) assertUploadTools(c *gc.C, vers version.Binary,
allowRelease bool,
+ extraConfig map[string]
+
s.PatchValue
// If we allow released tools to be uploaded, the build number is
incremented so in that case
// we need to ensure the environment is set up to allow dev tools to be
used.
- env := newEnviron("foo", useDefaultKeys,
map[string]
+ env := newEnviron("foo", useDefaultKeys, extraConfig)
s.setDummySt
envtesting.
@@ -372,17 +374,24 @@
func (s *bootstrapSuite) TestUploadTools(c *gc.C) { MustParseBinary ("1.19. 0-trusty- arm64") ools(c, vers, false, "") ReleaseVersionA llowed( c *gc.C) { MustParseBinary ("1.18. 0-trusty- arm64") ools(c, vers, true, "") ools(c, vers, false, nil, "") ForceVersionAll owsReleaseTools (c MustParseBinary ("1.18. 0-trusty- arm64") interface{ }{"development" : true} ools(c, vers, true, extraCfg, "") ForceVersionAll owsAgentVersion Set(c *gc.C) { MustParseBinary ("1.18. 0-trusty- arm64") interface{ }{"agent- version" : "1.18.0", "development": true} ools(c, vers, true, extraCfg, "")
vers := version.
- s.assertUploadT
-}
-
-func (s *bootstrapSuite) TestUploadTools
- vers := version.
- s.assertUploadT
+ s.assertUploadT
+}
+
+func (s *bootstrapSuite) TestUploadTools
*gc.C) {
+ vers := version.
+ extraCfg := map[string]
+ s.assertUploadT
+}
+
+func (s *bootstrapSuite)
TestUploadTools
+ vers := version.
+ extraCfg :=
map[string]
+ s.assertUploadT
}
func (s *bootstrapSuite) TestUploadTools ReleaseVersionD isallowed( c *gc.C) { MustParseBinary ("1.18. 0-trusty- arm64") ools(c, vers, false, "Juju cannot bootstrap because no ools(c, vers, false, nil, "Juju cannot bootstrap because
vers := version.
- s.assertUploadT
tools are available for your environment.*")
+ s.assertUploadT
no tools are available for your environment.*")
}
type bootstrapEnviron struct {
Index: environs/ bootstrap/ synctools. go bootstrap/ synctools. go' bootstrap/ synctools. go 2014-03-19 02:55:15 +0000 bootstrap/ synctools. go 2014-03-19 22:02:00 +0000
=== modified file 'environs/
--- environs/
+++ environs/
@@ -27,8 +27,10 @@
`
// UploadTools uploads tools for the specified series and any other Infof(" checking that upload is possible") llowed( env, toolsArch, allowRelease); err != nil llowed( env, toolsArch, forceVersion); err != nil
relevant series to
-// the environment storage, after which it sets the agent-version.
-func UploadTools(env environs.Environ, toolsArch *string, allowRelease
bool, bootstrapSeries ...string) error {
+// the environment storage, after which it sets the agent-version. If
forceVersion is true,
+// we allow uploading release tools versions and allow uploading even when
the agent-version is
+// already set in the environment.
+func UploadTools(env environs.Environ, toolsArch *string, forceVersion
bool, bootstrapSeries ...string) error {
logger.
// Check the series are valid.
for _, series := range bootstrapSeries {
@@ -37,15 +39,15 @@
}
}
// See that we are allowed to upload the tools.
- if err := validateUploadA
{
+ if err := validateUploadA
{
return err
}
cfg := env.Config() version. Current. Number, nil) version. Current. Number, nil) Infof(" uploading tools for series %s", uploadSeries) env.Storage( ), &forceVersion, uploadSeries...) env.Storage( ), &explicitVersion,
- forceVersion := uploadVersion(
+ explicitVersion := uploadVersion(
uploadSeries := SeriesToUpload(cfg, bootstrapSeries)
logger.
- tools, err := sync.Upload(
+ tools, err := sync.Upload(
uploadSeries...)
if err != nil {
return err
}
@@ -91,13 +93,14 @@
// validateUploadA llowed returns an error if an attempt to upload tools llowed( env environs.Environ, toolsArch *string, ).AgentVersion( ); hasAgentVersion || Current. IsDev() ) { noToolsNoUpload Message) llowed( env environs.Environ, toolsArch *string, ).AgentVersion( ); hasAgentVersion | Current. IsDev() { noToolsNoUpload Message)
should
// not be allowed.
-func validateUploadA
allowRelease bool) error {
- // First, check that there isn't already an agent version specified, and
that we
- // are running a development version.
- if _, hasAgentVersion := env.Config(
(!allowRelease && !version.
- return fmt.Errorf(
+func validateUploadA
forceVersion bool) error {
+ if !forceVersion {
+ // First, check that there isn't already an agent version specified, and
that we
+ // are running a development version.
+ if _, hasAgentVersion := env.Config(
| !version.
+ return fmt.Errorf(
+ }
}
-
// Now check that the architecture for which we are setting up an
// environment matches that from which we are bootstrapping.
hostArch := arch.HostArch()