Replace the classic open() with opening context manager to open
files which is in the create_iscsi_target methods of volume targets.
Change-Id: I12e19801a21b1279308983fd0257dae9c9653641
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})
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})