Skip to content

Commit

Permalink
feat(services/swift): add ceph test setup for swift (#4307)
Browse files Browse the repository at this point in the history
* add ceph test setup

* fix typos

* modify ListOpResponse

* update code format

* fix wrong test and add more context
  • Loading branch information
zjregee authored Mar 3, 2024
1 parent 6925aef commit 3e0a3fd
Show file tree
Hide file tree
Showing 4 changed files with 105 additions and 7 deletions.
49 changes: 49 additions & 0 deletions .github/services/swift/ceph_rados_swift/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
# 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: ceph_rados_swift
description: 'Behavior test for CEPH OBJECT GATEWAY Swift.'

runs:
using: "composite"
steps:
- name: Setup Ceph Rados Server
shell: bash
working-directory: fixtures/swift
run: docker compose -f docker-compose-ceph-rados.yml up -d --wait

- name: Create environment variables and setup test container
shell: bash
working-directory: fixtures/swift
run: |
docker exec ceph-demo radosgw-admin user create \
--subuser="test_user:test_swift_user" --uid="test_user" --display-name="test_user" \
--key-type=swift --secret="password" --access=full
response=$(curl -i -H "X-Auth-User: test_user:test_swift_user" -H "X-Auth-Key: password" http://127.0.0.1:8080/auth/v1)
token=$(echo "$response" | grep X-Auth-Token | head -n1 | awk '{print $2}' | tr -d '[:space:]')
endpoint=$(echo "$response" | grep X-Storage-Url | head -n1 | awk '{print $2}' | tr -d '[:space:]')
curl --location --request PUT "${endpoint}/testing" --header "X-Auth-Token: $token"
echo "OPENDAL_SWIFT_TOKEN=${token}" >> $GITHUB_ENV
echo "OPENDAL_SWIFT_ENDPOINT=${endpoint}" >> $GITHUB_ENV
- name: Set environment variables
shell: bash
run: |
cat << EOF >> $GITHUB_ENV
OPENDAL_SWIFT_CONTAINER=testing
OPENDAL_SWIFT_ROOT=/
EOF
6 changes: 2 additions & 4 deletions core/src/services/swift/core.rs
Original file line number Diff line number Diff line change
Expand Up @@ -229,8 +229,8 @@ pub enum ListOpResponse {
bytes: u64,
hash: String,
name: String,
content_type: String,
last_modified: String,
content_type: Option<String>,
},
}

Expand Down Expand Up @@ -270,10 +270,8 @@ mod tests {
bytes: 147,
hash: "5e6b5b70b0426b1cc1968003e1afa5ad".to_string(),
name: "test.txt".to_string(),
content_type:
"multipart/form-data;boundary=------------------------25004a866ee9c0cb"
.to_string(),
last_modified: "2023-11-01T03:00:23.147480".to_string(),
content_type: Some("text/plain".to_string()),
}
);

Expand Down
13 changes: 10 additions & 3 deletions core/src/services/swift/lister.rs
Original file line number Diff line number Diff line change
Expand Up @@ -95,10 +95,17 @@ impl oio::PageList for SwiftLister {
meta.set_content_length(bytes);
meta.set_content_md5(hash.as_str());

// we'll change "2023-10-28T19:18:11.682610" to "2023-10-28T19:18:11.682610Z"
last_modified.push('Z');
// OpenStack Swift returns time without 'Z' at the end,
// which causes an error in parse_datetime_from_rfc3339.
// we'll change "2023-10-28T19:18:11.682610" to "2023-10-28T19:18:11.682610Z".
if !last_modified.ends_with('Z') {
last_modified.push('Z');
}
meta.set_last_modified(parse_datetime_from_rfc3339(last_modified.as_str())?);
meta.set_content_type(content_type.as_str());

if let Some(content_type) = content_type {
meta.set_content_type(content_type.as_str());
}

oio::Entry::with(name, meta)
}
Expand Down
44 changes: 44 additions & 0 deletions fixtures/swift/docker-compose-ceph-rados.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
# 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.

version: "3.8"

services:
ceph-demo:
image: quay.io/ceph/demo
container_name: ceph-demo
environment:
- MON_IP=127.0.0.1
- CEPH_PUBLIC_NETWORK=0.0.0.0/0
- DEMO_DAEMONS=osd,mds,rgw
- CEPH_DEMO_UID=demo
- CEPH_DEMO_ACCESS_KEY=demo
- CEPH_DEMO_SECRET_KEY=demo
ports:
- "8080:8080"
- "5000:5000"
- "6789:6789"
volumes:
- ceph-vol:/var/lib/ceph/
network_mode: "host"
healthcheck:
test: [ "CMD", "radosgw-admin", "user", "list" ]
interval: 6s
retries: 100

volumes:
ceph-vol:

0 comments on commit 3e0a3fd

Please sign in to comment.