[pyramid] Avoid shutting down the repository at exit if it's already shutting down
For install `cubicweb-ctl pyramid` command will explicitly call
`repo.shutdown()` so the atexit hook is redundant. Prevent the latter to be
executed when the repository is already shutting down (otherwise one gets an
assertion error).
[server/test] Extract a "ldapsource" function in unittest_ldapsource.py
We will add more use of this pattern in forthcoming changesets,
so avoid repetition.