Scenario : Start instances using fixed network when possible

Uses the fixed_network_name option to select which network
to boot test instances on.  This allows Tempest to be run
in environments where there are multiple networks available.

Change-Id: I64ad6ce6bee3fe33537ac4f8d8d913856fe46554
Partial-Bug: #1250866
diff --git a/tempest/scenario/manager.py b/tempest/scenario/manager.py
index b4fb6ab..2a40238 100644
--- a/tempest/scenario/manager.py
+++ b/tempest/scenario/manager.py
@@ -290,6 +290,27 @@
             image = CONF.compute.image_ref
         if flavor is None:
             flavor = CONF.compute.flavor_ref
+
+        fixed_network_name = CONF.compute.fixed_network_name
+        if 'nics' not in create_kwargs and fixed_network_name:
+            networks = client.networks.list()
+            # If several networks found, set the NetID on which to connect the
+            # server to avoid the following error "Multiple possible networks
+            # found, use a Network ID to be more specific."
+            # See Tempest #1250866
+            if len(networks) > 1:
+                for network in networks:
+                    if network.label == fixed_network_name:
+                        create_kwargs['nics'] = [{'net-id': network.id}]
+                        break
+                # If we didn't find the network we were looking for :
+                else:
+                    msg = ("The network on which the NIC of the server must "
+                           "be connected can not be found : "
+                           "fixed_network_name=%s. Starting instance without "
+                           "specifying a network.") % fixed_network_name
+                    LOG.info(msg)
+
         LOG.debug("Creating a server (name: %s, image: %s, flavor: %s)",
                   name, image, flavor)
         server = client.servers.create(name, image, flavor, **create_kwargs)