Files
trove-integration/scripts/functions
Auston McReynolds 34ea41c273 Custom Guest Log Directory Causes Init Failure
The log_dir in trove-guestagent.conf.sample currently defaults to
'/tmp', and the log_file to 'logfile.txt'.

If the log_dir value is changed to, say, '/var/log/trove', guest
initialization will fail because the directory does not exist. Even
if log_dir is set to '/var/log', initialization will fail due to
insufficient write permissions in said directory.

Solution: The log_dir specified in trove-guestagent.conf.sample
should be created on-demand if necessary.

Change-Id: Ic819aaa08f8a78483e1c0ae0aa8af370c6705562
Closes-Bug: #1219137
2013-09-03 17:53:18 -07:00

102 lines
3.5 KiB
Bash

#!/bin/bash
# This file format was stolen from devstack <3
# This method was stolen from devstack
# git clone only if directory doesn't exist already. Since ``DEST`` might not
# be owned by the installation user, we create the directory and change the
# ownership to the proper user.
# Set global RECLONE=yes to simulate a clone when dest-dir exists
# git_clone remote dest-dir branch
function git_clone {
[[ "$OFFLINE" = "True" ]] && return
GIT_REMOTE=$1
GIT_DEST=$2
GIT_BRANCH=$3
if echo $GIT_BRANCH | egrep -q "^refs"; then
# If our branch name is a gerrit style refs/changes/...
if [[ ! -d $GIT_DEST ]]; then
git clone $GIT_REMOTE $GIT_DEST
fi
cd $GIT_DEST
git fetch $GIT_REMOTE $GIT_BRANCH && git checkout FETCH_HEAD
else
# do a full clone only if the directory doesn't exist
if [[ ! -d $GIT_DEST ]]; then
git clone $GIT_REMOTE $GIT_DEST
cd $GIT_DEST
# This checkout syntax works for both branches and tags
git checkout $GIT_BRANCH
elif [[ "$RECLONE" == "yes" ]]; then
# if it does exist then simulate what clone does if asked to RECLONE
cd $GIT_DEST
# set the url to pull from and fetch
git remote set-url origin $GIT_REMOTE
git fetch origin
# remove the existing ignored files (like pyc) as they cause breakage
# (due to the py files having older timestamps than our pyc, so python
# thinks the pyc files are correct using them)
find $GIT_DEST -name '*.pyc' -delete
git checkout -f origin/$GIT_BRANCH
# a local branch might not exist
git branch -D $GIT_BRANCH || true
git checkout -b $GIT_BRANCH
fi
fi
}
# Authenticates and gets a token. Requires a username, password, and tenant name.
# This function assumes localhost keystone at the default port a la devstack.
function retrieve_token {
USERNAME=$1
PASSWORD=$2
TENANT_NAME=$3
curl -d "{\"auth\":{\"passwordCredentials\":{\"username\": \"$USERNAME\", \"password\": \"$PASSWORD\"},\"tenantName\":\"$TENANT_NAME\"}}" \
-H "Content-type: application/json" http://localhost:35357/v2.0/tokens | python -c 'import json, sys; print json.loads("\n".join(sys.stdin))["access"]["token"]["tenant"]["id"]'
}
# Determinate is the given option present in the INI file
# ini_has_option config-file section option
function ini_has_option() {
local file=$1
local section=$2
local option=$3
local line
line=$(sed -ne "/^\[$section\]/,/^\[.*\]/ { /^$option[ \t]*=/ p; }" "$file")
[ -n "$line" ]
}
# Get an option from an INI file
# iniget config-file section option
function iniget() {
local file=$1
local section=$2
local option=$3
local line
line=$(sed -ne "/^\[$section\]/,/^\[.*\]/ { /^$option[ \t]*=/ p; }" "$file")
echo ${line#*=}
}
# Set an option in an INI file
# iniset config-file section option value
function iniset() {
local file=$1
local section=$2
local option=$3
local value=$4
if ! grep -q "^\[$section\]" "$file"; then
# Add section at the end
echo -e "\n[$section]" >>"$file"
fi
if ! ini_has_option "$file" "$section" "$option"; then
# Add it
sed -i -e "/^\[$section\]/ a\\
$option = $value
" "$file"
else
# Replace it
sed -i -e "/^\[$section\]/,/^\[.*\]/ s|^\($option[ \t]*=[ \t]*\).*$|\1$value|" "$file"
fi
}