Tempest plugin for the Neutron project.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

88 lines
2.7KB

  1. # Generic use functions
  2. # ensure we don't re-source this in the same environment
  3. [[ -z "$_NEUTRON_TEMPEST_PLUGIN_FUNCTIONS" ]] || return 0
  4. declare -r -g _NEUTRON_TEMPEST_PLUGIN_FUNCTIONS=1
  5. # Create a function copying the code from an existing one
  6. function save_function {
  7. local old_name=$1
  8. local new_name=$2
  9. # Saving the same function again after redefining it could produce a
  10. # recorsive function in case for example this plugin is sourced twice
  11. if type -t "${new_name}"; then
  12. # Prevent copying the same function twice
  13. return 0
  14. fi
  15. # Save xtrace setting
  16. _XTRACE_FUNCTIONS=$(set +o | grep xtrace)
  17. set +o xtrace
  18. # Get code of the original function
  19. local old_code=$(declare -f ${old_name})
  20. # Produce code for the new function
  21. local new_code="${new_name}${old_code#${old_name}}"
  22. # Define the new function
  23. eval "${new_code}"
  24. # Restore xtrace
  25. $_XTRACE_FUNCTIONS
  26. }
  27. #Add advanced image config to tempest.conf
  28. function configure_advanced_image {
  29. local advanced_image_uuid
  30. if ! is_service_enabled glance; then
  31. # if glance is not enabled, there is no image for to configure
  32. return 0
  33. fi
  34. if [[ -z "$ADVANCED_IMAGE_NAME" ]]; then
  35. # if name of advanced image is not provided, there is no image to
  36. # configure
  37. return 0
  38. fi
  39. while read -r IMAGE_NAME IMAGE_UUID; do
  40. if [ "$IMAGE_NAME" = "$ADVANCED_IMAGE_NAME" ]; then
  41. advanced_image_uuid="$IMAGE_UUID"
  42. break
  43. fi
  44. done < <(openstack image list --property status=active | awk -F'|' '!/^(+--)|ID|aki|ari/ { print $3,$2 }')
  45. if [[ -z "$advanced_image_uuid" ]]; then
  46. echo "No image with name $ADVANCED_IMAGE_NAME found."
  47. return 1
  48. fi
  49. iniset $TEMPEST_CONFIG neutron_plugin_options advanced_image_ref $advanced_image_uuid
  50. iniset $TEMPEST_CONFIG neutron_plugin_options advanced_image_ssh_user $ADVANCED_INSTANCE_USER
  51. }
  52. function configure_flavor_for_advanced_image {
  53. local flavor_ref
  54. if ! is_service_enabled nova; then
  55. # if nova is not enabled, there is no flavor to configure
  56. return 0
  57. fi
  58. if [[ -z "$ADVANCED_INSTANCE_TYPE" ]]; then
  59. # if name of flavor for advanced image is not provided, there is no
  60. # flavor to configure
  61. return 0
  62. fi
  63. flavor_ref=$(openstack flavor show $ADVANCED_INSTANCE_TYPE -f value -c id)
  64. if [[ -z "$flavor_ref" ]]; then
  65. echo "Found no valid flavors to use for $ADVANCED_IMAGE_NAME !"
  66. echo "Fallback to use $DEFAULT_INSTANCE_TYPE"
  67. flavor_ref=$(iniget $TEMPEST_CONFIG compute flavor_ref)
  68. fi
  69. iniset $TEMPEST_CONFIG neutron_plugin_options advanced_image_flavor_ref $flavor_ref
  70. }