Browse code

Set non-0 disk sizes for tempest flavors

Nova change https://review.openstack.org/603910/ is
going to change the default rule on policy
os_compute_api:servers:create:zero_disk_flavor to
admin-only, which will prevent non-admins from
creating image-backed servers with a flavor that
has disk=0 since it's a potential security exposure.

Therefore we need the test flavors that are created
for tempest to use non-0 disk values. Since the flavor_ref
and flavor_ref_alt can be aligned to the image_ref and
image_ref_alt in tempest.conf, we get the image sizes
from glance (in bytes) and convert those to GiB disk
sizes for each flavor, respectively. Since we're using
Cirros images by default, we need to make sure to round
up otherwise we'd still have a 0-disk flavor.

There are lots of ways the math could be done here
using numfmt, bash, awk, bc, etc, but it's simplest to
write and probably easiest to read by using python for
the size conversion code.

Change-Id: I537c299b0cd400982189f35b31df74755422737e
Related-Bug: #1739646

Matt Riedemann authored on 2018/11/22 02:10:32
Showing 1 changed files
... ...
@@ -102,6 +102,14 @@ function remove_disabled_extensions {
102 102
     remove_disabled_services "$extensions_list" "$disabled_exts"
103 103
 }
104 104
 
105
+# image_size_in_gib - converts an image size from bytes to GiB, rounded up
106
+# Takes an image ID parameter as input
107
+function image_size_in_gib {
108
+    local size
109
+    size=$(openstack image show $1 -c size -f value)
110
+    echo $size | python -c "import math; print int(math.ceil(float(int(raw_input()) / 1024.0 ** 3)))"
111
+}
112
+
105 113
 # configure_tempest() - Set config files, create data dirs, etc
106 114
 function configure_tempest {
107 115
     if [[ "$INSTALL_TEMPEST" == "True" ]]; then
... ...
@@ -125,6 +133,7 @@ function configure_tempest {
125 125
     local public_network_id
126 126
     local public_router_id
127 127
     local ssh_connect_method="floating"
128
+    local disk
128 129
 
129 130
     # Save IFS
130 131
     ifs=$IFS
... ...
@@ -190,11 +199,15 @@ function configure_tempest {
190 190
         available_flavors=$(nova flavor-list)
191 191
         if  [[ -z "$DEFAULT_INSTANCE_TYPE" ]]; then
192 192
             if [[ ! ( $available_flavors =~ 'm1.nano' ) ]]; then
193
-                openstack flavor create --id 42 --ram 64 --disk 0 --vcpus 1 m1.nano
193
+                # Determine the flavor disk size based on the image size.
194
+                disk=$(image_size_in_gib $image_uuid)
195
+                openstack flavor create --id 42 --ram 64 --disk $disk --vcpus 1 m1.nano
194 196
             fi
195 197
             flavor_ref=42
196 198
             if [[ ! ( $available_flavors =~ 'm1.micro' ) ]]; then
197
-                openstack flavor create --id 84 --ram 128 --disk 0 --vcpus 1 m1.micro
199
+                # Determine the alt flavor disk size based on the alt image size.
200
+                disk=$(image_size_in_gib $image_uuid_alt)
201
+                openstack flavor create --id 84 --ram 128 --disk $disk --vcpus 1 m1.micro
198 202
             fi
199 203
             flavor_ref_alt=84
200 204
         else