diff --git a/manifests/test.pp b/manifests/test.pp index fa5387b..75e7152 100644 --- a/manifests/test.pp +++ b/manifests/test.pp @@ -7,7 +7,10 @@ Variant[Boolean,String] $ensure = present, - String $template = 'tp/test/acceptance.erb', + Variant[Undef,String,Array] $source = undef, + Variant[Undef,String,Array] $template = undef, + Variant[Undef,String] $epp = undef, + Variant[Undef,String] $content = undef, Hash $options_hash = { }, Hash $settings_hash = { }, @@ -47,13 +50,15 @@ $array_service_name=any2array($settings['service_name']) $array_tcp_port=any2array($settings['tcp_port']) - if $template != '' { + $file_content = tp_content($content, $template, $epp) + if $file_content != '' { file { "${base_dir}/${title}": ensure => $ensure, mode => '0755', owner => 'root', group => 'root', - content => template($template), + content => $file_content, + source => $source, tag => 'tp_test', } } diff --git a/templates/tp.erb b/templates/tp.erb index 7e71154..f2cdd28 100644 --- a/templates/tp.erb +++ b/templates/tp.erb @@ -12,6 +12,8 @@ else TINYDATA_DIR = '/etc/puppetlabs/code/modules/tinydata/data' end +COMMAND_REDIR = ' > /dev/null 2>&1' + TP_APPS = Dir.entries(TP_APP_DIR).reject { |f| File.directory?(f) } # Trap CTRL+C cleanly (in tp log) @@ -45,33 +47,48 @@ end def tp_test(app) begin settings = check_yaml app - puts - puts "### #{app} status" + + # Run custom test script if exists if File.exists?(TP_TEST_DIR + "/#{app}") - system(TP_TEST_DIR + "/#{app}") + system(TP_TEST_DIR + "/#{app}" + COMMAND_REDIR) result = $? if result == 0 - puts "\e[32m# Test #{app}: OK \e[0m\n" + puts "- #{app}: \e[32m#{TP_TEST_DIR}/#{app} OK \e[0m\n" else - puts "\e[41m# Test #{app}: ERROR #\e[0m\n" + puts "- #{app}: \e[31m#{TP_TEST_DIR}/#{app} ERROR \e[0m\n" end $error_exit = 1 if result != 0 - else - if settings['package_name'] and settings['package_name'] != "" - Array(settings['package_name']).each do |s| - system("<%= @options['check_package_command'] %> " + s + " 2> /dev/null") + end + + # Check package if defined + if settings['package_name'] and settings['package_name'] != "" + Array(settings['package_name']).each do |s| + if settings['package_provider'] == 'gem' + system("gem list | grep " + s + " " + COMMAND_REDIR) + elsif settings['package_provider'] == 'pip' + system("pip list | grep " + s + " " + COMMAND_REDIR) + else + system("<%= @options['check_package_command'] %> " + s + " " + COMMAND_REDIR) + end + result = $? + if result == 0 + puts "- #{app}: \e[32mpackage #{s} OK \e[0m\n" + else + puts "- #{app}: \e[31mpackage #{s} ERROR \e[0m\n" end + $error_exit = 1 if result != 0 end + end - if settings['service_name'] and settings['service_name'] != "" - Array(settings['service_name']).each do |s| - system("<%= @options['check_service_command'] %> " + s + " <%= @options['check_service_command_post'] %>") - end + # Check service if defined + if settings['service_name'] and settings['service_name'] != "" + Array(settings['service_name']).each do |s| + system("<%= @options['check_service_command'] %> " + s + " <%= @options['check_service_command_post'] %>" + COMMAND_REDIR) result = $? if result == 0 - puts "\e[32m# Test #{app}: OK \e[0m\n" + puts "- #{app}: \e[32mservice #{s} OK \e[0m\n" else - puts "\e[41m# Test #{app}: ERROR #\e[0m\n" + puts "- #{app}: \e[31mservice #{s} ERROR \e[0m\n" end $error_exit = 1 if result != 0 end @@ -92,9 +109,9 @@ when 'test' app.send("tp_test", app) end if $error_exit == 0 - puts "\n\e[32m### ALL TESTS PASSED ###\e[0m\n" + puts "\n\e[32mAll tests OK\e[0m\n" else - puts "\n\e[41m### SOME TESTS FAILED ###\e[0m\n" + puts "\n\e[31mSome test in ERROR\e[0m\n" end exit($error_exit)