Merge "Create stack_domain_admin user"
diff --git a/clean.sh b/clean.sh
index b2a9405..e121e4f 100755
--- a/clean.sh
+++ b/clean.sh
@@ -119,4 +119,10 @@
fi
# Clean up files
-rm -f $TOP_DIR/.stackenv
+
+FILES_TO_CLEAN=".localrc.auto docs-files docs/ shocco/ stack-screenrc test*.conf* test.ini*"
+FILES_TO_CLEAN+=".stackenv .prereqs"
+
+for file in FILES_TO_CLEAN; do
+ rm -f $TOP_DIR/$file
+done
diff --git a/extras.d/70-savanna.sh b/extras.d/70-savanna.sh
index 6bbe113..edc1376 100644
--- a/extras.d/70-savanna.sh
+++ b/extras.d/70-savanna.sh
@@ -8,6 +8,7 @@
elif [[ "$1" == "stack" && "$2" == "install" ]]; then
echo_summary "Installing Savanna"
install_savanna
+ cleanup_savanna
if is_service_enabled horizon; then
install_savanna_dashboard
fi
@@ -29,4 +30,8 @@
cleanup_savanna_dashboard
fi
fi
+
+ if [[ "$1" == "clean" ]]; then
+ cleanup_savanna
+ fi
fi
diff --git a/files/apts/glance b/files/apts/glance
index 22787bc..6dc878e 100644
--- a/files/apts/glance
+++ b/files/apts/glance
@@ -1,5 +1,5 @@
gcc
-libffi-dev # testonly
+libffi-dev
libmysqlclient-dev # testonly
libpq-dev # testonly
libssl-dev # testonly
diff --git a/files/apts/sysstat b/files/apts/sysstat
deleted file mode 100644
index ea0c342..0000000
--- a/files/apts/sysstat
+++ /dev/null
@@ -1 +0,0 @@
-sysstat
diff --git a/files/rpms-suse/sysstat b/files/rpms-suse/sysstat
deleted file mode 100644
index ea0c342..0000000
--- a/files/rpms-suse/sysstat
+++ /dev/null
@@ -1 +0,0 @@
-sysstat
diff --git a/files/rpms/glance b/files/rpms/glance
index 785ce25..25c5d39 100644
--- a/files/rpms/glance
+++ b/files/rpms/glance
@@ -1,5 +1,5 @@
gcc
-libffi-devel # testonly
+libffi-devel
libxml2-devel # testonly
libxslt-devel # testonly
mysql-devel # testonly
diff --git a/files/rpms/sysstat b/files/rpms/sysstat
deleted file mode 100644
index ea0c342..0000000
--- a/files/rpms/sysstat
+++ /dev/null
@@ -1 +0,0 @@
-sysstat
diff --git a/functions-common b/functions-common
index d92e39c..79003fc 100644
--- a/functions-common
+++ b/functions-common
@@ -39,59 +39,76 @@
# Append a new option in an ini file without replacing the old value
# iniadd config-file section option value1 value2 value3 ...
function iniadd() {
+ local xtrace=$(set +o | grep xtrace)
+ set +o xtrace
local file=$1
local section=$2
local option=$3
shift 3
local values="$(iniget_multiline $file $section $option) $@"
iniset_multiline $file $section $option $values
+ $xtrace
}
# Comment an option in an INI file
# inicomment config-file section option
function inicomment() {
+ local xtrace=$(set +o | grep xtrace)
+ set +o xtrace
local file=$1
local section=$2
local option=$3
sed -i -e "/^\[$section\]/,/^\[.*\]/ s|^\($option[ \t]*=.*$\)|#\1|" "$file"
+ $xtrace
}
# Get an option from an INI file
# iniget config-file section option
function iniget() {
+ local xtrace=$(set +o | grep xtrace)
+ set +o xtrace
local file=$1
local section=$2
local option=$3
local line
line=$(sed -ne "/^\[$section\]/,/^\[.*\]/ { /^$option[ \t]*=/ p; }" "$file")
echo ${line#*=}
+ $xtrace
}
# Get a multiple line option from an INI file
# iniget_multiline config-file section option
function iniget_multiline() {
+ local xtrace=$(set +o | grep xtrace)
+ set +o xtrace
local file=$1
local section=$2
local option=$3
local values
values=$(sed -ne "/^\[$section\]/,/^\[.*\]/ { s/^$option[ \t]*=[ \t]*//gp; }" "$file")
echo ${values}
+ $xtrace
}
# Determinate is the given option present in the INI file
# ini_has_option config-file section option
function ini_has_option() {
+ local xtrace=$(set +o | grep xtrace)
+ set +o xtrace
local file=$1
local section=$2
local option=$3
local line
line=$(sed -ne "/^\[$section\]/,/^\[.*\]/ { /^$option[ \t]*=/ p; }" "$file")
+ $xtrace
[ -n "$line" ]
}
# Set an option in an INI file
# iniset config-file section option value
function iniset() {
+ local xtrace=$(set +o | grep xtrace)
+ set +o xtrace
local file=$1
local section=$2
local option=$3
@@ -113,11 +130,14 @@
# Replace it
sed -i -e '/^\['${section}'\]/,/^\[.*\]/ s'${sep}'^\('${option}'[ \t]*=[ \t]*\).*$'${sep}'\1'"${value}"${sep} "$file"
fi
+ $xtrace
}
# Set a multiple line option in an INI file
# iniset_multiline config-file section option value1 value2 valu3 ...
function iniset_multiline() {
+ local xtrace=$(set +o | grep xtrace)
+ set +o xtrace
local file=$1
local section=$2
local option=$3
@@ -142,15 +162,19 @@
$option = $v
" "$file"
done
+ $xtrace
}
# Uncomment an option in an INI file
# iniuncomment config-file section option
function iniuncomment() {
+ local xtrace=$(set +o | grep xtrace)
+ set +o xtrace
local file=$1
local section=$2
local option=$3
sed -i -e "/^\[$section\]/,/^\[.*\]/ s|[^ \t]*#[ \t]*\($option[ \t]*=.*$\)|\1|" "$file"
+ $xtrace
}
# Normalize config values to True or False
@@ -158,6 +182,8 @@
# Accepts as True: 1 yes Yes YES true True TRUE
# VAR=$(trueorfalse default-value test-value)
function trueorfalse() {
+ local xtrace=$(set +o | grep xtrace)
+ set +o xtrace
local default=$1
local testval=$2
@@ -165,6 +191,7 @@
[[ "0 no No NO false False FALSE" =~ "$testval" ]] && { echo "False"; return; }
[[ "1 yes Yes YES true True TRUE" =~ "$testval" ]] && { echo "True"; return; }
echo "$default"
+ $xtrace
}
@@ -675,9 +702,14 @@
# Uses globals ``OFFLINE``, ``*_proxy``
# apt_get operation package [package ...]
function apt_get() {
+ local xtrace=$(set +o | grep xtrace)
+ set +o xtrace
+
[[ "$OFFLINE" = "True" || -z "$@" ]] && return
local sudo="sudo"
[[ "$(id -u)" = "0" ]] && sudo="env"
+
+ $xtrace
$sudo DEBIAN_FRONTEND=noninteractive \
http_proxy=$http_proxy https_proxy=$https_proxy \
no_proxy=$no_proxy \
@@ -695,6 +727,8 @@
# - ``# dist:DISTRO`` or ``dist:DISTRO1,DISTRO2`` limits the selection
# of the package to the distros listed. The distro names are case insensitive.
function get_packages() {
+ local xtrace=$(set +o | grep xtrace)
+ set +o xtrace
local services=$@
local package_dir=$(_get_package_dir)
local file_to_parse
@@ -706,6 +740,7 @@
fi
if [[ -z "$DISTRO" ]]; then
GetDistro
+ echo "Found Distro $DISTRO"
fi
for service in ${services//,/ }; do
# Allow individual services to specify dependencies
@@ -797,23 +832,30 @@
done
IFS=$OIFS
done
+ $xtrace
}
# Distro-agnostic package installer
# install_package package [package ...]
function install_package() {
+ local xtrace=$(set +o | grep xtrace)
+ set +o xtrace
if is_ubuntu; then
# if there are transient errors pulling the updates, that's fine. It may
# be secondary repositories that we don't really care about.
[[ "$NO_UPDATE_REPOS" = "True" ]] || apt_get update || /bin/true
NO_UPDATE_REPOS=True
+ $xtrace
apt_get install "$@"
elif is_fedora; then
+ $xtrace
yum_install "$@"
elif is_suse; then
+ $xtrace
zypper_install "$@"
else
+ $xtrace
exit_distro_not_supported "installing packages"
fi
}
@@ -1092,7 +1134,13 @@
# ``TRACK_DEPENDS``, ``*_proxy``
# pip_install package [package ...]
function pip_install {
- [[ "$OFFLINE" = "True" || -z "$@" ]] && return
+ local xtrace=$(set +o | grep xtrace)
+ set +o xtrace
+ if [[ "$OFFLINE" = "True" || -z "$@" ]]; then
+ $xtrace
+ return
+ fi
+
if [[ -z "$os_PACKAGE" ]]; then
GetOSVersion
fi
@@ -1121,6 +1169,7 @@
# this problem. See https://github.com/pypa/pip/issues/709
local pip_build_tmp=$(mktemp --tmpdir -d pip-build.XXXXX)
+ $xtrace
$SUDO_PIP PIP_DOWNLOAD_CACHE=${PIP_DOWNLOAD_CACHE:-/var/cache/pip} \
HTTP_PROXY=$http_proxy \
HTTPS_PROXY=$https_proxy \
@@ -1235,32 +1284,36 @@
# Uses global ``ENABLED_SERVICES``
# is_service_enabled service [service ...]
function is_service_enabled() {
+ local xtrace=$(set +o | grep xtrace)
+ set +o xtrace
+ local enabled=1
services=$@
for service in ${services}; do
- [[ ,${ENABLED_SERVICES}, =~ ,${service}, ]] && return 0
+ [[ ,${ENABLED_SERVICES}, =~ ,${service}, ]] && enabled=0
# Look for top-level 'enabled' function for this service
if type is_${service}_enabled >/dev/null 2>&1; then
# A function exists for this service, use it
is_${service}_enabled
- return $?
+ enabled=$?
fi
# TODO(dtroyer): Remove these legacy special-cases after the is_XXX_enabled()
# are implemented
- [[ ${service} == n-cell-* && ${ENABLED_SERVICES} =~ "n-cell" ]] && return 0
- [[ ${service} == "nova" && ${ENABLED_SERVICES} =~ "n-" ]] && return 0
- [[ ${service} == "cinder" && ${ENABLED_SERVICES} =~ "c-" ]] && return 0
- [[ ${service} == "ceilometer" && ${ENABLED_SERVICES} =~ "ceilometer-" ]] && return 0
- [[ ${service} == "glance" && ${ENABLED_SERVICES} =~ "g-" ]] && return 0
- [[ ${service} == "ironic" && ${ENABLED_SERVICES} =~ "ir-" ]] && return 0
- [[ ${service} == "neutron" && ${ENABLED_SERVICES} =~ "q-" ]] && return 0
- [[ ${service} == "trove" && ${ENABLED_SERVICES} =~ "tr-" ]] && return 0
- [[ ${service} == "swift" && ${ENABLED_SERVICES} =~ "s-" ]] && return 0
- [[ ${service} == s-* && ${ENABLED_SERVICES} =~ "swift" ]] && return 0
+ [[ ${service} == n-cell-* && ${ENABLED_SERVICES} =~ "n-cell" ]] && enabled=0
+ [[ ${service} == "nova" && ${ENABLED_SERVICES} =~ "n-" ]] && enabled=0
+ [[ ${service} == "cinder" && ${ENABLED_SERVICES} =~ "c-" ]] && enabled=0
+ [[ ${service} == "ceilometer" && ${ENABLED_SERVICES} =~ "ceilometer-" ]] && enabled=0
+ [[ ${service} == "glance" && ${ENABLED_SERVICES} =~ "g-" ]] && enabled=0
+ [[ ${service} == "ironic" && ${ENABLED_SERVICES} =~ "ir-" ]] && enabled=0
+ [[ ${service} == "neutron" && ${ENABLED_SERVICES} =~ "q-" ]] && enabled=0
+ [[ ${service} == "trove" && ${ENABLED_SERVICES} =~ "tr-" ]] && enabled=0
+ [[ ${service} == "swift" && ${ENABLED_SERVICES} =~ "s-" ]] && enabled=0
+ [[ ${service} == s-* && ${ENABLED_SERVICES} =~ "swift" ]] && enabled=0
done
- return 1
+ $xtrace
+ return $enabled
}
# Toggle enable/disable_service for services that must run exclusive of each other
@@ -1286,6 +1339,8 @@
# Only run the command if the target file (the last arg) is not on an
# NFS filesystem.
function _safe_permission_operation() {
+ local xtrace=$(set +o | grep xtrace)
+ set +o xtrace
local args=( $@ )
local last
local sudo_cmd
@@ -1299,6 +1354,7 @@
fi
if is_nfs_directory "$dir_to_check" ; then
+ $xtrace
return 0
fi
@@ -1308,6 +1364,7 @@
sudo_cmd="sudo"
fi
+ $xtrace
$sudo_cmd $@
}
diff --git a/lib/savanna b/lib/savanna
index 43c5e38..954f0e7 100644
--- a/lib/savanna
+++ b/lib/savanna
@@ -10,6 +10,7 @@
# configure_savanna
# start_savanna
# stop_savanna
+# cleanup_savanna
# Save trace setting
XTRACE=$(set +o | grep xtrace)
@@ -33,6 +34,8 @@
SAVANNA_SERVICE_PORT=${SAVANNA_SERVICE_PORT:-8386}
SAVANNA_SERVICE_PROTOCOL=${SAVANNA_SERVICE_PROTOCOL:-$SERVICE_PROTOCOL}
+SAVANNA_AUTH_CACHE_DIR=${SAVANNA_AUTH_CACHE_DIR:-/var/cache/savanna}
+
# Support entry points installation of console scripts
if [[ -d $SAVANNA_DIR/bin ]]; then
SAVANNA_BIN_DIR=$SAVANNA_DIR/bin
@@ -83,6 +86,14 @@
fi
}
+# cleanup_savanna() - Remove residual data files, anything left over from
+# previous runs that would need to clean up.
+function cleanup_savanna() {
+
+ # Cleanup auth cache dir
+ sudo rm -rf $SAVANNA_AUTH_CACHE_DIR
+}
+
# configure_savanna() - Set config files, create data dirs, etc
function configure_savanna() {
@@ -94,9 +105,27 @@
# Copy over savanna configuration file and configure common parameters.
cp $SAVANNA_DIR/etc/savanna/savanna.conf.sample $SAVANNA_CONF_FILE
+ # Create auth cache dir
+ sudo mkdir -p $SAVANNA_AUTH_CACHE_DIR
+ sudo chown $STACK_USER $SAVANNA_AUTH_CACHE_DIR
+ rm -rf $SAVANNA_AUTH_CACHE_DIR/*
+
+ # Set obsolete keystone auth configs for backward compatibility
+ iniset $SAVANNA_CONF_FILE DEFAULT os_auth_host $KEYSTONE_SERVICE_HOST
+ iniset $SAVANNA_CONF_FILE DEFAULT os_auth_port $KEYSTONE_SERVICE_PORT
+ iniset $SAVANNA_CONF_FILE DEFAULT os_auth_protocol $KEYSTONE_SERVICE_PROTOCOL
iniset $SAVANNA_CONF_FILE DEFAULT os_admin_password $SERVICE_PASSWORD
iniset $SAVANNA_CONF_FILE DEFAULT os_admin_username savanna
iniset $SAVANNA_CONF_FILE DEFAULT os_admin_tenant_name $SERVICE_TENANT_NAME
+
+ # Set actual keystone auth configs
+ iniset $SAVANNA_CONF_FILE keystone_authtoken auth_uri $KEYSTONE_SERVICE_PROTOCOL://$KEYSTONE_SERVICE_HOST:$KEYSTONE_SERVICE_PORT/
+ iniset $SAVANNA_CONF_FILE keystone_authtoken admin_tenant_name $SERVICE_TENANT_NAME
+ iniset $SAVANNA_CONF_FILE keystone_authtoken admin_user savanna
+ iniset $SAVANNA_CONF_FILE keystone_authtoken admin_password $SERVICE_PASSWORD
+ iniset $SAVANNA_CONF_FILE keystone_authtoken signing_dir $SAVANNA_AUTH_CACHE_DIR
+ iniset $SAVANNA_CONF_FILE keystone_authtoken cafile $KEYSTONE_SSL_CA
+
iniset $SAVANNA_CONF_FILE DEFAULT debug $SAVANNA_DEBUG
iniset $SAVANNA_CONF_FILE database connection `database_connection_url savanna`
diff --git a/lib/tempest b/lib/tempest
index 596750b..83ce5d2 100644
--- a/lib/tempest
+++ b/lib/tempest
@@ -87,11 +87,6 @@
local boto_instance_type="m1.tiny"
local ssh_connect_method="fixed"
- if [[ ! -d $TEMPEST_CONFIG_DIR ]]; then
- sudo mkdir -p $TEMPEST_CONFIG_DIR
- fi
- sudo chown $STACK_USER $TEMPEST_CONFIG_DIR
-
# TODO(afazekas):
# sudo python setup.py deploy
@@ -142,8 +137,12 @@
# Create tempest.conf from tempest.conf.sample
# copy every time, because the image UUIDS are going to change
- sudo cp $TEMPEST_DIR/etc/tempest.conf.sample $TEMPEST_CONFIG
- sudo chmod 644 $TEMPEST_CONFIG
+ if [[ ! -d $TEMPEST_CONFIG_DIR ]]; then
+ sudo mkdir -p $TEMPEST_CONFIG_DIR
+ fi
+ sudo chown $STACK_USER $TEMPEST_CONFIG_DIR
+ cp $TEMPEST_DIR/etc/tempest.conf.sample $TEMPEST_CONFIG
+ chmod 644 $TEMPEST_CONFIG
password=${ADMIN_PASSWORD:-secrete}
diff --git a/run_tests.sh b/run_tests.sh
index b4f26c5..a0bfbee 100755
--- a/run_tests.sh
+++ b/run_tests.sh
@@ -26,4 +26,4 @@
echo "Running bash8..."
-./tools/bash8.py $FILES
+./tools/bash8.py -v $FILES
diff --git a/stack.sh b/stack.sh
index ce19b8f..22a418f 100755
--- a/stack.sh
+++ b/stack.sh
@@ -294,15 +294,9 @@
SYSLOG_HOST=${SYSLOG_HOST:-$HOST_IP}
SYSLOG_PORT=${SYSLOG_PORT:-516}
-# Enable sysstat logging
-SYSSTAT_FILE=${SYSSTAT_FILE:-"sysstat.dat"}
-SYSSTAT_INTERVAL=${SYSSTAT_INTERVAL:-"1"}
-
+# for DSTAT logging
DSTAT_FILE=${DSTAT_FILE:-"dstat.txt"}
-PIDSTAT_FILE=${PIDSTAT_FILE:-"pidstat.txt"}
-PIDSTAT_INTERVAL=${PIDSTAT_INTERVAL:-"5"}
-
# Use color for logging output (only available if syslog is not used)
LOG_COLOR=`trueorfalse True $LOG_COLOR`
@@ -529,10 +523,11 @@
if [[ "$VERBOSE" == "True" ]]; then
# Redirect stdout/stderr to tee to write the log file
exec 1> >( awk '
+ /((set \+o$)|xtrace)/ { next }
{
- cmd ="date +\"%Y-%m-%d %H:%M:%S \""
+ cmd ="date +\"%Y-%m-%d %H:%M:%S.%3N | \""
cmd | getline now
- close("date +\"%Y-%m-%d %H:%M:%S \"")
+ close("date +\"%Y-%m-%d %H:%M:%S.%3N | \"")
sub(/^/, now)
print
fflush()
@@ -862,23 +857,9 @@
# Initialize the directory for service status check
init_service_check
-
-# Sysstat and friends
+# Dstat
# -------
-# If enabled, systat has to start early to track OpenStack service startup.
-# what we want to measure
-# -u : cpu statitics
-# -q : load
-# -b : io load rates
-# -w : process creation and context switch rates
-SYSSTAT_OPTS="-u -q -b -w"
-if [[ -n ${SCREEN_LOGDIR} ]]; then
- screen_it sysstat "cd $TOP_DIR; ./tools/sar_filter.py $SYSSTAT_OPTS -o $SCREEN_LOGDIR/$SYSSTAT_FILE $SYSSTAT_INTERVAL"
-else
- screen_it sysstat "./tools/sar_filter.py $SYSSTAT_OPTS $SYSSTAT_INTERVAL"
-fi
-
# A better kind of sysstat, with the top process per time slice
DSTAT_OPTS="-tcndylp --top-cpu-adv"
if [[ -n ${SCREEN_LOGDIR} ]]; then
@@ -887,15 +868,6 @@
screen_it dstat "dstat $DSTAT_OPTS"
fi
-# Per-process stats
-PIDSTAT_OPTS="-l -p ALL -T ALL"
-if [[ -n ${SCREEN_LOGDIR} ]]; then
- screen_it pidstat "cd $TOP_DIR; pidstat $PIDSTAT_OPTS $PIDSTAT_INTERVAL > $SCREEN_LOGDIR/$PIDSTAT_FILE"
-else
- screen_it pidstat "pidstat $PIDSTAT_OPTS $PIDSTAT_INTERVAL"
-fi
-
-
# Start Services
# ==============
diff --git a/tools/bash8.py b/tools/bash8.py
index 7552e0d..ca0abd9 100755
--- a/tools/bash8.py
+++ b/tools/bash8.py
@@ -110,11 +110,13 @@
return False
-def check_files(files):
+def check_files(files, verbose):
in_multiline = False
logical_line = ""
token = False
for line in fileinput.input(files):
+ if verbose and fileinput.isfirstline():
+ print "Running bash8 on %s" % fileinput.filename()
# NOTE(sdague): multiline processing of heredocs is interesting
if not in_multiline:
logical_line = line
@@ -141,13 +143,14 @@
parser.add_argument('files', metavar='file', nargs='+',
help='files to scan for errors')
parser.add_argument('-i', '--ignore', help='Rules to ignore')
+ parser.add_argument('-v', '--verbose', action='store_true', default=False)
return parser.parse_args()
def main():
opts = get_options()
register_ignores(opts.ignore)
- check_files(opts.files)
+ check_files(opts.files, opts.verbose)
if ERRORS > 0:
print("%d bash8 error(s) found" % ERRORS)
diff --git a/tools/create-stack-user.sh b/tools/create-stack-user.sh
index 50f6592..9c29ecd 100755
--- a/tools/create-stack-user.sh
+++ b/tools/create-stack-user.sh
@@ -15,6 +15,7 @@
# and it was time for this nonsense to stop. Run this script as root to create
# the user and configure sudo.
+set -o errexit
# Keep track of the devstack directory
TOP_DIR=$(cd $(dirname "$0")/.. && pwd)
@@ -27,12 +28,14 @@
# and ``DISTRO``
GetDistro
-# Needed to get ``ENABLED_SERVICES``
+# Needed to get ``ENABLED_SERVICES`` and ``STACK_USER``
source $TOP_DIR/stackrc
# Give the non-root user the ability to run as **root** via ``sudo``
is_package_installed sudo || install_package sudo
+[[ -z "$STACK_USER" ]] && die "STACK_USER is not set. Exiting."
+
if ! getent group $STACK_USER >/dev/null; then
echo "Creating a group called $STACK_USER"
groupadd $STACK_USER
diff --git a/tools/fixup_stuff.sh b/tools/fixup_stuff.sh
index 47b0cd1..048024a 100755
--- a/tools/fixup_stuff.sh
+++ b/tools/fixup_stuff.sh
@@ -98,6 +98,10 @@
sudo setenforce 0
fi
+ # make sure we have the "optional" repo enabled; it provides some
+ # packages like libffi-devel for example
+ sudo yum-config-manager --enable rhel-6-server-optional-rpms
+
# If the ``dbus`` package was installed by DevStack dependencies the
# uuid may not be generated because the service was never started (PR#598200),
# causing Nova to stop later on complaining that ``/var/lib/dbus/machine-id``
diff --git a/tools/sar_filter.py b/tools/sar_filter.py
deleted file mode 100755
index 24ef0e4..0000000
--- a/tools/sar_filter.py
+++ /dev/null
@@ -1,86 +0,0 @@
-#!/usr/bin/env python
-#
-# Copyright 2014 Samsung Electronics Corp. All Rights Reserved.
-#
-# Licensed under the Apache License, Version 2.0 (the "License");
-# you may not use this file except in compliance with the License.
-# You may obtain a copy of the License at
-#
-# http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
-# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
-# License for the specific language governing permissions and limitations
-# under the License.
-
-import re
-import subprocess
-import sys
-
-
-def is_data_line(line):
- timestamp, data = parse_line(line)
- return re.search('\d\.d', data)
-
-
-def parse_line(line):
- m = re.search('(\d\d:\d\d:\d\d( \w\w)?)(\s+((\S+)\s*)+)', line)
- if m:
- date = m.group(1)
- data = m.group(3).rstrip()
- return date, data
- else:
- return None, None
-
-
-process = subprocess.Popen(
- "sar %s" % " ".join(sys.argv[1:]),
- shell=True,
- stdout=subprocess.PIPE,
- stderr=subprocess.STDOUT)
-
-# Poll process for new output until finished
-
-start_time = ""
-header = ""
-data_line = ""
-printed_header = False
-current_ts = None
-
-# print out the first sysstat line regardless
-print process.stdout.readline()
-
-while True:
- nextline = process.stdout.readline()
- if nextline == '' and process.poll() is not None:
- break
-
- date, data = parse_line(nextline)
- # stop until we get to the first set of real lines
- if not date:
- continue
-
- # now we eat the header lines, and only print out the header
- # if we've never seen them before
- if not start_time:
- start_time = date
- header += "%s %s" % (date, data)
- elif date == start_time:
- header += " %s" % data
- elif not printed_header:
- printed_header = True
- print header
-
- # now we know this is a data line, printing out if the timestamp
- # has changed, and stacking up otherwise.
- nextline = process.stdout.readline()
- date, data = parse_line(nextline)
- if date != current_ts:
- current_ts = date
- print data_line
- data_line = "%s %s" % (date, data)
- else:
- data_line += " %s" % data
-
- sys.stdout.flush()