func (s *AddRelationSuite) TestAddRelationBlocked(c *gc.C) { s.mockAPI.SetErrors(common.OperationBlockedError("TestBlockAddRelation")) err := s.runAddRelation(c, "application1", "application2") coretesting.AssertOperationWasBlocked(c, err, ".*TestBlockAddRelation.*") s.mockAPI.CheckCall(c, 0, "AddRelation", []string{"application1", "application2"}) s.mockAPI.CheckCall(c, 1, "Close") }
func (m *mockRunAPI) RunOnAllMachines(commands string, timeout time.Duration) ([]params.ActionResult, error) { var result []params.ActionResult if m.block { return result, common.OperationBlockedError("the operation has been blocked") } sortedMachineIds := make([]string, 0, len(m.machines)) for machineId := range m.machines { sortedMachineIds = append(sortedMachineIds, machineId) } sort.Strings(sortedMachineIds) for _, machineId := range sortedMachineIds { response, found := m.runResponses[machineId] if !found { // Consider this a timeout response = params.ActionResult{ Action: ¶ms.Action{ Receiver: names.NewMachineTag(machineId).String(), }, Message: exec.ErrCancelled.Error(), } } result = append(result, response) } return result, nil }
func (s *SetSuite) TestBlockedError(c *gc.C) { s.fake.err = common.OperationBlockedError("TestBlockedError") _, err := s.run(c, "special=extra") c.Assert(err, gc.Equals, cmd.ErrSilent) // msg is logged c.Check(c.GetTestLog(), jc.Contains, "TestBlockedError") }
func (s *DefaultsCommandSuite) TestResetBlockedError(c *gc.C) { s.fake.err = common.OperationBlockedError("TestBlockedError") _, err := s.run(c, "--reset", "attr") c.Assert(err, gc.Equals, cmd.ErrSilent) // msg is logged c.Check(c.GetTestLog(), jc.Contains, "TestBlockedError") }
func (s *AddMachineSuite) TestBlockedError(c *gc.C) { s.fakeAddMachine.addError = common.OperationBlockedError("TestBlockedError") _, err := s.run(c) c.Assert(err, gc.Equals, cmd.ErrSilent) // msg is logged stripped := strings.Replace(c.GetTestLog(), "\n", "", -1) c.Check(stripped, gc.Matches, ".*TestBlockedError.*") }
func (s *syncToolsSuite) TestAPIAdapterBlockUploadTools(c *gc.C) { syncTools = func(sctx *sync.SyncContext) error { // Block operation return common.OperationBlockedError("TestAPIAdapterBlockUploadTools") } _, err := s.runSyncToolsCommand(c, "-m", "test-target", "--destination", c.MkDir(), "--stream", "released") coretesting.AssertOperationWasBlocked(c, err, ".*TestAPIAdapterBlockUploadTools.*") }
func (s *ConstraintsCommandsSuite) TestBlockSetService(c *gc.C) { s.fake.addTestingService("svc") // Block operation s.fake.err = common.OperationBlockedError("TestBlockSetService") // Set constraints. s.assertSetBlocked(c, "-s", "svc", "mem=4G", "cpu-power=250") }
func (s *AddUnitSuite) TestBlockAddUnit(c *gc.C) { // Block operation s.fake.err = common.OperationBlockedError("TestBlockAddUnit") s.runAddUnit(c, "some-application-name") // msg is logged stripped := strings.Replace(c.GetTestLog(), "\n", "", -1) c.Check(stripped, gc.Matches, ".*TestBlockAddUnit.*") }
func (s *RemoveMachineSuite) TestBlockedError(c *gc.C) { s.fake.removeError = common.OperationBlockedError("TestBlockedError") _, err := s.run(c, "1") c.Assert(err, gc.Equals, cmd.ErrSilent) c.Assert(s.fake.forced, jc.IsFalse) // msg is logged stripped := strings.Replace(c.GetTestLog(), "\n", "", -1) c.Assert(stripped, gc.Matches, ".*TestBlockedError.*") }
func (s *EnableHASuite) TestBlockEnableHA(c *gc.C) { s.fake.err = common.OperationBlockedError("TestBlockEnableHA") _, err := s.runEnableHA(c, "-n", "1") c.Assert(err, gc.ErrorMatches, cmd.ErrSilent.Error()) // msg is logged stripped := strings.Replace(c.GetTestLog(), "\n", "", -1) c.Check(stripped, gc.Matches, ".*TestBlockEnableHA.*") }
func (s *syncToolsSuite) TestAPIAdapterBlockUploadTools(c *gc.C) { syncTools = func(sctx *sync.SyncContext) error { // Block operation return common.OperationBlockedError("TestAPIAdapterBlockUploadTools") } _, err := runSyncToolsCommand(c, "-m", "test-target", "--destination", c.MkDir(), "--stream", "released") c.Assert(err, gc.ErrorMatches, cmd.ErrSilent.Error()) // msg is logged stripped := strings.Replace(c.GetTestLog(), "\n", "", -1) c.Check(stripped, gc.Matches, ".*TestAPIAdapterBlockUploadTools.*") }
func (m *mockAddUserAPI) AddUser(username, displayname, password string) (names.UserTag, []byte, error) { if m.blocked { return names.UserTag{}, nil, common.OperationBlockedError("the operation has been blocked") } m.username = username m.displayname = displayname m.password = password if m.failMessage != "" { return names.UserTag{}, nil, errors.New(m.failMessage) } return names.NewLocalUserTag(username), m.secretKey, nil }
// DestroySystem will attempt to destroy the system. If the args specify the // removal of blocks or the destruction of the environments, this method will // attempt to do so. func (s *SystemManagerAPI) DestroySystem(args params.DestroySystemArgs) error { // Get list of all environments in the system. allEnvs, err := s.state.AllEnvironments() if err != nil { return errors.Trace(err) } // If there are hosted environments and DestroyEnvironments was not // specified, don't bother trying to destroy the system, as it will fail. if len(allEnvs) > 1 && !args.DestroyEnvironments { return errors.Errorf("state server environment cannot be destroyed before all other environments are destroyed") } // If there are blocks, and we aren't being told to ignore them, let the // user know. blocks, err := s.state.AllBlocksForSystem() if err != nil { logger.Debugf("Unable to get blocks for system: %s", err) if !args.IgnoreBlocks { return errors.Trace(err) } } if len(blocks) > 0 { if !args.IgnoreBlocks { return common.OperationBlockedError("found blocks in system environments") } err := s.state.RemoveAllBlocksForSystem() if err != nil { return errors.Trace(err) } } systemEnv, err := s.state.StateServerEnvironment() if err != nil { return errors.Trace(err) } systemTag := systemEnv.EnvironTag() if args.DestroyEnvironments { for _, env := range allEnvs { environTag := env.EnvironTag() if environTag != systemTag { if err := common.DestroyEnvironment(s.state, environTag); err != nil { logger.Errorf("unable to destroy environment %q: %s", env.UUID(), err) } } } } return errors.Trace(common.DestroyEnvironment(s.state, systemTag)) }
func (s *SetSuite) TestBlockSetConfig(c *gc.C) { // Block operation s.fakeServiceAPI.err = common.OperationBlockedError("TestBlockSetConfig") ctx := coretesting.ContextForDir(c, s.dir) code := cmd.Main(service.NewSetCommandWithAPI(s.fakeClientAPI, s.fakeServiceAPI), ctx, []string{ "dummy-service", "--config", "testconfig.yaml"}) c.Check(code, gc.Equals, 1) // msg is logged stripped := strings.Replace(c.GetTestLog(), "\n", "", -1) c.Check(stripped, gc.Matches, ".*TestBlockSetConfig.*") }
func (s *ControllerAPI) ensureNotBlocked(args params.DestroyControllerArgs) error { // If there are blocks let the user know. blocks, err := s.state.AllBlocksForController() if err != nil { logger.Debugf("Unable to get blocks for controller: %s", err) return errors.Trace(err) } if len(blocks) > 0 { return common.OperationBlockedError("found blocks in controller models") } return nil }
func (s *configCommandSuite) TestBlockSetConfig(c *gc.C) { // Block operation s.fake.err = common.OperationBlockedError("TestBlockSetConfig") ctx := coretesting.ContextForDir(c, s.dir) code := cmd.Main(application.NewConfigCommandForTest(s.fake), ctx, []string{ "dummy-application", "--file", "testconfig.yaml"}) c.Check(code, gc.Equals, 1) // msg is logged stripped := strings.Replace(c.GetTestLog(), "\n", "", -1) c.Check(stripped, gc.Matches, ".*TestBlockSetConfig.*") }
func (s *UpgradeJujuSuite) TestBlockUpgradeInProgress(c *gc.C) { fakeAPI := NewFakeUpgradeJujuAPI(c, s.State) fakeAPI.setVersionErr = common.OperationBlockedError("the operation has been blocked") fakeAPI.patch(s) cmd := &upgradeJujuCommand{} err := coretesting.InitCommand(modelcmd.Wrap(cmd), []string{}) c.Assert(err, jc.ErrorIsNil) // Block operation s.BlockAllChanges(c, "TestBlockUpgradeInProgress") err = modelcmd.Wrap(cmd).Run(coretesting.Context(c)) s.AssertBlocked(c, err, ".*To enable changes.*") }
func (s *UnsetSuite) TestBlockUnset(c *gc.C) { // Block operation s.fake.err = common.OperationBlockedError("TestBlockUnset") ctx := coretesting.ContextForDir(c, s.dir) code := cmd.Main(service.NewUnsetCommand(s.fake), ctx, []string{ "dummy-service", "username"}) c.Check(code, gc.Equals, 1) // msg is logged stripped := strings.Replace(c.GetTestLog(), "\n", "", -1) c.Check(stripped, gc.Matches, ".*TestBlockUnset.*") }
func (s *retryProvisioningSuite) TestBlockRetryProvisioning(c *gc.C) { s.fake.err = common.OperationBlockedError("TestBlockRetryProvisioning") command := model.NewRetryProvisioningCommandForTest(s.fake) for i, t := range resolvedMachineTests { c.Logf("test %d: %v", i, t.args) _, err := testing.RunCommand(c, command, t.args...) if t.err != "" { c.Check(err, gc.ErrorMatches, t.err) continue } testing.AssertOperationWasBlocked(c, err, ".*TestBlockRetryProvisioning.*") } }
func (s *retryProvisioningSuite) TestBlockRetryProvisioning(c *gc.C) { s.fake.err = common.OperationBlockedError("TestBlockRetryProvisioning") command := environment.NewRetryProvisioningCommand(s.fake) for i, t := range resolvedMachineTests { c.Logf("test %d: %v", i, t.args) _, err := testing.RunCommand(c, command, t.args...) if t.err != "" { c.Check(err, gc.ErrorMatches, t.err) continue } c.Assert(err, gc.ErrorMatches, cmd.ErrSilent.Error()) // msg is logged stripped := strings.Replace(c.GetTestLog(), "\n", "", -1) c.Check(stripped, gc.Matches, ".*TestBlockRetryProvisioning.*") } }
func (m *mockRunAPI) Run(runParams params.RunParams) ([]params.RunResult, error) { var result []params.RunResult if m.block { return result, common.OperationBlockedError("the operation has been blocked") } // Just add in ids that match in order. for _, id := range runParams.Machines { response, found := m.responses[id] if found { result = append(result, response) } } // mock ignores services for _, id := range runParams.Units { response, found := m.responses[id] if found { result = append(result, response) } } return result, nil }
func (m *mockRunAPI) RunOnAllMachines(commands string, timeout time.Duration) ([]params.RunResult, error) { var result []params.RunResult if m.block { return result, common.OperationBlockedError("the operation has been blocked") } sortedMachineIds := make([]string, 0, len(m.machines)) for machineId := range m.machines { sortedMachineIds = append(sortedMachineIds, machineId) } sort.Strings(sortedMachineIds) for _, machineId := range sortedMachineIds { response, found := m.responses[machineId] if !found { // Consider this a timeout response = params.RunResult{MachineId: machineId, Error: "command timed out"} } result = append(result, response) } return result, nil }
func (s *ConstraintsCommandsSuite) TestBlockSetEnviron(c *gc.C) { // Block operation s.fake.err = common.OperationBlockedError("TestBlockSetEnviron") // Set constraints. s.assertSetBlocked(c, "mem=4G", "cpu-power=250") }
func (s *DefaultsCommandSuite) TestBlockedErrorOnSet(c *gc.C) { s.fakeDefaultsAPI.err = common.OperationBlockedError("TestBlockedError") _, err := s.run(c, "special=extra") testing.AssertOperationWasBlocked(c, err, ".*TestBlockedError.*") }
func (s *DefaultsCommandSuite) TestResetBlockedError(c *gc.C) { s.fakeDefaultsAPI.err = common.OperationBlockedError("TestBlockedError") _, err := s.run(c, "--reset", "attr") testing.AssertOperationWasBlocked(c, err, ".*TestBlockedError.*") }
func (s *BlockCommandSuite) TestProcessErrOperationBlocked(c *gc.C) { s.processErrorTest(c, common.OperationBlockedError("operations that remove"), block.BlockRemove, cmd.ErrSilent, ".*operations that remove.*") s.processErrorTest(c, common.OperationBlockedError("destroy-environment operation has been blocked"), block.BlockDestroy, cmd.ErrSilent, ".*destroy-environment operation has been blocked.*") }
err: common.ErrTryAgain, code: params.CodeTryAgain, status: http.StatusInternalServerError, helperFunc: params.IsCodeTryAgain, }, { err: leadership.ErrClaimDenied, code: params.CodeLeadershipClaimDenied, status: http.StatusInternalServerError, helperFunc: params.IsCodeLeadershipClaimDenied, }, { err: lease.ErrClaimDenied, code: params.CodeLeaseClaimDenied, status: http.StatusInternalServerError, helperFunc: params.IsCodeLeaseClaimDenied, }, { err: common.OperationBlockedError("test"), code: params.CodeOperationBlocked, status: http.StatusBadRequest, helperFunc: params.IsCodeOperationBlocked, }, { err: errors.NotSupportedf("needed feature"), code: params.CodeNotSupported, status: http.StatusInternalServerError, helperFunc: params.IsCodeNotSupported, }, { err: errors.BadRequestf("something"), code: params.CodeBadRequest, status: http.StatusBadRequest, helperFunc: params.IsBadRequest, }, { err: errors.MethodNotAllowedf("something"),
func (s *grantRevokeSuite) TestBlockGrant(c *gc.C) { s.fake.err = common.OperationBlockedError("TestBlockGrant") _, err := s.run(c, "sam", "read", "foo") testing.AssertOperationWasBlocked(c, err, ".*TestBlockGrant.*") }
func (s *EnableHASuite) TestBlockEnableHA(c *gc.C) { s.fake.err = common.OperationBlockedError("TestBlockEnableHA") _, err := s.runEnableHA(c, "-n", "1") coretesting.AssertOperationWasBlocked(c, err, ".*TestBlockEnableHA.*") }
func (s *ConfigCommandSuite) TestResetBlockedError(c *gc.C) { s.fake.err = common.OperationBlockedError("TestBlockedError") _, err := s.run(c, "--reset", "special") testing.AssertOperationWasBlocked(c, err, ".*TestBlockedError.*") }