Merge "Add restrictions on updated_at when getting instance action records"

This commit is contained in:
Zuul
2018-10-29 04:33:15 +00:00
committed by Gerrit Code Review
3 changed files with 49 additions and 0 deletions

View File

@@ -465,6 +465,9 @@ changes_before_instance_action:
The ``±hh:mm`` value, if included, returns the time zone as an offset from UTC. The ``±hh:mm`` value, if included, returns the time zone as an offset from UTC.
For example, ``2015-08-27T09:49:58-05:00``. For example, ``2015-08-27T09:49:58-05:00``.
If you omit the time zone, the UTC time zone is assumed. If you omit the time zone, the UTC time zone is assumed.
When both ``changes-since`` and ``changes-before`` are specified,
the value of the ``changes-before`` must be later than or equal to
the value of the ``changes-since`` otherwise API will return 400.
in: query in: query
required: false required: false
type: string type: string
@@ -525,6 +528,9 @@ changes_since_instance_action:
The ``±hh:mm`` value, if included, returns the time zone as an offset from UTC. The ``±hh:mm`` value, if included, returns the time zone as an offset from UTC.
For example, ``2015-08-27T09:49:58-05:00``. For example, ``2015-08-27T09:49:58-05:00``.
If you omit the time zone, the UTC time zone is assumed. If you omit the time zone, the UTC time zone is assumed.
When both ``changes-since`` and ``changes-before`` are specified,
the value of the ``changes-since`` must be earlier than or equal to
the value of the ``changes-before`` otherwise API will return 400.
in: query in: query
required: false required: false
type: string type: string

View File

@@ -110,6 +110,12 @@ class InstanceActionsController(wsgi.Controller):
if 'changes-before' in search_opts: if 'changes-before' in search_opts:
search_opts['changes-before'] = timeutils.parse_isotime( search_opts['changes-before'] = timeutils.parse_isotime(
search_opts['changes-before']) search_opts['changes-before'])
changes_since = search_opts.get('changes-since')
if (changes_since and search_opts['changes-before'] <
search_opts['changes-since']):
msg = _('The value of changes-since must be less than '
'or equal to changes-before.')
raise exc.HTTPBadRequest(explanation=msg)
limit, marker = common.get_limit_and_marker(req) limit, marker = common.get_limit_and_marker(req)
try: try:

View File

@@ -14,7 +14,9 @@
# under the License. # under the License.
import copy import copy
import datetime
import iso8601
import mock import mock
from oslo_policy import policy as oslo_policy from oslo_policy import policy as oslo_policy
from oslo_utils.fixture import uuidsentinel as uuids from oslo_utils.fixture import uuidsentinel as uuids
@@ -30,6 +32,7 @@ from nova import objects
from nova import policy from nova import policy
from nova import test from nova import test
from nova.tests.unit.api.openstack import fakes from nova.tests.unit.api.openstack import fakes
from nova.tests.unit import fake_instance
from nova.tests.unit import fake_server_actions from nova.tests.unit import fake_server_actions
@@ -340,6 +343,40 @@ class InstanceActionsTestV266(InstanceActionsTestV258):
self.assertIn('Invalid input for query parameters changes-before', self.assertIn('Invalid input for query parameters changes-before',
six.text_type(ex)) six.text_type(ex))
@mock.patch('nova.compute.api.InstanceActionAPI.actions_get')
@mock.patch('nova.api.openstack.common.get_instance')
def test_get_action_with_changes_since_and_changes_before(
self, mock_get_instance, mock_action_get):
param = 'changes-since=2012-12-05T00:00:00Z&' \
'changes-before=2012-12-05T01:00:00Z'
req = self._get_http_req_with_version('os-instance-actions?%s' %
param, use_admin_context=True,
version=self.wsgi_api_version)
instance = fake_instance.fake_instance_obj(req.environ['nova.context'])
mock_get_instance.return_value = instance
self.controller.index(req, FAKE_UUID)
filters = {'changes-since': datetime.datetime(
2012, 12, 5, 0, 0, tzinfo=iso8601.iso8601.UTC),
'changes-before': datetime.datetime(
2012, 12, 5, 1, 0, tzinfo=iso8601.iso8601.UTC)}
mock_action_get.assert_called_once_with(req.environ['nova.context'],
instance, limit=1000,
marker=None,
filters=filters)
def test_instance_actions_filters_with_distinct_changes_time_bad_request(
self):
changes_since = '2018-09-04T05:45:27Z'
changes_before = '2018-09-03T05:45:27Z'
req = self._get_http_req('os-instance-actions?'
'changes-since=%s&changes-before=%s' %
(changes_since, changes_before))
ex = self.assertRaises(exc.HTTPBadRequest, self.controller.index,
req, FAKE_UUID)
self.assertIn('The value of changes-since must be less than '
'or equal to changes-before', six.text_type(ex))
def test_get_action_with_changes_before_old_microversion(self): def test_get_action_with_changes_before_old_microversion(self):
"""Tests that the changes-before query parameter is an error before """Tests that the changes-before query parameter is an error before
microversion 2.66. microversion 2.66.