16039: Accommodate API servers with no config export.
authorTom Clegg <tom@tomclegg.ca>
Wed, 12 Feb 2020 15:37:48 +0000 (10:37 -0500)
committerTom Clegg <tom@tomclegg.ca>
Wed, 12 Feb 2020 15:37:48 +0000 (10:37 -0500)
Add more checks in test cases.

Arvados-DCO-1.1-Signed-off-by: Tom Clegg <tom@tomclegg.ca>

sdk/python/arvados/util.py
services/fuse/arvados_fuse/fusedir.py
services/fuse/tests/test_mount.py

index b27b64e5979d53d4e350dfefdb834bbc573f0ec3..9e0a3178305068c4edec716c57467221f98af562 100644 (file)
@@ -421,6 +421,9 @@ def new_request_id():
     return rid
 
 def get_config_once(svc):
+    if not svc._rootDesc.get('resources')['configs']:
+        # Old API server version, no config export endpoint
+        return {}
     if not hasattr(svc, '_cached_config'):
         svc._cached_config = svc.configs().get().execute()
     return svc._cached_config
index 9853f6ac20d591f4e71da9f7ef32823e1a793607..3f6430973d07e282eb025ea63c5b51b0ac954e91 100644 (file)
@@ -55,10 +55,24 @@ class Directory(FreshBase):
         self._entries = {}
         self._mtime = time.time()
 
+    def forward_slash_subst(self):
+        if not hasattr(self, '_fsns'):
+            self._fsns = None
+            config = self.apiconfig()
+            try:
+                self._fsns = config["Collections"]["ForwardSlashNameSubstitution"]
+            except KeyError:
+                # old API server with no FSNS config
+                self._fsns = '_'
+            else:
+                if self._fsns == '' or self._fsns == '/':
+                    self._fsns = None
+        return self._fsns
+
     def unsanitize_filename(self, incoming):
         """Replace ForwardSlashNameSubstitution value with /"""
-        fsns = self.apiconfig()["Collections"]["ForwardSlashNameSubstitution"]
-        if isinstance(fsns, str) and fsns != '' and fsns != '/':
+        fsns = self.forward_slash_subst()
+        if isinstance(fsns, str):
             return incoming.replace(fsns, '/')
         else:
             return incoming
@@ -76,8 +90,8 @@ class Directory(FreshBase):
         elif dirty == '..':
             return '__'
         else:
-            fsns = self.apiconfig()["Collections"]["ForwardSlashNameSubstitution"]
-            if isinstance(fsns, str) and fsns != '':
+            fsns = self.forward_slash_subst()
+            if isinstance(fsns, str):
                 dirty = dirty.replace('/', fsns)
             return _disallowed_filename_characters.sub('_', dirty)
 
index 3ec03fa22633d6655d3355898ec15c18843cd1ec..1e63b9f4da89f97a16955beac65e5ec9083dd6eb 100644 (file)
@@ -1214,10 +1214,11 @@ class SlashSubstitutionTest(IntegrationTest):
     def test_slash_substitution_before_listing(self, get_config_once):
         get_config_once.return_value = {"Collections": {"ForwardSlashNameSubstitution": "[SLASH]"}}
         self.pool_test(os.path.join(self.mnt, 'zzz'), self.fusename)
+        self.checkContents()
     @staticmethod
     def _test_slash_substitution_before_listing(self, tmpdir, fusename):
         with open(os.path.join(tmpdir, 'foo-bar-baz', 'waz'), 'w') as f:
-            f.write('foo')
+            f.write('xxx')
         with open(os.path.join(tmpdir, fusename, 'waz'), 'w') as f:
             f.write('foo')
 
@@ -1226,10 +1227,15 @@ class SlashSubstitutionTest(IntegrationTest):
     def test_slash_substitution_after_listing(self, get_config_once):
         get_config_once.return_value = {"Collections": {"ForwardSlashNameSubstitution": "[SLASH]"}}
         self.pool_test(os.path.join(self.mnt, 'zzz'), self.fusename)
+        self.checkContents()
     @staticmethod
     def _test_slash_substitution_after_listing(self, tmpdir, fusename):
         with open(os.path.join(tmpdir, 'foo-bar-baz', 'waz'), 'w') as f:
-            f.write('foo')
+            f.write('xxx')
         os.listdir(tmpdir)
         with open(os.path.join(tmpdir, fusename, 'waz'), 'w') as f:
             f.write('foo')
+
+    def checkContents(self):
+        self.assertRegexpMatches(self.api.collections().get(uuid=self.testcoll['uuid']).execute()['manifest_text'], ' acbd18db') # md5(foo)
+        self.assertRegexpMatches(self.api.collections().get(uuid=self.testcolleasy['uuid']).execute()['manifest_text'], ' f561aaf6') # md5(xxx)