Skip to content

Commit

Permalink
part 1 of 3: force remove app / unit.
Browse files Browse the repository at this point in the history
  • Loading branch information
anastasiamac committed Apr 1, 2019
1 parent 1a837fb commit 9844a63
Show file tree
Hide file tree
Showing 14 changed files with 624 additions and 172 deletions.
1 change: 1 addition & 0 deletions apiserver/common/remove.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ func (r *Remover) removeEntity(tag names.Tag) error {
return err
}
}
// TODO (anastasiamac) this needs to work with force if needed
return remover.Remove()
}

Expand Down
10 changes: 10 additions & 0 deletions apiserver/facades/client/application/application.go
Original file line number Diff line number Diff line change
Expand Up @@ -1370,9 +1370,13 @@ func (api *APIBase) DestroyUnit(args params.DestroyUnitsParams) (params.DestroyU
}
op := unit.DestroyOperation()
op.DestroyStorage = arg.DestroyStorage
op.Force = arg.Force
if err := api.backend.ApplyOperation(op); err != nil {
return nil, errors.Trace(err)
}
// TODO (anastasiamac 2019-03-29) we want to return errors and info when forced..
// maybe always, so that we can report how many errors we are getting/got.
// At the moment, this only returns the intent not the actual result.
return &info, nil
}
results := make([]params.DestroyUnitResult, len(args.Units))
Expand Down Expand Up @@ -1495,9 +1499,13 @@ func (api *APIBase) DestroyApplication(args params.DestroyApplicationsParams) (p
}
op := app.DestroyOperation()
op.DestroyStorage = arg.DestroyStorage
op.Force = arg.Force
if err := api.backend.ApplyOperation(op); err != nil {
return nil, err
}
// TODO (anastasiamac 2019-03-29) we want to return errors and info when forced..
// maybe always, so that we can report how many errors we are getting/got.
// At the moment, this only returns the intent not the actual result.
return &info, nil
}
results := make([]params.DestroyApplicationResult, len(args.Applications))
Expand Down Expand Up @@ -1532,6 +1540,8 @@ func (api *APIBase) DestroyConsumedApplications(args params.DestroyConsumedAppli
results[i].Error = common.ServerError(err)
continue
}
// TODO (anastasiamac 2019-03-29) This may need to be forced too.
// see https://bugs.launchpad.net/juju/+bug/1822050
err = app.Destroy()
if err != nil {
results[i].Error = common.ServerError(err)
Expand Down
25 changes: 22 additions & 3 deletions apiserver/facades/client/application/application_unit_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -466,9 +466,18 @@ func (s *ApplicationSuite) TestDestroyRelationIdRelationNotFound(c *gc.C) {
}

func (s *ApplicationSuite) TestDestroyApplication(c *gc.C) {
s.assertDestroyApplication(c, false)
}

func (s *ApplicationSuite) TestForceDestroyApplication(c *gc.C) {
s.assertDestroyApplication(c, true)
}

func (s *ApplicationSuite) assertDestroyApplication(c *gc.C, force bool) {
results, err := s.api.DestroyApplication(params.DestroyApplicationsParams{
Applications: []params.DestroyApplicationParams{{
ApplicationTag: "application-postgresql",
Force: force,
}},
})
c.Assert(err, jc.ErrorIsNil)
Expand Down Expand Up @@ -498,7 +507,7 @@ func (s *ApplicationSuite) TestDestroyApplication(c *gc.C) {
"UnitStorageAttachments",
"ApplyOperation",
)
s.backend.CheckCall(c, 7, "ApplyOperation", &state.DestroyApplicationOperation{})
s.backend.CheckCall(c, 7, "ApplyOperation", &state.DestroyApplicationOperation{Force: force})
}

func (s *ApplicationSuite) TestDestroyApplicationDestroyStorage(c *gc.C) {
Expand Down Expand Up @@ -582,10 +591,20 @@ func (s *ApplicationSuite) TestDestroyConsumedApplicationNotFound(c *gc.C) {
}

func (s *ApplicationSuite) TestDestroyUnit(c *gc.C) {
s.assertDestroyUnit(c, false)
}

func (s *ApplicationSuite) TestForceDestroyUnit(c *gc.C) {
s.assertDestroyUnit(c, true)
}

func (s *ApplicationSuite) assertDestroyUnit(c *gc.C, force bool) {
results, err := s.api.DestroyUnit(params.DestroyUnitsParams{
Units: []params.DestroyUnitParams{
{UnitTag: "unit-postgresql-0"},
{
UnitTag: "unit-postgresql-0",
Force: force,
}, {
UnitTag: "unit-postgresql-1",
DestroyStorage: true,
},
Expand Down Expand Up @@ -619,7 +638,7 @@ func (s *ApplicationSuite) TestDestroyUnit(c *gc.C) {
"UnitStorageAttachments",
"ApplyOperation",
)
s.backend.CheckCall(c, 6, "ApplyOperation", &state.DestroyUnitOperation{})
s.backend.CheckCall(c, 6, "ApplyOperation", &state.DestroyUnitOperation{Force: force})
s.backend.CheckCall(c, 9, "ApplyOperation", &state.DestroyUnitOperation{
DestroyStorage: true,
})
Expand Down
Loading

0 comments on commit 9844a63

Please sign in to comment.