def testB_addingConfigsAndTweaks(self): """ _addingConfigsAndTweaks_ Test adding config files and tweak files """ PSetTweak = "Hello, I am a PSetTweak. It's nice to meet you." attach = "Hello, I am an attachment" configCache = ConfigCache(os.environ["COUCHURL"], couchDBName = 'config_test') configCache.createUserGroup(groupname = "testGroup", username = '******') configCache.setPSetTweaks(PSetTweak = PSetTweak) configCache.attachments['attach1'] = attach psetPath = os.path.join(getTestBase(), "WMCore_t/Cache_t/PSet.txt") configCache.addConfig(newConfig = psetPath, psetHash = None) configCache.setLabel("sample-label") configCache.setDescription("describe this config here") configCache.save() configString1 = configCache.getConfig() configCache2 = ConfigCache(os.environ["COUCHURL"], couchDBName = 'config_test', id = configCache.getCouchID(), rev = configCache.getCouchRev()) configCache2.loadByID(configCache.getCouchID()) configString2 = configCache2.getConfig() self.assertEqual(configString1, configString2) self.assertEqual(configCache2.attachments.get('attach1', None), attach) configCache.delete() return
def testB_addingConfigsAndTweaks(self): """ _addingConfigsAndTweaks_ Test adding config files and tweak files """ PSetTweak = "Hello, I am a PSetTweak. It's nice to meet you." attach = "Hello, I am an attachment" configCache = ConfigCache(os.environ["COUCHURL"], couchDBName='config_test') configCache.createUserGroup(groupname="testGroup", username='******') configCache.setPSetTweaks(PSetTweak=PSetTweak) configCache.attachments['attach1'] = attach psetPath = os.path.join(getTestBase(), "WMCore_t/Cache_t/PSet.txt") configCache.addConfig(newConfig=psetPath, psetHash=None) configCache.setLabel("sample-label") configCache.setDescription("describe this config here") configCache.save() configString1 = configCache.getConfig() configCache2 = ConfigCache(os.environ["COUCHURL"], couchDBName='config_test', id=configCache.getCouchID(), rev=configCache.getCouchRev()) configCache2.loadByID(configCache.getCouchID()) configString2 = configCache2.getConfig() self.assertEqual(configString1, configString2) self.assertEqual(configCache2.attachments.get('attach1', None), attach) configCache.delete() return
def createAlgoFromInfo(info): """ Create an Algo object from basic information """ algo = {'ApplicationName': info.get('ApplicationName'), 'ApplicationFamily': info.get('ApplicationFamily'), 'ApplicationVersion': info.get('ApplicationVersion'), 'PSetHash': info.get('PSetHash'), 'PSetContent': None, 'InDBS': info.get('AlgoInDBS', None) } configString = info.get('PSetContent') if configString: split = configString.split(';;') cacheURL = split[0] cacheDB = split[1] configID = split[2] try: configCache = ConfigCache(cacheURL, cacheDB) configCache.loadByID(configID) algo['PSetContent'] = configCache.getConfig() except Exception, ex: msg = "Exception in getting configCache from DB\n" msg += "Ignoring this exception and continuing without config.\n" msg += str(ex) msg += str(traceback.format_exc()) logging.error(msg) logging.debug("URL: %s, DB: %s, ID: %s" % (cacheURL, cacheDB, configID))
def showOriginalConfig(self, docId): """ Makes a link to the original text of the config """ configCache = ConfigCache(self.couchUrl, self.configDBName) configCache.loadByID(docId) configString = configCache.getConfig() if configString == None: return "Cannot find document " + str(docId) + " in Couch DB" return '<pre>' + configString + '</pre>'
def createAlgoFromInfo(info): """ Create an Algo object from basic information """ algo = { 'ApplicationName': info['ApplicationName'], 'ApplicationFamily': info['ApplicationFamily'], 'ApplicationVersion': info['ApplicationVersion'], 'PSetHash': info['PSetHash'], 'PSetContent': None, 'InDBS': info['AlgoInDBS'] } configString = info.get('PSetContent') if configString: try: split = configString.split(';;') cacheURL = split[0] cacheDB = split[1] configID = split[2] except IndexError: msg = "configCache not properly formatted\n" msg += "configString\n: %s" % configString msg += "Not attempting to put configCache content in DBS for this algo" msg += "AlgoInfo: %s" % algo logging.error(msg) return algo if cacheURL == "None" or cacheDB == "None" or configID == "None": # No Config for this DB logging.debug("No configCache for this algo") return algo try: configCache = ConfigCache(cacheURL, cacheDB) configCache.loadByID(configID) algo['PSetContent'] = configCache.getConfig() except Exception as ex: msg = "Exception in getting configCache from DB\n" msg += "Ignoring this exception and continuing without config.\n" msg += str(ex) msg += str(traceback.format_exc()) logging.error(msg) logging.debug("URL: %s, DB: %s, ID: %s" % (cacheURL, cacheDB, configID)) return algo
def createAlgoFromInfo(info): """ Create an Algo object from basic information """ algo = { "ApplicationName": info["ApplicationName"], "ApplicationFamily": info["ApplicationFamily"], "ApplicationVersion": info["ApplicationVersion"], "PSetHash": info["PSetHash"], "PSetContent": None, "InDBS": info["AlgoInDBS"], } configString = info.get("PSetContent") if configString: try: split = configString.split(";;") cacheURL = split[0] cacheDB = split[1] configID = split[2] except IndexError: msg = "configCache not properly formatted\n" msg += "configString\n: %s" % configString msg += "Not attempting to put configCache content in DBS for this algo" msg += "AlgoInfo: %s" % algo logging.error(msg) return algo if cacheURL == "None" or cacheDB == "None" or configID == "None": # No Config for this DB logging.debug("No configCache for this algo") return algo try: configCache = ConfigCache(cacheURL, cacheDB) configCache.loadByID(configID) algo["PSetContent"] = configCache.getConfig() except Exception as ex: msg = "Exception in getting configCache from DB\n" msg += "Ignoring this exception and continuing without config.\n" msg += str(ex) msg += str(traceback.format_exc()) logging.error(msg) logging.debug("URL: %s, DB: %s, ID: %s" % (cacheURL, cacheDB, configID)) return algo
def testE_SaveConfigFileToDisk(self): """ _SaveConfigFileToDisk_ Check and see if we can save the config file attachment to disk """ targetFile = os.path.join(self.testDir, 'configCache.test') configCache = ConfigCache(os.environ["COUCHURL"], couchDBName = 'config_test') configCache.createUserGroup(groupname = "testGroup", username = '******') configCache.attachments['configFile'] = 'ThisIsAConfigFile' configCache.saveConfigToDisk(targetFile = targetFile) f = open(targetFile, 'r') content = f.read() f.close() self.assertEqual(content, configCache.getConfig()) return