Exemplo n.º 1
0
    def test_stack_delete_current_engine_active_lock(self, mock_expired,
                                                     mock_acquire, mock_try,
                                                     mock_load):
        cfg.CONF.set_override('error_wait_time', 0)
        self.man.engine_id = service_utils.generate_engine_id()
        stack_name = 'service_delete_test_stack_current_active_lock'
        stack = tools.get_stack(stack_name, self.ctx)
        sid = stack.store()

        # Insert a fake lock into the db
        stack_lock_object.StackLock.create(self.ctx, stack.id,
                                           self.man.engine_id)

        st = stack_object.Stack.get_by_id(self.ctx, sid)

        mock_load.return_value = stack
        mock_try.return_value = self.man.engine_id
        mock_send = self.patchobject(self.man.thread_group_mgr, 'send')
        mock_expired.side_effect = [False, True]

        with mock.patch.object(self.man.thread_group_mgr, 'stop') as mock_stop:
            self.assertIsNone(
                self.man.delete_stack(self.ctx, stack.identifier()))
            self.man.thread_group_mgr.groups[sid].wait()

            mock_load.assert_called_with(self.ctx, stack=st)
            mock_send.assert_called_once_with(stack.id, 'cancel')
            mock_stop.assert_called_once_with(stack.id)

        self.man.thread_group_mgr.stop(sid, graceful=True)

        self.assertEqual(2, len(mock_load.mock_calls))
        mock_try.assert_called_with()
        mock_acquire.assert_called_once_with(True)
Exemplo n.º 2
0
    def test_stack_delete_current_engine_active_lock(self, mock_expired,
                                                     mock_acquire, mock_try,
                                                     mock_load):
        cfg.CONF.set_override('error_wait_time', 0)
        self.man.engine_id = service_utils.generate_engine_id()
        stack_name = 'service_delete_test_stack_current_active_lock'
        stack = tools.get_stack(stack_name, self.ctx)
        sid = stack.store()

        # Insert a fake lock into the db
        stack_lock_object.StackLock.create(
            self.ctx, stack.id, self.man.engine_id)

        st = stack_object.Stack.get_by_id(self.ctx, sid)

        mock_load.return_value = stack
        mock_try.return_value = self.man.engine_id
        mock_send = self.patchobject(self.man.thread_group_mgr, 'send')
        mock_expired.side_effect = [False, True]

        with mock.patch.object(self.man.thread_group_mgr, 'stop') as mock_stop:
            self.assertIsNone(self.man.delete_stack(self.ctx,
                                                    stack.identifier()))
            self.man.thread_group_mgr.groups[sid].wait()

            mock_load.assert_called_with(self.ctx, stack=st)
            mock_send.assert_called_once_with(stack.id, 'cancel')
            mock_stop.assert_called_once_with(stack.id)

        self.man.thread_group_mgr.stop(sid, graceful=True)

        self.assertEqual(2, len(mock_load.mock_calls))
        mock_try.assert_called_with()
        mock_acquire.assert_called_once_with(True)
Exemplo n.º 3
0
 def setUp(self):
     super(StackLockTest, self).setUp()
     self.context = utils.dummy_context()
     self.stack_id = "aae01f2d-52ae-47ac-8a0d-3fde3d220fea"
     self.engine_id = service_utils.generate_engine_id()
     stack = mock.MagicMock()
     stack.id = self.stack_id
     stack.name = "test_stack"
     stack.action = "CREATE"
     self.mock_get_by_id = self.patchobject(
         stack_object.Stack, 'get_by_id', return_value=stack)
Exemplo n.º 4
0
 def setUp(self):
     super(StackLockTest, self).setUp()
     self.context = utils.dummy_context()
     self.stack_id = "aae01f2d-52ae-47ac-8a0d-3fde3d220fea"
     self.engine_id = service_utils.generate_engine_id()
     stack = mock.MagicMock()
     stack.id = self.stack_id
     stack.name = "test_stack"
     stack.action = "CREATE"
     self.mock_get_by_id = self.patchobject(
         stack_object.Stack, 'get_by_id', return_value=stack)
Exemplo n.º 5
0
    def test_stack_delete_other_engine_active_lock_succeeded(
            self, mock_expired, mock_acquire, mock_alive, mock_try, mock_load):
        cfg.CONF.set_override('error_wait_time', 0)

        OTHER_ENGINE = "other-engine-fake-uuid"
        self.man.engine_id = service_utils.generate_engine_id()
        self.man.listener = service.EngineListener(self.man.host,
                                                   self.man.engine_id,
                                                   self.man.thread_group_mgr)
        stack_name = 'service_delete_test_stack_other_engine_lock'
        stack = tools.get_stack(stack_name, self.ctx)
        sid = stack.store()

        # Insert a fake lock into the db
        stack_lock_object.StackLock.create(self.ctx, stack.id, OTHER_ENGINE)

        st = stack_object.Stack.get_by_id(self.ctx, sid)
        mock_load.return_value = stack
        mock_try.return_value = OTHER_ENGINE
        mock_alive.return_value = True
        mock_expired.side_effect = [False, True]
        mock_call = self.patchobject(self.man,
                                     '_remote_call',
                                     return_value=None)

        self.assertIsNone(self.man.delete_stack(self.ctx, stack.identifier()))
        self.man.thread_group_mgr.stop(sid, graceful=True)

        self.assertEqual(2, len(mock_load.mock_calls))
        mock_load.assert_called_with(self.ctx, stack=st)
        mock_try.assert_called_with()
        mock_alive.assert_called_with(self.ctx, OTHER_ENGINE)
        mock_call.assert_has_calls([
            mock.call(self.ctx,
                      OTHER_ENGINE,
                      mock.ANY,
                      "send",
                      message='cancel',
                      stack_identity=mock.ANY),
            mock.call(self.ctx,
                      OTHER_ENGINE,
                      mock.ANY,
                      "stop_stack",
                      stack_identity=mock.ANY)
        ])
        mock_acquire.assert_called_once_with(True)
    def test_stack_cancel_update_same_engine(self):
        stack_name = 'service_update_stack_test_cancel_same_engine'
        stk = tools.get_stack(stack_name, self.ctx)
        stk.state_set(stk.UPDATE, stk.IN_PROGRESS, 'test_override')
        stk.disable_rollback = False
        stk.store()

        self.man.engine_id = service_utils.generate_engine_id()

        self.patchobject(stack.Stack, 'load', return_value=stk)
        self.patchobject(stack_lock.StackLock, 'get_engine_id',
                         return_value=self.man.engine_id)
        self.patchobject(self.man.thread_group_mgr, 'send')

        self.man.stack_cancel_update(self.ctx, stk.identifier(),
                                     cancel_with_rollback=False)

        self.man.thread_group_mgr.send.assert_called_once_with(stk.id,
                                                               'cancel')
Exemplo n.º 7
0
    def test_stack_cancel_update_same_engine(self):
        stack_name = 'service_update_stack_test_cancel_same_engine'
        stk = tools.get_stack(stack_name, self.ctx)
        stk.state_set(stk.UPDATE, stk.IN_PROGRESS, 'test_override')
        stk.disable_rollback = False
        stk.store()

        self.man.engine_id = service_utils.generate_engine_id()

        self.patchobject(stack.Stack, 'load', return_value=stk)
        self.patchobject(stack_lock.StackLock, 'get_engine_id',
                         return_value=self.man.engine_id)
        self.patchobject(self.man.thread_group_mgr, 'send')

        self.man.stack_cancel_update(self.ctx, stk.identifier(),
                                     cancel_with_rollback=False)

        self.man.thread_group_mgr.send.assert_called_once_with(stk.id,
                                                               'cancel')
Exemplo n.º 8
0
    def test_stack_delete_other_engine_active_lock_failed(
            self, mock_expired, mock_alive, mock_try, mock_load):
        cfg.CONF.set_override('error_wait_time', 0)
        OTHER_ENGINE = "other-engine-fake-uuid"
        self.man.engine_id = service_utils.generate_engine_id()
        self.man.listener = service.EngineListener(self.man.host,
                                                   self.man.engine_id,
                                                   self.man.thread_group_mgr)
        stack_name = 'service_delete_test_stack_other_engine_lock_fail'
        stack = tools.get_stack(stack_name, self.ctx)
        sid = stack.store()

        # Insert a fake lock into the db
        stack_lock_object.StackLock.create(self.ctx, stack.id, OTHER_ENGINE)

        st = stack_object.Stack.get_by_id(self.ctx, sid)
        mock_load.return_value = stack
        mock_try.return_value = OTHER_ENGINE
        mock_alive.return_value = True
        mock_expired.side_effect = [False, True]

        mock_call = self.patchobject(self.man,
                                     '_remote_call',
                                     return_value=False)

        ex = self.assertRaises(dispatcher.ExpectedException,
                               self.man.delete_stack, self.ctx,
                               stack.identifier())
        self.assertEqual(exception.EventSendFailed, ex.exc_info[0])

        mock_load.assert_called_once_with(self.ctx, stack=st)
        mock_try.assert_called_once_with()
        mock_alive.assert_called_once_with(self.ctx, OTHER_ENGINE)
        mock_call.assert_called_once_with(self.ctx,
                                          OTHER_ENGINE,
                                          mock.ANY,
                                          "send",
                                          message='cancel',
                                          stack_identity=mock.ANY)
Exemplo n.º 9
0
    def test_stack_delete_other_engine_active_lock_succeeded(
            self, mock_expired, mock_acquire, mock_alive, mock_try, mock_load):
        cfg.CONF.set_override('error_wait_time', 0)

        OTHER_ENGINE = "other-engine-fake-uuid"
        self.man.engine_id = service_utils.generate_engine_id()
        self.man.listener = service.EngineListener(self.man.host,
                                                   self.man.engine_id,
                                                   self.man.thread_group_mgr)
        stack_name = 'service_delete_test_stack_other_engine_lock'
        stack = tools.get_stack(stack_name, self.ctx)
        sid = stack.store()

        # Insert a fake lock into the db
        stack_lock_object.StackLock.create(self.ctx, stack.id, OTHER_ENGINE)

        st = stack_object.Stack.get_by_id(self.ctx, sid)
        mock_load.return_value = stack
        mock_try.return_value = OTHER_ENGINE
        mock_alive.return_value = True
        mock_expired.side_effect = [False, True]
        mock_call = self.patchobject(self.man, '_remote_call',
                                     return_value=None)

        self.assertIsNone(self.man.delete_stack(self.ctx, stack.identifier()))
        self.man.thread_group_mgr.stop(sid, graceful=True)

        self.assertEqual(2, len(mock_load.mock_calls))
        mock_load.assert_called_with(self.ctx, stack=st)
        mock_try.assert_called_with()
        mock_alive.assert_called_with(self.ctx, OTHER_ENGINE)
        mock_call.assert_has_calls([
            mock.call(self.ctx, OTHER_ENGINE, mock.ANY, "send",
                      message='cancel',
                      stack_identity=mock.ANY),
            mock.call(self.ctx, OTHER_ENGINE, mock.ANY, "stop_stack",
                      stack_identity=mock.ANY)
        ])
        mock_acquire.assert_called_once_with(True)
Exemplo n.º 10
0
    def test_stack_delete_other_engine_active_lock_failed(self, mock_expired,
                                                          mock_alive, mock_try,
                                                          mock_load):
        cfg.CONF.set_override('error_wait_time', 0)
        OTHER_ENGINE = "other-engine-fake-uuid"
        self.man.engine_id = service_utils.generate_engine_id()
        self.man.listener = service.EngineListener(self.man.host,
                                                   self.man.engine_id,
                                                   self.man.thread_group_mgr)
        stack_name = 'service_delete_test_stack_other_engine_lock_fail'
        stack = tools.get_stack(stack_name, self.ctx)
        sid = stack.store()

        # Insert a fake lock into the db
        stack_lock_object.StackLock.create(self.ctx, stack.id, OTHER_ENGINE)

        st = stack_object.Stack.get_by_id(self.ctx, sid)
        mock_load.return_value = stack
        mock_try.return_value = OTHER_ENGINE
        mock_alive.return_value = True
        mock_expired.side_effect = [False, True]

        mock_call = self.patchobject(self.man, '_remote_call',
                                     return_value=False)

        ex = self.assertRaises(dispatcher.ExpectedException,
                               self.man.delete_stack,
                               self.ctx, stack.identifier())
        self.assertEqual(exception.EventSendFailed, ex.exc_info[0])

        mock_load.assert_called_once_with(self.ctx, stack=st)
        mock_try.assert_called_once_with()
        mock_alive.assert_called_once_with(self.ctx, OTHER_ENGINE)
        mock_call.assert_called_once_with(self.ctx, OTHER_ENGINE, mock.ANY,
                                          "send",
                                          message='cancel',
                                          stack_identity=mock.ANY)