Skip to content

Commit 60fbd00

Browse files
hrefgaudenz
authored andcommitted
Add bucket URLs test
1 parent 8d0a96b commit 60fbd00

2 files changed

Lines changed: 62 additions & 0 deletions

File tree

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ These tests are run regularly against our public infrastructure as well as our i
4545
| | [test_ping](./test_load_balancer.py#L855) | default |
4646
| **Nested Virtualization** | [test_virtualization_support](./test_nested_virtualization.py#L14) | default |
4747
| | [test_run_nested_vm](./test_nested_virtualization.py#L40) | default |
48+
| **Objects** | [test_bucket_urls](./test_objects.py#L23) | default |
4849
| **Private Network** | [test_private_ip_address_on_all_images](./test_private_network.py#L14) | all |
4950
| | [test_private_network_connectivity_on_all_images](./test_private_network.py#L35) | all |
5051
| | [test_multiple_private_network_interfaces](./test_private_network.py#L88) | default |

test_objects.py

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
"""
2+
3+
Objects Storage
4+
===============
5+
6+
Using an S3 compatible API, customers may store data in our Object Storage
7+
service and serve it without the need to manage their own storage system.
8+
9+
"""
10+
11+
import boto3
12+
import requests
13+
import secrets
14+
15+
from urllib.parse import urlparse
16+
17+
18+
def test_bucket_urls(objects_endpoint, access_key, secret_key):
19+
""" We can create a bucket using the official AWS SDK for Python, upload
20+
an object, and make it available publicly. It is then available as follows:
21+
22+
- <bucket>.objects.rma|lpg.cloudscale.ch/<key>
23+
- objects.rma|lpg.cloudscale.ch/<bucket>/<key>
24+
25+
"""
26+
27+
# Establish a connection using the official AWS SDK for Python
28+
s3 = boto3.client(
29+
's3',
30+
endpoint_url=objects_endpoint,
31+
aws_access_key_id=access_key,
32+
aws_secret_access_key=secret_key,
33+
)
34+
35+
# Generate a bucket name that has not been used yet (bucket names are
36+
# global across all our object storage endpoints).
37+
bucket = f"at-{secrets.token_hex(8)}"
38+
39+
# Create the bucket
40+
s3.create_bucket(Bucket=bucket)
41+
42+
# Upload an object
43+
s3.put_object(
44+
Bucket=bucket,
45+
Key='key.txt',
46+
Body=b'test',
47+
ACL='public-read',
48+
)
49+
50+
parts = urlparse(objects_endpoint)
51+
52+
# Read the expected URLs using an anonymous HTTP client
53+
urls = (
54+
f"{objects_endpoint}/{bucket}/key.txt",
55+
f"{parts.scheme}://{bucket}.{parts.netloc}/key.txt",
56+
)
57+
58+
for url in urls:
59+
response = requests.get(url)
60+
assert response.status_code == 200
61+
assert response.text == "test"

0 commit comments

Comments
 (0)