diff --git a/registry/storage/driver/azure/azure.go b/registry/storage/driver/azure/azure.go index 4e6d9a20..88aea274 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,11 +421,24 @@ 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, "/") } func is404(err error) bool { - return bloberror.HasCode(err, bloberror.BlobNotFound, bloberror.ContainerNotFound, bloberror.ResourceNotFound) + return bloberror.HasCode( + err, + bloberror.BlobNotFound, + bloberror.ContainerNotFound, + bloberror.ResourceNotFound, + bloberror.CannotVerifyCopySource, + ) } type writer struct { diff --git a/registry/storage/driver/azure/azure_test.go b/registry/storage/driver/azure/azure_test.go index 5b0b9533..42a8a9b4 100644 --- a/registry/storage/driver/azure/azure_test.go +++ b/registry/storage/driver/azure/azure_test.go @@ -52,14 +52,18 @@ func init() { } azureDriverConstructor := func() (storagedriver.StorageDriver, error) { - params := Parameters{ - Container: container, - AccountName: accountName, - AccountKey: accountKey, - Realm: realm, - RootDirectory: rootDirectory, + parameters := map[string]interface{}{ + "container": container, + "accountname": accountName, + "accountkey": accountKey, + "realm": realm, + "rootdirectory": rootDirectory, } - return New(¶ms) + params, err := NewParameters(parameters) + if err != nil { + return nil, err + } + return New(params) } // Skip Azure storage driver tests if environment variable parameters are not provided diff --git a/registry/storage/driver/testsuites/testsuites.go b/registry/storage/driver/testsuites/testsuites.go index 58f6b6d6..9847bb38 100644 --- a/registry/storage/driver/testsuites/testsuites.go +++ b/registry/storage/driver/testsuites/testsuites.go @@ -388,7 +388,11 @@ func (suite *DriverSuite) TestReaderWithOffset(c *check.C) { // TestContinueStreamAppendLarge tests that a stream write can be appended to without // corrupting the data with a large chunk size. func (suite *DriverSuite) TestContinueStreamAppendLarge(c *check.C) { - suite.testContinueStreamAppend(c, int64(10*1024*1024)) + chunkSize := int64(10 * 1024 * 1024) + if suite.Name() == "azure" { + chunkSize = int64(4 * 1024 * 1024) + } + suite.testContinueStreamAppend(c, chunkSize) } // TestContinueStreamAppendSmall is the same as TestContinueStreamAppendLarge, but only @@ -824,6 +828,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