Handle invalid edition on xapi startup

We changed the editions in a later version of XenServer. If an old xapi
restarts during an upgrade, we may have an invalid edition in the database. If
the edition found in the database isn't in the list of allowed editions, we
instead use the "default edition" (the "lowest" edition returned by
V6client.get_editions).

CA-121350

Signed-off-by: Mike McClurg <mike.mcclurg@citrix.com>

fix
Refactor License_init.initialise

Clean up initialise, and move xcp-mode error handler into initialise, since we
now call V6client functions from initialise.

Signed-off-by: Mike McClurg <mike.mcclurg@citrix.com>
Add dependency injection for V6client to License_init

Signed-off-by: Mike McClurg <mike.mcclurg@citrix.com>
Add Pool_role_shared.set_pool_role_test for unit testing

Signed-off-by: Mike McClurg <mike.mcclurg@citrix.com>
Add unit tests for CA-121350

Signed-off-by: Mike McClurg <mike.mcclurg@citrix.com>
Add some packages and paths to merlin file

Signed-off-by: Mike McClurg <mike.mcclurg@citrix.com>
We shouldn't be printf'ing things

Signed-off-by: Mike McClurg <mike.mcclurg@citrix.com>
Refactor xapi.ml for unit testing

Move main loop to xapi_main.ml so we don't run it when we run unit tests.
Extract function for initializing unix domain sockets.

Signed-off-by: Mike McClurg <mike.mcclurg@citrix.com>
WIP unit tests: start http_svr, enable logging

Signed-off-by: Mike McClurg <mike.mcclurg@citrix.com>
Set pool role to Master during unit tests

Make sure pool role is correctly set during startup. Since Context's initial
database is created at module init time, we need to do this even before the
unit test harness can positively set the pool role. We check that this is a
unit test context by checking that the executable's name is not 'xapi'. If it's
not, we assume unit test.

This commit also modifies config_misc to return a default string for the Xen
version if we're running in unit test mode and get an error that we can't
connect to the xc interface.

Signed-off-by: Mike McClurg <mike.mcclurg@citrix.com>
Unit tests can make API calls and persist DB to disk

Suite now initialises xapi's http-svr, http handlers, and domain sockets. The
mock database is set to persist to disk, and can persist between invocations of
make_context_with_new_db (but by default it creates a fresh database each
time). Test case test_ca12350 has been modified to take advantage of these
improvements.

Signed-off-by: Mike McClurg <mike.mcclurg@citrix.com>
Fix test case test_pool_db_backup

This test case was broken by the database changes in the previous commit. After
inspecting the test case, it appears that the test itself was incorrect, and
was passing only because of oddities in the way that the mock database was
constructed. This commit fixes the test case.

Signed-off-by: Mike McClurg <mike.mcclurg@citrix.com>
Merge pull request #1582 from mcclurmc/more-unit-tests-ca121350

Future-proof against license-editions changes; major unit test improvements