def update(self, request, schedule_id, body): if not body: msg = _('The request body must not be empty') raise webob.exc.HTTPBadRequest(explanation=msg) elif not 'schedule' in body: msg = _('The request body must contain a "schedule" entity') raise webob.exc.HTTPBadRequest(explanation=msg) # NOTE(jculp): only raise if a blank tenant is passed # passing no tenant at all is perfectly fine. elif ('tenant' in body['schedule'] and not body['schedule']['tenant'].strip()): msg = _('The request body has not specified a "tenant" entity') raise webob.exc.HTTPBadRequest(explanation=msg) api_utils.deserialize_schedule_metadata(body['schedule']) values = {} values.update(body['schedule']) try: values = api_utils.check_read_only_properties(values) except exception.Forbidden as e: raise webob.exc.HTTPForbidden(explanation=unicode(e)) request_next_run = body['schedule'].get('next_run') times = { 'minute': None, 'hour': None, 'month': None, 'day_of_week': None, 'day_of_month': None, } update_schedule_times = False for key in times: if key in values: times[key] = values[key] update_schedule_times = True if update_schedule_times: # NOTE(ameade): We must recalculate the schedules next_run time # since the schedule has changed values.update(times) values['next_run'] = api_utils.schedule_to_next_run(times) elif request_next_run: try: timeutils.parse_isotime(request_next_run) except ValueError as e: msg = _('Invalid "next_run" value. Must be ISO 8601 format') raise webob.exc.HTTPBadRequest(explanation=msg) try: schedule = self.db_api.schedule_update(schedule_id, values) except exception.NotFound: msg = _('Schedule %s could not be found.') % schedule_id raise webob.exc.HTTPNotFound(explanation=msg) utils.serialize_datetimes(schedule) api_utils.serialize_schedule_metadata(schedule) return {'schedule': schedule}
def update(self, request, schedule_id, body): if not body: msg = _('The request body must not be empty') raise webob.exc.HTTPBadRequest(explanation=msg) elif 'schedule' not in body: msg = _('The request body must contain a "schedule" entity') raise webob.exc.HTTPBadRequest(explanation=msg) # NOTE(jculp): only raise if a blank tenant is passed # passing no tenant at all is perfectly fine. elif('tenant' in body['schedule'] and not body['schedule']['tenant'].strip()): msg = _('The request body has not specified a "tenant" entity') raise webob.exc.HTTPBadRequest(explanation=msg) api_utils.deserialize_schedule_metadata(body['schedule']) values = {} values.update(body['schedule']) try: values = api_utils.check_read_only_properties(values) except exception.Forbidden as e: raise webob.exc.HTTPForbidden(explanation=unicode(e)) request_next_run = body['schedule'].get('next_run') times = { 'minute': None, 'hour': None, 'month': None, 'day_of_week': None, 'day_of_month': None, } update_schedule_times = False for key in times: if key in values: times[key] = values[key] update_schedule_times = True if update_schedule_times: # NOTE(ameade): We must recalculate the schedules next_run time # since the schedule has changed values.update(times) values['next_run'] = api_utils.schedule_to_next_run(times) elif request_next_run: try: timeutils.parse_isotime(request_next_run) except ValueError as e: msg = _('Invalid "next_run" value. Must be ISO 8601 format') raise webob.exc.HTTPBadRequest(explanation=msg) try: schedule = self.db_api.schedule_update(schedule_id, values) except exception.NotFound: msg = _('Schedule %s could not be found.') % schedule_id raise webob.exc.HTTPNotFound(explanation=msg) utils.serialize_datetimes(schedule) api_utils.serialize_schedule_metadata(schedule) return {'schedule': schedule}
def update(self, request, schedule_id, body): if not body: msg = _('The request body must not be empty') raise webob.exc.HTTPBadRequest(explanation=msg) if not 'schedule' in body: msg = _('The request body must contain a "schedule" entity') raise webob.exc.HTTPBadRequest(explanation=msg) api_utils.deserialize_schedule_metadata(body['schedule']) values = {} values.update(body['schedule']) try: values = api_utils.check_read_only_properties(values) except exception.Forbidden as e: raise webob.exc.HTTPForbidden(explanation=unicode(e)) times = { 'minute': None, 'hour': None, 'month': None, 'day_of_week': None, 'day_of_month': None, } update_schedule_times = False for key in times: if key in values: times[key] = values[key] update_schedule_times = True if update_schedule_times: # NOTE(ameade): We must recalculate the schedules next_run time # since the schedule has changed values.update(times) values['next_run'] = api_utils.schedule_to_next_run(times) try: schedule = self.db_api.schedule_update(schedule_id, values) except exception.NotFound: msg = _('Schedule %s could not be found.') % schedule_id raise webob.exc.HTTPNotFound(explanation=msg) utils.serialize_datetimes(schedule) api_utils.serialize_schedule_metadata(schedule) return {'schedule': schedule}
def test_check_read_only_properties(self): values = {'name': 'instance-1'} new_values = api_utils.check_read_only_properties(values) self.assertEquals(values, new_values)