private/testplanet: add some more error wrapping

Change-Id: I4cbdaafc0f6827e569d9b70acac3ce448359f125
This commit is contained in:
Egon Elbre 2023-01-31 15:44:59 +02:00
parent 3a714cefcf
commit 9bb9275acf
5 changed files with 73 additions and 75 deletions

View File

@ -11,6 +11,7 @@ import (
"runtime/pprof"
"strconv"
"github.com/zeebo/errs"
"go.uber.org/zap"
"storj.io/common/storj"
@ -65,7 +66,7 @@ func (planet *Planet) newMultinodes(ctx context.Context, prefix string, count in
system, err = planet.newMultinode(ctx, name, index, log)
})
if err != nil {
return nil, err
return nil, errs.Wrap(err)
}
log.Debug("id=" + system.ID().String() + " addr=" + system.Addr())
@ -80,12 +81,12 @@ func (planet *Planet) newMultinode(ctx context.Context, prefix string, index int
storageDir := filepath.Join(planet.directory, prefix)
if err := os.MkdirAll(storageDir, 0700); err != nil {
return nil, err
return nil, errs.Wrap(err)
}
identity, err := planet.NewIdentity()
if err != nil {
return nil, err
return nil, errs.Wrap(err)
}
config := multinode.Config{
@ -106,24 +107,24 @@ func (planet *Planet) newMultinode(ctx context.Context, prefix string, index int
var db multinode.DB
db, err = multinodedb.Open(ctx, log.Named("db"), database)
if err != nil {
return nil, err
return nil, errs.Wrap(err)
}
if planet.config.Reconfigure.MultinodeDB != nil {
db, err = planet.config.Reconfigure.MultinodeDB(index, db, planet.log)
if err != nil {
return nil, err
return nil, errs.Wrap(err)
}
}
peer, err := multinode.New(log, identity, config, db)
if err != nil {
return nil, err
return nil, errs.Wrap(err)
}
err = db.MigrateToLatest(ctx)
if err != nil {
return nil, err
return nil, errs.Wrap(err)
}
planet.databases = append(planet.databases, db)

View File

@ -159,12 +159,12 @@ func NewCustom(ctx *testcontext.Context, log *zap.Logger, config Config, satelli
var err error
planet.directory, err = os.MkdirTemp("", "planet")
if err != nil {
return nil, err
return nil, errs.Wrap(err)
}
whitelistPath, err := planet.WriteWhitelist(*config.IdentityVersion)
if err != nil {
return nil, err
return nil, errs.Wrap(err)
}
planet.whitelistPath = whitelistPath

View File

@ -237,32 +237,32 @@ func (system *Satellite) AddUser(ctx context.Context, newUser console.CreateUser
regToken, err := system.API.Console.Service.CreateRegToken(ctx, maxNumberOfProjects)
if err != nil {
return nil, err
return nil, errs.Wrap(err)
}
newUser.Password = newUser.FullName
user, err := system.API.Console.Service.CreateUser(ctx, newUser, regToken.Secret)
if err != nil {
return nil, err
return nil, errs.Wrap(err)
}
activationToken, err := system.API.Console.Service.GenerateActivationToken(ctx, user.ID, user.Email)
if err != nil {
return nil, err
return nil, errs.Wrap(err)
}
_, err = system.API.Console.Service.ActivateAccount(ctx, activationToken)
if err != nil {
return nil, err
return nil, errs.Wrap(err)
}
userCtx, err := system.UserContext(ctx, user.ID)
if err != nil {
return nil, err
return nil, errs.Wrap(err)
}
_, err = system.API.Console.Service.Payments().SetupAccount(userCtx)
if err != nil {
return nil, err
return nil, errs.Wrap(err)
}
return user, nil
@ -274,13 +274,13 @@ func (system *Satellite) AddProject(ctx context.Context, ownerID uuid.UUID, name
ctx, err = system.UserContext(ctx, ownerID)
if err != nil {
return nil, err
return nil, errs.Wrap(err)
}
project, err := system.API.Console.Service.CreateProject(ctx, console.ProjectInfo{
Name: name,
})
if err != nil {
return nil, err
return nil, errs.Wrap(err)
}
return project, nil
}
@ -291,7 +291,7 @@ func (system *Satellite) UserContext(ctx context.Context, userID uuid.UUID) (_ c
user, err := system.API.Console.Service.GetUser(ctx, userID)
if err != nil {
return nil, err
return nil, errs.Wrap(err)
}
return console.WithUser(ctx, user), nil
@ -359,7 +359,7 @@ func (planet *Planet) newSatellites(ctx context.Context, count int, databases sa
system, err = planet.newSatellite(ctx, prefix, index, log, databases)
})
if err != nil {
return nil, err
return nil, errs.Wrap(err)
}
log.Debug("id=" + system.ID().String() + " addr=" + system.Addr())
@ -375,17 +375,17 @@ func (planet *Planet) newSatellite(ctx context.Context, prefix string, index int
storageDir := filepath.Join(planet.directory, prefix)
if err := os.MkdirAll(storageDir, 0700); err != nil {
return nil, err
return nil, errs.Wrap(err)
}
identity, err := planet.NewIdentity()
if err != nil {
return nil, err
return nil, errs.Wrap(err)
}
db, err := satellitedbtest.CreateMasterDB(ctx, log.Named("db"), planet.config.Name, "S", index, databases.MasterDB)
if err != nil {
return nil, err
return nil, errs.Wrap(err)
}
if planet.config.Reconfigure.SatelliteDB != nil {
@ -400,14 +400,14 @@ func (planet *Planet) newSatellite(ctx context.Context, prefix string, index int
redis, err := testredis.Mini(ctx)
if err != nil {
return nil, err
return nil, errs.Wrap(err)
}
encryptionKeys, err := orders.NewEncryptionKeys(orders.EncryptionKey{
ID: orders.EncryptionKeyID{1},
Key: storj.Key{1},
})
if err != nil {
return nil, err
return nil, errs.Wrap(err)
}
var config satellite.Config
@ -492,7 +492,7 @@ func (planet *Planet) newSatellite(ctx context.Context, prefix string, index int
MultipleVersions: config.Metainfo.MultipleVersions,
})
if err != nil {
return nil, err
return nil, errs.Wrap(err)
}
if planet.config.Reconfigure.SatelliteMetabaseDB != nil {
@ -525,52 +525,52 @@ func (planet *Planet) newSatellite(ctx context.Context, prefix string, index int
peer, err := satellite.New(log, identity, db, metabaseDB, revocationDB, liveAccounting, rollupsWriteCache, versionInfo, &config, nil)
if err != nil {
return nil, err
return nil, errs.Wrap(err)
}
err = db.TestingMigrateToLatest(ctx)
if err != nil {
return nil, err
return nil, errs.Wrap(err)
}
err = metabaseDB.TestMigrateToLatest(ctx)
if err != nil {
return nil, err
return nil, errs.Wrap(err)
}
api, err := planet.newAPI(ctx, index, identity, db, metabaseDB, config, versionInfo)
if err != nil {
return nil, err
return nil, errs.Wrap(err)
}
adminPeer, err := planet.newAdmin(ctx, index, identity, db, metabaseDB, config, versionInfo)
if err != nil {
return nil, err
return nil, errs.Wrap(err)
}
repairerPeer, err := planet.newRepairer(ctx, index, identity, db, metabaseDB, config, versionInfo)
if err != nil {
return nil, err
return nil, errs.Wrap(err)
}
auditorPeer, err := planet.newAuditor(ctx, index, identity, db, metabaseDB, config, versionInfo)
if err != nil {
return nil, err
return nil, errs.Wrap(err)
}
gcPeer, err := planet.newGarbageCollection(ctx, index, identity, db, metabaseDB, config, versionInfo)
if err != nil {
return nil, err
return nil, errs.Wrap(err)
}
gcBFPeer, err := planet.newGarbageCollectionBF(ctx, index, identity, db, metabaseDB, config, versionInfo)
if err != nil {
return nil, err
return nil, errs.Wrap(err)
}
rangedLoopPeer, err := planet.newRangedLoop(ctx, index, db, metabaseDB, config)
if err != nil {
return nil, err
return nil, errs.Wrap(err)
}
if config.EmailReminders.Enable {

View File

@ -76,7 +76,7 @@ func (planet *Planet) newStorageNodes(ctx context.Context, count int, whiteliste
for _, u := range whitelistedSatellites {
source, err := trust.NewStaticURLSource(u.String())
if err != nil {
return nil, err
return nil, errs.Wrap(err)
}
sources = append(sources, source)
}
@ -93,7 +93,7 @@ func (planet *Planet) newStorageNodes(ctx context.Context, count int, whiteliste
system, err = planet.newStorageNode(ctx, prefix, index, count, log, sources)
})
if err != nil {
return nil, err
return nil, errs.Wrap(err)
}
log.Debug("id=" + system.ID().String() + " addr=" + system.Addr())
@ -108,12 +108,12 @@ func (planet *Planet) newStorageNode(ctx context.Context, prefix string, index,
storageDir := filepath.Join(planet.directory, prefix)
if err := os.MkdirAll(storageDir, 0700); err != nil {
return nil, err
return nil, errs.Wrap(err)
}
identity, err := planet.NewIdentity()
if err != nil {
return nil, err
return nil, errs.Wrap(err)
}
config := storagenode.Config{
@ -232,17 +232,17 @@ func (planet *Planet) newStorageNode(ctx context.Context, prefix string, index,
var db storagenode.DB
db, err = storagenodedbtest.OpenNew(ctx, log.Named("db"), config.DatabaseConfig())
if err != nil {
return nil, err
return nil, errs.Wrap(err)
}
if err := db.Pieces().CreateVerificationFile(ctx, identity.ID); err != nil {
return nil, err
return nil, errs.Wrap(err)
}
if planet.config.Reconfigure.StorageNodeDB != nil {
db, err = planet.config.Reconfigure.StorageNodeDB(index, db, planet.log)
if err != nil {
return nil, err
return nil, errs.Wrap(err)
}
}
@ -254,7 +254,7 @@ func (planet *Planet) newStorageNode(ctx context.Context, prefix string, index,
peer, err := storagenode.New(log, identity, db, revocationDB, config, verisonInfo, nil)
if err != nil {
return nil, err
return nil, errs.Wrap(err)
}
// Mark the peer's PieceDeleter as in testing mode, so it is easy to wait on the deleter
@ -262,7 +262,7 @@ func (planet *Planet) newStorageNode(ctx context.Context, prefix string, index,
err = db.MigrateToLatest(ctx)
if err != nil {
return nil, err
return nil, errs.Wrap(err)
}
planet.databases = append(planet.databases, db)

View File

@ -88,7 +88,7 @@ func (planet *Planet) newUplinks(ctx context.Context, prefix string, count int)
uplink, err = planet.newUplink(ctx, name)
})
if err != nil {
return nil, err
return nil, errs.Wrap(err)
}
xs = append(xs, uplink)
}
@ -102,14 +102,14 @@ func (planet *Planet) newUplink(ctx context.Context, name string) (_ *Uplink, er
identity, err := planet.NewIdentity()
if err != nil {
return nil, err
return nil, errs.Wrap(err)
}
tlsOptions, err := tlsopts.NewOptions(identity, tlsopts.Config{
PeerIDVersions: strconv.Itoa(int(planet.config.IdentityVersion.Number)),
}, nil)
if err != nil {
return nil, err
return nil, errs.Wrap(err)
}
planetUplink := &Uplink{
@ -133,7 +133,7 @@ func (planet *Planet) newUplink(ctx context.Context, name string) (_ *Uplink, er
Email: fmt.Sprintf("user@%s.test", projectName),
}, 10)
if err != nil {
return nil, err
return nil, errs.Wrap(err)
}
planetUplink.User[satellite.ID()] = UserLogin{
@ -143,16 +143,16 @@ func (planet *Planet) newUplink(ctx context.Context, name string) (_ *Uplink, er
project, err := satellite.AddProject(ctx, user.ID, projectName)
if err != nil {
return nil, err
return nil, errs.Wrap(err)
}
userCtx, err := satellite.UserContext(ctx, user.ID)
if err != nil {
return nil, err
return nil, errs.Wrap(err)
}
_, apiKey, err := consoleAPI.Service.CreateAPIKey(userCtx, project.ID, "root")
if err != nil {
return nil, err
return nil, errs.Wrap(err)
}
planetUplink.APIKey[satellite.ID()] = apiKey
@ -226,27 +226,27 @@ func (client *Uplink) UploadWithExpiration(ctx context.Context, satellite *Satel
project, err := client.GetProject(ctx, satellite)
if err != nil {
return err
return errs.Wrap(err)
}
defer func() { err = errs.Combine(err, project.Close()) }()
_, err = project.EnsureBucket(ctx, bucketName)
if err != nil {
return err
return errs.Wrap(err)
}
upload, err := project.UploadObject(ctx, bucketName, path, &uplink.UploadOptions{
Expires: expiration,
})
if err != nil {
return err
return errs.Wrap(err)
}
_, err = io.Copy(upload, bytes.NewReader(data))
if err != nil {
abortErr := upload.Abort()
err = errs.Combine(err, abortErr)
return err
return errs.Wrap(err)
}
return upload.Commit()
@ -258,13 +258,13 @@ func (client *Uplink) Download(ctx context.Context, satellite *Satellite, bucket
project, err := client.GetProject(ctx, satellite)
if err != nil {
return nil, err
return nil, errs.Wrap(err)
}
defer func() { err = errs.Combine(err, project.Close()) }()
download, err := project.DownloadObject(ctx, bucketName, path, nil)
if err != nil {
return nil, err
return nil, errs.Wrap(err)
}
defer func() { err = errs.Combine(err, download.Close()) }()
@ -281,14 +281,14 @@ func (client *Uplink) DownloadStream(ctx context.Context, satellite *Satellite,
project, err := client.GetProject(ctx, satellite)
if err != nil {
return nil, nil, err
return nil, nil, errs.Wrap(err)
}
cleanup = func() error {
err = errs.Combine(err,
project.Close(),
)
return err
return errs.Wrap(err)
}
downloader, err := project.DownloadObject(ctx, bucketName, path, nil)
@ -301,21 +301,18 @@ func (client *Uplink) DownloadStreamRange(ctx context.Context, satellite *Satell
project, err := client.GetProject(ctx, satellite)
if err != nil {
return nil, nil, err
return nil, nil, errs.Wrap(err)
}
cleanup = func() error {
err = errs.Combine(err,
project.Close(),
)
return err
return errs.Combine(err, project.Close())
}
downloader, err := project.DownloadObject(ctx, bucketName, path, &uplink.DownloadOptions{
Offset: start,
Length: limit,
})
return downloader, cleanup, err
return downloader, cleanup, errs.Wrap(err)
}
// DeleteObject deletes an object at the path in a bucket.
@ -324,15 +321,15 @@ func (client *Uplink) DeleteObject(ctx context.Context, satellite *Satellite, bu
project, err := client.GetProject(ctx, satellite)
if err != nil {
return err
return errs.Wrap(err)
}
defer func() { err = errs.Combine(err, project.Close()) }()
_, err = project.DeleteObject(ctx, bucketName, path)
if err != nil {
return err
return errs.Wrap(err)
}
return err
return errs.Wrap(err)
}
// CopyObject copies an object.
@ -355,13 +352,13 @@ func (client *Uplink) CreateBucket(ctx context.Context, satellite *Satellite, bu
project, err := client.GetProject(ctx, satellite)
if err != nil {
return err
return errs.Wrap(err)
}
defer func() { err = errs.Combine(err, project.Close()) }()
_, err = project.CreateBucket(ctx, bucketName)
if err != nil {
return err
return errs.Wrap(err)
}
return nil
}
@ -372,13 +369,13 @@ func (client *Uplink) DeleteBucket(ctx context.Context, satellite *Satellite, bu
project, err := client.GetProject(ctx, satellite)
if err != nil {
return err
return errs.Wrap(err)
}
defer func() { err = errs.Combine(err, project.Close()) }()
_, err = project.DeleteBucket(ctx, bucketName)
if err != nil {
return err
return errs.Wrap(err)
}
return nil
}
@ -390,7 +387,7 @@ func (client *Uplink) ListBuckets(ctx context.Context, satellite *Satellite) (_
var buckets = []*uplink.Bucket{}
project, err := client.GetProject(ctx, satellite)
if err != nil {
return buckets, err
return buckets, errs.Wrap(err)
}
defer func() { err = errs.Combine(err, project.Close()) }()
@ -408,7 +405,7 @@ func (client *Uplink) ListObjects(ctx context.Context, satellite *Satellite, buc
var objects = []*uplink.Object{}
project, err := client.GetProject(ctx, satellite)
if err != nil {
return objects, err
return objects, errs.Wrap(err)
}
defer func() { err = errs.Combine(err, project.Close()) }()
@ -427,7 +424,7 @@ func (client *Uplink) GetProject(ctx context.Context, satellite *Satellite) (_ *
project, err := client.Config.OpenProject(ctx, access)
if err != nil {
return nil, err
return nil, errs.Wrap(err)
}
return project, nil
}