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

Adjust couchapp push command to match CMSCouchapp #10485

Merged
merged 2 commits into from
May 12, 2021
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 11 additions & 6 deletions bin/wmagent-couchapp-init
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ wmagent-couchapp-init
from __future__ import print_function, division

from future import standard_library

standard_library.install_aliases()

import argparse
Expand All @@ -16,9 +17,7 @@ import tempfile
import urllib

from urllib.parse import urlsplit

from couchapp.commands import push as couchapppush
from couchapp.config import Config

from WMCore.Configuration import loadConfigurationFile
from WMCore.Lexicon import splitCouchServiceURL
Expand All @@ -45,14 +44,20 @@ def installCouchApp(couchUrl, couchDBName, couchAppName, basePath=None):
Install the given couch app on the given server in the given database. If
the database already exists it will be deleted.
"""
# set of options required by the couchapp push command
# from collections import namedtuple
# couchOpts = namedtuple("opts", ["export", "output", "force", "no_atomic"])
# for attribute in ["export", "output", "force", "no_atomic"]:
# setattr(couchOpts, attribute, False)
### AMR debugging workqueue couchapps, remove it later ###
#couchOpts.export = True
#couchOpts.output = "/data/WorkQueue.json"
##########################################################
if not basePath:
basePath = couchAppRoot(couchAppName)
print("Installing %s into %s" % (couchAppName, urllib.unquote_plus(couchDBName)))

couchappConfig = Config()

couchapppush(couchappConfig, "%s/%s" % (basePath, couchAppName),
"%s/%s" % (couchUrl, couchDBName))
couchapppush("%s/%s" % (basePath, couchAppName), "%s/%s" % (couchUrl, couchDBName))
return


Expand Down
19 changes: 9 additions & 10 deletions src/python/WMQuality/TestInitCouchApp.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,25 +13,27 @@

from builtins import object
from future import standard_library

standard_library.install_aliases()

import os
import urllib.parse

from couchapp.commands import push as couchapppush
from couchapp.config import Config
from WMCore.Database.CMSCouch import CouchServer

from WMQuality.TestInit import TestInit


class CouchAppTestHarness(object):
"""
Test Harness for installing a couch database instance with several couchapps
in a unittest.setUp and wiping it out in a unittest.tearDown


"""
def __init__(self, dbName, couchUrl = None):

def __init__(self, dbName, couchUrl=None):
self.couchUrl = os.environ.get("COUCHURL", couchUrl)
self.dbName = dbName
if self.couchUrl == None:
Expand All @@ -40,13 +42,11 @@ def __init__(self, dbName, couchUrl = None):
if self.couchUrl.endswith('/'):
raise RuntimeError("COUCHURL env var shouldn't end with /")
self.couchServer = CouchServer(self.couchUrl)
self.couchappConfig = Config()


def create(self, dropExistingDb=True):
"""create couch db instance"""
#import pdb
#pdb.set_trace()
# import pdb
# pdb.set_trace()
if self.dbName in self.couchServer.listDatabases():
if not dropExistingDb:
return
Expand All @@ -62,8 +62,8 @@ def pushCouchapps(self, *couchappdirs):
"""
push a list of couchapps to the database
"""
for couchappdir in couchappdirs:
couchapppush(self.couchappConfig, couchappdir, "%s/%s" % (self.couchUrl, urllib.parse.quote_plus(self.dbName)))
for couchappdir in couchappdirs:
couchapppush(couchappdir, "%s/%s" % (self.couchUrl, urllib.parse.quote_plus(self.dbName)))


class TestInitCouchApp(TestInit):
Expand Down Expand Up @@ -104,8 +104,7 @@ def setupCouch(self, dbName, *couchapps):
self.couch.create(dropExistingDb=self.dropExistingDb)
# just create the db is couchapps are not specified
if len(couchapps) > 0:
self.couch.pushCouchapps(*[os.path.join(self.couchAppRoot(couchapp), couchapp) for couchapp in couchapps ])

self.couch.pushCouchapps(*[os.path.join(self.couchAppRoot(couchapp), couchapp) for couchapp in couchapps])

couchUrl = property(lambda x: x.couch.couchUrl)
couchDbName = property(lambda x: x.couch.dbName)
Expand Down
7 changes: 1 addition & 6 deletions test/data/WMStats/generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
from argparse import ArgumentParser

from couchapp.commands import push as couchapppush
from couchapp.config import Config

from WMCore.Database.CMSCouch import CouchServer
from WMCore.Lexicon import splitCouchServiceURL
Expand Down Expand Up @@ -39,11 +38,7 @@ def installCouchApp(couchUrl, couchDBName, couchAppName, basePath=None):
basePath = couchAppRoot()
print("Installing %s into %s" % (couchAppName, couchDBName))

couchServer = CouchServer(couchUrl)
couchappConfig = Config()

couchapppush(couchappConfig, "%s/%s" % (basePath, couchAppName),
"%s/%s" % (couchUrl, couchDBName))
couchapppush("%s/%s" % (basePath, couchAppName), "%s/%s" % (couchUrl, couchDBName))
return


Expand Down