@@ -369,15 +369,6 @@ def getDBParameters(fullname):
369
369
"""Retrieve Database parameters from CS
370
370
371
371
:param str fullname: should be of the form <System>/<DBname>
372
- defaultHost is the host to return if the option is not found in the CS.
373
- Not used as the method will fail if it cannot be found
374
- defaultPort is the port to return if the option is not found in the CS
375
- defaultUser is the user to return if the option is not found in the CS.
376
- Not usePassword is the password to return if the option is not found in the CS.
377
- Not used as the method will fail if it cannot be found
378
- defaultDB is the db to return if the option is not found in the CS.
379
- Not used as the method will fail if it cannot be found
380
- defaultQueueSize is the QueueSize to return if the option is not found in the CS
381
372
382
373
:return: S_OK(dict)/S_ERROR() - dictionary with the keys: 'host', 'port', 'user', 'password',
383
374
'db' and 'queueSize'
@@ -386,6 +377,25 @@ def getDBParameters(fullname):
386
377
cs_path = getDatabaseSection (fullname )
387
378
parameters = {}
388
379
380
+ # Check mandatory parameters first: Password, User, Host and DBName
381
+ result = gConfig .getOption (cs_path + "/Password" )
382
+ if not result ["OK" ]:
383
+ # No individual password found, try at the common place
384
+ result = gConfig .getOption ("/Systems/Databases/Password" )
385
+ if not result ["OK" ]:
386
+ return S_ERROR ("Failed to get the configuration parameter: Password" )
387
+ dbPass = result ["Value" ]
388
+ parameters ["Password" ] = dbPass
389
+
390
+ result = gConfig .getOption (cs_path + "/User" )
391
+ if not result ["OK" ]:
392
+ # No individual user name found, try at the common place
393
+ result = gConfig .getOption ("/Systems/Databases/User" )
394
+ if not result ["OK" ]:
395
+ return S_ERROR ("Failed to get the configuration parameter: User" )
396
+ dbUser = result ["Value" ]
397
+ parameters ["User" ] = dbUser
398
+
389
399
result = gConfig .getOption (cs_path + "/Host" )
390
400
if not result ["OK" ]:
391
401
# No host name found, try at the common place
@@ -401,6 +411,13 @@ def getDBParameters(fullname):
401
411
dbHost = "localhost"
402
412
parameters ["Host" ] = dbHost
403
413
414
+ result = gConfig .getOption (cs_path + "/DBName" )
415
+ if not result ["OK" ]:
416
+ return S_ERROR ("Failed to get the configuration parameter: DBName" )
417
+ dbName = result ["Value" ]
418
+ parameters ["DBName" ] = dbName
419
+
420
+ # Check optional parameters: Port
404
421
# Mysql standard
405
422
dbPort = 3306
406
423
result = gConfig .getOption (cs_path + "/Port" )
@@ -413,30 +430,6 @@ def getDBParameters(fullname):
413
430
dbPort = int (result ["Value" ])
414
431
parameters ["Port" ] = dbPort
415
432
416
- result = gConfig .getOption (cs_path + "/User" )
417
- if not result ["OK" ]:
418
- # No individual user name found, try at the common place
419
- result = gConfig .getOption ("/Systems/Databases/User" )
420
- if not result ["OK" ]:
421
- return S_ERROR ("Failed to get the configuration parameter: User" )
422
- dbUser = result ["Value" ]
423
- parameters ["User" ] = dbUser
424
-
425
- result = gConfig .getOption (cs_path + "/Password" )
426
- if not result ["OK" ]:
427
- # No individual password found, try at the common place
428
- result = gConfig .getOption ("/Systems/Databases/Password" )
429
- if not result ["OK" ]:
430
- return S_ERROR ("Failed to get the configuration parameter: Password" )
431
- dbPass = result ["Value" ]
432
- parameters ["Password" ] = dbPass
433
-
434
- result = gConfig .getOption (cs_path + "/DBName" )
435
- if not result ["OK" ]:
436
- return S_ERROR ("Failed to get the configuration parameter: DBName" )
437
- dbName = result ["Value" ]
438
- parameters ["DBName" ] = dbName
439
-
440
433
return S_OK (parameters )
441
434
442
435
@@ -451,6 +444,26 @@ def getElasticDBParameters(fullname):
451
444
cs_path = getDatabaseSection (fullname )
452
445
parameters = {}
453
446
447
+ # Check mandatory parameters first: Password, User
448
+ result = gConfig .getOption (cs_path + "/Password" )
449
+ if not result ["OK" ]:
450
+ # No individual password found, try at the common place
451
+ result = gConfig .getOption ("/Systems/NoSQLDatabases/Password" )
452
+ if not result ["OK" ]:
453
+ return S_ERROR ("Failed to get the configuration parameter: Password." )
454
+ dbPass = result ["Value" ]
455
+ parameters ["Password" ] = dbPass
456
+
457
+ result = gConfig .getOption (cs_path + "/User" )
458
+ if not result ["OK" ]:
459
+ # No individual user name found, try at the common place
460
+ result = gConfig .getOption ("/Systems/NoSQLDatabases/User" )
461
+ if not result ["OK" ]:
462
+ return S_ERROR ("Failed to get the configuration parameter: User." )
463
+ dbUser = result ["Value" ]
464
+ parameters ["User" ] = dbUser
465
+
466
+ # Check optional parameters: Host, Port, SSL, CRT, ca_certs, client_key, client_cert
454
467
result = gConfig .getOption (cs_path + "/Host" )
455
468
if not result ["OK" ]:
456
469
# No host name found, try at the common place
@@ -484,36 +497,6 @@ def getElasticDBParameters(fullname):
484
497
dbPort = int (result ["Value" ])
485
498
parameters ["Port" ] = dbPort
486
499
487
- result = gConfig .getOption (cs_path + "/User" )
488
- if not result ["OK" ]:
489
- # No individual user name found, try at the common place
490
- result = gConfig .getOption ("/Systems/NoSQLDatabases/User" )
491
- if not result ["OK" ]:
492
- gLogger .warn (
493
- "Failed to get the configuration parameter: User. Assuming no user/password is provided/needed"
494
- )
495
- dbUser = None
496
- else :
497
- dbUser = result ["Value" ]
498
- else :
499
- dbUser = result ["Value" ]
500
- parameters ["User" ] = dbUser
501
-
502
- result = gConfig .getOption (cs_path + "/Password" )
503
- if not result ["OK" ]:
504
- # No individual password found, try at the common place
505
- result = gConfig .getOption ("/Systems/NoSQLDatabases/Password" )
506
- if not result ["OK" ]:
507
- gLogger .warn (
508
- "Failed to get the configuration parameter: Password. Assuming no user/password is provided/needed"
509
- )
510
- dbPass = None
511
- else :
512
- dbPass = result ["Value" ]
513
- else :
514
- dbPass = result ["Value" ]
515
- parameters ["Password" ] = dbPass
516
-
517
500
result = gConfig .getOption (cs_path + "/SSL" )
518
501
if not result ["OK" ]:
519
502
# No SSL option found, try at the common place
0 commit comments