properly fail if user has entered wrong connection information for the system database, closes #549136 stable
authorSylvain Thénault <sylvain.thenault@logilab.fr>
Tue, 01 Dec 2009 12:00:20 +0100
branchstable
changeset 3954 56a8b14d68aa
parent 3953 19aefd78f61b
child 3955 235a9fda6058
properly fail if user has entered wrong connection information for the system database, closes #549136
server/serverctl.py
--- a/server/serverctl.py	Tue Dec 01 08:43:37 2009 +0100
+++ b/server/serverctl.py	Tue Dec 01 12:00:20 2009 +0100
@@ -241,6 +241,7 @@
 
 
 # repository specific commands ################################################
+
 class CreateInstanceDBCommand(Command):
     """Create the system database of an instance (run after 'create').
 
@@ -359,8 +360,20 @@
     def run(self, args):
         print '\n'+underline_title('Initializing the system database')
         from cubicweb.server import init_repository
+        from logilab.common.db import get_connection
         appid = pop_arg(args, msg='No instance specified !')
         config = ServerConfiguration.config_for(appid)
+        try:
+            system = config.sources()['system']
+            get_connection(
+                system['db-driver'], database=system['db-name'],
+                host=system.get('db-host'), port=system.get('db-port'),
+                user=system.get('db-user'), password=system.get('db-password'))
+        except Exception, ex:
+            raise ConfigurationError(
+                'You seem to have provided wrong connection information in '\
+                'the %s file. Resolve this first (error: %s).'
+                % (config.sources_file(), str(ex).strip()))
         init_repository(config, drop=self.config.drop)
 
 
@@ -405,6 +418,7 @@
             cnx.commit()
             print '-> rights granted to %s on instance %s.' % (appid, user)
 
+
 class ResetAdminPasswordCommand(Command):
     """Reset the administrator password.