Exemplo n.º 1
0
    def test_failed_task(self):
        state = EventsState()
        state.get_or_create_worker('worker1')
        events = [Event('worker-online', hostname='worker1')]
        events += task_failed_events(worker='worker1', name='task1', id='123')
        for i, e in enumerate(events):
            e['clock'] = i
            e['local_received'] = time.time()
            state.event(e)
        self.app.events.state = state
        params = dict(draw=1, start=0, length=10)
        params['search[value]'] = ''
        params['order[0][column]'] = 0
        params['columns[0][data]'] = 'name'
        params['order[0][dir]'] = 'asc'
        r = self.get('/tasks/datatable?' +
                     '&'.join(map(lambda x: '%s=%s' % x, params.items())))

        table = json.loads(r.body.decode("utf-8"))

        self.assertEqual(200, r.code)
        self.assertEqual(1, table['recordsTotal'])
        self.assertEqual(1, table['recordsFiltered'])
        tasks = table['data']
        self.assertEqual(1, len(tasks))
        self.assertEqual('FAILURE', tasks[0]['state'])
        self.assertEqual('task1', tasks[0]['name'])
        self.assertEqual('123', tasks[0]['uuid'])
        self.assertEqual('worker1', tasks[0]['worker'])
Exemplo n.º 2
0
    def test_tasks(self):
        state = EventsState()
        state.get_or_create_worker("worker1")
        state.get_or_create_worker("worker2")
        state.get_or_create_worker("worker3")
        events = [Event("worker-online", hostname="worker1"), Event("worker-online", hostname="worker2")]
        for i in range(100):
            events += task_succeeded_events(worker="worker1")
        for i in range(10):
            events += task_succeeded_events(worker="worker3")
        for i in range(13):
            events += task_failed_events(worker="worker3")
        for i, e in enumerate(events):
            e["clock"] = i
            e["local_received"] = time.time()
            state.event(e)

        self.app.events.state = state

        r = self.get("/dashboard")

        table = HtmlTableParser()
        table.parse(str(r.body))

        self.assertEqual(200, r.code)
        self.assertEqual(3, len(table.rows()))

        self.assertEqual(["worker1", "True", "0", "100", "0", "100", "0", None], table.get_row("worker1"))
        self.assertEqual(["worker2", "True", "0", "0", "0", "0", "0", None], table.get_row("worker2"))
        self.assertEqual(["worker3", "True", "0", "23", "13", "10", "0", None], table.get_row("worker3"))
Exemplo n.º 3
0
    def test_failed_task(self):
        state = EventsState()
        state.get_or_create_worker('worker1')
        events = [Event('worker-online', hostname='worker1')]
        events += task_failed_events(worker='worker1', name='task1',
                                     id='123')
        for i, e in enumerate(events):
            e['clock'] = i
            e['local_received'] = time.time()
            state.event(e)
        self.app.events.state = state

        params = dict(draw=1, start=0, length=10)
        params['search[value]'] = ''
        params['order[0][column]'] = 0
        params['columns[0][data]'] = 'name'
        params['order[0][dir]'] = 'asc'

        r = self.get('/tasks/datatable?' + '&'.join(
                        map(lambda x: '%s=%s' % x, params.items())))

        table = json.loads(r.body.decode("utf-8"))
        self.assertEqual(200, r.code)
        self.assertEqual(1, table['recordsTotal'])
        self.assertEqual(1, table['recordsFiltered'])
        tasks = table['data']
        self.assertEqual(1, len(tasks))
        self.assertEqual('FAILURE', tasks[0]['state'])
        self.assertEqual('task1', tasks[0]['name'])
        self.assertEqual('123', tasks[0]['uuid'])
        self.assertEqual('worker1', tasks[0]['worker'])
Exemplo n.º 4
0
    def test_tasks(self):
        state = EventsState()
        state.get_or_create_worker('worker1')
        state.get_or_create_worker('worker2')
        state.get_or_create_worker('worker3')
        events = [
            Event('worker-online', hostname='worker1'),
            Event('worker-online', hostname='worker2')
        ]
        for i in range(100):
            events += task_succeeded_events(worker='worker1')
        for i in range(10):
            events += task_succeeded_events(worker='worker3')
        for i in range(13):
            events += task_failed_events(worker='worker3')
        for i, e in enumerate(events):
            e['clock'] = i
            e['local_received'] = time.time()
            state.event(e)

        self.app.events.state = state

        r = self.get('/dashboard')

        table = HtmlTableParser()
        table.parse(str(r.body))

        self.assertEqual(200, r.code)
        self.assertEqual(3, len(table.rows()))

        self.assertEqual(
            ['worker1', 'True', '0', '100', '0', '100', '0', None],
            table.get_row('worker1'))
        self.assertEqual(['worker2', 'True', '0', '0', '0', '0', '0', None],
                         table.get_row('worker2'))
        self.assertEqual(['worker3', 'True', '0', '23', '13', '10', '0', None],
                         table.get_row('worker3'))
Exemplo n.º 5
0
    def test_running_cycle_with_children_allocate_chain_failed(self):
        worker = 'headworker1'
        state = EventsState()
        state.get_or_create_worker(worker)
        cycle_id = uuid()
        events = [Event('worker-online', hostname=worker)]
        cycle = '20000101_0000z'
        cycle_events = cycle_task(worker, cycle, 'RUNNING', id=cycle_id)
        child_id = uuid()
        child_task_events = task_failed_events(worker,
                                               child_id,
                                               'chain.AllocateChainTask',
                                               kwargs={
                                                   'action_id': 'test_action',
                                                   'cycle_dt': cycle,
                                                   'parent': cycle_id
                                               })
        chain_child_id = uuid()
        child_task_events += task_failed_events(worker,
                                                chain_child_id,
                                                'wrappers.WrapperTask',
                                                kwargs={
                                                    'action_id': 'test_action',
                                                    'cycle_dt': cycle,
                                                    'parent': child_id
                                                })
        events.extend(cycle_events)
        events.extend(child_task_events)
        for i, e in enumerate(events):
            e['clock'] = i
            e['local_received'] = time.time()
            state.event(e)
        self.app.events.state = state
        r = self.get('/cycles')
        self.assertEqual(200, r.code)
        self.assertIn('/task/' + cycle_id, r.body.decode("utf-8"))

        params = dict(draw=1, start=0, length=10, selected='previous')
        params['search[value]'] = ''
        params['order[0][column]'] = 0
        params['columns[0][data]'] = 'name'
        params['order[0][dir]'] = 'asc'

        r = self.get('/cycles/datatable?' +
                     '&'.join(map(lambda x: '%s=%s' % x, params.items())))

        table = json.loads(r.body.decode("utf-8"))
        self.assertEqual(200, r.code)
        self.assertEqual(0, table['recordsTotal'])

        params = dict(draw=1, start=0, length=10, selected='active')
        params['search[value]'] = ''
        params['order[0][column]'] = 0
        params['columns[0][data]'] = 'name'
        params['order[0][dir]'] = 'asc'

        r = self.get('/cycles/datatable?' +
                     '&'.join(map(lambda x: '%s=%s' % x, params.items())))

        table = json.loads(r.body.decode("utf-8"))
        self.assertEqual(200, r.code)
        self.assertEqual(1, table['recordsTotal'])

        tasks = table['data']
        self.assertEqual('FAILURE', tasks[0]['state'])
        self.assertEqual('chain.AllocateChainTask', tasks[0]['name'])
        self.assertEqual(child_id, tasks[0]['uuid'])
        self.assertEqual(worker, tasks[0]['worker'])