dtk-node-agent 0.6.6 → 0.6.7

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 CHANGED
@@ -1,7 +1,15 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: 85f8d6ff17f511126ef50045eb00df6ed4927c03
4
- data.tar.gz: d3cc6438de22cd32cf8e2468261ead9071e798c0
2
+ !binary "U0hBMQ==":
3
+ metadata.gz: !binary |-
4
+ ODVhMGY3YTdhZWQwN2Q4ZTZmMmI5ODgzYzNiNTkxMTRiYzg4MjkyNg==
5
+ data.tar.gz: !binary |-
6
+ NTI5NDk3NGUyOTIyZTI5ZjNlZmNkMDNkMTg4ZGJkNDE5YmYwNDRjMg==
5
7
  SHA512:
6
- metadata.gz: 9d8cc97113aecaddb6c42857979e32822816b3999c80699e6bb65a56e356c11dfab5c23a1495362654e73404d9e2c03dadd5b22cfbe1a0dbaa12786ac2bcb5d2
7
- data.tar.gz: c88deee409b86539366a253c4174e063dadfb6a30f3f2c5c31c781853415f412955b49a0fab5b12bec0f454a30cf4c6beff83b7a719a2369051bd1e9e3eb2ddf
8
+ metadata.gz: !binary |-
9
+ ZjI2MzM4M2M4NDA2OTZmNjA1ZjNlYjA2OWMwYTk0MTY2ZjYyZTA0YmZmZTMz
10
+ NzY0ODUwYmMxMzQzYWVmMDYzYmJlZThjN2RkYzE3YWM3NTdlNWYyNTZlOWVh
11
+ MGI3MzZhYjk2NmMzOTkzYTY0MjFlNTdhZGQwOTY2YTE3NWU2Y2M=
12
+ data.tar.gz: !binary |-
13
+ MzYyNWRkN2NlMTU4MWJkNGY3OGVhNzhmNWQ2OTg0ZDk2M2I0ZmY2ZWIyZjcx
14
+ MjIxMTFhYmI0NWNkOTNlMmMxNzBiYzBjZGU4YTUwZjA0OTJlNDM5NDViNTJj
15
+ YzllNWNmMDBiMzQ3Y2U1N2Q3NjgxZjcwYmMwOTJiYmNiYjQ0MjQ=
@@ -1,3 +1,3 @@
1
1
  module DtkNodeAgent
2
- VERSION="0.6.6"
2
+ VERSION="0.6.7"
3
3
  end
@@ -21,19 +21,8 @@ module MCollective
21
21
  File.open(rsa_pub_path,"w"){|f|f.print request[:agent_ssh_key_public]}
22
22
  end
23
23
 
24
- #create or append if key not there
25
- skip = nil
26
- fp = request[:server_ssh_rsa_fingerprint]
27
- if File.exists?(known_hosts)
28
- fp_key = (fp =~ Regexp.new("^[|]1[|]([^=]+)=");$1)
29
- if fp_key
30
- fp_key_regexp = Regexp.new("^.1.#{fp_key}")
31
- skip = !!File.open(known_hosts){|f|f.find{|line|line =~ fp_key_regexp}}
32
- end
33
- end
34
- unless skip
35
- File.open(known_hosts,"a"){|f|f.print request[:server_ssh_rsa_fingerprint]}
36
- end
24
+ # add rsa_fingerprint to known hsots; server logic makes sure that is not requested twice so no duplicates
25
+ File.open(known_hosts,"a"){|f|f.print request[:server_ssh_rsa_fingerprint]}
37
26
 
38
27
  reply.data = { :status => :succeeded}
39
28
  rescue Exception => e
@@ -139,6 +139,7 @@ module MCollective
139
139
  Thread.current[:task_id] = task_id
140
140
  clean_state()
141
141
  ret = nil
142
+ runtime_errors = nil # in contast to compile errors
142
143
  # TODO: harmonize request[:top_task_id] and top_task_id()
143
144
  dtk_puppet_cache = DTKPuppetCache.new(@service_name,top_task_id())
144
145
  log_file_path = dtk_puppet_cache.log_file_path(inter_node_stage)
@@ -199,18 +200,20 @@ module MCollective
199
200
  return_code = ((report_status == :failed || report_info[:errors]) ? 1 : exit_status)
200
201
  ret ||= Response.new()
201
202
  if return_code == 0
202
- if dynamic_attributes = process_dynamic_attributes?(cmps_with_attrs)
203
- @log.info("dynamic_attributes = #{dynamic_attributes.inspect}")
204
- ret.set_dynamic_attributes!(dynamic_attributes)
203
+ if dynamic_attr_info = has_dynamic_attributes?(cmps_with_attrs)
204
+ @log.info("dynamic_attributes = #{dynamic_attr_info.inspect}")
205
+ process_dynamic_attributes!(ret,dynamic_attr_info)
206
+ else
207
+ ret.set_status_succeeded!()
205
208
  end
206
- ret.set_status_succeeded!()
207
209
  else
208
210
  ret.set_status_failed!()
209
211
  error_info = {
210
212
  :return_code => return_code
211
213
  }
212
- error_info.merge!(:errors => report_info[:errors]) if (report_info||{})[:errors]
213
- error_info[:errors].each { |error| error["type"] = "user_error" } if error_info[:errors]
214
+ if runtime_errors = (report_info||{})[:errors]
215
+ error_info[:errors] = runtime_errors.map{|e|e.merge(:type => "user_error")}
216
+ end
214
217
  ret.merge!(error_info)
215
218
  end
216
219
  rescue Exception => e
@@ -233,11 +236,14 @@ module MCollective
233
236
  stderr_msg = stderr_capture.read
234
237
  stderr_capture.close
235
238
  stderr_capture.unlink
236
- if err_message = compile_error_message?(return_code,stderr_msg,log_file_path)
237
- ret[:errors] = (ret[:errors]||[]) + [{:message => err_message, :type => "user_error" }]
238
- ret.set_status_failed!()
239
- Puppet::err stderr_msg
240
- Puppet::info "(end)"
239
+ # dont look for compile errors if runtime errors
240
+ unless runtime_errors
241
+ if err_message = compile_error_message?(return_code,stderr_msg,log_file_path)
242
+ ret[:errors] = [{:message => err_message, :type => "user_error" }]
243
+ ret.set_status_failed!()
244
+ Puppet::err stderr_msg
245
+ Puppet::info "(end)"
246
+ end
241
247
  end
242
248
  end
243
249
  Puppet::Util::Log.close_all()
@@ -249,12 +255,20 @@ module MCollective
249
255
  if stderr_msg and not stderr_msg.empty?
250
256
  stderr_msg
251
257
  elsif return_code != 0
252
- if last_line = `tail -1 "#{log_file_path}"`
253
- #TODO: might be more general pattern to search
254
- if last_line =~ /^.+Puppet \(err\):\s*(.+$)/
255
- $1
258
+ rest_reverse = Array.new
259
+ error = nil
260
+ begin
261
+ File.open(log_file_path).read.split("\n").reverse_each do |line|
262
+ if line =~ /^.+Puppet \(err\):\s*(.+$)/
263
+ error = $1
264
+ break
265
+ else
266
+ rest_reverse << line
267
+ end
256
268
  end
269
+ rescue
257
270
  end
271
+ ([error || 'Puppet catalog compile error'] + rest_reverse.reverse).join("\n")
258
272
  end
259
273
  end
260
274
 
@@ -385,21 +399,60 @@ module MCollective
385
399
  end
386
400
  end
387
401
 
388
- def process_dynamic_attributes?(cmps_with_attrs)
389
- ret = Array.new
390
- cmps_with_attrs.each do |cmp_with_attrs|
391
- dyn_attrs = cmp_with_attrs["dynamic_attributes"]
392
- if dyn_attrs and not dyn_attrs.empty?
393
- cmp_ref = component_ref(cmp_with_attrs)
394
- dyn_attrs.each do |dyn_attr|
395
- if el = dynamic_attr_response_el(cmp_ref,dyn_attr)
396
- ret << el
397
- end
402
+ def has_dynamic_attributes?(cmps_with_attrs)
403
+ ret = cmps_with_attrs.map do |cmp_with_attrs|
404
+ dyn_attrs = cmp_with_attrs["dynamic_attributes"]||[]
405
+ if !dyn_attrs.empty?
406
+ {
407
+ :cmp_ref => component_ref(cmp_with_attrs),
408
+ :dynamic_attrs => dyn_attrs
409
+ }
410
+ end
411
+ end.compact
412
+ !ret.empty? && ret
413
+ end
414
+
415
+ def process_dynamic_attributes!(ret,dynamic_attr_info)
416
+ dyn_attr_assigns = Array.new
417
+ missing_dyn_attrs = Array.new
418
+ dynamic_attr_info.each do |info|
419
+ cmp_ref = info[:cmp_ref]
420
+ info[:dynamic_attrs].each do |dyn_attr|
421
+ if dyn_attr_assign = dynamic_attr_response_el(cmp_ref,dyn_attr)
422
+ dyn_attr_assigns << dyn_attr_assign
423
+ else
424
+ missing_attr = {
425
+ :cmp_ref => cmp_ref,
426
+ :attr => dyn_attr[:name]
427
+ }
428
+ missing_dyn_attrs << missing_attr
398
429
  end
399
430
  end
400
431
  end
401
- ret.empty? ? nil : ret
432
+ if missing_dyn_attrs.empty?
433
+ ret.set_dynamic_attributes!(dyn_attr_assigns)
434
+ ret.set_status_succeeded!()
435
+ else
436
+ set_error_missing_dynamic_attrs!(ret,missing_dyn_attrs)
437
+ ret.set_status_failed!()
438
+ end
439
+ end
440
+
441
+ def set_error_missing_dynamic_attrs!(ret,missing_dyn_attrs)
442
+ errors = missing_dyn_attrs.map do |info|
443
+ err_message = "Dynamic Attribute (#{info[:attr]}) is not set by component (#{info[:cmp_ref]})"
444
+ {
445
+ :message => err_message,
446
+ :type => "user_error"
447
+ }
448
+ end
449
+ error_info = {
450
+ :return_code => 1,
451
+ :errors => errors
452
+ }
453
+ ret.merge!(error_info)
402
454
  end
455
+
403
456
  def dynamic_attr_response_el(cmp_name,dyn_attr)
404
457
  ret = nil
405
458
  val =
@@ -520,9 +573,10 @@ module MCollective
520
573
  cmp_with_attrs["name"]
521
574
  when "definition"
522
575
  defn = cmp_with_attrs["name"]
523
- name_attr_val = (cmp_with_attrs["attributes"].find{|attr|attr["name"]}||{})["value"]
524
- raise "Cannot find the name associated with definition #{defn}" unless name_attr_val
525
- "#{cmp_with_attrs["name"]}[#{name_attr_val}]"
576
+ unless name_attr = cmp_with_attrs["attributes"].find{|attr|attr["name"] == "name"}
577
+ raise "Cannot find the name associated with definition #{defn}"
578
+ end
579
+ "#{cmp_with_attrs["name"]}[#{name_attr["value"]}]"
526
580
  else
527
581
  raise "Reference to type #{cmp_with_attrs["component_type"]} not treated"
528
582
  end
@@ -661,7 +715,7 @@ module MCollective
661
715
  Thread.current[:report_status] = status.to_sym
662
716
  end
663
717
  def self.get_status()
664
- Thread.current[:report_status]
718
+ Thread.current[:report_status] || :failed
665
719
  end
666
720
  def self.set_report_info(report_info)
667
721
  Thread.current[:report_info] = report_info
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dtk-node-agent
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.6.6
4
+ version: 0.6.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - Rich PELAVIN
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-11-07 00:00:00.000000000 Z
11
+ date: 2014-12-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: puppet
@@ -211,12 +211,12 @@ require_paths:
211
211
  - lib
212
212
  required_ruby_version: !ruby/object:Gem::Requirement
213
213
  requirements:
214
- - - '>='
214
+ - - ! '>='
215
215
  - !ruby/object:Gem::Version
216
216
  version: '0'
217
217
  required_rubygems_version: !ruby/object:Gem::Requirement
218
218
  requirements:
219
- - - '>='
219
+ - - ! '>='
220
220
  - !ruby/object:Gem::Version
221
221
  version: '0'
222
222
  requirements: []