Exemplo n.º 1
0
 def task_manager(self):
     if (self._task_manager is None or self._pid != os.getpid()):
         LOG.debug("Creating task manager")
         self._pid = os.getpid()
         interval = cfg.CONF.nsxv.task_status_check_interval
         self._task_manager = tasks.TaskManager(interval)
         LOG.debug("Starting task manager")
         self._task_manager.start()
     return self._task_manager
Exemplo n.º 2
0
    def _test_task_manager_stop(self,
                                exec_wait=False,
                                result_wait=False,
                                stop_wait=0):
        def _exec(task):
            if exec_wait:
                greenthread.sleep(0.01)
            return ts_const.TaskStatus.PENDING

        def _status(task):
            greenthread.sleep(0.01)
            return ts_const.TaskStatus.PENDING

        def _result(task):
            if result_wait:
                greenthread.sleep(0)
            pass

        manager = ts.TaskManager().start(100)
        manager.stop()
        # Task manager should not leave running threads around
        # if _thread is None it means it was killed in stop()
        self.assertIsNone(manager._thread)
        manager.start(100)

        alltasks = {}
        for i in range(100):
            res = 'res-%d' % i
            tasks = []
            for i in range(100):
                task = ts.Task('name', res, _exec, _status, _result)
                manager.add(task)
                tasks.append(task)
            alltasks[res] = tasks

        greenthread.sleep(stop_wait)
        manager.stop()
        # Task manager should not leave running threads around
        # if _thread is None it means it was killed in stop()
        self.assertIsNone(manager._thread)

        for res, tasks in six.iteritems(alltasks):
            for task in tasks:
                self.assertEqual(ts_const.TaskStatus.ABORT, task.status)
Exemplo n.º 3
0
    def test_task_pending_task(self):
        def _exec(task):
            task.userdata['executing'] = True
            while not task.userdata['tested']:
                greenthread.sleep(0)
            task.userdata['executing'] = False
            return ts_const.TaskStatus.COMPLETED

        userdata = {'executing': False, 'tested': False}
        manager = ts.TaskManager().start(100)
        task = ts.Task('name', 'res', _exec, userdata=userdata)
        manager.add(task)

        while not userdata['executing']:
            greenthread.sleep(0)
        self.assertTrue(manager.has_pending_task())

        userdata['tested'] = True
        while userdata['executing']:
            greenthread.sleep(0)
        self.assertFalse(manager.has_pending_task())
Exemplo n.º 4
0
 def setUp(self):
     super(VcnsDriverTaskManagerTestCase, self).setUp()
     self.manager = ts.TaskManager()
     self.manager.start(100)