Skip to content

Commit

Permalink
Merge pull request #11988 from todor-ivanov/bugfix_WMAgent_ZeroLength…
Browse files Browse the repository at this point in the history
…ValidityWindowForRenewProxy_fix-11985

Add --only-cron parameter to wmagent-couchapp-init
  • Loading branch information
amaltaro authored May 17, 2024
2 parents ddecd5b + 4bf911e commit b895c1f
Showing 1 changed file with 41 additions and 8 deletions.
49 changes: 41 additions & 8 deletions bin/wmagent-couchapp-init
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,19 @@ from WMCore.Configuration import loadConfigurationFile
from WMCore.Lexicon import splitCouchServiceURL
from WMCore.WMBase import getWMBASE

parser = argparse.ArgumentParser()
parser.add_argument("--skip-cron", dest = "cron",
default = True, action = "store_false",
help = "Do not install maintenance cron jobs")
parser.add_argument("--only-cron", dest = "pushApps",
default = True, action = "store_false",
help = "Install only maintenance cron jobs")
options = parser.parse_args()

if not options.cron and not options.pushApps:
print("Mutually excluding options: --skip-cron && --only-cron")
print("Chose only one of them.")
sys.exit(1)

def couchAppRoot(couchapp):
"""Return parent path containing couchapp"""
Expand All @@ -31,7 +44,32 @@ def couchAppRoot(couchapp):
return os.path.join(wmcoreroot, 'data', 'couchapps')
raise OSError('Cannot find couchapp: %s' % couchapp)


# Defining a minimal decorator with parameter
def pushApps(pushAppsFlag):
"""
Decorator with a single Bool parameter
:param pushApps: Bool parameter to check if the callFunc is to be executed or not
:return: The decorated function with call arguments if pushApps=True
"""
def pushAppsDecorator(callFunc):
"""
An Auxiliary simple decorator
"""
def installCouchAppWrapper(*args, **kwargs):
"""
The callFunc wrapper. To decide whether to return the call to the
wrapped function or not based on the decorator's pushAppsFlag
:*args: All parameters passed to the wrapped function call
:**kwargs: All keyword arguments passed to the wrapped function call
"""
if pushAppsFlag:
return callFunc(*args, **kwargs)
else:
return
return installCouchAppWrapper
return pushAppsDecorator

@pushApps(options.pushApps)
def installCouchApp(couchUrl, couchDBName, couchAppName, basePath=None):
"""
_installCouchApp_
Expand Down Expand Up @@ -273,19 +311,14 @@ files_needed_from_yui = [


if __name__ == "__main__":
parser = argparse.ArgumentParser()
parser.add_argument("--skip-cron", dest = "cron",
default = True, action = "store_false",
help = "Do not install maintenance cron jobs")
options = parser.parse_args()

if "WMAGENT_CONFIG" not in os.environ:
print("The WMAGENT_CONFIG environment variable needs to be set before")
print("this can run.")
sys.exit(1)

wmagentConfig = loadConfigurationFile(os.environ["WMAGENT_CONFIG"])

if hasattr(wmagentConfig, "JobStateMachine") and hasattr(wmagentConfig.JobStateMachine, "couchDBName"):
fwjrDumpName = urllib.parse.quote_plus("%s/fwjrs" % wmagentConfig.JobStateMachine.couchDBName)
jobDumpName = urllib.parse.quote_plus("%s/jobs" % wmagentConfig.JobStateMachine.couchDBName)
Expand Down Expand Up @@ -355,7 +388,7 @@ if __name__ == "__main__":
urlsplit(wmagentConfig.WorkloadSummary.couchurl).scheme == 'http':
installCouchApp(wmagentConfig.ACDC.couchurl, wmagentConfig.ACDC.database, "ACDC")
installCouchApp(wmagentConfig.ACDC.couchurl, wmagentConfig.ACDC.database, "GroupUser")

if hasattr(wmagentConfig, "Tier0Feeder"):
installCouchApp(wmagentConfig.JobStateMachine.couchurl, wmagentConfig.Tier0Feeder.requestDBName, "T0Request")
centralWMStatsURL = wmagentConfig.General.centralWMStatsURL
Expand Down

0 comments on commit b895c1f

Please sign in to comment.