cem_acpt 0.6.4 → 0.6.5

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: 52762f33465c435a0c6009002d7915dd249c145210493cd503936e7e816177a2
4
- data.tar.gz: 6b7f8cb35ed65f914269ae0a5179a89f7ca3cc4d0f0d940bfd9a913b0c2cabf2
3
+ metadata.gz: 98336b152de85be1f1d7bfd20cd901da25d728d9ea120fb713becff384986560
4
+ data.tar.gz: ab6e2579bb7df9e58a0c4ed290e40a64a4b1a0c6a6f00894b924694de915e65e
5
5
  SHA512:
6
- metadata.gz: e6e1a5986dda72b212bb344c8b62ddceb5ca8277be3fc392ff6f5dea61981a1666ace99f205a43d7ba63013d4fce0e509ec48819e4a96e9577fa5dbae52c180f
7
- data.tar.gz: 529dbb05eabffe98ee9c7feaa1635858245d4ac20d681451a43d377c04a42f77516371c986c1a5add2c719631e8625dd454471b99fbb1e5270c8ee1d49ce4127
6
+ metadata.gz: 3c353057f6cda43e7b2e2a6eacfba36cdd41c2c78e459f7548b3e3ddd789a1c732e143b008b62f7c4e8fbb11e823a3e69f16a9a810c3c81db86be77e45b4b89e
7
+ data.tar.gz: c2cb83e57613ec0bed0292411e83a99705af80f0d205b699b52dd07ae49814d4adc8d235a9233c65b658d9652686b3dd302f5a1f45d0c19551f8c2811ef62ade
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- cem_acpt (0.6.4)
4
+ cem_acpt (0.6.5)
5
5
  async-http (>= 0.60, < 0.70)
6
6
  bcrypt_pbkdf (>= 1.0, < 2.0)
7
7
  deep_merge (>= 1.2, < 2.0)
@@ -359,6 +359,7 @@ module CemAcpt
359
359
  checksum = File.read(module_terraform_checksum_file).strip
360
360
  return if checksum == module_terraform_checksum
361
361
  end
362
+ FileUtils.rm_rf(File.join(user_config_dir, 'terraform'))
362
363
  FileUtils.cp_r(File.expand_path(File.join(__dir__, '..', 'terraform')), user_config_dir)
363
364
  @module_terraform_checksum = new_module_terraform_checksum
364
365
  File.write(module_terraform_checksum_file, module_terraform_checksum)
@@ -126,9 +126,11 @@ module CemAcpt
126
126
  # Wraps the given block in a Github Actions group if in CI mode
127
127
  # @param name [String] the name of the group
128
128
  def with_ci_group(name)
129
- return yield unless @ci_mode
130
-
131
- self.<< "::group::#{name}\n"
129
+ if @ci_mode
130
+ self.<< "::group::#{name}\n"
131
+ else
132
+ info(name)
133
+ end
132
134
  yield
133
135
  ensure
134
136
  self.<< "::endgroup::\n" if @ci_mode
@@ -14,7 +14,7 @@ module CemAcpt
14
14
  DEFAULT_VARS_FILE = 'testvars.json'
15
15
  include CemAcpt::Logging
16
16
 
17
- attr_reader :environment, :working_dir
17
+ attr_reader :environment, :working_dir, :module_package_path, :private_key, :public_key
18
18
 
19
19
  def initialize(config, provision_data)
20
20
  @config = config
@@ -22,11 +22,14 @@ module CemAcpt
22
22
  @backend = new_backend(@provision_data[:test_data].first[:test_name])
23
23
  @environment = new_environment(@config)
24
24
  @working_dir = nil
25
+ @module_package_path = nil
26
+ @private_key = nil
27
+ @public_key = nil
25
28
  end
26
29
 
27
- def provision
30
+ def provision(reuse_working_dir: false)
28
31
  logger.info('Terraform') { 'Provisioning nodes...' }
29
- @working_dir = new_working_dir
32
+ @working_dir = new_working_dir unless reuse_working_dir
30
33
  validate_working_dir!
31
34
  save_vars_to_file!(formatted_vars) # Easier to reuse nodes this way
32
35
 
@@ -42,6 +45,9 @@ module CemAcpt
42
45
  logger.verbose('Terraform') { "Deleting old working directory #{working_dir}" }
43
46
  FileUtils.rm_rf(working_dir)
44
47
  @working_dir = nil
48
+ @module_package_path = nil
49
+ @private_key = nil
50
+ @public_key = nil
45
51
  end
46
52
 
47
53
  def show
@@ -156,7 +162,18 @@ module CemAcpt
156
162
  FileUtils.cp_r(@backend.provision_directory, work_dir)
157
163
  logger.verbose('Terraform') { "Copied provision directory #{@backend.provision_directory} to #{work_dir}" }
158
164
  FileUtils.cp(@provision_data[:module_package_path], work_dir)
165
+ @module_package_path = File.join(work_dir, File.basename(@provision_data[:module_package_path]))
159
166
  logger.verbose('Terraform') { "Copied module package #{@provision_data[:module_package_path]} to #{work_dir}" }
167
+ if File.exist?(@provision_data[:private_key])
168
+ FileUtils.cp(@provision_data[:private_key], work_dir)
169
+ @private_key = File.join(work_dir, File.basename(@provision_data[:private_key]))
170
+ logger.verbose('Terraform') { "Copied private key #{@provision_data[:private_key]} to #{work_dir}" }
171
+ end
172
+ if File.exist?(@provision_data[:public_key])
173
+ FileUtils.cp(@provision_data[:public_key], work_dir)
174
+ @public_key = File.join(work_dir, File.basename(@provision_data[:public_key]))
175
+ logger.verbose('Terraform') { "Copied public key #{@provision_data[:public_key]} to #{work_dir}" }
176
+ end
160
177
  work_dir
161
178
  rescue StandardError => e
162
179
  logger.error('Terraform') { 'Error creating working directory' }
@@ -204,9 +221,9 @@ module CemAcpt
204
221
  def formatted_vars
205
222
  @provision_data[:nodes].first.platform_data.merge(
206
223
  {
207
- puppet_module_package: @provision_data[:module_package_path],
208
- private_key: @provision_data[:private_key],
209
- public_key: @provision_data[:public_key],
224
+ puppet_module_package: @module_package_path,
225
+ private_key: @private_key,
226
+ public_key: @public_key,
210
227
  node_data: provision_node_data,
211
228
  }
212
229
  )
@@ -39,27 +39,27 @@ module CemAcpt
39
39
  def run
40
40
  @run_data = {}
41
41
  @start_time = Time.now
42
- logger.info('CemAcpt') { "Starting CemAcpt v#{CemAcpt::VERSION}..." }
43
- logger.info('CemAcpt') { "Test suite started at #{@start_time}..." }
44
- logger.info('CemAcpt') { "Using module directory: #{config.get('module_dir')}..." }
45
- Dir.chdir(config.get('module_dir')) do
46
- keep_terminal_alive
47
- @run_data[:private_key], @run_data[:public_key], @run_data[:known_hosts] = new_ephemeral_ssh_keys
48
- logger.info('CemAcpt') { 'Created ephemeral SSH key pair...' }
49
- @run_data[:module_package_path] = build_module_package
50
- logger.info('CemAcpt') { "Created module package: #{@run_data[:module_package_path]}..." }
51
- @run_data[:test_data] = new_test_data
52
- logger.info('CemAcpt') { 'Created test data...' }
53
- logger.verbose('CemAcpt') { "Test data: #{@run_data[:test_data]}" }
54
- @run_data[:nodes] = new_node_data
55
- logger.info('CemAcpt') { 'Created node data...' }
56
- logger.verbose('CemAcpt') { "Node data: #{@run_data[:nodes]}" }
57
- @instance_names_ips = provision_test_nodes
58
- logger.info('CemAcpt') { 'Provisioned test nodes...' }
59
- logger.debug('CemAcpt') { "Instance names and IPs: #{@instance_names_ips}" }
60
- @results = run_tests(@instance_names_ips.map { |_, v| v['ip'] },
61
- config.get('actions.only'),
62
- config.get('actions.except'))
42
+ logger.with_ci_group("CemAcpt v#{CemAcpt::VERSION} run started at #{@start_time}") do
43
+ logger.info('CemAcpt') { "Using module directory: #{config.get('module_dir')}..." }
44
+ Dir.chdir(config.get('module_dir')) do
45
+ keep_terminal_alive
46
+ @run_data[:private_key], @run_data[:public_key], @run_data[:known_hosts] = new_ephemeral_ssh_keys
47
+ logger.info('CemAcpt') { 'Created ephemeral SSH key pair...' }
48
+ @run_data[:module_package_path] = build_module_package
49
+ logger.info('CemAcpt') { "Created module package: #{@run_data[:module_package_path]}..." }
50
+ @run_data[:test_data] = new_test_data
51
+ logger.info('CemAcpt') { 'Created test data...' }
52
+ logger.verbose('CemAcpt') { "Test data: #{@run_data[:test_data]}" }
53
+ @run_data[:nodes] = new_node_data
54
+ logger.info('CemAcpt') { 'Created node data...' }
55
+ logger.verbose('CemAcpt') { "Node data: #{@run_data[:nodes]}" }
56
+ @instance_names_ips = provision_test_nodes
57
+ logger.info('CemAcpt') { 'Provisioned test nodes...' }
58
+ logger.debug('CemAcpt') { "Instance names and IPs: #{@instance_names_ips}" }
59
+ @results = run_tests(@instance_names_ips.map { |_, v| v['ip'] },
60
+ config.get('actions.only'),
61
+ config.get('actions.except'))
62
+ end
63
63
  end
64
64
  ensure
65
65
  clean_up
@@ -105,7 +105,7 @@ module CemAcpt
105
105
  end
106
106
 
107
107
  def clean_ephemeral_ssh_keys
108
- return if config.get('no_ephemeral_ssh_key')
108
+ return if config.get('no_ephemeral_ssh_key') || config.get('no_destroy_nodes')
109
109
 
110
110
  CemAcpt::Utils::SSH::Ephemeral.clean
111
111
  end
@@ -124,13 +124,17 @@ module CemAcpt
124
124
  end
125
125
 
126
126
  def destroy_test_nodes
127
- @provisioner&.destroy if config.get('no_destroy_nodes')
127
+ return no_destroy if config.get('no_destroy_nodes')
128
+
129
+ logger.with_ci_group("CemAcpt v#{CemAcpt::VERSION} run finished at #{Time.now}") { @provisioner&.destroy }
128
130
  end
129
131
 
130
132
  def no_destroy
131
133
  logger.warn('CemAcpt') { 'Not destroying test nodes...' }
132
- @provisioner&.show
133
- logger.info('CemAcpt') { "Test SSH Keys:\n Private Key: #{@run_data[:private_key]}\n Public Key:#{@run_data[:public_key]}" }
134
+ logger.with_ci_group("CemAcpt v#{CemAcpt::VERSION} run finished at #{Time.now}") do
135
+ @provisioner&.show
136
+ logger.info('CemAcpt') { "Test SSH Keys:\n Private Key: #{@run_data[:private_key]}\n Public Key:#{@run_data[:public_key]}" }
137
+ end
134
138
  end
135
139
 
136
140
  def run_tests(hosts, only_actions, except_actions)
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module CemAcpt
4
- VERSION = '0.6.4'
4
+ VERSION = '0.6.5'
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.6.4
4
+ version: 0.6.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - puppetlabs
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2023-04-25 00:00:00.000000000 Z
11
+ date: 2023-04-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: async-http