Esempio n. 1
0
 def _inject(self, numRequests):
     # This creates 10 documents using the test data above representing
     # 10 requests belonging to two campaigns that have just been placed
     # into the "ops-hold" into the ReqMgr. 
     # Whenever a request enters the "ops-hold" state, the dict containing the
     # request params should be added to the OpsClipboard using the
     # inject API call (see Assign.py):
     requests, campaignIds, requestIds = getTestRequests(numRequests)
     OpsClipboard.inject(self.testInit.couchUrl, self.testInit.couchDbName, *requests)
     return requests, campaignIds, requestIds
 def createRequests(self, numRequests):
     """
     Create numRequests in CouchDB.
     
     """
     print "Creating %s requests ..." % numRequests
     # attempt to do this on CouchDB behind frontend - as described above
     requests, campaignIds, requestIds = getTestRequests(numRequests)
     print "Request names: %s" % requestIds
     OpsClipboard.inject(self.couchUrl, self.dbName, *requests)
     print "OpsClipboard.inject() will inject only new request names ..."
Esempio n. 3
0
    def handleAssignmentPage(self, **kwargs):
        """ handler for the main page """
        #Accept Json encoded strings
        decodedArgs = {}
        for key in kwargs.keys():
            try:
                decodedArgs[key] = JsonWrapper.loads(kwargs[key])
            except:
                #Probably wasn't JSON
                decodedArgs[key] = kwargs[key]
        kwargs = decodedArgs
        # handle the checkboxes
        teams = []
        requestNames = []
        for key, value in kwargs.iteritems():
            if isinstance(value, types.StringTypes):
                kwargs[key] = value.strip()
            if key.startswith("Team"):
                teams.append(key[4:])
            if key.startswith("checkbox"):
                requestName = key[8:]
                self.validate(requestName)
                requestNames.append(key[8:])
        
        for requestName in requestNames:
            if kwargs['action'] == 'Reject':
                ChangeState.changeRequestStatus(requestName, 'rejected', wmstatUrl = self.wmstatWriteURL) 
            else:
                assignments = GetRequest.getAssignmentsByName(requestName)
                if teams == [] and assignments == []:
                    raise cherrypy.HTTPError(400, "Must assign to one or more teams")
                self.assignWorkload(requestName, kwargs)
                for team in teams:
                    if not team in assignments:
                        ChangeState.assignRequest(requestName, team, wmstatUrl = self.wmstatWriteURL)
                priority = kwargs.get(requestName+':priority', '')
                if priority != '':
                    Utilities.changePriority(requestName, priority, self.wmstatWriteURL)
        participle=kwargs['action']+'ed'
        if self.opshold and kwargs['action'] == 'Assign':
            participle='put into "ops-hold" state (see <a href="%s">OpsClipboard</a>)' % self.clipboardUrl
            # this, previously used, call made all requests injected into OpsClipboard to
            # have campaign_id null since the call doesn't propagate request's 
            # CampaignName at all, AcquisitionEra remains default null and probably
            # a bunch of other things is wrong too
            #requests = [GetRequest.getRequestByName(requestName) for requestName in requestNames]
            requests = [Utilities.requestDetails(requestName) for requestName in requestNames]
            OpsClipboard.inject(self.couchUrl, self.clipboardDB, *requests)
            for request in requestNames:
                ChangeState.changeRequestStatus(requestName, 'ops-hold', wmstatUrl = self.wmstatWriteURL)

        return self.templatepage("Acknowledge", participle=participle, requests=requestNames)
Esempio n. 4
0
 def testJ_update_adddescription(self):
     """
     Create a document and update function 'adddescription' handler
     to add descriptions (Ops notes) to request documents.
      
     """
     request = {"RequestName" : "testB_request", "CampaignName" : "testB_campaign"}
     OpsClipboard.inject(self.testInit.couchUrl, self.testInit.couchDbName, *[request])
     allRequests = self._getViewResults("all")
     self.assertEqual(len(allRequests), 1) # check only one request
     docId = allRequests[0][u"id"]
     # update the doc descriptions
     addDescription(self.testInit.couchUrl, self.testInit.couchDbName, docId, "NewDescription")
     doc = self.couch.document(docId)
     descriptions = doc["description"]
     # description entry is a list of dictionaries, each newly created request
     # has first initial description, just above added was the second one, index 1
     self.failUnless("NewDescription" in doc[u"description"][1].values())
Esempio n. 5
0
    def handleAssignmentPage(self, **kwargs):
        """ handler for the main page """
        # handle the checkboxes
        teams = []
        requestNames = []
        for key, value in kwargs.iteritems():
            if isinstance(value, types.StringTypes):
                kwargs[key] = value.strip()
            if key.startswith("Team"):
                teams.append(key[4:])
            if key.startswith("checkbox"):
                requestName = key[8:]
                self.validate(requestName)
                requestNames.append(key[8:])

        for requestName in requestNames:
            if kwargs["action"] == "Reject":
                ChangeState.changeRequestStatus(requestName, "rejected")
            else:
                assignments = GetRequest.getAssignmentsByName(requestName)
                if teams == [] and assignments == []:
                    raise cherrypy.HTTPError(400, "Must assign to one or more teams")
                self.assignWorkload(requestName, kwargs)
                for team in teams:
                    if not team in assignments:
                        ChangeState.assignRequest(requestName, team)
                priority = kwargs.get(requestName + ":priority", "")
                if priority != "":
                    Utilities.changePriority(requestName, priority)
        participle = kwargs["action"] + "ed"
        if self.opshold and kwargs["action"] == "Assign":
            participle = 'put into "ops-hold" state (see <a href="%s">OpsClipboard</a>)' % self.clipboardUrl
            # this, previously used, call made all requests injected into OpsClipboard to
            # have campaign_id null since the call doesn't propagate request's
            # CampaignName at all, AcquisitionEra remains default null and probably
            # a bunch of other things is wrong too
            # requests = [GetRequest.getRequestByName(requestName) for requestName in requestNames]
            requests = [Utilities.requestDetails(requestName) for requestName in requestNames]
            OpsClipboard.inject(self.couchUrl, self.clipboardDB, *requests)
            for requestName in requestNames:
                ChangeState.changeRequestStatus(requestName, "ops-hold")
        return self.templatepage("Acknowledge", participle=participle, requests=requestNames)
Esempio n. 6
0
 def injectOpsClipboard(self, reqName, couchUrl, couchDbName):
     """
     Once a request reaches "ops-hold" state, it can be injected into
     CouchDB, application OpsClipboard, for further manipulation.
     Do this here with the reqName request.
     
     OpsClipboard.inject() method which does in the CouchDB injection
     is called from WMCore/HTTPFrontEnd/RequestManager/Assign.py
         handleAssignmentPage method (which currently, 2012-01, doesn't
         have any unittest nor REST API) (used only from the Assignment webpage)
         
     Works when running locally accessing CouchDB behind frontend:
     py test/data/ReqMgr/reqmgr-load_example_data.py -u https://localhost:2000/reqmgr/reqMgr/ \
         -t testinguser_120131_213320_2161 -i -o https://localhost:2000/couchdb/ \
         -a ops_clipboard        
     
     """
     # find out campaign name associated with this request
     r = self.restSender.get("request/%s" % reqName)
     campaign = r[0]["Campaign"]
     logging.info("Campaign: %s" % campaign)
     requests = [{u"RequestName": reqName, u"CampaignName": campaign}]
     OpsClipboard.inject(couchUrl, couchDbName, *requests)
Esempio n. 7
0
 def handleAssignmentPage(self, **kwargs):
     """ handler for the main page """
     # handle the checkboxes
     teams = []
     requestNames = []
     for key, value in kwargs.iteritems():
         if isinstance(value, types.StringTypes):
             kwargs[key] = value.strip()
         if key.startswith("Team"):
             teams.append(key[4:])
         if key.startswith("checkbox"):
             requestName = key[8:]
             self.validate(requestName)
             requestNames.append(key[8:])
     
     for requestName in requestNames:
         if kwargs['action'] == 'Reject':
             ChangeState.changeRequestStatus(requestName, 'rejected') 
         else:
             assignments = GetRequest.getAssignmentsByName(requestName)
             if teams == [] and assignments == []:
                 raise cherrypy.HTTPError(400, "Must assign to one or more teams")
             self.assignWorkload(requestName, kwargs)
             for team in teams:
                 if not team in assignments:
                     ChangeState.assignRequest(requestName, team)
             priority = kwargs.get(requestName+':priority', '')
             if priority != '':
                 Utilities.changePriority(requestName, priority)
     participle=kwargs['action']+'ed'
     if self.hold and kwargs['action'] == 'Assign':
         participle='put into "ops-hold" state (see <a href="%s">OpsClipboard</a>)' % self.clipboardUrl
         requests = [GetRequest.getRequestByName(requestName) for requestName in requestNames]
         OpsClipboard.inject(self.couchUrl, self.clipboardDB, *requests)
         for request in requestNames:
             ChangeState.changeRequestStatus(requestName, 'ops-hold')
     return self.templatepage("Acknowledge", participle=participle, requests=requestNames)