[rql sources] uses an URL as remote host address for pyro/zmq rql sources,
instead of extra configuration parameters. Follows modification of dbapi.connect api.
Closes #2539822
--- a/doc/3.16.rst Fri Jan 04 15:18:44 2013 +0100
+++ b/doc/3.16.rst Fri Jan 04 15:39:52 2013 +0100
@@ -55,3 +55,11 @@
* Remove changelog view, as nor cubicweb nor known cubes/applications were properly
feeding related files
+
+
+Other changes
+-------------
+
+* 'pyrorql' sources will be automatically updated to use an URL to locate the source
+ rather than configuration option. 'zmqrql' sources were broken before this change,
+ so no upgrade needed...
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/misc/migration/3.16.0_Any.py Fri Jan 04 15:39:52 2013 +0100
@@ -0,0 +1,13 @@
+sync_schema_props_perms('EmailAddress')
+
+for source in rql('CWSource X WHERE X type "pyrorql"').entities():
+ sconfig = source.dictconfig
+ nsid = sconfig.pop('pyro-ns-id', config.appid)
+ nshost = sconfig.pop('pyro-ns-host', '')
+ nsgroup = sconfig.pop('pyro-ns-group', ':cubicweb')
+ if nsgroup:
+ nsgroup += '.'
+ source.cw_set(url=u'pyro://%s/%s%s' % (nshost, nsgroup, nsid))
+ source.update_config(skip_unknown=True, **sconfig)
+
+commit()
--- a/server/sources/pyrorql.py Fri Jan 04 15:18:44 2013 +0100
+++ b/server/sources/pyrorql.py Fri Jan 04 15:39:52 2013 +0100
@@ -23,9 +23,6 @@
import threading
from Pyro.errors import PyroError, ConnectionClosedError
-from logilab.common.configuration import REQUIRED
-
-from cubicweb import dbapi
from cubicweb import ConnectionError
from cubicweb.server.sources import ConnectionWrapper
@@ -34,44 +31,6 @@
class PyroRQLSource(RemoteSource):
"""External repository source, using Pyro connection"""
- CNX_TYPE = 'pyro'
-
- options = RemoteSource.options + (
- # XXX pyro-ns host/port
- ('pyro-ns-id',
- {'type' : 'string',
- 'default': REQUIRED,
- 'help': 'identifier of the repository in the pyro name server',
- 'group': 'remote-source', 'level': 0,
- }),
- ('pyro-ns-host',
- {'type' : 'string',
- 'default': None,
- 'help': 'Pyro name server\'s host. If not set, default to the value \
-from all_in_one.conf. It may contains port information using <host>:<port> notation.',
- 'group': 'remote-source', 'level': 1,
- }),
- ('pyro-ns-group',
- {'type' : 'string',
- 'default': None,
- 'help': 'Pyro name server\'s group where the repository will be \
-registered. If not set, default to the value from all_in_one.conf.',
- 'group': 'remote-source', 'level': 2,
- }),
- )
-
- def _get_connection(self):
- """open and return a connection to the source"""
- nshost = self.config.get('pyro-ns-host') or self.repo.config['pyro-ns-host']
- nsgroup = self.config.get('pyro-ns-group') or self.repo.config['pyro-ns-group']
- self.info('connecting to instance :%s.%s for user %s',
- nsgroup, self.config['pyro-ns-id'], self.config['cubicweb-user'])
- return dbapi.connect(database=self.config['pyro-ns-id'],
- login=self.config['cubicweb-user'],
- password=self.config['cubicweb-password'],
- host=nshost, group=nsgroup,
- setvreg=False)
-
def get_connection(self):
try:
return self._get_connection()
--- a/server/sources/remoterql.py Fri Jan 04 15:18:44 2013 +0100
+++ b/server/sources/remoterql.py Fri Jan 04 15:39:52 2013 +0100
@@ -49,8 +49,6 @@
class RemoteSource(AbstractSource):
"""Generic external repository source"""
- CNX_TYPE = None # Must be ovewritted !
-
# boolean telling if modification hooks should be called when something is
# modified in this source
should_call_hooks = False
@@ -112,14 +110,10 @@
if source_entity is not None:
self.latest_retrieval = source_entity.latest_retrieval
- def _get_connection(self):
- """open and return a connection to the source"""
- self.info('connecting to source %(base-url)s with user %(cubicweb-user)s',
- self.config)
- cnxprops = ConnectionProperties(cnxtype=self.CNX_TYPE)
- return dbapi.connect(login=self.config['cubicweb-user'],
- password=self.config['cubicweb-password'],
- cnxprops=cnxprops)
+ def _entity_update(self, source_entity):
+ super(RemoteSource, self)._entity_update(source_entity)
+ if self.urls and len(self.urls) > 1:
+ raise ValidationError(source_entity.eid, {'url': _('can only have one url')})
def get_connection(self):
try:
@@ -128,6 +122,13 @@
self.critical("can't get connection to source %s: %s", self.uri, ex)
return ConnectionWrapper()
+ def _get_connection(self):
+ """open and return a connection to the source"""
+ self.info('connecting to source %s as user %s',
+ self.urls[0], self.config['cubicweb-user'])
+ # XXX check protocol according to source type (zmq / pyro)
+ return dbapi.connect(self.urls[0], login=self.config['cubicweb-user'],
+ password=self.config['cubicweb-password'])
def reset_caches(self):
"""method called during test to reset potential source caches"""
@@ -238,7 +239,7 @@
"""synchronize content known by this repository with content in the
external repository
"""
- self.info('synchronizing remote %s source %s', (self.CNX_TYPE, self.uri))
+ self.info('synchronizing remote source %s', self.uri)
cnx = self.get_connection()
try:
extrepo = cnx._repo
--- a/server/sources/zmqrql.py Fri Jan 04 15:18:44 2013 +0100
+++ b/server/sources/zmqrql.py Fri Jan 04 15:39:52 2013 +0100
@@ -24,4 +24,3 @@
class ZMQRQLSource(RemoteSource):
"""External repository source, using ZMQ sockets"""
- CNX_TYPE = 'zmq'
--- a/server/test/unittest_multisources.py Fri Jan 04 15:18:44 2013 +0100
+++ b/server/test/unittest_multisources.py Fri Jan 04 15:39:52 2013 +0100
@@ -33,7 +33,6 @@
MTIME = datetime.utcnow() - timedelta(0, 10)
EXTERN_SOURCE_CFG = u'''
-pyro-ns-id = extern
cubicweb-user = admin
cubicweb-password = gingkow
base-url=http://extern.org/
@@ -60,9 +59,10 @@
def pre_setup_database_multi(session, config):
session.create_entity('CWSource', name=u'extern', type=u'pyrorql',
- config=EXTERN_SOURCE_CFG)
+ url=u'pyro:///extern', config=EXTERN_SOURCE_CFG)
session.commit()
+
class TwoSourcesTC(CubicWebTC):
"""Main repo -> extern-multi -> extern
\-------------/
@@ -90,7 +90,6 @@
cls.cnx3.close()
TestServerConfiguration.no_sqlite_wrap = False
-
@classmethod
def _init_repo(cls):
repo2_handler = get_test_db_handler(cls._cfg2)
@@ -122,12 +121,11 @@
def pre_setup_database(session, config):
for uri, src_config in [('extern', EXTERN_SOURCE_CFG),
('extern-multi', '''
-pyro-ns-id = extern-multi
cubicweb-user = admin
cubicweb-password = gingkow
''')]:
source = session.create_entity('CWSource', name=unicode(uri),
- type=u'pyrorql',
+ type=u'pyrorql', url=u'pyro:///extern-multi',
config=unicode(src_config))
session.commit()
add_extern_mapping(source)