choria-colt 0.3.0 → 0.4.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rubocop.yml +4 -0
- data/.rubocop_todo.yml +0 -5
- data/CHANGELOG.md +47 -0
- data/README.md +8 -1
- data/Rakefile +11 -0
- data/choria-colt.gemspec +1 -0
- data/lib/choria/colt/cli/formatter.rb +3 -3
- data/lib/choria/colt/cli.rb +16 -0
- data/lib/choria/colt/version.rb +1 -1
- data/lib/choria/colt.rb +13 -1
- data/lib/choria/orchestrator/task.rb +16 -12
- metadata +17 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8d2f9c64ee41ebc49a88deff71b470baab7c4e83b921102518969fe2a35b77f1
|
4
|
+
data.tar.gz: 8f69562d201ff4addc3b44aa693d508ceca1a1623455d2ac57b273e59cd300f1
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8fd9cc5e888843d6c8954fe7d2543b4496fe861354162f499831f4ebe7cc8ccd3def73604c6d44e6f83273f71eb8364fc1b01c99581c16e8b2635adbee071aea
|
7
|
+
data.tar.gz: 5a912066de4c960ffc85debf3cc53a678ac3312f2e75daec0d999f50af7f24215f1347b6c4984de55db9f3bb357075486310ab11db685e8f866c61a06049940f
|
data/.rubocop.yml
CHANGED
data/.rubocop_todo.yml
CHANGED
@@ -6,11 +6,6 @@
|
|
6
6
|
# Note that changes in the inspected code, or installation of new
|
7
7
|
# versions of RuboCop, may require this file to be generated again.
|
8
8
|
|
9
|
-
# Offense count: 1
|
10
|
-
# Configuration parameters: CountComments, CountAsOne.
|
11
|
-
Metrics/ClassLength:
|
12
|
-
Max: 109
|
13
|
-
|
14
9
|
# Offense count: 1
|
15
10
|
# Configuration parameters: IgnoredMethods.
|
16
11
|
Metrics/CyclomaticComplexity:
|
data/CHANGELOG.md
ADDED
@@ -0,0 +1,47 @@
|
|
1
|
+
# Changelog
|
2
|
+
|
3
|
+
## [v0.4.0](https://github.com/opus-codium/choria-colt/tree/v0.4.0) (2022-04-25)
|
4
|
+
|
5
|
+
[Full Changelog](https://github.com/opus-codium/choria-colt/compare/v0.3.0...v0.4.0)
|
6
|
+
|
7
|
+
**Merged pull requests:**
|
8
|
+
|
9
|
+
- Spec: Fix tests after duration introduction [\#20](https://github.com/opus-codium/choria-colt/pull/20) ([neomilium](https://github.com/neomilium))
|
10
|
+
- CLI: Add `colt task status` subcommand [\#19](https://github.com/opus-codium/choria-colt/pull/19) ([neomilium](https://github.com/neomilium))
|
11
|
+
|
12
|
+
## [v0.3.0](https://github.com/opus-codium/choria-colt/tree/v0.3.0) (2022-04-12)
|
13
|
+
|
14
|
+
[Full Changelog](https://github.com/opus-codium/choria-colt/compare/v0.2.0...v0.3.0)
|
15
|
+
|
16
|
+
**Merged pull requests:**
|
17
|
+
|
18
|
+
- Improve CLI output [\#18](https://github.com/opus-codium/choria-colt/pull/18) ([neomilium](https://github.com/neomilium))
|
19
|
+
- CLI: Add an option to choose log level [\#17](https://github.com/opus-codium/choria-colt/pull/17) ([neomilium](https://github.com/neomilium))
|
20
|
+
- Improve stability, fix results retrieving [\#16](https://github.com/opus-codium/choria-colt/pull/16) ([neomilium](https://github.com/neomilium))
|
21
|
+
- CLI: Add an option to set log level [\#15](https://github.com/opus-codium/choria-colt/pull/15) ([neomilium](https://github.com/neomilium))
|
22
|
+
- Setup CI [\#14](https://github.com/opus-codium/choria-colt/pull/14) ([neomilium](https://github.com/neomilium))
|
23
|
+
- CLI: Format error [\#13](https://github.com/opus-codium/choria-colt/pull/13) ([neomilium](https://github.com/neomilium))
|
24
|
+
- CLI: Display default value if available for parameters [\#12](https://github.com/opus-codium/choria-colt/pull/12) ([neomilium](https://github.com/neomilium))
|
25
|
+
- Test CLI formatter using RSpec [\#11](https://github.com/opus-codium/choria-colt/pull/11) ([neomilium](https://github.com/neomilium))
|
26
|
+
- Colorize outputs [\#10](https://github.com/opus-codium/choria-colt/pull/10) ([neomilium](https://github.com/neomilium))
|
27
|
+
- Fix task input option parsing and task output display [\#9](https://github.com/opus-codium/choria-colt/pull/9) ([neomilium](https://github.com/neomilium))
|
28
|
+
- Implement continous result display [\#8](https://github.com/opus-codium/choria-colt/pull/8) ([neomilium](https://github.com/neomilium))
|
29
|
+
- Improve robustness on errors [\#7](https://github.com/opus-codium/choria-colt/pull/7) ([neomilium](https://github.com/neomilium))
|
30
|
+
- Minor code readability improvements [\#6](https://github.com/opus-codium/choria-colt/pull/6) ([neomilium](https://github.com/neomilium))
|
31
|
+
- Improve logging [\#5](https://github.com/opus-codium/choria-colt/pull/5) ([neomilium](https://github.com/neomilium))
|
32
|
+
- Force convertion to boolean if parameter is true/false [\#4](https://github.com/opus-codium/choria-colt/pull/4) ([neomilium](https://github.com/neomilium))
|
33
|
+
- Tasks: Autofill default values [\#3](https://github.com/opus-codium/choria-colt/pull/3) ([neomilium](https://github.com/neomilium))
|
34
|
+
- CLI: Support filter on Puppet classes [\#2](https://github.com/opus-codium/choria-colt/pull/2) ([neomilium](https://github.com/neomilium))
|
35
|
+
- Tasks: Structure data before return results [\#1](https://github.com/opus-codium/choria-colt/pull/1) ([neomilium](https://github.com/neomilium))
|
36
|
+
|
37
|
+
## [v0.2.0](https://github.com/opus-codium/choria-colt/tree/v0.2.0) (2022-03-03)
|
38
|
+
|
39
|
+
[Full Changelog](https://github.com/opus-codium/choria-colt/compare/v0.1.1...v0.2.0)
|
40
|
+
|
41
|
+
## [v0.1.1](https://github.com/opus-codium/choria-colt/tree/v0.1.1) (2022-03-03)
|
42
|
+
|
43
|
+
[Full Changelog](https://github.com/opus-codium/choria-colt/compare/v0.1.0...v0.1.1)
|
44
|
+
|
45
|
+
|
46
|
+
|
47
|
+
\* *This Changelog was automatically generated by [github_changelog_generator](https://github.com/github-changelog-generator/github-changelog-generator)*
|
data/README.md
CHANGED
@@ -47,7 +47,14 @@ Or install it yourself as:
|
|
47
47
|
|
48
48
|
After checking out the repo, run `bin/setup` to install dependencies. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
49
49
|
|
50
|
-
To install this gem onto your local machine, run `bundle exec rake install`.
|
50
|
+
To install this gem onto your local machine, run `bundle exec rake install`.
|
51
|
+
|
52
|
+
|
53
|
+
To release a new version:
|
54
|
+
1. update the version number in `version.rb`
|
55
|
+
1. generate CHANGELOG.md with `bundle exec rake changelog`
|
56
|
+
1. commit changes
|
57
|
+
1. run `bundle exec rake release`, which will create a git tag for the version, push git commits and the created tag, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
51
58
|
|
52
59
|
## Contributing
|
53
60
|
|
data/Rakefile
CHANGED
@@ -3,6 +3,17 @@
|
|
3
3
|
require 'bundler/gem_tasks'
|
4
4
|
require 'rubocop/rake_task'
|
5
5
|
|
6
|
+
require 'choria/colt/version'
|
7
|
+
|
6
8
|
RuboCop::RakeTask.new
|
7
9
|
|
10
|
+
require 'github_changelog_generator/task'
|
11
|
+
|
12
|
+
GitHubChangelogGenerator::RakeTask.new :changelog do |config|
|
13
|
+
config.user = 'opus-codium'
|
14
|
+
config.project = 'choria-colt'
|
15
|
+
config.since_tag = 'v0.1.0'
|
16
|
+
config.future_release = "v#{Choria::Colt::VERSION}"
|
17
|
+
end
|
18
|
+
|
8
19
|
task default: :rubocop
|
data/choria-colt.gemspec
CHANGED
@@ -37,6 +37,7 @@ Gem::Specification.new do |spec|
|
|
37
37
|
spec.add_dependency 'tty-logger'
|
38
38
|
|
39
39
|
# spec.add_development_dependency 'byebug'
|
40
|
+
spec.add_development_dependency 'github_changelog_generator'
|
40
41
|
spec.add_development_dependency 'rake'
|
41
42
|
spec.add_development_dependency 'rspec'
|
42
43
|
spec.add_development_dependency 'rubocop'
|
@@ -20,7 +20,7 @@ module Choria
|
|
20
20
|
|
21
21
|
def process_success(result)
|
22
22
|
output_lines = [
|
23
|
-
"#{pastel.host(result[:sender]).ljust(60, ' ')}duration: #{pastel.bright_white result[:data][:runtime]}",
|
23
|
+
"#{pastel.host(result[:sender]).ljust(60, ' ')}duration: #{pastel.bright_white format('%.2fs', result[:data][:runtime])}",
|
24
24
|
]
|
25
25
|
|
26
26
|
output_lines += if result.dig(:result, :_output).nil?
|
@@ -32,8 +32,8 @@ module Choria
|
|
32
32
|
output_lines.join("\n")
|
33
33
|
end
|
34
34
|
|
35
|
-
def process_error(result) # rubocop:disable Metrics/AbcSize
|
36
|
-
host = "#{pastel.bright_red '⨯'} #{pastel.host(result[:sender]).ljust(60, ' ')}duration: #{pastel.bright_white result[:data][:runtime]}"
|
35
|
+
def process_error(result) # rubocop:disable Metrics/AbcSize, Metrics/MethodLength
|
36
|
+
host = "#{pastel.bright_red '⨯'} #{pastel.host(result[:sender]).ljust(60, ' ')}duration: #{pastel.bright_white format('%.2fs', result[:data][:runtime])}"
|
37
37
|
output = result.dig(:result, '_output')
|
38
38
|
error_details = JSON.pretty_generate(result.dig(:result, :_error, :details)).split "\n"
|
39
39
|
error_description = [
|
data/lib/choria/colt/cli.rb
CHANGED
@@ -78,6 +78,22 @@ module Choria
|
|
78
78
|
end
|
79
79
|
end
|
80
80
|
|
81
|
+
desc 'status <task id>', 'Show task results'
|
82
|
+
long_desc <<~DESC
|
83
|
+
Show results from a previously ran task.
|
84
|
+
|
85
|
+
A task ID is required to request Choria services and retrieve results.
|
86
|
+
DESC
|
87
|
+
def status(task_id)
|
88
|
+
results = colt.wait_bolt_task task_id do |result|
|
89
|
+
$stdout.puts formatter.process_result(result)
|
90
|
+
end
|
91
|
+
|
92
|
+
File.write 'last_run.json', JSON.pretty_generate(results)
|
93
|
+
rescue Choria::Orchestrator::Error => e
|
94
|
+
raise Thor::Error, "#{e.class}: #{e}"
|
95
|
+
end
|
96
|
+
|
81
97
|
no_commands do # rubocop:disable Metrics/BlockLength
|
82
98
|
def colt
|
83
99
|
@colt ||= Choria::Colt.new logger: logger
|
data/lib/choria/colt/version.rb
CHANGED
data/lib/choria/colt.rb
CHANGED
@@ -21,7 +21,7 @@ module Choria
|
|
21
21
|
|
22
22
|
def run_bolt_task(task_name, input: {}, targets: nil, targets_with_classes: nil, &block)
|
23
23
|
logger.debug "Instantiate task '#{task_name}' and validate input"
|
24
|
-
task = Choria::Orchestrator::Task.new(task_name, input: input, orchestrator: orchestrator)
|
24
|
+
task = Choria::Orchestrator::Task.new(name: task_name, input: input, orchestrator: orchestrator)
|
25
25
|
|
26
26
|
task.on_result(&block) if block_given?
|
27
27
|
|
@@ -33,6 +33,18 @@ module Choria
|
|
33
33
|
raise
|
34
34
|
end
|
35
35
|
|
36
|
+
def wait_bolt_task(task_id, &block)
|
37
|
+
task = Choria::Orchestrator::Task.new(id: task_id, orchestrator: orchestrator)
|
38
|
+
|
39
|
+
task.on_result(&block) if block_given?
|
40
|
+
|
41
|
+
task.wait
|
42
|
+
task.results
|
43
|
+
rescue Choria::Orchestrator::Error => e
|
44
|
+
logger.error e.message
|
45
|
+
raise
|
46
|
+
end
|
47
|
+
|
36
48
|
def tasks(environment:, cache: nil)
|
37
49
|
tasks_names = orchestrator.tasks_support.tasks(environment).map do |task|
|
38
50
|
task['name']
|
@@ -8,17 +8,19 @@ module Choria
|
|
8
8
|
class Task
|
9
9
|
class Error < Orchestrator::Error; end
|
10
10
|
|
11
|
-
attr_reader :name, :input, :environment, :rpc_results, :results
|
11
|
+
attr_reader :id, :name, :input, :environment, :rpc_results, :results
|
12
12
|
attr_accessor :rpc_responses
|
13
13
|
|
14
|
-
def initialize(name,
|
14
|
+
def initialize(orchestrator:, id: nil, name: nil, input: {}, environment: 'production')
|
15
|
+
@id = id
|
15
16
|
@name = name
|
16
17
|
@environment = environment
|
17
18
|
@orchestrator = orchestrator
|
18
|
-
@input = default_input.merge input
|
19
|
-
|
20
19
|
@results = []
|
21
20
|
|
21
|
+
return if @name.nil?
|
22
|
+
|
23
|
+
@input = default_input.merge input
|
22
24
|
logger.debug "Task inputs: #{input}"
|
23
25
|
validate_inputs
|
24
26
|
end
|
@@ -32,16 +34,18 @@ module Choria
|
|
32
34
|
end
|
33
35
|
|
34
36
|
def wait # rubocop:disable Metrics/AbcSize
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
37
|
+
if @id.nil?
|
38
|
+
rpc_responses_ok, rpc_responses_error = rpc_responses.partition { |res| (res[:body][:statuscode]).zero? }
|
39
|
+
rpc_responses_error.each do |res|
|
40
|
+
logger.error "Task request failed on '#{res[:senderid]}':\n#{pp res}"
|
41
|
+
end
|
39
42
|
|
40
|
-
|
43
|
+
task_ids = rpc_responses_ok.map { |res| res[:body][:data][:task_id] }.uniq
|
41
44
|
|
42
|
-
|
45
|
+
raise NotImplementedError, "Multiple task IDs: #{task_ids}" unless task_ids.count == 1
|
43
46
|
|
44
|
-
|
47
|
+
@id = task_ids.first
|
48
|
+
end
|
45
49
|
|
46
50
|
wait_results
|
47
51
|
end
|
@@ -76,7 +80,7 @@ module Choria
|
|
76
80
|
def wait_results
|
77
81
|
raise 'Task ID is required!' if @id.nil?
|
78
82
|
|
79
|
-
logger.info
|
83
|
+
logger.info "Waiting task #{@id} results…"
|
80
84
|
|
81
85
|
@results = []
|
82
86
|
@rpc_results = []
|
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.
|
4
|
+
version: 0.4.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-04-
|
11
|
+
date: 2022-04-25 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|
@@ -108,6 +108,20 @@ dependencies:
|
|
108
108
|
- - ">="
|
109
109
|
- !ruby/object:Gem::Version
|
110
110
|
version: '0'
|
111
|
+
- !ruby/object:Gem::Dependency
|
112
|
+
name: github_changelog_generator
|
113
|
+
requirement: !ruby/object:Gem::Requirement
|
114
|
+
requirements:
|
115
|
+
- - ">="
|
116
|
+
- !ruby/object:Gem::Version
|
117
|
+
version: '0'
|
118
|
+
type: :development
|
119
|
+
prerelease: false
|
120
|
+
version_requirements: !ruby/object:Gem::Requirement
|
121
|
+
requirements:
|
122
|
+
- - ">="
|
123
|
+
- !ruby/object:Gem::Version
|
124
|
+
version: '0'
|
111
125
|
- !ruby/object:Gem::Dependency
|
112
126
|
name: rake
|
113
127
|
requirement: !ruby/object:Gem::Requirement
|
@@ -189,6 +203,7 @@ files:
|
|
189
203
|
- ".rspec"
|
190
204
|
- ".rubocop.yml"
|
191
205
|
- ".rubocop_todo.yml"
|
206
|
+
- CHANGELOG.md
|
192
207
|
- Gemfile
|
193
208
|
- README.md
|
194
209
|
- Rakefile
|