def test_setup(self):
     self.assertEqual(self.coll.count(),
                      len(self.new_workflows + self.old_workflows))
     self.assertEqual(sorted(self.new_workflows),
                      sorted(manageactions.get_actions(acted=0).keys()))
     self.assertEqual(sorted(self.old_workflows),
                      sorted(manageactions.get_actions(acted=1).keys()))
示例#2
0
    def getaction(self, days=0, acted=0):
        """
        The page at ``https://localhost:8080/getaction``
        returns a list of workflows to perform actions on.
        It may be useful to use this page to immediately check
        if your submission went through properly.
        This page will mostly be used by Unified though for acting on operator submissions.

        :param int days: The number of past days to check.
                         The default, 0, means to only check today.
        :param int acted: Used to determine which actions to return.
                          The following values can be used:

                          - 0 - The default value selects actions that have not been run on
                          - 1 - Selects actions reported as submitted by Unified
                          - Negative integer - Selects all actions

        :returns: JSON-formatted information containing actions to act on.
                  The top-level keys of the JSON are the workflow names.
                  Each of these keys refers to a dictionary specifying:

                  - **"Action"** - The action to take on the workflow
                  - **"Reasons"** - A list of reasons for this action
                  - **"Parameters"** - Changes to make for the resubmission
                  - **"user"** - The account name that submitted that action

        :rtype: JSON
        """
        acted = int(acted)
        if acted < 0:
            acted = None
        if acted > 1:
            acted = 1

        return manageactions.get_actions(int(days), acted=acted)
示例#3
0
    def submitaction(self, workflows='', action='', **kwargs):
        """Submits the action to Unified and notifies the user that this happened

        :param str workflows: is a list of workflows to apply the action to
        :param str action: is the suggested action for Unified to take
        :param kwargs: can include various reasons and additional datasets
        :returns: a confirmation page
        :rtype: str
        """

        cherrypy.log('args: {0}'.format(kwargs))

        if workflows == '':
            return render('scolduser.html', workflow='')

        if action == '':
            return render('scolduser.html', workflow=workflows[0])

        output = ''

        self.seeworkflowlock.acquire()
        try:

            workflows, reasons, params = manageactions.\
                submitaction(cherrypy.request.login, workflows, action, cherrypy.session,
                             **kwargs)

            # Immediately get actions to check the sites list
            check_actions = manageactions.get_actions()
            blank_sites_subtask = []
            sites_to_run = {}
            # Loop through all workflows just submitted
            for workflow in workflows:
                # Check sites of recovered workflows
                if check_actions[workflow]['Action'] in ['acdc', 'recovery']:
                    for subtask, params in check_actions[workflow][
                            'Parameters'].items():
                        # Empty sites are noted
                        if not params.get('sites'):
                            blank_sites_subtask.append('/%s/%s' %
                                                       (workflow, subtask))
                            sites_to_run['/%s/%s' % (workflow, subtask)] = \
                                globalerrors.check_session(cherrypy.session).\
                                get_workflow(workflow).site_to_run(subtask)

            if blank_sites_subtask:
                drain_statuses = {sitename: drain for sitename, _, drain in \
                                      sitereadiness.i_site_readiness()}
                output = render('picksites.html',
                                tasks=blank_sites_subtask,
                                statuses=drain_statuses,
                                sites_to_run=sites_to_run)

            else:
                output = render('actionsubmitted.html',
                                workflows=workflows,
                                action=action,
                                reasons=reasons,
                                params=params,
                                user=cherrypy.request.login)

        finally:
            self.seeworkflowlock.release()

        return output
示例#4
0
"""
.. describe:: add_acdc.py

A python script that searches the actions database
and adds the list of ACDCs to all previous actions

:author: Daniel Abercrombie <*****@*****.**>
"""

from workflowwebtools import workflowinfo
from workflowwebtools import manageactions

if __name__ == '__main__':

    manageactions.serverconfig.LOCATION = '.'
    COLLECTION = manageactions.get_actions_collection()

    for workflow in manageactions.get_actions(0):

        print workflow

        prep_id = workflowinfo.WorkflowInfo(workflow).get_prep_id()

        COLLECTION.update_one({'workflow': workflow},
                              {'$set': {'parameters.ACDCs':
                                            [wkf for wkf in \
                                                 workflowinfo.PrepIDInfo(prep_id).get_workflows() \
                                                 if wkf != workflow]}
                              })