Skip to content

Commit

Permalink
Block cli changes.
Browse files Browse the repository at this point in the history
  • Loading branch information
anastasiamac committed Feb 26, 2015
1 parent 13c7ae1 commit db22748
Show file tree
Hide file tree
Showing 52 changed files with 1,157 additions and 1,079 deletions.
4 changes: 2 additions & 2 deletions api/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -815,8 +815,8 @@ func (c *Client) UploadTools(r io.Reader, vers version.Binary, additionalSeries
}
if resp.StatusCode != http.StatusOK {
message := fmt.Sprintf("%s", bytes.TrimSpace(body))
if resp.StatusCode == http.StatusBadRequest && strings.Contains(message, "The operation has been blocked.") {
// Operation Blocked errors must contain correct Error Code
if resp.StatusCode == http.StatusBadRequest && strings.Contains(message, params.CodeOperationBlocked) {
// Operation Blocked errors must contain correct error code and message.
return nil, &params.Error{Code: params.CodeOperationBlocked, Message: message}
}
return nil, errors.Errorf("tools upload failed: %v (%s)", resp.StatusCode, message)
Expand Down
7 changes: 7 additions & 0 deletions apiserver/client/api_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import (
gc "gopkg.in/check.v1"

"github.com/juju/juju/api"
commontesting "github.com/juju/juju/apiserver/common/testing"
"github.com/juju/juju/constraints"
"github.com/juju/juju/environs"
"github.com/juju/juju/environs/config"
Expand All @@ -32,6 +33,12 @@ func TestAll(t *stdtesting.T) {

type baseSuite struct {
testing.JujuConnSuite
commontesting.BlockSwitch
}

func (s *baseSuite) SetUpTest(c *gc.C) {
s.JujuConnSuite.SetUpTest(c)
s.BlockSwitch = commontesting.NewBlockSwitch(s.APIState)
}

var _ = gc.Suite(&baseSuite{})
Expand Down
9 changes: 1 addition & 8 deletions apiserver/client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -1121,14 +1121,7 @@ func (c *Client) EnvironmentGet() (params.EnvironmentConfigResults, error) {
// set-environment CLI command.
func (c *Client) EnvironmentSet(args params.EnvironmentSet) error {
if err := c.check.ChangeAllowed(); err != nil {
// if trying to change value for block-changes, we would want to let it go.
if v, present := args.Config[config.PreventAllChangesKey]; !present {
return errors.Trace(err)
} else if block, ok := v.(bool); ok && block {
// still want to block changes
return errors.Trace(err)
}
// else if block is false, we want to unblock changes
return errors.Trace(err)
}
// Make sure we don't allow changing agent-version.
checkAgentVersion := func(updateAttrs map[string]interface{}, removeAttrs []string, oldConfig *config.Config) error {
Expand Down
Loading

0 comments on commit db22748

Please sign in to comment.