mirror of
https://github.com/ansible/ansible.git
synced 2026-08-07 08:04:02 +02:00
Code cleanup to prepare for pylint update. (#75475)
* user - Remove unused code. * Replace deprecated abstractproperty decorator. * Fix __all__ to be a tuple. * Use a generator in subelements lookup. * Use from import in basic.py * Add changelog fragment. * Fix selinux unit test.
This commit is contained in:
@@ -0,0 +1,6 @@
|
|||||||
|
minor_changes:
|
||||||
|
- basic module_util - Clean up ``selinux`` compat import.
|
||||||
|
- subelements lookup - Use generator in instance type check.
|
||||||
|
- unicode utils - Fix ``__all__`` which was incorrectly declared as a string instead of a tuple.
|
||||||
|
- connection base - Avoid using deprecated ``@abstractproperty`` decorator.
|
||||||
|
- user module - Remove unused code.
|
||||||
@@ -73,7 +73,7 @@ except ImportError:
|
|||||||
|
|
||||||
HAVE_SELINUX = False
|
HAVE_SELINUX = False
|
||||||
try:
|
try:
|
||||||
import ansible.module_utils.compat.selinux as selinux
|
from ansible.module_utils.compat import selinux
|
||||||
HAVE_SELINUX = True
|
HAVE_SELINUX = True
|
||||||
except ImportError:
|
except ImportError:
|
||||||
pass
|
pass
|
||||||
|
|||||||
@@ -3197,12 +3197,12 @@ def main():
|
|||||||
# deal with password expire max
|
# deal with password expire max
|
||||||
if user.password_expire_max:
|
if user.password_expire_max:
|
||||||
if user.user_exists():
|
if user.user_exists():
|
||||||
(rc, out, err) = user.set_password_expire_max()
|
user.set_password_expire_max()
|
||||||
|
|
||||||
# deal with password expire min
|
# deal with password expire min
|
||||||
if user.password_expire_min:
|
if user.password_expire_min:
|
||||||
if user.user_exists():
|
if user.user_exists():
|
||||||
(rc, out, err) = user.set_password_expire_min()
|
user.set_password_expire_min()
|
||||||
|
|
||||||
module.exit_json(**result)
|
module.exit_json(**result)
|
||||||
|
|
||||||
|
|||||||
@@ -9,7 +9,7 @@ import fcntl
|
|||||||
import os
|
import os
|
||||||
import shlex
|
import shlex
|
||||||
|
|
||||||
from abc import abstractmethod, abstractproperty
|
from abc import abstractmethod
|
||||||
from functools import wraps
|
from functools import wraps
|
||||||
|
|
||||||
from ansible import constants as C
|
from ansible import constants as C
|
||||||
@@ -121,7 +121,8 @@ class ConnectionBase(AnsiblePlugin):
|
|||||||
# In Python3, shlex.split doesn't work on a byte string.
|
# In Python3, shlex.split doesn't work on a byte string.
|
||||||
return [to_text(x.strip()) for x in shlex.split(argstring) if x.strip()]
|
return [to_text(x.strip()) for x in shlex.split(argstring) if x.strip()]
|
||||||
|
|
||||||
@abstractproperty
|
@property
|
||||||
|
@abstractmethod
|
||||||
def transport(self):
|
def transport(self):
|
||||||
"""String used to identify this Connection class from other classes"""
|
"""String used to identify this Connection class from other classes"""
|
||||||
pass
|
pass
|
||||||
|
|||||||
@@ -126,7 +126,7 @@ class LookupModule(LookupBase):
|
|||||||
flags = {}
|
flags = {}
|
||||||
if len(terms) == 3:
|
if len(terms) == 3:
|
||||||
flags = terms[2]
|
flags = terms[2]
|
||||||
if not isinstance(flags, dict) and not all([isinstance(key, string_types) and key in FLAGS for key in flags]):
|
if not isinstance(flags, dict) and not all(isinstance(key, string_types) and key in FLAGS for key in flags):
|
||||||
_raise_terms_error("the optional third item must be a dict with flags %s" % FLAGS)
|
_raise_terms_error("the optional third item must be a dict with flags %s" % FLAGS)
|
||||||
|
|
||||||
# build_items
|
# build_items
|
||||||
|
|||||||
@@ -22,7 +22,7 @@ __metaclass__ = type
|
|||||||
from ansible.module_utils._text import to_text
|
from ansible.module_utils._text import to_text
|
||||||
|
|
||||||
|
|
||||||
__all__ = ('unicode_wrap')
|
__all__ = ('unicode_wrap',)
|
||||||
|
|
||||||
|
|
||||||
def unicode_wrap(func, *args, **kwargs):
|
def unicode_wrap(func, *args, **kwargs):
|
||||||
|
|||||||
@@ -43,10 +43,10 @@ class TestImports(ModuleTestCase):
|
|||||||
|
|
||||||
@patch.object(builtins, '__import__')
|
@patch.object(builtins, '__import__')
|
||||||
def test_module_utils_basic_import_selinux(self, mock_import):
|
def test_module_utils_basic_import_selinux(self, mock_import):
|
||||||
def _mock_import(name, *args, **kwargs):
|
def _mock_import(name, globals=None, locals=None, fromlist=tuple(), level=0, **kwargs):
|
||||||
if name == 'ansible.module_utils.compat.selinux':
|
if name == 'ansible.module_utils.compat' and fromlist == ('selinux',):
|
||||||
raise ImportError
|
raise ImportError
|
||||||
return realimport(name, *args, **kwargs)
|
return realimport(name, globals=globals, locals=locals, fromlist=fromlist, level=level, **kwargs)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
self.clear_modules(['ansible.module_utils.compat.selinux', 'ansible.module_utils.basic'])
|
self.clear_modules(['ansible.module_utils.compat.selinux', 'ansible.module_utils.basic'])
|
||||||
|
|||||||
Reference in New Issue
Block a user