Skip to content
This repository has been archived by the owner on Jan 29, 2022. It is now read-only.

Replace all MCollective agent calls with the agent lib. #44

Merged
merged 13 commits into from
Feb 7, 2018

Conversation

dhollinger
Copy link
Member

@dhollinger dhollinger commented Feb 4, 2018

This is an initial feature change. The goal was to mirror existing MCollective functionality, but using the Agent library. As the project moves along, additional functionality will be added.

Special thanks to @ripienaar for help.

dhollinger and others added 9 commits January 29, 2018 17:10
Added new mcollective class in the plugins directory that will execute
mcollective via ruby rather than using system calls. This will replace
and consolidate the use_mco_ruby and use_mcollective options into a
single option.
The mco helper method has been replaced by the
PuppetWebhook::MCollective class and as such has been replaced.
@coveralls
Copy link

coveralls commented Feb 4, 2018

Coverage Status

Coverage decreased (-1.2%) to 48.101% when pulling ee7d5f9 on dhollinger:mco_lib_calls into 14bd522 on voxpupuli:master.

# Currently requires puppet_webhook to be run as a non-root
# user with access to running the MCollective client.
if settings.use_mcollective
result = PuppetWebhook::Mcollective.new('r10k',
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should probably be turned into a helper method to reduce duplicated code.

Copy link
Member

@binford2k binford2k left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks decent, overall. I'm not a fan of executing a string of code that uses untrusted variables. At some point, these should probably be ported to use parameterized calls.

result = PuppetWebhook::Mcollective.new('r10k',
'deploy',
{
dtimeoute: settings.discovery_timeout,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this is a typo

# If you don't use mcollective then this hook needs to be running as r10k's user i.e. root
"#{settings.command_prefix} r10k deploy environment #{branch} #{settings.r10k_deploy_arguments}"
end
command = "#{settings.command_prefix} r10k deploy environment #{branch} #{settings.r10k_deploy_arguments}"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are all these variables sanitized already? eg, what if branch was set to ; rm -rf /;?

Copy link
Member Author

@dhollinger dhollinger Feb 5, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We are not sanitizing that, no. I'm not sure if that config parameter will still be around in the future. I'm planning on (attempting) to replace r10k open3 calls with the r10k libs (if possible).

I want to remove run_command if at all possible. (Maybe re implement it as another plugin or through something like MCO or bolt)

result = PuppetWebhook::Mcollective.new('r10k',
'deploy',
{
dtimeoute: settings.discovery_timeout,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

cut&paste, or is it really spelled like that? (if so, maybe a comment that the spelling is intentional)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch. I just spelled that wrong.

@voxpupuli voxpupuli deleted a comment Feb 5, 2018
@voxpupuli voxpupuli deleted a comment Feb 5, 2018
@voxpupuli voxpupuli deleted a comment Feb 5, 2018
timeout: settings.client_timeout
},
settings.client_cfg,
environment: branch).run.first
raise result.results[:statusmsg] unless result.results[:statuscode].zero?

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you should also check the RPC stats that the client return and check for nodes that did not respond. You can get to that via the client.stats method.

It'll be an instance of this https://github.com/puppetlabs/marionette-collective/blob/master/lib/mcollective/rpc/stats.rb and there check noresponsefrom

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point. I've added some code for that.

@ripienaar @binford2k - could one/both of you give one more pass over before I merge? I added some code to both the plugin and the deployments helper methods based on @ripienaar's comment.

results.each do |result|
raise result.results[:statusmsg] unless result.results[:statuscode].zero?
end
raise results.stats[:noresponsefrom] unless result.stats[:noresponsefrom].length.zero?

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

seems good, though raising an array is super weird :P

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Each RPC Result object is stored as an array and I couldn't think of a better way (at the time) to validate that each result status code was 0.

@dhollinger dhollinger merged commit 178cf03 into voxpupuli:master Feb 7, 2018
@dhollinger dhollinger deleted the mco_lib_calls branch February 7, 2018 16:59
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants