예제 #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["nova.limits"] = _limits
     return request
예제 #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["nova.limits"] = _limits
     return request
예제 #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)
예제 #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)
예제 #5
0
from six.moves import range
import webob

from nova.api.openstack.compute.legacy_v2 import limits
from nova.api.openstack.compute import limits as limits_v21
from nova.api.openstack.compute import views
from nova.api.openstack import wsgi
import nova.context
from nova import exception
from nova import test
from nova.tests.unit.api.openstack import fakes
from nova.tests.unit import matchers
from nova import utils

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


class BaseLimitTestSuite(test.NoDBTestCase):
    """Base test suite which provides relevant stubs and time abstraction."""