cem_acpt 0.6.0 → 0.6.2

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: 4936d14749b4fc458a1eb938299c091e45c28c69a838efe947edb1510a10f151
4
- data.tar.gz: 52b205f0be2bffa478a474c50bd0686e4ba32f2cec69d710b2a89ecde94c45c3
3
+ metadata.gz: 1e2aaf3de96bb10c9091d11e8d5e2e9680cd07bd601fa349be1c75db15e7428e
4
+ data.tar.gz: 3ac23bcddfd8ebd461d437de6b77454a19bf6e72ebd7e1986b76c5601f8e87c2
5
5
  SHA512:
6
- metadata.gz: 96d81ee34960856f0accf22efec6aa3a12f34abf6b9137c43f886102d8a210eca2e907ff2cd2d0d01f6ce37026f9bf6b70c1ba07fd495ff3ad247ae6c3f713fb
7
- data.tar.gz: 46a2f685ede232a010f26e8968666011c8ddfdf690f26df1fc11d3aa3e062d021db56df42854964a8b114b2a2d046127c47dba9b1f87334dd18160aeb2ff7367
6
+ metadata.gz: 8eeb0684612c1df4d7d1087bc411a351906c475b5ad9d32b61221023efc806a4137c74bb926e700cbe21ee36d1d0f5d1dd2915e7f006102ac9b5c872de82d97b
7
+ data.tar.gz: f7fce1e31b862cabfb19aba1e3ce8c0c32e9e99b80ca892dba64f7cfd711ebf6a64a253470803ce0dac9b65da3af2a7e02d2f8597c552e891e785cc4960fc27e
@@ -15,14 +15,22 @@ jobs:
15
15
  tests:
16
16
  name: RSpec tests
17
17
  runs-on: ubuntu-20.04
18
+ strategy:
19
+ matrix:
20
+ ruby:
21
+ - 2.7
22
+ - 3.2
18
23
  steps:
19
24
  - name: Checkout Source
20
25
  uses: actions/checkout@v3
21
26
 
27
+ - name: Delete Gemfile.lock
28
+ run: rm -f Gemfile.lock
29
+
22
30
  - name: Set up Ruby
23
31
  uses: ruby/setup-ruby@v1
24
32
  with:
25
- ruby-version: 3.2
33
+ ruby-version: ${{ matrix.ruby }}
26
34
  bundler-cache: true
27
35
 
28
36
  - name: Run RSpec
data/Gemfile.lock CHANGED
@@ -1,17 +1,13 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- cem_acpt (0.6.0)
4
+ cem_acpt (0.6.2)
5
5
  async-http (>= 0.60, < 0.70)
6
6
  bcrypt_pbkdf (>= 1.0, < 2.0)
7
- concurrent-ruby (>= 1.1, < 2.0)
8
7
  deep_merge (>= 1.2, < 2.0)
9
8
  ed25519 (>= 1.2, < 2.0)
10
- net-ssh (>= 7.1, < 7.2)
11
- parallel (~> 1.22)
12
9
  puppet-modulebuilder (>= 0.0.1)
13
10
  ruby-terraform (~> 1.7)
14
- serverspec (~> 2.42)
15
11
 
16
12
  GEM
17
13
  remote: https://rubygems.org/
@@ -52,11 +48,6 @@ GEM
52
48
  open4 (~> 1.3)
53
49
  method_source (1.0.0)
54
50
  minitar (0.9)
55
- multi_json (1.15.0)
56
- net-scp (4.0.0)
57
- net-ssh (>= 2.6.5, < 8.0.0)
58
- net-ssh (7.1.0)
59
- net-telnet (0.1.1)
60
51
  open4 (1.3.4)
61
52
  parallel (1.22.1)
62
53
  parser (3.2.1.1)
@@ -88,9 +79,6 @@ GEM
88
79
  rspec-expectations (3.12.2)
89
80
  diff-lcs (>= 1.2.0, < 2.0)
90
81
  rspec-support (~> 3.12.0)
91
- rspec-its (1.3.0)
92
- rspec-core (>= 3.0.0)
93
- rspec-expectations (>= 3.0.0)
94
82
  rspec-mocks (3.12.4)
95
83
  diff-lcs (>= 1.2.0, < 2.0)
96
84
  rspec-support (~> 3.12.0)
@@ -111,17 +99,6 @@ GEM
111
99
  ruby-terraform (1.7.0)
112
100
  immutable-struct (~> 2.4)
113
101
  lino (~> 3.0)
114
- serverspec (2.42.2)
115
- multi_json
116
- rspec (~> 3.0)
117
- rspec-its
118
- specinfra (~> 2.72)
119
- sfl (2.3)
120
- specinfra (2.85.0)
121
- net-scp
122
- net-ssh (>= 2.7)
123
- net-telnet (= 0.1.1)
124
- sfl
125
102
  timers (4.3.5)
126
103
  traces (0.9.1)
127
104
  unicode-display_width (2.4.2)
data/cem_acpt.gemspec CHANGED
@@ -26,17 +26,13 @@ Gem::Specification.new do |spec|
26
26
  spec.bindir = 'exe'
27
27
  spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
28
28
  spec.require_paths = ['lib']
29
- #spec.platform = Gem::Platform.local
29
+ # spec.platform = Gem::Platform.local
30
30
  spec.add_runtime_dependency 'async-http', '>= 0.60', '< 0.70'
31
- spec.add_runtime_dependency 'concurrent-ruby', '>= 1.1', '< 2.0'
31
+ spec.add_runtime_dependency 'bcrypt_pbkdf', '>= 1.0', '< 2.0'
32
32
  spec.add_runtime_dependency 'deep_merge', '>= 1.2', '< 2.0'
33
33
  spec.add_runtime_dependency 'ed25519', '>= 1.2', '< 2.0'
34
- spec.add_runtime_dependency 'bcrypt_pbkdf', '>= 1.0', '< 2.0'
35
- spec.add_runtime_dependency 'net-ssh', '>= 7.1', '< 7.2'
36
- spec.add_runtime_dependency 'parallel', '~> 1.22'
37
34
  spec.add_runtime_dependency 'puppet-modulebuilder', '>= 0.0.1'
38
35
  spec.add_runtime_dependency 'ruby-terraform', '~> 1.7'
39
- spec.add_runtime_dependency 'serverspec', '~> 2.42'
40
36
  spec.add_development_dependency 'pry'
41
37
  spec.add_development_dependency 'rubocop'
42
38
  end
@@ -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'
@@ -118,10 +119,6 @@ module CemAcpt
118
119
  end
119
120
  alias to_h config
120
121
 
121
- def user_config_dir
122
- @user_config_dir ||= @config.dget('user_config.dir')
123
- end
124
-
125
122
  def explain
126
123
  explanation = {}
127
124
  %i[defaults env_vars user_config config_from_file options].each do |source|
@@ -207,6 +204,14 @@ module CemAcpt
207
204
  @terraform_dir ||= File.join(user_config_dir, 'terraform')
208
205
  end
209
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
+
210
215
  def valid_env_var?(env_var)
211
216
  env_var.start_with?('CEM_ACPT_') && ENV[env_var]
212
217
  end
@@ -297,6 +302,7 @@ module CemAcpt
297
302
 
298
303
  conf_file = find_option('config_file')
299
304
  return {} if conf_file.nil? || conf_file.empty?
305
+
300
306
  unless conf_file
301
307
  warn "Invalid config_file type '#{conf_file.class}'. Must be a String."
302
308
  return {}
@@ -321,11 +327,19 @@ module CemAcpt
321
327
  def load_config_file(config_file)
322
328
  return {} if config_file.nil? || config_file.empty? || !File.exist?(File.expand_path(config_file))
323
329
 
324
- loaded = YAML.safe_load_file(File.expand_path(config_file), permitted_classes: [Regexp])
330
+ loaded = load_yaml(config_file)
325
331
  loaded.format!
326
332
  loaded
327
333
  end
328
334
 
335
+ def load_yaml(config_file)
336
+ if YAML.respond_to?(:safe_load_file) # Ruby 3.0+
337
+ YAML.safe_load_file(File.expand_path(config_file), permitted_classes: [Regexp])
338
+ else
339
+ YAML.safe_load(File.read(File.expand_path(config_file)), permitted_classes: [Regexp])
340
+ end
341
+ end
342
+
329
343
  def validate_config!
330
344
  @config.each do |key, _value|
331
345
  warn "Unknown config key: #{key}" unless KEYS.include?(key)
@@ -333,8 +347,33 @@ module CemAcpt
333
347
  end
334
348
 
335
349
  def create_config_dirs!
336
- FileUtils.mkdir_p(user_config_dir) unless Dir.exist?(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
337
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
338
377
  end
339
378
  end
340
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
- def initialize(config, single_test_data)
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 ||= (@test_data[:private_key] || File.join(Dir.home, '.ssh', 'google_compute_engine'))
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 ||= (@test_data[:public_key] || File.join(Dir.home, '.ssh', 'google_compute_engine.pub'))
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
@@ -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 test_data [Hash] the test data
21
- def use(platform, config, test_data)
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, 'test_data must be an Array' unless test_data.is_a?(Array)
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
- #local_port = local_port_allocator.allocate
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') { "Creating new working directory" }
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
- goss_file: node.test_data[:goss_file],
170
- puppet_manifest: node.test_data[:puppet_manifest],
171
- provision_dir_source: @backend.provision_directory,
172
- provision_dir_dest: @backend.destination_provision_directory,
173
- provision_commands: @backend.provision_commands,
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
- puppet_module_package: @provision_data[:module_package_path],
185
- node_data: provision_node_data,
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
@@ -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[:priv_key], @run_data[:pub_key], @run_data[:known_hosts] = new_ephemeral_ssh_keys
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
- kill_keep_terminal_alive
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[:test_data])
116
+ CemAcpt::Platform.use(config.get('platform.name'), config, @run_data)
118
117
  end
119
118
 
120
119
  def provision_test_nodes
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module CemAcpt
4
- VERSION = '0.6.0'
4
+ VERSION = '0.6.2'
5
5
  end
data/lib/cem_acpt.rb CHANGED
@@ -1,11 +1,11 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require_relative 'cem_acpt/config'
4
- require_relative 'cem_acpt/logging'
5
- require_relative 'cem_acpt/test_runner'
6
- require_relative 'cem_acpt/version'
7
-
8
3
  module CemAcpt
4
+ require_relative 'cem_acpt/config'
5
+ require_relative 'cem_acpt/logging'
6
+ require_relative 'cem_acpt/test_runner'
7
+ require_relative 'cem_acpt/version'
8
+
9
9
  class << self
10
10
  include CemAcpt::Logging
11
11
 
@@ -173,9 +173,9 @@ resource "google_compute_instance" "acpt-test-node" {
173
173
  }
174
174
 
175
175
  metadata = {
176
- oslogin = "TRUE"
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.0
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-20 00:00:00.000000000 Z
11
+ date: 2023-04-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: async-http
@@ -31,12 +31,12 @@ dependencies:
31
31
  - !ruby/object:Gem::Version
32
32
  version: '0.70'
33
33
  - !ruby/object:Gem::Dependency
34
- name: concurrent-ruby
34
+ name: bcrypt_pbkdf
35
35
  requirement: !ruby/object:Gem::Requirement
36
36
  requirements:
37
37
  - - ">="
38
38
  - !ruby/object:Gem::Version
39
- version: '1.1'
39
+ version: '1.0'
40
40
  - - "<"
41
41
  - !ruby/object:Gem::Version
42
42
  version: '2.0'
@@ -46,7 +46,7 @@ dependencies:
46
46
  requirements:
47
47
  - - ">="
48
48
  - !ruby/object:Gem::Version
49
- version: '1.1'
49
+ version: '1.0'
50
50
  - - "<"
51
51
  - !ruby/object:Gem::Version
52
52
  version: '2.0'
@@ -90,60 +90,6 @@ dependencies:
90
90
  - - "<"
91
91
  - !ruby/object:Gem::Version
92
92
  version: '2.0'
93
- - !ruby/object:Gem::Dependency
94
- name: bcrypt_pbkdf
95
- requirement: !ruby/object:Gem::Requirement
96
- requirements:
97
- - - ">="
98
- - !ruby/object:Gem::Version
99
- version: '1.0'
100
- - - "<"
101
- - !ruby/object:Gem::Version
102
- version: '2.0'
103
- type: :runtime
104
- prerelease: false
105
- version_requirements: !ruby/object:Gem::Requirement
106
- requirements:
107
- - - ">="
108
- - !ruby/object:Gem::Version
109
- version: '1.0'
110
- - - "<"
111
- - !ruby/object:Gem::Version
112
- version: '2.0'
113
- - !ruby/object:Gem::Dependency
114
- name: net-ssh
115
- requirement: !ruby/object:Gem::Requirement
116
- requirements:
117
- - - ">="
118
- - !ruby/object:Gem::Version
119
- version: '7.1'
120
- - - "<"
121
- - !ruby/object:Gem::Version
122
- version: '7.2'
123
- type: :runtime
124
- prerelease: false
125
- version_requirements: !ruby/object:Gem::Requirement
126
- requirements:
127
- - - ">="
128
- - !ruby/object:Gem::Version
129
- version: '7.1'
130
- - - "<"
131
- - !ruby/object:Gem::Version
132
- version: '7.2'
133
- - !ruby/object:Gem::Dependency
134
- name: parallel
135
- requirement: !ruby/object:Gem::Requirement
136
- requirements:
137
- - - "~>"
138
- - !ruby/object:Gem::Version
139
- version: '1.22'
140
- type: :runtime
141
- prerelease: false
142
- version_requirements: !ruby/object:Gem::Requirement
143
- requirements:
144
- - - "~>"
145
- - !ruby/object:Gem::Version
146
- version: '1.22'
147
93
  - !ruby/object:Gem::Dependency
148
94
  name: puppet-modulebuilder
149
95
  requirement: !ruby/object:Gem::Requirement
@@ -172,20 +118,6 @@ dependencies:
172
118
  - - "~>"
173
119
  - !ruby/object:Gem::Version
174
120
  version: '1.7'
175
- - !ruby/object:Gem::Dependency
176
- name: serverspec
177
- requirement: !ruby/object:Gem::Requirement
178
- requirements:
179
- - - "~>"
180
- - !ruby/object:Gem::Version
181
- version: '2.42'
182
- type: :runtime
183
- prerelease: false
184
- version_requirements: !ruby/object:Gem::Requirement
185
- requirements:
186
- - - "~>"
187
- - !ruby/object:Gem::Version
188
- version: '2.42'
189
121
  - !ruby/object:Gem::Dependency
190
122
  name: pry
191
123
  requirement: !ruby/object:Gem::Requirement