Skip to content

Commit 23d33a8

Browse files
committed
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
1 parent 0c6208c commit 23d33a8

1 file changed

Lines changed: 15 additions & 2 deletions

File tree

lib/tempest

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,14 @@ function remove_disabled_extensions {
102102
remove_disabled_services "$extensions_list" "$disabled_exts"
103103
}
104104

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+
105113
# configure_tempest() - Set config files, create data dirs, etc
106114
function configure_tempest {
107115
if [[ "$INSTALL_TEMPEST" == "True" ]]; then
@@ -125,6 +133,7 @@ function configure_tempest {
125133
local public_network_id
126134
local public_router_id
127135
local ssh_connect_method="floating"
136+
local disk
128137

129138
# Save IFS
130139
ifs=$IFS
@@ -190,11 +199,15 @@ function configure_tempest {
190199
available_flavors=$(nova flavor-list)
191200
if [[ -z "$DEFAULT_INSTANCE_TYPE" ]]; then
192201
if [[ ! ( $available_flavors =~ 'm1.nano' ) ]]; then
193-
openstack flavor create --id 42 --ram 64 --disk 0 --vcpus 1 m1.nano
202+
# Determine the flavor disk size based on the image size.
203+
disk=$(image_size_in_gib $image_uuid)
204+
openstack flavor create --id 42 --ram 64 --disk $disk --vcpus 1 m1.nano
194205
fi
195206
flavor_ref=42
196207
if [[ ! ( $available_flavors =~ 'm1.micro' ) ]]; then
197-
openstack flavor create --id 84 --ram 128 --disk 0 --vcpus 1 m1.micro
208+
# Determine the alt flavor disk size based on the alt image size.
209+
disk=$(image_size_in_gib $image_uuid_alt)
210+
openstack flavor create --id 84 --ram 128 --disk $disk --vcpus 1 m1.micro
198211
fi
199212
flavor_ref_alt=84
200213
else

0 commit comments

Comments
 (0)