-
Notifications
You must be signed in to change notification settings - Fork 495
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Allow
CLUSTER:
locations to be used for cloud sync tasks
- Loading branch information
1 parent
7e66d2e
commit f6198f7
Showing
13 changed files
with
207 additions
and
141 deletions.
There are no files selected for viewing
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
import pytest | ||
|
||
from middlewared.client import ClientException | ||
from middlewared.test.integration.assets.cloudsync import * | ||
|
||
from config import CLUSTER_INFO, CLUSTER_IPS | ||
from utils import make_request, ssh_test, wait_on_job | ||
|
||
LOCAL_PATH = f'/cluster/{CLUSTER_INFO["GLUSTER_VOLUME"]}/cloudsync_01' | ||
CLUSTER_PATH = f'CLUSTER:{CLUSTER_INFO["GLUSTER_VOLUME"]}/cloudsync_01' | ||
|
||
|
||
def test_works(): | ||
res = ssh_test(CLUSTER_IPS[0], f'mkdir {LOCAL_PATH}') | ||
assert res['result'], res['stderr'] | ||
try: | ||
res = ssh_test(CLUSTER_IPS[0], f'echo test > {LOCAL_PATH}/file01') | ||
assert res['result'], res['stderr'] | ||
|
||
try: | ||
with local_s3_task({ | ||
"path": CLUSTER_PATH, | ||
}) as task: | ||
run_task(task) | ||
|
||
res = ssh_test(CLUSTER_IPS[0], f'cat {LOCAL_PATH}/file01') | ||
assert res['result'], res['stderr'] | ||
|
||
assert res['output'] == 'test\n' | ||
finally: | ||
res = ssh_test(CLUSTER_IPS[0], f'rm -rf {LOCAL_PATH}') | ||
assert res['result'], res['stderr'] | ||
finally: | ||
res = ssh_test(CLUSTER_IPS[0], f'rm -rf {LOCAL_PATH}') | ||
assert res['result'], res['stderr'] | ||
|
||
|
||
def test_invalid_cluster_path(): | ||
with pytest.raises(ClientException) as e: | ||
with local_s3_task({ | ||
"path": CLUSTER_PATH, | ||
}) as task: | ||
run_task(task) | ||
|
||
assert str(e.value) == f"[EFAULT] Directory '{CLUSTER_PATH}' does not exist" | ||
|
||
|
||
def test_cluster_path_snapshot(): | ||
with pytest.raises(ClientException) as e: | ||
with local_s3_task({ | ||
"path": CLUSTER_PATH, | ||
"snapshot": True | ||
}) as task: | ||
pass | ||
|
||
assert str(e.value) == f"[EINVAL] cloud_sync_create.snapshot: This option can not be used for cluster paths" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
90 changes: 90 additions & 0 deletions
90
src/middlewared/middlewared/test/integration/assets/cloudsync.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
# -*- coding=utf-8 -*- | ||
import contextlib | ||
import logging | ||
|
||
from middlewared.test.integration.assets.pool import dataset | ||
from middlewared.test.integration.assets.s3 import s3_server | ||
from middlewared.test.integration.utils import call | ||
|
||
logger = logging.getLogger(__name__) | ||
|
||
__all__ = ["credential", "task", "local_s3_credential", "local_s3_task", "run_task"] | ||
|
||
|
||
@contextlib.contextmanager | ||
def credential(data): | ||
data = { | ||
"name": "Test", | ||
**data, | ||
} | ||
|
||
credential = call("cloudsync.credentials.create", data) | ||
try: | ||
yield credential | ||
finally: | ||
call("cloudsync.credentials.delete", credential["id"]) | ||
|
||
|
||
@contextlib.contextmanager | ||
def task(data): | ||
data = { | ||
"description": "Test", | ||
"schedule": { | ||
"minute": "00", | ||
"hour": "00", | ||
"dom": "1", | ||
"month": "1", | ||
"dow": "1", | ||
}, | ||
**data | ||
} | ||
|
||
task = call("cloudsync.create", data) | ||
try: | ||
yield task | ||
finally: | ||
call("cloudsync.delete", task["id"]) | ||
|
||
|
||
@contextlib.contextmanager | ||
def local_s3_credential(credential_params=None): | ||
credential_params = credential_params or {} | ||
|
||
with dataset("cloudsync_remote") as remote_dataset: | ||
with s3_server(remote_dataset) as s3: | ||
with credential({ | ||
"provider": "S3", | ||
"attributes": { | ||
"access_key_id": s3.access_key, | ||
"secret_access_key": s3.secret_key, | ||
"endpoint": "http://localhost:9000", | ||
"skip_region": True, | ||
**credential_params, | ||
}, | ||
}) as c: | ||
yield c | ||
|
||
|
||
@contextlib.contextmanager | ||
def local_s3_task(params=None, credential_params=None): | ||
params = params or {} | ||
credential_params = credential_params or {} | ||
|
||
with dataset("cloudsync_local") as local_dataset: | ||
with local_s3_credential(credential_params) as c: | ||
with task({ | ||
"direction": "PUSH", | ||
"transfer_mode": "COPY", | ||
"path": f"/mnt/{local_dataset}", | ||
"credentials": c["id"], | ||
"attributes": { | ||
"bucket": "bucket", | ||
"folder": "", | ||
}, | ||
**params, | ||
}) as t: | ||
yield t | ||
|
||
|
||
def run_task(task, timeout=120): | ||
call("cloudsync.sync", task["id"], job=True, timeout=timeout) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.