Skip to content

Commit

Permalink
test: testing sshfs with local ssh server (#1013)
Browse files Browse the repository at this point in the history
* run sshfs test when ssh server is enabled

* configure ssh server for tests

* handle sshfs not implement interface

* alert us when sshfs implements cat_file

* Update tests/test_0692_fsspec.py

Co-authored-by: Jim Pivarski <jpivarski@users.noreply.github.com>

* missing line break

---------

Co-authored-by: Jim Pivarski <jpivarski@users.noreply.github.com>
  • Loading branch information
lobis and jpivarski authored Nov 2, 2023
1 parent 0f2c4da commit 7d058d8
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 6 deletions.
11 changes: 11 additions & 0 deletions .github/workflows/build-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,17 @@ jobs:
mamba install root
conda list
- name: Install sshd for sshfs tests
if: runner.os != 'macOS' && runner.os != 'Windows'
run: |
sudo apt-get install -y openssh-server
sudo service ssh restart
ssh-keygen -t rsa -N "" -f ~/.ssh/id_rsa
cat ~/.ssh/id_rsa.pub >> ~/.ssh/authorized_keys
chmod og-wx ~/.ssh/authorized_keys
ssh-keyscan -H localhost >> ~/.ssh/known_hosts
ssh -o StrictHostKeyChecking=no localhost echo "ssh connection successful"
- name: Install XRootD
if: runner.os != 'macOS' && runner.os != 'Windows'
run: |
Expand Down
38 changes: 32 additions & 6 deletions tests/test_0692_fsspec.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
# BSD 3-Clause License; see https://github.com/scikit-hep/uproot4/blob/main/LICENSE

import fsspec
import pytest
import uproot
import uproot.source.fsspec

import skhep_testdata
import queue
import subprocess


def test_open_fsspec_http(server):
Expand Down Expand Up @@ -65,14 +67,38 @@ def test_open_fsspec_s3(handler):
assert len(data) == 8004


@pytest.mark.parametrize("handler", [uproot.source.fsspec.FSSpecSource, None])
@pytest.mark.skip("you must provide an ssh server to test this")
def test_open_fsspec_ssh(handler):
def test_open_fsspec_ssh():
pytest.importorskip("sshfs")

# change this to a server you have access to
uri = "ssh://user@host:22/tmp/file.root"
with uproot.open(uri, handler=handler) as f:
# check localhost has ssh access to itself
try:
user = subprocess.check_output(["whoami"]).strip().decode("ascii")
host = "localhost"
ssh_command = ["ssh", f"{user}@{host}", "'echo hello'"]
result = subprocess.run(
ssh_command,
shell=True,
text=True,
capture_output=True,
)
assert (
result.returncode == 0
), f"ssh access to localhost failed with {result.stderr}"
except Exception as e:
pytest.skip(f"ssh access to localhost failed with {e}")

# at this time sshfs does not implement cat_file. This will alert us if it ever does
with pytest.raises(NotImplementedError):
fs = fsspec.filesystem("ssh", host="localhost")
fs.cat_file("some-file", start=0, end=100)

pytest.skip("sshfs does not implement cat_file")

# cache the file
local_path = skhep_testdata.data_path("uproot-issue121.root")

uri = f"ssh://{user}@{host}:22{local_path}"
with uproot.open(uri, handler=uproot.source.fsspec.FSSpecSource) as f:
data = f["Events/MET_pt"].array(library="np")
assert len(data) == 40

Expand Down

0 comments on commit 7d058d8

Please sign in to comment.