pep related fixes

This commit is contained in:
Adolfo Gómez García 2018-04-18 01:06:06 +02:00
parent f74b0b0fe9
commit 0021fd5ff9
11 changed files with 26 additions and 25 deletions

View File

@ -156,10 +156,10 @@ class Auths(Handler):
authenticated = False # By default, all handlers needs authentication
def auths(self):
all = self._params.get('all', 'false') == 'true'
paramAll = self._params.get('all', 'false') == 'true'
for a in Authenticator.objects.all():
theType = a.getType()
if all or (theType.isCustom() is False and theType.typeType not in ('IP',)):
if paramAll or (theType.isCustom() is False and theType.typeType not in ('IP',)):
yield {
'authId': a.uuid,
'authSmallName': str(a.small_name),

View File

@ -344,7 +344,6 @@ class RegexLdap(auths.Authenticator):
def searchUsers(self, pattern):
try:
con = self.__connection()
res = []
for r in ldaputil.getAsDict(
con=self.__connection(),
@ -388,7 +387,7 @@ class RegexLdap(auths.Authenticator):
if len(con.search_ext_s(base=self._ldapBase, scope=ldap.SCOPE_SUBTREE, filterstr='(objectClass=%s)' % self._userClass, sizelimit=1)) == 1:
raise Exception()
return [False, _('Ldap user class seems to be incorrect (no user found by that class)')]
except Exception as e:
except Exception:
# If found 1 or more, all right
pass
@ -397,7 +396,7 @@ class RegexLdap(auths.Authenticator):
if len(con.search_ext_s(base=self._ldapBase, scope=ldap.SCOPE_SUBTREE, filterstr='(&(objectClass=%s)(%s=*))' % (self._userClass, self._userIdAttr), sizelimit=1)) == 1:
raise Exception()
return [False, _('Ldap user id attr is probably wrong (can\'t find any user with both conditions)')]
except Exception as e:
except Exception:
# If found 1 or more, all right
pass
@ -418,7 +417,7 @@ class RegexLdap(auths.Authenticator):
# Check validity of regular expression (try to compile it)
# this only right now
pass
except Exception as e:
except Exception:
pass
return [True, _("Connection params seem correct, test was succesfully executed")]

View File

@ -349,7 +349,7 @@ class SimpleLDAPAuthenticator(Authenticator):
if len(con.search_ext_s(base=self._ldapBase, scope=ldap.SCOPE_SUBTREE, filterstr='(objectClass=%s)' % self._userClass, sizelimit=1)) == 1:
raise Exception()
return [False, _('Ldap user class seems to be incorrect (no user found by that class)')]
except Exception as e:
except Exception:
# If found 1 or more, all right
pass
@ -359,7 +359,7 @@ class SimpleLDAPAuthenticator(Authenticator):
if len(con.search_ext_s(base=self._ldapBase, scope=ldap.SCOPE_SUBTREE, filterstr='(objectClass=%s)' % self._groupClass, sizelimit=1)) == 1:
raise Exception()
return [False, _('Ldap group class seems to be incorrect (no group found by that class)')]
except Exception as e:
except Exception:
# If found 1 or more, all right
pass
@ -369,7 +369,7 @@ class SimpleLDAPAuthenticator(Authenticator):
if len(con.search_ext_s(base=self._ldapBase, scope=ldap.SCOPE_SUBTREE, filterstr='(%s=*)' % self._userIdAttr, sizelimit=1)) == 1:
raise Exception()
return [False, _('Ldap user id attribute seems to be incorrect (no user found by that attribute)')]
except Exception as e:
except Exception:
# If found 1 or more, all right
pass
@ -379,7 +379,7 @@ class SimpleLDAPAuthenticator(Authenticator):
if len(con.search_ext_s(base=self._ldapBase, scope=ldap.SCOPE_SUBTREE, filterstr='(%s=*)' % self._groupIdAttr, sizelimit=1)) == 1:
raise Exception()
return [False, _('Ldap group id attribute seems to be incorrect (no group found by that attribute)')]
except Exception as e:
except Exception:
# If found 1 or more, all right
pass
@ -390,7 +390,7 @@ class SimpleLDAPAuthenticator(Authenticator):
if len(con.search_ext_s(base=self._ldapBase, scope=ldap.SCOPE_SUBTREE, filterstr='(&(objectClass=%s)(%s=*))' % (self._userClass, self._userIdAttr), sizelimit=1)) == 1:
raise Exception()
return [False, _('Ldap user class or user id attr is probably wrong (can\'t find any user with both conditions)')]
except Exception as e:
except Exception:
# If found 1 or more, all right
pass
@ -408,7 +408,7 @@ class SimpleLDAPAuthenticator(Authenticator):
break
if ok is False:
raise Exception(_('Can\'t locate any group with the membership attribute specified'))
except Exception as e:
except Exception:
return [False, six.text_type(e)]
logger.debug('LDAP group class and group id attr seems to be correct')

View File

@ -172,8 +172,8 @@ class StatsManager(object):
try:
# Replaces nulls for ''
def noneToEmpty(str):
return six.text_type(str) if str is not None else ''
def noneToEmpty(value):
return six.text_type(value) if value is not None else ''
fld1 = noneToEmpty(kwargs.get('fld1', kwargs.get('username', kwargs.get('platform', ''))))
fld2 = noneToEmpty(kwargs.get('fld2', kwargs.get('srcip', kwargs.get('browser', ''))))

View File

@ -6,6 +6,7 @@ from django.db import models, migrations
from uds.core.util.model import generateUuid
# noinspection PyUnusedLocal
def add_uuids(apps, schema_editor):
"""
Adds uuids values to migrated models
@ -19,6 +20,7 @@ def add_uuids(apps, schema_editor):
m.save()
# noinspection PyUnusedLocal
def remove_uuids(apps, schema_editor):
"""
Dummy function. uuid field will be dropped on reverse migration

View File

@ -4,6 +4,7 @@ from __future__ import unicode_literals
from django.db import models, migrations
# noinspection PyUnusedLocal
def add_parent_uuids(apps, schema_editor):
"""
Adds uuids values to migrated models
@ -22,6 +23,7 @@ def add_parent_uuids(apps, schema_editor):
m.save()
# noinspection PyUnusedLocal
def remove_parent_uuids(apps, schema_editor):
"""
Dummy function. uuid field will be dropped on reverse migration

View File

@ -183,7 +183,6 @@ class Authenticator(ManagedObjectModel, TaggingMixin):
"""
from uds.core.util.Config import GlobalConfig
auths = []
if tag is not None:
auths = Authenticator.objects.filter(small_name=tag).order_by('priority', 'name')
if auths.count() == 0:

View File

@ -101,7 +101,6 @@ class WinDomainOsManager(WindowsOsManager):
_str = "No servers found"
for server in servers:
_str = ''
try:
return ldaputil.connection(account, self._password, server[0], server[1], ssl=False, timeout=10, debug=False)
except Exception as e:

View File

@ -113,8 +113,6 @@ class WindowsOsManager(osmanagers.OSManager):
def notifyIp(self, uid, service, data):
si = service.getInstance()
ip = ''
ip = ''
# Notifies IP to deployed
for p in data['ips']:

View File

@ -82,6 +82,7 @@ def asList(element):
return element,
# noinspection PyShadowingNames
class OpenNebulaClient(object):
def __init__(self, username, password, endpoint):
self.username = username

View File

@ -60,7 +60,7 @@ def getMachineState(api, machineId):
# vm.info()
# return vm.state
return api.getVMState(machineId)
except Exception as e:
except Exception:
logger.error('Error obtaining machine state for {} on OpenNebula: {}'.format(machineId, e))
return VmState.UNKNOWN
@ -72,7 +72,7 @@ def getMachineSubstate(api, machineId):
"""
try:
return api.getVMSubState(machineId)
except Exception as e:
except Exception:
logger.error('Error obtaining machine state for {} on OpenNebula: {}'.format(machineId, e))
return VmState.UNKNOWN
@ -91,10 +91,11 @@ def startMachine(api, machineId):
"""
try:
api.VMAction(machineId, 'resume')
except Exception as e:
except Exception:
# MAybe the machine is already running. If we get error here, simply ignore it for now...
pass
def stopMachine(api, machineId):
"""
Tries to start a machine. No check is done, it is simply requested to OpenNebula
@ -106,7 +107,7 @@ def stopMachine(api, machineId):
"""
try:
api.VMAction(machineId, 'poweroff-hard')
except Exception as e:
except Exception:
logger.error('Error powering off {} on OpenNebula: {}'.format(machineId, e))
@ -121,7 +122,7 @@ def suspendMachine(api, machineId):
"""
try:
api.VMAction(machineId, 'suspend')
except Exception as e:
except Exception:
logger.error('Error suspending {} on OpenNebula: {}'.format(machineId, e))
@ -136,7 +137,7 @@ def resetMachine(api, machineId):
"""
try:
api.VMAction(machineId, 'reboot-hard')
except Exception as e:
except Exception:
logger.error('Error reseting {} on OpenNebula: {}'.format(machineId, e))
@ -153,7 +154,7 @@ def removeMachine(api, machineId):
# vm = oca.VirtualMachine.new_with_id(api, int(machineId))
# vm.delete()
api.deleteVM(machineId)
except Exception as e:
except Exception:
logger.exception('Error removing machine {} on OpenNebula: {}'.format(machineId, e))
raise 'Error removing machine {} on OpenNebula: {}'.format(machineId, e)