Merge "Optimize "open" method with context manager"

This commit is contained in:
Jenkins 2015-12-01 05:48:25 +00:00 committed by Gerrit Code Review
commit e62cb5eac5
2 changed files with 4 additions and 6 deletions

View File

@ -130,9 +130,8 @@ class CxtAdm(iscsi.ISCSITarget):
if os.path.exists(volume_path):
LOG.warning(_LW('Persistence file already exists for volume, '
'found file at: %s'), volume_path)
f = open(volume_path, 'w+')
f.write(volume_conf)
f.close()
with open(volume_path, 'w+') as f:
f.write(volume_conf)
LOG.debug('Created volume path %(vp)s,\n'
'content: %(vc)s',
{'vp': volume_path, 'vc': volume_conf})

View File

@ -165,9 +165,8 @@ class TgtAdm(iscsi.ISCSITarget):
if os.path.exists(volume_path):
LOG.warning(_LW('Persistence file already exists for volume, '
'found file at: %s'), volume_path)
f = open(volume_path, 'w+')
f.write(volume_conf)
f.close()
with open(volume_path, 'w+') as f:
f.write(volume_conf)
LOG.debug(('Created volume path %(vp)s,\n'
'content: %(vc)s'),
{'vp': volume_path, 'vc': volume_conf})