-
Notifications
You must be signed in to change notification settings - Fork 493
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
NAS-129790 / 24.10 / Fix
cloudsync.credentials.verify
(#13956)
* Fix `cloudsync.credentials.verify` * Fix cloud sync tests * Type hints
- Loading branch information
1 parent
ab3ef1c
commit 249ad0e
Showing
8 changed files
with
132 additions
and
173 deletions.
There are no files selected for viewing
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 was deleted.
Oops, something went wrong.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
from middlewared.test.integration.assets.cloud_sync import local_ftp_credential_data | ||
from middlewared.test.integration.utils import call | ||
|
||
|
||
def test_verify_cloud_credential(): | ||
with local_ftp_credential_data() as data: | ||
assert call("cloudsync.credentials.verify", data)["valid"] | ||
|
||
|
||
def test_verify_cloud_credential_fail(): | ||
with local_ftp_credential_data() as data: | ||
data["attributes"]["user"] = "root" | ||
assert not call("cloudsync.credentials.verify", data)["valid"] |
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,88 @@ | ||
import pytest | ||
|
||
from middlewared.service_exception import CallError | ||
from middlewared.test.integration.assets.cloud_sync import credential as _credential, task as _task | ||
from middlewared.test.integration.assets.pool import dataset | ||
from middlewared.test.integration.utils import call, ssh | ||
|
||
try: | ||
from config import ( | ||
AWS_ACCESS_KEY_ID, | ||
AWS_SECRET_ACCESS_KEY, | ||
AWS_BUCKET | ||
) | ||
except ImportError: | ||
Reason = 'AWS credential are missing in config.py' | ||
pytestmark = pytest.mark.skip(reason=Reason) | ||
|
||
|
||
@pytest.fixture(scope='module') | ||
def credentials(): | ||
with _credential({ | ||
"provider": "S3", | ||
"attributes": { | ||
"access_key_id": AWS_ACCESS_KEY_ID, | ||
"secret_access_key": AWS_SECRET_ACCESS_KEY, | ||
} | ||
}) as c: | ||
yield c | ||
|
||
|
||
@pytest.fixture(scope='module') | ||
def task(credentials): | ||
with dataset("cloudsync_local") as local_dataset: | ||
with _task({ | ||
"direction": "PUSH", | ||
"transfer_mode": "COPY", | ||
"path": f"/mnt/{local_dataset}", | ||
"credentials": credentials["id"], | ||
"attributes": { | ||
"bucket": AWS_BUCKET, | ||
"folder": "", | ||
}, | ||
}) as t: | ||
yield t | ||
|
||
|
||
def test_update_cloud_credentials(credentials): | ||
call("cloudsync.credentials.update", credentials["id"], { | ||
"attributes": { | ||
"access_key_id": "garbage", | ||
"secret_access_key": AWS_SECRET_ACCESS_KEY, | ||
} | ||
}) | ||
|
||
assert call("cloudsync.credentials.get_instance", credentials["id"])["attributes"]["access_key_id"] == "garbage" | ||
|
||
call("cloudsync.credentials.update", credentials["id"], { | ||
"attributes": { | ||
"access_key_id": AWS_ACCESS_KEY_ID, | ||
"secret_access_key": AWS_SECRET_ACCESS_KEY, | ||
}, | ||
}) | ||
|
||
|
||
def test_update_cloud_sync(task): | ||
assert call("cloudsync.update", task["id"], {"direction": "PULL"}) | ||
|
||
|
||
def test_run_cloud_sync(task): | ||
call("cloudsync.sync", task["id"], job=True) | ||
print(ssh(f"ls {task['path']}")) | ||
assert ssh(f"cat {task['path']}/freenas-test.txt") == "freenas-test\n" | ||
|
||
|
||
def test_restore_cloud_sync(task): | ||
restore_task = call("cloudsync.restore", task["id"], { | ||
"transfer_mode": "COPY", | ||
"path": task["path"], | ||
}) | ||
|
||
call("cloudsync.delete", restore_task["id"]) | ||
|
||
|
||
def test_delete_cloud_credentials_error(credentials, task): | ||
with pytest.raises(CallError) as ve: | ||
call("cloudsync.credentials.delete", credentials["id"]) | ||
|
||
assert "This credential is used by cloud sync task" in ve.value.errmsg |