diff --git a/.github/workflows/basic.yml b/.github/workflows/basic.yml index e042a9d474a..6168cb34c55 100644 --- a/.github/workflows/basic.yml +++ b/.github/workflows/basic.yml @@ -12,11 +12,11 @@ jobs: fail-fast: False matrix: command: - - pytest - - DIRAC_USE_M2CRYPTO=Yes DIRAC_M2CRYPTO_SPLIT_HANDSHAKE=Yes pytest + - pytest --no-cov + - DIRAC_USE_M2CRYPTO=Yes DIRAC_M2CRYPTO_SPLIT_HANDSHAKE=Yes pytest --no-cov # Security tests are flakey due to reference counting bugs in pyGSI/src/crypto/asn1.c - - pytest Core/Security/test || (echo "Retrying..."; pytest Core/Security/test) || (echo "Retrying again..."; pytest Core/Security/test) - - DIRAC_USE_M2CRYPTO=Yes DIRAC_M2CRYPTO_SPLIT_HANDSHAKE=Yes pytest Core/Security/test || (echo "Retrying..."; DIRAC_USE_M2CRYPTO=No pytest Core/Security/test) || (echo "Retrying again..."; DIRAC_USE_M2CRYPTO=No pytest Core/Security/test) + - pytest --no-cov Core/Security/test + - DIRAC_USE_M2CRYPTO=Yes DIRAC_M2CRYPTO_SPLIT_HANDSHAKE=Yes pytest --no-cov Core/Security/test - tests/checkDocs.sh # TODO This should cover more than just tests/CI # Excluded codes related to sourcing files diff --git a/.gitignore b/.gitignore index a6d1f26792f..85f8efb537c 100644 --- a/.gitignore +++ b/.gitignore @@ -73,6 +73,7 @@ tests/CI/SERVERCONFIG # VSCode .vscode +.env # docs # this is auto generated diff --git a/ConfigurationSystem/Client/CSAPI.py b/ConfigurationSystem/Client/CSAPI.py index 2a8f1b1b0e5..2f24fb2fe56 100644 --- a/ConfigurationSystem/Client/CSAPI.py +++ b/ConfigurationSystem/Client/CSAPI.py @@ -210,7 +210,7 @@ def listHosts(self): def describeUsers(self, users=None): """ describe users by nickname - :param list users: list of users' nickanames + :param list users: list of users' nicknames :return: a S_OK(description) of the users in input """ if users is None: @@ -329,14 +329,14 @@ def addUser(self, username, properties): """ Add a user to the cs - :param str username: group name - :param dict properties: dictionary describing user properties: + :param str username: username + :param dict properties: dictionary describing user properties: - - DN - - groups - - + - DN + - groups + - - :return: True/False + :return: True/False """ if not self.__initialized['OK']: return self.__initialized @@ -368,14 +368,15 @@ def modifyUser(self, username, properties, createIfNonExistant=False): """ Modify a user - :param str username: group name - :param dict properties: dictionary describing user properties: + :param str username: group name + :param dict properties: dictionary describing user properties: - DN - Groups - - :return: S_OK, Value = True/False + :param bool createIfNonExistant: if true, registers the users if it did not exist + :return: S_OK, Value = True/False """ if not self.__initialized['OK']: return self.__initialized @@ -430,14 +431,14 @@ def addGroup(self, groupname, properties): """ Add a group to the cs - :param str groupname: group name - :param dict properties: dictionary describing group properties: + :param str groupname: group name + :param dict properties: dictionary describing group properties: - Users - Properties - - :return: True/False + :return: S_OK, Value = True/False """ if not self.__initialized['OK']: return self.__initialized @@ -455,14 +456,15 @@ def modifyGroup(self, groupname, properties, createIfNonExistant=False): """ Modify a group - :param str groupname: group name - :param dict properties: dictionary describing group properties: + :param str groupname: group name + :param dict properties: dictionary describing group properties: - Users - Properties - - :return: True/False + :param bool createIfNonExistant: if true, creates the group if it did not exist + :return: S_OK, Value = True/False """ if not self.__initialized['OK']: return self.__initialized @@ -490,14 +492,15 @@ def modifyGroup(self, groupname, properties, createIfNonExistant=False): def addHost(self, hostname, properties): """ Add a host to the cs - :param str hostname: hostname name - :param dict properties: dictionary describing host properties: + + :param str hostname: host name + :param dict properties: dictionary describing host properties: - DN - Properties - - :return: True/False + :return: S_OK, Value = True/False """ if not self.__initialized['OK']: return self.__initialized @@ -617,14 +620,16 @@ def getOpsSection(): def modifyHost(self, hostname, properties, createIfNonExistant=False): """ Modify a host - :param str hostname: hostname name - :param dict properties: dictionary describing host properties: + + :param str hostname: hostname name + :param dict properties: dictionary describing host properties: - DN - Properties - - :return: True/False + :param bool createIfNonExistant: if true, creates the host if it did not exist + :return: S_OK, Value = True/False """ if not self.__initialized['OK']: return self.__initialized diff --git a/ConfigurationSystem/Client/Config.py b/ConfigurationSystem/Client/Config.py index 11314f2a160..6363f77d4c5 100755 --- a/ConfigurationSystem/Client/Config.py +++ b/ConfigurationSystem/Client/Config.py @@ -6,8 +6,13 @@ from DIRAC.ConfigurationSystem.private.ConfigurationClient import ConfigurationClient +#: Global gConfig object of type :class:`~DIRAC.ConfigurationSystem.private.ConfigurationClient.ConfigurationClient` gConfig = ConfigurationClient() def getConfig(): + """ + :returns: gConfig + :rtype: ~DIRAC.ConfigurationSystem.private.ConfigurationClient.ConfigurationClient + """ return gConfig diff --git a/ConfigurationSystem/Client/Helpers/Registry.py b/ConfigurationSystem/Client/Helpers/Registry.py index eaa337add26..13eeef17da8 100644 --- a/ConfigurationSystem/Client/Helpers/Registry.py +++ b/ConfigurationSystem/Client/Helpers/Registry.py @@ -23,6 +23,7 @@ def getUsernameForDN(dn, usersList=None): :return: S_OK(str)/S_ERROR() """ + dn = dn.strip() if not usersList: result = gConfig.getSections("%s/Users" % gBaseRegistrySection) if not result['OK']: @@ -63,6 +64,7 @@ def getGroupsForDN(dn): :return: S_OK(list)/S_ERROR() -- contain list of groups """ + dn = dn.strip() result = getUsernameForDN(dn) if not result['OK']: return result @@ -128,6 +130,7 @@ def getHostnameForDN(dn): :return: S_OK()/S_ERROR() """ + dn = dn.strip() result = gConfig.getSections("%s/Hosts" % gBaseRegistrySection) if not result['OK']: return result @@ -153,6 +156,7 @@ def findDefaultGroupForDN(dn): :return: S_OK()/S_ERROR() """ + dn = dn.strip() result = getUsernameForDN(dn) if not result['OK']: return result diff --git a/Core/DISET/private/Transports/M2SSLTransport.py b/Core/DISET/private/Transports/M2SSLTransport.py index 9def1d7fd63..fde34b9fbb3 100755 --- a/Core/DISET/private/Transports/M2SSLTransport.py +++ b/Core/DISET/private/Transports/M2SSLTransport.py @@ -45,6 +45,9 @@ def __init__(self, *args, **kwargs): as for other transports. If ctx is specified (as an instance of SSL.Context) then use that rather than creating a new context. """ + # The thread init of M2Crypto is not really thread safe. + # So we put it a second time + M2Threading.init() self.remoteAddress = None self.peerCredentials = {} self.__timeout = 1 @@ -98,9 +101,7 @@ def initAsClient(self): error = "%s:%s" % (e, repr(e)) if self.oSocket is not None: - self.oSocket.close() - self.oSocket.socket.close() - self.oSocket = None + self.close() return S_ERROR(error) @@ -125,20 +126,85 @@ def initAsServer(self): return S_OK() def close(self): + # pylint: disable=line-too-long """ Close this socket. """ + if self.oSocket: + # TL;DR: + # Do NOT touch that method + # # Surprisingly (to me at least), M2Crypto does not close - # the socket when calling SSL.Connection.close - # It only does it when the garbage collector kicks in - # We have to manually close it here, otherwise the connections - # will hang forever + # the underlying socket when calling SSL.Connection.close + # It only does it when the garbage collector kicks in (see ~M2Crypto.SSL.Connection.Connection.__del__) + # If the socket is not closed, the connection may hang forever. + # + # Thus, we are setting self.oSocket to None to allow the GC to do the work, but since we are not sure + # that it will run, we anyway force the connection to be closed + # + # However, we should close the underlying socket only after SSL was shutdown properly. + # This is because OpenSSL `ssl3_shutdown` (see callstack below) may still read some data + # (see https://github.com/openssl/openssl/blob/master/ssl/s3_lib.c#L4509):: + # + # + # 1 0x00007fffe9d48fc0 in sock_read () from /lib/libcrypto.so.1.0.0 + # 2 0x00007fffe9d46e83 in BIO_read () from /lib/libcrypto.so.1.0.0 + # 3 0x00007fffe9eab9dd in ssl3_read_n () from /lib/libssl.so.1.0.0 + # 4 0x00007fffe9ead216 in ssl3_read_bytes () from /lib/libssl.so.1.0.0 + # 5 0x00007fffe9ea999c in ssl3_shutdown () from /lib/libssl.so.1.0.0 + # 6 0x00007fffe9ed4f93 in ssl_free () from /lib/libssl.so.1.0.0 + # 7 0x00007fffe9d46d5b in BIO_free () from /lib/libcrypto.so.1.0.0 + # 8 0x00007fffe9f30a96 in bio_free (bio=0x5555556f3200) at SWIG/_m2crypto_wrap.c:5008 + # 9 0x00007fffe9f30b1e in _wrap_bio_free (self=, args=) at SWIG/_m2crypto_wrap.c + # + # We unfortunately have no way to force that order, and there is a risk of deadlock + # when running in a multi threaded environment like the agents:: + # + # Thread A opens socket, gets FD = 111 + # Thread A works on it + # Thread A closes FD 111 (underlying socket.close()) + # Thread B opens socket, gets FD = 111 + # Thread A calls read on FD=111 from ssl3_shutdown + # + # This is illustrated on the strace below:: + # + # 26461 14:25:15.266692 write(111]:42688->[]:9140]>, + # "blabla", 37 + # 26464 14:25:15.266857 <... connect resumed>) = 0 <0.000195> + # 26464 14:25:15.267023 getsockname(120:44252->188.185.84.86:9140]>, + # 26461 14:25:15.267176 <... write resumed>) = 37 <0.000453> + # 26464 14:25:15.267425 <... getsockname resumed>{sa_family=AF_INET, sin_port=htons(44252), + # sin_addr=inet_addr("")}, [28->16]) = 0 <0.000292> + # 26461 14:25:15.267466 close(111]:42688->[]:9140]> + # 26464 14:25:15.267637 close(120:44252->188.185.84.86:9140]> + # 26464 14:25:15.267738 <... close resumed>) = 0 <0.000086> + # 26461 14:25:15.267768 <... close resumed>) = 0 <0.000285> + # 26464 14:25:15.267827 socket(AF_INET6, SOCK_DGRAM|SOCK_CLOEXEC, IPPROTO_IP + # 26461 14:25:15.267888 futex(0x21f8620, FUTEX_WAKE_PRIVATE, 1 + # 26464 14:25:15.267976 <... socket resumed>) = 111 <0.000138> + # 26461 14:25:15.268092 <... futex resumed>) = 1 <0.000196> + # 26464 14:25:15.268195 connect(111, + # {sa_family=AF_INET6, sin6_port=htons(9140), + # inet_pton(AF_INET6, "", &sin6_addr), + # sin6_flowinfo=htonl(0), sin6_scope_id=0 + # }, 28 + # 26461 14:25:15.268294 read(111]:42480->[]:9140]>, + # 26464 14:25:15.268503 <... connect resumed>) = 0 <0.000217> + # 26464 14:25:15.268673 getsockname(111]:42480->[]:9140]>, + # 26464 14:25:15.268862 <... getsockname resumed>{sa_family=AF_INET6, sin6_port=htons(42480), + # inet_pton(AF_INET6, "", &sin6_addr), sin6_flowinfo=htonl(0), sin6_scope_id= + # 0}, [28]) = 0 <0.000168> + # 26464 14:25:15.269048 + # close(111]:42480->[]:9140]> + # + self.oSocket.close() - self.oSocket.socket.close() - # del self.oSocket + underlyingSocket = self.oSocket.socket self.oSocket = None + underlyingSocket.close() return S_OK() def renewServerContext(self): + # pylint: disable=line-too-long """ Renews the server context. This reloads the certificates and re-initialises the SSL context. diff --git a/DataManagementSystem/Agent/FTS3Agent.py b/DataManagementSystem/Agent/FTS3Agent.py index 0a88c777fb1..b1ec43d52e2 100644 --- a/DataManagementSystem/Agent/FTS3Agent.py +++ b/DataManagementSystem/Agent/FTS3Agent.py @@ -369,24 +369,36 @@ def _treatOperation(self, operation): continueOperationProcessing = True # Check the status of the associated RMS Request. - # If it is canceled then we will not create new FTS3Jobs, and mark + # If it is canceled or does not exist anymore then we will not create new FTS3Jobs, and mark # this as FTS3Operation canceled. if operation.rmsReqID: res = ReqClient().getRequestStatus(operation.rmsReqID) if not res['OK']: - log.error("Could not get request status", res) - return operation, res - rmsReqStatus = res['Value'] - - if rmsReqStatus == 'Canceled': - log.info( - "The RMS Request is canceled, canceling the FTS3Operation", - "rmsReqID: %s, FTS3OperationID: %s" % - (operation.rmsReqID, - operation.operationID)) - operation.status = 'Canceled' - continueOperationProcessing = False + # If the Request does not exist anymore + if cmpError(res, errno.ENOENT): + log.info( + "The RMS Request does not exist anymore, canceling the FTS3Operation", + "rmsReqID: %s, FTS3OperationID: %s" % + (operation.rmsReqID, + operation.operationID)) + operation.status = 'Canceled' + continueOperationProcessing = False + else: + log.error("Could not get request status", res) + return operation, res + + else: + rmsReqStatus = res['Value'] + + if rmsReqStatus == 'Canceled': + log.info( + "The RMS Request is canceled, canceling the FTS3Operation", + "rmsReqID: %s, FTS3OperationID: %s" % + (operation.rmsReqID, + operation.operationID)) + operation.status = 'Canceled' + continueOperationProcessing = False if continueOperationProcessing: res = operation.prepareNewJobs( diff --git a/DataManagementSystem/Client/FTS3Client.py b/DataManagementSystem/Client/FTS3Client.py index 29f653e1016..79fdb5f4ba2 100644 --- a/DataManagementSystem/Client/FTS3Client.py +++ b/DataManagementSystem/Client/FTS3Client.py @@ -11,7 +11,7 @@ class FTS3Client(Client): def __init__(self, url=None, **kwargs): """ Constructor function. """ - Client.__init__(self, **kwargs) + super(FTS3Client, self).__init__(**kwargs) self.setServer('DataManagement/FTS3Manager') if url: self.setServer(url) diff --git a/DataManagementSystem/Client/S3GatewayClient.py b/DataManagementSystem/Client/S3GatewayClient.py index 04bd31396a3..263b77b49bb 100644 --- a/DataManagementSystem/Client/S3GatewayClient.py +++ b/DataManagementSystem/Client/S3GatewayClient.py @@ -11,7 +11,7 @@ class S3GatewayClient(Client): def __init__(self, url=None, **kwargs): """ Constructor function. """ - Client.__init__(self, **kwargs) + super(S3GatewayClient, self).__init__(**kwargs) self.setServer('DataManagement/S3Gateway') if url: self.setServer(url) diff --git a/DataManagementSystem/scripts/dirac-dms-add-file.py b/DataManagementSystem/scripts/dirac-dms-add-file.py index bb5bf2c59b6..d3ffc0eea9d 100755 --- a/DataManagementSystem/scripts/dirac-dms-add-file.py +++ b/DataManagementSystem/scripts/dirac-dms-add-file.py @@ -61,6 +61,11 @@ def getDict(item_list): return lfn_dict +from DIRAC.DataManagementSystem.Client.DataManager import DataManager +from DIRAC import gLogger +import DIRAC +exitCode = 0 + lfns = [] if len(args) == 1: inputFileName = args[0] @@ -72,14 +77,12 @@ def getDict(item_list): items[0] = items[0].replace('LFN:', '').replace('lfn:', '') lfns.append(getDict(items)) inputFile.close() + else: + gLogger.error("Error: LFN list '%s' missing." % inputFileName) + exitCode = 4 else: lfns.append(getDict(args)) -from DIRAC.DataManagementSystem.Client.DataManager import DataManager -from DIRAC import gLogger -import DIRAC -exitCode = 0 - dm = DataManager() for lfn in lfns: if not os.path.exists(lfn['localfile']): diff --git a/FrameworkSystem/Client/BundleDeliveryClient.py b/FrameworkSystem/Client/BundleDeliveryClient.py index eeb72c8c24e..5667199a351 100644 --- a/FrameworkSystem/Client/BundleDeliveryClient.py +++ b/FrameworkSystem/Client/BundleDeliveryClient.py @@ -2,30 +2,30 @@ """ import os +import io import tarfile import cStringIO from DIRAC import S_OK, gLogger -from DIRAC.Core.DISET.RPCClient import RPCClient +from DIRAC.Core.Base.Client import Client, createClient from DIRAC.Core.DISET.TransferClient import TransferClient from DIRAC.Core.Security import Locations, Utilities +from DIRAC.Core.Utilities.File import mkDir from DIRAC.ConfigurationSystem.Client.Helpers.CSGlobals import skipCACheck + + __RCSID__ = "$Id$" -class BundleDeliveryClient(object): +@createClient('Framework/BundleDelivery') +class BundleDeliveryClient(Client): - def __init__(self, rpcClient=False, transferClient=False): - self.rpcClient = rpcClient + def __init__(self, transferClient=False, **kwargs): + super(BundleDeliveryClient, self).__init__(**kwargs) + self.setServer('Framework/BundleDelivery') self.transferClient = transferClient self.log = gLogger.getSubLogger("BundleDelivery") - def __getRPCClient(self): - if self.rpcClient: - return self.rpcClient - return RPCClient("Framework/BundleDelivery", - skipCACheck=skipCACheck()) - def __getTransferClient(self): if self.transferClient: return self.transferClient @@ -34,7 +34,7 @@ def __getTransferClient(self): def __getHash(self, bundleID, dirToSyncTo): try: - with open(os.path.join(dirToSyncTo, ".dab.%s" % bundleID), "rb") as fd: + with io.open(os.path.join(dirToSyncTo, ".dab.%s" % bundleID), "rb") as fd: bdHash = fd.read().strip() return bdHash except BaseException: @@ -43,7 +43,7 @@ def __getHash(self, bundleID, dirToSyncTo): def __setHash(self, bundleID, dirToSyncTo, bdHash): try: fileName = os.path.join(dirToSyncTo, ".dab.%s" % bundleID) - with open(fileName, "wb") as fd: + with io.open(fileName, "wb") as fd: fd.write(bdHash) except Exception as e: self.log.error("Could not save hash after synchronization", "%s: %s" % (fileName, str(e))) @@ -52,7 +52,7 @@ def syncDir(self, bundleID, dirToSyncTo): dirCreated = False if not os.path.isdir(dirToSyncTo): self.log.info("Creating dir %s" % dirToSyncTo) - os.makedirs(dirToSyncTo) + mkDir(dirToSyncTo) dirCreated = True currentHash = self.__getHash(bundleID, dirToSyncTo) self.log.info("Current hash for bundle %s in dir %s is '%s'" % (bundleID, dirToSyncTo, currentHash)) @@ -113,7 +113,7 @@ def getCAs(self): # if we can not found the file, we return the directory, where the file should be transferClient = self.__getTransferClient() casFile = os.path.join(os.path.dirname(retVal['Message']), "cas.pem") - with open(casFile, "w") as fd: + with io.open(casFile, "w") as fd: result = transferClient.receiveFile(fd, 'CAs') if not result['OK']: return result @@ -131,7 +131,7 @@ def getCLRs(self): # if we can not found the file, we return the directory, where the file should be transferClient = self.__getTransferClient() casFile = os.path.join(os.path.dirname(retVal['Message']), "crls.pem") - with open(casFile, "w") as fd: + with io.open(casFile, "w") as fd: result = transferClient.receiveFile(fd, 'CRLs') if not result['OK']: return result diff --git a/FrameworkSystem/Client/ComponentInstaller.py b/FrameworkSystem/Client/ComponentInstaller.py index e1ae37bc4d8..aceb78956ad 100644 --- a/FrameworkSystem/Client/ComponentInstaller.py +++ b/FrameworkSystem/Client/ComponentInstaller.py @@ -58,6 +58,7 @@ from __future__ import print_function, absolute_import import os +import io import re import glob import stat @@ -1015,7 +1016,7 @@ def getSoftwareComponents(self, extensions): for agent in agentList: if os.path.splitext(agent)[1] == ".py": agentFile = os.path.join(agentDir, agent) - with open(agentFile, 'r') as afile: + with io.open(agentFile, 'rt') as afile: body = afile.read() if body.find('AgentModule') != -1 or body.find('OptimizerModule') != -1: if system not in agents: @@ -1041,7 +1042,7 @@ def getSoftwareComponents(self, extensions): for executor in executorList: if os.path.splitext(executor)[1] == ".py": executorFile = os.path.join(executorDir, executor) - with open(executorFile, 'r') as afile: + with io.open(executorFile, 'rt') as afile: body = afile.read() if body.find('OptimizerExecutor') != -1: if system not in executors: @@ -1092,8 +1093,8 @@ def getInstalledComponents(self): for component in components: try: runFile = os.path.join(systemDir, component, 'run') - with open(runFile, 'r') as rfile: - body = rfile.read() + with io.open(runFile, 'rt') as rFile: + body = rFile.read() for cType in self.componentTypes: if body.find('dirac-%s' % (cType)) != -1: @@ -1126,12 +1127,12 @@ def getSetupComponents(self): for component in componentList: try: runFile = os.path.join(self.startDir, component, 'run') - with open(runFile, 'r') as rfile: + with io.open(runFile, 'rt') as rfile: body = rfile.read() for cType in self.componentTypes: if body.find('dirac-%s' % (cType)) != -1: - system, compT = component.split('_')[0:2] + system, compT = component.split('_', 1) if system not in resultDict[resultIndexes[cType]]: resultDict[resultIndexes[cType]][system] = [] resultDict[resultIndexes[cType]][system].append(compT) @@ -1462,7 +1463,7 @@ def getLogTail(self, system, component, length=100): if not os.path.exists(logFileName): retDict[compName] = 'No log file found' else: - with open(logFileName, 'r') as logFile: + with io.open(logFileName, 'rt') as logFile: lines = [line.strip() for line in logFile.readlines()] if len(lines) < length: @@ -1599,7 +1600,7 @@ def setupSite(self, scriptCfg, cfg=None): if not cmdFound: gLogger.notice('Starting runsvdir ...') - with open(os.devnull, 'w') as devnull: + with io.open(os.devnull, 'w') as devnull: subprocess.Popen(['nohup', 'runsvdir', self.startDir, 'log: DIRAC runsv'], stdout=devnull, stderr=devnull, universal_newlines=True) @@ -1813,22 +1814,21 @@ def _createRunitLog(self, runitCompDir): mkDir(logDir) logConfigFile = os.path.join(logDir, 'config') - with open(logConfigFile, 'w') as fd: + with io.open(logConfigFile, 'w') as fd: fd.write( - """s10000000 + u"""s10000000 n20 """) logRunFile = os.path.join(logDir, 'run') - with open(logRunFile, 'w') as fd: + with io.open(logRunFile, 'w') as fd: fd.write( - """#!/bin/bash - # - rcfile=%(bashrc)s - [ -e $rcfile ] && source $rcfile - # - exec svlogd . + u"""#!/bin/bash +rcfile=%(bashrc)s +[[ -e $rcfile ]] && source ${rcfile} +# +exec svlogd . """ % {'bashrc': os.path.join(self.instancePath, 'bashrc')}) os.chmod(logRunFile, self.gDefaultPerms) @@ -1894,30 +1894,30 @@ def installComponent(self, componentType, system, component, extensions, compone try: componentCfg = os.path.join(self.linkedRootPath, 'etc', '%s_%s.cfg' % (system, component)) if not os.path.exists(componentCfg): - fd = open(componentCfg, 'w') - fd.close() + io.open(componentCfg, 'w').close() self._createRunitLog(runitCompDir) runFile = os.path.join(runitCompDir, 'run') - with open(runFile, 'w') as fd: + with io.open(runFile, 'w') as fd: fd.write( - """#!/bin/bash - rcfile=%(bashrc)s - [ -e $rcfile ] && source $rcfile - # - exec 2>&1 - # - [ "%(componentType)s" = "agent" ] && renice 20 -p $$ - #%(bashVariables)s - # - exec python $DIRAC/DIRAC/Core/scripts/dirac-%(componentType)s.py %(system)s/%(component)s %(componentCfg)s < /dev/null - """ % {'bashrc': os.path.join(self.instancePath, 'bashrc'), - 'bashVariables': bashVars, - 'componentType': componentType, - 'system': system, - 'component': component, - 'componentCfg': componentCfg}) + u"""#!/bin/bash + +rcfile=%(bashrc)s +[[ -e $rcfile ]] && source ${rcfile} +# +exec 2>&1 +# +[[ "%(componentType)s" = "agent" ]] && renice 20 -p $$ +#%(bashVariables)s +# +exec python $DIRAC/DIRAC/Core/scripts/dirac-%(componentType)s.py %(system)s/%(component)s %(componentCfg)s < /dev/null + """ % {'bashrc': os.path.join(self.instancePath, 'bashrc'), + 'bashVariables': bashVars, + 'componentType': componentType, + 'system': system, + 'component': component, + 'componentCfg': componentCfg}) os.chmod(runFile, self.gDefaultPerms) @@ -1927,8 +1927,9 @@ def installComponent(self, componentType, system, component, extensions, compone stopFile = os.path.join(runitCompDir, 'control', 't') # This is, e.g., /opt/dirac/control/WorkfloadManagementSystem/Matcher/ controlDir = self.runitDir.replace('runit', 'control') - with open(stopFile, 'w') as fd: - fd.write("""#!/bin/bash + with io.open(stopFile, 'w') as fd: + fd.write(u"""#!/bin/bash + echo %(controlDir)s/%(system)s/%(component)s/stop_%(type)s touch %(controlDir)s/%(system)s/%(component)s/stop_%(type)s """ % {'controlDir': controlDir, @@ -2090,15 +2091,16 @@ def installPortal(self): try: self._createRunitLog(runitWebAppDir) runFile = os.path.join(runitWebAppDir, 'run') - with open(runFile, 'w') as fd: + with io.open(runFile, 'w') as fd: fd.write( - """#!/bin/bash - rcfile=%(bashrc)s - [ -e $rcfile ] && source $rcfile - # - exec 2>&1 - # - exec python %(DIRAC)s/WebAppDIRAC/scripts/dirac-webapp-run.py -p < /dev/null + u"""#!/bin/bash + +rcfile=%(bashrc)s +[[ -e $rcfile ]] && source $rcfile +# +exec 2>&1 +# +exec python %(DIRAC)s/WebAppDIRAC/scripts/dirac-webapp-run.py -p < /dev/null """ % {'bashrc': os.path.join(self.instancePath, 'bashrc'), 'DIRAC': self.linkedRootPath}) @@ -2402,9 +2404,8 @@ def _createMySQLCMDLines(self, dbFile): cmdLines = [] - fd = open(dbFile) - dbLines = fd.readlines() - fd.close() + with io.open(dbFile, 'rt') as fd: + dbLines = fd.readlines() for line in dbLines: # Should we first source an SQL file (is this sql file an extension)? @@ -2412,9 +2413,8 @@ def _createMySQLCMDLines(self, dbFile): sourcedDBbFileName = line.split(' ')[1].replace('\n', '') gLogger.info("Found file to source: %s" % sourcedDBbFileName) sourcedDBbFile = os.path.join(rootPath, sourcedDBbFileName) - fdSourced = open(sourcedDBbFile) - dbLinesSourced = fdSourced.readlines() - fdSourced.close() + with io.open(sourcedDBbFile, 'rt') as fdSourced: + dbLinesSourced = fdSourced.readlines() for lineSourced in dbLinesSourced: if lineSourced.strip(): cmdLines.append(lineSourced.strip()) diff --git a/FrameworkSystem/Client/ProxyManagerClient.py b/FrameworkSystem/Client/ProxyManagerClient.py index c8a42db8c13..67a7ddbf71d 100755 --- a/FrameworkSystem/Client/ProxyManagerClient.py +++ b/FrameworkSystem/Client/ProxyManagerClient.py @@ -1,4 +1,4 @@ -""" ProxyManagementAPI has the functions to "talk" to the ProxyManagement service +""" ProxyManagemerClient has the function to "talk" to the ProxyManagemer service """ import six import os @@ -35,11 +35,11 @@ def __init__(self): def __deleteTemporalFile(self, filename): """ Delete temporal file - :param basestring filename: path to file + :param str filename: path to file """ try: - os.unlink(filename) - except BaseException: + os.remove(filename) + except Exception: pass def clearCaches(self): @@ -89,8 +89,8 @@ def userHasProxy(self, userDN, userGroup, validSeconds=0): """ Check if a user(DN-group) has a proxy in the proxy management Updates internal cache if needed to minimize queries to the service - :param basestring userDN: user DN - :param basestring userGroup: user group + :param str userDN: user DN + :param str userGroup: user group :param int validSeconds: proxy valid time in a seconds :return: S_OK()/S_ERROR() @@ -110,8 +110,8 @@ def getUserPersistence(self, userDN, userGroup, validSeconds=0): """ Check if a user(DN-group) has a proxy in the proxy management Updates internal cache if needed to minimize queries to the service - :param basestring userDN: user DN - :param basestring userGroup: user group + :param str userDN: user DN + :param str userGroup: user group :param int validSeconds: proxy valid time in a seconds :return: S_OK()/S_ERROR() @@ -134,8 +134,8 @@ def getUserPersistence(self, userDN, userGroup, validSeconds=0): def setPersistency(self, userDN, userGroup, persistent): """ Set the persistency for user/group - :param basestring userDN: user DN - :param basestring userGroup: user group + :param str userDN: user DN + :param str userGroup: user group :param boolean persistent: presistent flag :return: S_OK()/S_ERROR() @@ -219,13 +219,13 @@ def downloadProxy(self, userDN, userGroup, limited=False, requiredTimeLeft=1200, cacheTime=14400, proxyToConnect=None, token=None): """ Get a proxy Chain from the proxy management - :param basestring userDN: user DN - :param basestring userGroup: user group + :param str userDN: user DN + :param str userGroup: user group :param boolean limited: if need limited proxy :param int requiredTimeLeft: required proxy live time in a seconds :param int cacheTime: store in a cache time in a seconds :param X509Chain proxyToConnect: proxy as a chain - :param basestring token: valid token to get a proxy + :param str token: valid token to get a proxy :return: S_OK(X509Chain)/S_ERROR() """ @@ -257,14 +257,14 @@ def downloadProxyToFile(self, userDN, userGroup, limited=False, requiredTimeLeft cacheTime=14400, filePath=None, proxyToConnect=None, token=None): """ Get a proxy Chain from the proxy management and write it to file - :param basestring userDN: user DN - :param basestring userGroup: user group + :param str userDN: user DN + :param str userGroup: user group :param boolean limited: if need limited proxy :param int requiredTimeLeft: required proxy live time in a seconds :param int cacheTime: store in a cache time in a seconds - :param basestring filePath: path to save proxy + :param str filePath: path to save proxy :param X509Chain proxyToConnect: proxy as a chain - :param basestring token: valid token to get a proxy + :param str token: valid token to get a proxy :return: S_OK(X509Chain)/S_ERROR() """ @@ -284,14 +284,14 @@ def downloadVOMSProxy(self, userDN, userGroup, limited=False, requiredTimeLeft=1 proxyToConnect=None, token=None): """ Download a proxy if needed and transform it into a VOMS one - :param basestring userDN: user DN - :param basestring userGroup: user group + :param str userDN: user DN + :param str userGroup: user group :param boolean limited: if need limited proxy :param int requiredTimeLeft: required proxy live time in a seconds :param int cacheTime: store in a cache time in a seconds - :param basestring requiredVOMSAttribute: VOMS attr to add to the proxy + :param str requiredVOMSAttribute: VOMS attr to add to the proxy :param X509Chain proxyToConnect: proxy as a chain - :param basestring token: valid token to get a proxy + :param str token: valid token to get a proxy :return: S_OK(X509Chain)/S_ERROR() """ @@ -325,15 +325,15 @@ def downloadVOMSProxyToFile(self, userDN, userGroup, limited=False, requiredTime proxyToConnect=None, token=None): """ Download a proxy if needed, transform it into a VOMS one and write it to file - :param basestring userDN: user DN - :param basestring userGroup: user group + :param str userDN: user DN + :param str userGroup: user group :param boolean limited: if need limited proxy :param int requiredTimeLeft: required proxy live time in a seconds :param int cacheTime: store in a cache time in a seconds - :param basestring requiredVOMSAttribute: VOMS attr to add to the proxy - :param basestring filePath: path to save proxy + :param str requiredVOMSAttribute: VOMS attr to add to the proxy + :param str filePath: path to save proxy :param X509Chain proxyToConnect: proxy as a chain - :param basestring token: valid token to get a proxy + :param str token: valid token to get a proxy :return: S_OK(X509Chain)/S_ERROR() """ @@ -351,9 +351,9 @@ def downloadVOMSProxyToFile(self, userDN, userGroup, limited=False, requiredTime def getPilotProxyFromDIRACGroup(self, userDN, userGroup, requiredTimeLeft=43200, proxyToConnect=None): """ Download a pilot proxy with VOMS extensions depending on the group - :param basestring userDN: user DN - :param basestring userGroup: user group - :param int requiredTimeLeft: required proxy live time in a seconds + :param str userDN: user DN + :param str userGroup: user group + :param int requiredTimeLeft: required proxy live time in seconds :param X509Chain proxyToConnect: proxy as a chain :return: S_OK(X509Chain)/S_ERROR() @@ -361,7 +361,7 @@ def getPilotProxyFromDIRACGroup(self, userDN, userGroup, requiredTimeLeft=43200, # Assign VOMS attribute vomsAttr = Registry.getVOMSAttributeForGroup(userGroup) if not vomsAttr: - gLogger.verbose("No voms attribute assigned to group %s when requested pilot proxy" % userGroup) + gLogger.warn("No voms attribute assigned to group %s when requested pilot proxy" % userGroup) return self.downloadProxy(userDN, userGroup, limited=False, requiredTimeLeft=requiredTimeLeft, proxyToConnect=proxyToConnect) else: @@ -371,8 +371,8 @@ def getPilotProxyFromDIRACGroup(self, userDN, userGroup, requiredTimeLeft=43200, def getPilotProxyFromVOMSGroup(self, userDN, vomsAttr, requiredTimeLeft=43200, proxyToConnect=None): """ Download a pilot proxy with VOMS extensions depending on the group - :param basestring userDN: user DN - :param basestring vomsAttr: VOMS attribute + :param str userDN: user DN + :param str vomsAttr: VOMS attribute :param int requiredTimeLeft: required proxy live time in a seconds :param X509Chain proxyToConnect: proxy as a chain @@ -395,10 +395,10 @@ def getPilotProxyFromVOMSGroup(self, userDN, vomsAttr, requiredTimeLeft=43200, p def getPayloadProxyFromDIRACGroup(self, userDN, userGroup, requiredTimeLeft, token=None, proxyToConnect=None): """ Download a payload proxy with VOMS extensions depending on the group - :param basestring userDN: user DN - :param basestring userGroup: user group + :param str userDN: user DN + :param str userGroup: user group :param int requiredTimeLeft: required proxy live time in a seconds - :param basestring token: valid token to get a proxy + :param str token: valid token to get a proxy :param X509Chain proxyToConnect: proxy as a chain :return: S_OK(X509Chain)/S_ERROR() @@ -417,9 +417,9 @@ def getPayloadProxyFromDIRACGroup(self, userDN, userGroup, requiredTimeLeft, tok def getPayloadProxyFromVOMSGroup(self, userDN, vomsAttr, token, requiredTimeLeft, proxyToConnect=None): """ Download a payload proxy with VOMS extensions depending on the VOMS attr - :param basestring userDN: user DN - :param basestring vomsAttr: VOMS attribute - :param basestring token: valid token to get a proxy + :param str userDN: user DN + :param str vomsAttr: VOMS attribute + :param str token: valid token to get a proxy :param int requiredTimeLeft: required proxy live time in a seconds :param X509Chain proxyToConnect: proxy as a chain @@ -442,10 +442,10 @@ def dumpProxyToFile(self, chain, destinationFile=None, requiredTimeLeft=600): """ Dump a proxy to a file. It's cached so multiple calls won't generate extra files :param X509Chain chain: proxy as a chain - :param basestring destinationFile: path to store proxy + :param str destinationFile: path to store proxy :param int requiredTimeLeft: required proxy live time in a seconds - :return: S_OK(basestring)/S_ERROR() + :return: S_OK(str)/S_ERROR() """ result = chain.hash() if not result['OK']: @@ -477,8 +477,8 @@ def requestToken(self, requesterDN, requesterGroup, numUses=1): """ Request a number of tokens. usesList must be a list of integers and each integer is the number of uses a token must have - :param basestring requesterDN: user DN - :param basestring requesterGroup: user group + :param str requesterDN: user DN + :param str requesterGroup: user group :param int numUses: number of uses :return: S_OK(tuple)/S_ERROR() -- tuple contain token, number uses @@ -573,15 +573,15 @@ def getVOMSAttributes(self, chain): :param X509Chain chain: proxy as a chain - :return: S_OK(basestring)/S_ERROR() + :return: S_OK(str)/S_ERROR() """ return VOMS().getVOMSAttributes(chain) def getUploadedProxyLifeTime(self, DN, group): """ Get the remaining seconds for an uploaded proxy - :param basestring DN: user DN - :param basestring group: group + :param str DN: user DN + :param str group: group :return: S_OK(int)/S_ERROR() """ diff --git a/FrameworkSystem/Client/SystemAdministratorClient.py b/FrameworkSystem/Client/SystemAdministratorClient.py index 784d7b7b824..0e69080403a 100644 --- a/FrameworkSystem/Client/SystemAdministratorClient.py +++ b/FrameworkSystem/Client/SystemAdministratorClient.py @@ -16,7 +16,7 @@ class SystemAdministratorClient(Client): def __init__(self, host, port=None, **kwargs): """ Constructor function. Takes a mandatory host parameter """ - Client.__init__(self, **kwargs) + super(SystemAdministratorClient, self).__init__(**kwargs) if not port: port = SYSADMIN_PORT self.setServer('dips://%s:%s/Framework/SystemAdministrator' % (host, port)) diff --git a/FrameworkSystem/Service/ProxyManagerHandler.py b/FrameworkSystem/Service/ProxyManagerHandler.py index 8f0b3c0b92e..eaee0640179 100644 --- a/FrameworkSystem/Service/ProxyManagerHandler.py +++ b/FrameworkSystem/Service/ProxyManagerHandler.py @@ -4,7 +4,6 @@ __RCSID__ = "$Id$" -from past.builtins import long import six from DIRAC import gLogger, S_OK, S_ERROR from DIRAC.Core.DISET.RequestHandler import RequestHandler @@ -37,7 +36,8 @@ def initializeHandler(cls, serviceInfoDict): gThreadScheduler.addPeriodicTask(900, cls.__proxyDB.purgeExpiredRequests, elapsedTime=900) gThreadScheduler.addPeriodicTask(21600, cls.__proxyDB.purgeLogs) gThreadScheduler.addPeriodicTask(3600, cls.__proxyDB.purgeExpiredProxies) - gLogger.info("MyProxy: %s\n MyProxy Server: %s" % (useMyProxy, cls.__proxyDB.getMyProxyServer())) + if useMyProxy: + gLogger.info("MyProxy: %s\n MyProxy Server: %s" % (useMyProxy, cls.__proxyDB.getMyProxyServer())) return S_OK() def __generateUserProxiesInfo(self): @@ -86,12 +86,12 @@ def export_getUserProxiesInfo(self): # WARN: Since v7r1 requestDelegationUpload method use only first argument! # WARN: Second argument for compatibility with older versions - types_requestDelegationUpload = [[int, long], [basestring, bool, type(None)]] + types_requestDelegationUpload = [six.integer_types, [six.string_types, bool, type(None)]] def export_requestDelegationUpload(self, requestedUploadTime, diracGroup=None): """ Request a delegation. Send a delegation request to client - :param int,long requestedUploadTime: requested live time + :param int requestedUploadTime: requested live time :return: S_OK(dict)/S_ERROR() -- dict contain id and proxy as string of the request """ @@ -120,13 +120,13 @@ def export_requestDelegationUpload(self, requestedUploadTime, diracGroup=None): gLogger.error("Upload request failed", "by %s:%s : %s" % (userName, userGroup, result['Message'])) return result - types_completeDelegationUpload = [six.integer_types, basestring] + types_completeDelegationUpload = [six.integer_types, six.string_types] def export_completeDelegationUpload(self, requestId, pemChain): """ Upload result of delegation :param int,long requestId: identity number - :param basestring pemChain: certificate as string + :param str pemChain: certificate as string :return: S_OK(dict)/S_ERROR() -- dict contain proxies """ @@ -157,8 +157,8 @@ def export_getRegisteredUsers(self, validSecondsRequired=0): def __checkProperties(self, requestedUserDN, requestedUserGroup): """ Check the properties and return if they can only download limited proxies if authorized - :param basestring requestedUserDN: user DN - :param basestring requestedUserGroup: DIRAC group + :param str requestedUserDN: user DN + :param str requestedUserGroup: DIRAC group :return: S_OK(boolean)/S_ERROR() """ @@ -176,7 +176,7 @@ def __checkProperties(self, requestedUserDN, requestedUserGroup): # Not authorized! return S_ERROR("You can't get proxies!") - types_getProxy = [basestring, basestring, basestring, six.integer_types] + types_getProxy = [six.string_types, six.string_types, six.string_types, six.integer_types] def export_getProxy(self, userDN, userGroup, requestPem, requiredLifetime): """ Get a proxy for a userDN/userGroup @@ -202,13 +202,13 @@ def export_getProxy(self, userDN, userGroup, requestPem, requiredLifetime): def __getProxy(self, userDN, userGroup, requestPem, requiredLifetime, forceLimited): """ Internal to get a proxy - :param basestring userDN: user DN - :param basestring userGroup: DIRAC group - :param basestring requestPem: dump of request certificate - :param int,long requiredLifetime: requested live time of proxy + :param str userDN: user DN + :param str userGroup: DIRAC group + :param str requestPem: dump of request certificate + :param int requiredLifetime: requested live time of proxy :param boolean forceLimited: limited proxy - :return: S_OK(basestring)/S_ERROR() + :return: S_OK(str)/S_ERROR() """ retVal = self.__proxyDB.getProxy(userDN, userGroup, requiredLifeTime=requiredLifetime) if not retVal['OK']: @@ -223,7 +223,9 @@ def __getProxy(self, userDN, userGroup, requestPem, requiredLifetime, forceLimit return retVal return S_OK(retVal['Value']) - types_getVOMSProxy = [basestring, basestring, basestring, six.integer_types, [basestring, type(None), bool]] + types_getVOMSProxy = [six.string_types, six.string_types, + six.string_types, six.integer_types, + [six.string_types, type(None), bool]] def export_getVOMSProxy(self, userDN, userGroup, requestPem, requiredLifetime, vomsAttribute=None): """ Get a proxy for a userDN/userGroup @@ -256,21 +258,17 @@ def __getVOMSProxy(self, userDN, userGroup, requestPem, requiredLifetime, vomsAt chain, secsLeft = retVal['Value'] # If possible we return a proxy 1.5 longer than requested requiredLifetime = int(min(secsLeft, requiredLifetime * self.__maxExtraLifeFactor)) - retVal = chain.generateChainFromRequestString(requestPem, - lifetime=requiredLifetime, - requireLimited=forceLimited) - if not retVal['OK']: - return retVal - _credDict = self.getRemoteCredentials() - return S_OK(retVal['Value']) + return chain.generateChainFromRequestString(requestPem, + lifetime=requiredLifetime, + requireLimited=forceLimited) - types_setPersistency = [basestring, basestring, bool] + types_setPersistency = [six.string_types, six.string_types, bool] def export_setPersistency(self, userDN, userGroup, persistentFlag): """ Set the persistency for a given dn/group - :param basestring userDN: user DN - :param basestring userGroup: DIRAC group + :param str userDN: user DN + :param str userGroup: DIRAC group :param boolean persistentFlag: if proxy persistent :return: S_OK()/S_ERROR() @@ -311,8 +309,8 @@ def export_deleteProxyBundle(self, idList): def export_deleteProxy(self, userDN, userGroup): """ Delete a proxy from the DB - :param basestring userDN: user DN - :param basestring userGroup: DIRAC group + :param str userDN: user DN + :param str userGroup: DIRAC group :return: S_OK()/S_ERROR() """ @@ -333,8 +331,8 @@ def export_getContents(self, selDict, sortDict, start, limit): :param dict selDict: selection fields :param list,tuple sortDict: sorting fields - :param int,long start: search limit start - :param int,long start: search limit amount + :param int start: search limit start + :param int start: search limit amount :return: S_OK(dict)/S_ERROR() -- dict contain fields, record list, total records """ @@ -350,21 +348,21 @@ def export_getLogContents(self, selDict, sortDict, start, limit): :param dict selDict: selection fields :param list,tuple sortDict: search filter - :param int,long start: search limit start - :param int,long start: search limit amount + :param int start: search limit start + :param int start: search limit amount :return: S_OK(dict)/S_ERROR() -- dict contain fields, record list, total records """ return self.__proxyDB.getLogsContent(selDict, sortDict, start, limit) - types_generateToken = [basestring, basestring, six.integer_types] + types_generateToken = [six.string_types, six.string_types, six.integer_types] def export_generateToken(self, requesterDN, requesterGroup, tokenUses): """ Generate tokens for proxy retrieval - :param basestring requesterDN: user DN - :param basestring requesterGroup: DIRAC group - :param int,long tokenUses: number of uses + :param str requesterDN: user DN + :param str requesterGroup: DIRAC group + :param int tokenUses: number of uses :return: S_OK(tuple)/S_ERROR() -- tuple contain token, number uses """ @@ -372,7 +370,7 @@ def export_generateToken(self, requesterDN, requesterGroup, tokenUses): self.__proxyDB.logAction("generate tokens", credDict['DN'], credDict['group'], requesterDN, requesterGroup) return self.__proxyDB.generateToken(requesterDN, requesterGroup, numUses=tokenUses) - types_getProxyWithToken = [basestring, basestring, basestring, six.integer_types, basestring] + types_getProxyWithToken = [six.string_types, six.string_types, six.string_types, six.integer_types, six.string_types] def export_getProxyWithToken(self, userDN, userGroup, requestPem, requiredLifetime, token): """ Get a proxy for a userDN/userGroup @@ -401,7 +399,9 @@ def export_getProxyWithToken(self, userDN, userGroup, requestPem, requiredLifeti self.__proxyDB.logAction("download proxy with token", credDict['DN'], credDict['group'], userDN, userGroup) return self.__getProxy(userDN, userGroup, requestPem, requiredLifetime, True) - types_getVOMSProxyWithToken = [basestring, basestring, basestring, six.integer_types, [basestring, type(None)]] + types_getVOMSProxyWithToken = [six.string_types, six.string_types, + six.string_types, six.integer_types, + [six.string_types, type(None)]] def export_getVOMSProxyWithToken(self, userDN, userGroup, requestPem, requiredLifetime, token, vomsAttribute=None): """ Get a proxy for a userDN/userGroup diff --git a/Interfaces/scripts/dirac-admin-add-host.py b/Interfaces/scripts/dirac-admin-add-host.py index 2a96fc4d4e6..215edba3e9c 100755 --- a/Interfaces/scripts/dirac-admin-add-host.py +++ b/Interfaces/scripts/dirac-admin-add-host.py @@ -85,6 +85,19 @@ def addProperty(arg): errorList.append(("commit", result['Message'])) exitCode = 255 +if exitCode == 0: + from DIRAC.FrameworkSystem.Client.ComponentMonitoringClient import ComponentMonitoringClient + cmc = ComponentMonitoringClient() + ret = cmc.hostExists(dict(HostName=hostName)) + if not ret['OK']: + Script.gLogger.error('Cannot check if host is registered in ComponentMonitoring', ret['Message']) + elif ret['Value']: + Script.gLogger.info('Host already registered in ComponentMonitoring') + else: + ret = cmc.addHost(dict(HostName=hostName, CPU='TO_COME')) + if not ret['OK']: + Script.gLogger.error('Failed to add Host to ComponentMonitoring', ret['Message']) + for error in errorList: Script.gLogger.error("%s: %s" % error) diff --git a/ProductionSystem/Client/ProductionClient.py b/ProductionSystem/Client/ProductionClient.py index b77bc1ca9d1..09404335569 100644 --- a/ProductionSystem/Client/ProductionClient.py +++ b/ProductionSystem/Client/ProductionClient.py @@ -3,10 +3,11 @@ __RCSID__ = "$Id$" from DIRAC import gLogger, S_OK, S_ERROR -from DIRAC.Core.Base.Client import Client +from DIRAC.Core.Base.Client import Client, createClient from DIRAC.ProductionSystem.Utilities.StateMachine import ProductionsStateMachine +@createClient('Framework/BundleDelivery') class ProductionClient(Client): """ Exposes the functionality available in the ProductionSystem/ProductionManagerHandler @@ -16,7 +17,7 @@ def __init__(self, **kwargs): """ Simple constructor """ - Client.__init__(self, **kwargs) + super(ProductionClient, self).__init__(**kwargs) self.setServer('Production/ProductionManager') self.prodDescription = {} self.stepCounter = 1 diff --git a/RequestManagementSystem/DB/RequestDB.py b/RequestManagementSystem/DB/RequestDB.py index e8b31eebbc9..0b58e0a9094 100644 --- a/RequestManagementSystem/DB/RequestDB.py +++ b/RequestManagementSystem/DB/RequestDB.py @@ -17,6 +17,7 @@ db holding Request, Operation and File """ import six +import errno import random import datetime @@ -666,7 +667,7 @@ def getRequestCountersWeb(self, groupingAttribute, selectDict): else: summaryQuery = summaryQuery.filter(eval('%s.%s' % (objectType, key)) == value) - summaryQuery = summaryQuery.group_by(groupingAttribute) + summaryQuery = summaryQuery.group_by(eval(groupingAttribute)) try: requestLists = summaryQuery.all() @@ -782,7 +783,7 @@ def getRequestStatus(self, requestID): try: status = session.query(Request._Status).filter(Request.RequestID == requestID).one() except NoResultFound: - return S_ERROR("Request %s does not exist" % requestID) + return S_ERROR(errno.ENOENT, "Request %s does not exist" % requestID) finally: session.close() return S_OK(status[0]) diff --git a/StorageManagementSystem/Client/StorageManagerClient.py b/StorageManagementSystem/Client/StorageManagerClient.py index d40f6060b53..fccbc359a23 100644 --- a/StorageManagementSystem/Client/StorageManagerClient.py +++ b/StorageManagementSystem/Client/StorageManagerClient.py @@ -223,5 +223,5 @@ class StorageManagerClient(Client): """ def __init__(self, **kwargs): - Client.__init__(self, **kwargs) + super(StorageManagerClient, self).__init__(**kwargs) self.setServer('StorageManagement/StorageManager') diff --git a/StorageManagementSystem/DB/StorageManagementDB.sql b/StorageManagementSystem/DB/StorageManagementDB.sql index e1cb451b30e..a446b922fce 100644 --- a/StorageManagementSystem/DB/StorageManagementDB.sql +++ b/StorageManagementSystem/DB/StorageManagementDB.sql @@ -9,7 +9,11 @@ use StorageManagementDB; +DROP TABLE IF EXISTS TaskReplicas; +DROP TABLE IF EXISTS StageRequests; +DROP TABLE IF EXISTS CacheReplicas; DROP TABLE IF EXISTS Tasks; + CREATE TABLE Tasks( TaskID INTEGER AUTO_INCREMENT, Status VARCHAR(32) DEFAULT 'New', @@ -23,7 +27,6 @@ CREATE TABLE Tasks( INDEX(TaskID,Status) )ENGINE=INNODB; -DROP TABLE IF EXISTS TaskReplicas; CREATE TABLE TaskReplicas( TaskID INTEGER(8) NOT NULL REFERENCES Tasks(TaskID), ReplicaID INTEGER(8) NOT NULL REFERENCES CacheReplicas(ReplicaID), @@ -33,7 +36,7 @@ CREATE TABLE TaskReplicas( CREATE TRIGGER taskreplicasAfterInsert AFTER INSERT ON TaskReplicas FOR EACH ROW UPDATE CacheReplicas SET CacheReplicas.Links=CacheReplicas.Links+1 WHERE CacheReplicas.ReplicaID=NEW.ReplicaID; CREATE TRIGGER taskreplicasAfterDelete AFTER DELETE ON TaskReplicas FOR EACH ROW UPDATE CacheReplicas SET CacheReplicas.Links=CacheReplicas.Links-1 WHERE CacheReplicas.ReplicaID=OLD.ReplicaID; -DROP TABLE IF EXISTS CacheReplicas; + CREATE TABLE CacheReplicas( ReplicaID INTEGER AUTO_INCREMENT, Type VARCHAR(32) NOT NULL, @@ -52,7 +55,7 @@ CREATE TABLE CacheReplicas( INDEX(ReplicaID,Status,SE) )ENGINE=INNODB; -DROP TABLE IF EXISTS StageRequests; + CREATE TABLE StageRequests( ReplicaID INTEGER(8) NOT NULL REFERENCES CacheReplicas(ReplicaID), StageStatus VARCHAR(32) DEFAULT 'StageSubmitted', diff --git a/TransformationSystem/Agent/MCExtensionAgent.py b/TransformationSystem/Agent/MCExtensionAgent.py index fb11d4d0ded..953349bdf37 100755 --- a/TransformationSystem/Agent/MCExtensionAgent.py +++ b/TransformationSystem/Agent/MCExtensionAgent.py @@ -80,7 +80,7 @@ def extendTransformation(self, transID, maxTasks): else: statusDict = res['Value'] gLogger.verbose("Current task count for transformation %d" % transID) - for status in sorted(statusDict.keys()): + for status in sorted(statusDict): statusCount = statusDict[status] gLogger.verbose("%s : %s" % (status.ljust(20), str(statusCount).rjust(8))) # Determine the number of tasks to be created diff --git a/TransformationSystem/Agent/TaskManagerAgentBase.py b/TransformationSystem/Agent/TaskManagerAgentBase.py index 241803885a9..879a6774ddb 100644 --- a/TransformationSystem/Agent/TaskManagerAgentBase.py +++ b/TransformationSystem/Agent/TaskManagerAgentBase.py @@ -285,7 +285,7 @@ def _execute(self, threadID): # Queue was cleared, nothing to do continue try: - transID = transIDOPBody.keys()[0] + transID = list(transIDOPBody)[0] operations = transIDOPBody[transID]['Operations'] if transID not in self.transInQueue: self._logWarn("Got a transf not in transInQueue...?", @@ -327,7 +327,7 @@ def _execute(self, threadID): def updateTaskStatus(self, transIDOPBody, clients): """ Updates the task status """ - transID = transIDOPBody.keys()[0] + transID = list(transIDOPBody)[0] method = 'updateTaskStatus' # Get the tasks which are in an UPDATE state, i.e. job statuses + request-specific statuses @@ -410,7 +410,7 @@ def updateTaskStatus(self, transIDOPBody, clients): def updateFileStatus(self, transIDOPBody, clients): """ Update the files status """ - transID = transIDOPBody.keys()[0] + transID = list(transIDOPBody)[0] method = 'updateFileStatus' timeStamp = str(datetime.datetime.utcnow() - datetime.timedelta(minutes=10)) @@ -480,7 +480,7 @@ def updateFileStatus(self, transIDOPBody, clients): def checkReservedTasks(self, transIDOPBody, clients): """ Checking Reserved tasks """ - transID = transIDOPBody.keys()[0] + transID = list(transIDOPBody)[0] method = 'checkReservedTasks' # Select the tasks which have been in Reserved status for more than 1 hour for selected transformations @@ -546,7 +546,7 @@ def submitTasks(self, transIDOPBody, clients): :return: S_OK/S_ERROR """ - transID = transIDOPBody.keys()[0] + transID = list(transIDOPBody)[0] transBody = transIDOPBody[transID]['Body'] owner = transIDOPBody[transID]['Owner'] ownerGroup = transIDOPBody[transID]['OwnerGroup'] diff --git a/TransformationSystem/Agent/TransformationCleaningAgent.py b/TransformationSystem/Agent/TransformationCleaningAgent.py index a5f126965e5..74d49bd24ae 100644 --- a/TransformationSystem/Agent/TransformationCleaningAgent.py +++ b/TransformationSystem/Agent/TransformationCleaningAgent.py @@ -23,16 +23,17 @@ from DIRAC.Core.Utilities.List import breakListIntoChunks from DIRAC.Core.Utilities.Proxy import executeWithUserProxy from DIRAC.Core.Utilities.DErrno import cmpError +from DIRAC.Core.Utilities.ReturnValues import returnSingleResult +from DIRAC.ConfigurationSystem.Client.ConfigurationData import gConfigurationData from DIRAC.ConfigurationSystem.Client.Helpers.Operations import Operations -from DIRAC.Resources.Catalog.FileCatalogClient import FileCatalogClient -from DIRAC.TransformationSystem.Client.TransformationClient import TransformationClient -from DIRAC.WorkloadManagementSystem.Client.WMSClient import WMSClient from DIRAC.DataManagementSystem.Client.DataManager import DataManager -from DIRAC.Resources.Storage.StorageElement import StorageElement -from DIRAC.Core.Utilities.ReturnValues import returnSingleResult +from DIRAC.Resources.Catalog.FileCatalogClient import FileCatalogClient from DIRAC.Resources.Catalog.FileCatalog import FileCatalog -from DIRAC.ConfigurationSystem.Client.ConfigurationData import gConfigurationData +from DIRAC.Resources.Storage.StorageElement import StorageElement from DIRAC.RequestManagementSystem.Client.ReqClient import ReqClient +from DIRAC.TransformationSystem.Client.TransformationClient import TransformationClient +from DIRAC.WorkloadManagementSystem.Client.JobMonitoringClient import JobMonitoringClient +from DIRAC.WorkloadManagementSystem.Client.WMSClient import WMSClient # # agent's name AGENT_NAME = 'Transformation/TransformationCleaningAgent' @@ -83,7 +84,7 @@ def __init__(self, *args, **kwargs): def initialize(self): """ agent initialisation - reading and setting confing opts + reading and setting config opts :param self: self reference """ @@ -123,6 +124,8 @@ def initialize(self): self.reqClient = ReqClient() # # file catalog client self.metadataClient = FileCatalogClient() + # # job monitoring client + self.jobMonitoringClient = JobMonitoringClient() return S_OK() @@ -190,6 +193,81 @@ def execute(self): self.log.error("Could not get the transformations", res['Message']) return S_OK() + def finalize(self): + """ Only at finalization: will clean ancient transformations (remnants) + + 1) get the transformation IDs of jobs that are older than 1 year + 2) find the status of those transformations. Those "Cleaned" and "Archived" will be + cleaned and archived (again) + + Why doing this here? Basically, it's a race: + + 1) the production manager submits a transformation + 2) the TransformationAgent, and a bit later the WorkflowTaskAgent, put such transformation in their internal queue, + so eventually during their (long-ish) cycle they'll work on it. + 3) 1 minute after creating the transformation, the production manager cleans it (by hand, for whatever reason). + So, the status is changed to "Cleaning" + 4) the TransformationCleaningAgent cleans what has been created (maybe, nothing), + then sets the transformation status to "Cleaned" or "Archived" + 5) a bit later the TransformationAgent, and later the WorkflowTaskAgent, kick in, + creating tasks and jobs for a production that's effectively cleaned (but these 2 agents don't know yet). + + Of course, one could make one final check in TransformationAgent or WorkflowTaskAgent, + but these 2 agents are already doing a lot of stuff, and are pretty heavy. + So, we should just clean from time to time. + What I added here is done only when the agent finalize, and it's quite light-ish operation anyway. + """ + res = self.jobMonitoringClient.getJobGroups(None, datetime.utcnow() - timedelta(days=365)) + if not res['OK']: + self.log.error("Failed to get job groups", res['Message']) + return res + transformationIDs = res['Value'] + if transformationIDs: + res = self.transClient.getTransformations({'TransformationID': transformationIDs}) + if not res['OK']: + self.log.error("Failed to get transformations", res['Message']) + return res + transformations = res['Value'] + toClean = [] + toArchive = [] + for transDict in transformations: + if transDict['Status'] == 'Cleaned': + toClean.append(transDict) + if transDict['Status'] == 'Archived': + toArchive.append(transDict) + + for transDict in toClean: + if self.shifterProxy: + self._executeClean(transDict) + else: + self.log.info("Cleaning transformation %(TransformationID)s with %(AuthorDN)s, %(AuthorGroup)s" % + transDict) + executeWithUserProxy(self._executeClean)(transDict, + proxyUserDN=transDict['AuthorDN'], + proxyUserGroup=transDict['AuthorGroup']) + + for transDict in toArchive: + if self.shifterProxy: + self._executeArchive(transDict) + else: + self.log.info("Archiving files for transformation %(TransformationID)s with %(AuthorDN)s, %(AuthorGroup)s" % + transDict) + executeWithUserProxy(self._executeArchive)(transDict, + proxyUserDN=transDict['AuthorDN'], + proxyUserGroup=transDict['AuthorGroup']) + + # Remove JobIDs that were unknown to the TransformationSystem + jobGroupsToCheck = [str(transDict['TransformationID']).zfill(8) for transDict in toClean + toArchive] + res = self.jobMonitoringClient.getJobs({'JobGroup': jobGroupsToCheck}) + if not res['OK']: + return res + jobIDsToRemove = [int(jobID) for jobID in res['Value']] + res = self.__removeWMSTasks(jobIDsToRemove) + if not res['OK']: + return res + + return S_OK() + def _executeClean(self, transDict): """Clean transformation.""" # if transformation is of type `Replication` or `Removal`, there is nothing to clean. @@ -348,7 +426,7 @@ def __getCatalogDirectoryContents(self, directories): activeDirs.extend(dirContents['SubDirs']) allFiles.update(dirContents['Files']) self.log.info("Found %d files" % len(allFiles)) - return S_OK(allFiles.keys()) + return S_OK(list(allFiles)) def cleanTransformationLogFiles(self, directory): """ clean up transformation logs from directory :directory: diff --git a/TransformationSystem/Agent/TransformationPlugin.py b/TransformationSystem/Agent/TransformationPlugin.py index f92d4d429cc..98811de4cdb 100644 --- a/TransformationSystem/Agent/TransformationPlugin.py +++ b/TransformationSystem/Agent/TransformationPlugin.py @@ -177,11 +177,11 @@ def _ByShare(self, shareType='CPU'): return res cpuShares = res['Value'] self.util.logInfo("Obtained the following target shares (%):") - for site in sorted(cpuShares.keys()): + for site in sorted(cpuShares): self.util.logInfo("%s: %.1f" % (site.ljust(15), cpuShares[site])) # Get the existing destinations from the transformationDB - res = self.util.getExistingCounters(requestedSites=cpuShares.keys()) + res = self.util.getExistingCounters(requestedSites=list(cpuShares)) if not res['OK']: self.util.logError("Failed to get existing file share", res['Message']) return res @@ -189,7 +189,7 @@ def _ByShare(self, shareType='CPU'): if existingCount: self.util.logInfo("Existing site utilization (%):") normalisedExistingCount = self.util._normaliseShares(existingCount.copy()) # pylint: disable=protected-access - for se in sorted(normalisedExistingCount.keys()): + for se in sorted(normalisedExistingCount): self.util.logInfo("%s: %.1f" % (se.ljust(15), normalisedExistingCount[se])) # Group the input files by their existing replicas diff --git a/TransformationSystem/Agent/ValidateOutputDataAgent.py b/TransformationSystem/Agent/ValidateOutputDataAgent.py index 32d2ee1aadb..87d194825a6 100755 --- a/TransformationSystem/Agent/ValidateOutputDataAgent.py +++ b/TransformationSystem/Agent/ValidateOutputDataAgent.py @@ -197,7 +197,7 @@ def checkTransformationIntegrity(self, transID): if res['Value']['Failed']: return S_ERROR("Failed to determine the existance of directories") directoryExists = res['Value']['Successful'] - for directory in sorted(directoryExists.keys()): + for directory in sorted(directoryExists): if not directoryExists[directory]: continue iRes = self.consistencyInspector.catalogDirectoryToSE(directory) diff --git a/TransformationSystem/Client/TaskManager.py b/TransformationSystem/Client/TaskManager.py index c028a6e7dbe..eee94d21323 100644 --- a/TransformationSystem/Client/TaskManager.py +++ b/TransformationSystem/Client/TaskManager.py @@ -391,7 +391,7 @@ def getSubmittedFileStatus(self, fileDicts): if transID is None: return S_OK({}) - res = self.transClient.getTransformationTasks({'TransformationID': transID, 'TaskID': taskFiles.keys()}) + res = self.transClient.getTransformationTasks({'TransformationID': transID, 'TaskID': list(taskFiles)}) if not res['OK']: return res requestFiles = {} @@ -668,10 +668,12 @@ def __prepareTasks(self, transBody, taskDict, owner, ownerGroup, ownerDN): method = '__prepareTasks' startTime = time.time() + oJobTemplate = self.jobClass(transBody) oJobTemplate.setOwner(owner) oJobTemplate.setOwnerGroup(ownerGroup) oJobTemplate.setOwnerDN(ownerDN) + try: site = oJobTemplate.workflow.findParameter('Site').getValue() except AttributeError: @@ -679,6 +681,7 @@ def __prepareTasks(self, transBody, taskDict, owner, ownerGroup, ownerDN): jobType = oJobTemplate.workflow.findParameter('JobType').getValue() templateOK = False getOutputDataTiming = 0. + for taskID, paramsDict in taskDict.iteritems(): # Create a job for each task and add it to the taskDict if not templateOK: @@ -828,8 +831,8 @@ def _checkSickTransformations(self, transID): """ Check if the transformation is in the transformations to be processed at Hospital or Clinic """ transID = int(transID) - clinicPath = "Hospital/Transformations" - if transID in set(int(x) for x in self.opsH.getValue(clinicPath, [])): + clinicPath = "Hospital" + if transID in set(int(x) for x in self.opsH.getValue(os.path.join(clinicPath, "Transformations"), [])): return clinicPath if "Clinics" in self.opsH.getSections("Hospital").get('Value', []): basePath = os.path.join("Hospital", "Clinics") diff --git a/TransformationSystem/Client/Transformation.py b/TransformationSystem/Client/Transformation.py index a29eb2943b5..0cff5c91eaa 100644 --- a/TransformationSystem/Client/Transformation.py +++ b/TransformationSystem/Client/Transformation.py @@ -187,7 +187,7 @@ def __getattr__(self, name): def __getParam(self): if self.item_called == 'Available': - return S_OK(self.paramTypes.keys()) + return S_OK(list(self.paramTypes)) if self.item_called == 'Parameters': return S_OK(self.paramValues) if self.item_called in self.paramValues: diff --git a/TransformationSystem/Client/TransformationCLI.py b/TransformationSystem/Client/TransformationCLI.py index cdf02a85909..d209c0960bc 100644 --- a/TransformationSystem/Client/TransformationCLI.py +++ b/TransformationSystem/Client/TransformationCLI.py @@ -541,11 +541,11 @@ def do_replicas(self, args): if not res['OK']: print("failed to get any replica information: %s" % res['Message']) return - for lfn in sorted(res['Value']['Failed'].keys()): + for lfn in sorted(res['Value']['Failed']): error = res['Value']['Failed'][lfn] print("failed to get replica information for %s: %s" % (lfn, error)) - for lfn in sorted(res['Value']['Successful'].keys()): - ses = sorted(res['Value']['Successful'][lfn].keys()) + for lfn in sorted(res['Value']['Successful']): + ses = sorted(res['Value']['Successful'][lfn]) outStr = "%s :" % lfn.ljust(100) for se in ses: outStr = "%s %s" % (outStr, se.ljust(15)) @@ -568,10 +568,10 @@ def do_addFile(self, args): if not res['OK']: print("failed to add any files: %s" % res['Message']) return - for lfn in sorted(res['Value']['Failed'].keys()): + for lfn in sorted(res['Value']['Failed']): error = res['Value']['Failed'][lfn] print("failed to add %s: %s" % (lfn, error)) - for lfn in sorted(res['Value']['Successful'].keys()): + for lfn in sorted(res['Value']['Successful']): print("added %s" % lfn) def do_removeFile(self, args): @@ -587,10 +587,10 @@ def do_removeFile(self, args): if not res['OK']: print("failed to remove any files: %s" % res['Message']) return - for lfn in sorted(res['Value']['Failed'].keys()): + for lfn in sorted(res['Value']['Failed']): error = res['Value']['Failed'][lfn] print("failed to remove %s: %s" % (lfn, error)) - for lfn in sorted(res['Value']['Successful'].keys()): + for lfn in sorted(res['Value']['Successful']): print("removed %s" % lfn) def do_addReplica(self, args): @@ -610,10 +610,10 @@ def do_addReplica(self, args): if not res['OK']: print("failed to add replica: %s" % res['Message']) return - for lfn in sorted(res['Value']['Failed'].keys()): + for lfn in sorted(res['Value']['Failed']): error = res['Value']['Failed'][lfn] print("failed to add replica: %s" % (error)) - for lfn in sorted(res['Value']['Successful'].keys()): + for lfn in sorted(res['Value']['Successful']): print("added %s" % lfn) def do_removeReplica(self, args): @@ -633,10 +633,10 @@ def do_removeReplica(self, args): if not res['OK']: print("failed to remove replica: %s" % res['Message']) return - for lfn in sorted(res['Value']['Failed'].keys()): + for lfn in sorted(res['Value']['Failed']): error = res['Value']['Failed'][lfn] print("failed to remove replica: %s" % (error)) - for lfn in sorted(res['Value']['Successful'].keys()): + for lfn in sorted(res['Value']['Successful']): print("removed %s" % lfn) def do_setReplicaStatus(self, args): @@ -663,10 +663,10 @@ def do_setReplicaStatus(self, args): if not res['OK']: print("failed to set replica status: %s" % res['Message']) return - for lfn in sorted(res['Value']['Failed'].keys()): + for lfn in sorted(res['Value']['Failed']): error = res['Value']['Failed'][lfn] print("failed to set replica status: %s" % (error)) - for lfn in sorted(res['Value']['Successful'].keys()): + for lfn in sorted(res['Value']['Successful']): print("updated replica status %s" % lfn) diff --git a/TransformationSystem/Client/TransformationClient.py b/TransformationSystem/Client/TransformationClient.py index 012ab9345c9..1489717ef6d 100644 --- a/TransformationSystem/Client/TransformationClient.py +++ b/TransformationSystem/Client/TransformationClient.py @@ -61,7 +61,7 @@ def __init__(self, **kwargs): """ Simple constructor """ - Client.__init__(self, **kwargs) + super(TransformationClient, self).__init__(**kwargs) opsH = Operations() self.maxResetCounter = opsH.getValue('Transformations/FilesMaxResetCounter', 10) diff --git a/TransformationSystem/DB/TransformationDB.py b/TransformationSystem/DB/TransformationDB.py index e75ba36d298..1b1fd24ceb1 100755 --- a/TransformationSystem/DB/TransformationDB.py +++ b/TransformationSystem/DB/TransformationDB.py @@ -524,7 +524,7 @@ def addFilesToTransformation(self, transName, lfns, connection=False): # Attach files to transformation successful = {} if fileIDs: - res = self.__addFilesToTransformation(transID, fileIDs.keys(), connection=connection) + res = self.__addFilesToTransformation(transID, list(fileIDs), connection=connection) if not res['OK']: return res for fileID in fileIDs: @@ -550,7 +550,7 @@ def getTransformationFiles(self, condDict=None, older=None, newer=None, timeStam if not res['OK']: return res originalFileIDs = res['Value'][0] - condDict['FileID'] = originalFileIDs.keys() + condDict['FileID'] = list(originalFileIDs) for val in condDict.itervalues(): if not val: @@ -1536,10 +1536,10 @@ def removeFile(self, lfns, connection=False): if lfn not in lfnFilesIDs: successful[lfn] = 'File does not exist' if fileIDs: - res = self.__setTransformationFileStatus(fileIDs.keys(), 'Deleted', connection=connection) + res = self.__setTransformationFileStatus(list(fileIDs), 'Deleted', connection=connection) if not res['OK']: return res - res = self.__setDataFileStatus(fileIDs.keys(), 'Deleted', connection=connection) + res = self.__setDataFileStatus(list(fileIDs), 'Deleted', connection=connection) if not res['OK']: return S_ERROR("TransformationDB.removeFile: Failed to remove files.") for lfn in lfnFilesIDs: diff --git a/TransformationSystem/Service/TransformationManagerHandler.py b/TransformationSystem/Service/TransformationManagerHandler.py index c31e8b24815..6cd8a1b6fcb 100644 --- a/TransformationSystem/Service/TransformationManagerHandler.py +++ b/TransformationSystem/Service/TransformationManagerHandler.py @@ -392,7 +392,7 @@ def export_removeFile(self, lfns): """ Interface provides [ LFN1, LFN2, ... ] """ if isinstance(lfns, dict): - lfns = lfns.keys() + lfns = list(lfns) res = database.removeFile(lfns) return self._parseRes(res) diff --git a/TransformationSystem/Utilities/TransformationInfo.py b/TransformationSystem/Utilities/TransformationInfo.py index ff51d8e4a7e..a6a0bc97938 100644 --- a/TransformationSystem/Utilities/TransformationInfo.py +++ b/TransformationSystem/Utilities/TransformationInfo.py @@ -155,7 +155,7 @@ def cleanOutputs(self, jobInfo): for lfn, err in result['Value']['Failed'].items(): reason = str(err) errorReasons[reason].append(lfn) - successfullyRemoved += len(result['Value']['Successful'].keys()) + successfullyRemoved += len(result['Value']['Successful']) for reason, lfns in errorReasons.items(): self.log.error("Failed to remove %d files with error: %s" % (len(lfns), reason)) self.log.notice("Successfully removed %d files" % successfullyRemoved) diff --git a/TransformationSystem/scripts/dirac-transformation-archive.py b/TransformationSystem/scripts/dirac-transformation-archive.py index 21c030ef086..3577bb39c27 100755 --- a/TransformationSystem/scripts/dirac-transformation-archive.py +++ b/TransformationSystem/scripts/dirac-transformation-archive.py @@ -5,14 +5,14 @@ from __future__ import print_function import sys -from DIRAC.Core.Base.Script import parseCommandLine +from DIRAC.Core.Base.Script import parseCommandLine, getPositionalArgs parseCommandLine() -if len(sys.argv) < 2: +if not getPositionalArgs(): print('Usage: dirac-transformation-archive transID [transID] [transID]') sys.exit() else: - transIDs = [int(arg) for arg in sys.argv[1:]] + transIDs = [int(arg) for arg in getPositionalArgs()] from DIRAC.TransformationSystem.Agent.TransformationCleaningAgent import TransformationCleaningAgent from DIRAC.TransformationSystem.Client.TransformationClient import TransformationClient diff --git a/TransformationSystem/scripts/dirac-transformation-clean.py b/TransformationSystem/scripts/dirac-transformation-clean.py index 0e07e23120d..8d808869e69 100755 --- a/TransformationSystem/scripts/dirac-transformation-clean.py +++ b/TransformationSystem/scripts/dirac-transformation-clean.py @@ -5,18 +5,17 @@ from __future__ import print_function import sys -from DIRAC.Core.Base.Script import parseCommandLine +from DIRAC.Core.Base.Script import parseCommandLine, getPositionalArgs parseCommandLine() from DIRAC.TransformationSystem.Agent.TransformationCleaningAgent import TransformationCleaningAgent from DIRAC.TransformationSystem.Client.TransformationClient import TransformationClient -if len(sys.argv) < 2: +if not getPositionalArgs(): print('Usage: dirac-transformation-clean transID [transID] [transID]') sys.exit() else: - transIDs = [int(arg) for arg in sys.argv[1:]] - + transIDs = [int(arg) for arg in getPositionalArgs()] agent = TransformationCleaningAgent('Transformation/TransformationCleaningAgent', 'Transformation/TransformationCleaningAgent', diff --git a/TransformationSystem/scripts/dirac-transformation-remove-output.py b/TransformationSystem/scripts/dirac-transformation-remove-output.py index a67f9ba33ae..31744773638 100755 --- a/TransformationSystem/scripts/dirac-transformation-remove-output.py +++ b/TransformationSystem/scripts/dirac-transformation-remove-output.py @@ -5,14 +5,14 @@ from __future__ import print_function import sys -from DIRAC.Core.Base.Script import parseCommandLine +from DIRAC.Core.Base.Script import parseCommandLine, getPositionalArgs parseCommandLine() -if len(sys.argv) < 2: +if not getPositionalArgs(): print('Usage: dirac-transformation-remove-output transID [transID] [transID]') sys.exit() else: - transIDs = [int(arg) for arg in sys.argv[1:]] + transIDs = [int(arg) for arg in getPositionalArgs()] from DIRAC.TransformationSystem.Agent.TransformationCleaningAgent import TransformationCleaningAgent from DIRAC.TransformationSystem.Client.TransformationClient import TransformationClient diff --git a/TransformationSystem/scripts/dirac-transformation-verify-outputdata.py b/TransformationSystem/scripts/dirac-transformation-verify-outputdata.py index 0202e77bdb1..1476d11eb4a 100755 --- a/TransformationSystem/scripts/dirac-transformation-verify-outputdata.py +++ b/TransformationSystem/scripts/dirac-transformation-verify-outputdata.py @@ -5,14 +5,14 @@ from __future__ import print_function import sys -from DIRAC.Core.Base.Script import parseCommandLine +from DIRAC.Core.Base.Script import parseCommandLine, getPositionalArgs parseCommandLine() -if len(sys.argv) < 2: +if not getPositionalArgs(): print('Usage: dirac-transformation-verify-outputdata transID [transID] [transID]') sys.exit() else: - transIDs = [int(arg) for arg in sys.argv[1:]] + transIDs = [int(arg) for arg in getPositionalArgs()] from DIRAC.TransformationSystem.Agent.ValidateOutputDataAgent import ValidateOutputDataAgent from DIRAC.TransformationSystem.Client.TransformationClient import TransformationClient diff --git a/TransformationSystem/test/Test_TransformationInfo.py b/TransformationSystem/test/Test_TransformationInfo.py index beb2a7141e1..30ab7a5dba8 100644 --- a/TransformationSystem/test/Test_TransformationInfo.py +++ b/TransformationSystem/test/Test_TransformationInfo.py @@ -352,7 +352,7 @@ def test_getJobs(tiFixture): assert ndone == 3 assert nfailed == 3 assert isinstance(jobs, OrderedDict) - assert [56, 89, 123, 456, 789, 1123] == jobs.keys() + assert [56, 89, 123, 456, 789, 1123] == list(jobs) # All ERROR tiFixture.jobMon.getJobs = Mock() diff --git a/WorkloadManagementSystem/Agent/SiteDirector.py b/WorkloadManagementSystem/Agent/SiteDirector.py index 6546b2e26d6..922b2cfbbf8 100644 --- a/WorkloadManagementSystem/Agent/SiteDirector.py +++ b/WorkloadManagementSystem/Agent/SiteDirector.py @@ -536,7 +536,7 @@ def submitPilots(self): totalWaitingPilots = 0 manyWaitingPilotsFlag = False if self.pilotWaitingFlag: - tqIDList = additionalInfo.keys() + tqIDList = list(additionalInfo) result = pilotAgentsDB.countPilots({'TaskQueueID': tqIDList, 'Status': WAITING_PILOT_STATUS}, None) @@ -659,7 +659,7 @@ def _ifAndWhereToSubmit(self): def monitorJobsQueuesPilots(self, matchingTQs): """ Just printout of jobs queues and pilots status in TQ """ - tqIDList = matchingTQs.keys() + tqIDList = list(matchingTQs) result = pilotAgentsDB.countPilots({'TaskQueueID': tqIDList, 'Status': WAITING_PILOT_STATUS}, None) diff --git a/WorkloadManagementSystem/Client/PilotsLoggingClient.py b/WorkloadManagementSystem/Client/PilotsLoggingClient.py index 87eb9ca17ca..2c3c03a494d 100644 --- a/WorkloadManagementSystem/Client/PilotsLoggingClient.py +++ b/WorkloadManagementSystem/Client/PilotsLoggingClient.py @@ -12,7 +12,7 @@ class PilotsLoggingClient(Client): """ def __init__(self, **kwargs): - Client.__init__(self, **kwargs) + super(PilotsLoggingClient, self).__init__(**kwargs) self.setServer('WorkloadManagement/PilotsLogging') def addPilotsLogging(self, pilotUUID, timestamp, source, phase, status, messageContent): diff --git a/WorkloadManagementSystem/PilotAgent/test/Test_Pilot.py b/WorkloadManagementSystem/PilotAgent/test/Test_Pilot.py index 8e986940958..a183bf9f959 100644 --- a/WorkloadManagementSystem/PilotAgent/test/Test_Pilot.py +++ b/WorkloadManagementSystem/PilotAgent/test/Test_Pilot.py @@ -2,54 +2,33 @@ """ # imports -import unittest import json import os +import sys + +if "--no-cov" in sys.argv: + del sys.argv[sys.argv.index('--no-cov')] from DIRAC.WorkloadManagementSystem.PilotAgent.pilotTools import PilotParams, CommandBase from DIRAC.WorkloadManagementSystem.PilotAgent.pilotCommands import GetPilotVersion -class PilotTestCase( unittest.TestCase ): - """ Base class for the Agents test cases - """ - def setUp( self ): - self.pp = PilotParams() - - def tearDown( self ): - try: - os.remove('pilot.out') - os.remove( 'pilot.json' ) - os.remove( 'pilot.json-local' ) - except OSError: - pass - - -class CommandsTestCase( PilotTestCase ): - - def test_commandBase(self): - cb = CommandBase(self.pp) - returnCode, _outputData = cb.executeAndGetOutput("ls") - self.assertEqual(returnCode, 0) - - def test_GetPilotVersion( self ): - - # Now defining a local file for test, and all the necessary parameters - fp = open( 'pilot.json', 'w' ) - json.dump( {'TestSetup':{'Version':['v1r1', 'v2r2']}}, fp ) - fp.close() - self.pp.setup = 'TestSetup' - self.pp.pilotCFGFileLocation = 'file://%s' % os.getcwd() - gpv = GetPilotVersion( self.pp ) - self.assertIsNone( gpv.execute() ) - self.assertEqual( gpv.pp.releaseVersion, 'v1r1' ) - -############################################################################# -# Test Suite run -############################################################################# - -if __name__ == '__main__': - suite = unittest.defaultTestLoader.loadTestsFromTestCase( PilotTestCase ) - suite.addTest( unittest.defaultTestLoader.loadTestsFromTestCase( CommandsTestCase ) ) - testResult = unittest.TextTestRunner( verbosity = 2 ).run( suite ) -# EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF# +def test_GetPilotVersion(): + pp = PilotParams() + # Now defining a local file for test, and all the necessary parameters + fp = open('pilot.json', 'w') + json.dump({'TestSetup': {'Version': ['v1r1', 'v2r2']}}, fp) + fp.close() + pp.setup = 'TestSetup' + pp.pilotCFGFileLocation = 'file://%s' % os.getcwd() + gpv = GetPilotVersion(pp) + result = gpv.execute() + assert result is None + assert gpv.pp.releaseVersion == 'v1r1' + + +def test_commandBase(): + pp = PilotParams() + cb = CommandBase(pp) + returnCode, _outputData = cb.executeAndGetOutput("ls") + assert returnCode == 0 diff --git a/WorkloadManagementSystem/Service/JobMonitoringHandler.py b/WorkloadManagementSystem/Service/JobMonitoringHandler.py index ccba404d2ca..3167a375e88 100755 --- a/WorkloadManagementSystem/Service/JobMonitoringHandler.py +++ b/WorkloadManagementSystem/Service/JobMonitoringHandler.py @@ -74,80 +74,79 @@ def initialize(self): types_getApplicationStates = [] @staticmethod - def export_getApplicationStates(): + def export_getApplicationStates(condDict=None, older=None, newer=None): """ Return Distinct Values of ApplicationStatus job Attribute in WMS """ - return gJobDB.getDistinctJobAttributes('ApplicationStatus') + return gJobDB.getDistinctJobAttributes('ApplicationStatus', condDict, older, newer) ############################################################################## types_getJobTypes = [] @staticmethod - def export_getJobTypes(): + def export_getJobTypes(condDict=None, older=None, newer=None): """ Return Distinct Values of JobType job Attribute in WMS """ - return gJobDB.getDistinctJobAttributes('JobType') + return gJobDB.getDistinctJobAttributes('JobType', condDict, older, newer) ############################################################################## types_getOwners = [] @staticmethod - def export_getOwners(): + def export_getOwners(condDict=None, older=None, newer=None): """ Return Distinct Values of Owner job Attribute in WMS """ - return gJobDB.getDistinctJobAttributes('Owner') + return gJobDB.getDistinctJobAttributes('Owner', condDict, older, newer) ############################################################################## types_getProductionIds = [] @staticmethod - def export_getProductionIds(): + def export_getProductionIds(condDict=None, older=None, newer=None): """ Return Distinct Values of ProductionId job Attribute in WMS """ - return gJobDB.getDistinctJobAttributes('JobGroup') + return gJobDB.getDistinctJobAttributes('JobGroup', condDict, older, newer) ############################################################################## types_getJobGroups = [] @staticmethod - def export_getJobGroups(condDict=None, cutDate=None): + def export_getJobGroups(condDict=None, older=None, cutDate=None): """ Return Distinct Values of ProductionId job Attribute in WMS """ - return gJobDB.getDistinctJobAttributes('JobGroup', condDict, - newer=cutDate) + return gJobDB.getDistinctJobAttributes('JobGroup', condDict, older, newer=cutDate) ############################################################################## types_getSites = [] @staticmethod - def export_getSites(): + def export_getSites(condDict=None, older=None, newer=None): """ Return Distinct Values of Site job Attribute in WMS """ - return gJobDB.getDistinctJobAttributes('Site') + return gJobDB.getDistinctJobAttributes('Site', condDict, older, newer) ############################################################################## types_getStates = [] @staticmethod - def export_getStates(): + def export_getStates(condDict=None, older=None, newer=None): """ Return Distinct Values of Status job Attribute in WMS """ - return gJobDB.getDistinctJobAttributes('Status') + return gJobDB.getDistinctJobAttributes('Status', condDict, older, newer) ############################################################################## types_getMinorStates = [] @staticmethod - def export_getMinorStates(): + def export_getMinorStates(condDict=None, older=None, newer=None): """ Return Distinct Values of Minor Status job Attribute in WMS """ - return gJobDB.getDistinctJobAttributes('MinorStatus') + return gJobDB.getDistinctJobAttributes('MinorStatus', condDict, older, newer) ############################################################################## types_getJobs = [] diff --git a/pytest.ini b/pytest.ini index 74fb4a3f68c..81dd39cb17f 100644 --- a/pytest.ini +++ b/pytest.ini @@ -5,4 +5,4 @@ python_files=Test_*.py assert*.py # The reason here is that we do nasty things with the pythonpath # in order to make sure that M2Crypto and pyGSI do not step # on each other's feet -addopts = -rx -v --color=yes --showlocals --tb=long --ignore=tests --ignore=Core/Security/test --cov=. --cov-report term-missing +addopts = -rx -v --color=yes --showlocals --tb=long --ignore=tests --ignore=Core/Security/test diff --git a/release.notes b/release.notes index 3307925a814..b25e29b728a 100644 --- a/release.notes +++ b/release.notes @@ -1,4 +1,4 @@ -[v7r2-pre10] +[v7r2-pre11] FIX: python 2-3 compatibility fixes @@ -27,6 +27,21 @@ CHANGE: (#4235) Removes locals() way of passing parameters *tests NEW: (#4179) Set up Gitlab CI pipeline using Docker containers +[v7r1p6] + +*Framework +CHANGE: (#4643) BundleDeliveryClient: inheriting from Client + +*SMS +FIX: (#4645) StorageManagementDB - drop the tables in the correct order to avoid foreign key errors + +*TS +NEW: (#4641) TransformationCleaningAgent will (re)clean very old transformations that are still in the system + +*tests +FIX: (#4645) dropDBs uses real array; +FIX: (#4645) remove readonly variables + [v7r1p5] *Framework @@ -176,6 +191,26 @@ FIX: (#4551) align ProxyDB test to current changes NEW: (#4289) Document how to run integration tests in docker NEW: (#4551) add DNProperties description to Registry/Users subsection +[v7r0p28] + +*Core +FIX: (#4642) M2Crypto closes the socket after dereferencing the Connection instance + +*DMS +FIX: (#4644) Cancel FTS3 Operation if the RMS request does not exist + +*RMS +NEW: (#4644) getRequestStatus returns ENOENT if the request does not exist + +*TS +FIX: (#4647) TaskManager - hospital sites were not looked for correctly, which + generated an exception +FIX: (#4656) fix parsing of command line flags (e.g., -ddd) for dirac-transformation-archive/clean/remove-output/verify-outputdata + +*Interfaces +CHANGE: (#4652) dirac-admin-add-host now inserts hosts into the ComponentMonitoring if the host + is not yet known + [v7r0p27] *Framework @@ -680,6 +715,14 @@ NEW: (#4170) added Production system documentation CHANGE: (#4224) Pilot 3 is the default NEW: (#4244) Added a few notes on using the JobParameters on ElasticSearch database +[v6r22p31] + +*DMS +FIX: (#4646) Print error from dirac-dms-add-file if input LFN list file is missing. + +*RMS +FIX: (#4657) RequestDB - fix getRequestCountersWeb error in DIRACOS + [v6r22p30] *DataManagementSystem diff --git a/tests/Integration/WorkloadManagementSystem/Test_Client_WMS.py b/tests/Integration/WorkloadManagementSystem/Test_Client_WMS.py index 87cf125b429..780db269479 100644 --- a/tests/Integration/WorkloadManagementSystem/Test_Client_WMS.py +++ b/tests/Integration/WorkloadManagementSystem/Test_Client_WMS.py @@ -26,7 +26,7 @@ # pylint: disable=protected-access,wrong-import-position,invalid-name from __future__ import print_function -from past.builtins import long + import unittest import sys import datetime @@ -365,6 +365,15 @@ def test_JobStateUpdateAndJobMonitoringMultuple(self): self.assertTrue(res['OK'], res.get('Message')) res = jobMonitor.getJobGroups() self.assertTrue(res['OK'], res.get('Message')) + resJG_empty = res['Value'] + res = jobMonitor.getJobGroups(None, datetime.datetime.utcnow()) + self.assertTrue(res['OK'], res.get('Message')) + resJG_olderThanNow = res['Value'] + self.assertEqual(resJG_empty, resJG_olderThanNow) + res = jobMonitor.getJobGroups(None, datetime.datetime.utcnow() - datetime.timedelta(days=365)) + self.assertTrue(res['OK'], res.get('Message')) + resJG_olderThanOneYear = res['Value'] + self.assertTrue(set(resJG_olderThanOneYear).issubset(set(resJG_olderThanNow))) res = jobMonitor.getStates() self.assertTrue(res['OK'], res.get('Message')) self.assertTrue(sorted(res['Value']) in [['Received'], sorted(['Received', 'Waiting'])]) @@ -382,9 +391,7 @@ def test_JobStateUpdateAndJobMonitoringMultuple(self): try: self.assertTrue( res['Value'].get('Received') + - res['Value'].get('Waiting') >= long( - len(lfnss) * - len(types))) + res['Value'].get('Waiting') >= int(len(lfnss) * len(types))) except TypeError: pass res = jobMonitor.getJobsSummary(jobIDs) diff --git a/tests/Jenkins/dirac_ci.sh b/tests/Jenkins/dirac_ci.sh index 387848c9ce8..9e3472802fc 100644 --- a/tests/Jenkins/dirac_ci.sh +++ b/tests/Jenkins/dirac_ci.sh @@ -66,11 +66,11 @@ fi # Creating default structure mkdir -p "$WORKSPACE/TestCode" # Where the test code resides -readonly TESTCODE=${_} +TESTCODE=${_} mkdir -p "$WORKSPACE/ServerInstallDIR" # Where servers are installed -readonly SERVERINSTALLDIR=${_} +SERVERINSTALLDIR=${_} mkdir -p "$WORKSPACE/ClientInstallDIR" # Where clients are installed -readonly CLIENTINSTALLDIR=${_} +CLIENTINSTALLDIR=${_} # Location of the CFG file to be used (this can be replaced by the extensions) INSTALL_CFG_FILE="${TESTCODE}/DIRAC/tests/Jenkins/install.cfg" diff --git a/tests/Jenkins/utilities.sh b/tests/Jenkins/utilities.sh index 5268ad15e72..ee1a1b9292d 100644 --- a/tests/Jenkins/utilities.sh +++ b/tests/Jenkins/utilities.sh @@ -892,8 +892,9 @@ diracMVDFCDB(){ dropDBs(){ echo '==> [dropDBs]' - dbs=$(cut -d ' ' -f 2 < databases | cut -d '.' -f 1 | grep -v ^RequestDB | grep -v ^FileCatalogDB) - python "${TESTCODE}/DIRAC/tests/Jenkins/dirac-drop-db.py" "$dbs" "${DEBUG}" + # make dbs a real array to avoid future mistake with escaping + mapfile -t dbs < <(cut -d ' ' -f 2 < /tmp/databases.txt | cut -d '.' -f 1 | grep -v ^RequestDB | grep -v ^FileCatalogDB) + python "${TESTCODE}/DIRAC/tests/Jenkins/dirac-drop-db.py" "${dbs[@]}" "${DEBUG}" } #------------------------------------------------------------------------------- diff --git a/virtualmachine/Vagrantfile b/virtualmachine/Vagrantfile index 9337da73b4c..2a5516ae3cf 100644 --- a/virtualmachine/Vagrantfile +++ b/virtualmachine/Vagrantfile @@ -50,7 +50,8 @@ Vagrant.configure("2") do |config| # the path on the host to the actual folder. The second argument is # the path on the guest to mount the folder. And the optional third # argument is a set of non-required options. - config.vm.synced_folder "..", "/opt/dirac/versions/hostcode" + config.vm.synced_folder "..", "/home/vagrant/hostcode/DIRAC" + config.vm.synced_folder "../../WebAppDIRAC", "/home/vagrant/hostcode/WebAppDIRAC" config.vm.synced_folder "../../certs", "/home/vagrant/.globus" # Provider-specific configuration so you can fine-tune various @@ -77,16 +78,16 @@ Vagrant.configure("2") do |config| # config.vm.provision "shell", inline: <<-SHELL # #!/bin/bash - # # Create DIRAC dirs - # mkdir -p /opt/dirac/DIRAC && \ - # mkdir -p /opt/dirac/etc/grid-security/certificates && \ - # cd /opt/dirac + # sudo chown vagrant:vagrant hostcode/ + # ln -s hostcode/DIRAC/ DIRAC + # # Create etc dir and link it + # mkdir -p /home/vagrant/etc/grid-security/certificates + # ln -s /home/vagrant/etc /home/vagrant/hostcode/etc # # Installing DIRAC in /opt/dirac # curl -L -o dirac-install https://raw.githubusercontent.com/DIRACGrid/DIRAC/integration/Core/scripts/dirac-install.py && \ # chmod +x dirac-install && \ # ./dirac-install -r $DIRAC_VERSION -t client && \ - # rm -rf /opt/dirac/.installCache && \ # rm dirac-install && \ # ln -s /etc/grid-security/certificates/ /opt/dirac/etc/grid-security/certificates