cem_acpt 0.6.1 → 0.6.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/Gemfile.lock +1 -1
- data/lib/cem_acpt/config.rb +35 -1
- data/lib/cem_acpt/platform/base.rb +3 -1
- data/lib/cem_acpt/platform/gcp.rb +2 -2
- data/lib/cem_acpt/platform.rb +10 -10
- data/lib/cem_acpt/provision/terraform.rb +19 -12
- data/lib/cem_acpt/test_runner.rb +4 -5
- data/lib/cem_acpt/version.rb +1 -1
- data/lib/terraform/gcp/linux/main.tf +3 -3
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1e2aaf3de96bb10c9091d11e8d5e2e9680cd07bd601fa349be1c75db15e7428e
|
4
|
+
data.tar.gz: 3ac23bcddfd8ebd461d437de6b77454a19bf6e72ebd7e1986b76c5601f8e87c2
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8eeb0684612c1df4d7d1087bc411a351906c475b5ad9d32b61221023efc806a4137c74bb926e700cbe21ee36d1d0f5d1dd2915e7f006102ac9b5c872de82d97b
|
7
|
+
data.tar.gz: f7fce1e31b862cabfb19aba1e3ce8c0c32e9e99b80ca892dba64f7cfd711ebf6a64a253470803ce0dac9b65da3af2a7e02d2f8597c552e891e785cc4960fc27e
|
data/Gemfile.lock
CHANGED
data/lib/cem_acpt/config.rb
CHANGED
@@ -1,5 +1,6 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
+
require 'digest'
|
3
4
|
require 'json'
|
4
5
|
require 'yaml'
|
5
6
|
require_relative 'core_extensions'
|
@@ -203,6 +204,14 @@ module CemAcpt
|
|
203
204
|
@terraform_dir ||= File.join(user_config_dir, 'terraform')
|
204
205
|
end
|
205
206
|
|
207
|
+
def module_terraform_checksum_file
|
208
|
+
@module_terraform_checksum_file ||= File.join(user_config_dir, 'terraform_checksum.txt')
|
209
|
+
end
|
210
|
+
|
211
|
+
def module_terraform_checksum
|
212
|
+
@module_terraform_checksum ||= new_module_terraform_checksum
|
213
|
+
end
|
214
|
+
|
206
215
|
def valid_env_var?(env_var)
|
207
216
|
env_var.start_with?('CEM_ACPT_') && ENV[env_var]
|
208
217
|
end
|
@@ -338,8 +347,33 @@ module CemAcpt
|
|
338
347
|
end
|
339
348
|
|
340
349
|
def create_config_dirs!
|
341
|
-
FileUtils.mkdir_p(user_config_dir)
|
350
|
+
FileUtils.mkdir_p(user_config_dir)
|
351
|
+
create_terraform_dir!
|
352
|
+
end
|
353
|
+
|
354
|
+
def create_terraform_dir!
|
355
|
+
raise 'Cannot create terraform dir without a user config dir' unless Dir.exist? user_config_dir
|
356
|
+
|
357
|
+
if File.exist?(module_terraform_checksum_file)
|
358
|
+
checksum = File.read(module_terraform_checksum_file).strip
|
359
|
+
return if checksum == module_terraform_checksum
|
360
|
+
end
|
342
361
|
FileUtils.cp_r(File.expand_path(File.join(__dir__, '..', 'terraform')), user_config_dir)
|
362
|
+
@module_terraform_checksum = new_module_terraform_checksum
|
363
|
+
File.write(module_terraform_checksum_file, module_terraform_checksum)
|
364
|
+
end
|
365
|
+
|
366
|
+
def new_module_terraform_checksum
|
367
|
+
sha256 = Digest::SHA256.new
|
368
|
+
files_and_dirs = Dir.glob(File.join(__dir__, '..', 'terraform', '**', '*'))
|
369
|
+
files_and_dirs.each do |file|
|
370
|
+
sha256 << if File.directory?(file)
|
371
|
+
File.basename(file)
|
372
|
+
else
|
373
|
+
File.read(file)
|
374
|
+
end
|
375
|
+
end
|
376
|
+
sha256.hexdigest
|
343
377
|
end
|
344
378
|
end
|
345
379
|
end
|
@@ -15,12 +15,14 @@ module CemAcpt::Platform
|
|
15
15
|
|
16
16
|
# @param conf [CemAcpt::Config] the config object.
|
17
17
|
# @param single_test_data [Hash] the test data for the current test.
|
18
|
-
|
18
|
+
# @param run_data [Hash] the run data for the current run minus the test data key.
|
19
|
+
def initialize(config, single_test_data, **run_data)
|
19
20
|
raise ArgumentError, 'single_test_data must be a Hash' unless single_test_data.is_a?(Hash)
|
20
21
|
|
21
22
|
@config = config
|
22
23
|
@test_data = single_test_data
|
23
24
|
@node_name = @test_data[:node_name] || random_node_name
|
25
|
+
@run_data = run_data
|
24
26
|
end
|
25
27
|
|
26
28
|
def to_h
|
@@ -54,11 +54,11 @@ module Platform
|
|
54
54
|
end
|
55
55
|
|
56
56
|
def gcp_private_key
|
57
|
-
@gcp_private_key ||= (@
|
57
|
+
@gcp_private_key ||= (@run_data[:private_key] || File.join(Dir.home, '.ssh', 'google_compute_engine'))
|
58
58
|
end
|
59
59
|
|
60
60
|
def gcp_public_key
|
61
|
-
@gcp_public_key ||= (@
|
61
|
+
@gcp_public_key ||= (@run_data[:public_key] || File.join(Dir.home, '.ssh', 'google_compute_engine.pub'))
|
62
62
|
end
|
63
63
|
|
64
64
|
def gcp_machine_type
|
data/lib/cem_acpt/platform.rb
CHANGED
@@ -17,16 +17,16 @@ module CemAcpt::Platform
|
|
17
17
|
# item in the test data.
|
18
18
|
# @param platform [String] the name of the platform
|
19
19
|
# @param config [CemAcpt::Config] the config object
|
20
|
-
# @param
|
21
|
-
def use(platform, config,
|
20
|
+
# @param run_data [Hash] the current run data. Must include a :test_data key
|
21
|
+
def use(platform, config, run_data)
|
22
22
|
raise Error, "Platform #{platform} is not supported" unless platforms.include?(platform)
|
23
|
-
raise Error, '
|
23
|
+
raise Error, 'run_data must be an Hash' unless run_data.is_a?(Hash)
|
24
|
+
raise Error, 'run_data must include a :test_data key' unless run_data.key?(:test_data)
|
25
|
+
raise Error, 'run_data[:test_data] must be an Array' unless run_data[:test_data].is_a?(Array)
|
24
26
|
|
25
|
-
logger.info "Using #{platform} for #{test_data.length} tests..."
|
26
|
-
test_data.each_with_object([]) do |single_test_data, ary|
|
27
|
-
|
28
|
-
#logger.debug("Allocated local port #{local_port} for test #{single_test_data[:test_name]}")
|
29
|
-
ary << new_platform_object(platform, config, single_test_data)
|
27
|
+
logger.info "Using #{platform} for #{run_data[:test_data].length} tests..."
|
28
|
+
run_data[:test_data].dup.each_with_object([]) do |single_test_data, ary|
|
29
|
+
ary << new_platform_object(platform, config, single_test_data, **run_data.except(:test_data))
|
30
30
|
end
|
31
31
|
end
|
32
32
|
|
@@ -62,10 +62,10 @@ module CemAcpt::Platform
|
|
62
62
|
# @param config [CemAcpt::Config] the config object.
|
63
63
|
# @param single_test_data [Hash] the test data for a single test.
|
64
64
|
# @return [CemAcpt::Platform::Base] an initialized platform class.
|
65
|
-
def new_platform_object(platform, config, single_test_data)
|
65
|
+
def new_platform_object(platform, config, single_test_data, **run_data)
|
66
66
|
raise Error, 'single_test_data must be a Hash' unless single_test_data.is_a?(Hash)
|
67
67
|
|
68
|
-
platform_class(platform).new(config, single_test_data)
|
68
|
+
platform_class(platform).new(config, single_test_data, **run_data)
|
69
69
|
end
|
70
70
|
|
71
71
|
# Creates a new platform-specific Class object for the given platform.
|
@@ -134,7 +134,7 @@ module CemAcpt
|
|
134
134
|
end
|
135
135
|
|
136
136
|
def new_working_dir
|
137
|
-
logger.debug('Terraform') {
|
137
|
+
logger.debug('Terraform') { 'Creating new working directory' }
|
138
138
|
base_dir = File.join(@config.get('terraform.dir'), @config.get('platform.name'))
|
139
139
|
logger.verbose('Terraform') { "Base directory defined as #{base_dir}" }
|
140
140
|
@backend.base_provision_directory = base_dir
|
@@ -157,6 +157,7 @@ module CemAcpt
|
|
157
157
|
logger.verbose('Terraform') { "Content of #{working_dir}:\n#{Dir.glob(File.join(working_dir, '*')).join("\n")}" }
|
158
158
|
raise "Terraform working directory #{working_dir} does not exist" unless File.directory?(working_dir)
|
159
159
|
raise "Terraform working directory #{working_dir} does not contain a Terraform file" unless Dir.glob(File.join(working_dir, '*.tf')).any?
|
160
|
+
|
160
161
|
logger.info('Terraform') { "Using working directory: #{working_dir}" }
|
161
162
|
rescue StandardError => e
|
162
163
|
logger.error('Terraform') { 'Error validating working directory' }
|
@@ -165,13 +166,15 @@ module CemAcpt
|
|
165
166
|
|
166
167
|
def provision_node_data
|
167
168
|
node_data = @provision_data[:nodes].each_with_object({}) do |node, h|
|
168
|
-
h[node.node_name] = node.node_data.merge(
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
|
169
|
+
h[node.node_name] = node.node_data.merge(
|
170
|
+
{
|
171
|
+
goss_file: node.test_data[:goss_file],
|
172
|
+
puppet_manifest: node.test_data[:puppet_manifest],
|
173
|
+
provision_dir_source: @backend.provision_directory,
|
174
|
+
provision_dir_dest: @backend.destination_provision_directory,
|
175
|
+
provision_commands: @backend.provision_commands,
|
176
|
+
}
|
177
|
+
)
|
175
178
|
end
|
176
179
|
node_data.to_json
|
177
180
|
rescue StandardError => e
|
@@ -180,10 +183,14 @@ module CemAcpt
|
|
180
183
|
end
|
181
184
|
|
182
185
|
def formatted_vars
|
183
|
-
@provision_data[:nodes].first.platform_data.merge(
|
184
|
-
|
185
|
-
|
186
|
-
|
186
|
+
@provision_data[:nodes].first.platform_data.merge(
|
187
|
+
{
|
188
|
+
puppet_module_package: @provision_data[:module_package_path],
|
189
|
+
private_key: @provision_data[:private_key],
|
190
|
+
public_key: @provision_data[:public_key],
|
191
|
+
node_data: provision_node_data,
|
192
|
+
}
|
193
|
+
)
|
187
194
|
rescue StandardError => e
|
188
195
|
logger.error('Terraform') { 'Error creating formatted vars' }
|
189
196
|
raise e
|
data/lib/cem_acpt/test_runner.rb
CHANGED
@@ -44,7 +44,7 @@ module CemAcpt
|
|
44
44
|
logger.info('CemAcpt') { "Using module directory: #{config.get('module_dir')}..." }
|
45
45
|
Dir.chdir(config.get('module_dir')) do
|
46
46
|
keep_terminal_alive
|
47
|
-
@run_data[:
|
47
|
+
@run_data[:private_key], @run_data[:public_key], @run_data[:known_hosts] = new_ephemeral_ssh_keys
|
48
48
|
logger.info('CemAcpt') { 'Created ephemeral SSH key pair...' }
|
49
49
|
@run_data[:module_package_path] = build_module_package
|
50
50
|
logger.info('CemAcpt') { "Created module package: #{@run_data[:module_package_path]}..." }
|
@@ -67,9 +67,8 @@ module CemAcpt
|
|
67
67
|
end
|
68
68
|
|
69
69
|
def clean_up(trap_context = false)
|
70
|
-
unless trap_context
|
71
|
-
|
72
|
-
end
|
70
|
+
kill_keep_terminal_alive unless trap_context
|
71
|
+
|
73
72
|
clean_ephemeral_ssh_keys
|
74
73
|
destroy_test_nodes
|
75
74
|
end
|
@@ -114,7 +113,7 @@ module CemAcpt
|
|
114
113
|
end
|
115
114
|
|
116
115
|
def new_node_data
|
117
|
-
CemAcpt::Platform.use(config.get('platform.name'), config, @run_data
|
116
|
+
CemAcpt::Platform.use(config.get('platform.name'), config, @run_data)
|
118
117
|
end
|
119
118
|
|
120
119
|
def provision_test_nodes
|
data/lib/cem_acpt/version.rb
CHANGED
@@ -173,9 +173,9 @@ resource "google_compute_instance" "acpt-test-node" {
|
|
173
173
|
}
|
174
174
|
|
175
175
|
metadata = {
|
176
|
-
oslogin = "
|
177
|
-
ssh-keys = "${var.username}:${file(var.public_key)}"
|
178
|
-
cem-acpt-test = each.value.test_name
|
176
|
+
"enable-oslogin" = "FALSE"
|
177
|
+
"ssh-keys" = "${var.username}:${file(var.public_key)}"
|
178
|
+
"cem-acpt-test" = each.value.test_name
|
179
179
|
}
|
180
180
|
|
181
181
|
tags = [ "cem-acpt-test-node" ]
|
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
|
+
version: 0.6.2
|
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-
|
11
|
+
date: 2023-04-24 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: async-http
|