Bug 846031

Summary: Adding a distributor to a repo via API causes duplicate Key Error
Product: [Retired] Pulp Reporter: Pradeep Kilambi <pkilambi>
Component: API/integrationAssignee: Jay Dobies <jason.dobies>
Status: CLOSED WORKSFORME QA Contact: Preethi Thomas <pthomas>
Severity: unspecified Docs Contact:
Priority: unspecified    
Version: 2.0.6CC: skarmark
Target Milestone: ---Keywords: Triaged
Target Release: Sprint 39   
Hardware: Unspecified   
OS: Unspecified   
Whiteboard:
Fixed In Version: Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of: Environment:
Last Closed: 2012-09-05 14:46:13 UTC Type: Bug
Regression: --- Mount Type: ---
Documentation: --- CRM:
Verified Versions: Category: ---
oVirt Team: --- RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: --- Target Upstream Version:
Embargoed:

Description Pradeep Kilambi 2012-08-06 15:14:23 UTC
Description of problem:

Adding a distributor to a repository via the api gives a duplicate key error

POST on /pulp/api/v2/repositories/<repoid>/distributors/

2012-08-06 10:46:34,575 12867:140591868974848: pulp.server.webservices.middleware.exception:ERROR: exception:63 Unhandled Exception
Traceback (most recent call last):
  File "/home/pkilambi/code/pulp/platform/src/pulp/server/webservices/middleware/exception.py", line 44, in __call__
    return self.app(environ, start_response)
  File "/home/pkilambi/code/pulp/platform/src/pulp/server/webservices/middleware/postponed.py", line 38, in __call__
    return self.app(environ, start_response)
  File "/usr/lib/python2.7/site-packages/web.py-0.32-py2.7.egg/web/application.py", line 279, in wsgi
    result = self.handle_with_processors()
  File "/home/pkilambi/code/pulp/platform/src/pulp/server/webservices/application.py", line 28, in _handle_with_processors
    return process(self.processors)
  File "/home/pkilambi/code/pulp/platform/src/pulp/server/webservices/application.py", line 25, in process
    return p(lambda : process(processors))
  File "/usr/lib/python2.7/site-packages/web.py-0.32-py2.7.egg/web/application.py", line 558, in processor
    return handler()
  File "/home/pkilambi/code/pulp/platform/src/pulp/server/webservices/application.py", line 25, in <lambda>
    return p(lambda : process(processors))
  File "/home/pkilambi/code/pulp/platform/src/pulp/server/webservices/application.py", line 25, in process
    return p(lambda : process(processors))
  File "/usr/lib/python2.7/site-packages/web.py-0.32-py2.7.egg/web/application.py", line 573, in processor
    result = handler()
  File "/home/pkilambi/code/pulp/platform/src/pulp/server/webservices/application.py", line 25, in <lambda>
    return p(lambda : process(processors))
  File "/home/pkilambi/code/pulp/platform/src/pulp/server/webservices/application.py", line 27, in process
    return self.handle()
  File "/usr/lib/python2.7/site-packages/web.py-0.32-py2.7.egg/web/application.py", line 414, in _delegate
    return f()
  File "/usr/lib/python2.7/site-packages/web.py-0.32-py2.7.egg/web/application.py", line 422, in <lambda>
    f = lambda: self._delegate_sub_application(pat, what)
  File "/usr/lib/python2.7/site-packages/web.py-0.32-py2.7.egg/web/application.py", line 447, in _delegate_sub_application
    return app.handle_with_processors()
  File "/home/pkilambi/code/pulp/platform/src/pulp/server/webservices/application.py", line 28, in _handle_with_processors
    return process(self.processors)
  File "/home/pkilambi/code/pulp/platform/src/pulp/server/webservices/application.py", line 25, in process
    return p(lambda : process(processors))
  File "/usr/lib/python2.7/site-packages/web.py-0.32-py2.7.egg/web/application.py", line 558, in processor
    return handler()
  File "/home/pkilambi/code/pulp/platform/src/pulp/server/webservices/application.py", line 25, in <lambda>
    return p(lambda : process(processors))
  File "/home/pkilambi/code/pulp/platform/src/pulp/server/webservices/application.py", line 25, in process
    return p(lambda : process(processors))
  File "/usr/lib/python2.7/site-packages/web.py-0.32-py2.7.egg/web/application.py", line 573, in processor
    result = handler()
  File "/home/pkilambi/code/pulp/platform/src/pulp/server/webservices/application.py", line 25, in <lambda>
    return p(lambda : process(processors))
  File "/home/pkilambi/code/pulp/platform/src/pulp/server/webservices/application.py", line 27, in process
    return self.handle()
  File "/usr/lib/python2.7/site-packages/web.py-0.32-py2.7.egg/web/application.py", line 233, in handle
    return self._delegate(fn, self.fvars, args)
  File "/usr/lib/python2.7/site-packages/web.py-0.32-py2.7.egg/web/application.py", line 412, in _delegate
    return handle_class(cls)
  File "/usr/lib/python2.7/site-packages/web.py-0.32-py2.7.egg/web/application.py", line 387, in handle_class
    return tocall(*args)
  File "/home/pkilambi/code/pulp/platform/src/pulp/server/webservices/controllers/decorators.py", line 137, in _auth_decorator
    value = method(self, *args, **kwargs)
  File "/home/pkilambi/code/pulp/platform/src/pulp/server/webservices/controllers/repositories.py", line 584, in POST
    return execution.execute_created(self, call_request, distributor_id)
  File "/home/pkilambi/code/pulp/platform/src/pulp/server/dispatch/task.py", line 130, in _run
    result = call(*args, **kwargs)
  File "/home/pkilambi/code/pulp/platform/src/pulp/server/managers/repo/distributor.py", line 206, in add_distributor
    distributor_coll.save(distributor, safe=True)
  File "/home/pkilambi/code/pulp/platform/src/pulp/server/db/connection.py", line 80, in retry
    return method(*args, **kwargs)
  File "/usr/lib/python2.7/site-packages/pymongo-2.1.1-py2.7-linux-x86_64.egg/pymongo/collection.py", line 237, in save
    manipulate, safe, _check_keys=True, **kwargs)
  File "/home/pkilambi/code/pulp/platform/src/pulp/server/db/connection.py", line 80, in retry
    return method(*args, **kwargs)
  File "/usr/lib/python2.7/site-packages/pymongo-2.1.1-py2.7-linux-x86_64.egg/pymongo/collection.py", line 411, in update
    _check_keys, self.__uuid_subtype), safe)
  File "/usr/lib/python2.7/site-packages/pymongo-2.1.1-py2.7-linux-x86_64.egg/pymongo/connection.py", line 822, in _send_message
    return self.__check_response_to_last_error(response)
  File "/usr/lib/python2.7/site-packages/pymongo-2.1.1-py2.7-linux-x86_64.egg/pymongo/connection.py", line 770, in __check_response_to_last_error
    raise DuplicateKeyError(error["err"])
DuplicateKeyError: E11000 duplicate key error index: pulp_database.repo_distributors.$repo_id_-1_id_-1  dup key: { : "testrepo", : "iso_distributor" }

Comment 1 Jay Dobies 2012-09-05 14:46:13 UTC
I can't reproduce this. I set up a script to create a repo and add both an ISO and yum distributor and it worked. Without more details on the call you made, this is going to be hard to debug. If this is an issue, we'll run into it when we start using the ISO distributor for normal repositories. For now, I'm closing this out figuring it was a local environment issue during dev.

Below are the REST calls back and forth for adding the two distributors. I even made the call to add the iso distributor twice; the first is replaced by the second and no duplicate was seen. No error was received:

Request Body
{
  "distributor_id": "yum_distributor", 
  "distributor_type_id": "yum_distributor", 
  "distributor_config": {
    "http": true, 
    "https": true, 
    "relative_url": "http://localhost"
  }
}
Response Body
{
  "repo_id": "one", 
  "_ns": "repo_distributors", 
  "last_publish": null, 
  "auto_publish": false, 
  "scheduled_publishes": [], 
  "distributor_type_id": "yum_distributor", 
  "scratchpad": null, 
  "_id": {
    "$oid": "504765028a905b04e9000094"
  }, 
  "config": {
    "http": true, 
    "relative_url": "http://localhost", 
    "https": true
  }, 
  "id": "yum_distributor"
}
Request Body
{
  "distributor_id": "iso_distributor", 
  "distributor_type_id": "iso_distributor", 
  "distributor_config": {
    "http": true, 
    "https": true
  }
}
Response Body
{
  "repo_id": "one", 
  "_ns": "repo_distributors", 
  "last_publish": null, 
  "auto_publish": false, 
  "scheduled_publishes": [], 
  "distributor_type_id": "iso_distributor", 
  "scratchpad": null, 
  "_id": {
    "$oid": "504765028a905b04e900009a"
  }, 
  "config": {
    "http": true, 
    "https": true
  }, 
  "id": "iso_distributor"
}
Request Body
{
  "distributor_id": "iso_distributor", 
  "distributor_type_id": "iso_distributor", 
  "distributor_config": {
    "http": true, 
    "https": true
  }
}
Response Body
{
  "repo_id": "one", 
  "_ns": "repo_distributors", 
  "last_publish": null, 
  "auto_publish": false, 
  "scheduled_publishes": [], 
  "distributor_type_id": "iso_distributor", 
  "scratchpad": null, 
  "_id": {
    "$oid": "5047656b8a905b04e90000b7"
  }, 
  "config": {
    "http": true, 
    "https": true
  }, 
  "id": "iso_distributor"
}