Browse code

Support extras in Glance Store install

Recent change to devstack dropped installing test-requirements [1]
However, this caused gate failures due to lack of glance-store
deps for cinder and swift support.

This patch makes devstack install relevant extras depending on
enabled features.

Additionally, relevant functions are added/fixed to make this
possible.

glance-store = glance_store (for gerrit search match)

[1] https://review.opendev.org/715469

Change-Id: I0bf5792a6058b52936115b515ea8360f6264a7c9

Radosław Piliszek authored on 2020/03/30 16:56:53
Showing 2 changed files
... ...
@@ -21,6 +21,14 @@ set +o xtrace
21 21
 # project.  A null value installs to the system Python directories.
22 22
 declare -A -g PROJECT_VENV
23 23
 
24
+# Utility Functions
25
+# =================
26
+
27
+# Joins bash array of extras with commas as expected by other functions
28
+function join_extras {
29
+    local IFS=","
30
+    echo "$*"
31
+}
24 32
 
25 33
 # Python Functions
26 34
 # ================
... ...
@@ -80,9 +88,9 @@ function pip_install_gr {
80 80
 function pip_install_gr_extras {
81 81
     local name=$1
82 82
     local extras=$2
83
-    local clean_name
84
-    clean_name=$(get_from_global_requirements $name)
85
-    pip_install $clean_name[$extras]
83
+    local version_constraints
84
+    version_constraints=$(get_version_constraints_from_global_requirements $name)
85
+    pip_install $name[$extras]$version_constraints
86 86
 }
87 87
 
88 88
 # enable_python3_package() -- no-op for backwards compatibility
... ...
@@ -230,6 +238,19 @@ function get_from_global_requirements {
230 230
     echo $required_pkg
231 231
 }
232 232
 
233
+# get only version constraints of a package from global requirements file
234
+# get_version_constraints_from_global_requirements <package>
235
+function get_version_constraints_from_global_requirements {
236
+    local package=$1
237
+    local required_pkg_version_constraint
238
+    # drop the package name from output (\K)
239
+    required_pkg_version_constraint=$(grep -i -h -o -P "^${package}\K.*" $REQUIREMENTS_DIR/global-requirements.txt | cut -d\# -f1)
240
+    if [[ $required_pkg_version_constraint == ""  ]]; then
241
+        die $LINENO "Can't find package $package in requirements"
242
+    fi
243
+    echo $required_pkg_version_constraint
244
+}
245
+
233 246
 # should we use this library from their git repo, or should we let it
234 247
 # get pulled in via pip dependencies.
235 248
 function use_library_from_git {
... ...
@@ -278,7 +299,7 @@ function setup_lib {
278 278
 #
279 279
 # use this for non namespaced libraries
280 280
 #
281
-# setup_dev_lib [-bindep] <name>
281
+# setup_dev_lib [-bindep] <name> [<extras>]
282 282
 function setup_dev_lib {
283 283
     local bindep
284 284
     if [[ $1 == -bindep* ]]; then
... ...
@@ -287,7 +308,8 @@ function setup_dev_lib {
287 287
     fi
288 288
     local name=$1
289 289
     local dir=${GITDIR[$name]}
290
-    setup_develop $bindep $dir
290
+    local extras=$2
291
+    setup_develop $bindep $dir $extras
291 292
 }
292 293
 
293 294
 # this should be used if you want to install globally, all libraries should
... ...
@@ -355,11 +355,24 @@ function install_glanceclient {
355 355
 
356 356
 # install_glance() - Collect source and prepare
357 357
 function install_glance {
358
+    local glance_store_extras=()
359
+
360
+    if is_service_enabled cinder; then
361
+        glance_store_extras=("cinder" "${glance_store_extras[@]}")
362
+    fi
363
+
364
+    if is_service_enabled swift; then
365
+        glance_store_extras=("swift" "${glance_store_extras[@]}")
366
+    fi
367
+
358 368
     # Install glance_store from git so we make sure we're testing
359 369
     # the latest code.
360 370
     if use_library_from_git "glance_store"; then
361 371
         git_clone_by_name "glance_store"
362
-        setup_dev_lib "glance_store"
372
+        setup_dev_lib "glance_store" $(join_extras "${glance_store_extras[@]}")
373
+    else
374
+        # we still need to pass extras
375
+        pip_install_gr_extras glance-store $(join_extras "${glance_store_extras[@]}")
363 376
     fi
364 377
 
365 378
     git_clone $GLANCE_REPO $GLANCE_DIR $GLANCE_BRANCH