~canonical-platform-qa/ubuntu-community-testing/fix-oauth-validation

« back to all changes in this revision

Viewing changes to ubuntu_pt_community/db/db.py

  • Committer: Brendan Donegan
  • Date: 2015-08-17 07:54:41 UTC
  • mfrom: (18.2.1 fix_db_config)
  • Revision ID: brendan.donegan@canonical.com-20150817075441-upex36d28j4dio4k
MergedĀ fromĀ trunk

Show diffs side-by-side

added added

removed removed

Lines of Context:
28
28
def get_database_client():
29
29
    """Return a MongoClient for the mongodb for this service."""
30
30
    config = get_config()
31
 
    return pymongo.MongoClient(config['address'], config['port'])
 
31
    port = config.get('port', None)
 
32
    port = int(port) if port else None
 
33
    return pymongo.MongoClient(config['address'], port)
32
34
 
33
35
 
34
36
def get_database(database_name):
62
64
    try:
63
65
        config_file_path = get_config_file_path()
64
66
        parser = configparser.ConfigParser()
65
 
        config = parser.read(config_file_path)
66
 
        return dict(config['mongodb'])
 
67
        parser.read(config_file_path)
 
68
        return dict(parser['mongodb'])
67
69
    except RuntimeError:
68
70
        # For local testing, should handle this better.
69
71
        return dict(address='localhost', port=27017)