-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Remove controller soft delete (#1229)
* Remove controller soft delete * PR comments * Test fixes * Further test fixes
- Loading branch information
Showing
13 changed files
with
260 additions
and
118 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,14 +4,11 @@ package db_test | |
|
||
import ( | ||
"context" | ||
"database/sql" | ||
"testing" | ||
"time" | ||
|
||
qt "github.com/frankban/quicktest" | ||
"github.com/google/go-cmp/cmp/cmpopts" | ||
jujuparams "github.com/juju/juju/rpc/params" | ||
"github.com/juju/juju/state" | ||
|
||
"github.com/canonical/jimm/internal/db" | ||
"github.com/canonical/jimm/internal/dbmodel" | ||
|
@@ -72,7 +69,6 @@ func (s *dbSuite) TestGetController(c *qt.C) { | |
controller := dbmodel.Controller{ | ||
Name: "test-controller", | ||
UUID: "00000000-0000-0000-0000-0000-0000000000001", | ||
Models: []dbmodel.Model{}, | ||
CloudName: "test-cloud", | ||
} | ||
err = s.Database.AddController(context.Background(), &controller) | ||
|
@@ -102,105 +98,6 @@ func (s *dbSuite) TestGetController(c *qt.C) { | |
c.Assert(eError.Code, qt.Equals, errors.CodeNotFound) | ||
} | ||
|
||
func (s *dbSuite) TestGetControllerWithModels(c *qt.C) { | ||
err := s.Database.Migrate(context.Background(), true) | ||
c.Assert(err, qt.Equals, nil) | ||
|
||
cloud := dbmodel.Cloud{ | ||
Name: "test-cloud", | ||
Type: "test-provider", | ||
Regions: []dbmodel.CloudRegion{{ | ||
Name: "test-region", | ||
}}, | ||
} | ||
c.Assert(s.Database.DB.Create(&cloud).Error, qt.IsNil) | ||
|
||
controller := dbmodel.Controller{ | ||
Name: "test-controller", | ||
UUID: "00000000-0000-0000-0000-0000-0000000000001", | ||
Models: []dbmodel.Model{}, | ||
CloudName: "test-cloud", | ||
CloudRegion: "test-region", | ||
} | ||
u, err := dbmodel.NewIdentity("[email protected]") | ||
c.Assert(err, qt.IsNil) | ||
c.Assert(s.Database.DB.Create(&u).Error, qt.IsNil) | ||
|
||
cred := dbmodel.CloudCredential{ | ||
Name: "test-cred", | ||
Cloud: cloud, | ||
Owner: *u, | ||
AuthType: "empty", | ||
} | ||
c.Assert(s.Database.DB.Create(&cred).Error, qt.IsNil) | ||
|
||
err = s.Database.AddController(context.Background(), &controller) | ||
c.Assert(err, qt.Equals, nil) | ||
|
||
models := []dbmodel.Model{{ | ||
Name: "test-model-1", | ||
UUID: sql.NullString{ | ||
String: "00000001-0000-0000-0000-0000-000000000001", | ||
Valid: true, | ||
}, | ||
Owner: *u, | ||
Controller: controller, | ||
CloudRegion: cloud.Regions[0], | ||
CloudCredential: cred, | ||
Type: "iaas", | ||
IsController: true, | ||
DefaultSeries: "warty", | ||
Life: state.Alive.String(), | ||
Status: dbmodel.Status{ | ||
Status: "available", | ||
Since: sql.NullTime{ | ||
Time: time.Now(), | ||
Valid: true, | ||
}, | ||
}, | ||
SLA: dbmodel.SLA{ | ||
Level: "unsupported", | ||
}, | ||
}, { | ||
Name: "test-model-2", | ||
UUID: sql.NullString{ | ||
String: "00000001-0000-0000-0000-0000-000000000002", | ||
Valid: true, | ||
}, | ||
Owner: *u, | ||
Controller: controller, | ||
CloudRegion: cloud.Regions[0], | ||
CloudCredential: cred, | ||
Type: "iaas", | ||
IsController: false, | ||
DefaultSeries: "warty", | ||
Life: state.Alive.String(), | ||
Status: dbmodel.Status{ | ||
Status: "available", | ||
Since: sql.NullTime{ | ||
Time: time.Now(), | ||
Valid: true, | ||
}, | ||
}, | ||
SLA: dbmodel.SLA{ | ||
Level: "unsupported", | ||
}, | ||
}} | ||
for _, m := range models { | ||
c.Assert(s.Database.DB.Create(&m).Error, qt.IsNil) | ||
} | ||
|
||
dbController := dbmodel.Controller{ | ||
UUID: controller.UUID, | ||
} | ||
err = s.Database.GetController(context.Background(), &dbController) | ||
c.Assert(err, qt.Equals, nil) | ||
controller.Models = []dbmodel.Model{ | ||
models[0], | ||
} | ||
c.Assert(dbController, qt.CmpEquals(cmpopts.IgnoreFields(dbmodel.Controller{}, "Models"), cmpopts.EquateEmpty()), controller) | ||
} | ||
|
||
func TestForEachControllerUnconfiguredDatabase(t *testing.T) { | ||
c := qt.New(t) | ||
|
||
|
@@ -289,7 +186,6 @@ func (s *dbSuite) TestUpdateController(c *qt.C) { | |
UUID: "00000000-0000-0000-0000-0000-0000000000001", | ||
CloudName: "test-cloud", | ||
CloudRegion: "test-region", | ||
Models: []dbmodel.Model{}, | ||
} | ||
err = s.Database.AddController(context.Background(), &controller) | ||
c.Assert(err, qt.Equals, nil) | ||
|
@@ -336,7 +232,6 @@ func (s *dbSuite) TestDeleteController(c *qt.C) { | |
Name: "test-controller", | ||
UUID: "00000000-0000-0000-0000-0000-0000000000001", | ||
CloudName: "test-cloud", | ||
Models: []dbmodel.Model{}, | ||
} | ||
err = s.Database.AddController(context.Background(), &controller) | ||
c.Assert(err, qt.Equals, nil) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,6 +7,7 @@ import ( | |
"database/sql" | ||
"sort" | ||
"testing" | ||
"time" | ||
|
||
qt "github.com/frankban/quicktest" | ||
"github.com/juju/juju/state" | ||
|
@@ -57,7 +58,6 @@ func (s *dbSuite) TestAddModel(c *qt.C) { | |
UUID: "00000000-0000-0000-0000-0000-0000000000001", | ||
CloudName: "test-cloud", | ||
CloudRegion: "test-region", | ||
Models: []dbmodel.Model{}, | ||
} | ||
err = s.Database.AddController(context.Background(), &controller) | ||
c.Assert(err, qt.Equals, nil) | ||
|
@@ -127,7 +127,6 @@ func (s *dbSuite) TestGetModel(c *qt.C) { | |
controller := dbmodel.Controller{ | ||
Name: "test-controller", | ||
UUID: "00000000-0000-0000-0000-0000-0000000000001", | ||
Models: []dbmodel.Model{}, | ||
CloudName: "test-cloud", | ||
CloudRegion: "test-region", | ||
} | ||
|
@@ -231,7 +230,6 @@ func (s *dbSuite) TestUpdateModel(c *qt.C) { | |
UUID: "00000000-0000-0000-0000-0000-0000000000001", | ||
CloudName: "test-cloud", | ||
CloudRegion: "test-region", | ||
Models: []dbmodel.Model{}, | ||
} | ||
err = s.Database.AddController(context.Background(), &controller) | ||
c.Assert(err, qt.Equals, nil) | ||
|
@@ -308,7 +306,6 @@ func (s *dbSuite) TestDeleteModel(c *qt.C) { | |
UUID: "00000000-0000-0000-0000-0000-0000000000001", | ||
CloudName: "test-cloud", | ||
CloudRegion: "test-region", | ||
Models: []dbmodel.Model{}, | ||
} | ||
err = s.Database.AddController(context.Background(), &controller) | ||
c.Assert(err, qt.Equals, nil) | ||
|
@@ -641,3 +638,102 @@ func (s *dbSuite) TestGetModelsByUUID(c *qt.C) { | |
c.Check(models[2].UUID.String, qt.Equals, "00000002-0000-0000-0000-000000000003") | ||
c.Check(models[2].Controller.Name, qt.Not(qt.Equals), "") | ||
} | ||
|
||
func (s *dbSuite) TestGetModelsByController(c *qt.C) { | ||
err := s.Database.Migrate(context.Background(), true) | ||
c.Assert(err, qt.Equals, nil) | ||
|
||
cloud := dbmodel.Cloud{ | ||
Name: "test-cloud", | ||
Type: "test-provider", | ||
Regions: []dbmodel.CloudRegion{{ | ||
Name: "test-region", | ||
}}, | ||
} | ||
c.Assert(s.Database.DB.Create(&cloud).Error, qt.IsNil) | ||
|
||
controller := dbmodel.Controller{ | ||
Name: "test-controller", | ||
UUID: "00000000-0000-0000-0000-0000-0000000000001", | ||
CloudName: "test-cloud", | ||
CloudRegion: "test-region", | ||
} | ||
u, err := dbmodel.NewIdentity("[email protected]") | ||
c.Assert(err, qt.IsNil) | ||
c.Assert(s.Database.DB.Create(&u).Error, qt.IsNil) | ||
|
||
cred := dbmodel.CloudCredential{ | ||
Name: "test-cred", | ||
Cloud: cloud, | ||
Owner: *u, | ||
AuthType: "empty", | ||
} | ||
c.Assert(s.Database.DB.Create(&cred).Error, qt.IsNil) | ||
|
||
err = s.Database.AddController(context.Background(), &controller) | ||
c.Assert(err, qt.Equals, nil) | ||
|
||
models := []dbmodel.Model{{ | ||
Name: "test-model-1", | ||
UUID: sql.NullString{ | ||
String: "00000001-0000-0000-0000-0000-000000000001", | ||
Valid: true, | ||
}, | ||
Owner: *u, | ||
Controller: controller, | ||
CloudRegion: cloud.Regions[0], | ||
CloudCredential: cred, | ||
Type: "iaas", | ||
IsController: true, | ||
DefaultSeries: "focal", | ||
Life: state.Alive.String(), | ||
Status: dbmodel.Status{ | ||
Status: "available", | ||
Since: sql.NullTime{ | ||
Time: time.Now(), | ||
Valid: true, | ||
}, | ||
}, | ||
SLA: dbmodel.SLA{ | ||
Level: "unsupported", | ||
}, | ||
}, { | ||
Name: "test-model-2", | ||
UUID: sql.NullString{ | ||
String: "00000001-0000-0000-0000-0000-000000000002", | ||
Valid: true, | ||
}, | ||
Owner: *u, | ||
Controller: controller, | ||
CloudRegion: cloud.Regions[0], | ||
CloudCredential: cred, | ||
Type: "iaas", | ||
IsController: false, | ||
DefaultSeries: "focal", | ||
Life: state.Alive.String(), | ||
Status: dbmodel.Status{ | ||
Status: "available", | ||
Since: sql.NullTime{ | ||
Time: time.Now(), | ||
Valid: true, | ||
}, | ||
}, | ||
SLA: dbmodel.SLA{ | ||
Level: "unsupported", | ||
}, | ||
}} | ||
for _, m := range models { | ||
c.Assert(s.Database.DB.Create(&m).Error, qt.IsNil) | ||
} | ||
foundModels, err := s.Database.GetModelsByController(context.Background(), controller) | ||
foundModelNames := []string{} | ||
for _, m := range foundModels { | ||
foundModelNames = append(foundModelNames, m.Name) | ||
} | ||
modelNames := []string{} | ||
for _, m := range models { | ||
modelNames = append(modelNames, m.Name) | ||
} | ||
c.Assert(err, qt.IsNil) | ||
c.Assert(foundModelNames, qt.DeepEquals, modelNames) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
-- 1_9.sql is a migration that deletes soft-deleted controllers and | ||
-- drops the deleted_at column from the controllers table. | ||
DELETE FROM controllers WHERE deleted_at IS NOT null; | ||
ALTER TABLE controllers DROP COLUMN deleted_at; | ||
|
||
UPDATE versions SET major=1, minor=9 WHERE component='jimmdb'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.