cem_acpt 0.3.3-universal-java-17 → 0.3.5-universal-java-17

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,181 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative '../logging'
4
+
5
+ module CemAcpt
6
+ module TestRunner
7
+ module Workflow
8
+ # Error used to wrap fatal errors raised in Runner steps
9
+ # @!attribute [r] step
10
+ # @return [Step] The step that raised the error
11
+ class StepError < StandardError
12
+ attr_reader :step
13
+
14
+ def initialize(step, err)
15
+ @step = step
16
+ @original_error = err
17
+ super err
18
+ set_backtrace err.backtrace if err.respond_to?(:backtrace)
19
+ end
20
+ end
21
+
22
+ # Step is a class that defines a single step in a Workflow.
23
+ # Step objects are created by the Workflow class and are not intended to be created directly.
24
+ # @!attribute [r] name
25
+ # @return [Symbol] The name of the step
26
+ # @!attribute [r] opts
27
+ # @return [Hash] The options passed to the step
28
+ # @!attribute [r] result
29
+ # @return [Object] The result of the step
30
+ class Step
31
+ include CemAcpt::TestRunner::Logging
32
+
33
+ attr_reader :logger, :name, :opts, :result
34
+
35
+ # @param name [Symbol] The name of the step
36
+ # @param opts [Hash] The options passed to the step
37
+ # @param block [Proc] The block to execute when the step is run
38
+ # @yieldparam step [Step] This step object is yielded to the block
39
+ def initialize(name, **opts, &block)
40
+ @name = name
41
+ @opts = opts
42
+ @block = block
43
+ @result = :not_run
44
+ @failed = false
45
+ @logger = use_logger(opts[:logger], step: name.to_s.capitalize)
46
+ end
47
+
48
+ # @return [Boolean] True if the step has been run and failed
49
+ def failed?
50
+ @failed
51
+ end
52
+
53
+ # Run the step. This calls and executes the block passed to the constructor.
54
+ # @param start_log [String] The message to log when the step starts
55
+ # @return [Object] The result of the step
56
+ def run(start_log = 'starting step')
57
+ @logger.info(start_log)
58
+ @result = @block.call(self)
59
+ @logger.debug('SUCCESS')
60
+ @result
61
+ rescue StandardError => e
62
+ @logger.debug("FAILED: #{e.message}")
63
+ @result = StepError.new(@name, e)
64
+ @failed = true
65
+ @result
66
+ ensure
67
+ Thread.pass # Be kind to the scheduler
68
+ end
69
+ end
70
+
71
+ # StepState is a class that holds the state of a Step.
72
+ # StepState objects are created by the Workflow class and are not intended to be created directly.
73
+ # @!attribute [r] step
74
+ # @return [Step] The step object
75
+ # @!attribute [r] position
76
+ # @return [Integer] The position of the step in the workflow
77
+ # @!attribute [r] opts
78
+ # @return [Hash] The options passed to the step
79
+ # @!attribute [r] run_count
80
+ # @return [Integer] The number of times the step has been run
81
+ # @!attribute [r] results
82
+ # @return [Array<Object>] The results of all runs of the step
83
+ # @!attribute [r] last_error
84
+ # @return [StepError] The last error raised by the step
85
+ # @!attribute [r] last_result
86
+ # @return [Object] The result of the last run of the step
87
+ class StepState
88
+ attr_reader :step, :position, :opts, :run_count, :results, :last_error, :last_result
89
+
90
+ # @param step [Step] The step object
91
+ # @param position [Integer] The position of the step in the workflow
92
+ # @param opts [Hash] The options passed to the step
93
+ def initialize(step, position, **opts)
94
+ @step = step
95
+ @position = position
96
+ @retryable = opts[:retryable] || false
97
+ @retry_max = opts[:retry_max] || 3
98
+ @retry_delay = opts[:retry_delay] || 0
99
+ @retry_workflow_on_fail = opts[:retry_workflow_on_fail] || false
100
+ @run_count = 0
101
+ @results = []
102
+ @last_error = nil
103
+ @last_result = nil
104
+ end
105
+
106
+ # Proxy any methods not defined in this class to the Step
107
+ def method_missing(method, *args, &block)
108
+ if @step.respond_to?(method)
109
+ @step.send(method, *args, &block)
110
+ else
111
+ super
112
+ end
113
+ end
114
+
115
+ # Proxy any methods not defined in this class to the Step
116
+ def respond_to_missing?(method, include_private = false)
117
+ @step.respond_to?(method) || super
118
+ end
119
+
120
+ # @return [Object] The result of the last run of the step
121
+ def result
122
+ @last_result || :not_run
123
+ end
124
+
125
+ # @return [Boolean] If the step is retryable
126
+ def retryable?
127
+ @retryable
128
+ end
129
+
130
+ # @return [Boolean] If the workflow should be retried if the step fails
131
+ def retry_workflow_on_fail?
132
+ @retry_workflow_on_fail
133
+ end
134
+
135
+ # @return [Boolean] True if the step has been run and failed
136
+ def failed?
137
+ @results.last.is_a?(StepError)
138
+ end
139
+
140
+ # Run the step. This wraps the Step#run method and handles updating the state of the step.
141
+ # @param start_log [String] The message to log when the step starts
142
+ # @return [Object] The result of the step
143
+ def run(start_log = 'starting step')
144
+ @run_count += 1
145
+ @last_result = @step.run(start_log)
146
+ @results << @last_result
147
+ if @last_result.is_a?(StepError)
148
+ handle_error(@last_result)
149
+ end
150
+ @last_result
151
+ end
152
+
153
+ private
154
+
155
+ # Handle the error raised by the step
156
+ # @param result [StepError] The result of the step
157
+ def handle_error(result)
158
+ @last_error = result
159
+ if retry_workflow_on_fail?
160
+ @last_result = :retry_workflow
161
+ elsif retry?
162
+ retry_step
163
+ else
164
+ @last_result = :fail
165
+ end
166
+ end
167
+
168
+ # @return [Boolean] True if the step should be retried
169
+ def retry?
170
+ @retryable && @run_count < @retry_max
171
+ end
172
+
173
+ # Retry running the step
174
+ def retry_step
175
+ sleep @retry_delay if @retry_delay.positive?
176
+ run("retrying step (attempt #{@run_count + 1} of #{@retry_max})")
177
+ end
178
+ end
179
+ end
180
+ end
181
+ end
@@ -0,0 +1,11 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative 'workflow/manager'
4
+ require_relative 'workflow/step'
5
+
6
+ module CemAcpt
7
+ module TestRunner
8
+ # Namespace for workflow classes
9
+ module Workflow; end
10
+ end
11
+ end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module CemAcpt
4
- VERSION = '0.3.3'
4
+ VERSION = '0.3.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.3.3
4
+ version: 0.3.5
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: 2022-12-14 00:00:00.000000000 Z
11
+ date: 2023-02-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  requirement: !ruby/object:Gem::Requirement
@@ -132,6 +132,20 @@ dependencies:
132
132
  - - ">="
133
133
  - !ruby/object:Gem::Version
134
134
  version: '0'
135
+ - !ruby/object:Gem::Dependency
136
+ requirement: !ruby/object:Gem::Requirement
137
+ requirements:
138
+ - - ">="
139
+ - !ruby/object:Gem::Version
140
+ version: '0'
141
+ name: pry
142
+ prerelease: false
143
+ type: :development
144
+ version_requirements: !ruby/object:Gem::Requirement
145
+ requirements:
146
+ - - ">="
147
+ - !ruby/object:Gem::Version
148
+ version: '0'
135
149
  description: Litmus-like library focusing on CEM Acceptance Tests
136
150
  email:
137
151
  - abide-team@puppet.com
@@ -140,6 +154,7 @@ executables:
140
154
  extensions: []
141
155
  extra_rdoc_files: []
142
156
  files:
157
+ - ".github/workflows/spec.yml"
143
158
  - ".gitignore"
144
159
  - ".rspec"
145
160
  - CODEOWNERS
@@ -167,6 +182,7 @@ files:
167
182
  - lib/cem_acpt/platform/gcp.rb
168
183
  - lib/cem_acpt/platform/gcp/cmd.rb
169
184
  - lib/cem_acpt/platform/gcp/compute.rb
185
+ - lib/cem_acpt/platform/utils/linux.rb
170
186
  - lib/cem_acpt/platform/vmpooler.rb
171
187
  - lib/cem_acpt/puppet_helpers.rb
172
188
  - lib/cem_acpt/rspec_utils.rb
@@ -174,9 +190,14 @@ files:
174
190
  - lib/cem_acpt/spec_helper_acceptance.rb
175
191
  - lib/cem_acpt/test_data.rb
176
192
  - lib/cem_acpt/test_runner.rb
193
+ - lib/cem_acpt/test_runner/logging.rb
177
194
  - lib/cem_acpt/test_runner/run_handler.rb
178
195
  - lib/cem_acpt/test_runner/runner.rb
179
196
  - lib/cem_acpt/test_runner/runner_result.rb
197
+ - lib/cem_acpt/test_runner/runner_workflow_builder.rb
198
+ - lib/cem_acpt/test_runner/workflow.rb
199
+ - lib/cem_acpt/test_runner/workflow/manager.rb
200
+ - lib/cem_acpt/test_runner/workflow/step.rb
180
201
  - lib/cem_acpt/utils.rb
181
202
  - lib/cem_acpt/version.rb
182
203
  - sample_config.yaml