-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
webhdfs: expose kerberos and https options (#6936)
* Add fsspec options for webhdfs * Add requests-kerberos dependency * Update dvc/fs/webhdfs.py Simplify config.pop. Co-authored-by: Ruslan Kuprieiev <kupruser@gmail.com> * Update dvc/fs/webhdfs.py * Simplify kerb_kwargs config setting. Co-authored-by: Ruslan Kuprieiev <kupruser@gmail.com> Co-authored-by: Ruslan Kuprieiev <kupruser@gmail.com>
- Loading branch information
1 parent
044e790
commit c5b1a73
Showing
4 changed files
with
62 additions
and
23 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,54 @@ | ||
from unittest.mock import Mock, create_autospec | ||
|
||
import pytest | ||
import requests | ||
|
||
from dvc.fs.webhdfs import WebHDFSFileSystem | ||
|
||
host = "host" | ||
kerberos = False | ||
kerberos_principal = "principal" | ||
port = 12345 | ||
proxy_to = "proxy" | ||
ssl_verify = False | ||
token = "token" | ||
use_https = True | ||
user = "test" | ||
webhdfs_token = "token" | ||
webhdfs_alias = "alias-name" | ||
hdfscli_config = "path/to/cli/config" | ||
|
||
|
||
def test_init(dvc): | ||
url = "webhdfs://test@127.0.0.1:50070" | ||
config = { | ||
"host": url, | ||
"webhdfs_token": webhdfs_token, | ||
"webhdfs_alias": webhdfs_alias, | ||
"hdfscli_config": hdfscli_config, | ||
"user": user, | ||
|
||
|
||
@pytest.fixture() | ||
def webhdfs_config(): | ||
url = f"webhdfs://{user}@{host}:{port}" | ||
url_config = WebHDFSFileSystem._get_kwargs_from_urls(url) | ||
return { | ||
"kerberos": kerberos, | ||
"kerberos_principal": kerberos_principal, | ||
"proxy_to": proxy_to, | ||
"ssl_verify": ssl_verify, | ||
"token": token, | ||
"use_https": use_https, | ||
**url_config, | ||
} | ||
|
||
fs = WebHDFSFileSystem(**config) | ||
assert fs.fs_args["token"] == webhdfs_token | ||
|
||
def test_init(dvc, webhdfs_config): | ||
fs = WebHDFSFileSystem(**webhdfs_config) | ||
assert fs.fs_args["host"] == host | ||
assert fs.fs_args["token"] == token | ||
assert fs.fs_args["user"] == user | ||
assert fs.fs_args["port"] == port | ||
assert fs.fs_args["kerberos"] == kerberos | ||
assert fs.fs_args["kerb_kwargs"] == {"principal": kerberos_principal} | ||
assert fs.fs_args["proxy_to"] == proxy_to | ||
assert fs.fs_args["use_https"] == use_https | ||
|
||
|
||
def test_verify_ssl(dvc, webhdfs_config, monkeypatch): | ||
mock_session = create_autospec(requests.Session) | ||
monkeypatch.setattr(requests, "Session", Mock(return_value=mock_session)) | ||
# can't have token at the same time as user or proxy_to | ||
del webhdfs_config["token"] | ||
fs = WebHDFSFileSystem(**webhdfs_config) | ||
# ssl verify can't be set until after the file system is instantiated | ||
fs.fs # pylint: disable=pointless-statement | ||
assert mock_session.verify == ssl_verify |