Skip to content

Commit

Permalink
Merge "Removed the dep on cinder.utils"
Browse files Browse the repository at this point in the history
  • Loading branch information
Jenkins authored and openstack-gerrit committed Jul 29, 2013
2 parents 9f0bb80 + ccc32c5 commit 6f81fa2
Showing 1 changed file with 27 additions and 7 deletions.
34 changes: 27 additions & 7 deletions cinder/brick/iscsi/iscsi.py
Expand Up @@ -20,7 +20,7 @@
"""


import contextlib
import os
import re

Expand All @@ -29,7 +29,7 @@
from cinder import exception
from cinder.openstack.common import fileutils
from cinder.openstack.common import log as logging
from cinder import utils
from cinder.openstack.common import processutils as putils
from cinder.volume import utils as volume_utils


Expand Down Expand Up @@ -116,7 +116,7 @@ def _delete_logicalunit(self, tid, lun, **kwargs):
class TgtAdm(TargetAdmin):
"""iSCSI target administration using tgtadm."""

def __init__(self, execute=utils.execute):
def __init__(self, execute=putils.execute):
super(TgtAdm, self).__init__('tgtadm', execute)

def _get_target(self, iqn):
Expand Down Expand Up @@ -233,7 +233,7 @@ def show_target(self, tid, iqn=None, **kwargs):
class IetAdm(TargetAdmin):
"""iSCSI target administration using ietadm."""

def __init__(self, execute=utils.execute):
def __init__(self, execute=putils.execute):
super(IetAdm, self).__init__('ietadm', execute)

def _iotype(self, path):
Expand All @@ -242,6 +242,26 @@ def _iotype(self, path):
else:
return CONF.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, run_as_root=True)
try:
yield
finally:
if orig_uid != owner_uid:
putils.execute('chown', orig_uid, path, run_as_root=True)

def create_iscsi_target(self, name, tid, lun, path,
chap_auth=None, **kwargs):

Expand All @@ -263,7 +283,7 @@ def create_iscsi_target(self, name, tid, lun, path,
Lun 0 Path=%s,Type=%s
""" % (name, chap_auth, path, self._iotype(path))

with utils.temporary_chown(conf_file):
with self.temporary_chown(conf_file):
f = open(conf_file, 'a+')
f.write(volume_conf)
f.close()
Expand All @@ -282,7 +302,7 @@ def remove_iscsi_target(self, tid, lun, vol_id, **kwargs):
vol_uuid_file = CONF.volume_name_template % vol_id
conf_file = CONF.iet_conf
if os.path.exists(conf_file):
with utils.temporary_chown(conf_file):
with self.temporary_chown(conf_file):
try:
iet_conf_text = open(conf_file, 'r+')
full_txt = iet_conf_text.readlines()
Expand Down Expand Up @@ -356,7 +376,7 @@ def create_iscsi_target(self, *args, **kwargs):

class LioAdm(TargetAdmin):
"""iSCSI target administration for LIO using python-rtslib."""
def __init__(self, execute=utils.execute):
def __init__(self, execute=putils.execute):
super(LioAdm, self).__init__('rtstool', execute)

try:
Expand Down

0 comments on commit 6f81fa2

Please sign in to comment.