Exemple #1
0
 def _populate_limits_diff_regex(self, request):
     """Put limit info into a request."""
     _limits = [
         limits.Limit("GET", "*", ".*", 10, 60).display(),
         limits.Limit("GET", "*", "*.*", 10, 60).display(),
     ]
     request.environ["cinder.limits"] = _limits
     return request
Exemple #2
0
 def _populate_limits(self, request):
     """Put limit info into a request."""
     _limits = [
         limits.Limit("GET", "*", ".*", 10, 60).display(),
         limits.Limit("POST", "*", ".*", 5, 60 * 60).display(),
         limits.Limit("GET", "changes-since*", "changes-since", 5,
                      60).display(),
     ]
     request.environ["cinder.limits"] = _limits
     return request
Exemple #3
0
 def test_GET_no_delay(self):
     """Test a limit handles 1 GET per second."""
     limit = limits.Limit("GET", "*", ".*", 1, 1)
     delay = limit("GET", "/anything")
     self.assertIsNone(delay)
     self.assertEqual(0, limit.next_request)
     self.assertEqual(0, limit.last_request)
Exemple #4
0
    def test_GET_delay(self):
        """Test two calls to 1 GET per second limit."""
        limit = limits.Limit("GET", "*", ".*", 1, 1)
        delay = limit("GET", "/anything")
        self.assertIsNone(delay)

        delay = limit("GET", "/anything")
        self.assertEqual(1, delay)
        self.assertEqual(1, limit.next_request)
        self.assertEqual(0, limit.last_request)

        self.time += 4

        delay = limit("GET", "/anything")
        self.assertIsNone(delay)
        self.assertEqual(4, limit.next_request)
        self.assertEqual(4, limit.last_request)
Exemple #5
0
from lxml import etree
from oslo_serialization import jsonutils
import six
from six.moves import http_client
from six.moves import range
import webob

from cinder.api.v1 import limits
from cinder.api import views
from cinder.api import xmlutil
import cinder.context
from cinder import test
from cinder.tests.unit import fake_constants as fake

TEST_LIMITS = [
    limits.Limit("GET", "/delayed", "^/delayed", 1, limits.PER_MINUTE),
    limits.Limit("POST", "*", ".*", 7, limits.PER_MINUTE),
    limits.Limit("POST", "/volumes", "^/volumes", 3, limits.PER_MINUTE),
    limits.Limit("PUT", "*", "", 10, limits.PER_MINUTE),
    limits.Limit("PUT", "/volumes", "^/volumes", 5, limits.PER_MINUTE),
]
NS = {
    'atom': 'http://www.w3.org/2005/Atom',
    'ns': 'http://docs.openstack.org/common/api/v1.0'
}


class BaseLimitTestSuite(test.TestCase):
    """Base test suite which provides relevant stubs and time abstraction."""
    def setUp(self):
        super(BaseLimitTestSuite, self).setUp()