Преглед изворни кода

Brick connector revised fix for NFS drivers

This change fixes the error that comes
while getting brick connector and attaching volumes
in case of NFS drivers in cinder. The attribute for
mount point base was not passed to attach_volume method
as the connector initialization logic is common for all
types of protocols. It is fixed by populating
the required parameter in the RemoteFsConnector
by extracting it from connection properties. The infrastructure
for fixing this situation for remote fs drivers is implemented
in this fix. The drivers need to override the method
_get_mount_point_base in their implementation. NFS driver
implements it. GlusterFs implementation of the method to follow
in a separate patch. Hence marking it partial fix.

Change-Id: Id61a437fca1870529fa8b85f7fc2f73eae665294
Partial-Bug: #1238085
(cherry picked from commit 1cd3626306)
tags/2013.2.2
Navneet Singh пре 5 година
родитељ
комит
b15118a78d

+ 16
- 1
cinder/brick/initiator/connector.py Прегледај датотеку

@@ -797,6 +797,21 @@ class RemoteFsConnector(InitiatorConnector):
797 797
                  execute=putils.execute,
798 798
                  device_scan_attempts=DEVICE_SCAN_ATTEMPTS_DEFAULT,
799 799
                  *args, **kwargs):
800
+        kwargs = kwargs or {}
801
+        conn = kwargs.get('conn')
802
+        if conn:
803
+            mount_point_base = conn.get('mount_point_base')
804
+            if mount_type.lower() == 'nfs':
805
+                kwargs['nfs_mount_point_base'] =\
806
+                    kwargs.get('nfs_mount_point_base') or\
807
+                    mount_point_base
808
+            elif mount_type.lower() == 'glusterfs':
809
+                kwargs['glusterfs_mount_point_base'] =\
810
+                    kwargs.get('glusterfs_mount_point_base') or\
811
+                    mount_point_base
812
+        else:
813
+            LOG.warn(_("Connection details not present."
814
+                       " RemoteFsClient may not initialize properly."))
800 815
         self._remotefsclient = remotefs.RemoteFsClient(mount_type, root_helper,
801 816
                                                        execute=execute,
802 817
                                                        *args, **kwargs)
@@ -822,7 +837,7 @@ class RemoteFsConnector(InitiatorConnector):
822 837
         """
823 838
 
824 839
         mnt_flags = []
825
-        if 'options' in connection_properties:
840
+        if connection_properties.get('options'):
826 841
             mnt_flags = connection_properties['options'].split()
827 842
 
828 843
         nfs_share = connection_properties['export']

+ 2
- 1
cinder/tests/test_coraid.py Прегледај датотеку

@@ -787,7 +787,8 @@ class CoraidDriverImageTestCases(CoraidDriverTestCase):
787 787
 
788 788
         utils.brick_get_connector('aoe',
789 789
                                   device_scan_attempts=3,
790
-                                  use_multipath=False).\
790
+                                  use_multipath=False,
791
+                                  conn=mox.IgnoreArg()).\
791 792
             AndReturn(aoe_initiator)
792 793
 
793 794
         aoe_initiator\

+ 4
- 2
cinder/utils.py Прегледај датотеку

@@ -794,7 +794,8 @@ def brick_get_connector_properties():
794 794
 def brick_get_connector(protocol, driver=None,
795 795
                         execute=processutils.execute,
796 796
                         use_multipath=False,
797
-                        device_scan_attempts=3):
797
+                        device_scan_attempts=3,
798
+                        *args, **kwargs):
798 799
     """Wrapper to get a brick connector object.
799 800
     This automatically populates the required protocol as well
800 801
     as the root_helper needed to execute commands.
@@ -806,7 +807,8 @@ def brick_get_connector(protocol, driver=None,
806 807
                                                 execute=execute,
807 808
                                                 use_multipath=use_multipath,
808 809
                                                 device_scan_attempts=
809
-                                                device_scan_attempts)
810
+                                                device_scan_attempts,
811
+                                                *args, **kwargs)
810 812
 
811 813
 
812 814
 def require_driver_initialized(func):

+ 2
- 1
cinder/volume/driver.py Прегледај датотеку

@@ -375,7 +375,8 @@ class VolumeDriver(object):
375 375
         connector = utils.brick_get_connector(protocol,
376 376
                                               use_multipath=use_multipath,
377 377
                                               device_scan_attempts=
378
-                                              device_scan_attempts)
378
+                                              device_scan_attempts,
379
+                                              conn=conn)
379 380
         device = connector.connect_volume(conn['data'])
380 381
         host_device = device['path']
381 382
 

+ 25
- 5
cinder/volume/drivers/nfs.py Прегледај датотеку

@@ -90,9 +90,25 @@ class RemoteFsDriver(driver.VolumeDriver):
90 90
             data['options'] = self.shares[volume['provider_location']]
91 91
         return {
92 92
             'driver_volume_type': self.driver_volume_type,
93
-            'data': data
93
+            'data': data,
94
+            'mount_point_base': self._get_mount_point_base()
94 95
         }
95 96
 
97
+    def _get_mount_point_base(self):
98
+        """Returns the mount point base for the remote fs.
99
+
100
+           This method facilitates returning mount point base
101
+           for the specific remote fs. Override this method
102
+           in the respective driver to return the entry to be
103
+           used while attach/detach using brick in cinder.
104
+           If not overridden then it returns None without
105
+           raising exception to continue working for cases
106
+           when not used with brick.
107
+        """
108
+        LOG.debug(_("Driver specific implementation needs to return"
109
+                    " mount_point_base."))
110
+        return None
111
+
96 112
     def create_volume(self, volume):
97 113
         """Creates a volume.
98 114
 
@@ -371,15 +387,16 @@ class NfsDriver(RemoteFsDriver):
371 387
         super(NfsDriver, self).__init__(*args, **kwargs)
372 388
         self.configuration.append_config_values(volume_opts)
373 389
         root_helper = utils.get_root_helper()
374
-        base = getattr(self.configuration,
375
-                       'nfs_mount_point_base',
376
-                       CONF.nfs_mount_point_base)
390
+        # base bound to instance is used in RemoteFsConnector.
391
+        self.base = getattr(self.configuration,
392
+                            'nfs_mount_point_base',
393
+                            CONF.nfs_mount_point_base)
377 394
         opts = getattr(self.configuration,
378 395
                        'nfs_mount_options',
379 396
                        CONF.nfs_mount_options)
380 397
         self._remotefsclient = remotefs.RemoteFsClient(
381 398
             'nfs', root_helper, execute=execute,
382
-            nfs_mount_point_base=base,
399
+            nfs_mount_point_base=self.base,
383 400
             nfs_mount_options=opts)
384 401
 
385 402
     def set_execute(self, execute):
@@ -531,3 +548,6 @@ class NfsDriver(RemoteFsDriver):
531 548
                               '*snapshot*', mount_point, run_as_root=True)
532 549
         total_allocated = float(du.split()[0])
533 550
         return total_size, total_available, total_allocated
551
+
552
+    def _get_mount_point_base(self):
553
+        return self.base

Loading…
Откажи
Сачувај