def setUp(self): super(StackEventTest, self).setUp() self.patchobject(context, 'StoredContext') self.ctx = utils.dummy_context(tenant_id='stack_event_test_tenant') self.eng = service.EngineService('a-host', 'a-topic') self.eng.thread_group_mgr = service.ThreadGroupManager()
def test_tgm_add_msg_queue(self): stack_id = 'add_msg_queues_test' e1, e2 = mock.Mock(), mock.Mock() thm = service.ThreadGroupManager() thm.add_msg_queue(stack_id, e1) thm.add_msg_queue(stack_id, e2) self.assertEqual([e1, e2], thm.msg_queues[stack_id])
def test_tgm_send(self): stack_id = 'send_test' e1, e2 = mock.MagicMock(), mock.Mock() thm = service.ThreadGroupManager() thm.add_msg_queue(stack_id, e1) thm.add_msg_queue(stack_id, e2) thm.send(stack_id, 'test_message')
def test_tgm_remove_msg_queue(self): stack_id = 'add_msg_queues_test' e1, e2 = mock.Mock(), mock.Mock() thm = service.ThreadGroupManager() thm.add_msg_queue(stack_id, e1) thm.add_msg_queue(stack_id, e2) thm.remove_msg_queue(None, stack_id, e2) self.assertEqual([e1], thm.msg_queues[stack_id]) thm.remove_msg_queue(None, stack_id, e1) self.assertNotIn(stack_id, thm.msg_queues)
def test_tgm_add_timer(self): stack_id = 'test' thm = service.ThreadGroupManager() thm.add_timer(stack_id, self.f, *self.fargs, **self.fkwargs) self.assertEqual(self.tg_mock, thm.groups[stack_id]) self.tg_mock.add_timer.assert_called_with( self.cfg_mock.CONF.periodic_interval, self.f, None, *self.fargs, **self.fkwargs)
def test_tgm_start(self): stack_id = 'test' thm = service.ThreadGroupManager() ret = thm.start(stack_id, self.f, *self.fargs, **self.fkwargs) self.assertEqual(self.tg_mock, thm.groups['test']) self.tg_mock.add_thread.assert_called_with( thm._start_with_trace, context.get_current(), None, self.f, *self.fargs, **self.fkwargs) self.assertEqual(ret, self.tg_mock.add_thread())
def create_stack(self, stack_name, scenario_tmpl): cnxt = utils.dummy_context() srv = service.EngineService("host", "engine") thread_group_mgr = service.ThreadGroupManager() srv.thread_group_mgr = thread_group_mgr hot_tmpl = self.scenario_template_to_hot(scenario_tmpl) srv.create_stack(cnxt, stack_name, hot_tmpl, params={}, files={}, args={})
def test_tgm_start_with_lock(self): thm = service.ThreadGroupManager() with self.patchobject(thm, 'start_with_acquired_lock'): mock_thread_lock = mock.Mock() mock_thread_lock.__enter__ = mock.Mock(return_value=None) mock_thread_lock.__exit__ = mock.Mock(return_value=None) self.lock_mock.thread_lock.return_value = mock_thread_lock thm.start_with_lock(self.cnxt, self.stack, self.engine_id, self.f, *self.fargs, **self.fkwargs) self.stlock_mock.StackLock.assert_called_with( self.cnxt, self.stack.id, self.engine_id) thm.start_with_acquired_lock.assert_called_once_with( self.stack, self.lock_mock, self.f, *self.fargs, **self.fkwargs)
def update_stack(self, stack_name, scenario_tmpl): cnxt = utils.dummy_context() db_stack = db_api.stack_get_by_name(cnxt, stack_name) srv = service.EngineService("host", "engine") thread_group_mgr = service.ThreadGroupManager() srv.thread_group_mgr = thread_group_mgr hot_tmpl = self.scenario_template_to_hot(scenario_tmpl) stack_identity = { 'stack_name': stack_name, 'stack_id': db_stack.id, 'tenant': db_stack.tenant, 'path': '' } srv.update_stack(cnxt, stack_identity, hot_tmpl, params={}, files={}, args={})
def test_tgm_stop(self): stack_id = 'test' done = [] def function(): while True: eventlet.sleep() def linked(gt, thread): for i in range(10): eventlet.sleep() done.append(thread) thm = service.ThreadGroupManager() thm.add_msg_queue(stack_id, mock.Mock()) thread = thm.start(stack_id, function) thread.link(linked, thread) thm.stop(stack_id) self.assertIn(thread, done) self.assertNotIn(stack_id, thm.groups) self.assertNotIn(stack_id, thm.msg_queues)
def setUp(self): super(StackServiceActionsTest, self).setUp() self.ctx = utils.dummy_context() self.man = service.EngineService('a-host', 'a-topic') self.man.thread_group_mgr = service.ThreadGroupManager()
def setUp(self): super(SnapshotServiceTest, self).setUp() self.ctx = utils.dummy_context() self.engine = service.EngineService('a-host', 'a-topic') self.engine.thread_group_mgr = service.ThreadGroupManager()
def setUp(self): super(StackCreateTest, self).setUp() self.ctx = utils.dummy_context() self.man = service.EngineService('a-host', 'a-topic') self.man.thread_group_mgr = service.ThreadGroupManager() cfg.CONF.set_override('convergence_engine', False)