Skip retry loop on first check for group

Don't retry checking the DB multiple times on first call to see if group
exists when determining whether the group needs to be created.

If the group exists, a previous iteration would already have waited for
the group to be written down from the cache. So if nothing is returned
then the group does not exist, and there is no point rechecking multiple
times to see if it will appear from the cache.

This speeds up creation of new groups by avoiding a 10 second wait
before creation due to the first call for group uuid unnecessarily
retrying multiple times.

Change-Id: I0afbc716159e8aecf1ade6442d9b02674094fa08
diff --git a/jeepyb/cmd/manage_projects.py b/jeepyb/cmd/manage_projects.py
index 878a4a8..3474e2b 100644
--- a/jeepyb/cmd/manage_projects.py
+++ b/jeepyb/cmd/manage_projects.py
@@ -211,7 +211,7 @@
     return True
 
 
-def _get_group_uuid(group):
+def _get_group_uuid(group, retries=10):
     """
     Gerrit keeps internal user groups in the DB while it keeps systems
     groups in All-Projects groups file (in refs/meta/config).  This
@@ -224,7 +224,7 @@
     """
     query = "SELECT group_uuid FROM account_groups WHERE name = %s"
     con = jeepyb.gerritdb.connect()
-    for x in range(10):
+    for x in range(retries):
         cursor = con.cursor()
         cursor.execute(query, (group,))
         data = cursor.fetchone()
@@ -232,12 +232,13 @@
         con.commit()
         if data:
             return data[0]
-        time.sleep(1)
+        if retries > 1:
+            time.sleep(1)
     return None
 
 
 def get_group_uuid(gerrit, group):
-    uuid = _get_group_uuid(group)
+    uuid = _get_group_uuid(group, retries=1)
     if uuid:
         return uuid
     if group in GERRIT_SYSTEM_GROUPS: