]> review.fuel-infra Code Review - openstack-build/cinder-build.git/commitdiff
Fix nfs_shares config file parsing of spaces
authorMikhail Khodos <mikhail.khodos@nexenta.com>
Tue, 17 Jun 2014 20:28:04 +0000 (00:28 +0400)
committerMikhail Khodos <mikhail.khodos@nexenta.com>
Fri, 20 Jun 2014 16:59:51 +0000 (20:59 +0400)
Driver fails in case if 'nfs_shares' file lines contain more than one
space between it's patrs. This patch fixes this.

Change-Id: I446ab23f0ae06ec9e8ad18ebc1d79c705de47e4d

cinder/tests/test_nexenta.py
cinder/volume/drivers/nexenta/nfs.py

index 2080f5ae2780ad9c88bc448a6ee9183c5bb74916..6a2bc52d44ec24c0d58afdf52b36dd18d8c9d493 100644 (file)
@@ -627,11 +627,11 @@ class TestNexentaNfsDriver(test.TestCase):
 
         self.mox.StubOutWithMock(self.drv, '_read_config_file')
         config_data = [
-            '%s %s' % (self.TEST_EXPORT1, self.TEST_NMS1),
-            '# %s %s' % (self.TEST_EXPORT2, self.TEST_NMS2),
+            '%s  %s' % (self.TEST_EXPORT1, self.TEST_NMS1),
+            '# %s   %s' % (self.TEST_EXPORT2, self.TEST_NMS2),
             '',
-            '%s %s %s' % (self.TEST_EXPORT2, self.TEST_NMS2,
-                          self.TEST_EXPORT2_OPTIONS)
+            '%s  %s %s' % (self.TEST_EXPORT2, self.TEST_NMS2,
+                           self.TEST_EXPORT2_OPTIONS)
         ]
 
         self.drv._read_config_file(self.TEST_SHARES_CONFIG_FILE).\
index d20cbf48f25871e414976713b7d4b35ad5b90ba7..4da76784ce43abb499083944c0b5a8643becfdf7 100644 (file)
@@ -23,6 +23,7 @@
 
 import hashlib
 import os
+import re
 
 from cinder import context
 from cinder import db
@@ -381,12 +382,17 @@ class NexentaNfsDriver(nfs.NfsDriver):  # pylint: disable=R0921
             if share.startswith('#'):
                 continue
 
-            share_info = share.split(' ', 2)
+            share_info = re.split(r'\s+', share, 2)
 
             share_address = share_info[0].strip().decode('unicode_escape')
             nms_url = share_info[1].strip()
             share_opts = share_info[2].strip() if len(share_info) > 2 else None
 
+            if not re.match(r'.+:/.+', share_address):
+                LOG.warn("Share %s ignored due to invalid format.  Must be of "
+                         "form address:/export." % share_address)
+                continue
+
             self.shares[share_address] = share_opts
             self.share2nms[share_address] = self._get_nms_for_url(nms_url)