facter-statistax 0.0.9 → 0.0.10

Sign up to get free protection for your applications and to get access to all the features.
Files changed (24) hide show
  1. checksums.yaml +4 -4
  2. data/acceptance/Gemfile +2 -1
  3. data/acceptance/log_performance/configuration.rb +65 -0
  4. data/acceptance/log_performance/custom_exceptions.rb +5 -0
  5. data/acceptance/log_performance/execute_beaker_tests/beaker.rb +77 -0
  6. data/acceptance/log_performance/execute_beaker_tests/command_logger.rb +24 -0
  7. data/acceptance/log_performance/execute_beaker_tests/ns_pooler.rb +60 -0
  8. data/acceptance/log_performance/execute_beaker_tests/output_parser.rb +40 -0
  9. data/acceptance/log_performance/execute_beaker_tests/run_command.rb +30 -0
  10. data/acceptance/log_performance/execute_beaker_tests/test_all_platforms.rb +99 -0
  11. data/acceptance/log_performance/execute_beaker_tests/vm_pooler.rb +7 -0
  12. data/acceptance/log_performance/get_supported_platforms.rb +1904 -0
  13. data/acceptance/log_performance/performance_times_logging/facter_performance_logs_parser.rb +65 -0
  14. data/acceptance/log_performance/performance_times_logging/google_sheets.rb +133 -0
  15. data/acceptance/log_performance/performance_times_logging/log_performance_times.rb +20 -0
  16. data/acceptance/log_performance/performance_times_logging/table_logging_utils.rb +55 -0
  17. data/acceptance/log_performance/performance_times_logging/write_facter_times_to_logger.rb +109 -0
  18. data/acceptance/log_performance/rspec/file_folder_utils_rspec.rb +12 -0
  19. data/acceptance/log_performance/utils.rb +41 -0
  20. data/acceptance/run/run_statistax.rb +45 -29
  21. data/lib/version.rb +1 -1
  22. data/scripts/benchmark_script.rb +9 -7
  23. metadata +21 -5
  24. data/acceptance/build_facter_ng_gem.sh +0 -1
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 5b94d29cf1132a42f4ae3c91d445eeba5860b65b270a6b4aec8fb3b9829f4ba0
4
- data.tar.gz: ec72d80f143a70e187585b746f34b2e1838b03a9f0cd70ce513f186fbf764997
3
+ metadata.gz: 1ebdaaa85edad0d762e03120c79a30ece47041dcf61287bbd82c2b9ae9635bcb
4
+ data.tar.gz: 8d0b91944694256ad8455e93edcf8b09c464ae0dea51a093611dc8e6021b4fcc
5
5
  SHA512:
6
- metadata.gz: 6b34c28e5b4735a7bcfcb38a83497a851a02d0df1747579a1c00c4a1788b427a90e8ec4a97a00e88e0a62796c37170fcd23a16e03e4d46bcc41d5b5473870a7e
7
- data.tar.gz: 8a2a73a57347090ccd60a9838a0853ac38811364c26117007276e270cb14ad510592c862f4096d29c60644fceb9743216d70228abb23253bf4cb2175f534c473
6
+ metadata.gz: 3dbfe4ce4094370d43301e30b1fbb504dc463fd61f87b09706ce40a85f564e20996a97f3eb953347647c308ea1efaa8bbb241ee47dba7f74bb25be6fffab0304
7
+ data.tar.gz: 3c3b4615a699b39f114ba4e4d29388a0f8511c084ea6878c492dc2c15801433c495e9ae8b8329e7d8dd1754751db4d9340da49f24ee6466d4fd4fec0201c7333
@@ -13,7 +13,7 @@ def location_for(place, fake_version = nil)
13
13
  end
14
14
 
15
15
  gem "beaker", *location_for(ENV['BEAKER_VERSION'] || '~> 4.0')
16
- gem "beaker-puppet", *location_for(ENV['BEAKER_PUPPET_VERSION'] || ["~>1.0", ">= 1.18.4"])
16
+ gem "beaker-puppet", *location_for(ENV['BEAKER_PUPPET_VERSION'] || ["~>1.0", ">= 1.18"])
17
17
  gem "beaker-hostgenerator", *location_for(ENV['BEAKER_HOSTGENERATOR_VERSION'] || "~> 1.1")
18
18
  gem "beaker-abs", *location_for(ENV['BEAKER_ABS_VERSION'] || "~> 0.4")
19
19
  gem "beaker-vagrant", *location_for(ENV['BEAKER_VAGRANT_VERSION'] || "~> 0")
@@ -23,6 +23,7 @@ gem "beaker-docker", *location_for(ENV['BEAKER_DOCKER_VERSION'] || "~> 0.5")
23
23
  gem "rake", "~> 10.1"
24
24
  gem "httparty", :require => false
25
25
  gem 'uuidtools', :require => false
26
+ gem "google-api-client", "~>0.36.4"
26
27
 
27
28
  group(:test) do
28
29
  gem "rspec", "~> 2.14.0", :require => false
@@ -0,0 +1,65 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Configuration
4
+ BEAKER_ENV_VARS = {
5
+ 'GOOGLE_APPLICATION_CREDENTIALS' => '/Users/andrei.filipovici/projects/google-sheets/Facter Performance History-99315759f0c6.json',
6
+ 'IS_GEM' => 'true'
7
+ }
8
+ SPREADSHEET_ID = '1giARlXsBSGhxIWRlThV8QfmybeAfaBrNRzdr9C0pvPw'
9
+ USER_HOME_PATH = '/Users/andrei.filipovici/'
10
+ FACTER_NG_PROJECT_PATH = '/Users/andrei.filipovici/projects/facter-ng-for-statistax'
11
+ STATISTAX_PROJECT_PATH = '/Users/andrei.filipovici/projects/facter-statistax/acceptance/'
12
+ LOGS_FOLDER_PATH = '/Users/andrei.filipovici/projects/facter-statistax/acceptance/cron_logs'
13
+ RUN_FAILS_LOG_NAME = '_run_failures'
14
+ SCRIPT_ERRORS_LOG_NAME = '_script_failures'
15
+ PRE_TESTS_LOG_NAME = '_all'
16
+ VMPOOLERP_PLATFORMS = [
17
+ # 'centos6-32',
18
+ # 'centos6-64',
19
+ # 'debian8-32',
20
+ # 'debian8-64',
21
+ # 'debian9-32',
22
+ # 'debian9-64',
23
+ # 'debian10-64',
24
+ # 'fedora28-64',
25
+ # 'fedora29-64',
26
+ # 'fedora30-64',
27
+ # 'fedora31-64',
28
+ # 'osx1012-64',
29
+ # 'osx1013-64',
30
+ # 'osx1014-64',
31
+ # 'osx1015-64',
32
+ # 'redhat5-64',
33
+ # 'redhat7-64',
34
+ # 'redhatfips7-64',
35
+ # 'redhat8-64',
36
+ # 'sles11-32',
37
+ # 'sles11-64',
38
+ # 'sles12-64',
39
+ # 'sles15-64',
40
+ # 'solaris10-64',
41
+ # 'solaris11-64',
42
+ # 'solaris114-64',
43
+ # 'ubuntu1404-32',
44
+ 'ubuntu1404-64',
45
+ # 'ubuntu1604-32',
46
+ # 'ubuntu1604-64',
47
+ # 'ubuntu1804-64',
48
+ # 'windows2008r2-64',
49
+ # 'windows2012r2-64',
50
+ # 'windowsfips2012r2-64',
51
+ # 'windows2016-64',
52
+ # 'windows2019-64',
53
+ # 'windows10ent-32',
54
+ # 'windows10ent-64',
55
+ ]
56
+ NSPOOLER_PLATFORMS = {
57
+ # "aix61-POWER" => "aix-6.1-power",
58
+ # "aix71-POWER" => "aix-7.1-power",
59
+ # "aix72-POWER" => "aix-7.2-power",
60
+ # "redhat7-POWER" => "redhat-7.3-power8",
61
+ # "redhat7-AARCH64" => "centos-7-arm64",
62
+ # "ubuntu1604-POWER" => "ubuntu-16.04-power8",
63
+ # "sles12-POWER" => "sles-12-power8",
64
+ }
65
+ end
@@ -0,0 +1,5 @@
1
+ class FailedCommand < StandardError
2
+ def message
3
+ "Command failed!"
4
+ end
5
+ end
@@ -0,0 +1,77 @@
1
+ require_relative '../custom_exceptions'
2
+ class Beaker
3
+
4
+ def initialize(platforms, user_home_path, beaker_env_vars, logger)
5
+ @platforms = platforms
6
+ @user_home_path = user_home_path
7
+ @beaker_env_vars = beaker_env_vars
8
+ @logger = logger
9
+ end
10
+
11
+ def run_test_on_all_platforms
12
+ @platforms.each do |platform|
13
+ begin
14
+ @current_platform = platform
15
+ test_sequence
16
+ rescue FailedCommand
17
+ destroy_environment
18
+ next
19
+ end
20
+ end
21
+ end
22
+
23
+ def test_sequence
24
+ time = TimedMethods.get_run_time{
25
+ clean_beaker_home
26
+ create_vm_hosts_file
27
+ config_hosts_options
28
+ provision
29
+ install_agent_facter_statistax
30
+ run_statistax_tests
31
+ destroy_environment
32
+ }
33
+ @logger.log("Runtime was #{time} minutes.", @current_platform)
34
+ end
35
+
36
+ def clean_beaker_home
37
+ # if an error happened and beaker destroy doesn't get called, the .beaker folder remains
38
+ # and it need to be deleted. Otherwise you get an error saying the beaker parameters can't be parsed
39
+ log_run_command("cd #{@user_home_path} && rm -rf .beaker")
40
+ end
41
+
42
+ def create_vm_hosts_file
43
+ log_run_command("beaker-hostgenerator #{@current_platform} > hosts.yaml")
44
+ end
45
+
46
+ def config_hosts_options
47
+ log_run_command('beaker init -h hosts.yaml --options-file config/aio/options.rb', 2)
48
+ end
49
+
50
+ def provision
51
+ log_run_command('bundle exec beaker provision', 10)
52
+ end
53
+
54
+ def install_agent_facter_statistax
55
+ log_run_command('bundle exec beaker exec pre-suite --pre-suite presuite/01_install_puppet_agent.rb,presuite/011_install_facter_ng.rb,presuite/02_install_facter_statistax.rb', 10)
56
+ end
57
+
58
+ def run_statistax_tests
59
+ log_run_command('bundle exec beaker exec run/run_statistax.rb', 10)
60
+ end
61
+
62
+ def destroy_environment
63
+ log_run_command('beaker destroy')
64
+ end
65
+
66
+ def log_run_command(command, timeout_minutes = 1)
67
+ output = RunCommand.run_command(timeout_minutes, @beaker_env_vars, command)
68
+ has_errors, errors = OutputParser.errors?(output)
69
+ @logger.log("Running command: #{command}\n#{output}", @current_platform)
70
+
71
+ return output unless has_errors
72
+
73
+ @logger.log_error("On platform #{@current_platform},
74
+ running command:\n #{command}\ngot error:\n#{errors.join("\n")}")
75
+ raise FailedCommand
76
+ end
77
+ end
@@ -0,0 +1,24 @@
1
+ class CommandLogger
2
+ def initialize(log_folder, error_log_file, log_file = 'log.log')
3
+ @log_folder = log_folder
4
+ @log_file = log_file
5
+ @errors_file = error_log_file
6
+ end
7
+
8
+ def log(data, log_file_name = nil)
9
+ log_file = log_file_name.nil? ? @log_file : log_file_name
10
+ append_to_file(data, log_file)
11
+ end
12
+
13
+ def log_error(data)
14
+ append_to_file(data, @errors_file)
15
+ end
16
+
17
+ private
18
+
19
+ def append_to_file(data, log_file_name)
20
+ File.open("#{@log_folder}/#{log_file_name}.log", mode: 'a') do |file|
21
+ file.write("\n#{data}\n")
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,60 @@
1
+ require_relative 'beaker'
2
+
3
+ class NSPooler < Beaker
4
+ def initialize(platforms, user_home_path, env_vars, logger)
5
+ super(platforms, user_home_path, env_vars, logger)
6
+ end
7
+
8
+ def run_test_on_all_platforms
9
+ @platforms.each do |platform, platform_template|
10
+ begin
11
+ @current_platform = platform
12
+ next unless get_nspooler_vm(platform_template)
13
+
14
+ test_sequence
15
+ rescue FailedCommand
16
+ destroy_environment
17
+ next
18
+ end
19
+ end
20
+ end
21
+
22
+ def create_vm_hosts_file
23
+ log_run_command("beaker-hostgenerator #{get_beaker_platform_name(@current_platform, @nspooler_host_name)} > hosts.yaml")
24
+ end
25
+
26
+ def destroy_environment
27
+ super
28
+ log_run_command("curl -H X-AUTH-TOKEN:VmPoolerAuthToken -X POST -d '' --url https://nspooler-service-prod-1.delivery.puppetlabs.net/api/v1/maint/reset/#{@nspooler_host_name}")
29
+ end
30
+
31
+ private
32
+
33
+ def get_nspooler_vm(platform_template)
34
+ provisioned_vm = make_request_for_vm(platform_template)
35
+ if provisioned_vm['ok'] == true
36
+ @nspooler_host_name = provisioned_vm[platform_template]['hostname']
37
+ true
38
+ else
39
+ @logger.log_error("No VM available for #{@current_platform}")
40
+ false
41
+ end
42
+ end
43
+
44
+ def make_request_for_vm(platform_template)
45
+ get_vm_response = log_run_command("curl --fail --silent --show-error -H X-AUTH-TOKEN:VmPoolerAuthToken -X POST -d '{\"#{platform_template}\":1}' --url https://nspooler-service-prod-1.delivery.puppetlabs.net/api/v1/host/")
46
+ JSON.parse(get_vm_response.gsub('=>', ':'))
47
+ end
48
+
49
+ def get_beaker_platform_name(platform, nsPooler_host_name)
50
+ #because of how packaging for agent is made we need to lie beaker about aix version. If we have a version 7, we need
51
+ # to tell it, it's running on version 6
52
+ beaker_platform = if platform.include?('aix7')
53
+ platform.sub(/aix7[1-2]/, 'aix61')
54
+ else
55
+ platform
56
+ end
57
+ "#{beaker_platform}\\{hypervisor=none\\,hostname=#{nsPooler_host_name}\\}"
58
+ end
59
+ end
60
+
@@ -0,0 +1,40 @@
1
+ require 'set'
2
+
3
+ module OutputParser
4
+ @error_tokens = [
5
+ 'retrying in',
6
+ 'command not found',
7
+ 'invalidurierror',
8
+ 'timed out',
9
+ 'Failed while running the pre_suite suite',
10
+ 'Failed while running the tests suite',
11
+ 'NoMethodError',
12
+ 'ERROR Facter',
13
+ 'ERROR: Gemspec file not found:'
14
+ ]
15
+
16
+ def self.errors?(data)
17
+ errors = extract_errors(data)
18
+ if errors.empty?
19
+ [false, '']
20
+ else
21
+ [true, errors.to_a]
22
+ end
23
+ end
24
+
25
+ private_class_method def self.extract_errors(data)
26
+ # data needs to be encoded because you never know what you get from different vms
27
+ data.encode!('UTF-8', invalid: :replace, undef: :replace)
28
+ errors = Set.new
29
+ @error_tokens.each do |error|
30
+ # Match substring that contains the error token and is between [<time>] and [<time>]
31
+ # used 'i' to ignore case
32
+ data.scan(/[^\[]*#{error}[^\[]*/i) do |entire_error|
33
+ errors << entire_error
34
+ end
35
+ end
36
+ errors
37
+ end
38
+
39
+ end
40
+
@@ -0,0 +1,30 @@
1
+ require 'open3'
2
+ require 'timeout'
3
+
4
+ module RunCommand
5
+ def self.run_command(timeout_in_minutes = 1, env_vars = {}, command)
6
+ @wait_thread = nil
7
+ @output = ''
8
+ begin
9
+ Timeout.timeout(timeout_in_minutes * 60) do
10
+ get_command_output(command, env_vars)
11
+ end
12
+ rescue Timeout::Error
13
+ Process.kill('KILL', @wait_thread) if @wait_thread.alive?
14
+ "Timed out! Did only:\n#{@output}"
15
+ end
16
+ end
17
+
18
+ private_class_method def self.get_command_output(command, env_vars)
19
+ Open3.popen2e(env_vars, command) do |_stdin, stdout_and_stderr, wait_thr|
20
+ @wait_thread = wait_thr
21
+ stdout_and_stderr.each do |line|
22
+ @output << line
23
+ puts line
24
+ end
25
+ end
26
+ @output
27
+ end
28
+
29
+ end
30
+
@@ -0,0 +1,99 @@
1
+ require 'benchmark'
2
+ require 'date'
3
+ require_relative 'vm_pooler'
4
+ require_relative 'ns_pooler'
5
+ require_relative 'run_command'
6
+ require_relative '../configuration'
7
+ require_relative '../utils'
8
+ require_relative 'command_logger'
9
+ require_relative 'output_parser'
10
+ require_relative '../custom_exceptions'
11
+
12
+ class TestAllPlatforms
13
+ def initialize
14
+ @logs_folder = "#{Configuration::LOGS_FOLDER_PATH}/#{DateTime.now.strftime("%d-%m-%Y_%H:%M")}"
15
+ @logger = CommandLogger.new(@logs_folder, Configuration::SCRIPT_ERRORS_LOG_NAME, Configuration::PRE_TESTS_LOG_NAME)
16
+ beaker_logger = CommandLogger.new(@logs_folder, Configuration::RUN_FAILS_LOG_NAME)
17
+ @vmpooler = VMPooler.new(Configuration::VMPOOLERP_PLATFORMS,
18
+ Configuration::USER_HOME_PATH,
19
+ Configuration::BEAKER_ENV_VARS,
20
+ beaker_logger)
21
+ @nspooler = NSPooler.new(Configuration::NSPOOLER_PLATFORMS,
22
+ Configuration::USER_HOME_PATH,
23
+ Configuration::BEAKER_ENV_VARS,
24
+ beaker_logger)
25
+ end
26
+
27
+ def run_tests
28
+ time = TimedMethods.get_run_time {
29
+ prepare_environment
30
+ run_tests_on_vms
31
+ }
32
+ @logger.log("Runtime was #{time} minutes.")
33
+ rescue FailedCommand
34
+ exit
35
+ rescue StandardError => e
36
+ log_script_error(e)
37
+ end
38
+
39
+ private
40
+
41
+ def prepare_environment
42
+ FileFolderUtils.create_directories(@logs_folder)
43
+ clean_workspace
44
+ Configuration::BEAKER_ENV_VARS['SHA'] = get_latest_agent_sha
45
+ get_latest_facter_ng_gem
46
+ end
47
+
48
+ def clean_workspace
49
+ Dir.chdir(Configuration::STATISTAX_PROJECT_PATH) do
50
+ log_run_command('rm *.gem')
51
+ log_run_command('rm puppet-agent*')
52
+ end
53
+ end
54
+
55
+ def get_latest_agent_sha
56
+ log_run_command('curl --fail --silent GET --url http://builds.delivery.puppetlabs.net/passing-agent-SHAs/puppet-agent-master')
57
+ end
58
+
59
+ def get_latest_facter_ng_gem
60
+ Dir.chdir(Configuration::FACTER_NG_PROJECT_PATH) do
61
+ update_facter_ng_master
62
+ log_run_command('gem build facter.gemspec')
63
+ log_run_command("mv *gem #{Configuration::STATISTAX_PROJECT_PATH}")
64
+ end
65
+ end
66
+
67
+ def update_facter_ng_master
68
+ log_run_command('git checkout master')
69
+ log_run_command('git fetch --all')
70
+ log_run_command('git reset --hard origin/master')
71
+ end
72
+
73
+ def run_tests_on_vms
74
+ Dir.chdir(Configuration::STATISTAX_PROJECT_PATH) do
75
+ @vmpooler.run_test_on_all_platforms
76
+ @nspooler.run_test_on_all_platforms
77
+ end
78
+ end
79
+
80
+ def log_run_command(command)
81
+ output = RunCommand.run_command(command)
82
+ has_errors, = OutputParser.errors?(output)
83
+ if has_errors
84
+ @logger.log("Command: #{command} had error:\n#{output}")
85
+ raise FailedCommand
86
+ else
87
+ @logger.log("Running command: #{command}\n#{output}")
88
+ end
89
+ output
90
+ end
91
+
92
+ def log_script_error(e)
93
+ error_message = e.message + "\n" + e.backtrace.inspect.gsub(', ', "\n")
94
+ puts error_message
95
+ @logger.log_error("#{@start_time}\n" + error_message)
96
+ end
97
+ end
98
+
99
+ TestAllPlatforms.new.run_tests
@@ -0,0 +1,7 @@
1
+ require_relative 'beaker'
2
+
3
+ class VMPooler < Beaker
4
+ def initialize(platforms, user_home_path, env_vars, logger)
5
+ super(platforms, user_home_path, env_vars, logger)
6
+ end
7
+ end