Пример #1
0
 def test_workflows_id_get(self):
     """ Testing GET:/identifier"""
     # Getting the identifier of the first workflow in order to validate the get-id function
     Workflows().workflows_get()
     rawj = json.loads(self.__client.last_response.data)
     instance_id = rawj[0].get('instanceId')
     assert_is_not_none(instance_id)
     Workflows().workflows_instance_id_get(instance_id)
     assert_equal(200, self.__client.last_response.status)
Пример #2
0
 def handle_graph_finish(self, body, message):
     routeId = message.delivery_info.get('routing_key').split(
         'graph.finished.')[1]
     Workflows().workflows_get()
     workflows = self.__get_data()
     for w in workflows:
         definition = w['definition']
         injectableName = definition.get('injectableName')
         if injectableName == 'Graph.SKU.Discovery':
             graphId = w['context'].get('graphId')
             if graphId == routeId:
                 status = body.get('status')
                 if status == 'succeeded':
                     options = definition.get('options')
                     nodeid = options['defaults'].get('nodeId')
                     duration = datetime.now() - self.__discovery_duration
                     LOG.info(
                         '{0} - target: {1}, status: {2}, route: {3}, duration: {4}'
                         .format(injectableName, nodeid, status, routeId,
                                 duration))
                     self.__discovered += 1
                     message.ack()
                     break
     check = self.check_compute_count()
     if check and check == self.__discovered:
         self.__worker.stop()
         self.__worker = None
         self.__discovered = 0
Пример #3
0
    def __handle_graph_finish(self, body, message):
        routeId = message.delivery_info.get('routing_key').split('graph.finished.')[1]
        Workflows().workflows_get()
        workflows = loads(self.client.last_response.data)

        message.ack()
        for w in workflows:
            definition = w['definition']
            injectableName = definition.get('injectableName')
            if injectableName == self.__graph_name:
                graphId = w['context'].get('graphId')
                if graphId == routeId:
                    status = body.get('status')
                    if status == 'succeeded':
                        self.__finished += 1
                        self.case_recorder.write_event('finish {0} {1}'
                                .format(self.__graph_name, self.__finished))
                        break

        if self.__node_count == self.__finished:
            self.__task.worker.stop()
            self.__task.running = False
            self.__finished = 0
            self._collect_case_data()
            LOG.info('Fetch {0} log finished'.format(self.__graph_name))
Пример #4
0
 def test_negative_workflows_id_get(self):
     """ Negative Testing GET:/identifier"""
     try:
         Workflows().nodes_identifier_workflows_get("WrongIdentifier")
     except Exception, e:
         assert_equal(HTTP_NOT_FOUND, e.status, \
             message = 'status should be {0}'.format(HTTP_NOT_FOUND))
Пример #5
0
 def handle_graph_finish(self, body, message):
     routeId = message.delivery_info.get('routing_key').split(
         'graph.finished.')[1]
     assert_not_equal(routeId, None)
     Workflows().workflows_get()
     workflows = loads(self.__client.last_response.data)
     message.ack()
     for w in workflows:
         injectableName = w['definition'].get('injectableName')
         if injectableName == self.__graph_name:
             graphId = w['context'].get('graphId')
             if graphId == routeId:
                 nodeid = w['context'].get('target', injectableName)
                 status = body['status']
                 if status == 'succeeded' or status == 'failed':
                     self.__graph_status.append(status)
                     for task in self.__tasks:
                         if task.id == nodeid:
                             task.worker.stop()
                             task.running = False
                     msg = {
                         'graph_name': injectableName,
                         'target': nodeid,
                         'status': status,
                         'route_id': routeId
                     }
                     if status == 'failed':
                         msg['active_task'] = w['tasks']
                         LOG.error(msg, json=True)
                     else:
                         LOG.info(msg, json=True)
                     break
Пример #6
0
 def test_workflows_library_identifier_get(self):
     """ Testing GET:/library:/identifier"""
     Workflows().workflows_library_injectable_name_get(
         self.workflowDict.get('injectableName'))
     assert_equal(200, self.__client.last_response.status)
     assert_equal(self.workflowDict.get('friendlyName'), \
         str(json.loads(self.__client.last_response.data).get('friendlyName')))
Пример #7
0
    def put_workflow(self, workflowDict):
        #adding/updating  a workflow task
        LOG.info ("Adding workflow task : " +  str(workflowDict))
        Workflows().workflows_put(body=workflowDict)
        resp= self.__client.last_response
        assert_equal(200,resp.status)

        #Validating the content is as expected
        Workflows().workflows_library_injectable_name_get('*')
        rawj=  json.loads(self.__client.last_response.data)
        foundInsertedWorkflow = False
        for i, var  in enumerate (rawj):
            if ( workflowDict['injectableName'] ==  str (rawj[i].get('injectableName')) ):
                foundInsertedWorkflow = True
                readWorkflowTask= rawj[i]
                readFriendlyName= readWorkflowTask.get('friendlyName')
                readInjectableName  = readWorkflowTask.get('injectableName')
                assert_equal(readFriendlyName,workflowDict.get('friendlyName'))
                assert_equal(readInjectableName,workflowDict.get('injectableName'))
        assert_equal(foundInsertedWorkflow, True)
Пример #8
0
    def test_workflows_put(self):
        """ Testing PUT:/workflows:/library """

        #Making sure that there is no workflowTask with the same name from previous test runs
        Workflows().workflows_library_injectable_name_get('*')
        rawj =  json.loads(self.__client.last_response.data)

        for i, var  in enumerate (rawj):
            if ( self.workflowDict['injectableName'] ==  str (rawj[i].get('injectableName')) ):
                fnameList = str (rawj[i].get('friendlyName')).split('_')
                suffix= int (fnameList[1]) + 1
                self.workflowDict['friendlyName']= fnameList[0]+ '_' + str(suffix)
                break

        self.put_workflow(self.workflowDict)
Пример #9
0
    def post_unbound_workflow(self, graph_name, \
                       timeout_sec=300, data={}, \
                       tasks=[], callback=None, run_now=True):
        self.__graph_name = graph_name
        self.__graph_status = []

        if callback == None:
            callback = self.handle_graph_finish

        LOG.info('Starting AMQP listener for {0}'.format(self.__graph_name))
        worker = AMQPWorker(queue=QUEUE_GRAPH_FINISH, callbacks=[callback])
        thread = WorkerThread(worker, self.__graph_name)
        self.__tasks.append(thread)
        tasks.append(thread)
        Workflows().workflows_post(graph_name, body=data)
        if run_now:
            self.run_workflow_tasks(self.__tasks, timeout_sec)
Пример #10
0
 def handle_graph_finish(self, body, message):
     routeId = message.delivery_info.get('routing_key').split(
         'graph.finished.')[1]
     Workflows().workflows_get()
     workflows = self.__get_data()
     for w in workflows:
         definition = w.get('definition', {})
         injectableName = definition.get('injectableName')
         if injectableName == 'Graph.SKU.Discovery':
             graphId = w.get('context', {}).get('graphId')
             if graphId == routeId:
                 message.ack()
                 status = body.get('status')
                 if status == 'succeeded' or status == 'failed':
                     options = definition.get('options')
                     nodeid = options.get('defaults', {}).get('nodeId')
                     duration = datetime.now() - self.__discovery_duration
                     msg = {
                         'graph_name': injectableName,
                         'target': nodeid,
                         'status': status,
                         'route_id': routeId,
                         'duration': str(duration)
                     }
                     if status == 'failed':
                         msg['active_task'] = w.get('tasks', {})
                         LOG.error(msg, json=True)
                     else:
                         LOG.info(msg, json=True)
                         self.__discovered += 1
                     break
     check = self.check_compute_count()
     if check and check == self.__discovered:
         self.__task.worker.stop()
         self.__task.running = False
         self.__discovered = 0
Пример #11
0
 def test_workflows_get(self):
     """ Testing GET:/"""
     Workflows().workflows_get()
     assert_equal(200, self.__client.last_response.status)
     assert_not_equal(0, len(json.loads(self.__client.last_response.data)), \
         message='Active workflows list was empty!')