diff options
| author | Jenkins <jenkins@review.openstack.org> | 2013-02-16 18:31:47 +0000 |
|---|---|---|
| committer | Gerrit Code Review <review@openstack.org> | 2013-02-16 18:31:47 +0000 |
| commit | 0b1d325f0d5ad4ce2050a8aba424a5fb315bb9d5 (patch) | |
| tree | 07ff276fb55828a2ea1f2f228c1fe09ea7e17aba | |
| parent | af9e267c70c7bca1df74cf11ac93f05fffad9729 (diff) | |
| parent | 23f7ee89ed5b5310b1604c3f745ae62b6969a0f0 (diff) | |
Merge "Ensure start time is earlier than end time in simple_tenant_usage"
| -rw-r--r-- | nova/api/openstack/compute/contrib/simple_tenant_usage.py | 7 | ||||
| -rw-r--r-- | nova/tests/api/openstack/compute/contrib/test_simple_tenant_usage.py | 15 |
2 files changed, 22 insertions, 0 deletions
diff --git a/nova/api/openstack/compute/contrib/simple_tenant_usage.py b/nova/api/openstack/compute/contrib/simple_tenant_usage.py index 2313c00ac..f219689f7 100644 --- a/nova/api/openstack/compute/contrib/simple_tenant_usage.py +++ b/nova/api/openstack/compute/contrib/simple_tenant_usage.py @@ -18,6 +18,8 @@ import datetime import urlparse +from webob import exc + from nova.api.openstack import extensions from nova.api.openstack import wsgi from nova.api.openstack import xmlutil @@ -204,6 +206,11 @@ class SimpleTenantUsageController(object): period_start = self._parse_datetime(env.get('start', [None])[0]) period_stop = self._parse_datetime(env.get('end', [None])[0]) + if not period_start < period_stop: + msg = _("Invalid start time. The start time cannot occur after " + "the end time.") + raise exc.HTTPBadRequest(explanation=msg) + detailed = env.get('detailed', ['0'])[0] == '1' return (period_start, period_stop, detailed) diff --git a/nova/tests/api/openstack/compute/contrib/test_simple_tenant_usage.py b/nova/tests/api/openstack/compute/contrib/test_simple_tenant_usage.py index 440c97fbd..ef4aacae8 100644 --- a/nova/tests/api/openstack/compute/contrib/test_simple_tenant_usage.py +++ b/nova/tests/api/openstack/compute/contrib/test_simple_tenant_usage.py @@ -218,6 +218,21 @@ class SimpleTenantUsageTest(test.TestCase): finally: policy.reset() + def test_get_tenants_usage_with_bad_start_date(self): + future = NOW + datetime.timedelta(hours=HOURS) + tenant_id = 0 + req = webob.Request.blank( + '/v2/faketenant_0/os-simple-tenant-usage/' + 'faketenant_%s?start=%s&end=%s' % + (tenant_id, future.isoformat(), NOW.isoformat())) + req.method = "GET" + req.headers["content-type"] = "application/json" + + res = req.get_response(fakes.wsgi_app( + fake_auth_context=self.user_context, + init_only=('os-simple-tenant-usage',))) + self.assertEqual(res.status_int, 400) + class SimpleTenantUsageSerializerTest(test.TestCase): def _verify_server_usage(self, raw_usage, tree): |
