diff options
| author | Brad Marshall <brad.marshall@canonical.com> | 2017-10-18 16:11:46 +1000 |
|---|---|---|
| committer | Brad Marshall <brad.marshall@canonical.com> | 2017-10-18 16:11:46 +1000 |
| commit | 6d0cdef37dbe34c0e3ff5679ae8190f0a322efed (patch) | |
| tree | 8d6b39b9aa6bd770d96bd17c12558a697919ac30 | |
| parent | be560db9f73d7050e7f738523d452561b46c8524 (diff) | |
Added loop to check if we have any users with a time delay to avoid race conditionuser-acct-race-fix
on install
| -rw-r--r-- | reactive/grafana.py | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/reactive/grafana.py b/reactive/grafana.py index d3b90bc..9235ee4 100644 --- a/reactive/grafana.py +++ b/reactive/grafana.py @@ -15,6 +15,7 @@ from charmhelpers.contrib.charmsupport import nrpe from charms.reactive import hook, remove_state, set_state, when, when_not from charms.reactive.helpers import any_file_changed, data_changed, is_state +import time try: import sqlite3 @@ -450,6 +451,23 @@ def check_adminuser(): conn = sqlite3.connect('/var/lib/grafana/grafana.db', timeout=30) cur = conn.cursor() + # Check if we have more than one user in the db + found = False + for x in range(0, 5): + if found: + break + hookenv.log("Checking for existing users, loop %d of 6" % (x + 1)) + time.sleep(5) + usercount = cur.execute('SELECT count(login) from user') + for row in usercount.fetchall(): + if row[0] > 0: + found = True + break + + else: + hookenv.log("We didn't find any users!") + return + query = cur.execute('SELECT id, login, salt FROM user') for row in query.fetchall(): if row[1] == 'admin': |
