]> review.fuel-infra Code Review - openstack-build/cinder-build.git/commitdiff
Remove redundant temporary_chown from IetAdm
authorJon Bernard <jobernar@redhat.com>
Mon, 18 Aug 2014 20:58:30 +0000 (16:58 -0400)
committerJon Bernard <jobernar@redhat.com>
Tue, 19 Aug 2014 19:59:50 +0000 (15:59 -0400)
I may have missed something but it appears this routine is effectively
the same as temporary_chown defined in utils.py.  It seems reasonable to
use that one instead.

Change-Id: I1de4a49797e50246b323dc460c07e2eec727b3bb

cinder/brick/iscsi/iscsi.py

index eee84ad8ed7b5a57998c149200d1365a3224ecad..f557e61724f3cfb581cfe5fb6e0c2e1568895570 100644 (file)
@@ -18,7 +18,6 @@ Helper code for the iSCSI volume driver.
 
 """
 
-import contextlib
 import os
 import re
 import stat
@@ -30,7 +29,7 @@ from cinder.i18n import _
 from cinder.openstack.common import fileutils
 from cinder.openstack.common import log as logging
 from cinder.openstack.common import processutils as putils
-
+from cinder import utils
 
 LOG = logging.getLogger(__name__)
 
@@ -346,28 +345,6 @@ class IetAdm(TargetAdmin):
         else:
             return self.iscsi_iotype
 
-    @contextlib.contextmanager
-    def temporary_chown(self, path, owner_uid=None):
-        """Temporarily chown a path.
-
-        :params path: The path to chown
-        :params owner_uid: UID of temporary owner (defaults to current user)
-        """
-        if owner_uid is None:
-            owner_uid = os.getuid()
-
-        orig_uid = os.stat(path).st_uid
-
-        if orig_uid != owner_uid:
-            putils.execute('chown', owner_uid, path,
-                           root_helper=self._root_helper, run_as_root=True)
-        try:
-            yield
-        finally:
-            if orig_uid != owner_uid:
-                putils.execute('chown', orig_uid, path,
-                               root_helper=self._root_helper, run_as_root=True)
-
     def create_iscsi_target(self, name, tid, lun, path,
                             chap_auth=None, **kwargs):
 
@@ -389,7 +366,7 @@ class IetAdm(TargetAdmin):
                             Lun 0 Path=%s,Type=%s
                 """ % (name, chap_auth, path, self._iotype(path))
 
-                with self.temporary_chown(conf_file):
+                with utils.temporary_chown(conf_file):
                     f = open(conf_file, 'a+')
                     f.write(volume_conf)
                     f.close()
@@ -408,7 +385,7 @@ class IetAdm(TargetAdmin):
         vol_uuid_file = vol_name
         conf_file = self.iet_conf
         if os.path.exists(conf_file):
-            with self.temporary_chown(conf_file):
+            with utils.temporary_chown(conf_file):
                 try:
                     iet_conf_text = open(conf_file, 'r+')
                     full_txt = iet_conf_text.readlines()