Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix some linter warnings, part 5 #216

Merged
merged 8 commits into from
Oct 16, 2017
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 13 additions & 13 deletions mysql-init/init.sh
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@ UPGRADE_SCRIPTS="/mysql-upgrade.d"
wait_mysql() {
echo "Waiting for MySQL to become available..."
success="false"
for i in $(seq $MYSQL_INIT_WAIT_RETRIES); do
for i in $(seq "$MYSQL_INIT_WAIT_RETRIES"); do
mysqladmin status \
--host="$MYSQL_INIT_HOST" \
--port=$MYSQL_INIT_PORT \
--port="$MYSQL_INIT_PORT" \
--user="$MYSQL_INIT_USERNAME" \
--password="$MYSQL_INIT_PASSWORD" \
--connect_timeout=10
Expand Down Expand Up @@ -58,7 +58,7 @@ clean_install() {
echo "Running script: $f"
mysql --host="$MYSQL_INIT_HOST" \
--user="$MYSQL_INIT_USERNAME" \
--port=$MYSQL_INIT_PORT \
--port="$MYSQL_INIT_PORT" \
--password="$MYSQL_INIT_PASSWORD" < "$f"
fi
done
Expand All @@ -69,7 +69,7 @@ clean_install() {
set +x
mysqladmin password \
--host="$MYSQL_INIT_HOST" \
--port=$MYSQL_INIT_PORT \
--port="$MYSQL_INIT_PORT" \
--user="$MYSQL_INIT_USERNAME" \
--password="$MYSQL_INIT_PASSWORD" \
"$MYSQL_INIT_SET_PASSWORD"
Expand All @@ -80,7 +80,7 @@ clean_install() {
pw=$(pwgen -1 32)
mysqladmin password \
--host="$MYSQL_INIT_HOST" \
--port=$MYSQL_INIT_PORT \
--port="$MYSQL_INIT_PORT" \
--user="$MYSQL_INIT_USERNAME" \
--password="$MYSQL_INIT_PASSWORD" \
"$pw"
Expand All @@ -92,7 +92,7 @@ clean_install() {
echo "Disabling remote root login..."
mysql --host="$MYSQL_INIT_HOST" \
--user="$MYSQL_INIT_USERNAME" \
--port=$MYSQL_INIT_PORT \
--port="$MYSQL_INIT_PORT" \
--password="$MYSQL_INIT_PASSWORD" < /disable-remote-root.sql
fi
}
Expand All @@ -102,7 +102,7 @@ schema_upgrade() {

# ash doesn't support arrays, this seems to be the most concise way to get
# fields by index
set $version
set "$version"
if [ "$#" -ne "3" ]; then
echo "Invalid version: '$version'"
sleep 1
Expand All @@ -125,7 +125,7 @@ schema_upgrade() {

# we explicitly want to word-split here...
# shellcheck disable=SC2046
set $(echo $diff_version | tr '.' ' ')
set $(echo "$diff_version" | tr '.' ' ')
if [ "$#" -ne "3" ]; then
echo "Invalid version number in upgrade directory, quitting! $diff_version"
sleep 1
Expand Down Expand Up @@ -164,7 +164,7 @@ schema_upgrade() {
set +x
mysql --host="$MYSQL_INIT_HOST" \
--user="$MYSQL_INIT_USERNAME" \
--port=$MYSQL_INIT_PORT \
--port="$MYSQL_INIT_PORT" \
--password="$MYSQL_INIT_PASSWORD" < "$f"
set -x
any_applied="true"
Expand All @@ -181,10 +181,10 @@ schema_upgrade() {
echo "Recording version in $database: $last_major.$last_minor.$last_patch"
query="insert into schema_version (major, minor, patch) values ($last_major, $last_minor, $last_patch);"
set +x
echo $query | mysql \
echo "$query" | mysql \
--host="$MYSQL_INIT_HOST" \
--user="$MYSQL_INIT_USERNAME" \
--port=$MYSQL_INIT_PORT \
--port="$MYSQL_INIT_PORT" \
--password="$MYSQL_INIT_PASSWORD" \
"$database"
set -x
Expand All @@ -201,10 +201,10 @@ query="select major, minor, patch from schema_version order by id desc limit 1;"
version=$(echo "$query" | mysql \
--host="$MYSQL_INIT_HOST" \
--user="$MYSQL_INIT_USERNAME" \
--port=$MYSQL_INIT_PORT \
--port="$MYSQL_INIT_PORT" \
--password="$MYSQL_INIT_PASSWORD" \
--silent \
$MYSQL_INIT_SCHEMA_DATABASE)
"$MYSQL_INIT_SCHEMA_DATABASE")
if [ $? -eq 0 ]; then
schema_upgrade "$version"
else
Expand Down
12 changes: 7 additions & 5 deletions mysql-init/template.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#!/usr/bin/env python
# coding=utf-8

# (C) Copyright 2017 Hewlett Packard Enterprise Development LP
#
Expand Down Expand Up @@ -30,11 +31,12 @@ def main():
out_path = sys.argv[2]

with open(in_path, 'r') as in_file, open(out_path, 'w') as out_file:
t = Template(in_file.read(),
keep_trailing_newline=True,
lstrip_blocks=True,
trim_blocks=True)
out_file.write(t.render(os.environ))
tmle = Template(in_file.read(),
keep_trailing_newline=True,
lstrip_blocks=True,
trim_blocks=True)
out_file.write(tmle.render(os.environ))


if __name__ == '__main__':
main()
12 changes: 7 additions & 5 deletions storm/clean_externals.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#!/usr/bin/env python
# coding=utf-8

# (C) Copyright 2017 Hewlett Packard Enterprise Development LP
#
Expand Down Expand Up @@ -34,17 +35,18 @@ def main():

invalid = keep.difference(externals)
if not keep.issubset(externals):
print('Invalid values for KEEP_EXTERNALS: %r' % invalid,
file=sys.stderr)
print('Invalid values for KEEP_EXTERNALS: {!r}'
.format(invalid, file=sys.stderr))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

file= should be outside the inner parens ... also not totally sure why '%' is preferred?

sys.exit(1)

externals.difference_update()

remove = externals.difference(keep)
for ext in remove:
p = os.path.join(EXTERNAL_PATH, ext)
print('Removing: %s' % p)
shutil.rmtree(p, ignore_errors=True)
ext_path = os.path.join(EXTERNAL_PATH, ext)
print('Removing: {}'.format(ext_path))
shutil.rmtree(ext_path, ignore_errors=True)


if __name__ == '__main__':
main()
18 changes: 9 additions & 9 deletions storm/entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -34,19 +34,19 @@ if [ -n "$ZOOKEEPER_PORT" ]; then
fi
fi

first_zk=$(echo $STORM_ZOOKEEPER_SERVERS | cut -d, -f1)
first_zk=$(echo "$STORM_ZOOKEEPER_SERVERS" | cut -d, -f1)

# wait for zookeeper to become available
if [ "$ZOOKEEPER_WAIT" = "true" ]; then
success="false"
for i in $(seq $ZOOKEEPER_WAIT_RETRIES); do
ok=$(echo ruok | nc $first_zk $STORM_ZOOKEEPER_PORT -w $ZOOKEEPER_WAIT_TIMEOUT)
for i in $(seq "$ZOOKEEPER_WAIT_RETRIES"); do
ok=$(echo ruok | nc "$first_zk" "$STORM_ZOOKEEPER_PORT" -w "$ZOOKEEPER_WAIT_TIMEOUT")
if [ $? -eq 0 -a "$ok" = "imok" ]; then
success="true"
break
else
echo "Connect attempt $i of $ZOOKEEPER_WAIT_RETRIES failed, retrying..."
sleep $ZOOKEEPER_WAIT_DELAY
sleep "$ZOOKEEPER_WAIT_DELAY"
fi
done

Expand All @@ -65,12 +65,12 @@ if [ -z "$STORM_LOCAL_HOSTNAME" ]; then
fi

if [ -z "$SUPERVISOR_CHILDOPTS" ]; then
SUPERVISOR_CHILDOPTS="-Xmx$(python /heap.py $SUPERVISOR_MAX_HEAP_MB)"
SUPERVISOR_CHILDOPTS="-Xmx$(python /heap.py "$SUPERVISOR_MAX_HEAP_MB")"
export SUPERVISOR_CHILDOPTS
fi

if [ -z "$WORKER_CHILDOPTS" ]; then
WORKER_CHILDOPTS="-Xmx$(python /heap.py $WORKER_MAX_HEAP_MB)"
WORKER_CHILDOPTS="-Xmx$(python /heap.py "$WORKER_MAX_HEAP_MB")"
WORKER_CHILDOPTS="$WORKER_CHILDOPTS -XX:+UseConcMarkSweepGC"
if [ "$WORKER_REMOTE_JMX" = "true" ]; then
WORKER_CHILDOPTS="$WORKER_CHILDOPTS -Dcom.sun.management.jmxremote"
Expand All @@ -80,12 +80,12 @@ if [ -z "$WORKER_CHILDOPTS" ]; then
fi

if [ -z "$NIMBUS_CHILDOPTS" ]; then
NIMBUS_CHILDOPTS="-Xmx$(python /heap.py $NIMBUS_MAX_HEAP_MB)"
NIMBUS_CHILDOPTS="-Xmx$(python /heap.py "$NIMBUS_MAX_HEAP_MB")"
export NIMBUS_CHILDOPTS
fi

if [ -z "$UI_CHILDOPTS" ]; then
UI_CHILDOPTS="-Xmx$(python /heap.py $UI_MAX_HEAP_MB)"
UI_CHILDOPTS="-Xmx$(python /heap.py "$UI_MAX_HEAP_MB")"
export UI_CHILDOPTS
fi

Expand Down Expand Up @@ -114,7 +114,7 @@ template_dir "$CONFIG_TEMPLATES" "$CONFIG_DEST"
template_dir "$LOG_TEMPLATES" "$LOG_DEST"

if [ "$WORKER_LOGS_TO_STDOUT" = "true" ]; then
for PORT in `echo $SUPERVISOR_SLOTS_PORTS | sed -e "s/,/ /" `; do
for PORT in `echo "$SUPERVISOR_SLOTS_PORTS" | sed -e "s/,/ /" `; do
LOGDIR="/storm/logs/workers-artifacts/thresh/$PORT"
mkdir -p "$LOGDIR"
WORKER_LOG="$LOGDIR/worker.log"
Expand Down
7 changes: 4 additions & 3 deletions storm/heap.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#!/usr/bin/env python
# coding=utf-8

# (C) Copyright 2017 Hewlett Packard Enterprise Development LP
#
Expand Down Expand Up @@ -50,7 +51,7 @@ def get_effective_memory_limit_mb():

def main():
if HEAP_OVERRIDE_MB:
print('%sm' % HEAP_OVERRIDE_MB)
print('{}m'.format(HEAP_OVERRIDE_MB))
return

system_max = get_system_memory_mb()
Expand All @@ -68,11 +69,11 @@ def main():
else:
arg_max = effective_max

print('%dm' % min([
print('{:d}m'.format(min([
effective_max,
env_max,
arg_max
]))
])))


if __name__ == '__main__':
Expand Down
8 changes: 5 additions & 3 deletions storm/storm_mirror.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#!/usr/bin/env python
# coding=utf-8

# (C) Copyright 2017 Hewlett Packard Enterprise Development LP
#
Expand Down Expand Up @@ -35,14 +36,15 @@ def main():
mirror = MIRROR

if not DIRECT:
r = requests.get(MIRROR, params={
req = requests.get(MIRROR, params={
'path': 'apache-storm-{0}.tar.gz'.format(version),
'as_json': '1'
})
r.raise_for_status()
mirror = r.json()['preferred']
req.raise_for_status()
mirror = req.json()['preferred']

print(PATH.format(mirror=mirror, version=version))


if __name__ == '__main__':
main()
12 changes: 7 additions & 5 deletions storm/template.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#!/usr/bin/env python
# coding=utf-8

# (C) Copyright 2017 Hewlett Packard Enterprise Development LP
#
Expand Down Expand Up @@ -30,11 +31,12 @@ def main():
out_path = sys.argv[2]

with open(in_path, 'r') as in_file, open(out_path, 'w') as out_file:
t = Template(in_file.read(),
keep_trailing_newline=True,
lstrip_blocks=True,
trim_blocks=True)
out_file.write(t.render(os.environ))
tmle = Template(in_file.read(),
keep_trailing_newline=True,
lstrip_blocks=True,
trim_blocks=True)
out_file.write(tmle.render(os.environ))


if __name__ == '__main__':
main()