(BOLT-286) Convert ExecutionResult to ResultSet#253
Conversation
| end | ||
|
|
||
| # Now that puppet is loaded we can include puppet mixins in data types | ||
| Bolt::ResultSet.include_iterable |
There was a problem hiding this comment.
How is Bolt::ResultSet being included? Does it matter that we won't be able to mixin iterable for commands/scripts?
There was a problem hiding this comment.
I guess the 1st question is answered: bolt/executor.
There was a problem hiding this comment.
Ah, this is preserving previous behavior. There's fallback for iterable when not using Puppet.
There was a problem hiding this comment.
I don't actually know when the fallback gets used. the ruby mixin Enumerable uses each and powers most of the iterator like behavior in ruby code(either in puppet functions or bolt)
| if result.instance_of? Bolt::ExecutionResult | ||
| result = result.unwrap | ||
| end | ||
| # TODO: Is there anything we still need to unwrap? |
There was a problem hiding this comment.
Do Puppet::DataTypes::Error display the way we want them to?
There was a problem hiding this comment.
We should be displaying the error_hash not the error datatype in bolt. I may not have fixed that properly
There was a problem hiding this comment.
I guess this is an arbitrary data type. If it's a ResultSet, that has a to_s method that writes an array of status_hash
| @notifier.shutdown | ||
|
|
||
| results_to_hash(results) | ||
| Bolt::ResultSet.new( results.map { |r| r } ) |
There was a problem hiding this comment.
Why can't we pass results directly? Is there a reason we don't want the concurrent version of an array?
There was a problem hiding this comment.
I'm not sure. it was doing this before with the hash.
| if state == 'finished' | ||
| exit_code = 0 | ||
| # If it's finished or already has a proper error simply pass it to the | ||
| # the result otherwise make sure an error is generated |
There was a problem hiding this comment.
Two spaces, looks weird.
| output.exit_code) | ||
| # TODO: what to call this it's the value minus special keys | ||
| # This should be {} if a value was set otherwise it's nil | ||
| def generic_value |
There was a problem hiding this comment.
We could call this value, and use something more generic (data?) for the pieces including special keys. I'm ok with generic_value though.
| end | ||
|
|
||
| # TODO: should this exist? | ||
| def [](node_uri) |
There was a problem hiding this comment.
Asking whether you should be able to look a value up by its name/uri? I feel like the one case that could be useful is when cross-referencing between several results. Like: several nodes performed an action against load-balanced servers, I want to group the results of that action by the server they operated against.
I feel like I'm having to stretch for examples, but it doesn't feel like much work to enable some use-cases we can't envision right now.
There was a problem hiding this comment.
I guess find already allows that. Are you suggesting that as better than []?
There was a problem hiding this comment.
find seems clearer. I'm not sure how [] should behave or if we should expose it when the underlying data structure is an array.
| self[node_uri] | ||
| end | ||
|
|
||
| # TODO delete me? |
There was a problem hiding this comment.
Anything we don't use and that's not exposed in the Puppet DataType seems like we can remove.
| self.class == other.class && @results == other.results | ||
| end | ||
|
|
||
| # TODO: this loses target information |
There was a problem hiding this comment.
Target data seems like something we'd want when serializing, but I'm not sure what we're using the serialization for.
| end | ||
|
|
||
| # name is currently just uri but should be be used instead to identify the | ||
| # Target ouside the transport or uri options. |
There was a problem hiding this comment.
That seems like hostname...
There was a problem hiding this comment.
The point of name is to give us/the user flexibility to define what matters for identity. hostname suffers from the same problem as URI.
For example the user to connect as may be part of the identity if you are running different commands as different users but it also could just be connection information. I suspect this will be a case where identity with default to url but users may end up overriding it eventually as needed.
| end | ||
|
|
||
| # this is used from 'bolt task run' | ||
| dispatch :run_task_raw do |
There was a problem hiding this comment.
What is run_task_raw used for? Not sure what we do with the block.
There was a problem hiding this comment.
we pass a block to output events when running tasks outside a plan
|
CLA signed by all contributors. |
MikaelSmith
left a comment
There was a problem hiding this comment.
Generally seems ok. I'll work on some exploratory testing around Result and ResultSet.
6e98039 to
f260b52
Compare
| private | ||
| # Warning: This will fail outside of a compilation. | ||
| # Use error_hash inside bolt. | ||
| # Is it crazy for this to behave differently outside a compiler? |
There was a problem hiding this comment.
I'm not sure what to do here. I think if we're going to change this behavior it needs to happen in a different ticket
| self.class == other.class && @results == other.results | ||
| end | ||
|
|
||
| def to_json |
There was a problem hiding this comment.
Getting an error
Plan aborted: run_task 'upgrade_pe::monolithic' failed on 1 nodes
bundler: failed to load command: bolt (/Users/michaelsmith/puppetlabs/orchestration-control/.bundle/gems/ruby/2.3.0/bin/bolt)
ArgumentError: wrong number of arguments (given 1, expected 0)
/Users/michaelsmith/puppetlabs/orchestration-control/.bundle/gems/ruby/2.3.0/bundler/gems/bolt-f260b52f88e9/lib/bolt/result_set.rb:82:in `to_json'
/Users/michaelsmith/.rbenv/versions/2.3.4/lib/ruby/2.3.0/json/common.rb:286:in `generate'
/Users/michaelsmith/.rbenv/versions/2.3.4/lib/ruby/2.3.0/json/common.rb:286:in `pretty_generate'
/Users/michaelsmith/puppetlabs/orchestration-control/.bundle/gems/ruby/2.3.0/bundler/gems/bolt-f260b52f88e9/lib/bolt/outputter/human.rb:142:in `fatal_error'
Plan I'm trying to run is
plan upgrade_pe::mono_cms(
String[1] $mono_master,
String[1] $build,
Optional[Variant[String[1], Array[String[1]]]] $compile_masters = undef,
) {
$mono = run_task('upgrade_pe::monolithic', $mono_master, build => $build)
$mono.each |$result| {
if $result.ok {
notice("${result.target} completed:\n${result.message}")
} else {
notice("${result.target} errored with message ${result.error}")
}
}
if ($mono.ok and $compile_masters) {
$_compile_masters = $compile_masters.split(',')
$cms = run_task('upgrade_pe::compile_master', $_compile_masters, master => $mono_master)
$cms.each |$result| {
if $result.ok {
notice("${result.target} completed:\n${result.message}")
} else {
notice("${result.target} errored with message ${result.error}")
}
}
}
}
There was a problem hiding this comment.
this was caused by to_json not accepting opts. it should be fixed now
This standardizes how results are handled in bolt and puppet. Previously a hash Bolt::Result objects were generated by they executor when a run_* action was taken from puppet. The puppet run_* functions then convverted those into and ExecutionResult. Now Results are built into a Bolt::ResultSet object in the executor. Both this and the bolt result are now pcore datatypes and available directly in the plan. This adds the Bolt::PAL class which is only used for testing so far. In the near future all interaction with Puppet should go through this class.
| require 'bolt_spec/pal' | ||
|
|
||
| require 'bolt/pal' | ||
| # TODO: clean this up |
There was a problem hiding this comment.
the requires. This should get cleaned up with the PAL work
This standardizes how results are handled in bolt and puppet. Previously
a hash Bolt::Result objects were generated by they executor when a
run_* action was taken from puppet. The puppet run_* functions then
convverted those into and ExecutionResult. Now Results are built into a
Bolt::ResultSet object in the executor. Both this and the bolt result
are now pcore datatypes and available directly in the plan.