From 90ece48d7750663d962adc8d12e80f60420ca7fc Mon Sep 17 00:00:00 2001 From: Flavian Missi Date: Tue, 30 May 2023 09:20:55 +0200 Subject: [PATCH] registry/storage/driver: add test call to Stat on "/" Stat(ctx, "/") is called by the registry healthcheck. Also fixes blob name building in the Azure driver so it no longer returns empty blob names. This was causing errors in the healthcheck call to Stat for Azure. Signed-off-by: Flavian Missi --- registry/storage/driver/azure/azure.go | 10 +++++++++- registry/storage/driver/testsuites/testsuites.go | 9 +++++++++ 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/registry/storage/driver/azure/azure.go b/registry/storage/driver/azure/azure.go index 4e6d9a20..028239fd 100644 --- a/registry/storage/driver/azure/azure.go +++ b/registry/storage/driver/azure/azure.go @@ -63,7 +63,8 @@ func New(params *Parameters) (*Driver, error) { d := &driver{ azClient: azClient, client: client, - rootDirectory: params.RootDirectory} + rootDirectory: params.RootDirectory, + } return &Driver{baseEmbed: baseEmbed{Base: base.Base{StorageDriver: d}}}, nil } @@ -420,6 +421,13 @@ func (d *driver) listBlobs(ctx context.Context, virtPath string) ([]string, erro } func (d *driver) blobName(path string) string { + // avoid returning an empty blob name. + // this will happen when rootDirectory is unset, and path == "/", + // which is what we get from the storage driver health check Stat call. + if d.rootDirectory == "" && path == "/" { + return path + } + return strings.TrimLeft(strings.TrimRight(d.rootDirectory, "/")+path, "/") } diff --git a/registry/storage/driver/testsuites/testsuites.go b/registry/storage/driver/testsuites/testsuites.go index 58f6b6d6..27923aa3 100644 --- a/registry/storage/driver/testsuites/testsuites.go +++ b/registry/storage/driver/testsuites/testsuites.go @@ -824,6 +824,15 @@ func (suite *DriverSuite) TestStatCall(c *check.C) { c.Assert(fi.Path(), check.Equals, dirPath) c.Assert(fi.Size(), check.Equals, int64(0)) c.Assert(fi.IsDir(), check.Equals, true) + + // The storage healthcheck performs this exact call to Stat. + // PathNotFoundErrors are not considered health check failures. + _, err = suite.StorageDriver.Stat(suite.ctx, "/") + // Some drivers will return a not found here, while others will not + // return an error at all. If we get an error, ensure it's a not found. + if err != nil { + c.Assert(err, check.FitsTypeOf, storagedriver.PathNotFoundError{}) + } } // TestPutContentMultipleTimes checks that if storage driver can overwrite the content