Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Changes to allow to use the db writer for the monitoring. #14734

Merged
merged 1 commit into from Jun 3, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
21 changes: 12 additions & 9 deletions CondCore/Utilities/python/o2o.py
Expand Up @@ -9,8 +9,8 @@
import netrc
import logging

prod_db_service = 'cms_orcon_prod'
dev_db_service = 'cms_orcoff_prep'
prod_db_service = ['cms_orcon_prod','o2o_prod']
dev_db_service = ['cms_orcoff_prep','o2o_dev']
schema_name = 'CMS_CONDITIONS'
oracle_tpl = 'oracle://%s:%s@%s'
private_db = 'sqlite:///o2o_jobs.db'
Expand All @@ -31,28 +31,30 @@

class O2OJob(_Base):
__tablename__ = 'O2O_JOB'
__table_args__ = {'schema' : schema_name}
name = sqlalchemy.Column(sqlalchemy.String(100), primary_key=True)
enabled = sqlalchemy.Column(sqlalchemy.Integer, nullable=False)
tag_name = sqlalchemy.Column(sqlalchemy.String(100), nullable=False)
interval = sqlalchemy.Column(sqlalchemy.Integer, nullable=False)

class O2ORun(_Base):
__tablename__ = 'O2O_RUN'
__table_args__ = {'schema' : schema_name}
job_name = sqlalchemy.Column(sqlalchemy.String(100), primary_key=True)
start_time = sqlalchemy.Column(sqlalchemy.TIMESTAMP, primary_key=True)
end_time = sqlalchemy.Column(sqlalchemy.TIMESTAMP, nullable=True)
status_code = sqlalchemy.Column(sqlalchemy.Integer, nullable=False)
log = sqlalchemy.Column(sqlalchemy.CLOB, nullable=True)

def get_db_credentials( serviceName, authFile ):
def get_db_credentials( db_service, authFile ):
pwd = None
if authFile is None:
if authPathEnvVar in os.environ:
authPath = os.environ[authPathEnvVar]
authFile = os.path.join(authPath,'.netrc')
logging.debug('Retrieving credentials from file %s' %authFile )
(username, account, pwd) = netrc.netrc( authFile ).authenticators(serviceName)
return pwd
(username, account, pwd) = netrc.netrc( authFile ).authenticators(db_service[1])
return username,pwd


class O2OMgr(object):
Expand All @@ -74,14 +76,15 @@ def getSession( self, db_service, auth ):
else:
self.logger.info('Getting credentials')
try:
pwd = get_db_credentials( db_service, auth )
username, pwd = get_db_credentials( db_service, auth )
except Exception as e:
logging.debug(str(e))
username = None
pwd = None
if not pwd:
logging.error('Credentials for service %s are not available',db_service)
if username is None:
logging.error('Credentials for service %s are not available',db_service[0])
return None
url = oracle_tpl %(schema_name,pwd,db_service)
url = oracle_tpl %(username,pwd,db_service[0])
session = None
try:
self.eng = sqlalchemy.create_engine( url )
Expand Down
20 changes: 12 additions & 8 deletions CondCore/Utilities/python/popcon2dropbox.py
Expand Up @@ -17,10 +17,10 @@
import upload_popcon

class CondMetaData(object):
def __init__( self ):
def __init__( self, fileName ):
self.md = {}
self.datef = datetime.now()
with open(confFileName) as jf:
with open(fileName) as jf:
try:
self.md = json.load(jf)
except ValueError as e:
Expand Down Expand Up @@ -86,7 +86,7 @@ def runO2O( cmsswdir, releasepath, release, arch, jobfilename, logfilename, *p )

def upload_to_dropbox( backend ):

md = CondMetaData()
md = CondMetaData(confFileName)
# check if the expected input file is there...
if not os.path.exists( dbFileForDropBox ):
print 'The input sqlite file has not been produced.'
Expand Down Expand Up @@ -120,8 +120,8 @@ def upload_to_dropbox( backend ):
print e
return False

def upload():
md = CondMetaData()
def upload( cfileName, authPath ):
md = CondMetaData(cfileName)

# check if the expected input file is there...
if not os.path.exists( dbFileForDropBox ):
Expand Down Expand Up @@ -158,6 +158,8 @@ def upload():
comment = v.get("comment")
metadata = md.dumpMetadataForUpload( inputTag, destTag, comment )
uploadCommand = 'uploadConditions.py %s' %fileNameForDropBox
if not authPath is None:
uploadCommand += ' -a %s' %authPath
try:
pipe = subprocess.Popen( uploadCommand, shell=True, stdout=subprocess.PIPE, stderr=subprocess.STDOUT )
stdout = pipe.communicate()[0]
Expand All @@ -182,14 +184,16 @@ def upload():
print e
return ret

def run( jobfilename, *p ):
def run( jobfilename, authPath ):
fns = os.path.splitext( jobfilename )
confFile = '%s.json' %fns[0]
if os.path.exists( '%s.db' %fileNameForDropBox ):
print "Removing files with name %s" %fileNameForDropBox
os.remove( '%s.db' %fileNameForDropBox )
if os.path.exists( '%s.txt' %fileNameForDropBox ):
os.remove( '%s.txt' %fileNameForDropBox )
command = 'cmsRun %s ' %jobfilename
command += ' '.join(p)
command += ' popconConfigFileName=%s' %confFile
command += ' 2>&1'
pipe = subprocess.Popen( command, shell=True, stdout=subprocess.PIPE, stderr=subprocess.STDOUT )
stdout = pipe.communicate()[0]
Expand All @@ -199,4 +203,4 @@ def run( jobfilename, *p ):
if retCode!=0:
print 'O2O job failed. Skipping upload.'
return retCode
return upload()
return upload( confFile, authPath )
23 changes: 17 additions & 6 deletions CondCore/Utilities/python/popcon2dropbox_job_conf.py
@@ -1,7 +1,18 @@
import FWCore.ParameterSet.Config as cms

import FWCore.ParameterSet.VarParsing as VarParsing
import popcon2dropbox
md = popcon2dropbox.CondMetaData()

options = VarParsing.VarParsing()
options.register('popconConfigFileName',
'popcon2dropbox.json',
VarParsing.VarParsing.multiplicity.singleton,
VarParsing.VarParsing.varType.string,
"PopCon config file name")

options.parseArguments()

md = popcon2dropbox.CondMetaData( options.popconConfigFileName )

psetForRec = []
for k,v in md.records().items():
psetForRec.append( cms.PSet( record = cms.string(str(k)),
Expand All @@ -22,16 +33,17 @@
timetype = cms.untracked.string(str(v.get('timetype')))
)
)
print psetForOutRec

process = cms.Process("TEST")
destinationDatabase = md.destinationDatabase()


process = cms.Process("PopCon")
process.load("CondCore.CondDB.CondDB_cfi")
process.CondDB.DBParameters.messageLevel = cms.untracked.int32( 3 )
process.CondDB.connect = 'sqlite:%s' %popcon2dropbox.dbFileForDropBox

process.PoolDBOutputService = cms.Service("PoolDBOutputService",
process.CondDB,
logconnect = cms.untracked.string('sqlite:%s' %popcon2dropbox.dbLogFile),
toPut = cms.VPSet( psetForOutRec )
)

Expand All @@ -42,5 +54,4 @@
interval = cms.uint64(1)
)

print process.CondDB.connect

35 changes: 35 additions & 0 deletions CondCore/Utilities/scripts/popconRun
@@ -0,0 +1,35 @@
#!/usr/bin/env python
'''Script that directs the popcon output to the condition uploader
'''
import os
import sys
from CondCore.Utilities import popcon2dropbox

import optparse
import argparse

def main( argv ):

parser = argparse.ArgumentParser()
parser.add_argument("job_file", type=str, help="wrapper for popcon jobs")
parser.add_argument("-a","--auth", type=str, help="authentication path (for conddb key and .netrc files)")
args = parser.parse_args()

if args.job_file is None:
print 'ERROR: the cfg file name has not been provided.'
return -1
if not os.path.exists( args.job_file ):
print 'ERROR: the specified cfg file %s has not been found in the execution directory' %args.job_file
return -2
fns = os.path.splitext( args.job_file )
confFile = '%s.json' %fns[0]
if not os.path.exists( confFile ):
print 'ERROR: the metadata file %s has not been found in the execution directory' %confFile
return -3

return popcon2dropbox.run( args.job_file, args.auth )

if __name__ == '__main__':
sys.exit(main(sys.argv))


43 changes: 43 additions & 0 deletions CondCore/Utilities/scripts/update_db_credential.py
@@ -0,0 +1,43 @@
#!/usr/bin/env python
import sys
import getpass
import subprocess
import optparse

def update_credential( serviceName, accountName, newPassword ):
command = 'cmscond_authentication_manager --update_conn -s %s -u %s -p %s' %(serviceName, accountName, newPassword )
pipe = subprocess.Popen( command, shell=True, stdout=subprocess.PIPE, stderr=subprocess.STDOUT )
stdout_val = pipe.communicate()[0]
return stdout_val

def main():

parser = optparse.OptionParser(usage =
'Usage: %prog <file> [<file> ...]\n'
)

parser.add_option('-s', '--service',
dest = 'service',
help = 'the service hosting the account'
)

parser.add_option('-a','--accountName',
dest = 'accountName',
help = 'the account name to change'
)

(options, arguments) = parser.parse_args()

if options.service == None or options.accountName == None:
parser.print_help()
return -2

password = getpass.getpass( prompt= 'Enter the new password:')

try:
print update_credential( options.service, options.accountName, password )
print 'Password changed.'
except e:
print 'Update credential failed.'
if __name__ == '__main__':
sys.exit(main())
11 changes: 10 additions & 1 deletion CondCore/Utilities/scripts/uploadConditions.py
Expand Up @@ -589,9 +589,12 @@ def uploadFile(self, filename, backend = defaultBackend, temporaryFile = default

def authenticateUser(dropBox, options):

netrcPath = None
if options.authPath is not None:
netrcPath = os.path.join( options.authPath,'.netrc' )
try:
# Try to find the netrc entry
(username, account, password) = netrc.netrc().authenticators(options.netrcHost)
(username, account, password) = netrc.netrc( netrcPath ).authenticators(options.netrcHost)
except Exception:
# netrc entry not found, ask for the username and password
logging.info(
Expand Down Expand Up @@ -813,6 +816,12 @@ def main():
help = 'The netrc host (machine) from where the username and password will be read. Default: %default',
)

parser.add_option('-a', '--authPath',
dest = 'authPath',
default = None,
help = 'The path of the .netrc file for the authentication. Default: $HOME',
)

(options, arguments) = parser.parse_args()

if len(arguments) < 1:
Expand Down