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:
parent
e396560f33
commit
4560e3e12a
cinder
@ -51,6 +51,12 @@ class FakeFileStorage(object):
|
|||||||
def close(self):
|
def close(self):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
def __enter__(self):
|
||||||
|
return self
|
||||||
|
|
||||||
|
def __exit__(self, type, value, traceback):
|
||||||
|
self.close()
|
||||||
|
|
||||||
|
|
||||||
class PasswordFileStorageTestCase(test.TestCase):
|
class PasswordFileStorageTestCase(test.TestCase):
|
||||||
"""Tests for the password storage."""
|
"""Tests for the password storage."""
|
||||||
|
@ -14,7 +14,6 @@
|
|||||||
|
|
||||||
"""Password storage."""
|
"""Password storage."""
|
||||||
|
|
||||||
import contextlib
|
|
||||||
import json
|
import json
|
||||||
import os
|
import os
|
||||||
import stat
|
import stat
|
||||||
@ -93,6 +92,12 @@ class FileStorage(object):
|
|||||||
self._file.close()
|
self._file.close()
|
||||||
self._file = None
|
self._file = None
|
||||||
|
|
||||||
|
def __enter__(self):
|
||||||
|
return self
|
||||||
|
|
||||||
|
def __exit__(self, type, value, traceback):
|
||||||
|
self.close()
|
||||||
|
|
||||||
|
|
||||||
class PasswordFileStorage(object):
|
class PasswordFileStorage(object):
|
||||||
"""Password storage implementation.
|
"""Password storage implementation.
|
||||||
@ -116,7 +121,7 @@ class PasswordFileStorage(object):
|
|||||||
@cinder_utils.synchronized(
|
@cinder_utils.synchronized(
|
||||||
'datacore-password_storage-' + self._file_path, external=True)
|
'datacore-password_storage-' + self._file_path, external=True)
|
||||||
def _set_password():
|
def _set_password():
|
||||||
with contextlib.closing(self._file_storage.open()) as storage:
|
with self._file_storage.open() as storage:
|
||||||
passwords = storage.load()
|
passwords = storage.load()
|
||||||
if resource not in passwords:
|
if resource not in passwords:
|
||||||
passwords[resource] = {}
|
passwords[resource] = {}
|
||||||
@ -138,7 +143,7 @@ class PasswordFileStorage(object):
|
|||||||
@cinder_utils.synchronized(
|
@cinder_utils.synchronized(
|
||||||
'datacore-password_storage-' + self._file_path, external=True)
|
'datacore-password_storage-' + self._file_path, external=True)
|
||||||
def _get_password():
|
def _get_password():
|
||||||
with contextlib.closing(self._file_storage.open()) as storage:
|
with self._file_storage.open() as storage:
|
||||||
passwords = storage.load()
|
passwords = storage.load()
|
||||||
if resource in passwords:
|
if resource in passwords:
|
||||||
return passwords[resource].get(username)
|
return passwords[resource].get(username)
|
||||||
@ -155,7 +160,7 @@ class PasswordFileStorage(object):
|
|||||||
@cinder_utils.synchronized(
|
@cinder_utils.synchronized(
|
||||||
'datacore-password_storage-' + self._file_path, external=True)
|
'datacore-password_storage-' + self._file_path, external=True)
|
||||||
def _delete_password():
|
def _delete_password():
|
||||||
with contextlib.closing(self._file_storage.open()) as storage:
|
with self._file_storage.open() as storage:
|
||||||
passwords = storage.load()
|
passwords = storage.load()
|
||||||
if resource in passwords and username in passwords[resource]:
|
if resource in passwords and username in passwords[resource]:
|
||||||
del passwords[resource][username]
|
del passwords[resource][username]
|
||||||
|
Loading…
x
Reference in New Issue
Block a user