Skip to content

Commit 5375329

Browse files
committed
Make changes such that -o nounset runs
This makes a bunch of variable cleanups that will let -o nounset function, for the time being we hide nounset behind another setting variable so that it's not on by default. Because this is bash, and things are only executed on demand, this probably only works in the config it was run in. Expect cleaning up all the paths to be something that takes quite a while. This also includes a new set of unit tests around the trueorfalse function, because my change in how it worked, didn't. Tests are good m'kay. Change-Id: I71a896623ea9e1f042a73dc0678ce85acf0dc87d
1 parent 5f6f43e commit 5375329

26 files changed

Lines changed: 265 additions & 121 deletions

clean.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ source $TOP_DIR/functions
1818
FILES=$TOP_DIR/files
1919

2020
# Load local configuration
21-
source $TOP_DIR/stackrc
21+
source $TOP_DIR/openrc
2222

2323
# Get the variables that are set in stack.sh
2424
if [[ -r $TOP_DIR/.stackenv ]]; then

extras.d/70-tuskar.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ TUSKARCLIENT_BRANCH=${TUSKARCLIENT_BRANCH:-master}
6565
TUSKAR_DIR=$DEST/tuskar
6666
TUSKARCLIENT_DIR=$DEST/python-tuskarclient
6767
TUSKAR_AUTH_CACHE_DIR=${TUSKAR_AUTH_CACHE_DIR:-/var/cache/tuskar}
68-
TUSKAR_STANDALONE=`trueorfalse False $TUSKAR_STANDALONE`
68+
TUSKAR_STANDALONE=$(trueorfalse False TUSKAR_STANDALONE)
6969
TUSKAR_CONF_DIR=/etc/tuskar
7070
TUSKAR_CONF=$TUSKAR_CONF_DIR/tuskar.conf
7171
TUSKAR_API_HOST=${TUSKAR_API_HOST:-$HOST_IP}

functions

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -353,7 +353,7 @@ function _ping_check_novanet {
353353
local boot_timeout=$3
354354
local expected=${4:-"True"}
355355
local check_command=""
356-
MULTI_HOST=`trueorfalse False $MULTI_HOST`
356+
MULTI_HOST=$(trueorfalse False MULTI_HOST)
357357
if [[ "$MULTI_HOST" = "True" && "$from_net" = "$PRIVATE_NETWORK_NAME" ]]; then
358358
return
359359
fi

functions-common

Lines changed: 45 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@
2121
#
2222
# The following variables are assumed to be defined by certain functions:
2323
#
24-
# - ``GIT_DEPTH``
2524
# - ``ENABLED_SERVICES``
2625
# - ``ERROR_ON_CLONE``
2726
# - ``FILES``
@@ -43,6 +42,8 @@ declare -A GITREPO
4342
declare -A GITBRANCH
4443
declare -A GITDIR
4544

45+
TRACK_DEPENDS=${TRACK_DEPENDS:-False}
46+
4647
# Config Functions
4748
# ================
4849

@@ -243,7 +244,8 @@ function trueorfalse {
243244
local xtrace=$(set +o | grep xtrace)
244245
set +o xtrace
245246
local default=$1
246-
local testval=$2
247+
local literal=$2
248+
local testval=${!literal}
247249

248250
[[ -z "$testval" ]] && { echo "$default"; return; }
249251
[[ "0 no No NO false False FALSE" =~ "$testval" ]] && { echo "False"; return; }
@@ -252,6 +254,14 @@ function trueorfalse {
252254
$xtrace
253255
}
254256

257+
function isset {
258+
nounset=$(set +o | grep nounset)
259+
set +o nounset
260+
[[ -n "${!1+x}" ]]
261+
result=$?
262+
$nounset
263+
return $result
264+
}
255265

256266
# Control Functions
257267
# =================
@@ -381,7 +391,11 @@ function warn {
381391
# ``os_UPDATE`` - update: ex. the ``5`` in ``RHEL6.5``
382392
# ``os_PACKAGE`` - package type: ``deb`` or ``rpm``
383393
# ``os_CODENAME`` - vendor's codename for release: ``snow leopard``, ``trusty``
384-
declare os_VENDOR os_RELEASE os_UPDATE os_PACKAGE os_CODENAME
394+
os_VENDOR=""
395+
os_RELEASE=""
396+
os_UPDATE=""
397+
os_PACKAGE=""
398+
os_CODENAME=""
385399

386400
# GetOSVersion
387401
function GetOSVersion {
@@ -577,8 +591,7 @@ function get_release_name_from_branch {
577591
# Set global ``RECLONE=yes`` to simulate a clone when dest-dir exists
578592
# Set global ``ERROR_ON_CLONE=True`` to abort execution with an error if the git repo
579593
# does not exist (default is False, meaning the repo will be cloned).
580-
# Set global ``GIT_DEPTH=<number>`` to limit the history depth of the git clone
581-
# Uses globals ``ERROR_ON_CLONE``, ``OFFLINE``, ``RECLONE``, ``GIT_DEPTH``
594+
# Uses globals ``ERROR_ON_CLONE``, ``OFFLINE``, ``RECLONE``
582595
# git_clone remote dest-dir branch
583596
function git_clone {
584597
local git_remote=$1
@@ -587,8 +600,7 @@ function git_clone {
587600
local orig_dir=$(pwd)
588601
local git_clone_flags=""
589602

590-
RECLONE=$(trueorfalse False $RECLONE)
591-
603+
RECLONE=$(trueorfalse False RECLONE)
592604
if [[ -n "${GIT_DEPTH}" ]]; then
593605
git_clone_flags="$git_clone_flags --depth $GIT_DEPTH"
594606
fi
@@ -978,9 +990,10 @@ function apt_get {
978990
[[ "$(id -u)" = "0" ]] && sudo="env"
979991

980992
$xtrace
993+
981994
$sudo DEBIAN_FRONTEND=noninteractive \
982-
http_proxy=$http_proxy https_proxy=$https_proxy \
983-
no_proxy=$no_proxy \
995+
http_proxy=${http_proxy:-} https_proxy=${https_proxy:-} \
996+
no_proxy=${no_proxy:-} \
984997
apt-get --option "Dpkg::Options::=--force-confold" --assume-yes "$@"
985998
}
986999

@@ -999,10 +1012,10 @@ function get_packages {
9991012
set +o xtrace
10001013
local services=$@
10011014
local package_dir=$(_get_package_dir)
1002-
local file_to_parse
1003-
local service
1015+
local file_to_parse=""
1016+
local service=""
10041017

1005-
INSTALL_TESTONLY_PACKAGES=$(trueorfalse False $INSTALL_TESTONLY_PACKAGES)
1018+
INSTALL_TESTONLY_PACKAGES=$(trueorfalse False INSTALL_TESTONLY_PACKAGES)
10061019

10071020
if [[ -z "$package_dir" ]]; then
10081021
echo "No package directory supplied"
@@ -1112,6 +1125,10 @@ function get_packages {
11121125
# Uses globals ``NO_UPDATE_REPOS``, ``REPOS_UPDATED``, ``RETRY_UPDATE``
11131126
# install_package package [package ...]
11141127
function update_package_repo {
1128+
NO_UPDATE_REPOS=${NO_UPDATE_REPOS:-False}
1129+
REPOS_UPDATED=${REPOS_UPDATED:-False}
1130+
RETRY_UPDATE=${RETRY_UPDATE:-False}
1131+
11151132
if [[ "$NO_UPDATE_REPOS" = "True" ]]; then
11161133
return 0
11171134
fi
@@ -1321,7 +1338,7 @@ function screen_process {
13211338

13221339
SCREEN_NAME=${SCREEN_NAME:-stack}
13231340
SERVICE_DIR=${SERVICE_DIR:-${DEST}/status}
1324-
USE_SCREEN=$(trueorfalse True $USE_SCREEN)
1341+
USE_SCREEN=$(trueorfalse True USE_SCREEN)
13251342

13261343
# Append the process to the screen rc file
13271344
screen_rc "$name" "$command"
@@ -1394,7 +1411,7 @@ function screen_stop_service {
13941411

13951412
SCREEN_NAME=${SCREEN_NAME:-stack}
13961413
SERVICE_DIR=${SERVICE_DIR:-${DEST}/status}
1397-
USE_SCREEN=$(trueorfalse True $USE_SCREEN)
1414+
USE_SCREEN=$(trueorfalse True USE_SCREEN)
13981415

13991416
if is_service_enabled $service; then
14001417
# Clean up the screen window
@@ -1412,7 +1429,7 @@ function stop_process {
14121429
local service=$1
14131430

14141431
SERVICE_DIR=${SERVICE_DIR:-${DEST}/status}
1415-
USE_SCREEN=$(trueorfalse True $USE_SCREEN)
1432+
USE_SCREEN=$(trueorfalse True USE_SCREEN)
14161433

14171434
if is_service_enabled $service; then
14181435
# Kill via pid if we have one available
@@ -1462,7 +1479,7 @@ function tail_log {
14621479
local name=$1
14631480
local logfile=$2
14641481

1465-
USE_SCREEN=$(trueorfalse True $USE_SCREEN)
1482+
USE_SCREEN=$(trueorfalse True USE_SCREEN)
14661483
if [[ "$USE_SCREEN" = "True" ]]; then
14671484
screen_process "$name" "sudo tail -f $logfile"
14681485
fi
@@ -1572,7 +1589,8 @@ function get_python_exec_prefix {
15721589
function pip_install {
15731590
local xtrace=$(set +o | grep xtrace)
15741591
set +o xtrace
1575-
if [[ "$OFFLINE" = "True" || -z "$@" ]]; then
1592+
local offline=${OFFLINE:-False}
1593+
if [[ "$offline" == "True" || -z "$@" ]]; then
15761594
$xtrace
15771595
return
15781596
fi
@@ -1601,20 +1619,20 @@ function pip_install {
16011619

16021620
$xtrace
16031621
$sudo_pip \
1604-
http_proxy=$http_proxy \
1605-
https_proxy=$https_proxy \
1606-
no_proxy=$no_proxy \
1622+
http_proxy=${http_proxy:-} \
1623+
https_proxy=${https_proxy:-} \
1624+
no_proxy=${no_proxy:-} \
16071625
$cmd_pip install \
16081626
$@
16091627

1610-
INSTALL_TESTONLY_PACKAGES=$(trueorfalse False $INSTALL_TESTONLY_PACKAGES)
1628+
INSTALL_TESTONLY_PACKAGES=$(trueorfalse False INSTALL_TESTONLY_PACKAGES)
16111629
if [[ "$INSTALL_TESTONLY_PACKAGES" == "True" ]]; then
16121630
local test_req="$@/test-requirements.txt"
16131631
if [[ -e "$test_req" ]]; then
16141632
$sudo_pip \
1615-
http_proxy=$http_proxy \
1616-
https_proxy=$https_proxy \
1617-
no_proxy=$no_proxy \
1633+
http_proxy=${http_proxy:-} \
1634+
https_proxy=${https_proxy:-} \
1635+
no_proxy=${no_proxy:-} \
16181636
$cmd_pip install \
16191637
-r $test_req
16201638
fi
@@ -2084,13 +2102,13 @@ function cp_it {
20842102
# http_proxy=http://proxy.example.com:3128/ no_proxy=repo.example.net ./stack.sh
20852103

20862104
function export_proxy_variables {
2087-
if [[ -n "$http_proxy" ]]; then
2105+
if isset http_proxy ; then
20882106
export http_proxy=$http_proxy
20892107
fi
2090-
if [[ -n "$https_proxy" ]]; then
2108+
if isset https_proxy ; then
20912109
export https_proxy=$https_proxy
20922110
fi
2093-
if [[ -n "$no_proxy" ]]; then
2111+
if isset no_proxy ; then
20942112
export no_proxy=$no_proxy
20952113
fi
20962114
}

lib/ceilometer

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,11 +75,14 @@ CEILOMETER_BACKEND=${CEILOMETER_BACKEND:-mysql}
7575
CEILOMETER_SERVICE_PROTOCOL=http
7676
CEILOMETER_SERVICE_HOST=$SERVICE_HOST
7777
CEILOMETER_SERVICE_PORT=${CEILOMETER_SERVICE_PORT:-8777}
78-
CEILOMETER_USE_MOD_WSGI=$(trueorfalse False $CEILOMETER_USE_MOD_WSGI)
78+
CEILOMETER_USE_MOD_WSGI=$(trueorfalse False CEILOMETER_USE_MOD_WSGI)
7979

8080
# To enable OSprofiler change value of this variable to "notifications,profiler"
8181
CEILOMETER_NOTIFICATION_TOPICS=${CEILOMETER_NOTIFICATION_TOPICS:-notifications}
8282

83+
CEILOMETER_COORDINATION_URL=${CEILOMETER_COORDINATION_URL:-}
84+
CEILOMETER_PIPELINE_INTERVAL=${CEILOMETER_PIPELINE_INTERVAL:-}
85+
8386
# Tell Tempest this project is present
8487
TEMPEST_SERVICES+=,ceilometer
8588

lib/cinder

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ fi
6868
# Maintain this here for backward-compatibility with the old configuration
6969
# DEPRECATED: Use CINDER_ENABLED_BACKENDS instead
7070
# Support for multi lvm backend configuration (default is no support)
71-
CINDER_MULTI_LVM_BACKEND=$(trueorfalse False $CINDER_MULTI_LVM_BACKEND)
71+
CINDER_MULTI_LVM_BACKEND=$(trueorfalse False CINDER_MULTI_LVM_BACKEND)
7272

7373
# Default backends
7474
# The backend format is type:name where type is one of the supported backend
@@ -85,7 +85,7 @@ fi
8585
# Should cinder perform secure deletion of volumes?
8686
# Defaults to true, can be set to False to avoid this bug when testing:
8787
# https://bugs.launchpad.net/ubuntu/+source/linux/+bug/1023755
88-
CINDER_SECURE_DELETE=`trueorfalse True $CINDER_SECURE_DELETE`
88+
CINDER_SECURE_DELETE=$(trueorfalse True CINDER_SECURE_DELETE)
8989

9090
# Cinder reports allocations back to the scheduler on periodic intervals
9191
# it turns out we can get an "out of space" issue when we run tests too

lib/cinder_backends/lvm

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ set +o xtrace
3333
# If ``VOLUME_GROUP`` is set, use it, otherwise we'll build a VG name based
3434
# on ``VOLUME_GROUP_NAME`` that includes the backend name
3535
# Grenade doesn't use ``VOLUME_GROUP2`` so it is left out
36+
VOLUME_GROUP=${VOLUME_GROUP:-}
3637
VOLUME_GROUP_NAME=${VOLUME_GROUP:-${VOLUME_GROUP_NAME:-stack-volumes}}
3738

3839
# TODO: resurrect backing device...need to know how to set values

lib/database

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,14 +23,15 @@
2323
XTRACE=$(set +o | grep xtrace)
2424
set +o xtrace
2525

26+
DATABASE_BACKENDS=""
2627

2728
# Register a database backend
2829
#
2930
# $1 The name of the database backend
3031
#
3132
# This is required to be defined before the specific database scripts are sourced
3233
function register_database {
33-
[ -z "$DATABASE_BACKENDS" ] && DATABASE_BACKENDS=$1 || DATABASE_BACKENDS+=" $1"
34+
DATABASE_BACKENDS+=" $1"
3435
}
3536

3637
# Sourcing the database libs sets DATABASE_BACKENDS with the available list

lib/databases/mysql

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,22 @@ set +o xtrace
1414

1515
register_database mysql
1616

17+
# Linux distros, thank you for being incredibly consistent
18+
MYSQL=mysql
19+
if is_fedora; then
20+
if [[ $DISTRO =~ (rhel6) ]]; then
21+
MYSQL=mysqld
22+
else
23+
MYSQL=mariadb
24+
fi
25+
fi
1726

1827
# Functions
1928
# ---------
2029

2130
# Get rid of everything enough to cleanly change database backends
2231
function cleanup_database_mysql {
32+
stop_service $MYSQL
2333
if is_ubuntu; then
2434
# Get ruthless with mysql
2535
stop_service $MYSQL

lib/dib

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ TIE_DIR=$DEST/tripleo-image-elements
2626
# NOTE: Setting DIB_APT_SOURCES assumes you will be building
2727
# Debian/Ubuntu based images. Leave unset for other flavors.
2828
DIB_APT_SOURCES=${DIB_APT_SOURCES:-""}
29-
DIB_BUILD_OFFLINE=$(trueorfalse False $DIB_BUILD_OFFLINE)
29+
DIB_BUILD_OFFLINE=$(trueorfalse False DIB_BUILD_OFFLINE)
3030
DIB_IMAGE_CACHE=$DATA_DIR/diskimage-builder/image-create
3131
DIB_PIP_REPO=$DATA_DIR/diskimage-builder/pip-repo
3232
DIB_PIP_REPO_PORT=${DIB_PIP_REPO_PORT:-8899}

0 commit comments

Comments
 (0)