cem_acpt 0.8.1 → 0.8.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: c7329475f3aa0a02e2b6f65017ed0c24b35769f31eddcff07f306297d99b6558
4
- data.tar.gz: 346c753606378a5b022f2c0cd5e2f3db37dbc473468828075c1c6b9d1f2bf8d6
3
+ metadata.gz: e7eb7faf465af2f2ea5ab7649db1cf7e05c55573b869966c7e99c49aff498bf7
4
+ data.tar.gz: d79aadcc053957630a339b49a5ea456c5d67cc0dab24b036184cfec3e6c67609
5
5
  SHA512:
6
- metadata.gz: d3eeb3af0f675509e0e02f658656a21d66e682c2d127196155a44adedade3513f4361dd78bb818070d0bd4bb2e349782d4a475a3d1a7a51b9ab800bcc0d9b1e6
7
- data.tar.gz: 2ac9dc43f0bd592b22053599060ffce68cccb995b32755686c0c4128cf69c2d125b155738be38a0ad91cbca7e7017109ab0721bfda4adaae4da46ab72e30a00d
6
+ metadata.gz: cee1f24c8c38d68b01078f56e41963a02f5c3c5e2df8a35907b86e19b20600fe5ba612d7382be02da41b0a38f662a09019f629cf4decae30f35dad14f878fd38
7
+ data.tar.gz: 968a449a29d6f487e802954ca9af7d1d64bd2dd85c7f95cbaf95cecf7357a261a113293e712b8be8b01a593564de885d25c80ab5b01632215b98e8bd43310012
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- cem_acpt (0.8.1)
4
+ cem_acpt (0.8.2)
5
5
  async-http (>= 0.60, < 0.70)
6
6
  bcrypt_pbkdf (>= 1.0, < 2.0)
7
7
  deep_merge (>= 1.2, < 2.0)
@@ -25,6 +25,7 @@ module CemAcpt
25
25
  @module_package_path = nil
26
26
  @private_key = nil
27
27
  @public_key = nil
28
+ @applied = false
28
29
  end
29
30
 
30
31
  # @return [Hash] A hash of instance names and IPs
@@ -36,13 +37,18 @@ module CemAcpt
36
37
  terraform_init
37
38
  terraform_plan(formatted_vars, DEFAULT_PLAN_NAME)
38
39
  terraform_apply(DEFAULT_PLAN_NAME)
39
- begin
40
- output = terraform_output('instance_name_ip', json: true)
41
- JSON.parse(output)
42
- rescue JSON::ParserError => e
43
- logger.error('CemAcpt::Provision::Terraform') { "Error parsing Terraform output: #{output}" }
44
- raise e
45
- end
40
+ @applied = true
41
+ end
42
+
43
+ def output
44
+ raise 'Terraform has not been applied yet' unless @applied
45
+
46
+ output = terraform_output('instance_name_ip', json: true)
47
+ logger.debug('CemAcpt::Provision::Terraform') { "Terraform output:\n#{output}" }
48
+ JSON.parse(output)
49
+ rescue JSON::ParserError => e
50
+ logger.error('CemAcpt::Provision::Terraform') { "Error parsing Terraform output: #{output}" }
51
+ raise e
46
52
  end
47
53
 
48
54
  def destroy
@@ -59,7 +59,8 @@ module CemAcpt
59
59
  @run_data[:nodes] = new_node_data
60
60
  logger.info('CemAcpt::TestRunner') { 'Created node data...' }
61
61
  logger.verbose('CemAcpt::TestRunner') { "Node data: #{@run_data[:nodes]}" }
62
- @instance_names_ips = provision_test_nodes
62
+ provision_test_nodes
63
+ @instance_names_ips = provisioner_output
63
64
  logger.info('CemAcpt::TestRunner') { "Instance names and IPs class: #{@instance_names_ips.class}" }
64
65
  @provisioned = true
65
66
  logger.info('CemAcpt::TestRunner') { 'Provisioned test nodes...' }
@@ -156,6 +157,24 @@ module CemAcpt
156
157
  @provisioner.provision
157
158
  end
158
159
 
160
+ def provisioner_output
161
+ logger.info('CemAcpt::TestRunner') { 'Getting provisioner output...' }
162
+ @attempts = 0
163
+ @max_attempts = 3
164
+ output = nil
165
+ while @attempts < @max_attempts
166
+ @attempts += 1
167
+ output = @provisioner.output
168
+ break unless (output.nil? || output.empty?) && @attempts < @max_attempts # Don't sleep if this is last attempt
169
+
170
+ logger.info('CemAcpt::TestRunner') { "Provisioner output is nil or empty, retrying (#{@attempts}/#{@max_attempts})" }
171
+ sleep 3
172
+ end
173
+ raise 'Provisioner output is nil or empty' if output.nil? || output.empty?
174
+
175
+ output
176
+ end
177
+
159
178
  def destroy_test_nodes
160
179
  logger.info('CemAcpt::TestRunner') { 'Destroying test nodes if necessary...' }
161
180
  if !@provisioned
@@ -30,19 +30,10 @@ module CemAcpt
30
30
  stdin.close
31
31
  outerr.sync = true
32
32
  output_thread = Thread.new do
33
- while (line = outerr.readline_nonblock)
33
+ while (line = outerr.gets("\n"))
34
34
  output << line if output
35
35
  io_outerr.write(line) unless line.chomp.empty?
36
36
  end
37
- rescue IO::WaitReadable
38
- begin
39
- IO.select([outerr])
40
- retry
41
- rescue IOError
42
- # outerr closed, won't retry
43
- end
44
- rescue EOFError
45
- # outerr closed, won't retry
46
37
  end
47
38
  wait_thr.join
48
39
  output_thread.exit
@@ -70,21 +61,6 @@ module CemAcpt
70
61
  end
71
62
  nil
72
63
  end
73
-
74
- # IO monkey patch for non-blocking readline
75
- class ::IO
76
- def readline_nonblock
77
- rlnb = []
78
- rnlb << read_nonblock(1) while rlnb[-1] != "\n"
79
- rlnb.join
80
- rescue IO::WaitReadable => blocking
81
- raise blocking if rlnb.empty?
82
-
83
- rlnb.join
84
- rescue EOFError
85
- rlnb.join
86
- end
87
- end
88
64
  end
89
65
  end
90
66
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module CemAcpt
4
- VERSION = '0.8.1'
4
+ VERSION = '0.8.2'
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cem_acpt
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.8.1
4
+ version: 0.8.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - puppetlabs