def DELETE(self, consumer_id, repo_id, distributor_id): """ Delete a bind association between the specified consumer and repo-distributor. Designed to be idempotent. @param consumer_id: A consumer ID. @type consumer_id: str @param repo_id: A repo ID. @type repo_id: str @param distributor_id: A distributor ID. @type distributor_id: str @return: A call_report @rtype: TaskResult """ body = self.params() forced = body.get('force', False) options = body.get('options', {}) if forced: call_report = consumer.force_unbind(consumer_id, repo_id, distributor_id, options) else: call_report = consumer.unbind(consumer_id, repo_id, distributor_id, options) if call_report.spawned_tasks: raise OperationPostponed(call_report) else: return self.ok(call_report.serialize())
def test_unbind_with_agent_notification(self, mock_bind_manager): binding_config = {'notify_agent': True} agent_options = {'bar': 'baz'} mock_bind_manager.consumer_bind_manager.return_value.get_bind.return_value = binding_config mock_bind_manager.consumer_agent_manager.return_value.unbind.return_value = \ {'task_id': 'foo-request-id'} result = consumer.force_unbind('foo_consumer_id', 'foo_repo_id', 'foo_distributor_id', agent_options) mock_bind_manager.consumer_agent_manager.return_value.unbind.assert_called_once_with( 'foo_consumer_id', 'foo_repo_id', 'foo_distributor_id', agent_options) self.assertTrue(isinstance(result, TaskResult)) self.assertEquals(result.spawned_tasks, [{'task_id': 'foo-request-id'}])
def test_unbind_no_agent_notification(self, mock_bind_manager): binding_config = {'notify_agent': False} agent_options = {'bar': 'baz'} mock_bind_manager.consumer_bind_manager.return_value.get_bind.return_value = binding_config result = consumer.force_unbind('foo_consumer_id', 'foo_repo_id', 'foo_distributor_id', agent_options) mock_bind_manager.consumer_bind_manager.return_value.delete.assert_called_once_with( 'foo_consumer_id', 'foo_repo_id', 'foo_distributor_id', True) self.assertEquals(None, result) #Make sure we didn't process the agent self.assertFalse(mock_bind_manager.consumer_agent_manager.called)
def test_unbind_with_agent_notification(self, mock_bind_manager): binding_config = {'notify_agent': True} agent_options = {'bar': 'baz'} mock_bind_manager.consumer_bind_manager.return_value.get_bind.return_value = binding_config mock_bind_manager.consumer_agent_manager.return_value.unbind.return_value = \ {'task_id': 'foo-request-id'} result = consumer.force_unbind('foo_consumer_id', 'foo_repo_id', 'foo_distributor_id', agent_options) mock_bind_manager.consumer_agent_manager.return_value.unbind.assert_called_once_with( 'foo_consumer_id', 'foo_repo_id', 'foo_distributor_id', agent_options) self.assertTrue(isinstance(result, TaskResult)) self.assertEquals(result.spawned_tasks, [{ 'task_id': 'foo-request-id' }])
def test_unbind_no_agent_notification(self, mock_bind_manager): binding_config = {'notify_agent': False} agent_options = {'bar': 'baz'} mock_bind_manager.consumer_bind_manager.return_value.get_bind.return_value = binding_config result = consumer.force_unbind('foo_consumer_id', 'foo_repo_id', 'foo_distributor_id', agent_options) mock_bind_manager.consumer_bind_manager.return_value.delete.assert_called_once_with( 'foo_consumer_id', 'foo_repo_id', 'foo_distributor_id', True) self.assertEqual(result.error, None) self.assertEqual(result.return_value, None) self.assertEqual(result.spawned_tasks, []) #Make sure we didn't process the agent self.assertFalse(mock_bind_manager.consumer_agent_manager.called)
def DELETE(self, consumer_id, repo_id, distributor_id): """ Delete a bind association between the specified consumer and repo-distributor. Designed to be idempotent. @param consumer_id: A consumer ID. @type consumer_id: str @param repo_id: A repo ID. @type repo_id: str @param distributor_id: A distributor ID. @type distributor_id: str @return: The list of call_reports @rtype: list """ body = self.params() forced = body.get('force', False) options = body.get('options', {}) if forced: result = consumer.force_unbind(consumer_id, repo_id, distributor_id, options) else: result = consumer.unbind(consumer_id, repo_id, distributor_id, options) if isinstance(result, TaskResult): raise OperationPostponed(result)
def delete(self, request, consumer_id, repo_id, distributor_id): """ Delete a bind association between the specified consumer and repo-distributor. :param request: WSGI request object :type request: django.core.handlers.wsgi.WSGIRequest :param consumer_id: A consumer ID. :type consumer_id: str :param repo_id: A repo ID. :type repo_id: str :param distributor_id: A distributor ID. :type distributor_id: str :raises OperationPostponed: will dispatch a task if 'notify_agent' is set to True :raises InvalidValue: if some parameters are invalid :return: Response representing the deleted binding(in case 'notify agent' is set to False) :rtype: django.http.HttpResponse """ body = request.body_as_json forced = body.get('force', False) if not isinstance(forced, bool): raise InvalidValue(['force']) options = body.get('options', {}) if not isinstance(options, dict): raise InvalidValue(['options']) if forced: call_report = consumer_task.force_unbind(consumer_id, repo_id, distributor_id, options) else: call_report = consumer_task.unbind(consumer_id, repo_id, distributor_id, options) if call_report.spawned_tasks: raise OperationPostponed(call_report) else: return generate_json_response_with_pulp_encoder(call_report.serialize())