cem_acpt 0.3.7-universal-java-17 → 0.4.1-universal-java-17

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 024fe8552168e6308e04edd5b2b3509f9b0249b140e1bbb42279eb0ad5095a3f
4
- data.tar.gz: bd8da637c1179eec3ccb906e476996a5cc9f4f61194c81bbc378dcaed9e9fd14
3
+ metadata.gz: 55f2c9e1e9aa4fffc50e388e4a26b24f2d854e4f3bf6a6117b2e9d0fe90639da
4
+ data.tar.gz: f0f405849e4cec9cd02a1ae33a2e3248718531e0651b46b5e370de3eda3f597b
5
5
  SHA512:
6
- metadata.gz: bef27a028ae54ef8aef9860bc2c59b71397f537cd5ece28a69443c9e6351f79b93986b6d24f57c3587adff5eccb7acc7a7d1c91c12842e8df7b18ae8f838c377
7
- data.tar.gz: 417ca629dc9f5e1dc6c6df84c9f27a8e574d2350d96fa0887fcb33cd9bd349bb9536767a3a67db6ac99bab8ffe6428bb91e72d1cbd6713b83835381422032cdf
6
+ metadata.gz: a0c7428a5456f4c077fada428a99feeaa56c226f1e6b15b00e0f5e5cc96622fbf37a94e5d188f7bccfd959935c85c8354db0a6216dac6a95a1fc0384c7fc41ae
7
+ data.tar.gz: 1e695e81427ebf83324a3885ef17b233892a3f247ae8ee039a0255120aebe19aeb0087bc38df6d867a349f1126ae2d10792c4ee003d6966f8dabaa32ae5abd84
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- cem_acpt (0.3.7-universal-java-17)
4
+ cem_acpt (0.4.1-universal-java-17)
5
5
  concurrent-ruby (>= 1.1, < 2.0)
6
6
  deep_merge (>= 1.2, < 2.0)
7
7
  ed25519 (>= 1.2, < 2.0)
@@ -37,6 +37,9 @@ module CemAcpt
37
37
  def new_test_ssh_key
38
38
  log('Creating ephemeral SSH key and known hosts file for acceptance test suites...')
39
39
  @ssh_priv_key, @ssh_pub_key, @ssh_known_hosts = CemAcpt::Utils::SSH::Ephemeral.create
40
+ unless @ssh_priv_key && @ssh_pub_key && @ssh_known_hosts
41
+ log('Did not create ephemeral SSH key and known hosts file for acceptance test suites. Environment variable CEM_ACPT_TEST_SSH_KEY is set.', :warn)
42
+ end
40
43
  log('Successfully created SSH files.')
41
44
  log("SSH private key: #{@ssh_priv_key}", :debug)
42
45
  log("SSH public key: #{@ssh_pub_key}", :debug)
@@ -69,11 +69,11 @@ module CemAcpt
69
69
 
70
70
  class GithubActionFormatter < FileFormatter
71
71
  SEV_MAP = {
72
- 'DEBUG' => '::debug',
73
- 'INFO' => '::notice',
74
- 'WARN' => '::warning',
75
- 'ERROR' => '::error',
76
- 'FATAL' => '::error',
72
+ 'DEBUG' => '::debug::',
73
+ 'INFO' => '::notice::',
74
+ 'WARN' => '::warning::',
75
+ 'ERROR' => '::error::',
76
+ 'FATAL' => '::error::',
77
77
  }.freeze
78
78
 
79
79
  def initialize
@@ -84,11 +84,7 @@ module CemAcpt
84
84
  private
85
85
 
86
86
  def format(severity, _datetime, _progname, msg)
87
- if severity == 'DEBUG'
88
- "#{SEV_MAP[severity]}::{#{msg}}\n"
89
- else
90
- "#{SEV_MAP[severity]} #{msg}\n"
91
- end
87
+ "#{SEV_MAP[severity]}#{msg}\n"
92
88
  end
93
89
  end
94
90
  end
@@ -7,17 +7,17 @@ module CemAcpt
7
7
  # Logging for CemAcpt
8
8
  module Logging
9
9
  LEVEL_MAP = {
10
- 'debug' => Logger::DEBUG,
11
- 'info' => Logger::INFO,
12
- 'warn' => Logger::WARN,
13
- 'error' => Logger::ERROR,
14
- 'fatal' => Logger::FATAL,
15
- 'unknown' => Logger::UNKNOWN,
10
+ 'debug' => ::Logger::DEBUG,
11
+ 'info' => ::Logger::INFO,
12
+ 'warn' => ::Logger::WARN,
13
+ 'error' => ::Logger::ERROR,
14
+ 'fatal' => ::Logger::FATAL,
15
+ 'unknown' => ::Logger::UNKNOWN,
16
16
  }
17
17
 
18
18
  # Delegator class for when you want to log to multiple devices
19
19
  # at the same time, such as STDOUT and a file.
20
- # @param loggers [::Logger] one or more instances of Logger
20
+ # @param loggers [Logger] one or more instances of CemAcpt::Logging::Logger
21
21
  class MultiLogger
22
22
  def initialize(*loggers)
23
23
  @loggers = loggers
@@ -36,6 +36,58 @@ module CemAcpt
36
36
  end
37
37
  end
38
38
 
39
+ # Delagator class for the standard Ruby Logger class.
40
+ # This class is used to ensure the Github Actions formatter
41
+ # correctly formats the log output when using the standard
42
+ # Ruby Logger class methods such as #info, #debug, etc.
43
+ class Logger < ::Logger
44
+ def initialize(logdev, shift_age = 0, shift_size = 1_048_576, **kwargs)
45
+ super(logdev, shift_age, shift_size, **kwargs)
46
+ if kwargs[:formatter].is_a?(Formatter::GithubActionFormatter) || ENV['GITHUB_ACTIONS'] || ENV['CI']
47
+ @ci_mode = true
48
+ end
49
+ end
50
+
51
+ def debug(progname = nil, &block)
52
+ unless log_ci_mode('debug', progname, &block)
53
+ super
54
+ end
55
+ end
56
+
57
+ def info(progname = nil, &block)
58
+ unless log_ci_mode('info', progname, &block)
59
+ super
60
+ end
61
+ end
62
+
63
+ def warn(progname = nil, &block)
64
+ unless log_ci_mode('warn', progname, &block)
65
+ super
66
+ end
67
+ end
68
+
69
+ def error(progname = nil, &block)
70
+ unless log_ci_mode('error', progname, &block)
71
+ super
72
+ end
73
+ end
74
+
75
+ def fatal(progname = nil, &block)
76
+ unless log_ci_mode('fatal', progname, &block)
77
+ super
78
+ end
79
+ end
80
+
81
+ private
82
+
83
+ def log_ci_mode(severity, progname = nil, &block)
84
+ return false unless @ci_mode
85
+
86
+ self.<<("::#{severity}::#{progname || (block && block.call) || ''}\n")
87
+ true
88
+ end
89
+ end
90
+
39
91
  class << self
40
92
  def new_logger(*logdevs, **configs)
41
93
  new_configs = current_log_config.merge(configs.reject { |_, v| v.nil? })
@@ -106,7 +158,7 @@ module CemAcpt
106
158
  logdev: $stdout,
107
159
  shift_age: 'o',
108
160
  shift_size: 1_048_576,
109
- level: Logger::INFO,
161
+ level: ::Logger::INFO,
110
162
  progname: 'CemAcpt',
111
163
  datetime_format: '%Y%m%dT%H%M%S%z',
112
164
  formatter: formatter,
@@ -67,7 +67,9 @@ module CemAcpt::Platform::Gcp
67
67
  def ssh_key
68
68
  return @ssh_key unless @ssh_key.nil?
69
69
 
70
- if File.exist?(File.join([ENV['HOME'], '.ssh', 'acpt_test_key']))
70
+ if CemAcpt::Platform::Utils::Linux::SSHelper.env_ssh_pri_key?
71
+ @ssh_key = CemAcpt::Platform::Utils::Linux::SSHelper.env_ssh_pri_key
72
+ elsif File.exist?(File.join([ENV['HOME'], '.ssh', 'acpt_test_key']))
71
73
  @ssh_key = File.join([ENV['HOME'], '.ssh', 'acpt_test_key'])
72
74
  else
73
75
  logger.debug("Test SSH key not found at #{File.join([ENV['HOME'], '.ssh', 'acpt_test_key'])}, using default")
@@ -117,13 +119,14 @@ module CemAcpt::Platform::Gcp
117
119
  CemAcpt::Platform::Utils::Linux::SSHelper.remove_known_host(vm_alias(instance_name), kh_file)
118
120
  end
119
121
  local_exec("compute instances delete #{instance_name} --quiet")
120
- rescue StandardError
121
- # Ignore errors when deleting instances.
122
+ rescue StandardError => e
123
+ # Just debug logging, otherwise ignore
124
+ logger.debug("Failed to delete known host for #{instance_name}, alias #{vm_alias(instance_name)}: #{e.message}")
122
125
  end
123
126
 
124
127
  # Returns a Hash describing a GCP VM instance.
125
128
  def vm_describe(instance_name, out_format: 'json', out_filter: nil)
126
- local_exec("compute instances describe #{instance_name}", out_format: out_format, out_filter: out_filter)
129
+ @vm_describe ||= local_exec("compute instances describe #{instance_name}", out_format: out_format, out_filter: out_filter)
127
130
  end
128
131
 
129
132
  # This function runs the specified command as the currently authenticated user
@@ -312,7 +315,17 @@ module CemAcpt::Platform::Gcp
312
315
  end
313
316
 
314
317
  def gcloud_ssh(instance_name, command, ignore_command_errors: false)
315
- local_exec("compute ssh --ssh-key-file #{ssh_key} --tunnel-through-iap #{instance_name} --command='#{command}'")
318
+ cmd = [
319
+ 'compute',
320
+ 'ssh',
321
+ '--ssh-key-file',
322
+ ssh_key,
323
+ '--tunnel-through-iap',
324
+ "--ssh-flag='-o UserKnownHostsFile=#{ssh_opts[:user_known_hosts_file]}'",
325
+ instance_name,
326
+ "--command='#{command}'",
327
+ ].join(' ')
328
+ local_exec(cmd)
316
329
  rescue StandardError => e
317
330
  raise e unless ignore_command_errors
318
331
  end
@@ -322,16 +335,21 @@ module CemAcpt::Platform::Gcp
322
335
  end
323
336
 
324
337
  def ssh_all_known_hosts
325
- [
338
+ kh = [
326
339
  File.join(ENV['HOME'], '.ssh', 'acpt_test_known_hosts'),
327
340
  File.join(ENV['HOME'], '.ssh', 'known_hosts'),
328
341
  File.join(ENV['HOME'], '.ssh', 'google_compute_known_hosts'),
329
342
  ]
343
+ if CemAcpt::Platform::Utils::Linux::SSHelper.env_ssh_known_hosts?
344
+ # Env var takes precedence
345
+ kh.unshift(CemAcpt::Platform::Utils::Linux::SSHelper.env_ssh_known_hosts)
346
+ end
347
+ kh
330
348
  end
331
349
 
332
350
  # Default options for Net::SSH
333
351
  def default_ssh_opts
334
- {
352
+ dopts = {
335
353
  auth_methods: ['publickey'],
336
354
  check_host_ip: false,
337
355
  compression: true,
@@ -342,9 +360,14 @@ module CemAcpt::Platform::Gcp
342
360
  non_interactive: true,
343
361
  port: 22,
344
362
  user: user_name,
345
- user_known_hosts_file: File.join(ENV['HOME'], '.ssh', 'acpt_test_known_hosts'),
346
363
  verify_host_key: :never,
347
364
  }
365
+ if CemAcpt::Platform::Utils::Linux::SSHelper.env_ssh_known_hosts?
366
+ dopts[:user_known_hosts_file] = CemAcpt::Platform::Utils::Linux::SSHelper.env_ssh_known_hosts
367
+ else
368
+ dopts[:user_known_hosts_file] = ssh_all_known_hosts.find { |f| File.exist?(File.expand_path(f)) unless f.nil? }
369
+ end
370
+ dopts
348
371
  end
349
372
 
350
373
  # Returns a Proxy::Command object to use for the SSH option ProxyCommand.
@@ -248,7 +248,8 @@ module CemAcpt::Platform::Gcp
248
248
  end
249
249
  @cmd.local_exec(create_cmd)
250
250
  rescue StandardError => e
251
- raise "Failed to create VM #{name} with command #{create_cmd}: #{e}"
251
+ logger.error("Failed to create VM #{name} with command #{create_cmd}: #{e}")
252
+ raise e
252
253
  end
253
254
 
254
255
  def ready?
@@ -6,6 +6,40 @@ module CemAcpt
6
6
  module Linux
7
7
  # Module provides SSH helper methods for Linux platforms
8
8
  class SSHelper
9
+ def self.env_ssh_pri_key
10
+ return unless ENV['CEM_ACPT_SSH_PRI_KEY']
11
+
12
+ File.expand_path(ENV['CEM_ACPT_SSH_PRI_KEY'])
13
+ end
14
+
15
+ def self.env_ssh_pri_key?
16
+ return false unless env_ssh_pri_key
17
+
18
+ File.exist?(env_ssh_pri_key)
19
+ end
20
+
21
+ def self.env_ssh_pub_key
22
+ "#{env_ssh_pri_key}.pub" if env_ssh_pri_key
23
+ end
24
+
25
+ def self.env_ssh_pub_key?
26
+ return false unless env_ssh_pub_key
27
+
28
+ File.exist?(env_ssh_pub_key)
29
+ end
30
+
31
+ def self.env_ssh_known_hosts
32
+ return unless ENV['CEM_ACPT_SSH_KNOWN_HOSTS']
33
+
34
+ File.expand_path(ENV['CEM_ACPT_SSH_KNOWN_HOSTS'])
35
+ end
36
+
37
+ def self.env_ssh_known_hosts?
38
+ return false unless env_ssh_known_hosts
39
+
40
+ File.exist?(env_ssh_known_hosts)
41
+ end
42
+
9
43
  def self.ssh_keygen?
10
44
  system('command -v ssh-keygen 2>&1 > /dev/null')
11
45
  end
@@ -133,7 +133,18 @@ module CemAcpt
133
133
  def handle_runner_error_results(runner)
134
134
  @logger.error("SUMMARY: Encountered an error with test #{runner.node.test_data[:test_name]} on node #{runner.node.node_name}", no_prefix: true)
135
135
  runner.run_result.to_h.each do |k, v|
136
- @logger.error("#{k.upcase}: #{v}", no_prefix: true)
136
+ if k == 'standard_error'
137
+ msg = v['message']
138
+ backtrace = v['backtrace']
139
+ @logger.error("#{k.upcase}: #{msg}", no_prefix: true) unless msg.nil?
140
+ @logger.error("BACKTRACE:\n#{backtrace.join("\n")}", no_prefix: true) unless backtrace.nil?
141
+ elsif v.is_a?(Hash)
142
+ v.each do |k2, v2|
143
+ @logger.error("#{k.upcase}: #{k2.upcase}: #{v2}", no_prefix: true)
144
+ end
145
+ else
146
+ @logger.error("#{k.upcase}: #{v}", no_prefix: true)
147
+ end
137
148
  end
138
149
  end
139
150
 
@@ -97,12 +97,16 @@ module CemAcpt
97
97
  end
98
98
 
99
99
  def self.create(keydir: CemAcpt::Utils::SSH.default_keydir)
100
+ return [false, false, false] if ENV['CEM_ACPT_TEST_SSH_KEY'] # Don't create ephemeral keys if this is set
101
+
100
102
  self.ephemeral_keydir = keydir
101
103
  @priv_key, @pub_key, @known_hosts = CemAcpt::Utils::SSH.create(PRIV_KEY, keydir: ephemeral_keydir, **CREATE_OPTS)
102
104
  [@priv_key, @pub_key, @known_hosts]
103
105
  end
104
106
 
105
107
  def self.clean
108
+ return if ENV['CEM_ACPT_TEST_SSH_KEY']
109
+
106
110
  [@priv_key, @pub_key, @known_hosts].each_with_object([]) do |f, arr|
107
111
  next unless f
108
112
 
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module CemAcpt
4
- VERSION = '0.3.7'
4
+ VERSION = '0.4.1'
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cem_acpt
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.7
4
+ version: 0.4.1
5
5
  platform: universal-java-17
6
6
  authors:
7
7
  - puppetlabs
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2023-03-15 00:00:00.000000000 Z
11
+ date: 2023-03-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  requirement: !ruby/object:Gem::Requirement