def PUT(self, consumer_id, content_type): """ Update the association of a profile with a consumer by content type ID. @param consumer_id: A consumer ID. @type consumer_id: str @param content_type: A content unit type ID. @type content_type: str @return: The updated model object: {consumer_id:<str>, content_type:<str>, profile:<dict>} @rtype: dict """ body = self.params() profile = body.get('profile') manager = managers.consumer_profile_manager() tags = [resource_tag(dispatch_constants.RESOURCE_CONSUMER_TYPE, consumer_id), resource_tag(dispatch_constants.RESOURCE_CONTENT_UNIT_TYPE, content_type), action_tag('profile_update')] call_request = CallRequest(manager.update, [consumer_id, content_type], {'profile': profile}, tags=tags, weight=0, kwarg_blacklist=['profile']) call_request.reads_resource(dispatch_constants.RESOURCE_CONSUMER_TYPE, consumer_id) call_report = CallReport.from_call_request(call_request) call_report.serialize_result = False consumer = execution.execute_sync(call_request, call_report) link = serialization.link.child_link_obj(consumer_id, content_type) consumer.update(link) return self.ok(consumer)
def POST(self): body = self.params() id = body.get('id') display_name = body.get('display_name') description = body.get('description') notes = body.get('notes') manager = managers.consumer_manager() args = [id, display_name, description, notes] weight = pulp_config.config.getint('tasks', 'create_weight') tags = [resource_tag(dispatch_constants.RESOURCE_CONSUMER_TYPE, id), action_tag('create')] call_request = CallRequest(manager.register, args, weight=weight, tags=tags) call_request.creates_resource(dispatch_constants.RESOURCE_CONSUMER_TYPE, id) call_report = CallReport.from_call_request(call_request) call_report.serialize_result = False consumer = execution.execute_sync(call_request, call_report) consumer.update({'_href': serialization.link.child_link_obj(consumer['id'])}) return self.created(consumer['_href'], consumer)
def POST(self): body = self.params() id = body.get('id') display_name = body.get('display_name') description = body.get('description') notes = body.get('notes') manager = managers.consumer_manager() args = [id, display_name, description, notes] weight = pulp_config.config.getint('tasks', 'create_weight') tags = [ resource_tag(dispatch_constants.RESOURCE_CONSUMER_TYPE, id), action_tag('create') ] call_request = CallRequest(manager.register, args, weight=weight, tags=tags) call_request.creates_resource( dispatch_constants.RESOURCE_CONSUMER_TYPE, id) call_report = CallReport.from_call_request(call_request) call_report.serialize_result = False consumer = execution.execute_sync(call_request, call_report) consumer.update( {'_href': serialization.link.child_link_obj(consumer['id'])}) return self.created(consumer['_href'], consumer)
def test_task_instantiation(self): call_request = CallRequest(mock.Mock()) call_report = CallReport() try: Task(call_request) Task(call_request, call_report) except: self.fail(traceback.format_exc())
def test_complete_callback(self): scheduled_call_request = CallRequest(itinerary_call) schedule_id = self.scheduler.add(scheduled_call_request, SCHEDULE_3_RUNS) run_call_request = scheduled_call_request.call()[0] run_call_report = CallReport.from_call_request(run_call_request) run_call_report.schedule_id = schedule_id scheduler_complete_callback(run_call_request, run_call_report) collection = ScheduledCall.get_collection() scheduled_call = collection.find_one({'_id': ObjectId(schedule_id)}) self.assertNotEqual(scheduled_call['last_run'], None)
def test_complete_callback_missing_schedule(self): scheduled_call_request = CallRequest(itinerary_call) schedule_id = self.scheduler.add(scheduled_call_request, SCHEDULE_3_RUNS) run_call_request = scheduled_call_request.call()[0] run_call_report = CallReport.from_call_request(run_call_request) run_call_report.schedule_id = schedule_id collection = ScheduledCall.get_collection() collection.remove({'_id': ObjectId(schedule_id)}, safe=True) try: scheduler_complete_callback(run_call_request, run_call_report) except: self.fail()
def test_scheduled_collision(self): call_request_scheduled = CallRequest(itinerary_call) schedule = dateutils.format_iso8601_interval(datetime.timedelta(minutes=1), datetime.datetime.now()) schedule_id = self.scheduler.add(call_request_scheduled, schedule) call_request_in_progress = CallRequest(dummy_call) call_report_in_progress = CallReport.from_call_request(call_request_in_progress) call_report_in_progress.schedule_id = schedule_id # return a call report list out of the coordinator that has tasks from # this schedule in it # this will be cleaned up by the base class tearDown method mocked_coordinator = mock.Mock() mocked_call_reports = mock.Mock(return_value=[call_report_in_progress]) mocked_coordinator.find_call_reports = mocked_call_reports dispatch_factory.coordinator = mock.Mock(return_value=mocked_coordinator) call_group_generator = self.scheduler._get_call_request_groups_for_scheduled_itineraries() # call reports should have indicated a collision, in which we do not # run the scheduled call group again, indicated here by an "empty" # generator self.assertRaises(StopIteration, next, call_group_generator)
def setUp(self): super(TaskTests, self).setUp() self.call_request = CallRequest(Call(), call_args, call_kwargs) self.call_report = CallReport() self.task = Task(self.call_request, self.call_report)
def setUp(self): self.call_request = CallRequest(Call(), call_args, call_kwargs) self.call_report = CallReport() self.task = AsyncTask(self.call_request, self.call_report)
def setUp(self): self.call_request = CallRequest(fail) self.call_report = CallReport() self.task = Task(self.call_request, self.call_report)
def test_call_report_instantiation(self): try: call_report = CallReport() except Exception, e: self.fail(e.message)
# Verify self.assertEqual(0, len(listeners)) def test_validate_events(self): crud._validate_event_types(event_data.ALL_EVENT_TYPES) def test_validate_star(self): crud._validate_event_types(['*']) def test_validate_empty(self): self.assertRaises(InvalidValue, crud._validate_event_types, []) # event tests ------------------------------------------------------------------ _test_call_report = CallReport() class EventTests(base.PulpAsyncServerTests): @mock.patch('pulp.server.dispatch.coordinator.Coordinator.find_call_reports', return_value=[_test_call_report]) def test_event_instantiation(self, mock_find): event_type = 'test_type' payload = 'test_payload' try: event = event_data.Event(event_type, payload) except Exception, e: self.fail(e.message) self.assertEqual(mock_find.call_count, 1) self.assertEqual(_test_call_report.serialize(), event.call_report)