Fix IP recycling on exhausted pool
When recycling an IP, allocation pools are loaded with an inner
join with ip avaiblity ranges. However, if the pool is exhausted,
there will be no availability ranges and the query will return
no results because of the inner join. It will therefore be
impossible to reuse IP addresses once the pool has been exhausted.
This patch tries to reload allocation pools without joining on
IP avaiability ranges if the first query did not return any result.
Replacing an inner join with an outer join will not be possible
as postgresql backend does not support 'SELECT ... FOR UPDATE' with
outer joins (for more info see bug
1215350).
The patch also contains unit tests for verifying IP are recycled
correctly even when the pool is exhausted.
Bug
1240353
Change-Id: I87f274bd759cb47be77717f0760d3704f9f34ade