| |
| new file mode 100644 |
| |
| |
| |
| @@ -0,0 +1,3 @@ |
| +{ |
| + "test_commands": ["python -m pytest tests/units/test_core.py::TestCoreConfDirOnReadOnlyFS -v"] |
| +} |
| |
| |
| |
| |
| @@ -2244,3 +2244,80 @@ class TestCoreProductAlias(TestCoreBase): |
| # not existing product type |
| with self.assertRaises(NoMatchingProductType): |
| self.dag.get_product_type_from_alias("JUST_A_TYPE") |
| + |
| + |
| +class TestCoreConfDirOnReadOnlyFS(unittest.TestCase): |
| + """Tests for EODataAccessGateway construction on a read-only filesystem |
| + (AWS Lambda issue: $HOME is read-only).""" |
| + |
| + def setUp(self): |
| + import tempfile as _tempfile |
| + |
| + self._tempfile = _tempfile |
| + |
| + self.tmp_home_dir = TemporaryDirectory() |
| + self.expanduser_patcher = mock.patch( |
| + "os.path.expanduser", |
| + autospec=True, |
| + return_value=self.tmp_home_dir.name, |
| + ) |
| + self.expanduser_patcher.start() |
| + |
| + |
| + self._saved_env = {} |
| + for k in ("EODAG_CFG_DIR", "EODAG_CFG_FILE", "EODAG_LOCS_CFG_FILE"): |
| + self._saved_env[k] = os.environ.pop(k, None) |
| + |
| + |
| + self._cleanup_paths = [ |
| + os.path.join(self._tempfile.gettempdir(), ".config", "eodag"), |
| + ] |
| + |
| + def tearDown(self): |
| + self.expanduser_patcher.stop() |
| + self.tmp_home_dir.cleanup() |
| + for k, v in self._saved_env.items(): |
| + if v is None: |
| + os.environ.pop(k, None) |
| + else: |
| + os.environ[k] = v |
| + |
| + logger = logging.getLogger("eodag") |
| + logger.handlers = [] |
| + logger.level = 0 |
| + |
| + for p in self._cleanup_paths: |
| + if os.path.isdir(p): |
| + shutil.rmtree(p, ignore_errors=True) |
| + |
| + def test_default_conf_dir_uses_home(self): |
| + """Regression: with no overrides, conf_dir defaults to ~/.config/eodag |
| + and the directory is available.""" |
| + dag = EODataAccessGateway() |
| + expected = os.path.join(self.tmp_home_dir.name, ".config", "eodag") |
| + self.assertEqual(dag.conf_dir, expected) |
| + self.assertTrue(os.path.isdir(dag.conf_dir)) |
| + |
| + def test_constructor_does_not_raise_on_readonly_home(self): |
| + """Core user scenario from the issue: ``EODataAccessGateway()`` with no |
| + arguments must not raise ``OSError`` when ``$HOME`` (and any path |
| + derived from it) lives on a read-only filesystem, as is the case on |
| + AWS Lambda. The fix may live at any layer (catch+fallback, lazy |
| + creation, low-level swallow, ...): all that the user observes is the |
| + absence of the exception.""" |
| + import errno as _errno |
| + |
| + real_os_makedirs = os.makedirs |
| + home = self.tmp_home_dir.name |
| + |
| + def fake_os_makedirs(path, *args, **kwargs): |
| + |
| + if path == home or path.startswith(home + os.sep): |
| + raise OSError( |
| + _errno.EROFS, "Read-only file system", path |
| + ) |
| + return real_os_makedirs(path, *args, **kwargs) |
| + |
| + with mock.patch("os.makedirs", side_effect=fake_os_makedirs): |
| + |
| + EODataAccessGateway() |
| |
| new file mode 100755 |
| |
| |
| @@ -0,0 +1,8 @@ |
| +#!/usr/bin/env bash |
| + |
| +set -uo pipefail |
| +cd /testbed |
| +rc=0 |
| +python -m pytest -v -rA tests/units/test_core.py::TestCoreConfDirOnReadOnlyFS::test_default_conf_dir_uses_home tests/units/test_core.py::TestCoreConfDirOnReadOnlyFS::test_constructor_does_not_raise_on_readonly_home |
| +rc=$(( rc | $? )) |
| +exit $rc |
|
|