alphagov/vcloud-core — pull request #74 by mattbostock (2014-06-02 08:09:18+00:00)
Title: Create fixtures for EdgeGateway integration tests

Add a new helper function for the Vcloud::Core::EdgeGateway integration tests, IntegrationHelper::ensure_networks_correct, that checks if the
networks required for the integration tests already exist in the test
organisation and if not, create them.

Notice that we don't tear down the networks once tests have finished.
There are two reasons for this; firstly because deleting and creating
networks can be expensive operations and secondly because many other
tests rely on these networks and have not yet been converted to create
these fixtures as required. I'm no longer convinced that setting up and
tearing down the networks before and after each test run is so
expensive, so it's worth reexamining this once all of the other tests
are able to setup their fixtures as required (see story 67916012).

If a network with the same name as the test networks already exists, we
check its configuration and raise an error if it is incorrectly
configured for our tests. Raise an error rather than deleting these
networks as it's less aggressive and an existing network with a
different configuration may indicate an underlying issue, i.e. perhaps
the tests are running against the wrong organisation.

Note that we don't check the 'IsEnabled' property of the network
adapters as it's not exposed by the call to
Fog::Compute::VcloudDirector::Collection#all. We could make an extra
call to the API separately but in reality a disabled network is an edge
case and I don't think it's worth the extra API call.

* * *

We use Fog::Compute::VcloudDirector::Collection#all to retrieve the list
of networks in the organisation instead of
Vcloud::Core::EdgeGateway#interfaces as that method does not return
_isolated_ networks, which appear not to associate to a specific Edge
Gateway. Interestingly, the EdgeGateway#interfaces method _does_ return
the 'IsEnabled' property for network interfaces (see comments above).

* * *

We define an array of test parameters (populated with values from the
vCloud Tools Tester gem) so that we can modify the parameters later.
This is necessary so that we can set the network UUID (`network_1_id`
and `network_2_id` specifically) if the networks have been created by
the IntegrationHelper::ensure_networks_correct method.

This may indicate that we need more flexibility in the vCloud Tools
Tester gem either so that test parameters can be modified, or so that
vCloud Tools Tester assumes the responsibility of setting up test
fixtures.

Also, once other gems have been updated so that the network UUIDs are
set by querying the API, we should remove these as test parameters so
that they are no longer read from the configuration file consumed by
vCloud Tools Tester.