summaryrefslogtreecommitdiff
path: root/bin
diff options
context:
space:
mode:
Diffstat (limited to 'bin')
-rwxr-xr-xbin/debug.sh29
-rw-r--r--bin/node_init86
-rwxr-xr-xbin/puppet_command14
-rwxr-xr-xbin/run_tests52
4 files changed, 169 insertions, 12 deletions
diff --git a/bin/debug.sh b/bin/debug.sh
new file mode 100755
index 00000000..d6f37542
--- /dev/null
+++ b/bin/debug.sh
@@ -0,0 +1,29 @@
+#!/bin/bash
+# debug script to be run on remote servers
+# called from leap_cli with the 'leap debug' cmd
+
+apps='(leap|pixelated|stunnel|couch|soledad|haproxy)'
+
+facts='(apt_running |^architecture |^augeasversion |^couchdb_.* |^debian_.* |^dhcp_enabled |^domain |^facterversion |^filesystems |^fqdn |^hardwaremodel |^hostname |^interface.* |^ipaddress.* |^is_pe |^is_virtual |^kernel.* |^lib |^lsb.* |^memory.* |^mtu_.* |^netmask.* |^network_.* |^operatingsystem |^os.* |^path |^physicalprocessorcount |^processor.* |^ps |^puppetversion |^root_home |^rsyslog_version |^rubysitedir |^rubyversion |^selinux |^ssh_version |^swapfree.* |^swapsize.* |^type |^virtual)'
+
+
+# query facts and filter out private stuff
+export FACTERLIB="/srv/leap/puppet/modules/apache/lib/facter:/srv/leap/puppet/modules/apt/lib/facter:/srv/leap/puppet/modules/concat/lib/facter:/srv/leap/puppet/modules/couchdb/lib/facter:/srv/leap/puppet/modules/rsyslog/lib/facter:/srv/leap/puppet/modules/site_config/lib/facter:/srv/leap/puppet/modules/sshd/lib/facter:/srv/leap/puppet/modules/stdlib/lib/facter"
+
+facter 2>/dev/null | egrep -i "$facts"
+
+# query installed versions
+echo -e '\n\n'
+dpkg -l | egrep "$apps"
+
+
+# query running procs
+echo -e '\n\n'
+ps aux|egrep "$apps"
+
+echo -e '\n\n'
+echo -e "Last deploy:\n"
+tail -2 /var/log/leap/deploy-summary.log
+
+
+
diff --git a/bin/node_init b/bin/node_init
new file mode 100644
index 00000000..da250012
--- /dev/null
+++ b/bin/node_init
@@ -0,0 +1,86 @@
+#!/bin/bash
+#
+# LEAP Platform node initialization.
+# This script is run on the target server when `leap node init` is run.
+#
+
+DEBIAN_VERSION="^(jessie|8\.)"
+LEAP_DIR="/srv/leap"
+HIERA_DIR="/etc/leap"
+INIT_FILE="/srv/leap/initialized"
+REQUIRED_PACKAGES="puppet rsync lsb-release locales"
+
+PATH="/bin:/sbin:/usr/sbin:/usr/bin"
+APT_GET="apt-get -q -y -o DPkg::Options::=--force-confold"
+APT_GET_UPDATE="apt-get update -o Acquire::Languages=none"
+BAD_APT_RESPONSE="(BADSIG|NO_PUBKEY|KEYEXPIRED|REVKEYSIG|NODATA|Could not resolve|failed to fetch)"
+export DEBIAN_FRONTEND=noninteractive
+
+test -f $INIT_FILE && rm $INIT_FILE
+if ! egrep -q "$DEBIAN_VERSION" /etc/debian_version; then
+ echo "ERROR: This operating system is not supported. The file /etc/debian_version must match /$DEBIAN_VERSION/ but is: `cat /etc/debian_version`"
+ exit 1
+fi
+mkdir -p $LEAP_DIR
+echo "en_US.UTF-8 UTF-8" > /etc/locale.gen
+
+#
+# UPDATE PACKAGES
+# (exit code is not reliable, sadly)
+#
+echo "updating package list"
+
+error_count=0
+while read line; do
+ error=$(echo $line | egrep "$BAD_APT_RESPONSE")
+ if [[ $error ]]; then
+ errors[error_count]=$error
+ ((error_count++))
+ break # should we halt on first error?
+ fi
+ echo $line
+done < <($APT_GET_UPDATE 2>&1)
+
+if [[ $error_count > 0 ]]; then
+ echo "ERROR: fatal error in 'apt-get update', bailing out."
+ for e in "${errors[@]}"; do
+ echo " $e"
+ done
+ exit 1
+fi
+
+#
+# UPDATE TIME
+#
+if [[ ! $(which ntpd) ]]; then
+ echo "installing ntpd"
+ $APT_GET install ntp
+ exit_code=$?
+ if [[ $exit_code -ne 0 ]]; then
+ echo "ERROR: bailing out."
+ exit $exit_code
+ fi
+fi
+
+echo "updating server time"
+systemctl -q is-active ntp.service && systemctl stop ntp.service
+ntpd -gxq
+systemctl -q is-active ntp.service || systemctl start ntp.service
+
+#
+# INSTALL PACKAGES
+#
+echo "installing required packages"
+$APT_GET install $REQUIRED_PACKAGES
+exit_code=$?
+if [[ $exit_code -ne 0 ]]; then
+ echo "ERROR: bailing out."
+ exit $exit_code
+fi
+
+#
+# FINALIZE
+#
+mkdir -p $HIERA_DIR
+chmod 0755 $HIERA_DIR
+touch $INIT_FILE
diff --git a/bin/puppet_command b/bin/puppet_command
index 1e74522a..eb3cd0b9 100755
--- a/bin/puppet_command
+++ b/bin/puppet_command
@@ -13,6 +13,7 @@ require 'logger'
require 'socket'
require 'fileutils'
+DEBIAN_VERSION = /^(jessie|8\.)/
PUPPET_BIN = '/usr/bin/puppet'
PUPPET_DIRECTORY = '/srv/leap'
PUPPET_PARAMETERS = '--color=false --detailed-exitcodes --libdir=puppet/lib --confdir=puppet'
@@ -28,7 +29,12 @@ SUMMARY_LOG_1 = '/var/log/leap/deploy-summary.log.1'
APPLY_START_STR = "STARTING APPLY"
APPLY_FINISH_STR = "APPLY COMPLETE"
+
def main
+ if File.read('/etc/debian_version') !~ DEBIAN_VERSION
+ log "ERROR: This operating system is not supported. The file /etc/debian_version must match #{DEBIAN_VERSION}."
+ exit 1
+ end
process_command_line_arguments
with_lockfile do
@commands.each do |command|
@@ -58,9 +64,11 @@ def log(str, *args)
str = str.strip
$stdout.puts str
$stdout.flush
- $logger.info(str)
- if args.include? :summary
- $summary_logger.info(str)
+ if $logger
+ $logger.info(str)
+ if args.include? :summary
+ $summary_logger.info(str)
+ end
end
end
diff --git a/bin/run_tests b/bin/run_tests
index 8eab5286..b6784ed5 100755
--- a/bin/run_tests
+++ b/bin/run_tests
@@ -14,6 +14,7 @@
require 'minitest/unit'
require 'yaml'
require 'tsort'
+require 'timeout'
##
## CONSTANTS
@@ -33,7 +34,8 @@ HELPER_PATHS = [
]
TEST_PATHS = [
'../../tests/white-box/*.rb',
- '/srv/leap/files/tests/white-box/*.rb'
+ '/srv/leap/files/tests/white-box/*.rb',
+ '/srv/leap/tests_custom/*.rb'
]
##
@@ -80,6 +82,8 @@ end
class LeapTest < MiniTest::Unit::TestCase
class Pass < MiniTest::Assertion
end
+ class SilentPass < Pass
+ end
class Ignore < MiniTest::Assertion
end
@@ -114,6 +118,16 @@ class LeapTest < MiniTest::Unit::TestCase
end
#
+ # thrown Timeout::Error if test run
+ # takes longer than $timeout
+ #
+ def run(*args)
+ Timeout::timeout($timeout, Timeout::Error) do
+ super(*args)
+ end
+ end
+
+ #
# The default pass just does an `assert true`. In our case, we want to make the passes more explicit.
#
def pass
@@ -121,6 +135,12 @@ class LeapTest < MiniTest::Unit::TestCase
end
#
+ # This is just like pass(), but the result is normally silent, unless `run_tests --test TEST`
+ def silent_pass
+ raise LeapTest::SilentPass
+ end
+
+ #
# Called when the test should be silently ignored.
#
def ignore
@@ -143,6 +163,7 @@ class LeapTest < MiniTest::Unit::TestCase
MiniTest::Unit.runner.warn(self.class, method_name, msg.join("\n"))
end
+ #
# Always runs test methods within a test class in alphanumeric order
#
def self.test_order
@@ -208,6 +229,10 @@ class LeapRunner < MiniTest::Unit
if @verbose
report_line("IGNORE", klass, meth, e, e.message)
end
+ when LeapTest::SilentPass then
+ if $pinned_test_method || $output_format == :checkmk
+ report_line("PASS", klass, meth)
+ end
when LeapTest::Pass then
@passes += 1
report_line("PASS", klass, meth)
@@ -217,6 +242,12 @@ class LeapRunner < MiniTest::Unit
if $halt_on_failure
raise TestFailure.new
end
+ when Timeout::Error then
+ @failures += 1
+ report_line("TIMEOUT", klass, meth, nil, "Test stopped because timeout exceeded (#{$timeout} seconds).")
+ if $halt_on_failure
+ raise TestFailure.new
+ end
else
@errors += 1
bt = MiniTest::filter_backtrace(e.backtrace).join "\n"
@@ -260,7 +291,7 @@ class LeapRunner < MiniTest::Unit
def report_line(prefix, klass, meth, e=nil, message=nil)
msg_txt = nil
if message
- message = message.sub(/http:\/\/([a-z_]+):([a-zA-Z0-9_]+)@/, "http://\\1:REDACTED@")
+ message = message.gsub(/http:\/\/([a-z_]+):([a-zA-Z0-9_]+)@/, "http://\\1:REDACTED@")
if $output_format == :human
indent = "\n "
msg_txt = indent + message.split("\n").join(indent)
@@ -370,13 +401,14 @@ end
def print_help
puts ["USAGE: run_tests [OPTIONS]",
- " --continue Don't halt on an error, but continue to the next test.",
- " --checkmk Print test results in checkmk format (must come before --test).",
- " --test TEST Run only the test with name TEST.",
- " --list-tests Prints the names of all available tests and exit.",
- " --retry COUNT If the tests don't pass, retry COUNT additional times (default is zero)",
- " --wait SECONDS Wait for SECONDS between retries (default is 5)",
- " --debug Print out full stack trace on errors"].join("\n")
+ " --continue Don't halt on an error, but continue to the next test.",
+ " --checkmk Print test results in checkmk format (must come before --test).",
+ " --test TEST Run only the test with name TEST.",
+ " --list-tests Prints the names of all available tests and exit.",
+ " --retry COUNT If the tests don't pass, retry COUNT additional times (default is zero).",
+ " --timeout SECONDS Halt a test if it exceed SECONDS (default is 30).",
+ " --wait SECONDS Wait for SECONDS between retries (default is 5).",
+ " --debug Print out full stack trace on errors."].join("\n")
exit(0)
end
@@ -454,6 +486,7 @@ def main
$output_format = :human
$retry = false
$wait = 5
+ $timeout = 30
loop do
case ARGV[0]
when '--continue' then ARGV.shift; $halt_on_failure = false;
@@ -462,6 +495,7 @@ def main
when '--test' then ARGV.shift; pin_test_name(ARGV.shift)
when '--list-tests' then list_tests
when '--retry' then ARGV.shift; $retry = ARGV.shift.to_i
+ when '--timeout' then ARGV.shift; $timeout = ARGV.shift.to_i;
when '--wait' then ARGV.shift; $wait = ARGV.shift.to_i
when '--debug' then ARGV.shift
when '-d' then ARGV.shift