From 494e24691b1639d72b516a825351579547c1c2cb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adolfo=20G=C3=B3mez=20Garc=C3=ADa?= Date: Thu, 4 Jan 2024 00:48:31 +0100 Subject: [PATCH] refactoring to camel_case, some minor fixes --- .gitignore | 1 + server/{src => }/coverage.ini | 0 server/src/uds/REST/log.py | 4 ++-- server/src/uds/REST/methods/actor_v3.py | 2 +- .../uds/REST/methods/meta_service_pools.py | 10 +++++----- server/src/uds/REST/methods/op_calendars.py | 10 +++++----- server/src/uds/REST/methods/services.py | 2 +- server/src/uds/REST/methods/services_pools.py | 2 +- server/src/uds/REST/methods/tunnels.py | 8 ++++---- server/src/uds/REST/methods/user_services.py | 20 +++++++++---------- server/src/uds/REST/methods/users_groups.py | 2 +- server/src/uds/REST/model.py | 2 +- server/src/uds/core/auths/auth.py | 8 ++++---- server/src/uds/core/managers/publication.py | 2 +- .../uds/core/managers/servers_api/events.py | 4 ++-- server/src/uds/core/managers/user_service.py | 14 ++++++------- .../core/managers/userservice/opchecker.py | 6 +++--- server/src/uds/core/osmanagers/osmanager.py | 8 ++++---- server/src/uds/core/services/provider.py | 4 ++-- server/src/uds/core/services/service.py | 4 ++-- server/src/uds/core/services/user_service.py | 4 ++-- server/src/uds/core/util/log.py | 16 +++++++-------- .../workers/hanged_userservice_cleaner.py | 8 ++++---- .../workers/servicepools_cache_updater.py | 4 ++-- server/src/uds/core/workers/stuck_cleaner.py | 2 +- server/src/uds/dispatchers/guacamole/views.py | 4 ++-- server/src/uds/management/commands/tree.py | 2 +- server/src/uds/models/authenticator.py | 2 +- server/src/uds/models/group.py | 2 +- server/src/uds/models/meta_pool.py | 2 +- server/src/uds/models/provider.py | 2 +- server/src/uds/models/service.py | 2 +- server/src/uds/models/service_pool.py | 4 ++-- .../uds/models/service_pool_publication.py | 2 +- server/src/uds/models/user.py | 2 +- server/src/uds/models/user_service.py | 4 ++-- .../LinuxOsManager/linux_osmanager.py | 8 ++++---- .../linux_randompass_osmanager.py | 2 +- .../uds/osmanagers/Test/testing_osmanager.py | 8 ++++---- .../osmanagers/WindowsOsManager/windows.py | 8 ++++---- .../WindowsOsManager/windows_domain.py | 12 +++++------ .../WindowsOsManager/windows_random.py | 2 +- server/src/uds/services/OVirt/deployment.py | 4 ++-- server/src/uds/services/OVirt/jobs.py | 2 +- .../src/uds/services/OpenGnsys/deployment.py | 4 ++-- .../src/uds/services/OpenNebula/deployment.py | 4 ++-- .../src/uds/services/OpenStack/deployment.py | 4 ++-- .../services/PhysicalMachines/deployment.py | 2 +- .../uds/services/PhysicalMachines/provider.py | 2 +- .../PhysicalMachines/service_multi.py | 2 +- server/src/uds/services/Proxmox/deployment.py | 4 ++-- server/src/uds/services/Proxmox/jobs.py | 2 +- server/src/uds/services/Proxmox/service.py | 2 +- server/src/uds/services/Xen/deployment.py | 4 ++-- server/src/uds/web/views/service.py | 4 ++-- server/tests/REST/servers/test_events_log.py | 7 +++---- server/tests/utils/rest/test.py | 8 ++++---- 57 files changed, 135 insertions(+), 135 deletions(-) rename server/{src => }/coverage.ini (100%) diff --git a/.gitignore b/.gitignore index f39486277..143f8a943 100644 --- a/.gitignore +++ b/.gitignore @@ -13,6 +13,7 @@ *.debhelper* *-stamp *.substvars +.coverage* # /client/administration/ /client/administration/*.suo diff --git a/server/src/coverage.ini b/server/coverage.ini similarity index 100% rename from server/src/coverage.ini rename to server/coverage.ini diff --git a/server/src/uds/REST/log.py b/server/src/uds/REST/log.py index 88d5f934e..9662a4f1c 100644 --- a/server/src/uds/REST/log.py +++ b/server/src/uds/REST/log.py @@ -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}'[ diff --git a/server/src/uds/REST/methods/actor_v3.py b/server/src/uds/REST/methods/actor_v3.py index fa9d40ec5..6cd8564e3 100644 --- a/server/src/uds/REST/methods/actor_v3.py +++ b/server/src/uds/REST/methods/actor_v3.py @@ -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'], diff --git a/server/src/uds/REST/methods/meta_service_pools.py b/server/src/uds/REST/methods/meta_service_pools.py index e500cdeee..e780889c5 100644 --- a/server/src/uds/REST/methods/meta_service_pools.py +++ b/server/src/uds/REST/methods/meta_service_pools.py @@ -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) diff --git a/server/src/uds/REST/methods/op_calendars.py b/server/src/uds/REST/methods/op_calendars.py index f63d96267..b0b7526db 100644 --- a/server/src/uds/REST/methods/op_calendars.py +++ b/server/src/uds/REST/methods/op_calendars.py @@ -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() diff --git a/server/src/uds/REST/methods/services.py b/server/src/uds/REST/methods/services.py index a002c69e6..76b320f2d 100644 --- a/server/src/uds/REST/methods/services.py +++ b/server/src/uds/REST/methods/services.py @@ -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 diff --git a/server/src/uds/REST/methods/services_pools.py b/server/src/uds/REST/methods/services_pools.py index 684803ec7..9256da624 100644 --- a/server/src/uds/REST/methods/services_pools.py +++ b/server/src/uds/REST/methods/services_pools.py @@ -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 [] diff --git a/server/src/uds/REST/methods/tunnels.py b/server/src/uds/REST/methods/tunnels.py index e7aa3dbda..9041b32a2 100644 --- a/server/src/uds/REST/methods/tunnels.py +++ b/server/src/uds/REST/methods/tunnels.py @@ -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, diff --git a/server/src/uds/REST/methods/user_services.py b/server/src/uds/REST/methods/user_services.py index e951a10a2..4787a509d 100644 --- a/server/src/uds/REST/methods/user_services.py +++ b/server/src/uds/REST/methods/user_services.py @@ -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}', diff --git a/server/src/uds/REST/methods/users_groups.py b/server/src/uds/REST/methods/users_groups.py index 0d0d1e92c..5a0186225 100644 --- a/server/src/uds/REST/methods/users_groups.py +++ b/server/src/uds/REST/methods/users_groups.py @@ -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) diff --git a/server/src/uds/REST/model.py b/server/src/uds/REST/model.py index 980e2c922..077f40366 100644 --- a/server/src/uds/REST/model.py +++ b/server/src/uds/REST/model.py @@ -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 [] diff --git a/server/src/uds/core/auths/auth.py b/server/src/uds/core/auths/auth.py index db7ccaf57..d92ddd14e 100644 --- a/server/src/uds/core/auths/auth.py +++ b/server/src/uds/core/auths/auth.py @@ -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) diff --git a/server/src/uds/core/managers/publication.py b/server/src/uds/core/managers/publication.py index fa2518237..01f6b2c83 100644 --- a/server/src/uds/core/managers/publication.py +++ b/server/src/uds/core/managers/publication.py @@ -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', diff --git a/server/src/uds/core/managers/servers_api/events.py b/server/src/uds/core/managers/servers_api/events.py index 011db2eb0..4f70a04ca 100644 --- a/server/src/uds/core/managers/servers_api/events.py +++ b/server/src/uds/core/managers/servers_api/events.py @@ -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) diff --git a/server/src/uds/core/managers/user_service.py b/server/src/uds/core/managers/user_service.py index bc71ec278..fc1903cf3 100644 --- a/server/src/uds/core/managers/user_service.py +++ b/server/src/uds/core/managers/user_service.py @@ -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})', diff --git a/server/src/uds/core/managers/userservice/opchecker.py b/server/src/uds/core/managers/userservice/opchecker.py index 804ab0f7e..bb139ea45 100644 --- a/server/src/uds/core/managers/userservice/opchecker.py +++ b/server/src/uds/core/managers/userservice/opchecker.py @@ -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']) diff --git a/server/src/uds/core/osmanagers/osmanager.py b/server/src/uds/core/osmanagers/osmanager.py index fb8db088d..253aec54f 100644 --- a/server/src/uds/core/osmanagers/osmanager.py +++ b/server/src/uds/core/osmanagers/osmanager.py @@ -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, diff --git a/server/src/uds/core/services/provider.py b/server/src/uds/core/services/provider.py index d53e14424..51a17419a 100644 --- a/server/src/uds/core/services/provider.py +++ b/server/src/uds/core/services/provider.py @@ -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): """ diff --git a/server/src/uds/core/services/service.py b/server/src/uds/core/services/service.py index b0a2b0b33..e2709b6a4 100644 --- a/server/src/uds/core/services/service.py +++ b/server/src/uds/core/services/service.py @@ -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: diff --git a/server/src/uds/core/services/user_service.py b/server/src/uds/core/services/user_service.py index a6a69b688..ced41e3ac 100644 --- a/server/src/uds/core/services/user_service.py +++ b/server/src/uds/core/services/user_service.py @@ -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': """ diff --git a/server/src/uds/core/util/log.py b/server/src/uds/core/util/log.py index 92b35fc99..0017ab74e 100644 --- a/server/src/uds/core/util/log.py +++ b/server/src/uds/core/util/log.py @@ -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 diff --git a/server/src/uds/core/workers/hanged_userservice_cleaner.py b/server/src/uds/core/workers/hanged_userservice_cleaner.py index 10f5c8ae0..f9164db49 100644 --- a/server/src/uds/core/workers/hanged_userservice_cleaner.py +++ b/server/src/uds/core/workers/hanged_userservice_cleaner.py @@ -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' diff --git a/server/src/uds/core/workers/servicepools_cache_updater.py b/server/src/uds/core/workers/servicepools_cache_updater.py index ca27d7846..126c0fd50 100644 --- a/server/src/uds/core/workers/servicepools_cache_updater.py +++ b/server/src/uds/core/workers/servicepools_cache_updater.py @@ -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', diff --git a/server/src/uds/core/workers/stuck_cleaner.py b/server/src/uds/core/workers/stuck_cleaner.py index 0af8c8da4..ee8fbf27a 100644 --- a/server/src/uds/core/workers/stuck_cleaner.py +++ b/server/src/uds/core/workers/stuck_cleaner.py @@ -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', diff --git a/server/src/uds/dispatchers/guacamole/views.py b/server/src/uds/dispatchers/guacamole/views.py index c117b93b3..2a3d2b7c4 100644 --- a/server/src/uds/dispatchers/guacamole/views.py +++ b/server/src/uds/dispatchers/guacamole/views.py @@ -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, diff --git a/server/src/uds/management/commands/tree.py b/server/src/uds/management/commands/tree.py index 96e34423d..45068a56b 100644 --- a/server/src/uds/management/commands/tree.py +++ b/server/src/uds/management/commands/tree.py @@ -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] = { '_': { diff --git a/server/src/uds/models/authenticator.py b/server/src/uds/models/authenticator.py index 350e57b65..e43388ae8 100644 --- a/server/src/uds/models/authenticator.py +++ b/server/src/uds/models/authenticator.py @@ -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) diff --git a/server/src/uds/models/group.py b/server/src/uds/models/group.py index ede8f5dfc..c7465707a 100644 --- a/server/src/uds/models/group.py +++ b/server/src/uds/models/group.py @@ -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) diff --git a/server/src/uds/models/meta_pool.py b/server/src/uds/models/meta_pool.py index 4652c9e65..ef158f44a 100644 --- a/server/src/uds/models/meta_pool.py +++ b/server/src/uds/models/meta_pool.py @@ -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) diff --git a/server/src/uds/models/provider.py b/server/src/uds/models/provider.py index bee523034..ff6c96e6e 100644 --- a/server/src/uds/models/provider.py +++ b/server/src/uds/models/provider.py @@ -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) diff --git a/server/src/uds/models/service.py b/server/src/uds/models/service.py index 2edc02f2c..33b004b4a 100644 --- a/server/src/uds/models/service.py +++ b/server/src/uds/models/service.py @@ -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) diff --git a/server/src/uds/models/service_pool.py b/server/src/uds/models/service_pool.py index 177de11b8..dd7cbbdb6 100644 --- a/server/src/uds/models/service_pool.py +++ b/server/src/uds/models/service_pool.py @@ -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) diff --git a/server/src/uds/models/service_pool_publication.py b/server/src/uds/models/service_pool_publication.py index e38da75f7..db24afcc3 100644 --- a/server/src/uds/models/service_pool_publication.py +++ b/server/src/uds/models/service_pool_publication.py @@ -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) diff --git a/server/src/uds/models/user.py b/server/src/uds/models/user.py index a662e2cbe..23a5b8de9 100644 --- a/server/src/uds/models/user.py +++ b/server/src/uds/models/user.py @@ -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(): diff --git a/server/src/uds/models/user_service.py b/server/src/uds/models/user_service.py index 674fe0376..fd4a45597 100644 --- a/server/src/uds/models/user_service.py +++ b/server/src/uds/models/user_service.py @@ -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) diff --git a/server/src/uds/osmanagers/LinuxOsManager/linux_osmanager.py b/server/src/uds/osmanagers/LinuxOsManager/linux_osmanager.py index d9f768802..930b5139a 100644 --- a/server/src/uds/osmanagers/LinuxOsManager/linux_osmanager.py +++ b/server/src/uds/osmanagers/LinuxOsManager/linux_osmanager.py @@ -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.', diff --git a/server/src/uds/osmanagers/LinuxOsManager/linux_randompass_osmanager.py b/server/src/uds/osmanagers/LinuxOsManager/linux_randompass_osmanager.py index 0d6f988c1..8cb883885 100644 --- a/server/src/uds/osmanagers/LinuxOsManager/linux_randompass_osmanager.py +++ b/server/src/uds/osmanagers/LinuxOsManager/linux_randompass_osmanager.py @@ -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}"', diff --git a/server/src/uds/osmanagers/Test/testing_osmanager.py b/server/src/uds/osmanagers/Test/testing_osmanager.py index f6936e356..0f302a758 100644 --- a/server/src/uds/osmanagers/Test/testing_osmanager.py +++ b/server/src/uds/osmanagers/Test/testing_osmanager.py @@ -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.', diff --git a/server/src/uds/osmanagers/WindowsOsManager/windows.py b/server/src/uds/osmanagers/WindowsOsManager/windows.py index 836641463..e28d81cd9 100644 --- a/server/src/uds/osmanagers/WindowsOsManager/windows.py +++ b/server/src/uds/osmanagers/WindowsOsManager/windows.py @@ -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.', diff --git a/server/src/uds/osmanagers/WindowsOsManager/windows_domain.py b/server/src/uds/osmanagers/WindowsOsManager/windows_domain.py index 718e6d9a8..75a3c1dd1 100644 --- a/server/src/uds/osmanagers/WindowsOsManager/windows_domain.py +++ b/server/src/uds/osmanagers/WindowsOsManager/windows_domain.py @@ -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})', diff --git a/server/src/uds/osmanagers/WindowsOsManager/windows_random.py b/server/src/uds/osmanagers/WindowsOsManager/windows_random.py index 24ff5759a..9977d91a5 100644 --- a/server/src/uds/osmanagers/WindowsOsManager/windows_random.py +++ b/server/src/uds/osmanagers/WindowsOsManager/windows_random.py @@ -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}"', diff --git a/server/src/uds/services/OVirt/deployment.py b/server/src/uds/services/OVirt/deployment.py index 775f0d9b2..93b12d2fc 100644 --- a/server/src/uds/services/OVirt/deployment.py +++ b/server/src/uds/services/OVirt/deployment.py @@ -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) diff --git a/server/src/uds/services/OVirt/jobs.py b/server/src/uds/services/OVirt/jobs.py index 6166b26ce..5142033c8 100644 --- a/server/src/uds/services/OVirt/jobs.py +++ b/server/src/uds/services/OVirt/jobs.py @@ -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') diff --git a/server/src/uds/services/OpenGnsys/deployment.py b/server/src/uds/services/OpenGnsys/deployment.py index 40079274f..4b34074b4 100644 --- a/server/src/uds/services/OpenGnsys/deployment.py +++ b/server/src/uds/services/OpenGnsys/deployment.py @@ -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}', ) diff --git a/server/src/uds/services/OpenNebula/deployment.py b/server/src/uds/services/OpenNebula/deployment.py index e01cade34..ed69f1b30 100644 --- a/server/src/uds/services/OpenNebula/deployment.py +++ b/server/src/uds/services/OpenNebula/deployment.py @@ -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: diff --git a/server/src/uds/services/OpenStack/deployment.py b/server/src/uds/services/OpenStack/deployment.py index 0fc8d1937..51e763860 100644 --- a/server/src/uds/services/OpenStack/deployment.py +++ b/server/src/uds/services/OpenStack/deployment.py @@ -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: diff --git a/server/src/uds/services/PhysicalMachines/deployment.py b/server/src/uds/services/PhysicalMachines/deployment.py index 4aec77c35..0f764fa8d 100644 --- a/server/src/uds/services/PhysicalMachines/deployment.py +++ b/server/src/uds/services/PhysicalMachines/deployment.py @@ -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}).' ) diff --git a/server/src/uds/services/PhysicalMachines/provider.py b/server/src/uds/services/PhysicalMachines/provider.py index a0c5a7c77..22c1f300a 100644 --- a/server/src/uds/services/PhysicalMachines/provider.py +++ b/server/src/uds/services/PhysicalMachines/provider.py @@ -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 '' diff --git a/server/src/uds/services/PhysicalMachines/service_multi.py b/server/src/uds/services/PhysicalMachines/service_multi.py index 3b7531c61..a61c18fe7 100644 --- a/server/src/uds/services/PhysicalMachines/service_multi.py +++ b/server/src/uds/services/PhysicalMachines/service_multi.py @@ -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}', ) diff --git a/server/src/uds/services/Proxmox/deployment.py b/server/src/uds/services/Proxmox/deployment.py index ce9ce6856..26d8f53d6 100644 --- a/server/src/uds/services/Proxmox/deployment.py +++ b/server/src/uds/services/Proxmox/deployment.py @@ -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.', ) diff --git a/server/src/uds/services/Proxmox/jobs.py b/server/src/uds/services/Proxmox/jobs.py index 3a8816289..08b70aac6 100644 --- a/server/src/uds/services/Proxmox/jobs.py +++ b/server/src/uds/services/Proxmox/jobs.py @@ -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') diff --git a/server/src/uds/services/Proxmox/service.py b/server/src/uds/services/Proxmox/service.py index c7e9a1582..13b48b801 100644 --- a/server/src/uds/services/Proxmox/service.py +++ b/server/src/uds/services/Proxmox/service.py @@ -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) diff --git a/server/src/uds/services/Xen/deployment.py b/server/src/uds/services/Xen/deployment.py index f23f972d4..22a4737c5 100644 --- a/server/src/uds/services/Xen/deployment.py +++ b/server/src/uds/services/Xen/deployment.py @@ -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: diff --git a/server/src/uds/web/views/service.py b/server/src/uds/web/views/service.py index 5565e8b84..01d37cf3d 100644 --- a/server/src/uds/web/views/service.py +++ b/server/src/uds/web/views/service.py @@ -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( diff --git a/server/tests/REST/servers/test_events_log.py b/server/tests/REST/servers/test_events_log.py index e87af3498..12fd8a0ca 100644 --- a/server/tests/REST/servers/test_events_log.py +++ b/server/tests/REST/servers/test_events_log.py @@ -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 ) diff --git a/server/tests/utils/rest/test.py b/server/tests/utils/rest/test.py index e1e7d7bf6..ab92f2d80 100644 --- a/server/tests/utils/rest/test.py +++ b/server/tests/utils/rest/test.py @@ -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()