1
0
mirror of https://github.com/dkmstr/openuds.git synced 2025-01-03 01:17:56 +03:00

refactoring to camel_case, some minor fixes

This commit is contained in:
Adolfo Gómez García 2024-01-04 00:48:31 +01:00
parent 233d66921e
commit 494e24691b
No known key found for this signature in database
GPG Key ID: DD1ABF20724CDA23
57 changed files with 135 additions and 135 deletions

1
.gitignore vendored
View File

@ -13,6 +13,7 @@
*.debhelper*
*-stamp
*.substvars
.coverage*
# /client/administration/
/client/administration/*.suo

View File

@ -36,7 +36,7 @@ from uds import models
# Import for REST using this module can access constants easily
# pylint: disable=unused-import
from uds.core.util.log import LogLevel, LogSource, doLog
from uds.core.util.log import LogLevel, LogSource, log
if typing.TYPE_CHECKING:
from .handlers import Handler
@ -91,7 +91,7 @@ def logOperation(
path = replacePath(path)
username = handler.request.user.pretty_name if handler.request.user else 'Unknown'
doLog(
log(
None, # > None Objects goes to SYSLOG (global log)
level=level,
message=f'{handler.request.ip} [{username}]: [{handler.request.method}/{response_code}] {path}'[

View File

@ -712,7 +712,7 @@ class Log(ActorV3Action):
level = log.LogLevel.fromInt(int(self._params['level']) + 10000)
else:
level = log.LogLevel.fromInt(int(self._params['level']))
log.doLog(
log.log(
userService,
level,
self._params['message'],

View File

@ -112,7 +112,7 @@ class MetaServicesPool(DetailHandler):
else:
parent.members.create(pool=pool, priority=priority, enabled=enabled)
log.doLog(
log.log(
parent,
log.LogLevel.INFO,
("Added" if uuid is None else "Modified")
@ -129,7 +129,7 @@ class MetaServicesPool(DetailHandler):
member.delete()
log.doLog(parent, log.LogLevel.INFO, logStr, log.LogSource.ADMIN)
log.log(parent, log.LogLevel.INFO, logStr, log.LogSource.ADMIN)
class MetaAssignedService(DetailHandler):
@ -241,7 +241,7 @@ class MetaAssignedService(DetailHandler):
try:
asignedService = self._getAssignedService(parent, item)
logger.debug('Getting logs for %s', asignedService)
return log.getLogs(asignedService)
return log.get_logs(asignedService)
except Exception:
raise self.invalidItemException()
@ -267,7 +267,7 @@ class MetaAssignedService(DetailHandler):
else:
raise self.invalidItemException(_('Item is not removable'))
log.doLog(parent, log.LogLevel.INFO, logStr, log.LogSource.ADMIN)
log.log(parent, log.LogLevel.INFO, logStr, log.LogSource.ADMIN)
# Only owner is allowed to change right now
def saveItem(self, parent: 'Model', item: typing.Optional[str]):
@ -299,4 +299,4 @@ class MetaAssignedService(DetailHandler):
service.save()
# Log change
log.doLog(parent, log.LogLevel.INFO, logStr, log.LogSource.ADMIN)
log.log(parent, log.LogLevel.INFO, logStr, log.LogSource.ADMIN)

View File

@ -117,7 +117,7 @@ class AccessCalendars(DetailHandler):
calendar=calendar, access=access, priority=priority
)
log.doLog(
log.log(
parent,
log.LogLevel.INFO,
f'{"Added" if uuid is None else "Updated"} access calendar {calendar.name}/{access} by {self._user.pretty_name}',
@ -130,7 +130,7 @@ class AccessCalendars(DetailHandler):
logStr = f'Removed access calendar {calendarAccess.calendar.name} by {self._user.pretty_name}'
calendarAccess.delete()
log.doLog(parent, log.LogLevel.INFO, logStr, log.LogSource.ADMIN)
log.log(parent, log.LogLevel.INFO, logStr, log.LogSource.ADMIN)
class ActionsCalendars(DetailHandler):
@ -225,7 +225,7 @@ class ActionsCalendars(DetailHandler):
params=params,
)
log.doLog(parent, log.LogLevel.INFO, logStr, log.LogSource.ADMIN)
log.log(parent, log.LogLevel.INFO, logStr, log.LogSource.ADMIN)
def deleteItem(self, parent: 'Model', item: str) -> None:
parent = ensure.is_instance(parent, ServicePool)
@ -239,7 +239,7 @@ class ActionsCalendars(DetailHandler):
calendarAction.delete()
log.doLog(parent, log.LogLevel.INFO, logStr, log.LogSource.ADMIN)
log.log(parent, log.LogLevel.INFO, logStr, log.LogSource.ADMIN)
def execute(self, parent: 'Model', item: str):
parent = ensure.is_instance(parent, ServicePool)
@ -255,7 +255,7 @@ class ActionsCalendars(DetailHandler):
f'{calendarAction.params}" by {self._user.pretty_name}'
)
log.doLog(parent, log.LogLevel.INFO, logStr, log.LogSource.ADMIN)
log.log(parent, log.LogLevel.INFO, logStr, log.LogSource.ADMIN)
calendarAction.execute()
return self.success()

View File

@ -332,7 +332,7 @@ class Services(DetailHandler): # pylint: disable=too-many-public-methods
try:
service = parent.services.get(uuid=processUuid(item))
logger.debug('Getting logs for %s', item)
return log.getLogs(service)
return log.get_logs(service)
except Exception:
raise self.invalidItemException() from None

View File

@ -602,7 +602,7 @@ class ServicesPools(ModelHandler):
def getLogs(self, item: 'Model') -> list[dict]:
item = ensure.is_instance(item, ServicePool)
try:
return log.getLogs(item)
return log.get_logs(item)
except Exception:
return []

View File

@ -105,8 +105,8 @@ class TunnelTicket(Handler):
now = sql_stamp_seconds()
totalTime = now - extra.get('b', now - 1)
msg = f'User {user.name} stopped tunnel {extra.get("t", "")[:8]}... to {host}:{port}: u:{sent}/d:{recv}/t:{totalTime}.'
log.doLog(user.manager, log.LogLevel.INFO, msg)
log.doLog(userService, log.LogLevel.INFO, msg)
log.log(user.manager, log.LogLevel.INFO, msg)
log.log(userService, log.LogLevel.INFO, msg)
# Try to log Close event
try:
@ -134,8 +134,8 @@ class TunnelTicket(Handler):
tunnel=self._args[0],
)
msg = f'User {user.name} started tunnel {self._args[0][:8]}... to {host}:{port} from {self._args[1]}.'
log.doLog(user.manager, log.LogLevel.INFO, msg)
log.doLog(userService, log.LogLevel.INFO, msg)
log.log(user.manager, log.LogLevel.INFO, msg)
log.log(userService, log.LogLevel.INFO, msg)
# Generate new, notify only, ticket
notifyTicket = models.TicketStore.create_for_tunnel(
userService=userService,

View File

@ -183,7 +183,7 @@ class AssignedService(DetailHandler):
try:
userService: models.UserService = parent.assignedUserServices().get(uuid=processUuid(item))
logger.debug('Getting logs for %s', userService)
return log.getLogs(userService)
return log.get_logs(userService)
except Exception as e:
raise self.invalidItemException() from e
@ -210,7 +210,7 @@ class AssignedService(DetailHandler):
else:
raise self.invalidItemException(_('Item is not removable'))
log.doLog(parent, log.LogLevel.INFO, logStr, log.LogSource.ADMIN)
log.log(parent, log.LogLevel.INFO, logStr, log.LogSource.ADMIN)
# Only owner is allowed to change right now
def saveItem(self, parent: 'Model', item: typing.Optional[str]) -> None:
@ -239,7 +239,7 @@ class AssignedService(DetailHandler):
userService.save()
# Log change
log.doLog(parent, log.LogLevel.INFO, logStr, log.LogSource.ADMIN)
log.log(parent, log.LogLevel.INFO, logStr, log.LogSource.ADMIN)
def reset(self, parent: 'models.ServicePool', item: str) -> typing.Any:
userService = parent.userServices.get(uuid=processUuid(item))
@ -296,7 +296,7 @@ class CachedService(AssignedService):
try:
userService = parent.cachedUserServices().get(uuid=processUuid(item))
logger.debug('Getting logs for %s', item)
return log.getLogs(userService)
return log.get_logs(userService)
except Exception:
raise self.invalidItemException() from None
@ -359,7 +359,7 @@ class Groups(DetailHandler):
parent = ensure.is_instance(parent, models.ServicePool)
group: models.Group = models.Group.objects.get(uuid=processUuid(self._params['id']))
parent.assignedGroups.add(group)
log.doLog(
log.log(
parent,
log.LogLevel.INFO,
f'Added group {group.pretty_name} by {self._user.pretty_name}',
@ -370,7 +370,7 @@ class Groups(DetailHandler):
parent = ensure.is_instance(parent, models.ServicePool)
group: models.Group = models.Group.objects.get(uuid=processUuid(self._args[0]))
parent.assignedGroups.remove(group)
log.doLog(
log.log(
parent,
log.LogLevel.INFO,
f'Removed group {group.pretty_name} by {self._user.pretty_name}',
@ -420,7 +420,7 @@ class Transports(DetailHandler):
parent = ensure.is_instance(parent, models.ServicePool)
transport: models.Transport = models.Transport.objects.get(uuid=processUuid(self._params['id']))
parent.transports.add(transport)
log.doLog(
log.log(
parent,
log.LogLevel.INFO,
f'Added transport {transport.name} by {self._user.pretty_name}',
@ -431,7 +431,7 @@ class Transports(DetailHandler):
parent = ensure.is_instance(parent, models.ServicePool)
transport: models.Transport = models.Transport.objects.get(uuid=processUuid(self._args[0]))
parent.transports.remove(transport)
log.doLog(
log.log(
parent,
log.LogLevel.INFO,
f'Removed transport {transport.name} by {self._user.pretty_name}',
@ -464,7 +464,7 @@ class Publications(DetailHandler):
logger.debug('Custom "publish" invoked for %s', parent)
parent.publish(changeLog) # Can raise exceptions that will be processed on response
log.doLog(
log.log(
parent,
log.LogLevel.INFO,
f'Initiated publication v{parent.current_pub_revision} by {self._user.pretty_name}',
@ -494,7 +494,7 @@ class Publications(DetailHandler):
except Exception as e:
raise ResponseError(str(e)) from e
log.doLog(
log.log(
parent,
log.LogLevel.INFO,
f'Canceled publication v{parent.current_pub_revision} by {self._user.pretty_name}',

View File

@ -191,7 +191,7 @@ class Users(DetailHandler):
except Exception:
raise self.invalidItemException() from None
return log.getLogs(user)
return log.get_logs(user)
def saveItem(self, parent: 'Model', item):
parent = ensure.is_instance(parent, Authenticator)

View File

@ -787,7 +787,7 @@ class ModelHandler(BaseModelHandler):
def getLogs(self, item: models.Model) -> list[dict]:
self.ensureAccess(item, types.permissions.PermissionType.READ)
try:
return log.getLogs(item)
return log.get_logs(item)
except Exception as e:
logger.warning('Exception getting logs for %s: %s', item, e)
return []

View File

@ -538,7 +538,7 @@ def authenticate_log_login(
)
)
level = log.LogLevel.INFO if logStr == 'Logged in' else log.LogLevel.ERROR
log.doLog(
log.log(
authenticator,
level,
f'user {userName} has {logStr} from {request.ip} where os is {request.os.os.name}',
@ -548,7 +548,7 @@ def authenticate_log_login(
try:
# Root user is not on any authenticator, so we cannot attach log to an db user
user = authenticator.users.get(name=userName)
log.doLog(
log.log(
user,
level,
f'{logStr} from {request.ip} where OS is {request.os.os.name}',
@ -561,12 +561,12 @@ def authenticate_log_login(
def auth_log_logout(request: 'ExtendedHttpRequest') -> None:
if request.user:
if request.user.manager.id is not None:
log.doLog(
log.log(
request.user.manager,
log.LogLevel.INFO,
f'user {request.user.name} has logged out from {request.ip}',
log.LogSource.WEB,
)
log.doLog(request.user, log.LogLevel.INFO, f'has logged out from {request.ip}', log.LogSource.WEB)
log.log(request.user, log.LogLevel.INFO, f'has logged out from {request.ip}', log.LogSource.WEB)
else:
logger.info('Root has logged out from %s', request.ip)

View File

@ -342,7 +342,7 @@ class PublicationManager(metaclass=singleton.Singleton):
if publication.state not in State.PUBLISH_STATES:
if publication.state == State.CANCELING: # Double cancel
logger.info('Double cancel invoked for a publication')
log.doLog(
log.log(
publication.deployed_service,
log.LogLevel.WARNING,
'Forced cancel on publication, you must check uncleaned resources manually',

View File

@ -49,14 +49,14 @@ def process_log(server: 'models.Server', data: dict[str, typing.Any]) -> typing.
if data.get('userservice_uuid', None): # Log for an user service
try:
userService = models.UserService.objects.get(uuid=data['userservice_uuid'])
log.doLog(
log.log(
userService, log.LogLevel.fromStr(data['level']), data['message'], source=log.LogSource.SERVER
)
return rest_result(consts.OK)
except models.UserService.DoesNotExist:
pass # If not found, log on server
log.doLog(server, log.LogLevel.fromStr(data['level']), data['message'], source=log.LogSource.SERVER)
log.log(server, log.LogLevel.fromStr(data['level']), data['message'], source=log.LogSource.SERVER)
return rest_result(consts.OK)

View File

@ -511,7 +511,7 @@ class UserServiceManager(metaclass=singleton.Singleton):
if (
inAssigned >= servicePool.max_srvs
): # cacheUpdater will drop unnecesary L1 machines, so it's not neccesary to check against inCacheL1
log.doLog(
log.log(
servicePool,
log.LogLevel.WARNING,
f'Max number of services reached: {servicePool.max_srvs}',
@ -786,7 +786,7 @@ class UserServiceManager(metaclass=singleton.Singleton):
# Test if the service is ready
if userService.isReady():
serviceNotReadyCode = 0x0002
log.doLog(
log.log(
userService,
log.LogLevel.INFO,
f"User {user.pretty_name} from {srcIp} has initiated access",
@ -800,7 +800,7 @@ class UserServiceManager(metaclass=singleton.Singleton):
if self.checkUuid(userService) is False: # The service is not the expected one
serviceNotReadyCode = 0x0004
log.doLog(
log.log(
userService,
log.LogLevel.WARNING,
f'User service is not accessible due to invalid UUID (user: {user.pretty_name}, ip: {ip})',
@ -820,7 +820,7 @@ class UserServiceManager(metaclass=singleton.Singleton):
serviceNotReadyCode = 0x0003
transportInstance = transport.get_instance()
if transportInstance.isAvailableFor(userService, ip):
log.doLog(userService, log.LogLevel.INFO, "User service ready", log.LogSource.WEB)
log.log(userService, log.LogLevel.INFO, "User service ready", log.LogSource.WEB)
self.notifyPreconnect(
userService,
transportInstance.getConnectionInfo(userService, user, ''),
@ -841,7 +841,7 @@ class UserServiceManager(metaclass=singleton.Singleton):
)
message = transportInstance.getCustomAvailableErrorMsg(userService, ip)
log.doLog(userService, log.LogLevel.WARNING, message, log.LogSource.TRANSPORT)
log.log(userService, log.LogLevel.WARNING, message, log.LogSource.TRANSPORT)
logger.debug(
'Transport is not ready for user service %s: %s',
userService,
@ -850,7 +850,7 @@ class UserServiceManager(metaclass=singleton.Singleton):
else:
logger.debug('Ip not available from user service %s', userService)
else:
log.doLog(
log.log(
userService,
log.LogLevel.WARNING,
f'User {user.pretty_name} from {srcIp} tried to access, but service was not ready',
@ -1042,7 +1042,7 @@ class UserServiceManager(metaclass=singleton.Singleton):
)
usable = None
log.doLog(
log.log(
meta,
log.LogLevel.WARNING,
f'No user service accessible from device (ip {srcIp}, os: {os.os.name})',

View File

@ -66,7 +66,7 @@ class StateUpdater:
logger.error('Got error on processor: %s', msg)
self.save(State.ERROR)
if msg is not None:
log.doLog(self.userService, log.LogLevel.ERROR, msg, log.LogSource.INTERNAL)
log.log(self.userService, log.LogLevel.ERROR, msg, log.LogSource.INTERNAL)
def save(self, newState: typing.Optional[str] = None):
if newState:
@ -249,7 +249,7 @@ class UserServiceOpChecker(DelayedTask):
except Exception as e:
logger.exception('Checking service state')
log.doLog(userService, log.LogLevel.ERROR, f'Exception: {e}', log.LogSource.INTERNAL)
log.log(userService, log.LogLevel.ERROR, f'Exception: {e}', log.LogSource.INTERNAL)
userService.setState(State.ERROR)
userService.save(update_fields=['data'])
@ -288,7 +288,7 @@ class UserServiceOpChecker(DelayedTask):
# Exception caught, mark service as errored
logger.exception("Error %s, %s :", e.__class__, e)
if uService:
log.doLog(uService, log.LogLevel.ERROR, f'Exception: {e}', log.LogSource.INTERNAL)
log.log(uService, log.LogLevel.ERROR, f'Exception: {e}', log.LogSource.INTERNAL)
try:
uService.setState(State.ERROR)
uService.save(update_fields=['data'])

View File

@ -259,14 +259,14 @@ class OSManager(Module):
fld4=fullUserName,
)
log.doLog(
log.log(
userService,
log.LogLevel.INFO,
f'User {userName} has logged in',
log.LogSource.OSMANAGER,
)
log.useLog(
log.log_use(
'login',
uniqueId,
serviceIp,
@ -323,14 +323,14 @@ class OSManager(Module):
fld4=fullUserName,
)
log.doLog(
log.log(
userService,
log.LogLevel.INFO,
f'User {userName} has logged out',
log.LogSource.OSMANAGER,
)
log.useLog(
log.log_use(
'logout',
uniqueId,
serviceIp,

View File

@ -220,14 +220,14 @@ class ServiceProvider(module.Module):
val = getattr(val, 'value', val)
return val is True or val == consts.TRUE_STR
def doLog(self, level: log.LogLevel, message: str) -> None:
def do_log(self, level: log.LogLevel, message: str) -> None:
"""
Logs a message with requested level associated with this service
"""
from uds.models import Provider as DBProvider # pylint: disable=import-outside-toplevel
if self.getUuid():
log.doLog(DBProvider.objects.get(uuid=self.getUuid()), level, message, log.LogSource.SERVICE)
log.log(DBProvider.objects.get(uuid=self.getUuid()), level, message, log.LogSource.SERVICE)
def __str__(self):
"""

View File

@ -466,14 +466,14 @@ class Service(Module):
"""
return False
def doLog(self, level: log.LogLevel, message: str) -> None:
def do_log(self, level: log.LogLevel, message: str) -> None:
"""
Logs a message with requested level associated with this service
"""
from uds.models import Service as DBService # pylint: disable=import-outside-toplevel
if self.getUuid():
log.doLog(DBService.objects.get(uuid=self.getUuid()), level, message, log.LogSource.SERVICE)
log.log(DBService.objects.get(uuid=self.getUuid()), level, message, log.LogSource.SERVICE)
@classmethod
def canAssign(cls) -> bool:

View File

@ -225,12 +225,12 @@ class UserService(Environmentable, Serializable):
def getUuid(self) -> str:
return self._uuid
def doLog(self, level: log.LogLevel, message: str) -> None:
def do_log(self, level: log.LogLevel, message: str) -> None:
"""
Logs a message with requested level associated with this user deployment
"""
if self._dbObj:
log.doLog(self._dbObj, level, message, log.LogSource.SERVICE)
log.log(self._dbObj, level, message, log.LogSource.SERVICE)
def macGenerator(self) -> 'UniqueMacGenerator':
"""

View File

@ -132,7 +132,7 @@ class LogSource(enum.StrEnum):
LOGS = 'logs'
def useLog(
def log_use(
type_: str,
serviceUniqueId: str,
serviceIp: str,
@ -174,7 +174,7 @@ def useLog(
# Will be stored on database by UDSLogHandler
def doLog(
def log(
wichObject: typing.Optional['Model'],
level: LogLevel,
message: str,
@ -187,7 +187,7 @@ def doLog(
LogManager.manager().log(wichObject, level, message, source, logName)
def getLogs(wichObject: typing.Optional['Model'], limit: int = -1) -> list[dict]:
def get_logs(wichObject: typing.Optional['Model'], limit: int = -1) -> list[dict]:
"""
Get the logs associated with "wichObject", limiting to "limit" (default is GlobalConfig.MAX_LOGS_PER_ELEMENT)
"""
@ -197,7 +197,7 @@ def getLogs(wichObject: typing.Optional['Model'], limit: int = -1) -> list[dict]
return LogManager().get_logs(wichObject, limit)
def clearLogs(wichObject: typing.Optional['Model']) -> None:
def clear_logs(wichObject: typing.Optional['Model']) -> None:
"""
Clears the logs associated with the object using the logManager
"""
@ -220,7 +220,7 @@ class UDSLogHandler(logging.handlers.RotatingFileHandler):
# pylint: disable=import-outside-toplevel
from uds.core.managers.notifications import NotificationsManager
def formatMessage(*, clearLevel: bool) -> str:
def _format_msg(*, clearLevel: bool) -> str:
msg = self.format(record)
# Remove date and time from message, as it will be stored on database
msg = DATETIME_PATTERN.sub('', msg)
@ -238,11 +238,11 @@ class UDSLogHandler(logging.handlers.RotatingFileHandler):
logLevel = LogLevel.fromLoggingLevel(record.levelno)
UDSLogHandler.emiting = True
identificator = os.path.basename(self.baseFilename)
msg = formatMessage(clearLevel=True)
msg = _format_msg(clearLevel=True)
if record.levelno >= logging.WARNING:
# Remove traceback from message, as it will be stored on database
notify(msg.splitlines()[0], identificator, logLevel)
doLog(None, logLevel, msg, LogSource.LOGS, identificator)
log(None, logLevel, msg, LogSource.LOGS, identificator)
except Exception: # nosec: If cannot log, just ignore it
pass
finally:
@ -250,7 +250,7 @@ class UDSLogHandler(logging.handlers.RotatingFileHandler):
# Send warning and error messages to systemd journal
if record.levelno >= logging.WARNING:
msg = formatMessage(clearLevel=False)
msg = _format_msg(clearLevel=False)
# Send to systemd journaling, transforming identificator and priority
identificator = 'UDS-' + os.path.basename(self.baseFilename).split('.')[0]
# convert syslog level to systemd priority

View File

@ -97,26 +97,26 @@ class HangedCleaner(Job):
if (
us.state in [State.REMOVING, State.CANCELING]
): # Removing too long, remark it as removable
log.doLog(
log.log(
us,
log.LogLevel.ERROR,
'User Service hanged on removal process. Restarting removal.',
log.LogSource.INTERNAL,
)
log.doLog(
log.log(
servicePool,
log.LogLevel.ERROR,
f'User service {us.friendly_name} hanged on removal. Restarting removal.',
)
us.release() # Mark it again as removable, and let's see
else:
log.doLog(
log.log(
us,
log.LogLevel.ERROR,
'User Service seems to be hanged. Removing it.',
log.LogSource.INTERNAL,
)
log.doLog(
log.log(
servicePool,
log.LogLevel.ERROR,
f'Removing user service {us.friendly_name} because it seems to be hanged'

View File

@ -63,7 +63,7 @@ class ServiceCacheUpdater(Job):
@staticmethod
def __notifyRestrain(servicePool) -> None:
log.doLog(
log.log(
servicePool,
log.LogLevel.WARNING,
'Service Pool is restrained due to excesive errors',
@ -241,7 +241,7 @@ class ServiceCacheUpdater(Job):
services.UserService.L1_CACHE,
)
except MaxServicesReachedError:
log.doLog(
log.log(
servicePool,
log.LogLevel.ERROR,
'Max number of services reached for this service',

View File

@ -94,7 +94,7 @@ class StuckCleaner(Job):
# logger.debug('Searching for stuck states for %s', servicePool.name)
for stuck in stuckUserServices(servicePool):
logger.debug('Found stuck user service %s', stuck)
log.doLog(
log.log(
servicePool,
log.LogLevel.ERROR,
f'User service {stuck.name} has been hard removed because it\'s stuck',

View File

@ -90,8 +90,8 @@ def guacamole(request: ExtendedHttpRequestWithUser, token: str, tunnelId: str) -
protocol = 'RDS' if 'remote-app' in val else val['protocol'].upper()
host = val.get('hostname', '0.0.0.0') # nosec: Not a bind, just a placeholder for "no host"
msg = f'User {user.name} started HTML5 {protocol} tunnel to {host}.'
log.doLog(user.manager, log.LogLevel.INFO, msg)
log.doLog(userService, log.LogLevel.INFO, msg)
log.log(user.manager, log.LogLevel.INFO, msg)
log.log(userService, log.LogLevel.INFO, msg)
events.addEvent(
userService.deployed_service,

View File

@ -154,7 +154,7 @@ class Command(BaseCommand):
for item in fltr[:max_items]: # at most max_items items
logs = [
f'{l["date"]}: {log.LogLevel.fromStr(l["level"])} [{l["source"]}] - {l["message"]}'
for l in log.getLogs(item)
for l in log.get_logs(item)
]
userServices[item.friendly_name] = {
'_': {

View File

@ -295,7 +295,7 @@ class Authenticator(ManagedObjectModel, TaggingMixin):
s.env.clearRelatedData()
# Clears related logs
log.clearLogs(toDelete)
log.clear_logs(toDelete)
# Clears related permissions
clean(toDelete)

View File

@ -123,7 +123,7 @@ class Group(UUIDModel):
to_delete.getManager().remove_group(to_delete.name)
# Clears related logs
log.clearLogs(to_delete)
log.clear_logs(to_delete)
logger.debug('Deleted group %s', to_delete)

View File

@ -275,7 +275,7 @@ class MetaPool(UUIDModel, TaggingMixin): # type: ignore
toDelete: 'MetaPool' = kwargs['instance']
# Clears related logs
log.clearLogs(toDelete)
log.clear_logs(toDelete)
# Clears related permissions
clean(toDelete)

View File

@ -124,7 +124,7 @@ class Provider(ManagedObjectModel, TaggingMixin): # type: ignore
s.env.clearRelatedData()
# Clears related logs
log.clearLogs(to_delete)
log.clear_logs(to_delete)
# Clears related permissions
clean(to_delete)

View File

@ -223,7 +223,7 @@ class Service(ManagedObjectModel, TaggingMixin): # type: ignore
s.env.clearRelatedData()
# Clears related logs
log.clearLogs(to_delete)
log.clear_logs(to_delete)
# Clears related permissions
clean(to_delete)

View File

@ -655,7 +655,7 @@ class ServicePool(UUIDModel, TaggingMixin): # type: ignore
# Utility for logging
def log(self, message: str, level: log.LogLevel = log.LogLevel.INFO) -> None:
log.doLog(self, level, message, log.LogSource.INTERNAL)
log.log(self, level, message, log.LogSource.INTERNAL)
@staticmethod
def pre_delete(sender, **kwargs) -> None: # pylint: disable=unused-argument
@ -677,7 +677,7 @@ class ServicePool(UUIDModel, TaggingMixin): # type: ignore
toDelete.get_environment().clearRelatedData()
# Clears related logs
log.clearLogs(toDelete)
log.clear_logs(toDelete)
# Clears related permissions
clean(toDelete)

View File

@ -217,7 +217,7 @@ class ServicePoolPublication(UUIDModel):
# It's handled as "publish", and as so, it can be a multi-step process
# Clears related logs
log.clearLogs(to_delete)
log.clear_logs(to_delete)
logger.debug('Deleted publication %s', to_delete)

View File

@ -252,7 +252,7 @@ class User(UUIDModel, properties.PropertiesMixin):
User.objects.filter(parent=to_delete.id).delete()
# Remove related logs
log.clearLogs(to_delete)
log.clear_logs(to_delete)
# Removes all user services assigned to this user (unassign it and mark for removal)
for us in to_delete.userServices.all():

View File

@ -604,7 +604,7 @@ class UserService(UUIDModel, properties.PropertiesMixin):
# Utility for logging
def log(self, message: str, level: log.LogLevel = log.LogLevel.INFO) -> None:
log.doLog(self, level, message, log.LogSource.INTERNAL)
log.log(self, level, message, log.LogSource.INTERNAL)
def testServer(self, host, port, timeout=4) -> bool:
return self.deployed_service.testServer(host, port, timeout)
@ -635,7 +635,7 @@ class UserService(UUIDModel, properties.PropertiesMixin):
to_delete.closeSession('')
# Clear related logs to this user service
log.clearLogs(to_delete)
log.clear_logs(to_delete)
logger.debug('Deleted user service %s', to_delete)

View File

@ -137,7 +137,7 @@ class LinuxOsManager(osmanagers.OSManager):
"""
return service.getName()
def doLog(self, service: 'UserService', data, origin=log.LogSource.OSMANAGER) -> None:
def do_log(self, service: 'UserService', data, origin=log.LogSource.OSMANAGER) -> None:
# Stores a log associated with this service
try:
msg, slevel = data.split('\t')
@ -146,9 +146,9 @@ class LinuxOsManager(osmanagers.OSManager):
except Exception:
logger.debug('Do not understand level %s', slevel)
level = log.LogLevel.INFO
log.doLog(service, level, msg, origin)
log.log(service, level, msg, origin)
except Exception:
log.doLog(service, log.LogLevel.ERROR, f'do not understand {data}', origin)
log.log(service, log.LogLevel.ERROR, f'do not understand {data}', origin)
def actorData(
self, userService: 'UserService'
@ -161,7 +161,7 @@ class LinuxOsManager(osmanagers.OSManager):
This function can update userService values. Normal operation will be remove machines if this state is not valid
"""
if self.isRemovableOnLogout(userService):
log.doLog(
log.log(
userService,
log.LogLevel.INFO,
'Unused user service for too long. Removing due to OS Manager parameters.',

View File

@ -100,7 +100,7 @@ class LinuxRandomPassManager(LinuxOsManager):
for _ in range(16)
)
service.storeValue('linOsRandomPass', randomPass)
log.doLog(
log.log(
service,
log.LogLevel.INFO,
f'Password set to "{randomPass}"',

View File

@ -109,7 +109,7 @@ class TestOSManager(osmanagers.OSManager):
"""
return userService.getName()
def doLog(self, service: 'UserService', data, origin=log.LogSource.OSMANAGER) -> None:
def do_log(self, service: 'UserService', data, origin=log.LogSource.OSMANAGER) -> None:
# Stores a log associated with this service
try:
msg, slevel = data.split('\t')
@ -118,9 +118,9 @@ class TestOSManager(osmanagers.OSManager):
except Exception:
logger.debug('Do not understand level %s', slevel)
level = log.LogLevel.INFO
log.doLog(service, level, msg, origin)
log.log(service, level, msg, origin)
except Exception:
log.doLog(service, log.LogLevel.ERROR, f'do not understand {data}', origin)
log.log(service, log.LogLevel.ERROR, f'do not understand {data}', origin)
def actorData(
self, userService: 'UserService'
@ -133,7 +133,7 @@ class TestOSManager(osmanagers.OSManager):
This function can update userService values. Normal operation will be remove machines if this state is not valid
"""
if self.isRemovableOnLogout(userService):
log.doLog(
log.log(
userService,
log.LogLevel.INFO,
'Unused user service for too long. Removing due to OS Manager parameters.',

View File

@ -143,7 +143,7 @@ class WindowsOsManager(osmanagers.OSManager):
def getName(self, userService: 'UserService') -> str:
return userService.getName()
def doLog(self, userService: 'UserService', data: str, origin=log.LogSource.OSMANAGER):
def do_log(self, userService: 'UserService', data: str, origin=log.LogSource.OSMANAGER):
# Stores a log associated with this service
try:
msg, levelStr = data.split('\t')
@ -153,10 +153,10 @@ class WindowsOsManager(osmanagers.OSManager):
logger.debug('Do not understand level %s', levelStr)
level = log.LogLevel.INFO
log.doLog(userService, level, msg, origin)
log.log(userService, level, msg, origin)
except Exception:
logger.exception('WindowsOs Manager message log: ')
log.doLog(
log.log(
userService, log.LogLevel.ERROR, f'do not understand {data}', origin
)
@ -192,7 +192,7 @@ class WindowsOsManager(osmanagers.OSManager):
This function can update userService values. Normal operation will be remove machines if this state is not valid
"""
if self.isRemovableOnLogout(userService):
log.doLog(
log.log(
userService,
log.LogLevel.INFO,
'Unused user service for too long. Removing due to OS Manager parameters.',

View File

@ -296,7 +296,7 @@ class WinDomainOsManager(WindowsOsManager):
break
except dns.resolver.NXDOMAIN: # No domain found, log it and pass
logger.warning('Could not find _ldap._tcp.%s', self._domain)
log.doLog(
log.log(
userService,
log.LogLevel.WARNING,
f'Could not remove machine from domain (_ldap._tcp.{self._domain} not found)',
@ -314,7 +314,7 @@ class WinDomainOsManager(WindowsOsManager):
# logger.exception('Ldap Exception caught')
if error:
log.doLog(userService, log.LogLevel.WARNING, error, log.LogSource.OSMANAGER)
log.log(userService, log.LogLevel.WARNING, error, log.LogSource.OSMANAGER)
logger.error(error)
def release(self, userService: 'UserService') -> None:
@ -326,7 +326,7 @@ class WinDomainOsManager(WindowsOsManager):
if '.' not in self._domain:
# logger.info('Releasing from a not FQDN domain is not supported')
log.doLog(
log.log(
userService,
log.LogLevel.INFO,
"Removing a domain machine form a non FQDN domain is not supported.",
@ -338,7 +338,7 @@ class WinDomainOsManager(WindowsOsManager):
ldapConnection = self.__connectLdap()
except dns.resolver.NXDOMAIN: # No domain found, log it and pass
logger.warning('Could not find _ldap._tcp.%s', self._domain)
log.doLog(
log.log(
userService,
log.LogLevel.WARNING,
f'Could not remove machine from domain (_ldap._tcp.{self._domain} not found)',
@ -347,7 +347,7 @@ class WinDomainOsManager(WindowsOsManager):
return
except ldaputil.LDAPError as e:
# logger.exception('Ldap Exception caught')
log.doLog(
log.log(
userService,
log.LogLevel.WARNING,
f'Could not remove machine from domain ({e})',
@ -356,7 +356,7 @@ class WinDomainOsManager(WindowsOsManager):
return
except Exception as e:
# logger.exception('Exception caught')
log.doLog(
log.log(
userService,
log.LogLevel.WARNING,
f'Could not remove machine from domain ({e})',

View File

@ -116,7 +116,7 @@ class WinRandomPassManager(WindowsOsManager):
pos = rnd.randrange(0, len(randomPass))
randomPass = randomPass[:pos] + base + randomPass[pos:]
userService.storeValue('winOsRandomPass', randomPass)
log.doLog(
log.log(
userService,
log.LogLevel.INFO,
f'Password set to "{randomPass}"',

View File

@ -219,7 +219,7 @@ class OVirtLinkedDeployment(services.UserService):
self.cache.put('ready', '1')
except Exception as e:
self.doLog(log.LogLevel.ERROR, f'Error on setReady: {e}')
self.do_log(log.LogLevel.ERROR, f'Error on setReady: {e}')
# Treat as operation done, maybe the machine is ready and we can continue
return State.FINISHED
@ -336,7 +336,7 @@ if sys.platform == 'win32':
"""
reason = str(reason)
logger.debug('Setting error state, reason: %s', reason)
self.doLog(log.LogLevel.ERROR, reason)
self.do_log(log.LogLevel.ERROR, reason)
if self._vmid != '': # Powers off
OVirtDeferredRemoval.remove(self.service().parent(), self._vmid)

View File

@ -116,7 +116,7 @@ class OVirtDeferredRemoval(jobs.Job):
# It this is reached, remove check
storage.remove('tr' + vmId)
except Exception as e: # Any other exception wil be threated again
# instance.doLog('Delayed removal of %s has failed: %s. Will retry later', vmId, e)
# instance.log('Delayed removal of %s has failed: %s. Will retry later', vmId, e)
logger.error('Delayed removal of %s failed: %s', i, e)
logger.debug('Deferred removal finished')

View File

@ -227,7 +227,7 @@ class OGDeployment(services.UserService):
State.ERROR, so we can do "return self.__error(reason)"
"""
logger.debug('Setting error state, reason: %s', reason)
self.doLog(log.LogLevel.ERROR, reason)
self.do_log(log.LogLevel.ERROR, reason)
if self._machineId:
try:
@ -309,7 +309,7 @@ class OGDeployment(services.UserService):
self._ip = r['ip']
self._stamp = sql_stamp_seconds()
self.doLog(
self.do_log(
log.LogLevel.INFO,
f'Reserved machine {self._name}: id: {self._machineId}, mac: {self._mac}, ip: {self._ip}',
)

View File

@ -142,7 +142,7 @@ class LiveDeployment(services.UserService): # pylint: disable=too-many-public-m
self.cache.put('ready', '1')
except Exception as e:
self.doLog(log.LogLevel.ERROR, 'Error on setReady: {}'.format(e))
self.do_log(log.LogLevel.ERROR, 'Error on setReady: {}'.format(e))
# Treat as operation done, maybe the machine is ready and we can continue
return State.FINISHED
@ -243,7 +243,7 @@ class LiveDeployment(services.UserService): # pylint: disable=too-many-public-m
"""
reason = str(reason)
logger.debug('Setting error state, reason: %s', reason)
self.doLog(log.LogLevel.ERROR, reason)
self.do_log(log.LogLevel.ERROR, reason)
if self._vmid: # Powers off & delete it
try:

View File

@ -158,7 +158,7 @@ class LiveDeployment(services.UserService): # pylint: disable=too-many-public-m
self.cache.put('ready', '1')
except Exception as e:
self.doLog(log.LogLevel.ERROR, 'Error on setReady: {}'.format(e))
self.do_log(log.LogLevel.ERROR, 'Error on setReady: {}'.format(e))
# Treat as operation done, maybe the machine is ready and we can continue
return State.FINISHED
@ -248,7 +248,7 @@ class LiveDeployment(services.UserService): # pylint: disable=too-many-public-m
self._queue = [opError]
self._reason = str(reason)
self.doLog(log.LogLevel.ERROR, self._reason)
self.do_log(log.LogLevel.ERROR, self._reason)
if self._vmid: # Powers off & delete it
try:

View File

@ -86,7 +86,7 @@ class IPMachineDeployed(services.UserService, AutoAttributes):
res = dns.resolver.resolve(ip, 'AAAA')
ip = typing.cast(str, res[0].address) # type: ignore # If no address, it will raise an exception
except Exception as e:
self.service().parent().doLog(
self.service().parent().do_log(
log.LogLevel.WARNING, f'User service could not resolve Name {ip} ({e}).'
)

View File

@ -145,7 +145,7 @@ class PhysicalMachinesProvider(services.ServiceProvider):
res = dns.resolver.resolve(ip, 'AAAA')
ip = res[0].address
except Exception as e:
self.doLog(log.LogLevel.WARNING, f'Name {ip} could not be resolved')
self.do_log(log.LogLevel.WARNING, f'Name {ip} could not be resolved')
logger.warning('Name %s could not be resolved (%s)', ip, e)
return ''

View File

@ -287,7 +287,7 @@ class IPMachinesService(IPServiceBase):
if self._port > 0 and not wolENABLED: # If configured WOL, check is a nonsense
if net.testConnection(theIP, self._port, timeOut=0.5) is False:
# Log into logs of provider, so it can be "shown" on services logs
self.parent().doLog(
self.parent().do_log(
log.LogLevel.WARNING,
f'Host {theIP} not accesible on port {self._port}',
)

View File

@ -298,7 +298,7 @@ if sys.platform == 'win32':
"""
reason = str(reason)
logger.debug('Setting error state, reason: %s', reason)
self.doLog(log.LogLevel.ERROR, reason)
self.do_log(log.LogLevel.ERROR, reason)
if self._vmid != '': # Powers off
ProxmoxDeferredRemoval.remove(self.service().parent(), int(self._vmid))
@ -532,7 +532,7 @@ if sys.platform == 'win32':
logger.debug('State is running')
if sql_stamp_seconds() - shutdown_start > GUEST_SHUTDOWN_WAIT:
logger.debug('Time is consumed, falling back to stop')
self.doLog(
self.do_log(
log.LogLevel.ERROR,
f'Could not shutdown machine using soft power off in time ({GUEST_SHUTDOWN_WAIT} seconds). Powering off.',
)

View File

@ -134,7 +134,7 @@ class ProxmoxDeferredRemoval(jobs.Job):
except client.ProxmoxNotFound:
storage.remove('tr' + str(vmId)) # VM does not exists anymore
except Exception as e: # Any other exception wil be threated again
# instance.doLog('Delayed removal of %s has failed: %s. Will retry later', vmId, e)
# instance.log('Delayed removal of %s has failed: %s. Will retry later', vmId, e)
logger.error('Delayed removal of %s failed: %s', i, e)
logger.debug('Deferred removal for proxmox finished')

View File

@ -296,7 +296,7 @@ class ProxmoxLinkedService(services.Service): # pylint: disable=too-many-public
self.disableHA(vmId)
except Exception as e:
logger.warning('Exception disabling HA for vm %s: %s', vmId, e)
self.doLog(level=log.LogLevel.WARNING, message=f'Exception disabling HA for vm {vmId}: {e}')
self.do_log(level=log.LogLevel.WARNING, message=f'Exception disabling HA for vm {vmId}: {e}')
# And remove it
return self.parent().removeMachine(vmId)

View File

@ -155,7 +155,7 @@ class XenLinkedDeployment(services.UserService):
self.cache.put('ready', '1', 30)
except Exception as e:
# On case of exception, log an an error and return as if the operation was executed
self.doLog(log.LogLevel.ERROR, 'Error setting machine state: {}'.format(e))
self.do_log(log.LogLevel.ERROR, 'Error setting machine state: {}'.format(e))
# return self.__error('Machine is not available anymore')
return State.FINISHED
@ -225,7 +225,7 @@ class XenLinkedDeployment(services.UserService):
def __error(self, reason: typing.Any) -> str:
logger.debug('Setting error state, reason: %s', reason)
self.doLog(log.LogLevel.ERROR, reason)
self.do_log(log.LogLevel.ERROR, reason)
if self._vmid != '': # Powers off and delete VM
try:

View File

@ -193,7 +193,7 @@ def action(request: 'ExtendedHttpRequestWithUser', idService: str, actionString:
if userService:
if actionString == 'release' and userService.deployed_service.allow_users_remove:
rebuild = True
log.doLog(
log.log(
userService.deployed_service,
log.LogLevel.INFO,
"Removing User Service {} as requested by {} from {}".format(
@ -209,7 +209,7 @@ def action(request: 'ExtendedHttpRequestWithUser', idService: str, actionString:
and userService.deployed_service.service.get_type().canReset # type: ignore
):
rebuild = True
log.doLog(
log.log(
userService.deployed_service,
log.LogLevel.INFO,
"Reseting User Service {} as requested by {} from {}".format(

View File

@ -63,8 +63,7 @@ class ServerEventsLogTest(rest.test.RESTTestCase):
server = servers_fixtures.createServer()
userService = self.user_service_managed
# Mock the "log.doLog" method (uds.core.util.log.doLog)
with mock.patch('uds.core.managers.log.manager.LogManager.doLog') as doLog:
with mock.patch('uds.core.managers.log.manager.LogManager.log') as the_log:
# Now notify to server
response = self.client.rest_post(
'/servers/event',
@ -77,7 +76,7 @@ class ServerEventsLogTest(rest.test.RESTTestCase):
)
self.assertEqual(response.status_code, 200)
# First call shout have
doLog.assert_any_call(server, log.LogLevel.INFO, 'test message', log.LogSource.SERVER, None)
the_log.assert_any_call(server, log.LogLevel.INFO, 'test message', log.LogSource.SERVER, None)
# Now notify to an userService
response = self.client.rest_post(
@ -92,7 +91,7 @@ class ServerEventsLogTest(rest.test.RESTTestCase):
)
self.assertEqual(response.status_code, 200)
doLog.assert_any_call(
the_log.assert_any_call(
userService, log.LogLevel.INFO, 'test message userservice', log.LogSource.SERVER, None
)

View File

@ -90,10 +90,10 @@ class RESTTestCase(test.UDSTransactionTestCase):
)
for user in self.users:
log.doLog(user, log.LogLevel.DEBUG, f'Debug Log for {user.name}')
log.doLog(user, log.LogLevel.INFO, f'Info Log for {user.name}')
log.doLog(user, log.LogLevel.WARNING, f'Warning Log for {user.name}')
log.doLog(user, log.LogLevel.ERROR, f'Error Log for {user.name}')
log.log(user, log.LogLevel.DEBUG, f'Debug Log for {user.name}')
log.log(user, log.LogLevel.INFO, f'Info Log for {user.name}')
log.log(user, log.LogLevel.WARNING, f'Warning Log for {user.name}')
log.log(user, log.LogLevel.ERROR, f'Error Log for {user.name}')
self.provider = services_fixtures.createProvider()