Пример #1
0
 def test_action_does_not_have_specific_policies(self):
     self.assertFalse(
         policy_service.has_policies(
             self.lv_ac_db_1,
             policy_types=policy_constants.POLICY_TYPES_REQUIRING_LOCK
         )
     )
Пример #2
0
 def test_action_has_specific_policies(self):
     self.assertTrue(
         policy_service.has_policies(
             self.lv_ac_db_2,
             policy_types=policy_constants.POLICY_TYPES_REQUIRING_LOCK
         )
     )
Пример #3
0
    def _handle_execution(self, execution_queue_item_db):
        liveaction_id = str(execution_queue_item_db.liveaction_id)
        queue_item_id = str(execution_queue_item_db.id)

        extra = {
            'liveaction_id': liveaction_id,
            'queue_item_id': queue_item_id
        }

        LOG.info('Scheduling liveaction: %s (queue_item_id=%s)',
                 liveaction_id,
                 queue_item_id,
                 extra=extra)

        try:
            liveaction_db = action_utils.get_liveaction_by_id(liveaction_id)
        except StackStormDBObjectNotFoundError:
            LOG.exception(
                'Failed to find liveaction %s in the database (queue_item_id=%s).',
                liveaction_id,
                queue_item_id,
                extra=extra)
            ActionExecutionSchedulingQueue.delete(execution_queue_item_db)
            raise

        # Identify if the action has policies that require locking.
        action_has_policies_require_lock = policy_service.has_policies(
            liveaction_db,
            policy_types=policy_constants.POLICY_TYPES_REQUIRING_LOCK)

        # Acquire a distributed lock if the referenced action has specific policies attached.
        if action_has_policies_require_lock:
            # Warn users that the coordination service is not configured.
            if not coordination_service.configured():
                LOG.warn('Coordination backend is not configured. '
                         'Policy enforcement is best effort.')

            # Acquire a distributed lock before querying the database to make sure that only one
            # scheduler is scheduling execution for this action. Even if the coordination service
            # is not configured, the fake driver using zake or the file driver can still acquire
            # a lock for the local process or server respectively.
            lock_uid = liveaction_db.action
            LOG.debug('%s is attempting to acquire lock "%s".',
                      self.__class__.__name__, lock_uid)
            lock = self._coordinator.get_lock(lock_uid)

            try:
                if lock.acquire(blocking=False):
                    self._regulate_and_schedule(liveaction_db,
                                                execution_queue_item_db)
                else:
                    self._delay(liveaction_db, execution_queue_item_db)
            finally:
                lock.release()
        else:
            # Otherwise if there is no policy, then schedule away.
            self._schedule(liveaction_db, execution_queue_item_db)
Пример #4
0
    def _handle_execution(self, execution_queue_item_db):
        liveaction_id = str(execution_queue_item_db.liveaction_id)
        queue_item_id = str(execution_queue_item_db.id)

        extra = {
            'liveaction_id': liveaction_id,
            'queue_item_id': queue_item_id
        }

        LOG.info('Scheduling liveaction: %s (queue_item_id=%s)', liveaction_id,
                 queue_item_id, extra=extra)

        try:
            liveaction_db = action_utils.get_liveaction_by_id(liveaction_id)
        except StackStormDBObjectNotFoundError:
            LOG.exception('Failed to find liveaction %s in the database (queue_item_id=%s).',
                          liveaction_id, queue_item_id, extra=extra)
            ActionExecutionSchedulingQueue.delete(execution_queue_item_db)
            raise

        # Identify if the action has policies that require locking.
        action_has_policies_require_lock = policy_service.has_policies(
            liveaction_db,
            policy_types=policy_constants.POLICY_TYPES_REQUIRING_LOCK
        )

        # Acquire a distributed lock if the referenced action has specific policies attached.
        if action_has_policies_require_lock:
            # Warn users that the coordination service is not configured.
            if not coordination_service.configured():
                LOG.warn(
                    'Coordination backend is not configured. '
                    'Policy enforcement is best effort.'
                )

            # Acquire a distributed lock before querying the database to make sure that only one
            # scheduler is scheduling execution for this action. Even if the coordination service
            # is not configured, the fake driver using zake or the file driver can still acquire
            # a lock for the local process or server respectively.
            lock_uid = liveaction_db.action
            LOG.debug('%s is attempting to acquire lock "%s".', self.__class__.__name__, lock_uid)
            lock = self._coordinator.get_lock(lock_uid)

            try:
                if lock.acquire(blocking=False):
                    self._regulate_and_schedule(liveaction_db, execution_queue_item_db)
                else:
                    self._delay(liveaction_db, execution_queue_item_db)
            finally:
                lock.release()
        else:
            # Otherwise if there is no policy, then schedule away.
            self._schedule(liveaction_db, execution_queue_item_db)
Пример #5
0
 def test_action_has_policies(self):
     self.assertTrue(policy_service.has_policies(self.lv_ac_db_1))
Пример #6
0
 def test_action_does_not_have_specific_policies(self):
     self.assertFalse(
         policy_service.has_policies(
             self.lv_ac_db_1,
             policy_types=policy_constants.POLICY_TYPES_REQUIRING_LOCK,
         ))
Пример #7
0
 def test_action_has_specific_policies(self):
     self.assertTrue(
         policy_service.has_policies(
             self.lv_ac_db_2,
             policy_types=policy_constants.POLICY_TYPES_REQUIRING_LOCK,
         ))
Пример #8
0
 def test_action_does_not_have_policies(self):
     self.assertFalse(policy_service.has_policies(self.lv_ac_db_3))
Пример #9
0
 def test_action_does_not_have_policies(self):
     self.assertFalse(policy_service.has_policies(self.lv_ac_db_3))
Пример #10
0
 def test_action_has_policies(self):
     self.assertTrue(policy_service.has_policies(self.lv_ac_db_1))