[Pulp-list] update semantics

Jeff Ortel jortel at redhat.com
Thu Mar 10 15:31:20 UTC 2011


I've pushed the 2nd round of changes that complete the "update semantics" story.  This 
work included the decoupling of the DB crud operations from the APIs.  The API classes 
have been changed to use the mongo collection.  Also, the BaseApi insert(), update(), 
delete() methods have been commented out to ensure two things.  First, API classes most 
provided meaningful implementations for the CRUD of system entities.  Second, it forces 
the afore mentioned DB decoupling.  Although, BaseApi.clean() remains and I think we 
should consider leaving delete() as they rarely need to be specialized.

For those API classes that did not implement an update() method, I added one.  I 
determined which keywords (fields) to support in the 'delta' using the following criteria: 
1) looking in the model and assuming what was reasonable; 2) only considered fields that 
were *not* covered by specific update-like method in the API such as RepoApi.add_package().

Here's the basic update() impl pattern:

def update(id, delta):

   1. Get rid of the ID in the 'delta'.  Eg: delta.pop('id', None)
   2. Fetch the object.
   3. Iterate the 'delta' content in as CASE style loop.

          for key,value in delta.items():
              if key in ('a','b',...):  <----- SIMPLE UPDATES FIRST
                  object[key] = value
              if key == 'foobar':       <------ SPECIAL UPDATES (repeat)
                  <special logic>
                  object[key] = <something>
              # default                 <------ UNSUPPORTED
              raise Exception, 'not supported'

   4. Save the updated object using the mongo collection
   5. Return the updated object.

There are as many 'SPECIAL UPDATES' blocks as needed.  So, when adding a supported field 
to an update() method, please add another 'if key; continue' block.

After converting each API class, I updated the callers in the expected places:
   * The WS controllers
   * The other APIs
   * The unit tests
   * The CLI classes to just pass delta
   * The client.api classes update() signatures

In some cases, I changed the call to Api.update() to match the signature.  In other cases, 
the changed the call to use one of the specific update methods on the API such as 
RepoApi.add_package() rather then updating the packages list on the repo and calling 
update().  It's more appropriate anyway.

The nosetests are clean and I've sanity tested using the CLI.  But, I can't test 
everything.  I would really appreciate everyone taking a good look at the Api.update() 
methods and making sure I got the fields correct.  Also, take some time to double check 
the WS controllers as they are not tested by the unit tests.



More information about the Pulp-list mailing list