Skip to content

Commit

Permalink
Merge pull request juju#18451 from manadart/dqlite-destroy-controller…
Browse files Browse the repository at this point in the history
…-skip-factory

juju#18451

More removal of tests using `MakeCharm` from the testing factory, and recording of coverage required.

See: juju#18441
  • Loading branch information
jujubot authored Dec 2, 2024
2 parents 127cf8d + d6f0caf commit c01a90e
Showing 1 changed file with 8 additions and 106 deletions.
114 changes: 8 additions & 106 deletions apiserver/facades/client/controller/destroy_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ package controller_test

import (
"context"
"time"

"github.com/juju/errors"
"github.com/juju/names/v5"
Expand All @@ -20,11 +19,9 @@ import (
loggertesting "github.com/juju/juju/internal/logger/testing"
"github.com/juju/juju/internal/testing"
"github.com/juju/juju/internal/testing/factory"
"github.com/juju/juju/internal/uuid"
jujutesting "github.com/juju/juju/juju/testing"
"github.com/juju/juju/rpc/params"
"github.com/juju/juju/state"
stateerrors "github.com/juju/juju/state/errors"
)

// NOTE: the testing of the general model destruction code
Expand Down Expand Up @@ -91,6 +88,14 @@ func (s *destroyControllerSuite) SetUpTest(c *gc.C) {
c.Assert(err, jc.ErrorIsNil)
}

func (s *destroyControllerSuite) TestStub(c *gc.C) {
// These will likely be tests for the service layer.
c.Skip(`This suite is missing tests for the following scenarios:
- Successfully destroying a controller (life->dying) whose model has apps with storage when --destroy-storage is included.
- An error when destroying a controller also with storage, but without including --destroy-storage.
`)
}

func (s *destroyControllerSuite) TestDestroyControllerKillErrsOnHostedModelsWithBlocks(c *gc.C) {
s.BlockDestroyModel(c, "TestBlockDestroyModel")
s.BlockRemoveObject(c, "TestBlockRemoveObject")
Expand Down Expand Up @@ -185,109 +190,6 @@ func (s *destroyControllerSuite) TestDestroyControllerNoHostedModelsWithBlockFai
c.Assert(len(numBlocks), gc.Equals, 2)
}

func (s *destroyControllerSuite) TestDestroyControllerDestroyStorageNotSpecified(c *gc.C) {
controllerConfigService := s.ControllerDomainServices(c).ControllerConfig()
controllerConfig, err := controllerConfigService.ControllerConfig(context.Background())
c.Assert(err, jc.ErrorIsNil)

f, release := s.NewFactory(c, s.ControllerModelUUID())
defer release()

// For the test to run properly with part of the model in mongo and
// part in a service domain, a model with the same uuid is required
// in both places for the test to work. Necessary after model config
// was move to the domain services.
modelUUID, err := uuid.UUIDFromString(s.DefaultModelUUID.String())
c.Assert(err, jc.ErrorIsNil)
modelState := f.MakeModel(c, &factory.ModelParams{
UUID: &modelUUID,
Name: "modelconfig",
Owner: s.otherModelOwner,
ConfigAttrs: testing.Attrs{
"controller": false,
},
})
s.AddCleanup(func(c *gc.C) { _ = modelState.Close() })

f2 := factory.NewFactory(modelState, s.StatePool(), controllerConfig)
f2.MakeUnit(c, &factory.UnitParams{
Application: f2.MakeApplication(c, &factory.ApplicationParams{
Charm: f2.MakeCharm(c, &factory.CharmParams{
Name: "storage-block",
}),
Storage: map[string]state.StorageConstraints{
"data": {Pool: "modelscoped"},
},
}),
})

err = s.controller.DestroyController(context.Background(), params.DestroyControllerArgs{
DestroyModels: true,
})
c.Assert(err, jc.ErrorIs, stateerrors.PersistentStorageError)

c.Assert(s.ControllerModel(c).Life(), gc.Equals, state.Alive)
}

func (s *destroyControllerSuite) TestDestroyControllerDestroyStorageSpecified(c *gc.C) {
controllerConfigService := s.ControllerDomainServices(c).ControllerConfig()
controllerConfig, err := controllerConfigService.ControllerConfig(context.Background())
c.Assert(err, jc.ErrorIsNil)

f, release := s.NewFactory(c, s.ControllerModelUUID())
defer release()

// For the test to run properly with part of the model in mongo and
// part in a service domain, a model with the same uuid is required
// in both places for the test to work. Necessary after model config
// was move to the domain services.
modelUUID, err := uuid.UUIDFromString(s.DefaultModelUUID.String())
c.Assert(err, jc.ErrorIsNil)
modelState := f.MakeModel(c, &factory.ModelParams{
UUID: &modelUUID,
Name: "modelconfig",
Owner: s.otherModelOwner,
ConfigAttrs: testing.Attrs{
"controller": false,
},
})
s.AddCleanup(func(c *gc.C) { _ = modelState.Close() })

f2 := factory.NewFactory(modelState, s.StatePool(), controllerConfig)
f2.MakeUnit(c, &factory.UnitParams{
Application: f2.MakeApplication(c, &factory.ApplicationParams{
Charm: f2.MakeCharm(c, &factory.CharmParams{
Name: "storage-block",
}),
Storage: map[string]state.StorageConstraints{
"data": {Pool: "modelscoped"},
},
}),
})

destroyStorage := false
err = s.controller.DestroyController(context.Background(), params.DestroyControllerArgs{
DestroyModels: true,
DestroyStorage: &destroyStorage,
})
c.Assert(err, jc.ErrorIsNil)

c.Assert(s.ControllerModel(c).Life(), gc.Equals, state.Dying)
}

func (s *destroyControllerSuite) TestDestroyControllerForce(c *gc.C) {
force := true
timeout := 1 * time.Hour
err := s.controller.DestroyController(context.Background(), params.DestroyControllerArgs{
DestroyModels: true,
Force: &force,
ModelTimeout: &timeout,
})
c.Assert(err, jc.ErrorIsNil)
c.Assert(s.ControllerModel(c).ForceDestroyed(), jc.IsTrue)
c.Assert(s.ControllerModel(c).DestroyTimeout().Hours(), gc.Equals, 1.0)
}

// BlockAllChanges blocks all operations that could change the model.
func (s *destroyControllerSuite) BlockAllChanges(c *gc.C, msg string) {
err := s.DefaultModelDomainServices(c).BlockCommand().SwitchBlockOn(context.Background(), blockcommand.ChangeBlock, msg)
Expand Down

0 comments on commit c01a90e

Please sign in to comment.