From bda0ba1e59e1131339683259fdb9839169d76945 Mon Sep 17 00:00:00 2001 From: Christoph Kluenter Date: Thu, 10 Dec 2015 10:25:48 +0100 Subject: look for tests in custom directory if 3rd parties want to add tests that get run by 'leap test' they can now just drop them in /srv/leap/tests_custom/ and they wil 'just work' --- bin/run_tests | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'bin') diff --git a/bin/run_tests b/bin/run_tests index 8eab5286..fc668ad6 100755 --- a/bin/run_tests +++ b/bin/run_tests @@ -33,7 +33,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' ] ## -- cgit v1.2.3 From 45412d75d16189719c059c0368eca4bda75e6ff8 Mon Sep 17 00:00:00 2001 From: varac Date: Tue, 19 Jan 2016 20:05:22 +0100 Subject: [feat] Add 'leap debug' cmd This will output node debug information by calling the bin/debug.sh script. --- bin/debug.sh | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100755 bin/debug.sh (limited to 'bin') diff --git a/bin/debug.sh b/bin/debug.sh new file mode 100755 index 00000000..2363644c --- /dev/null +++ b/bin/debug.sh @@ -0,0 +1,25 @@ +#!/bin/bash +# debug script to be run on remote servers +# called from leap_cli with the 'leap debug' cmd + +regexp='(leap|pixelated|stunnel|couch|soledad|haproxy)' + +# query facts and filter out private stuff +echo -e '\n\n' +facter | egrep -iv '(^ssh|^uniqueid)' + +# query installed versions +echo -e '\n\n' +dpkg -l | egrep "$regexp" + + +# query running procs +echo -e '\n\n' +ps aux|egrep "$regexp" + +echo -e '\n\n' +echo -e "Last deploy:\n" +tail -2 /var/log/leap/deploy-summary.log + + + -- cgit v1.2.3 From 27a059ccb3b5210f7e539326c30f20d8530cde1d Mon Sep 17 00:00:00 2001 From: varac Date: Mon, 25 Jan 2016 16:49:18 +0100 Subject: [feat] Whitelist facts to query from debug script - Resolves: #7823 --- bin/debug.sh | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) (limited to 'bin') diff --git a/bin/debug.sh b/bin/debug.sh index 2363644c..d6f37542 100755 --- a/bin/debug.sh +++ b/bin/debug.sh @@ -2,20 +2,24 @@ # debug script to be run on remote servers # called from leap_cli with the 'leap debug' cmd -regexp='(leap|pixelated|stunnel|couch|soledad|haproxy)' +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 -echo -e '\n\n' -facter | egrep -iv '(^ssh|^uniqueid)' +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 "$regexp" +dpkg -l | egrep "$apps" # query running procs echo -e '\n\n' -ps aux|egrep "$regexp" +ps aux|egrep "$apps" echo -e '\n\n' echo -e "Last deploy:\n" -- cgit v1.2.3 From edc9aa13f5ebb07f27e73fd4befc5fbbadfebc66 Mon Sep 17 00:00:00 2001 From: elijah Date: Mon, 1 Feb 2016 17:02:52 -0800 Subject: tests: added --timeout to run_tests (default 30 seconds). test halts and fails after timeout is reached. closes #7806 --- bin/run_tests | 35 ++++++++++++++++++++++++++++------- 1 file changed, 28 insertions(+), 7 deletions(-) (limited to 'bin') diff --git a/bin/run_tests b/bin/run_tests index fc668ad6..4cb652db 100755 --- a/bin/run_tests +++ b/bin/run_tests @@ -14,6 +14,7 @@ require 'minitest/unit' require 'yaml' require 'tsort' +require 'timeout' ## ## CONSTANTS @@ -114,6 +115,16 @@ class LeapTest < MiniTest::Unit::TestCase self.instance_methods.grep(/^test_/).sort 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. # @@ -144,6 +155,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 @@ -218,6 +230,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" @@ -371,13 +389,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 @@ -455,6 +474,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; @@ -463,6 +483,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 -- cgit v1.2.3 From d547f9564fb8aae5e2839cfbc5f54a706398a2b0 Mon Sep 17 00:00:00 2001 From: elijah Date: Fri, 12 Feb 2016 15:07:58 -0800 Subject: require jessie and created note_init script for node initialization --- bin/node_init | 86 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ bin/puppet_command | 6 ++++ 2 files changed, 92 insertions(+) create mode 100644 bin/node_init (limited to 'bin') 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..702c8cbd 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| -- cgit v1.2.3 From ed140134b5c2f4fa02c5e3622cb1979901b2d4db Mon Sep 17 00:00:00 2001 From: elijah Date: Wed, 24 Feb 2016 13:11:26 -0800 Subject: fix logging error in puppet_command --- bin/puppet_command | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) (limited to 'bin') diff --git a/bin/puppet_command b/bin/puppet_command index 702c8cbd..eb3cd0b9 100755 --- a/bin/puppet_command +++ b/bin/puppet_command @@ -64,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 -- cgit v1.2.3 From 966120293ec289636874edda6089b99dc49cb9ae Mon Sep 17 00:00:00 2001 From: elijah Date: Fri, 18 Mar 2016 09:40:41 -0700 Subject: tests: fix mx test, ensure password is redacted. --- bin/run_tests | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'bin') diff --git a/bin/run_tests b/bin/run_tests index 4cb652db..5733f526 100755 --- a/bin/run_tests +++ b/bin/run_tests @@ -279,7 +279,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) -- cgit v1.2.3 From 232047fdee815d9cf8c92b6853c5bc8039f2719c Mon Sep 17 00:00:00 2001 From: elijah Date: Wed, 13 Apr 2016 02:36:47 -0700 Subject: test: ensure that checkmk always gets the same list of tests --- bin/run_tests | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'bin') diff --git a/bin/run_tests b/bin/run_tests index 5733f526..b6784ed5 100755 --- a/bin/run_tests +++ b/bin/run_tests @@ -82,6 +82,8 @@ end class LeapTest < MiniTest::Unit::TestCase class Pass < MiniTest::Assertion end + class SilentPass < Pass + end class Ignore < MiniTest::Assertion end @@ -132,6 +134,12 @@ class LeapTest < MiniTest::Unit::TestCase raise LeapTest::Pass 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. # @@ -221,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) -- cgit v1.2.3