diff --git a/src/DIRAC/ConfigurationSystem/Client/CSAPI.py b/src/DIRAC/ConfigurationSystem/Client/CSAPI.py index 2dbab567651..399fde278bd 100644 --- a/src/DIRAC/ConfigurationSystem/Client/CSAPI.py +++ b/src/DIRAC/ConfigurationSystem/Client/CSAPI.py @@ -5,16 +5,16 @@ import datetime -from DIRAC import gLogger, gConfig, S_OK, S_ERROR +from DIRAC import S_ERROR, S_OK, gConfig, gLogger from DIRAC.ConfigurationSystem.Client.ConfigurationClient import ConfigurationClient -from DIRAC.Core.Utilities import List -from DIRAC.Core.Security.X509Chain import X509Chain # pylint: disable=import-error -from DIRAC.Core.Security import Locations -from DIRAC.ConfigurationSystem.private.Modificator import Modificator from DIRAC.ConfigurationSystem.Client.Helpers import CSGlobals from DIRAC.ConfigurationSystem.Client.Helpers.Operations import Operations -from DIRAC.ConfigurationSystem.Client.Helpers.Resources import getSites, getCESiteMapping from DIRAC.ConfigurationSystem.Client.Helpers.Path import cfgPath +from DIRAC.ConfigurationSystem.Client.Helpers.Resources import getCESiteMapping, getSites +from DIRAC.ConfigurationSystem.private.Modificator import Modificator +from DIRAC.Core.Security import Locations +from DIRAC.Core.Security.X509Chain import X509Chain # pylint: disable=import-error +from DIRAC.Core.Utilities import List class CSAPI: diff --git a/src/DIRAC/Core/Security/VOMSService.py b/src/DIRAC/Core/Security/VOMSService.py index e22bbd06c48..883d2533d99 100644 --- a/src/DIRAC/Core/Security/VOMSService.py +++ b/src/DIRAC/Core/Security/VOMSService.py @@ -37,27 +37,6 @@ def __init__(self, vo=None): self.userDict = None - def attGetUserNickname(self, dn, _ca=None): - """Get user nickname for a given DN if any - - :param str dn: user DN - :param str _ca: CA, kept for backward compatibility - :return: S_OK with Value: nickname - """ - - if self.userDict is None: - result = self.getUsers() - if not result["OK"]: - return result - - uDict = self.userDict.get(dn) - if not uDict: - return S_ERROR(DErrno.EVOMS, "No nickname defined") - nickname = uDict.get("nickname") - if not nickname: - return S_ERROR(DErrno.EVOMS, "No nickname defined") - return S_OK(nickname) - def getUsers(self): """Get all the users of the VOMS VO with their detailed information diff --git a/src/DIRAC/Core/scripts/dirac_configure.py b/src/DIRAC/Core/scripts/dirac_configure.py index 2d51abd6ca5..e381adf429b 100755 --- a/src/DIRAC/Core/scripts/dirac_configure.py +++ b/src/DIRAC/Core/scripts/dirac_configure.py @@ -44,6 +44,7 @@ import os import sys import warnings + import urllib3 import DIRAC @@ -235,9 +236,10 @@ def runConfigurationWizard(params): """Interactively configure DIRAC using metadata from installed extensions""" import subprocess - from DIRAC.Core.Utilities.Extensions import extensionsByPriority, getExtensionMetadata from prompt_toolkit import HTML, print_formatted_text, prompt + from DIRAC.Core.Utilities.Extensions import extensionsByPriority, getExtensionMetadata + for extension in extensionsByPriority(): extensionMetadata = getExtensionMetadata(extension) if extensionMetadata.get("primary_extension", False): @@ -302,13 +304,14 @@ def main(): def login(params): + from prompt_toolkit import HTML, print_formatted_text, prompt + from DIRAC.FrameworkSystem.private.authorization.utils.Tokens import ( getTokenFileLocation, readTokenFromFile, writeTokenDictToTokenFile, ) from DIRAC.Resources.IdProvider.IdProviderFactory import IdProviderFactory - from prompt_toolkit import HTML, print_formatted_text, prompt # Init authorization client result = IdProviderFactory().getIdProvider("DIRACCLI", issuer=params.issuer, scope=" ") diff --git a/src/DIRAC/DataManagementSystem/Agent/FTS3Agent.py b/src/DIRAC/DataManagementSystem/Agent/FTS3Agent.py index 4151a3fffb8..cf21652750e 100644 --- a/src/DIRAC/DataManagementSystem/Agent/FTS3Agent.py +++ b/src/DIRAC/DataManagementSystem/Agent/FTS3Agent.py @@ -15,32 +15,30 @@ import datetime import errno import os -from urllib import parse import time -# from threading import current_thread -from multiprocessing.pool import ThreadPool - # We use the dummy module because we use the ThreadPool from multiprocessing.dummy import current_process -from socket import gethostname - -from DIRAC import S_OK, S_ERROR +# from threading import current_thread +from multiprocessing.pool import ThreadPool +from socket import gethostname +from urllib import parse -from DIRAC.MonitoringSystem.Client.DataOperationSender import DataOperationSender +from DIRAC import S_ERROR, S_OK +from DIRAC.ConfigurationSystem.Client.Helpers.Operations import Operations as opHelper +from DIRAC.ConfigurationSystem.Client.Helpers.Registry import getDNForUsername +from DIRAC.ConfigurationSystem.Client.Helpers.Resources import getFTS3ServerDict from DIRAC.Core.Base.AgentModule import AgentModule from DIRAC.Core.Utilities.DErrno import cmpError from DIRAC.Core.Utilities.DictCache import DictCache from DIRAC.Core.Utilities.TimeUtilities import fromString -from DIRAC.ConfigurationSystem.Client.Helpers.Resources import getFTS3ServerDict -from DIRAC.ConfigurationSystem.Client.Helpers.Operations import Operations as opHelper -from DIRAC.ConfigurationSystem.Client.Helpers.Registry import getDNForUsername +from DIRAC.DataManagementSystem.Client.FTS3Job import FTS3Job +from DIRAC.DataManagementSystem.DB.FTS3DB import FTS3DB +from DIRAC.DataManagementSystem.private import FTS3Utilities from DIRAC.FrameworkSystem.Client.Logger import gLogger from DIRAC.FrameworkSystem.Client.ProxyManagerClient import gProxyManager -from DIRAC.DataManagementSystem.private import FTS3Utilities -from DIRAC.DataManagementSystem.DB.FTS3DB import FTS3DB -from DIRAC.DataManagementSystem.Client.FTS3Job import FTS3Job +from DIRAC.MonitoringSystem.Client.DataOperationSender import DataOperationSender from DIRAC.RequestManagementSystem.Client.ReqClient import ReqClient # pylint: disable=attribute-defined-outside-init diff --git a/src/DIRAC/DataManagementSystem/Service/FTS3ManagerHandler.py b/src/DIRAC/DataManagementSystem/Service/FTS3ManagerHandler.py index 989ee7c0403..91992f6e387 100644 --- a/src/DIRAC/DataManagementSystem/Service/FTS3ManagerHandler.py +++ b/src/DIRAC/DataManagementSystem/Service/FTS3ManagerHandler.py @@ -8,16 +8,13 @@ :caption: FTS3Manager options """ -from DIRAC import S_OK, S_ERROR, gLogger +from DIRAC import S_ERROR, S_OK, gLogger from DIRAC.ConfigurationSystem.Client.Helpers.Registry import getDNForUsername from DIRAC.Core.DISET.RequestHandler import RequestHandler, getServiceOption from DIRAC.Core.Security.Properties import FULL_DELEGATION, LIMITED_DELEGATION from DIRAC.Core.Utilities import DErrno -from DIRAC.Core.Utilities.JEncode import strToIntDict - - +from DIRAC.Core.Utilities.JEncode import decode, encode, strToIntDict from DIRAC.DataManagementSystem.DB.FTS3DB import FTS3DB -from DIRAC.Core.Utilities.JEncode import encode, decode ######################################################################## diff --git a/src/DIRAC/FrameworkSystem/Client/ComponentInstaller.py b/src/DIRAC/FrameworkSystem/Client/ComponentInstaller.py index de66319d961..8498afb398a 100644 --- a/src/DIRAC/FrameworkSystem/Client/ComponentInstaller.py +++ b/src/DIRAC/FrameworkSystem/Client/ComponentInstaller.py @@ -64,7 +64,6 @@ import MySQLdb from diraccfg import CFG from prompt_toolkit import prompt -from typing import cast import DIRAC from DIRAC import gConfig, gLogger, rootPath @@ -85,10 +84,10 @@ JOB_ADMINISTRATOR, NORMAL_USER, OPERATOR, + PRODUCTION_MANAGEMENT, PROXY_MANAGEMENT, SERVICE_ADMINISTRATOR, TRUSTED_HOST, - PRODUCTION_MANAGEMENT, ) from DIRAC.Core.Utilities.Extensions import ( extensionsByPriority, diff --git a/src/DIRAC/FrameworkSystem/Service/TornadoTokenManagerHandler.py b/src/DIRAC/FrameworkSystem/Service/TornadoTokenManagerHandler.py index f15d2415136..41da31e61ff 100644 --- a/src/DIRAC/FrameworkSystem/Service/TornadoTokenManagerHandler.py +++ b/src/DIRAC/FrameworkSystem/Service/TornadoTokenManagerHandler.py @@ -31,22 +31,21 @@ import pprint -from DIRAC import S_OK, S_ERROR +from DIRAC import S_ERROR, S_OK +from DIRAC.ConfigurationSystem.Client.Helpers import Registry from DIRAC.Core.Security import Properties +from DIRAC.Core.Tornado.Server.TornadoService import TornadoService from DIRAC.Core.Utilities import ThreadSafe from DIRAC.Core.Utilities.DictCache import DictCache -from DIRAC.Core.Tornado.Server.TornadoService import TornadoService from DIRAC.FrameworkSystem.DB.TokenDB import TokenDB -from DIRAC.ConfigurationSystem.Client.Helpers import Registry -from DIRAC.Resources.IdProvider.IdProviderFactory import IdProviderFactory from DIRAC.FrameworkSystem.Utilities.TokenManagementUtilities import ( - getIdProviderClient, + DEFAULT_AT_EXPIRATION_TIME, + DEFAULT_RT_EXPIRATION_TIME, getCachedKey, getCachedToken, - DEFAULT_RT_EXPIRATION_TIME, - DEFAULT_AT_EXPIRATION_TIME, + getIdProviderClient, ) - +from DIRAC.Resources.IdProvider.IdProviderFactory import IdProviderFactory # Used to synchronize the cache with user tokens gTokensSync = ThreadSafe.Synchronizer() diff --git a/src/DIRAC/FrameworkSystem/scripts/dirac_login.py b/src/DIRAC/FrameworkSystem/scripts/dirac_login.py index 5e503ebe72b..0c68987da88 100644 --- a/src/DIRAC/FrameworkSystem/scripts/dirac_login.py +++ b/src/DIRAC/FrameworkSystem/scripts/dirac_login.py @@ -13,44 +13,41 @@ # Return token $ dirac-login dirac_user --token """ +import copy import os import sys -import copy -import datetime -import json -from pathlib import Path -from prompt_toolkit import prompt, print_formatted_text as print, HTML + +from prompt_toolkit import HTML, prompt +from prompt_toolkit import print_formatted_text as print import DIRAC -from DIRAC import gConfig, gLogger, S_OK, S_ERROR -from DIRAC.Core.Security.Locations import getDefaultProxyLocation, getCertificateAndKeyLocation -from DIRAC.Core.Security.VOMS import VOMS +from DIRAC import S_ERROR, S_OK, gConfig, gLogger +from DIRAC.Core.Base.Script import Script from DIRAC.Core.Security.DiracX import addTokenToPEM +from DIRAC.Core.Security.Locations import getCertificateAndKeyLocation, getDefaultProxyLocation from DIRAC.Core.Security.ProxyFile import writeToProxyFile -from DIRAC.Core.Security.ProxyInfo import getProxyInfo, formatProxyInfoAsString +from DIRAC.Core.Security.ProxyInfo import formatProxyInfoAsString, getProxyInfo +from DIRAC.Core.Security.VOMS import VOMS from DIRAC.Core.Security.X509Chain import X509Chain # pylint: disable=import-error -from DIRAC.Core.Base.Script import Script -from DIRAC.Core.Base.Client import Client - # At this point, we disable CS synchronization so that an error related # to the lack of a proxy certificate does not occur when trying to synchronize. # Synchronization will take place after passing the authorization algorithm (creating a proxy). Script.disableCS() -from DIRAC.Resources.IdProvider.IdProviderFactory import IdProviderFactory -from DIRAC.FrameworkSystem.Client.ProxyManagerClient import gProxyManager -from DIRAC.FrameworkSystem.private.authorization.utils.Tokens import ( - writeTokenDictToTokenFile, - readTokenFromFile, - getTokenFileLocation, -) from DIRAC.ConfigurationSystem.Client.Helpers.Registry import ( + findDefaultGroupForDN, getGroupOption, getVOMSAttributeForGroup, getVOMSVOForGroup, - findDefaultGroupForDN, ) +from DIRAC.FrameworkSystem.Client.ProxyManagerClient import gProxyManager +from DIRAC.FrameworkSystem.private.authorization.utils.Tokens import ( + getTokenFileLocation, + readTokenFromFile, + writeTokenDictToTokenFile, +) +from DIRAC.Resources.IdProvider.IdProviderFactory import IdProviderFactory # This value shows what authorization way will be by default DEFAULT_AUTH_WAY = "certificate" # possible values are "certificate", "diracas" diff --git a/src/DIRAC/FrameworkSystem/scripts/dirac_proxy_destroy.py b/src/DIRAC/FrameworkSystem/scripts/dirac_proxy_destroy.py index 7441fa35ae4..2fd8e6a5719 100755 --- a/src/DIRAC/FrameworkSystem/scripts/dirac_proxy_destroy.py +++ b/src/DIRAC/FrameworkSystem/scripts/dirac_proxy_destroy.py @@ -8,13 +8,12 @@ import os import DIRAC -from DIRAC import gLogger, S_OK +from DIRAC import S_OK, gLogger +from DIRAC.ConfigurationSystem.Client.Helpers import Registry +from DIRAC.Core.Base.Client import Client from DIRAC.Core.Base.Script import Script - from DIRAC.Core.Security import Locations, ProxyInfo -from DIRAC.Core.Base.Client import Client from DIRAC.FrameworkSystem.Client.ProxyManagerClient import gProxyManager -from DIRAC.ConfigurationSystem.Client.Helpers import Registry class Params: diff --git a/src/DIRAC/FrameworkSystem/scripts/dirac_proxy_get_uploaded_info.py b/src/DIRAC/FrameworkSystem/scripts/dirac_proxy_get_uploaded_info.py index a10f98496a4..cb9cac5cd81 100755 --- a/src/DIRAC/FrameworkSystem/scripts/dirac_proxy_get_uploaded_info.py +++ b/src/DIRAC/FrameworkSystem/scripts/dirac_proxy_get_uploaded_info.py @@ -17,12 +17,12 @@ """ import sys -from DIRAC import gLogger, S_OK +from DIRAC import S_OK, gLogger +from DIRAC.ConfigurationSystem.Client.Helpers import Registry from DIRAC.Core.Base.Script import Script -from DIRAC.FrameworkSystem.Client.ProxyManagerClient import ProxyManagerClient from DIRAC.Core.Security import Properties from DIRAC.Core.Security.ProxyInfo import getProxyInfo -from DIRAC.ConfigurationSystem.Client.Helpers import Registry +from DIRAC.FrameworkSystem.Client.ProxyManagerClient import ProxyManagerClient userName = False diff --git a/src/DIRAC/Interfaces/API/DiracAdmin.py b/src/DIRAC/Interfaces/API/DiracAdmin.py index 2d9905f5e66..a04f6586973 100755 --- a/src/DIRAC/Interfaces/API/DiracAdmin.py +++ b/src/DIRAC/Interfaces/API/DiracAdmin.py @@ -90,7 +90,7 @@ def checkProxyUploaded(self, userDN, userGroup, requiredTime): Example usage: - >>> gLogger.notice(diracAdmin.setProxyPersistency( 'some DN', 'dirac group', True )) + >>> gLogger.notice(diracAdmin.checkProxyUploaded( 'some DN', 'dirac group', True )) {'OK': True, 'Value' : True/False } :param userDN: User DN diff --git a/src/DIRAC/Interfaces/Utilities/DCommands.py b/src/DIRAC/Interfaces/Utilities/DCommands.py index d7f2f8226b6..867436c763b 100644 --- a/src/DIRAC/Interfaces/Utilities/DCommands.py +++ b/src/DIRAC/Interfaces/Utilities/DCommands.py @@ -1,27 +1,26 @@ #!/usr/bin/env python +import glob +import json import os.path +import random import re -import uuid import stat -import json -import random -import glob import time -from configparser import ConfigParser, NoSectionError, NoOptionError +import uuid +from configparser import ConfigParser, NoOptionError, NoSectionError import DIRAC import DIRAC.Core.Security.ProxyInfo as ProxyInfo import DIRAC.FrameworkSystem.Client.ProxyGeneration as ProxyGeneration -from DIRAC import S_OK, S_ERROR, gConfig, gLogger -from DIRAC.Core.Security.Locations import getCAsLocation -from DIRAC.Core.Security import Locations, VOMS +from DIRAC import S_ERROR, S_OK, gConfig, gLogger +from DIRAC.ConfigurationSystem.Client.Helpers import Registry +from DIRAC.Core.Security import VOMS, Locations from DIRAC.Core.Security.DiracX import addTokenToPEM +from DIRAC.Core.Security.Locations import getCAsLocation from DIRAC.Core.Utilities.PrettyPrint import printTable from DIRAC.FrameworkSystem.Client.BundleDeliveryClient import BundleDeliveryClient -from DIRAC.ConfigurationSystem.Client.Helpers import Registry from DIRAC.Resources.Catalog.FileCatalog import FileCatalog - # ----------------------------- # Proxy manipulation functions # ----------------------------- @@ -530,16 +529,6 @@ def addVomsExt(self, proxy): chain = result["Value"] chain.dumpAllToFile(proxy) - def checkProxyOrInit(self): - create = False - try: - create = not self.proxyIsValid() - except: - create = True - - if create: - self.proxyInit() - def getUserName(self): proxyPath = _getProxyLocation() if not proxyPath: @@ -601,28 +590,6 @@ def guessConfigFromCS(config, section, userName, groupName): config.set(section, "default_se", defaultSESite) -def sessionFromProxy(config=None, sessionDir=None): - session = DSession(None, config, sessionDir=sessionDir) - # force copy of config profile options to environment - session.copyProfile() - return session - - -def getDNFromProxy(): - proxyPath = _getProxyLocation() - if not proxyPath: - gLogger.error("No proxy found") - return None - - retVal = _getProxyInfo(proxyPath) - if not retVal["OK"]: - return retVal - - pi = retVal["Value"] - - return S_OK(pi["identity"]) - - # ------------------------- # DCommands FC/LFN helpers # ------------------------- diff --git a/src/DIRAC/Interfaces/scripts/dconfig.py b/src/DIRAC/Interfaces/scripts/dconfig.py index f44e2ed7a9d..92a2d4502a7 100755 --- a/src/DIRAC/Interfaces/scripts/dconfig.py +++ b/src/DIRAC/Interfaces/scripts/dconfig.py @@ -7,14 +7,12 @@ $ dconfig (lists contents of ~/dirac/dcommands.conf) """ import DIRAC -from DIRAC import gLogger, S_OK +from DIRAC import S_OK, gLogger from DIRAC.Core.Base.Script import Script - from DIRAC.Interfaces.Utilities.DCommands import ( DConfig, createMinimalConfig, ) -from DIRAC.Interfaces.Utilities.DCommands import getDNFromProxy class Params: @@ -77,7 +75,7 @@ def main(): else: section = arg - if value != None: + if value is not None: dconfig.set(section, option, value) modified = True else: diff --git a/src/DIRAC/Interfaces/scripts/dirac_admin_sync_users_from_file.py b/src/DIRAC/Interfaces/scripts/dirac_admin_sync_users_from_file.py index 675c8d51e16..cd4b2343ed1 100755 --- a/src/DIRAC/Interfaces/scripts/dirac_admin_sync_users_from_file.py +++ b/src/DIRAC/Interfaces/scripts/dirac_admin_sync_users_from_file.py @@ -41,7 +41,7 @@ def main(): usersCFG = CFG().loadFromFile(args[0]) except Exception as e: errorList.append(("file open", f"Can't parse file {args[0]}: {str(e)}")) - errorCode = 1 + exitCode = 1 else: if not diracAdmin.csSyncUsersWithCFG(usersCFG): errorList.append(("modify users", f"Cannot sync with {args[0]}")) diff --git a/src/DIRAC/RequestManagementSystem/private/OperationHandlerBase.py b/src/DIRAC/RequestManagementSystem/private/OperationHandlerBase.py index 3278e8b27cb..f4cd288849d 100644 --- a/src/DIRAC/RequestManagementSystem/private/OperationHandlerBase.py +++ b/src/DIRAC/RequestManagementSystem/private/OperationHandlerBase.py @@ -33,9 +33,9 @@ import os -from DIRAC import gLogger, gConfig, S_ERROR, S_OK +from DIRAC import S_ERROR, S_OK, gConfig, gLogger from DIRAC.ConfigurationSystem.Client.Helpers.Operations import Operations -from DIRAC.ConfigurationSystem.Client.Helpers.Registry import getGroupsWithVOMSAttribute, getDNForUsername +from DIRAC.ConfigurationSystem.Client.Helpers.Registry import getDNForUsername, getGroupsWithVOMSAttribute from DIRAC.Core.Utilities import Network, TimeUtilities from DIRAC.Core.Utilities.ReturnValues import returnSingleResult from DIRAC.DataManagementSystem.Client.DataManager import DataManager diff --git a/src/DIRAC/Resources/Computing/CloudComputingElement.py b/src/DIRAC/Resources/Computing/CloudComputingElement.py index e98f9b5aec9..6ba416b0a15 100644 --- a/src/DIRAC/Resources/Computing/CloudComputingElement.py +++ b/src/DIRAC/Resources/Computing/CloudComputingElement.py @@ -147,24 +147,23 @@ """ -import uuid +import configparser +import datetime import os import sys +import uuid +from email.mime.multipart import MIMEMultipart +from email.mime.text import MIMEText + import yaml -import configparser -import datetime -from libcloud.compute.types import Provider, NodeState from libcloud.compute.providers import get_driver, set_driver -from email.mime.text import MIMEText -from email.mime.multipart import MIMEMultipart +from libcloud.compute.types import NodeState, Provider -from DIRAC import S_OK, S_ERROR, gConfig, rootPath -from DIRAC.Resources.Computing.ComputingElement import ComputingElement -from DIRAC.Core.Security.ProxyInfo import getProxyInfo -from DIRAC.ConfigurationSystem.Client.Helpers.Registry import getVOForGroup +from DIRAC import S_ERROR, S_OK, rootPath from DIRAC.ConfigurationSystem.Client.Helpers.Operations import Operations -from DIRAC.FrameworkSystem.Client.ProxyManagerClient import ProxyManagerClient -from DIRAC.FrameworkSystem.Client.ProxyManagerClient import gProxyManager +from DIRAC.Core.Security.ProxyInfo import getProxyInfo +from DIRAC.FrameworkSystem.Client.ProxyManagerClient import ProxyManagerClient, gProxyManager +from DIRAC.Resources.Computing.ComputingElement import ComputingElement # Standard CE name CE_NAME = "CloudCE" diff --git a/src/DIRAC/TransformationSystem/Client/RequestTasks.py b/src/DIRAC/TransformationSystem/Client/RequestTasks.py index 900d64f3e6d..69052d91a63 100644 --- a/src/DIRAC/TransformationSystem/Client/RequestTasks.py +++ b/src/DIRAC/TransformationSystem/Client/RequestTasks.py @@ -1,14 +1,13 @@ import time -from DIRAC import S_OK, S_ERROR, gLogger - +from DIRAC import S_ERROR, S_OK, gLogger from DIRAC.ConfigurationSystem.Client.Helpers.Registry import getDNForUsername from DIRAC.Core.Security.ProxyInfo import getProxyInfo from DIRAC.Core.Utilities.JEncode import decode +from DIRAC.RequestManagementSystem.Client.File import File +from DIRAC.RequestManagementSystem.Client.Operation import Operation from DIRAC.RequestManagementSystem.Client.ReqClient import ReqClient from DIRAC.RequestManagementSystem.Client.Request import Request -from DIRAC.RequestManagementSystem.Client.Operation import Operation -from DIRAC.RequestManagementSystem.Client.File import File from DIRAC.RequestManagementSystem.private.RequestValidator import RequestValidator from DIRAC.TransformationSystem.Client import TransformationFilesStatus from DIRAC.TransformationSystem.Client.BodyPlugin.BaseBody import BaseBody diff --git a/src/DIRAC/WorkloadManagementSystem/Agent/PilotLoggingAgent.py b/src/DIRAC/WorkloadManagementSystem/Agent/PilotLoggingAgent.py index 44708e9ab44..bef36abc719 100644 --- a/src/DIRAC/WorkloadManagementSystem/Agent/PilotLoggingAgent.py +++ b/src/DIRAC/WorkloadManagementSystem/Agent/PilotLoggingAgent.py @@ -11,17 +11,16 @@ # # imports import os -import time import tempfile -from DIRAC import S_OK, S_ERROR, gConfig +import time + +from DIRAC import S_ERROR, S_OK from DIRAC.ConfigurationSystem.Client.Helpers.Operations import Operations -from DIRAC.ConfigurationSystem.Client.Helpers.Registry import getVOs +from DIRAC.ConfigurationSystem.Client.Helpers.Registry import getDNForUsername, getVOMSAttributeForGroup, getVOs from DIRAC.Core.Base.AgentModule import AgentModule from DIRAC.Core.Security.ProxyInfo import getProxyInfo -from DIRAC.Core.Utilities.Proxy import executeWithoutServerCertificate -from DIRAC.Core.Utilities.Proxy import getProxy +from DIRAC.Core.Utilities.Proxy import executeWithoutServerCertificate, getProxy from DIRAC.DataManagementSystem.Client.DataManager import DataManager -from DIRAC.ConfigurationSystem.Client.Helpers.Registry import getVOMSAttributeForGroup, getDNForUsername from DIRAC.WorkloadManagementSystem.Client.TornadoPilotLoggingClient import TornadoPilotLoggingClient diff --git a/src/DIRAC/WorkloadManagementSystem/Agent/test/Test_Agent_PilotLoggingAgent.py b/src/DIRAC/WorkloadManagementSystem/Agent/test/Test_Agent_PilotLoggingAgent.py index 8bf566199ac..23adff9854d 100644 --- a/src/DIRAC/WorkloadManagementSystem/Agent/test/Test_Agent_PilotLoggingAgent.py +++ b/src/DIRAC/WorkloadManagementSystem/Agent/test/Test_Agent_PilotLoggingAgent.py @@ -46,7 +46,6 @@ def plaBase(mocker): "DIRAC.WorkloadManagementSystem.Agent.PilotLoggingAgent.getVOs", return_value={"OK": True, "Value": ["gridpp", "lz"]}, ) - mocker.patch("DIRAC.WorkloadManagementSystem.Agent.PilotLoggingAgent.gConfig.getValue", return_value="GridPP") mocker.patch("DIRAC.WorkloadManagementSystem.Agent.PilotLoggingAgent.Operations.getValue", side_effect=mockReply) mocker.patch( "DIRAC.WorkloadManagementSystem.Agent.PilotLoggingAgent.Operations.getOptionsDict", side_effect=mockReply1 diff --git a/src/DIRAC/WorkloadManagementSystem/DB/JobDB.py b/src/DIRAC/WorkloadManagementSystem/DB/JobDB.py index f52618817a3..cc819b329b7 100755 --- a/src/DIRAC/WorkloadManagementSystem/DB/JobDB.py +++ b/src/DIRAC/WorkloadManagementSystem/DB/JobDB.py @@ -1338,18 +1338,18 @@ def getAllSiteMaskStatus(self): return S_OK(siteDict) ############################################################################# - def setSiteMask(self, siteMaskList, authorDN="Unknown", comment="No comment"): + def setSiteMask(self, siteMaskList, author="Unknown", comment="No comment"): """Set the Site Mask to the given mask in a form of a list of tuples (site,status)""" for site, status in siteMaskList: - result = self.__setSiteStatusInMask(site, status, authorDN, comment) + result = self.__setSiteStatusInMask(site, status, author, comment) if not result["OK"]: return result return S_OK() ############################################################################# - def __setSiteStatusInMask(self, site, status, authorDN="Unknown", comment="No comment"): + def __setSiteStatusInMask(self, site, status, author="Unknown", comment="No comment"): """Set the given site status to 'status' or add a new active site""" result = self._escapeString(site) @@ -1362,10 +1362,10 @@ def __setSiteStatusInMask(self, site, status, authorDN="Unknown", comment="No co return result status = result["Value"] - result = self._escapeString(authorDN) + result = self._escapeString(author) if not result["OK"]: return result - authorDN = result["Value"] + author = result["Value"] result = self._escapeString(comment) if not result["OK"]: @@ -1384,14 +1384,14 @@ def __setSiteStatusInMask(self, site, status, authorDN="Unknown", comment="No co "UPDATE SiteMask SET Status=%s,LastUpdateTime=UTC_TIMESTAMP()," "Author=%s, Comment=%s WHERE Site=%s" ) - req = req % (status, authorDN, comment, site) + req = req % (status, author, comment, site) else: - req = f"INSERT INTO SiteMask VALUES ({site},{status},UTC_TIMESTAMP(),{authorDN},{comment})" + req = f"INSERT INTO SiteMask VALUES ({site},{status},UTC_TIMESTAMP(),{author},{comment})" result = self._update(req) if not result["OK"]: return S_ERROR("Failed to update the Site Mask") # update the site mask logging record - req = f"INSERT INTO SiteMaskLogging VALUES ({site},{status},UTC_TIMESTAMP(),{authorDN},{comment})" + req = f"INSERT INTO SiteMaskLogging VALUES ({site},{status},UTC_TIMESTAMP(),{author},{comment})" result = self._update(req) if not result["OK"]: self.log.warn("Failed to update site mask logging", f"for {site}") @@ -1401,16 +1401,16 @@ def __setSiteStatusInMask(self, site, status, authorDN="Unknown", comment="No co return S_OK() ############################################################################# - def banSiteInMask(self, site, authorDN="Unknown", comment="No comment"): + def banSiteInMask(self, site, author="Unknown", comment="No comment"): """Forbid the given site in the Site Mask""" - return self.__setSiteStatusInMask(site, "Banned", authorDN, comment) + return self.__setSiteStatusInMask(site, "Banned", author, comment) ############################################################################# - def allowSiteInMask(self, site, authorDN="Unknown", comment="No comment"): + def allowSiteInMask(self, site, author="Unknown", comment="No comment"): """Forbid the given site in the Site Mask""" - return self.__setSiteStatusInMask(site, "Active", authorDN, comment) + return self.__setSiteStatusInMask(site, "Active", author, comment) ############################################################################# def removeSiteFromMask(self, site=None): diff --git a/src/DIRAC/WorkloadManagementSystem/DB/SandboxMetadataDB.py b/src/DIRAC/WorkloadManagementSystem/DB/SandboxMetadataDB.py index 20e12bc6009..cdd778a2f80 100644 --- a/src/DIRAC/WorkloadManagementSystem/DB/SandboxMetadataDB.py +++ b/src/DIRAC/WorkloadManagementSystem/DB/SandboxMetadataDB.py @@ -375,7 +375,7 @@ def getSandboxOwner(self, SEName, SEPFN, requesterDN, requesterGroup): :param SEName: name of the StorageElement :param SEPFN: PFN of the Sandbox - :param requestDN: host DN used as credentials + :param requesterDN: host DN used as credentials :param requesterGroup: group used to use as credentials (should be 'hosts') :returns: S_OK with tuple (owner, ownerGroup) diff --git a/src/DIRAC/WorkloadManagementSystem/Service/JobPolicy.py b/src/DIRAC/WorkloadManagementSystem/Service/JobPolicy.py index 81b34ff6f70..c200bc834de 100755 --- a/src/DIRAC/WorkloadManagementSystem/Service/JobPolicy.py +++ b/src/DIRAC/WorkloadManagementSystem/Service/JobPolicy.py @@ -5,7 +5,6 @@ from DIRAC.ConfigurationSystem.Client.Helpers.Registry import ( getGroupsForUser, getPropertiesForGroup, - getUsernameForDN, getUsersInGroup, ) from DIRAC.Core.Security import Properties diff --git a/src/DIRAC/WorkloadManagementSystem/Service/WMSAdministratorHandler.py b/src/DIRAC/WorkloadManagementSystem/Service/WMSAdministratorHandler.py index eb43dda6910..e64c88efd3f 100755 --- a/src/DIRAC/WorkloadManagementSystem/Service/WMSAdministratorHandler.py +++ b/src/DIRAC/WorkloadManagementSystem/Service/WMSAdministratorHandler.py @@ -50,7 +50,7 @@ def export_setSiteMask(self, siteList): """ credDict = self.getRemoteCredentials() maskList = [(site, "Active") for site in siteList] - return self.jobDB.setSiteMask(maskList, credDict["DN"], "No comment") + return self.jobDB.setSiteMask(maskList, credDict["username"], "No comment") ############################################################################## types_getSiteMask = [] @@ -101,7 +101,7 @@ def export_banSite(self, site, comment="No comment"): :return: S_OK()/S_ERROR() """ credDict = self.getRemoteCredentials() - author = credDict["username"] if credDict["username"] != "anonymous" else credDict["DN"] + author = credDict["username"] if credDict["username"] != "anonymous" else credDict["username"] return self.jobDB.banSiteInMask(site, author, comment) ############################################################################## @@ -116,7 +116,7 @@ def export_allowSite(self, site, comment="No comment"): :return: S_OK()/S_ERROR() """ credDict = self.getRemoteCredentials() - author = credDict["username"] if credDict["username"] != "anonymous" else credDict["DN"] + author = credDict["username"] if credDict["username"] != "anonymous" else credDict["username"] return self.jobDB.allowSiteInMask(site, author, comment) ##############################################################################