Eliminate the race when selecting a port for tests.

Functional tests currently select ports on which the various services
will listen by opening a socket in the ephemeral port range, checking
its port, closing the socket, and then sometime later starting the
service and instructing it to use that port.  There are a few bugs that
reference fragile tests.  In many of these case it is possible that
another processes claimed the selected port in between the time it was
first opened and closed and the time that the service actually used it.
Because this is a known possibility, and because the tests fail
infrequently resolving these bug becomes difficult.

This patch eliminates the window in which another processes could claim
the port.  The socket is opened in the test code but not closed. Then
the service process (api or registry) is forked off where it inherits
the open file descriptor.  A environment variable is used to tell the
new wsgi process that it is a test process and should thus get its
socket from the FD instead of creating a new socket.

In the case where glance-control is used with the --respawn option this
solution is not possible.  The problem is that the FD is only good once.
I can pass from the test code, to glance-control, and to glance-{api,
registry} but only 1 time.  If the service dies, and glance-control
restarts it the FD will no longer be valid.  For this case the forked FD
code is disabled.  However, the socket is still closed much later making
the race condition even less likely.

This fixes bug: 1047593
It may fix some other "fragile test" bugs as well.

Change-Id: I27313d144bc7bd2132a604dcc22916c80338abab
Merge "Eliminate the race when selecting a port for tests."