DataCore: get rid of pylint errors due to contextlib

Use of contextlib.closing causes pylint to not recognize the
type and causes "no memeber" errors. Since this is a locally
defined class that can simply be made into a context manager,
this removes the use of contextlib and handles it directly in
code.

Change-Id: I2b284b1ba51f848c183c3895948131de9e89d300
This commit is contained in:
Sean McGinnis 2018-06-20 13:51:00 -05:00
parent e396560f33
commit 4560e3e12a
2 changed files with 15 additions and 4 deletions

View File

@ -51,6 +51,12 @@ class FakeFileStorage(object):
def close(self):
pass
def __enter__(self):
return self
def __exit__(self, type, value, traceback):
self.close()
class PasswordFileStorageTestCase(test.TestCase):
"""Tests for the password storage."""

View File

@ -14,7 +14,6 @@
"""Password storage."""
import contextlib
import json
import os
import stat
@ -93,6 +92,12 @@ class FileStorage(object):
self._file.close()
self._file = None
def __enter__(self):
return self
def __exit__(self, type, value, traceback):
self.close()
class PasswordFileStorage(object):
"""Password storage implementation.
@ -116,7 +121,7 @@ class PasswordFileStorage(object):
@cinder_utils.synchronized(
'datacore-password_storage-' + self._file_path, external=True)
def _set_password():
with contextlib.closing(self._file_storage.open()) as storage:
with self._file_storage.open() as storage:
passwords = storage.load()
if resource not in passwords:
passwords[resource] = {}
@ -138,7 +143,7 @@ class PasswordFileStorage(object):
@cinder_utils.synchronized(
'datacore-password_storage-' + self._file_path, external=True)
def _get_password():
with contextlib.closing(self._file_storage.open()) as storage:
with self._file_storage.open() as storage:
passwords = storage.load()
if resource in passwords:
return passwords[resource].get(username)
@ -155,7 +160,7 @@ class PasswordFileStorage(object):
@cinder_utils.synchronized(
'datacore-password_storage-' + self._file_path, external=True)
def _delete_password():
with contextlib.closing(self._file_storage.open()) as storage:
with self._file_storage.open() as storage:
passwords = storage.load()
if resource in passwords and username in passwords[resource]:
del passwords[resource][username]