示例#1
0
    def test_service_configured(self):
        cfg.CONF.set_override(name="url", override=None, group="coordination")
        self.assertEqual(coordination.get_driver_name(), None)

        cfg.CONF.set_override(name="url",
                              override="kazoo://127.0.0.1:2181",
                              group="coordination")
        self.assertTrue(coordination.configured())
        self.assertEqual(coordination.get_driver_name(), "kazoo")

        cfg.CONF.set_override(name="url",
                              override="file:///tmp",
                              group="coordination")
        self.assertFalse(coordination.configured())
        self.assertEqual(coordination.get_driver_name(), "file")

        cfg.CONF.set_override(name="url",
                              override="zake://",
                              group="coordination")
        self.assertFalse(coordination.configured())
        self.assertEqual(coordination.get_driver_name(), "zake")

        cfg.CONF.set_override(name="url",
                              override="redis://*****:*****@127.0.0.1",
                              group="coordination")
        self.assertTrue(coordination.configured())
        self.assertEqual(coordination.get_driver_name(), "redis")
示例#2
0
    def test_service_configured(self):
        cfg.CONF.set_override(name='url', override='kazoo://127.0.0.1:2181', group='coordination')
        self.assertTrue(coordination.configured())

        cfg.CONF.set_override(name='url', override='file:///tmp', group='coordination')
        self.assertFalse(coordination.configured())

        cfg.CONF.set_override(name='url', override='zake://', group='coordination')
        self.assertFalse(coordination.configured())
    def test_service_configured(self):
        cfg.CONF.set_override(name='url', override='kazoo://localhost:2181', group='coordination')
        self.assertTrue(coordination.configured())

        cfg.CONF.set_override(name='url', override='file:///tmp', group='coordination')
        self.assertFalse(coordination.configured())

        cfg.CONF.set_override(name='url', override='zake://', group='coordination')
        self.assertFalse(coordination.configured())
示例#4
0
    def test_service_configured(self):
        cfg.CONF.set_default('url',
                             'kazoo://localhost:2181',
                             group='coordination')
        self.assertTrue(coordination.configured())

        cfg.CONF.set_default('url', 'file:///tmp', group='coordination')
        self.assertFalse(coordination.configured())

        cfg.CONF.set_default('url', 'zake://', group='coordination')
        self.assertFalse(coordination.configured())
示例#5
0
    def test_service_configured(self):
        cfg.CONF.set_override(name="url",
                              override="kazoo://127.0.0.1:2181",
                              group="coordination")
        self.assertTrue(coordination.configured())

        cfg.CONF.set_override(name="url",
                              override="file:///tmp",
                              group="coordination")
        self.assertFalse(coordination.configured())

        cfg.CONF.set_override(name="url",
                              override="zake://",
                              group="coordination")
        self.assertFalse(coordination.configured())
示例#6
0
    def apply_before(self, target):
        target = super(ConcurrencyByAttributeApplicator,
                       self).apply_before(target=target)

        valid_states = [
            action_constants.LIVEACTION_STATUS_REQUESTED,
            action_constants.LIVEACTION_STATUS_DELAYED,
        ]

        # Exit if target not in valid state.
        if target.status not in valid_states:
            LOG.debug(
                "The live action is not schedulable therefore the policy "
                '"%s" cannot be applied. %s',
                self._policy_ref,
                target,
            )
            return target

        # Warn users that the coordination service is not configured.
        if not coordination.configured():
            LOG.warn(
                "Coordination service is not configured. Policy enforcement is best effort."
            )

        target = self._apply_before(target)

        return target
示例#7
0
    def apply_before(self, target):
        # Exit if target not in schedulable state.
        if target.status != action_constants.LIVEACTION_STATUS_REQUESTED:
            LOG.debug(
                'The live action is not schedulable therefore the policy '
                '"%s" cannot be applied. %s', self._policy_ref, target)
            return target

        # Warn users that the coordination service is not configured.
        if not coordination.configured():
            LOG.warn(
                'Coordination service 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 = self._get_lock_uid(target)
        LOG.debug('%s is attempting to acquire lock "%s".',
                  self.__class__.__name__, lock_uid)
        with self.coordinator.get_lock(lock_uid):
            target = self._apply_before(target)

        return target
示例#8
0
文件: handler.py 项目: tools-env/st2
    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)
示例#9
0
文件: handler.py 项目: mahak/st2
    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)
示例#10
0
文件: base.py 项目: LindsayHill/st2
    def apply_after(self, target):
        """
        Apply the policy after the target does work.

        :param target: The instance of the resource being affected by this policy.
        :type target: ``object``

        :rtype: ``object``
        """
        # Warn users that the coordination service is not configured
        if not coordination.configured():
            LOG.warn('Coordination service is not configured. Policy enforcement is best effort.')

        return target
示例#11
0
    def apply_after(self, target):
        # Warn users that the coordination service is not configured.
        if not coordination.configured():
            LOG.warn('Coordination service 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 = self._get_lock_uid(target)
        LOG.debug('%s is attempting to acquire lock "%s".', self.__class__.__name__, lock_uid)
        with self.coordinator.get_lock(lock_uid):
            self._apply_after(target)

        return target
示例#12
0
    def apply_after(self, target):
        # Warn users that the coordination service is not configured.
        if not coordination.configured():
            LOG.warn('Coordination service 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 = self._get_lock_uid(target)
        LOG.debug('%s is attempting to acquire lock "%s".', self.__class__.__name__, lock_uid)
        with self.coordinator.get_lock(lock_uid):
            self._apply_after(target)

        return target
示例#13
0
    def apply_after(self, target):
        """
        Apply the policy after the target does work.

        :param target: The instance of the resource being affected by this policy.
        :type target: ``object``

        :rtype: ``object``
        """
        # Warn users that the coordination service is not configured
        if not coordination.configured():
            LOG.warn(
                'Coordination service is not configured. Policy enforcement is best effort.'
            )

        return target
示例#14
0
    def apply_before(self, target):
        # Exit if target not in schedulable state.
        if target.status != action_constants.LIVEACTION_STATUS_REQUESTED:
            LOG.debug('The live action is not schedulable therefore the policy '
                      '"%s" cannot be applied. %s', self._policy_ref, target)
            return target

        # Warn users that the coordination service is not configured.
        if not coordination.configured():
            LOG.warn('Coordination service 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 = self._get_lock_uid(target)
        LOG.debug('%s is attempting to acquire lock "%s".', self.__class__.__name__, lock_uid)
        with self.coordinator.get_lock(lock_uid):
            target = self._apply_before(target)

        return target
示例#15
0
    def apply_before(self, target):
        target = super(ConcurrencyByAttributeApplicator, self).apply_before(target=target)

        valid_states = [
            action_constants.LIVEACTION_STATUS_REQUESTED,
            action_constants.LIVEACTION_STATUS_DELAYED
        ]

        # Exit if target not in valid state.
        if target.status not in valid_states:
            LOG.debug('The live action is not schedulable therefore the policy '
                      '"%s" cannot be applied. %s', self._policy_ref, target)
            return target

        # Warn users that the coordination service is not configured.
        if not coordination.configured():
            LOG.warn('Coordination service is not configured. Policy enforcement is best effort.')

        target = self._apply_before(target)

        return target