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