Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ci(services/azfile): add azfile integration test #3409

Merged
merged 7 commits into from
Oct 29, 2023
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
68 changes: 68 additions & 0 deletions .github/workflows/service_test_azfile.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.

name: Service Test Azfile
dqhl76 marked this conversation as resolved.
Show resolved Hide resolved

on:
push:
branches:
- main
pull_request:
branches:
- main
paths:
- "core/src/**"
- "core/tests/**"
- "!core/src/docs/**"
- "!core/src/services/**"
- "core/src/services/azfile/**"
- ".github/workflows/service_test_azfile.yml"

concurrency:
group: ${{ github.workflow }}-${{ github.ref }}-${{ github.event_name }}
cancel-in-progress: true

jobs:
azure_azfile:
runs-on: ubuntu-latest
if: github.event_name == 'push' || !github.event.pull_request.head.repo.fork
steps:
- uses: actions/checkout@v4
- name: Setup Rust toolchain
uses: ./.github/actions/setup
with:
need-nextest: true

- name: Load secret
id: op-load-secret
uses: 1password/load-secrets-action@v1
with:
export-env: true
env:
OP_SERVICE_ACCOUNT_TOKEN: ${{ secrets.OP_SERVICE_ACCOUNT_TOKEN }}
OPENDAL_AZFILE_ACCOUNT_NAME: op://services/azfile/account_name
OPENDAL_AZFILE_ENDPOINT: op://services/azfile/endpoint
OPENDAL_AZFILE_ACCOUNT_KEY: op://services/azfile/account_key
OPENDAL_AZFILE_SHARE_NAME: op://services/azfile/share_name

- name: Test
shell: bash
working-directory: core
run: cargo nextest run behavior
env:
OPENDAL_TEST: azfile
OPENDAL_AZDLS_ROOT: test/
8 changes: 7 additions & 1 deletion core/src/services/azfile/backend.rs
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,7 @@ impl Builder for AzfileBuilder {

let config_loader = AzureStorageConfig {
account_name: Some(account_name),
account_key: self.account_key.clone(),
sas_token: self.sas_token.clone(),
..Default::default()
};
Expand Down Expand Up @@ -289,6 +290,11 @@ impl Accessor for AzfileBackend {
Ok(RpCreateDir::default())
}
_ => {
// we cannot just check status code because 409 Conflict has two meaning:
// 1. If a directory by the same name is being deleted when Create Directory is called, the server returns status code 409 (Conflict)
// 2. If a directory or file with the same name already exists, the operation fails with status code 409 (Conflict).
// but we just need case 2 (already exists)
// ref: https://learn.microsoft.com/en-us/rest/api/storageservices/create-directory
if resp
.headers()
.get("x-ms-error-code")
Expand Down Expand Up @@ -380,7 +386,7 @@ impl Accessor for AzfileBackend {

let status = resp.status();
match status {
StatusCode::ACCEPTED => {
StatusCode::ACCEPTED | StatusCode::NOT_FOUND => {
resp.into_body().consume().await?;
Ok(RpDelete::default())
}
Expand Down
37 changes: 32 additions & 5 deletions core/src/services/azfile/core.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,10 @@ use crate::*;

const X_MS_VERSION: &str = "x-ms-version";
const X_MS_WRITE: &str = "x-ms-write";
const X_MS_RENAME_SOURCE: &str = "x-ms-rename-source";
const X_MS_FILE_RENAME_SOURCE: &str = "x-ms-file-rename-source";
const X_MS_CONTENT_LENGTH: &str = "x-ms-content-length";
const X_MS_TYPE: &str = "x-ms-type";
const X_MS_FILE_RENAME_REPLACE_IF_EXISTS: &str = "x-ms-file-rename-replace-if-exists";

pub struct AzfileCore {
pub root: String,
Expand Down Expand Up @@ -111,7 +112,19 @@ impl AzfileCore {

let mut req = Request::get(&url);

req = req.header(RANGE, range.to_header());
if !range.is_full() {
// azfile doesn't support read with suffix range.
//
// ref: https://learn.microsoft.com/en-us/rest/api/storageservices/specifying-the-range-header-for-file-service-operations
if range.offset().is_none() && range.size().is_some() {
return Err(Error::new(
ErrorKind::Unsupported,
"azblob doesn't support read with suffix range",
));
}

req = req.header(RANGE, range.to_header());
}

let mut req = req
.body(AsyncBody::Empty)
Expand Down Expand Up @@ -262,22 +275,36 @@ impl AzfileCore {
"{}/{}/{}?restype=directory&comp=rename",
self.endpoint,
self.share_name,
percent_encode_path(&p)
percent_encode_path(&new_p)
)
} else {
format!(
"{}/{}/{}?comp=rename",
self.endpoint,
self.share_name,
percent_encode_path(&p)
percent_encode_path(&new_p)
)
};

let mut req = Request::put(&url);

req = req.header(CONTENT_LENGTH, 0);

req = req.header(X_MS_RENAME_SOURCE, percent_encode_path(&new_p));
// x-ms-file-rename-source specifies the file or directory to be renamed.
// the value must be a URL style path
// the official document does not mention the URL style path
// find the solution from the community FAQ and implementation of the Java-SDK
// ref: https://learn.microsoft.com/en-us/answers/questions/799611/azure-file-service-rest-api(rename)?page=1
let source_url = format!(
"{}/{}/{}",
self.endpoint,
self.share_name,
percent_encode_path(&p)
);

req = req.header(X_MS_FILE_RENAME_SOURCE, &source_url);

req = req.header(X_MS_FILE_RENAME_REPLACE_IF_EXISTS, "true");

let mut req = req
.body(AsyncBody::Empty)
Expand Down
2 changes: 2 additions & 0 deletions core/src/types/operator/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,8 @@ impl Operator {
Scheme::Azblob => Self::from_map::<services::Azblob>(map)?.finish(),
#[cfg(feature = "services-azdls")]
Scheme::Azdls => Self::from_map::<services::Azdls>(map)?.finish(),
#[cfg(feature = "services-azfile")]
Scheme::Azfile => Self::from_map::<services::Azfile>(map)?.finish(),
#[cfg(feature = "services-cacache")]
Scheme::Cacache => Self::from_map::<services::Cacache>(map)?.finish(),
#[cfg(feature = "services-cos")]
Expand Down
2 changes: 2 additions & 0 deletions core/src/types/scheme.rs
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,8 @@ impl Scheme {
Scheme::Azblob,
#[cfg(feature = "services-azdls")]
Scheme::Azdls,
#[cfg(feature = "services-azfile")]
Scheme::Azfile,
#[cfg(feature = "services-cacache")]
Scheme::Cacache,
#[cfg(feature = "services-cos")]
Expand Down