First off, I love this project. Big time user first time caller.
Quick bug report that ldap_sync.py doesn't seem to work if there are currently 0 users in the oncall database. The relevant section of code is below:
159 oncall_users = {}
160 users_query = '''SELECT `user`.`name` as `name`, `contact_mode`.`name` as `mode`, `user_contact`.`destination`,
161 `user`.`full_name`, `user`.`photo_url`
162 FROM `user`
163 LEFT OUTER JOIN `user_contact` ON `user`.`id` = `user_contact`.`user_id`
164 LEFT OUTER JOIN `contact_mode` ON `user_contact`.`mode_id` = `contact_mode`.`id`
165 ORDER BY `user`.`name`'''
(Pdb)
166 for row in engine.execute(users_query):
167 contacts = oncall_users.setdefault(row.name, {})
168 if row.mode is None or row.destination is None:
169 continue
170 contacts[row.mode] = row.destination
171 contacts['full_name'] = row.full_name
172 contacts['photo_url'] = row.photo_url
173
174 oncall_usernames = set(oncall_users)
175
176 # users from ldap and config file
(Pdb)
177 ldap_users = fetch_ldap()
178 stats['ldap_found'] += len(ldap_users)
179 ldap_users.update(get_predefined_users(config))
180 ldap_usernames = set(ldap_users)
181
182 # set of ldap users not in oncall
183 users_to_insert = ldap_usernames - oncall_usernames
184 # set of existing oncall users that are in ldap
185 users_to_update = oncall_usernames & ldap_usernames
186 # set of users in oncall but not ldap, assumed to be inactive
187 inactive_users = oncall_usernames - ldap_usernames
(Pdb)
188 # users who need to be deactivated
189 rows = engine.execute('SELECT name FROM user WHERE active = TRUE AND name IN %s', inactive_users)
File "ldap_sync.py", line 309, in <module>
main(config)
File "ldap_sync.py", line 300, in main
sync(config, engine)
File "ldap_sync.py", line 189, in sync
rows = engine.execute('SELECT name FROM user WHERE active = TRUE AND name IN %s', inactive_users)
File "/alldata/home/iris/env/local/lib/python2.7/site-packages/sqlalchemy/engine/base.py", line 1991, in execute
return connection.execute(statement, *multiparams, **params)
File "/alldata/home/iris/env/local/lib/python2.7/site-packages/sqlalchemy/engine/base.py", line 906, in execute
return self._execute_text(object, multiparams, params)
File "/alldata/home/iris/env/local/lib/python2.7/site-packages/sqlalchemy/engine/base.py", line 1054, in _execute_text
statement, parameters
File "/alldata/home/iris/env/local/lib/python2.7/site-packages/sqlalchemy/engine/base.py", line 1146, in _execute_context
context)
File "/alldata/home/iris/env/local/lib/python2.7/site-packages/sqlalchemy/engine/base.py", line 1341, in _handle_dbapi_exception
exc_info
File "/alldata/home/iris/env/local/lib/python2.7/site-packages/sqlalchemy/util/compat.py", line 200, in raise_from_cause
reraise(type(exception), exception, tb=exc_tb)
File "/alldata/home/iris/env/local/lib/python2.7/site-packages/sqlalchemy/engine/base.py", line 1139, in _execute_context
context)
File "/alldata/home/iris/env/local/lib/python2.7/site-packages/sqlalchemy/engine/default.py", line 450, in do_execute
cursor.execute(statement, parameters)
File "/alldata/home/iris/env/local/lib/python2.7/site-packages/pymysql/cursors.py", line 158, in execute
result = self._query(query)
File "/alldata/home/iris/env/local/lib/python2.7/site-packages/pymysql/cursors.py", line 308, in _query
conn.query(q)
File "/alldata/home/iris/env/local/lib/python2.7/site-packages/pymysql/connections.py", line 820, in query
self._affected_rows = self._read_query_result(unbuffered=unbuffered)
File "/alldata/home/iris/env/local/lib/python2.7/site-packages/pymysql/connections.py", line 1002, in _read_query_result
result.read()
File "/alldata/home/iris/env/local/lib/python2.7/site-packages/pymysql/connections.py", line 1285, in read
first_packet = self.connection._read_packet()
File "/alldata/home/iris/env/local/lib/python2.7/site-packages/pymysql/connections.py", line 966, in _read_packet
packet.check_error()
File "/alldata/home/iris/env/local/lib/python2.7/site-packages/pymysql/connections.py", line 394, in check_error
err.raise_mysql_exception(self._data)
File "/alldata/home/iris/env/local/lib/python2.7/site-packages/pymysql/err.py", line 120, in raise_mysql_exception
_check_mysql_exception(errinfo)
File "/alldata/home/iris/env/local/lib/python2.7/site-packages/pymysql/err.py", line 112, in _check_mysql_exception
raise errorclass(errno, errorvalue)
sqlalchemy.exc.ProgrammingError: (pymysql.err.ProgrammingError) (1064, u"You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ')' at line 1") [SQL: 'SELECT name FROM user WHERE active = TRUE AND name IN %s'] [parameters: (set([]),)]
I got around it in the meantime by just using oncall-admin to create a temporary user.