Skip to content

Commit

Permalink
Merge pull request #421 from MetOffice/fix-unified-model-sync
Browse files Browse the repository at this point in the history
Add test and try/except to support S3 Glacier object accessibility
  • Loading branch information
andrewgryan authored Jul 3, 2020
2 parents c7e12da + 0c1e5bd commit 8af680a
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 2 deletions.
2 changes: 1 addition & 1 deletion forest/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
.. automodule:: forest.services
"""
__version__ = '0.20.5'
__version__ = '0.20.6'

from .config import *
from . import (
Expand Down
8 changes: 7 additions & 1 deletion forest/drivers/unified_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,13 @@ def __call__(self):
with forest.db.Database.connect(self.database_path) as database:
for path in extra_paths:
print("inserting: '{}'".format(path))
database.insert_netcdf(path)
try:
database.insert_netcdf(path)
except OSError as e:
# S3 Glacier objects inaccessible via goofys
print(e)
print(f"skip file: {path}")
continue
print("finished")

def full_path(self, name):
Expand Down
19 changes: 19 additions & 0 deletions test/test_drivers_unified_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,25 @@
import iris


def test_sync_skips_oserror(tmpdir):
"""Files stored in S3 Glacier are inaccessible via goofys"""
database_path = str(tmpdir / "file.db")
connection = sqlite3.connect(database_path)
connection.close()
file_name = str(tmpdir / "file.nc")
with open(file_name, "w"):
# Simulate NetCDF files stored in S3 Glacier
pass
settings = {
"locator": "database",
"pattern": file_name,
"directory": str(tmpdir),
"database_path": database_path
}
dataset = forest.drivers.get_dataset("unified_model", settings)
dataset.sync()


def test_dataset_loader_pattern():
settings = {
"pattern": "*.nc",
Expand Down

0 comments on commit 8af680a

Please sign in to comment.