cem_acpt 0.7.2 → 0.8.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (37) hide show
  1. checksums.yaml +4 -4
  2. data/.rubocop.yml +3 -1
  3. data/Gemfile.lock +42 -14
  4. data/README.md +8 -0
  5. data/cem_acpt.gemspec +3 -1
  6. data/exe/cem_acpt_image +0 -0
  7. data/lib/cem_acpt/action_result.rb +85 -0
  8. data/lib/cem_acpt/cli.rb +46 -22
  9. data/lib/cem_acpt/config/base.rb +27 -4
  10. data/lib/cem_acpt/config/cem_acpt.rb +0 -17
  11. data/lib/cem_acpt/config/cem_acpt_image.rb +2 -17
  12. data/lib/cem_acpt/goss/api.rb +8 -2
  13. data/lib/cem_acpt/image_builder.rb +82 -64
  14. data/lib/cem_acpt/logging.rb +41 -30
  15. data/lib/cem_acpt/platform.rb +4 -5
  16. data/lib/cem_acpt/provision/terraform/linux.rb +17 -1
  17. data/lib/cem_acpt/provision/terraform/terraform_cmd.rb +181 -0
  18. data/lib/cem_acpt/provision/terraform/windows.rb +9 -0
  19. data/lib/cem_acpt/provision/terraform.rb +34 -47
  20. data/lib/cem_acpt/provision.rb +1 -1
  21. data/lib/cem_acpt/puppet_helpers.rb +1 -1
  22. data/lib/cem_acpt/test_data.rb +3 -3
  23. data/lib/cem_acpt/test_runner/log_formatter/error_formatter.rb +33 -0
  24. data/lib/cem_acpt/test_runner/log_formatter.rb +10 -1
  25. data/lib/cem_acpt/test_runner.rb +151 -52
  26. data/lib/cem_acpt/utils/ssh.rb +2 -2
  27. data/lib/cem_acpt/utils/terminal.rb +1 -5
  28. data/lib/cem_acpt/utils/winrm_runner.rb +160 -0
  29. data/lib/cem_acpt/utils.rb +41 -1
  30. data/lib/cem_acpt/version.rb +1 -1
  31. data/lib/cem_acpt.rb +51 -21
  32. data/lib/terraform/gcp/linux/goss/puppet_idempotent.yaml +2 -2
  33. data/lib/terraform/gcp/linux/goss/puppet_noop.yaml +1 -1
  34. data/lib/terraform/gcp/windows/goss/puppet_idempotent.yaml +9 -0
  35. data/lib/terraform/gcp/windows/goss/puppet_noop.yaml +12 -0
  36. data/lib/terraform/gcp/windows/main.tf +115 -0
  37. metadata +49 -8
data/lib/cem_acpt.rb CHANGED
@@ -22,6 +22,7 @@ module CemAcpt
22
22
  end
23
23
 
24
24
  def run(command, original_command, options)
25
+ set_up_signal_handlers
25
26
  case command
26
27
  when :version
27
28
  puts "#{original_command} v#{CemAcpt::VERSION}"
@@ -30,9 +31,9 @@ module CemAcpt
30
31
  when :print_explain_config
31
32
  print_config(options, command: original_command.to_sym, format: :explain)
32
33
  when :cem_acpt
33
- run_cem_acpt(options)
34
+ trace_it(options[:trace], options[:trace_events]) { run_cem_acpt(options) }
34
35
  when :cem_acpt_image
35
- run_cem_acpt_image(options)
36
+ trace_it(options[:trace], options[:trace_events]) { run_cem_acpt_image(options) }
36
37
  else
37
38
  raise "Command #{command} does not exist"
38
39
  end
@@ -78,41 +79,70 @@ module CemAcpt
78
79
  new_log
79
80
  end
80
81
 
82
+ TRACE_EVENTS = %i[line call b_call thread_begin thread_end].freeze
83
+
84
+ def trace_it(should_trace = false, trace_events = nil)
85
+ if should_trace
86
+ trace_events ||= TRACE_EVENTS
87
+ tracer = TracePoint.new(*trace_events.map(&:to_sym)) do |tp|
88
+ if tp&.path&.include?('lib/cem_acpt') && !tp&.path&.include?('lib/cem_acpt/logging')
89
+ begin
90
+ logger << "## TRACE ## #{tp.path}:#{tp.lineno}: #{tp.event} #{tp.method_id}\n"
91
+ rescue StandardError
92
+ # Trace will often run into the trap context problem before the signal handler call back
93
+ logger.trap_context = true
94
+ logger << "## TRACE ## #{tp.path}:#{tp.lineno}: #{tp.event}\n"
95
+ end
96
+ end
97
+ end
98
+ tracer.enable do
99
+ yield
100
+ end
101
+ else
102
+ yield
103
+ end
104
+ end
105
+
106
+ def signal_handlers
107
+ {
108
+ 'INT' => proc do
109
+ @trap_context = true
110
+ logger.trap_context = @trap_context
111
+ logger.fatal('CemAcpt') { 'Received interrupt signal. Exiting.' }
112
+ exit 1
113
+ end,
114
+ }
115
+ end
116
+
117
+ def set_up_signal_handlers
118
+ signal_handlers.each do |signal, handler|
119
+ Signal.trap(signal, &handler)
120
+ logger.debug('CemAcpt') { "Signal handler set for #{signal}" }
121
+ end
122
+ end
123
+
81
124
  def run_cem_acpt(options)
82
125
  # Set up config, logger, and helper
83
126
  @config = new_config(options)
84
127
  initialize_logger!
128
+ logger.debug('CemAcpt') { 'Config set and logger initialized...' }
85
129
  runner = new_runner
86
-
87
- # Set up signal handlers
88
- Signal.trap('INT') do
89
- @trap_context = true
90
- logger.trap_context = @trap_context
91
- logger.fatal('Signal Handler') { 'Received interrupt signal. Cleaning up test suite...' }
92
- runner.clean_up(@trap_context)
93
- logger.fatal('Signal Handler') { 'Exiting due to interrupt signal' }
94
- exit 1
95
- end
130
+ logger.debug('CemAcpt') { 'Runner initialized...' }
96
131
 
97
132
  # Run the test suite
133
+ logger.debug('CemAcpt') { 'Running test suite...' }
98
134
  runner.run
99
-
135
+ logger.debug('CemAcpt') { "Test suite run complete, exiting with code #{runner.exit_code}" }
100
136
  exit runner.exit_code
101
137
  end
102
138
 
103
139
  def run_cem_acpt_image(options)
104
140
  @config = new_config(options, command: :cem_acpt_image)
105
141
  initialize_logger!
106
-
107
- # Set up signal handlers
108
- Signal.trap('INT') do
109
- @trap_context = true
110
- logger.trap_context = @trap_context
111
- logger.fatal('Signal Handler') { 'Received interrupt signal. Cleaning up test suite...' }
112
- exit 1
113
- end
142
+ logger.debug('CemAcptImage') { 'Config set and logger initialized...' }
114
143
 
115
144
  # Build the images
145
+ logger.debug('CemAcptImage') { 'Building images...' }
116
146
  CemAcpt::ImageBuilder.build_images(@config)
117
147
  end
118
148
  end
@@ -1,9 +1,9 @@
1
1
  command:
2
2
  puppet_idempotent:
3
- exec: 'sudo /opt/puppetlabs/puppet/bin/puppet apply --verbose --detailed-exitcodes /opt/cem_acpt/manifest.pp'
3
+ exec: 'sudo /opt/puppetlabs/puppet/bin/puppet apply --logdest console,/opt/cem_acpt/idempotent_apply.log --debug --verbose --detailed-exitcodes /opt/cem_acpt/manifest.pp'
4
4
  timeout: 300000 # 5 mins in miliseconds
5
5
  stdout:
6
- - "Applied catalog in"
6
+ - "/Applied catalog in.*/"
7
7
  stderr:
8
8
  - ""
9
9
  exit-status: 0
@@ -1,6 +1,6 @@
1
1
  command:
2
2
  puppet_noop:
3
- exec: 'sudo /opt/puppetlabs/puppet/bin/puppet apply --verbose --detailed-exitcodes --noop /opt/cem_acpt/manifest.pp'
3
+ exec: 'sudo /opt/puppetlabs/puppet/bin/puppet apply --logdest console,/opt/cem_acpt/noop_apply.log --debug --verbose --detailed-exitcodes --noop /opt/cem_acpt/manifest.pp'
4
4
  timeout: 300000 # 5 mins in miliseconds
5
5
  stdout:
6
6
  - "Applied catalog in"
@@ -0,0 +1,9 @@
1
+ command:
2
+ puppet_idempotent:
3
+ exec: 'C:\Program Files\Puppet Labs\Puppet\bin\puppet apply --verbose --detailed-exitcodes C:\cem_acpt\manifest.pp'
4
+ timeout: 300000 # 5 mins in miliseconds
5
+ stdout:
6
+ - "Applied catalog in"
7
+ stderr:
8
+ - ""
9
+ exit-status: 0
@@ -0,0 +1,12 @@
1
+ command:
2
+ puppet_noop:
3
+ exec: 'C:\Program Files\Puppet Labs\Puppet\bin\puppet apply --verbose --detailed-exitcodes --noop C:\cem_acpt\manifest.pp'
4
+ timeout: 300000 # 5 mins in miliseconds
5
+ stdout:
6
+ - "Applied catalog in"
7
+ stderr:
8
+ - ""
9
+ exit-status:
10
+ or:
11
+ - 0
12
+ - 2
@@ -0,0 +1,115 @@
1
+ terraform {
2
+ required_providers {
3
+ google = {
4
+ source = "hashicorp/google"
5
+ version = "4.59.0"
6
+ }
7
+ }
8
+ }
9
+
10
+ variable "credentials_file" {
11
+ type = string
12
+ }
13
+
14
+ variable "project" {
15
+ type = string
16
+ }
17
+
18
+ variable "region" {
19
+ type = string
20
+ }
21
+
22
+ variable "zone" {
23
+ type = string
24
+ }
25
+
26
+ variable "subnetwork" {
27
+ type = string
28
+ }
29
+
30
+ # Just stub this out for now
31
+ variable "username" {
32
+ type = string
33
+ }
34
+
35
+ # Just stub this out for now
36
+ variable "private_key" {
37
+ type = string
38
+ sensitive = true
39
+ }
40
+
41
+ # Just stub this out for now
42
+ variable "public_key" {
43
+ type = string
44
+ }
45
+
46
+ # Just stub this out for now
47
+ variable "puppet_module_package" {
48
+ type = string
49
+ }
50
+
51
+ variable "node_data" {
52
+ type = map(object({
53
+ machine_type = string
54
+ image = string
55
+ disk_size = number
56
+ test_name = string
57
+ }))
58
+ }
59
+
60
+ provider "google" {
61
+ credentials = file(var.credentials_file)
62
+ project = var.project
63
+ region = var.region
64
+ zone = var.zone
65
+ }
66
+
67
+ resource "google_compute_instance" "acpt-test-node" {
68
+ provider = google
69
+ for_each = var.node_data
70
+ name = each.key
71
+ machine_type = each.value.machine_type
72
+
73
+ boot_disk {
74
+ initialize_params {
75
+ image = each.value.image
76
+ size = each.value.disk_size
77
+ type = "pd-standard"
78
+ }
79
+ }
80
+
81
+ scheduling {
82
+ preemptible = true
83
+ automatic_restart = false
84
+ provisioning_model = "SPOT"
85
+ instance_termination_action = "DELETE"
86
+ }
87
+
88
+ network_interface {
89
+ subnetwork = var.subnetwork
90
+ access_config {
91
+ network_tier = "STANDARD"
92
+ }
93
+ }
94
+
95
+ service_account {
96
+ email = "cem-windows-acpt-test@team-sse.iam.gserviceaccount.com"
97
+ scopes = ["cloud-platform"]
98
+ }
99
+
100
+ metadata = {
101
+ "enable-oslogin" = "TRUE"
102
+ "cem-acpt-test" = each.value.test_name
103
+ }
104
+
105
+ tags = [ "cem-acpt-test-node" ]
106
+ }
107
+
108
+ output "instance_name_ip" {
109
+ value = {
110
+ for k, v in google_compute_instance.acpt-test-node : v.name => {
111
+ ip = v.network_interface.0.access_config.0.nat_ip,
112
+ test_name = v.metadata.cem-acpt-test,
113
+ }
114
+ }
115
+ }
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.7.2
4
+ version: 0.8.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - puppetlabs
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2023-05-25 00:00:00.000000000 Z
11
+ date: 2023-08-30 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: async-http
@@ -105,19 +105,25 @@ dependencies:
105
105
  - !ruby/object:Gem::Version
106
106
  version: 0.0.1
107
107
  - !ruby/object:Gem::Dependency
108
- name: ruby-terraform
108
+ name: winrm
109
109
  requirement: !ruby/object:Gem::Requirement
110
110
  requirements:
111
- - - "~>"
111
+ - - ">="
112
+ - !ruby/object:Gem::Version
113
+ version: '2.3'
114
+ - - "<"
112
115
  - !ruby/object:Gem::Version
113
- version: '1.7'
116
+ version: '3.0'
114
117
  type: :runtime
115
118
  prerelease: false
116
119
  version_requirements: !ruby/object:Gem::Requirement
117
120
  requirements:
118
- - - "~>"
121
+ - - ">="
119
122
  - !ruby/object:Gem::Version
120
- version: '1.7'
123
+ version: '2.3'
124
+ - - "<"
125
+ - !ruby/object:Gem::Version
126
+ version: '3.0'
121
127
  - !ruby/object:Gem::Dependency
122
128
  name: pry
123
129
  requirement: !ruby/object:Gem::Requirement
@@ -146,6 +152,34 @@ dependencies:
146
152
  - - ">="
147
153
  - !ruby/object:Gem::Version
148
154
  version: '0'
155
+ - !ruby/object:Gem::Dependency
156
+ name: rubocop-performance
157
+ requirement: !ruby/object:Gem::Requirement
158
+ requirements:
159
+ - - ">="
160
+ - !ruby/object:Gem::Version
161
+ version: '0'
162
+ type: :development
163
+ prerelease: false
164
+ version_requirements: !ruby/object:Gem::Requirement
165
+ requirements:
166
+ - - ">="
167
+ - !ruby/object:Gem::Version
168
+ version: '0'
169
+ - !ruby/object:Gem::Dependency
170
+ name: rubocop-rspec
171
+ requirement: !ruby/object:Gem::Requirement
172
+ requirements:
173
+ - - ">="
174
+ - !ruby/object:Gem::Version
175
+ version: '0'
176
+ type: :development
177
+ prerelease: false
178
+ version_requirements: !ruby/object:Gem::Requirement
179
+ requirements:
180
+ - - ">="
181
+ - !ruby/object:Gem::Version
182
+ version: '0'
149
183
  description: Litmus-like library focusing on CEM Acceptance Tests
150
184
  email:
151
185
  - abide-team@puppet.com
@@ -170,6 +204,7 @@ files:
170
204
  - exe/cem_acpt
171
205
  - exe/cem_acpt_image
172
206
  - lib/cem_acpt.rb
207
+ - lib/cem_acpt/action_result.rb
173
208
  - lib/cem_acpt/cli.rb
174
209
  - lib/cem_acpt/config.rb
175
210
  - lib/cem_acpt/config/base.rb
@@ -192,16 +227,19 @@ files:
192
227
  - lib/cem_acpt/provision/terraform.rb
193
228
  - lib/cem_acpt/provision/terraform/linux.rb
194
229
  - lib/cem_acpt/provision/terraform/os_data.rb
230
+ - lib/cem_acpt/provision/terraform/terraform_cmd.rb
195
231
  - lib/cem_acpt/provision/terraform/windows.rb
196
232
  - lib/cem_acpt/puppet_helpers.rb
197
233
  - lib/cem_acpt/test_data.rb
198
234
  - lib/cem_acpt/test_runner.rb
199
235
  - lib/cem_acpt/test_runner/log_formatter.rb
236
+ - lib/cem_acpt/test_runner/log_formatter/error_formatter.rb
200
237
  - lib/cem_acpt/test_runner/log_formatter/goss_action_response.rb
201
238
  - lib/cem_acpt/utils.rb
202
239
  - lib/cem_acpt/utils/puppet.rb
203
240
  - lib/cem_acpt/utils/ssh.rb
204
241
  - lib/cem_acpt/utils/terminal.rb
242
+ - lib/cem_acpt/utils/winrm_runner.rb
205
243
  - lib/cem_acpt/version.rb
206
244
  - lib/terraform/gcp/linux/goss/puppet_idempotent.yaml
207
245
  - lib/terraform/gcp/linux/goss/puppet_noop.yaml
@@ -210,6 +248,9 @@ files:
210
248
  - lib/terraform/gcp/linux/systemd/goss-idempotent.service
211
249
  - lib/terraform/gcp/linux/systemd/goss-noop.service
212
250
  - lib/terraform/gcp/windows/.keep
251
+ - lib/terraform/gcp/windows/goss/puppet_idempotent.yaml
252
+ - lib/terraform/gcp/windows/goss/puppet_noop.yaml
253
+ - lib/terraform/gcp/windows/main.tf
213
254
  - lib/terraform/image/gcp/linux/main.tf
214
255
  - lib/terraform/image/gcp/windows/.keep
215
256
  - sample_config.yaml
@@ -235,7 +276,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
235
276
  - !ruby/object:Gem::Version
236
277
  version: '0'
237
278
  requirements: []
238
- rubygems_version: 3.4.6
279
+ rubygems_version: 3.4.18
239
280
  signing_key:
240
281
  specification_version: 4
241
282
  summary: CEM Acceptance Tests