Use advanced image only when it's necessary

In some scenario tests there is need to use advanced image,
like Ubuntu or Centos, because Cirros doesn't provide required
features.
It is like that in some tests from modules:

    neutron_tempest_plugin.scenario.test_mtu
    neutron_tempest_plugin.scenario.test_trunk

But such advanced image needs much more time to boot and to
have SSH to vm available.

There is no need to use such advanced image in all tests.

This patch makes some changes in tempest plugin config options:

* image_is_advanced - option is removed,
* advanced_image_ref - new option added - it's uuid for advanced image,
* advanced_flavor_ref - new option added - id of flavor to use with
  advanced image
* advanced_image_ssh_user - new option added - name of user to use
  to ssh to vm booted from advanced image,

This patch also modify neutron_tempest_plugin devstack plugin that
it now can find advanced image id in installed Glance service and
configure those new config options in Tempest's config file.

This patch also modifies scenario jobs definitions that this
new advanced_image can be configured and used when it's nesessary.

Finally this patch also changes tests mentioned above that now
this advanced image is used in those tests.
All other scenario tests should works with default, Cirros image.

Change-Id: If1b83fbaf33cc01473badeb5cabc8e8670d51d9e
diff --git a/devstack/functions.sh b/devstack/functions.sh
index 026f527..8d8a4bf 100644
--- a/devstack/functions.sh
+++ b/devstack/functions.sh
@@ -30,3 +30,58 @@
     # Restore xtrace
     $_XTRACE_FUNCTIONS
 }
+
+#Add advanced image config to tempest.conf
+function configure_advanced_image {
+    local advanced_image_uuid
+
+    if ! is_service_enabled glance; then
+        # if glance is not enabled, there is no image for to configure
+        return 0
+    fi
+
+    if [[ -z "$ADVANCED_IMAGE_NAME" ]]; then
+        # if name of advanced image is not provided, there is no image to
+        # configure
+        return 0
+    fi
+
+    while read -r IMAGE_NAME IMAGE_UUID; do
+        if [ "$IMAGE_NAME" = "$ADVANCED_IMAGE_NAME" ]; then
+            advanced_image_uuid="$IMAGE_UUID"
+            break
+        fi
+    done < <(openstack image list --property status=active | awk -F'|' '!/^(+--)|ID|aki|ari/ { print $3,$2 }')
+
+    if [[ -z "$advanced_image_uuid" ]]; then
+        echo "No image with name $ADVANCED_IMAGE_NAME found."
+        return 1
+    fi
+
+    iniset $TEMPEST_CONFIG neutron_plugin_options advanced_image_ref $advanced_image_uuid
+    iniset $TEMPEST_CONFIG neutron_plugin_options advanced_image_ssh_user $ADVANCED_INSTANCE_USER
+}
+
+
+function configure_flavor_for_advanced_image {
+    local flavor_ref
+
+    if ! is_service_enabled nova; then
+        # if nova is not enabled, there is no flavor to configure
+        return 0
+    fi
+
+    if [[ -z "$ADVANCED_INSTANCE_TYPE" ]]; then
+        # if name of flavor for advanced image is not provided, there is no
+        # flavor to configure
+        return 0
+    fi
+
+    flavor_ref=$(openstack flavor show $ADVANCED_INSTANCE_TYPE -f value -c id)
+    if [[ -z "$flavor_ref" ]]; then
+        echo "Found no valid flavors to use for $ADVANCED_IMAGE_NAME !"
+        echo "Fallback to use $DEFAULT_INSTANCE_TYPE"
+        flavor_ref=$(iniget $TEMPEST_CONFIG compute flavor_ref)
+    fi
+    iniset $TEMPEST_CONFIG neutron_plugin_options advanced_image_flavor_ref $flavor_ref
+}