Beispiel #1
0
    def test_hydrate(self, mock_hydrate):
        result = database.limits_hydrate('db', ['lim1', 'lim2', 'lim3'])

        self.assertEqual(result, ['limit:lim1', 'limit:lim2', 'limit:lim3'])
        mock_hydrate.assert_has_calls([
            mock.call('db', 'lim1'),
            mock.call('db', 'lim2'),
            mock.call('db', 'lim3'),
        ])
Beispiel #2
0
    def test_hydrate(self, mock_hydrate):
        result = database.limits_hydrate('db', ['lim1', 'lim2', 'lim3'])

        self.assertEqual(result, ['limit:lim1', 'limit:lim2', 'limit:lim3'])
        mock_hydrate.assert_has_calls([
            mock.call('db', 'lim1'),
            mock.call('db', 'lim2'),
            mock.call('db', 'lim3'),
        ])
Beispiel #3
0
    def recheck_limits(self):
        """
        Re-check that the cached limits are the current limits.
        """

        limit_data = self.control_daemon.get_limits()

        try:
            # Get the new checksum and list of limits
            new_sum, new_limits = limit_data.get_limits(self.limit_sum)

            # Convert the limits list into a list of objects
            lims = database.limits_hydrate(self.db, new_limits)

            # Build a new mapper
            mapper = routes.Mapper(register=False)
            for lim in lims:
                lim._route(mapper)

            # Save the new data
            self.limits = lims
            self.limit_sum = new_sum
            self.mapper = mapper
        except control.NoChangeException:
            # No changes to process; just keep going...
            return
        except Exception:
            # Log an error
            LOG.exception("Could not load limits")

            # Get our error set and publish channel
            control_args = self.conf['control']
            error_key = control_args.get('errors_key', 'errors')
            error_channel = control_args.get('errors_channel', 'errors')

            # Get an informative message
            msg = "Failed to load limits: " + traceback.format_exc()

            # Store the message into the error set.  We use a set
            # here because it's likely that more than one node
            # will generate the same message if there is an error,
            # and this avoids an explosion in the size of the set.
            with utils.ignore_except():
                self.db.sadd(error_key, msg)

            # Publish the message to a channel
            with utils.ignore_except():
                self.db.publish(error_channel, msg)
Beispiel #4
0
    def recheck_limits(self):
        """
        Re-check that the cached limits are the current limits.
        """

        limit_data = self.control_daemon.get_limits()

        try:
            # Get the new checksum and list of limits
            new_sum, new_limits = limit_data.get_limits(self.limit_sum)

            # Convert the limits list into a list of objects
            lims = database.limits_hydrate(self.db, new_limits)

            # Build a new mapper
            mapper = routes.Mapper(register=False)
            for lim in lims:
                lim._route(mapper)

            # Save the new data
            self.limits = lims
            self.limit_sum = new_sum
            self.mapper = mapper
        except control.NoChangeException:
            # No changes to process; just keep going...
            return
        except Exception:
            # Log an error
            LOG.exception("Could not load limits")

            # Get our error set and publish channel
            control_args = self.conf["control"]
            error_key = control_args.get("errors_key", "errors")
            error_channel = control_args.get("errors_channel", "errors")

            # Get an informative message
            msg = "Failed to load limits: " + traceback.format_exc()

            # Store the message into the error set.  We use a set
            # here because it's likely that more than one node
            # will generate the same message if there is an error,
            # and this avoids an explosion in the size of the set.
            with utils.ignore_except():
                self.db.sadd(error_key, msg)

            # Publish the message to a channel
            with utils.ignore_except():
                self.db.publish(error_channel, msg)