func (s *SetSuite) TestBlockedError(c *gc.C) { s.fake.err = common.ErrOperationBlocked("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 *ConstraintsCommandsSuite) TestBlockSetService(c *gc.C) { s.fake.addTestingService("svc") // Block operation s.fake.err = common.ErrOperationBlocked("TestBlockSetService") // Set constraints. s.assertSetBlocked(c, "-s", "svc", "mem=4G", "cpu-power=250") }
func (s *AddMachineSuite) TestBlockedError(c *gc.C) { s.fakeAddMachine.addError = common.ErrOperationBlocked("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 *RemoveMachineSuite) TestBlockedError(c *gc.C) { s.fake.removeError = common.ErrOperationBlocked("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 *EnsureAvailabilitySuite) TestBlockEnsureAvailability(c *gc.C) { s.fake.err = common.ErrOperationBlocked("TestBlockEnsureAvailability") _, err := s.runEnsureAvailability(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, ".*TestBlockEnsureAvailability.*") }
func (s *AddUnitSuite) TestBlockAddUnit(c *gc.C) { // Block operation s.fake.err = common.ErrOperationBlocked("TestBlockAddUnit") s.runAddUnit(c, "some-service-name") // msg is logged stripped := strings.Replace(c.GetTestLog(), "\n", "", -1) c.Check(stripped, gc.Matches, ".*TestBlockAddUnit.*") }
// 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.ErrOperationBlocked("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 *UnsetSuite) TestBlockUnset(c *gc.C) { // Block operation s.fake.err = common.ErrOperationBlocked("TestBlockUnset") ctx := coretesting.ContextForDir(c, s.dir) code := cmd.Main(envcmd.Wrap(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 *UpgradeJujuSuite) TestBlockUpgradeInProgress(c *gc.C) { fakeAPI := NewFakeUpgradeJujuAPI(c, s.State) fakeAPI.setVersionErr = common.ErrOperationBlocked("The operation has been blocked.") fakeAPI.patch(s) cmd := &UpgradeJujuCommand{} err := coretesting.InitCommand(envcmd.Wrap(cmd), []string{}) c.Assert(err, jc.ErrorIsNil) // Block operation s.BlockAllChanges(c, "TestBlockUpgradeInProgress") err = cmd.Run(coretesting.Context(c)) s.AssertBlocked(c, err, ".*To unblock changes.*") }
func (m *mockAddUserAPI) AddUser(username, displayname, password string) (names.UserTag, error) { if m.blocked { return names.UserTag{}, common.ErrOperationBlocked("The operation has been blocked.") } m.username = username m.displayname = displayname m.password = password if m.failMessage == "" { return names.NewLocalUserTag(username), nil } return names.UserTag{}, errors.New(m.failMessage) }
func (s *retryProvisioningSuite) TestBlockRetryProvisioning(c *gc.C) { s.fake.err = common.ErrOperationBlocked("TestBlockRetryProvisioning") command := environment.NewRetryProvisioningCommand(s.fake) for i, t := range resolvedMachineTests { c.Logf("test %d: %v", i, t.args) _, err := testing.RunCommand(c, envcmd.Wrap(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.ErrOperationBlocked("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.ErrOperationBlocked("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 *BlockCommandSuite) TestProcessErrOperationBlocked(c *gc.C) { s.processErrorTest(c, common.ErrOperationBlocked("operations that remove"), block.BlockRemove, cmd.ErrSilent, ".*operations that remove.*") s.processErrorTest(c, common.ErrOperationBlocked("destroy-environment operation has been blocked"), block.BlockDestroy, cmd.ErrSilent, ".*destroy-environment operation has been blocked.*") }
code: params.CodeHasAssignedUnits, helperFunc: params.IsCodeHasAssignedUnits, }, { err: common.ErrTryAgain, code: params.CodeTryAgain, helperFunc: params.IsCodeTryAgain, }, { err: state.UpgradeInProgressError, code: params.CodeUpgradeInProgress, helperFunc: params.IsCodeUpgradeInProgress, }, { err: leadership.ErrClaimDenied, code: params.CodeLeadershipClaimDenied, helperFunc: params.IsCodeLeadershipClaimDenied, }, { err: common.ErrOperationBlocked("test"), code: params.CodeOperationBlocked, helperFunc: params.IsCodeOperationBlocked, }, { err: errors.NotSupportedf("needed feature"), code: params.CodeNotSupported, helperFunc: params.IsCodeNotSupported, }, { err: stderrors.New("an error"), code: "", }, { err: unhashableError{"foo"}, code: "", }, { err: common.UnknownEnvironmentError("dead-beef-123456"), code: params.CodeNotFound,
func (s *ConstraintsCommandsSuite) TestBlockSetEnviron(c *gc.C) { // Block operation s.fake.err = common.ErrOperationBlocked("TestBlockSetEnviron") // Set constraints. s.assertSetBlocked(c, "mem=4G", "cpu-power=250") }