diff --git a/docs/source/UserGuide/Tutorials/ManagingUserCredentials/index.rst b/docs/source/UserGuide/Tutorials/ManagingUserCredentials/index.rst index 7f0283339a6..55d7d692601 100644 --- a/docs/source/UserGuide/Tutorials/ManagingUserCredentials/index.rst +++ b/docs/source/UserGuide/Tutorials/ManagingUserCredentials/index.rst @@ -164,11 +164,11 @@ Getting the proxy information $ dirac-proxy-get-uploaded-info Checking for DNs /O=GRID-FR/C=FR/O=CNRS/OU=CPPM/CN=Vanessa Hamar - -------------------------------------------------------------------------------------------------------- - | UserDN | UserGroup | ExpirationTime | PersistentFlag | - -------------------------------------------------------------------------------------------------------- - | /O=GRID-FR/C=FR/O=CNRS/OU=CPPM/CN=Vanessa Hamar | dirac_user | 2011-06-29 12:04:25 | True | - -------------------------------------------------------------------------------------------------------- + --------------------------------------------------------------------------------------- + | UserDN | UserGroup | ExpirationTime | + --------------------------------------------------------------------------------------- + | /O=GRID-FR/C=FR/O=CNRS/OU=CPPM/CN=Vanessa Hamar | dirac_user | 2011-06-29 12:04:25 | + --------------------------------------------------------------------------------------- - The same can be checked in the Web Portal at the following location:: diff --git a/docs/source/UserGuide/WebPortalReference/ManageProxies/index.rst b/docs/source/UserGuide/WebPortalReference/ManageProxies/index.rst index 648d0e9075a..fbdc2242fe4 100644 --- a/docs/source/UserGuide/WebPortalReference/ManageProxies/index.rst +++ b/docs/source/UserGuide/WebPortalReference/ManageProxies/index.rst @@ -37,9 +37,6 @@ Columns Date until user certificate is valid. - **Persistent** - - Show if a proxy is persistent (value=true) or not (value=false). You can choose to display the proxies by group or grouping by field choosing them in the menu, activated by pressing on a menu button. diff --git a/src/DIRAC/FrameworkSystem/Client/ProxyManagerClient.py b/src/DIRAC/FrameworkSystem/Client/ProxyManagerClient.py index 5da4b09e528..12bfa464354 100755 --- a/src/DIRAC/FrameworkSystem/Client/ProxyManagerClient.py +++ b/src/DIRAC/FrameworkSystem/Client/ProxyManagerClient.py @@ -113,57 +113,6 @@ def userHasProxy(self, userDN, userGroup, validSeconds=0): return S_OK(False) - @gUsersSync - 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 str userDN: user DN - :param str userGroup: user group - :param int validSeconds: proxy valid time in a seconds - - :return: S_OK()/S_ERROR() - """ - cacheKey = (userDN, userGroup) - userData = self.__usersCache.get(cacheKey, validSeconds) - if userData: - if userData["persistent"]: - return S_OK(True) - # Get list of users from the DB with proxys at least 300 seconds - gLogger.verbose("Updating list of users in proxy management") - retVal = self.__refreshUserCache(validSeconds) - if not retVal["OK"]: - return retVal - userData = self.__usersCache.get(cacheKey, validSeconds) - if userData: - return S_OK(userData["persistent"]) - return S_OK(False) - - def setPersistency(self, userDN, userGroup, persistent): - """Set the persistency for user/group - - :param str userDN: user DN - :param str userGroup: user group - :param boolean persistent: presistent flag - - :return: S_OK()/S_ERROR() - """ - # Hack to ensure bool in the rpc call - persistentFlag = True - if not persistent: - persistentFlag = False - rpcClient = Client(url="Framework/ProxyManager", timeout=120) - retVal = rpcClient.setPersistency(userDN, userGroup, persistentFlag) - if not retVal["OK"]: - return retVal - # Update internal persistency cache - cacheKey = (userDN, userGroup) - record = self.__usersCache.get(cacheKey, 0) - if record: - record["persistent"] = persistentFlag - self.__usersCache.add(cacheKey, self.__getSecondsLeftToExpiration(record["expirationtime"]), record) - return retVal - def uploadProxy(self, proxy=None, restrictLifeTime: int = 0, rfcIfPossible=None): """Upload a proxy to the proxy management service using delegation diff --git a/src/DIRAC/FrameworkSystem/ConfigTemplate.cfg b/src/DIRAC/FrameworkSystem/ConfigTemplate.cfg index d84d588020c..c3bf30e83bb 100644 --- a/src/DIRAC/FrameworkSystem/ConfigTemplate.cfg +++ b/src/DIRAC/FrameworkSystem/ConfigTemplate.cfg @@ -65,7 +65,6 @@ Services getVOMSProxyWithToken += LimitedDelegation getVOMSProxyWithToken += PrivateLimitedDelegation getLogContents = ProxyManagement - setPersistency = ProxyManagement } } ##END @@ -94,7 +93,6 @@ Services getVOMSProxyWithToken += LimitedDelegation getVOMSProxyWithToken += PrivateLimitedDelegation getLogContents = ProxyManagement - setPersistency = ProxyManagement } } ##END diff --git a/src/DIRAC/FrameworkSystem/DB/ProxyDB.py b/src/DIRAC/FrameworkSystem/DB/ProxyDB.py index 41faa607aa2..f42a9befd9e 100755 --- a/src/DIRAC/FrameworkSystem/DB/ProxyDB.py +++ b/src/DIRAC/FrameworkSystem/DB/ProxyDB.py @@ -5,7 +5,6 @@ * ProxyDB_Requests -- a delegation requests storage table for a given proxy Chain * ProxyDB_CleanProxies -- table for storing proxies in "clean" form, ie without the presence of DIRAC and VOMS extensions. - * ProxyDB_Proxies -- obsolete table for storing proxies with already added DIRAC group extension, it is present only for backward compatibility and is used only if ProxyDB_CleanProxies does not have the required proxy. * ProxyDB_VOMSProxies -- proxy storage table with VOMS extension already added. @@ -84,19 +83,6 @@ def __initializeDB(self): }, "PrimaryKey": ["UserDN", "ProxyProvider"], } - # WARN: Now proxies upload only in ProxyDB_CleanProxies, so this table will not be needed in some future - if "ProxyDB_Proxies" not in tablesInDB: - tablesD["ProxyDB_Proxies"] = { - "Fields": { - "UserName": "VARCHAR(64) NOT NULL", - "UserDN": "VARCHAR(255) NOT NULL", - "UserGroup": "VARCHAR(255) NOT NULL", - "Pem": "BLOB", - "ExpirationTime": "DATETIME", - "PersistentFlag": 'ENUM ("True","False") NOT NULL DEFAULT "True"', - }, - "PrimaryKey": ["UserDN", "UserGroup"], - } if "ProxyDB_VOMSProxies" not in tablesInDB: tablesD["ProxyDB_VOMSProxies"] = { @@ -392,7 +378,7 @@ def purgeExpiredProxies(self, sendNotifications=True): :return: S_OK(int)/S_ERROR() -- int is number of purged expired proxies """ purged = 0 - for tableName in ("ProxyDB_CleanProxies", "ProxyDB_Proxies", "ProxyDB_VOMSProxies"): + for tableName in ("ProxyDB_CleanProxies", "ProxyDB_VOMSProxies"): cmd = f"DELETE FROM `{tableName}` WHERE ExpirationTime < UTC_TIMESTAMP()" result = self._update(cmd) if not result["OK"]: @@ -431,11 +417,10 @@ def deleteProxy(self, userDN, userGroup=None, proxyProvider=None): ) if not result["OK"]: errMsgs.append(result["Message"]) - for table in ["ProxyDB_Proxies", "ProxyDB_VOMSProxies"]: - result = self._update(f"{req % table} {userGroup and f'AND UserGroup={userGroup}' or ''}") - if not result["OK"]: - if result["Message"] not in errMsgs: - errMsgs.append(result["Message"]) + result = self._update(f"{req} {userGroup and f'AND UserGroup={userGroup}' or ''}") + if not result["OK"]: + if result["Message"] not in errMsgs: + errMsgs.append(result["Message"]) if errMsgs: return S_ERROR(", ".join(errMsgs)) return result @@ -484,8 +469,6 @@ def __getPemAndTimeLeft(self, userDN, userGroup=None, vomsAttr=None, proxyProvid return S_ERROR("Invalid DN or Group") if proxyProvider: sTable = "`ProxyDB_CleanProxies`" - elif not vomsAttr: - sTable = "`ProxyDB_Proxies`" else: sTable = "`ProxyDB_VOMSProxies`" cmd = f"SELECT Pem, TIMESTAMPDIFF( SECOND, UTC_TIMESTAMP(), ExpirationTime ) from {sTable} " @@ -682,7 +665,7 @@ def getProxy(self, userDN, userGroup, requiredLifeTime=None): return S_OK((chain, timeLeft)) # Standard proxy is requested - self.log.verbose("Try to get proxy from ProxyDB_Proxies") + self.log.verbose("Try to get proxy from ProxyDB_CleanProxies") retVal = self.__getPemAndTimeLeft(userDN, userGroup) errMsg = "Can't get proxy%s: " % (requiredLifeTime and " for %s seconds" % requiredLifeTime or "") if not retVal["OK"]: @@ -858,7 +841,7 @@ def getUsers(self, validSecondsLeft=0, userMask=None): :param str userMask: user name that need to add to search filter :return: S_OK(list)/S_ERROR() -- list contain dicts with user name, DN, group - expiration time, persistent flag + expiration time """ data = [] sqlCond = [] @@ -878,7 +861,6 @@ def getUsers(self, validSecondsLeft=0, userMask=None): for table, fields in [ ("ProxyDB_CleanProxies", ("UserName", "UserDN", "ExpirationTime")), - ("ProxyDB_Proxies", ("UserName", "UserDN", "UserGroup", "ExpirationTime", "PersistentFlag")), ]: cmd = f"SELECT {', '.join(fields)} FROM `{table}`" if sqlCond: @@ -897,65 +879,10 @@ def getUsers(self, validSecondsLeft=0, userMask=None): "DN": record[1], "group": record[2], "expirationtime": record[3], - "persistent": record[4] == "True", } ) return S_OK(data) - def setPersistencyFlag(self, userDN, userGroup, persistent=True): - """Set the proxy PersistentFlag to the flag value - - :param str userDN: user DN - :param str userGroup: group name - :param boolean persistent: enable persistent flag - - :return: S_OK()/S_ERROR() - """ - - try: - sUserDN = self._escapeString(userDN)["Value"] - sUserGroup = self._escapeString(userGroup)["Value"] - except KeyError: - return S_ERROR("Can't escape something") - if persistent: - sqlFlag = "True" - else: - sqlFlag = "False" - retVal = self._query( - f"SELECT PersistentFlag FROM `ProxyDB_Proxies` WHERE UserDN={sUserDN} AND UserGroup={sUserGroup}" - ) - sqlInsert = True - if retVal["OK"]: - data = retVal["Value"] - if len(data) > 0: - sqlInsert = False - if data[0][0] == sqlFlag: - return S_OK() - if sqlInsert: - # If it's not in the db and we're removing the persistency then do nothing - if not persistent: - return S_OK() - result = Registry.getUsernameForDN(userDN) - if not result["OK"]: - self.log.error("setPersistencyFlag: Can not retrieve username for DN", userDN) - return result - try: - sUserName = self._escapeString(result["Value"])["Value"] - except KeyError: - return S_ERROR("Can't escape user name") - cmd = "INSERT INTO `ProxyDB_Proxies` ( UserName, UserDN, UserGroup, Pem, ExpirationTime, PersistentFlag ) " - cmd += f" VALUES( {sUserName}, {sUserDN}, {sUserGroup}, '', UTC_TIMESTAMP(), 'True' )" - else: - cmd = "UPDATE `ProxyDB_Proxies` SET PersistentFlag='{}' WHERE UserDN={} AND UserGroup={}".format( - sqlFlag, - sUserDN, - sUserGroup, - ) - retVal = self._update(cmd) - if not retVal["OK"]: - return retVal - return S_OK() - def getProxiesContent(self, selDict, sortList, start=0, limit=0): """Get the contents of the db, parameters are a filter to the db @@ -970,7 +897,6 @@ def getProxiesContent(self, selDict, sortList, start=0, limit=0): sqlWhere = ["Pem is not NULL"] for table, fields in [ ("ProxyDB_CleanProxies", ("UserName", "UserDN", "ExpirationTime")), - ("ProxyDB_Proxies", ("UserName", "UserDN", "UserGroup", "ExpirationTime", "PersistentFlag")), ]: cmd = f"SELECT {', '.join(fields)} FROM `{table}`" for field in selDict: @@ -993,7 +919,7 @@ def getProxiesContent(self, selDict, sortList, start=0, limit=0): elif len(sort) > 2: return S_ERROR(f"Invalid sort {sort}") if sort[0] not in fields: - if table == "ProxyDB_CleanProxies" and sort[0] in ["UserGroup", "PersistentFlag"]: + if table == "ProxyDB_CleanProxies" and sort[0] == "UserGroup": continue return S_ERROR(f"Invalid sorting field {sort[0]}") if sort[1].upper() not in ("ASC", "DESC"): diff --git a/src/DIRAC/FrameworkSystem/Service/ProxyManagerHandler.py b/src/DIRAC/FrameworkSystem/Service/ProxyManagerHandler.py index 54862812187..2f0f68f6870 100644 --- a/src/DIRAC/FrameworkSystem/Service/ProxyManagerHandler.py +++ b/src/DIRAC/FrameworkSystem/Service/ProxyManagerHandler.py @@ -6,12 +6,12 @@ :dedent: 2 :caption: ProxyManager options """ -from DIRAC import gLogger, S_OK, S_ERROR -from DIRAC.Core.Utilities.ReturnValues import convertToReturnValue +from DIRAC import S_ERROR, S_OK, gLogger +from DIRAC.ConfigurationSystem.Client.Helpers import Registry from DIRAC.Core.DISET.RequestHandler import RequestHandler, getServiceOption from DIRAC.Core.Security import Properties from DIRAC.Core.Utilities.ObjectLoader import ObjectLoader -from DIRAC.ConfigurationSystem.Client.Helpers import Registry +from DIRAC.Core.Utilities.ReturnValues import convertToReturnValue from DIRAC.FrameworkSystem.Utilities.diracx import get_token DEFAULT_MAIL_FROM = "proxymanager@diracgrid.org" @@ -119,7 +119,7 @@ def export_getRegisteredUsers(self, validSecondsRequired=0): :param int validSecondsRequired: required seconds the proxy is valid for :return: S_OK(list)/S_ERROR() -- list contain dicts with user name, DN, group - expiration time, persistent flag + expiration time """ credDict = self.getRemoteCredentials() if Properties.PROXY_MANAGEMENT not in credDict["properties"]: @@ -241,26 +241,6 @@ def __getVOMSProxy(self, userDN, userGroup, requestPem, requiredLifetime, vomsAt requiredLifetime = int(min(secsLeft, requiredLifetime * self.__maxExtraLifeFactor)) return chain.generateChainFromRequestString(requestPem, lifetime=requiredLifetime, requireLimited=forceLimited) - types_setPersistency = [str, str, bool] - - def export_setPersistency(self, userDN, userGroup, persistentFlag): - """Set the persistency for a given dn/group - - :param str userDN: user DN - :param str userGroup: DIRAC group - :param boolean persistentFlag: if proxy persistent - - :return: S_OK()/S_ERROR() - """ - retVal = self.__proxyDB.setPersistencyFlag(userDN, userGroup, persistentFlag) - if not retVal["OK"]: - return retVal - credDict = self.getRemoteCredentials() - self.__proxyDB.logAction( - f"set persistency to {bool(persistentFlag)}", credDict["DN"], credDict["group"], userDN, userGroup - ) - return S_OK() - types_deleteProxyBundle = [(list, tuple)] def export_deleteProxyBundle(self, idList): diff --git a/src/DIRAC/FrameworkSystem/scripts/dirac_admin_users_with_proxy.py b/src/DIRAC/FrameworkSystem/scripts/dirac_admin_users_with_proxy.py index c071e15d2f8..88c934ea6cf 100755 --- a/src/DIRAC/FrameworkSystem/scripts/dirac_admin_users_with_proxy.py +++ b/src/DIRAC/FrameworkSystem/scripts/dirac_admin_users_with_proxy.py @@ -8,23 +8,20 @@ DN : /O=GRID-FR/C=FR/O=CNRS/OU=CPPM/CN=Vanessa Hamar group : dirac_admin not after : 2011-06-29 12:04:25 - persistent : False - DN : /O=GRID-FR/C=FR/O=CNRS/OU=CPPM/CN=Vanessa Hamar group : dirac_pilot not after : 2011-06-29 12:04:27 - persistent : False - DN : /O=GRID-FR/C=FR/O=CNRS/OU=CPPM/CN=Vanessa Hamar group : dirac_user not after : 2011-06-29 12:04:30 - persistent : True """ import datetime import DIRAC -from DIRAC.Core.Utilities import TimeUtilities from DIRAC.Core.Base.Script import Script +from DIRAC.Core.Utilities import TimeUtilities from DIRAC.FrameworkSystem.Client.ProxyManagerClient import gProxyManager @@ -65,10 +62,10 @@ def main(): dt = expirationDate - now secsLeft = dt.days * 86400 + dt.seconds if secsLeft > params.proxyLifeTime: - userName, userDN, userGroup, _, persistent = record + userName, userDN, userGroup, _ = record if userName not in dataDict: dataDict[userName] = [] - dataDict[userName].append((userDN, userGroup, expirationDate, persistent)) + dataDict[userName].append((userDN, userGroup, expirationDate)) for userName in dataDict: print(f"* {userName}") @@ -77,7 +74,6 @@ def main(): print(f" DN : {data[0]}") print(f" group : {data[1]}") print(f" not after : {TimeUtilities.toString(data[2])}") - print(f" persistent : {data[3]}") if iP < len(dataDict[userName]) - 1: print(" -") 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 cb9cac5cd81..5e3f9f867cc 100755 --- a/src/DIRAC/FrameworkSystem/scripts/dirac_proxy_get_uploaded_info.py +++ b/src/DIRAC/FrameworkSystem/scripts/dirac_proxy_get_uploaded_info.py @@ -9,11 +9,11 @@ Example: $ dirac-proxy-get-uploaded-info Checking for DNs /O=GRID-FR/C=FR/O=CNRS/OU=CPPM/CN=Vanessa Hamar - -------------------------------------------------------------------------------------------------------- - | UserDN | UserGroup | ExpirationTime | PersistentFlag | - -------------------------------------------------------------------------------------------------------- - | /O=GRID-FR/C=FR/O=CNRS/OU=CPPM/CN=Vanessa Hamar | dirac_user | 2011-06-29 12:04:25 | True | - -------------------------------------------------------------------------------------------------------- + --------------------------------------------------------------------------------------- + | UserDN | UserGroup | ExpirationTime | + --------------------------------------------------------------------------------------- + | /O=GRID-FR/C=FR/O=CNRS/OU=CPPM/CN=Vanessa Hamar | dirac_user | 2011-06-29 12:04:25 | + --------------------------------------------------------------------------------------- """ import sys diff --git a/src/DIRAC/Interfaces/API/DiracAdmin.py b/src/DIRAC/Interfaces/API/DiracAdmin.py index a04f6586973..b0471f49bda 100755 --- a/src/DIRAC/Interfaces/API/DiracAdmin.py +++ b/src/DIRAC/Interfaces/API/DiracAdmin.py @@ -65,28 +65,9 @@ def uploadProxy(self): """ return gProxyManager.uploadProxy() - ############################################################################# - def setProxyPersistency(self, userDN, userGroup, persistent=True): - """Set the persistence of a proxy in the Proxy Manager - - Example usage: - - >>> gLogger.notice(diracAdmin.setProxyPersistency( 'some DN', 'dirac group', True )) - {'OK': True } - - :param userDN: User DN - :type userDN: string - :param userGroup: DIRAC Group - :type userGroup: string - :param persistent: Persistent flag - :type persistent: boolean - :return: S_OK,S_ERROR - """ - return gProxyManager.setPersistency(userDN, userGroup, persistent) - ############################################################################# def checkProxyUploaded(self, userDN, userGroup, requiredTime): - """Set the persistence of a proxy in the Proxy Manager + """Checks that a user has a proxy in the Proxy Manager Example usage: diff --git a/src/DIRAC/WorkloadManagementSystem/Service/JobManagerHandler.py b/src/DIRAC/WorkloadManagementSystem/Service/JobManagerHandler.py index f8a27b07d57..6c7214a78be 100755 --- a/src/DIRAC/WorkloadManagementSystem/Service/JobManagerHandler.py +++ b/src/DIRAC/WorkloadManagementSystem/Service/JobManagerHandler.py @@ -216,11 +216,6 @@ def export_submitJob(self, jobDesc): jobIDList.append(jobID) - # Set persistency flag - retVal = gProxyManager.getUserPersistence(ownerDN, self.ownerGroup) - if "Value" not in retVal or not retVal["Value"]: - gProxyManager.setPersistency(ownerDN, self.ownerGroup, True) - if parametricJob: result = S_OK(jobIDList) else: diff --git a/tests/Integration/Framework/Test_ProxyDB.py b/tests/Integration/Framework/Test_ProxyDB.py index bf1c7afb4e9..f037a7069ab 100644 --- a/tests/Integration/Framework/Test_ProxyDB.py +++ b/tests/Integration/Framework/Test_ProxyDB.py @@ -312,13 +312,11 @@ def setUp(self): gLogger.debug("\n") if self.failed: self.fail(self.failed) - db._update('DELETE FROM ProxyDB_Proxies WHERE UserName IN ("user_ca", "user", "user_1", "user_2", "user_3")') db._update( 'DELETE FROM ProxyDB_CleanProxies WHERE UserName IN ("user_ca", "user", "user_1", "user_2", "user_3")' ) def tearDown(self): - db._update('DELETE FROM ProxyDB_Proxies WHERE UserName IN ("user_ca", "user", "user_1", "user_2", "user_3")') db._update( 'DELETE FROM ProxyDB_CleanProxies WHERE UserName IN ("user_ca", "user", "user_1", "user_2", "user_3")' ) @@ -354,11 +352,6 @@ def test_getUsers(self): # Fill table for test gLogger.info("\n* Fill tables for test..") for table, values, fields in [ - ( - "ProxyDB_Proxies", - [field % ("user", "user", '"group_1",', "800"), field % ("user_2", "user_2", '"group_1",', "-1")], - "(UserName, UserDN, UserGroup, Pem, ExpirationTime)", - ), ( "ProxyDB_CleanProxies", [field % ("user_3", "user_3", "", "43200")], @@ -388,12 +381,12 @@ def test_purgeExpiredProxies(self): """Test 'purgeExpiredProxies' - try to purge expired proxies""" # Purge existed proxies gLogger.info("\n* First cleaning..") - cmd = "INSERT INTO ProxyDB_Proxies(UserName, UserDN, UserGroup, Pem, ExpirationTime) VALUES " + cmd = "INSERT INTO ProxyDB_CleanProxies(UserName, UserDN, UserGroup, Pem, ExpirationTime) VALUES " cmd += '("user", "/C=CC/O=DN/O=DIRAC/CN=user", "group_1", "PEM", ' cmd += "TIMESTAMPADD(SECOND, -1, UTC_TIMESTAMP()));" result = db._query(cmd) self.assertTrue(result["OK"], "\n" + result.get("Message", "Error message is absent.")) - cmd = "SELECT COUNT( * ) FROM ProxyDB_Proxies WHERE ExpirationTime < UTC_TIMESTAMP()" + cmd = "SELECT COUNT( * ) FROM ProxyDB_CleanProxies WHERE ExpirationTime < UTC_TIMESTAMP()" self.assertTrue(bool(db._query(cmd)["Value"][0][0] > 0)) result = db.purgeExpiredProxies() self.assertTrue(result["OK"], "\n" + result.get("Message", "Error message is absent.")) @@ -409,7 +402,7 @@ def test_getRemoveProxy(self): gLogger.info("* Check posible crashes when get proxy..") # Make record with not valid proxy, valid group, user and short expired time - cmd = "INSERT INTO ProxyDB_Proxies(UserName, UserDN, UserGroup, Pem, ExpirationTime) VALUES " + cmd = "INSERT INTO ProxyDB_CleanProxies(UserName, UserDN, UserGroup, Pem, ExpirationTime) VALUES " cmd += '("user", "/C=CC/O=DN/O=DIRAC/CN=user", "group_1", "PEM", ' cmd += "TIMESTAMPADD(SECOND, 1800, UTC_TIMESTAMP()));" result = db._update(cmd) @@ -420,9 +413,9 @@ def test_getRemoveProxy(self): "/C=CC/O=DN/O=DIRAC/CN=user", "group_1", 9999, - "No proxy provider, set request time, not valid proxy in ProxyDB_Proxies", + "No proxy provider, set request time, not valid proxy in ProxyDB_CleanProxies", ), - ("/C=CC/O=DN/O=DIRAC/CN=user", "group_1", 0, "Not valid proxy in ProxyDB_Proxies"), + ("/C=CC/O=DN/O=DIRAC/CN=user", "group_1", 0, "Not valid proxy in ProxyDB_CleanProxies"), ("/C=CC/O=DN/O=DIRAC/CN=no_user", "no_valid_group", 0, "User not exist, proxy not in DB tables"), ("/C=CC/O=DN/O=DIRAC/CN=user", "no_valid_group", 0, "Group not valid, proxy not in DB tables"), ("/C=CC/O=DN/O=DIRAC/CN=user", "group_1", 0, "No proxy provider for user, proxy not in DB tables"), @@ -433,7 +426,7 @@ def test_getRemoveProxy(self): self.assertFalse(result["OK"], "Must be fail.") gLogger.info(f"Msg: {result['Message']}") # In the last case method found proxy and must to delete it as not valid - cmd = 'SELECT COUNT( * ) FROM ProxyDB_Proxies WHERE UserName="user"' + cmd = 'SELECT COUNT( * ) FROM ProxyDB_CleanProxies WHERE UserName="user"' self.assertTrue(bool(db._query(cmd)["Value"][0][0] == 0), "GetProxy method didn't delete the last proxy.") gLogger.info("* Check that DB is clean..") @@ -449,12 +442,11 @@ def test_getRemoveProxy(self): result = db.getProxiesContent({"UserName": "user_ca"}, {}) self.assertTrue(result["OK"], "\n" + result.get("Message", "Error message is absent.")) self.assertTrue(bool(int(result["Value"]["TotalRecords"]) == 1), "Generated proxy must be one.") - for table, count in [("ProxyDB_Proxies", 0), ("ProxyDB_CleanProxies", 1)]: - cmd = f'SELECT COUNT( * ) FROM {table} WHERE UserName="user_ca"' - self.assertTrue( - bool(db._query(cmd)["Value"][0][0] == count), - table + " must " + (count and "contain proxy" or "be empty"), - ) + cmd = 'SELECT COUNT( * ) FROM ProxyDB_CleanProxies WHERE UserName="user_ca"' + self.assertTrue( + bool(db._query(cmd)["Value"][0][0] == 1), + "ProxyDB_CleanProxies" + " must " + (1 and "contain proxy" or "be empty"), + ) gLogger.info("* Check that DB is clean..") result = db.deleteProxy( @@ -475,11 +467,10 @@ def test_getRemoveProxy(self): ("user", "/C=CC/O=DN/O=DIRAC/CN=user", False, False, 12, True, "Valid proxy"), ]: # Clean tables with proxies - for table in ["ProxyDB_Proxies", "ProxyDB_CleanProxies"]: - result = db._update(f'DELETE FROM {table} WHERE UserName = "user"') - self.assertTrue(result["OK"], "\n" + result.get("Message", "Error message is absent.")) - result = db._update(f'DELETE FROM {table} WHERE UserName = "user_1"') - self.assertTrue(result["OK"], "\n" + result.get("Message", "Error message is absent.")) + result = db._update('DELETE FROM ProxyDB_CleanProxies WHERE UserName = "user"') + self.assertTrue(result["OK"], "\n" + result.get("Message", "Error message is absent.")) + result = db._update('DELETE FROM ProxyDB_CleanProxies WHERE UserName = "user_1"') + self.assertTrue(result["OK"], "\n" + result.get("Message", "Error message is absent.")) self.assertTrue(result["OK"], "\n" + result.get("Message", "Error message is absent.")) gLogger.info(f"== > {log}:") @@ -507,10 +498,10 @@ def test_getRemoveProxy(self): self.assertEqual(result["OK"], res, text) if not res: gLogger.info(f"Msg: {result['Message']}") - cmd = f'SELECT COUNT( * ) FROM ProxyDB_Proxies WHERE UserName="{user}"' + cmd = f'SELECT COUNT( * ) FROM ProxyDB_CleanProxies WHERE UserName="{user}"' self.assertTrue( bool(db._query(cmd)["Value"][0][0] == 0), - "ProxyDB_Proxies must " + ("contain proxy" if res else "be empty"), + "ProxyDB_CleanProxies must " + ("contain proxy" if res else "be empty"), ) cmd = f'SELECT COUNT( * ) FROM ProxyDB_CleanProxies WHERE UserName="{user}"' self.assertTrue( @@ -556,12 +547,12 @@ def test_getRemoveProxy(self): self.assertTrue(result["OK"], "\n" + result.get("Message", "Error message is absent.")) self.assertTrue(bool(int(result["Value"]["TotalRecords"]) == 0), "In DB present proxies.") - gLogger.info("* Get proxy when it store only in ProxyDB_Proxies..") + gLogger.info("* Get proxy when it store only in ProxyDB_CleanProxies..") # Make record with proxy that contain group result = ca._forceGenerateProxyForDN("/C=CC/O=DN/O=DIRAC/CN=user", 12 * 3600, group="group_1") self.assertTrue(result["OK"], "\n" + result.get("Message", "Error message is absent.")) proxyStr = result["Value"][1] - cmd = "INSERT INTO ProxyDB_Proxies(UserName, UserDN, UserGroup, Pem, ExpirationTime) VALUES " + cmd = "INSERT INTO ProxyDB_CleanProxies(UserName, UserDN, UserGroup, Pem, ExpirationTime) VALUES " cmd += f'("user", "{dn}", "{group}", "{proxyStr}", TIMESTAMPADD(SECOND, 43200, UTC_TIMESTAMP()))' result = db._update(cmd) self.assertTrue(result["OK"], "\n" + result.get("Message", "Error message is absent.")) @@ -592,7 +583,7 @@ def test_getRemoveProxy(self): # Assert VOMSProxy self.assertTrue(bool(chain.isVOMS().get("Value")), "Cannot create proxy with VOMS extension") - cmd = "INSERT INTO ProxyDB_Proxies(UserName, UserDN, UserGroup, Pem, ExpirationTime) VALUES " + cmd = "INSERT INTO ProxyDB_CleanProxies(UserName, UserDN, UserGroup, Pem, ExpirationTime) VALUES " cmd += f'("{vomsuser}", "/C=CC/O=DN/O=DIRAC/CN={vomsuser}", "group_1", "{proxyStr}", ' cmd += "TIMESTAMPADD(SECOND, 43200, UTC_TIMESTAMP()))" result = db._update(cmd) @@ -639,13 +630,13 @@ def test_getRemoveProxy(self): self.assertFalse(result["OK"], "Must be fail.") gLogger.info(f"Msg: {result['Message']}") # Check stored proxies - for table, user, count in [("ProxyDB_Proxies", "user", 1), ("ProxyDB_CleanProxies", "user_ca", 1)]: + for table, user, count in [("ProxyDB_CleanProxies", "user", 1), ("ProxyDB_CleanProxies", "user_ca", 1)]: cmd = f'SELECT COUNT( * ) FROM {table} WHERE UserName="{user}"' self.assertTrue(bool(db._query(cmd)["Value"][0][0] == count)) gLogger.info("* Delete proxies..") for dn, table in [ - ("/C=CC/O=DN/O=DIRAC/CN=user", "ProxyDB_Proxies"), + ("/C=CC/O=DN/O=DIRAC/CN=user", "ProxyDB_CleanProxies"), ("/C=DN/O=DIRACCA/OU=None/CN=user_ca/emailAddress=user_ca@diracgrid.org", "ProxyDB_CleanProxies"), ]: result = db.deleteProxy(dn)