Merge lp://staging/~free.ekanayaka/storm/schema-uri-in-testresource into lp://staging/storm

Proposed by Free Ekanayaka
Status: Merged
Approved by: Björn Tillenius
Approved revision: 394
Merge reported by: Free Ekanayaka
Merged at revision: not available
Proposed branch: lp://staging/~free.ekanayaka/storm/schema-uri-in-testresource
Merge into: lp://staging/storm
Diff against target: 226 lines (+137/-14)
3 files modified
NEWS (+16/-0)
storm/zope/testing.py (+45/-11)
tests/zope/testing.py (+76/-3)
To merge this branch: bzr merge lp://staging/~free.ekanayaka/storm/schema-uri-in-testresource
Reviewer Review Type Date Requested Status
Björn Tillenius (community) Approve
Thomas Herve (community) Approve
Review via email: mp+59353@code.staging.launchpad.net

Description of the change

This branch makes ZStormResourceManager support applying database schemas by connecting with a custom URI, typically using a user with greater privileges than the application one.

To post a comment you must log in.
391. By Free Ekanayaka

Fix docstring

Revision history for this message
Thomas Herve (therve) wrote :

[1]
+ different user with greater priviliges than the user running the tests. Note

Typo: privileges.

+1!

review: Approve
Revision history for this message
Free Ekanayaka (free.ekanayaka) wrote :

Thanks Thomas!

[1]

Fixed.

392. By Free Ekanayaka

Fix typo

393. By Free Ekanayaka

Clear the alive cache before calling transaction.abort

394. By Free Ekanayaka

Add force_delete class variable

Revision history for this message
Björn Tillenius (bjornt) wrote :

This looks reasonable to me. Since I'm no Storm expert, I do have some questions, though?

[1]

+ @param databases: A C{list} of C{dict}s holding the following keys:
+ - 'name', the name of the store to be registered.
+ - 'uri', the database URI to use to create the store.
+ - 'schema', the L{Schema} for the tables in the store.
+ - 'schema-uri', optionally an alternate URI to use for applying the
+ schema, if not given it defaults to 'uri'.

Maybe it would be worth adding a note about the old deprecated format as well? It will save someone some confusion, when he see that the code he has doesn't match the documentation.

[2]
+ schema_zstorm = ZStorm()
+ databases = self._databases
+
+ # Adapt the old databases format to the new one, for backward
+ # compatibility. This should be eventually dropped.
+ if isinstance(databases, dict):
+ databases = [{"name": name, "uri": uri, "schema": schema}
+ for name, (uri, schema) in databases.iteritems()]
+
+ for database in databases:
+ name = database["name"]
+ uri = database["uri"]
+ schema = database["schema"]
+ schema_uri = database.get("schema-uri", uri)
+ self._schemas[name] = schema
                 zstorm.set_default_uri(name, uri)
+ schema_zstorm.set_default_uri(name, schema_uri)
                 store = zstorm.get(name)
                 self._set_commit_proxy(store)
- schema.upgrade(store)
+ schema_store = schema_zstorm.get(name)
+ schema.upgrade(schema_store)

I guess we will always have two connections to the database, even if the same user is to be used? Will this have the risk of causing any trouble for someone? Would it make sense to set schema_zstorm = zstorm, if no schema_uri is provided, to have it work exactly as before, if no specific user is specified.

[3]

Specifying a schema URI requires you to repeat certain things from the normal URI, like database type, port number, host name, database name. Would it be possible to come up with an API where you specify only a username and password?

review: Needs Information
Revision history for this message
Björn Tillenius (bjornt) wrote :

< free> BjornT: so about point [1], maybe it'd create more confusion than.
        clarity, because this feature was added just in the last Storm.
        release, and I'd be surprised if there's any code beside.
        clouddeck that is using it
< BjornT> free: sure, sounds reasonable
< free> BjornT: about point [2], yeah, I've thought about that as well,.
        but probably it's good to keep the connections separate in all.
        cases, for separating concerns, in case some test really messes.
        up the stores
< free> BjornT: [3] is a bit unfortunate indeed, but actually it would be.
        possible to pass a storm.uri.URI() object, the thing is that the.
        latter is not really part of the public API, I guess
< free> BjornT: and requires a string in the __init__, I guess it could.
        be changed to accomodate similar use cases
< free> BjornT: and the code in the branch would work without changes
< free> BjornT: passing only the user and the password might not be.
        enough, because you might want to pass specific options, etc. so.
        an uri string or an URI object is the most generic way to do that
< BjornT> free: ok. none of these issues were blocking. i mainly wanted.
          to make sure you thought about these things.

review: Approve
Revision history for this message
Jamu Kakar (jkakar) wrote :

As a point of reference, we're using ZStormResourceManager in
Fluidinfo. Anyway, this change won't cause problems for us, thanks
for pushing it forward! :)

Revision history for this message
Free Ekanayaka (free.ekanayaka) wrote :

@Jamu: Doh :)

Revision history for this message
Gustavo Niemeyer (niemeyer) wrote :

As a minor nit, it feels like it's time to introduce a richer object to hold that information. There's no reason to carry around that kind of untyped blob and have to parse it out when reading.

Note that *everything* can be represented as a key and a value in a dict in a list in a ... still, we use types and instances with nicely named methods, etc.

Revision history for this message
Free Ekanayaka (free.ekanayaka) wrote :

Hi Gustavo,

so you mean a parameter object? like:

class ZStormResourceManagerDatabase(object):

    def __init__(self, name, uri, schema, schema_uri=None):
        ...

and then

   manager = ZStormResourceManager([ZStormResourceManagerDatabase(...),
                                    ZStormResourceManagerDatabase(...),
                                    ...])

Alternatively instead of passing this information in the constructor we could have a configuration method like:

class ZStormResourceManager(object):

    def add_database(self, name, uri, schema, schema_uri=None):
        ...

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
The diff is not available at this time. You can reload the page or download it.

Subscribers

People subscribed via source and target branches

to status/vote changes: