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:19:08 +1000 |
| commit | 784e48b35c03f83366671d720483f0cb288ffe77 (patch) | |
| tree | a4d457d400d81df4ca9855ea4b227aa8e7968bec | |
| parent | 7df3c3d9ea4620ea85eed7374d08e78878d8f9e2 (diff) | |
Added loop to check if we have any users with a time delay to avoid race condition
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': |
