choria-colt 0.6.0 → 0.7.0

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,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 4e76e667917bf1958b48d45148712fa5e0d6f2c15280bbbda0d4899b0537e9f8
4
- data.tar.gz: 17637d3bf6738bef6c28a282aabb1c4ac7680e4b2e8a6f0fe873a27b59079cc1
3
+ metadata.gz: e86ae8b9274433cf146d571d2a7466a2c7c131e826ec5e4a8df9540d37f7994d
4
+ data.tar.gz: 9e4717f11b4f1f3f93c555818b9281e0118ac59a4bbf7b2573d6a85ed6e74fd9
5
5
  SHA512:
6
- metadata.gz: bacccbdfd46669936f1271d05e4fdceae1864e07ae7f14b260f6de3ec2ed1e90d0c3270f57ea3faaa424b267eab59e1460abcdf4262feec421c6ea510bc811d5
7
- data.tar.gz: ad8aaf32f6f71f349d04955cb795c0439c4ecd30103f290da82b3ce7037c6dce330b7e89123a416c120b61bc194c754debfb97412e6e200af8d53264aaba169c
6
+ metadata.gz: 3754982bc70a01d44fc4115c76693f67201d5a618d2f61b229d9b3408bea3ff2c2ac187ea5c0bd55fdbf8ca391c668f09086339ab366a85f93100c0ac1bd8973
7
+ data.tar.gz: c1a1dd4eaf6287d28d09baa7f45ff7ab297ffff5a8bd78d519d9a814dfcab74512d6f300fe6696789d1687e1a9f04aa021f90531a98143e263fae4d3a8d53688
data/CHANGELOG.md CHANGED
@@ -1,5 +1,18 @@
1
1
  # Changelog
2
2
 
3
+ ## [v0.7.0](https://github.com/opus-codium/choria-colt/tree/v0.7.0) (2022-09-26)
4
+
5
+ [Full Changelog](https://github.com/opus-codium/choria-colt/compare/v0.6.0...v0.7.0)
6
+
7
+ **Fixed bugs:**
8
+
9
+ - Task: Fix IDs array processing [\#30](https://github.com/opus-codium/choria-colt/pull/30) ([neomilium](https://github.com/neomilium))
10
+
11
+ **Merged pull requests:**
12
+
13
+ - Use ActiveSuport::Cache instead our own Cache mecanism for tasks metadata [\#31](https://github.com/opus-codium/choria-colt/pull/31) ([neomilium](https://github.com/neomilium))
14
+ - Improve robustness when nodes are unhealthy [\#29](https://github.com/opus-codium/choria-colt/pull/29) ([neomilium](https://github.com/neomilium))
15
+
3
16
  ## [v0.6.0](https://github.com/opus-codium/choria-colt/tree/v0.6.0) (2022-05-16)
4
17
 
5
18
  [Full Changelog](https://github.com/opus-codium/choria-colt/compare/v0.5.1...v0.6.0)
@@ -68,10 +68,9 @@ module Choria
68
68
  default: 'production'
69
69
  def show(*tasks_names)
70
70
  environment = options['environment']
71
- cache_directory = File.expand_path('.cache/colt/tasks')
72
- FileUtils.mkdir_p cache_directory
73
- cache = Cache.new(path: File.join(cache_directory, "#{environment}.yaml"))
74
71
 
72
+ require 'active_support/cache/file_store'
73
+ cache = ActiveSupport::Cache::FileStore.new File.expand_path('~/.cache/colt/tasks')
75
74
  tasks = colt.tasks(environment: environment, cache: cache)
76
75
 
77
76
  if tasks_names.empty?
@@ -4,14 +4,25 @@ module Choria
4
4
  def self.structure(res) # rubocop:disable Metrics/AbcSize
5
5
  return res unless [0, 1].include? res[:statuscode]
6
6
 
7
+ # If data is empty, status message is an RPC error
8
+ if res[:data].empty?
9
+ res[:result] = {
10
+ _error: {
11
+ kind: 'choria/rpc',
12
+ msg: res[:statusmsg],
13
+ },
14
+ }
15
+ return res
16
+ end
17
+
7
18
  # data.stdout seems to always be JSON, so parse it once.
8
- res[:result] = JSON.parse res[:data][:stdout]
19
+ res[:result] = JSON.parse res[:data][:stdout] unless res.dig(:data, :stdout).nil?
9
20
  res[:data].delete :stdout
10
21
 
11
22
  # On one side, data.stderr is filled by the remote execution stderr.
12
23
  # On the other side, error description is in JSON (ie. '_error')
13
24
  # So merge data.stderr in '_error'.'details'
14
- unless res[:data][:stderr].empty?
25
+ unless res.dig(:data, :stderr).nil? || res[:data][:stderr].empty?
15
26
  raise NotImplementedError, 'What to do when res[:data][:stderr] contains something?' if res[:result]['_error'].empty?
16
27
 
17
28
  res[:result]['_error']['details'].merge!({ 'stderr' => res[:data][:stderr].split("\n") })
@@ -19,7 +30,7 @@ module Choria
19
30
  res[:data].delete :stderr
20
31
 
21
32
  # Convert '_output' (ie. stdout) lines into array
22
- res[:result]['_output'] = res[:result]['_output'].split("\n") unless res[:result]['_output'].nil?
33
+ res[:result]['_output'] = res[:result]['_output'].split("\n") unless res.dig(:result, '_output').nil?
23
34
 
24
35
  res
25
36
  end
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Choria
4
4
  class Colt
5
- VERSION = '0.6.0'
5
+ VERSION = '0.7.0'
6
6
  end
7
7
  end
data/lib/choria/colt.rb CHANGED
@@ -1,12 +1,13 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'choria/colt/cache'
4
3
  require 'choria/colt/version'
5
4
  require 'choria/orchestrator'
6
5
  require 'choria/orchestrator/task'
7
6
 
8
7
  require 'logger'
9
8
 
9
+ require 'active_support/cache/memory_store'
10
+
10
11
  module Choria
11
12
  class Colt
12
13
  class Error < StandardError; end
@@ -45,32 +46,30 @@ module Choria
45
46
  raise
46
47
  end
47
48
 
48
- def tasks(environment:, cache: nil)
49
+ def tasks(environment:, cache: nil, force_cache_refresh: false)
50
+ cache ||= ActiveSupport::Cache::MemoryStore.new
51
+
49
52
  tasks_names = orchestrator.tasks_support.tasks(environment).map do |task|
50
53
  task['name']
51
54
  end
52
55
 
53
- return tasks_metadata(tasks_names, environment) if cache.nil?
54
-
55
- cached_tasks = cache.load
56
- return cached_tasks if cache.clean? && cached_tasks.keys.sort == tasks_names.sort
57
-
58
- updated_tasks = tasks_metadata(tasks_names, environment)
59
- cache.save updated_tasks
60
-
61
- updated_tasks
56
+ tasks_names.map do |task_name|
57
+ metadata = cache.fetch(task_name, force: force_cache_refresh) do
58
+ task_metadata(task_name, environment)
59
+ end
60
+ [task_name, metadata]
61
+ end.to_h
62
62
  end
63
63
 
64
64
  private
65
65
 
66
- def tasks_metadata(tasks, environment)
67
- logger.info "Fetching metadata for tasks (environment: '#{environment}')"
66
+ def task_metadata(name, environment)
67
+ logger.debug "Fetching metadata for task '#{name}' (environment: '#{environment}')"
68
68
 
69
- tasks.map do |task|
70
- logger.debug "Fetching metadata for task '#{task}' (environment: '#{environment}')"
71
- metadata = orchestrator.tasks_support.task_metadata(task, environment)
72
- [task, metadata]
73
- end.to_h
69
+ # FIXME: Remove this workaround when the Puppet bug is fixed
70
+ return { 'metadata' => { 'private' => true } } if ['application::utils'].include? name
71
+
72
+ orchestrator.tasks_support.task_metadata(name, environment)
74
73
  end
75
74
  end
76
75
  end
@@ -103,6 +103,7 @@ module Choria
103
103
  end
104
104
  raise NoNodesLeftError, "No nodes left to continue after 'run_no_wait' action" if @pending_targets.empty?
105
105
 
106
+ task_ids.compact!
106
107
  task_ids.uniq!
107
108
  raise NotImplementedError, "Multiple task IDs: #{task_ids}" unless task_ids.count == 1
108
109
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: choria-colt
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.6.0
4
+ version: 0.7.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Romuald Conty
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2022-05-16 00:00:00.000000000 Z
11
+ date: 2022-09-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -210,7 +210,6 @@ files:
210
210
  - choria-colt.gemspec
211
211
  - exe/colt
212
212
  - lib/choria/colt.rb
213
- - lib/choria/colt/cache.rb
214
213
  - lib/choria/colt/cli.rb
215
214
  - lib/choria/colt/cli/formatter.rb
216
215
  - lib/choria/colt/cli/thor.rb
@@ -1,33 +0,0 @@
1
- require 'yaml'
2
-
3
- module Choria
4
- class Colt
5
- class Cache
6
- def initialize(path:, force_refresh: false)
7
- @path = path
8
- @data = YAML.safe_load File.read(@path)
9
- @clean = true unless force_refresh
10
- rescue Errno::ENOENT
11
- @clean = false
12
- end
13
-
14
- def dirty?
15
- !clean?
16
- end
17
-
18
- def clean?
19
- @clean
20
- end
21
-
22
- def load
23
- @data
24
- end
25
-
26
- def save(data)
27
- @data = data
28
- File.write @path, data.to_yaml
29
- @clean = true
30
- end
31
- end
32
- end
33
- end