Skip to content

Commit

Permalink
Streamlined cavern calls
Browse files Browse the repository at this point in the history
  • Loading branch information
Adrian Damian authored and Adrian Damian committed Mar 28, 2024
1 parent 2489f5b commit 34f45f9
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 5 deletions.
11 changes: 11 additions & 0 deletions vos/vos/tests/test_vos.py
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,7 @@ def test_get_node_url():
response.headers = {'Location': transfer_url}
mock_session = Mock(spec=requests.Session, get=Mock(return_value=response))
client.get_session = Mock(return_value=mock_session)
client._fs_type = False
assert transfer_url == \
client.get_node_url('vos://cadc.nrc.ca!vospace/auser',
view='header')
Expand Down Expand Up @@ -478,11 +479,21 @@ def is_remote_file(uri):
response.iter_content.return_value = BytesIO(file_content)
session.get.return_value = response
test_client.get_session = Mock(return_value=session)
# client must be a vault client
test_client._fs_type = False
test_client.copy('{}{}'.format(vospaceLocation,
'[1][10:60]'), osLocation)
get_node_url_mock.assert_called_once_with(
vospaceLocation, method='GET', cutout='[1][10:60]', view='cutout')

# test cavern does not support SODA operations
test_client._fs_type = True
with pytest.raises(ValueError):
test_client.copy('{}{}'.format(vospaceLocation, '[1][10:60]'), osLocation)
with pytest.raises(ValueError):
test_client.copy(vospaceLocation, osLocation, head=True)

test_client._fs_type = False
# copy to vospace when md5 sums are the same -> only update occurs
get_node_url_mock.reset_mock()
computed_md5_mock.reset_mock()
Expand Down
16 changes: 11 additions & 5 deletions vos/vos/vos.py
Original file line number Diff line number Diff line change
Expand Up @@ -1526,6 +1526,7 @@ def __init__(self, vospace_certfile=None,
Client.VOSPACE_CERTFILE or vospace_certfile
self.vospace_token = vospace_token
self.insecure = insecure
self._fs_type = True # True - file system type (cavern), False - db type (vault)

def glob(self, pathname):
"""Return a list of paths matching a pathname pattern.
Expand Down Expand Up @@ -1690,6 +1691,10 @@ def get_endpoints(self, uri):

else:
raise OSError('No scheme in {}'.format(uri))
# following is a CADC hack as others can deploy the services under different
# resource IDs
if 'vault' in resource_id:
self._fs_type = False
if resource_id not in self._endpoints:
try:
self._endpoints[resource_id] = EndPoints(
Expand Down Expand Up @@ -1844,6 +1849,8 @@ def copy(self, source, destination, send_md5=False, disposition=False,

get_urls = []
files_url = None
if self._fs_type and (cutout or view == 'header'):
raise ValueError('cavern/arc service does not support cutouts or header operations')
if new_vos:
files_url = self.get_node_url(source, method='GET', cutout=cutout,
view=view)
Expand Down Expand Up @@ -2419,18 +2426,17 @@ def _get(self, uri):
if not file_path:
return None

Check warning on line 2427 in vos/vos/vos.py

View check run for this annotation

Codecov / codecov/patch

vos/vos/vos.py#L2427

Added line #L2427 was not covered by tests
files_url = '{}{}'.format(files_ep, file_path)
if self._fs_type:
# files_url contains the bytes
return files_url

Check warning on line 2431 in vos/vos/vos.py

View check run for this annotation

Codecov / codecov/patch

vos/vos/vos.py#L2431

Added line #L2431 was not covered by tests
# remaining is for vault
try:
response = self.get_session(uri).get(files_url, allow_redirects=False)
response.raise_for_status()
except Exception:
return None

Check warning on line 2437 in vos/vos/vos.py

View check run for this annotation

Codecov / codecov/patch

vos/vos/vos.py#L2436-L2437

Added lines #L2436 - L2437 were not covered by tests
if response.status_code == 303:
return response.headers.get('Location', None)
elif response.status_code == 200:
# TODO this happens for cavern. It is wasteful since the response
# already contains the bytes but there's no other way to find out the
# actual location of the bytes.
return files_url
return None

Check warning on line 2440 in vos/vos/vos.py

View check run for this annotation

Codecov / codecov/patch

vos/vos/vos.py#L2440

Added line #L2440 was not covered by tests

def _add_soda_ops(self, url, view=None, cutout=None):
Expand Down

0 comments on commit 34f45f9

Please sign in to comment.