summaryrefslogtreecommitdiff
diff options
authorBrad Marshall <brad.marshall@canonical.com>2017-10-18 17:26:34 +1000
committerBrad Marshall <brad.marshall@canonical.com>2017-10-18 17:26:34 +1000
commita82a300a29fa615e17c362f8dae486fa2833c0ea (patch)
tree817643080c7cc6f18fbe9181d60904742a71b12f
parent784e48b35c03f83366671d720483f0cb288ffe77 (diff)
Refactor the for loop a little to be less complicatedsql-install-race
-rw-r--r--reactive/grafana.py13
1 files changed, 4 insertions, 9 deletions
diff --git a/reactive/grafana.py b/reactive/grafana.py
index 9235ee4..8b3b126 100644
--- a/reactive/grafana.py
+++ b/reactive/grafana.py
@@ -452,18 +452,13 @@ 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
-
+ results = cur.execute('SELECT count(login) from user')
+ usercount = results.fetchall()[0][0]
+ if usercount > 0:
+ break
else:
hookenv.log("We didn't find any users!")
return