-
Notifications
You must be signed in to change notification settings - Fork 6
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add concurrency option #7
Conversation
@@ -1,6 +1,7 @@ | |||
require 'hammer_cli' | |||
require 'hammer_cli_foreman/host' | |||
require 'net/ssh/multi' | |||
require 'pry' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
leftover from testing? :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Derp. Let me get rid of that...
I also noticed there were some race conditions affecting net-ssh-multi when setting concurrent_connections -- fortunately, they have been fixed in an upstream pull request. I've updated the gemspec to reflect the new dependency. See this pull request for more information on the race conditions. |
Thats, OK, we can handle the version dependency in our packaging, I guess... |
@dudemcbacon BTW, could you squash your commits together into one? |
Done! |
@@ -12,6 +12,7 @@ class Command < HammerCLIForeman::Command | |||
|
|||
command_name 'SSH to hosts' | |||
option %w(-c --command), 'COMMAND', _('Command to execute'), :attribute_name => :command, :required => true | |||
option %w(-n --concurrent), 'CONCURRENCY', _('Number of concurrent SSH sessions'), :attribute_name => :concurrent |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should we provide a default? i think asking each time could be annoying ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd actually prefer if we didn't. It'd make the code more complex. When the option isn't set and no default is specified concurrent == nil. When concurrent_connections is set to nil (and passed to Net::SSH::Multi) it disables the concurrency limit. If we set a default value for concurrent it will be set to whatever the default is even if the option isn't specified. We'd either need to add an option to disable concurrency limits or use some other method to determine when the option wasn't actually passed by the user.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"it disables the concurrency limit." means 1 or infinity?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
infinity -- as in the way it behaved before this pull request.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I guess if it's like before I'm OK with it - and see this PR even more valuable as it's making a limit possible. 🎯
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can add
option ....... do |o|
Integer(o)
end
for Hammer to ensure valid Integer is given
+1 to not force user to set concurrency limit
I have modified the pull request slightly in the following ways:
This fixes the assumption I made about the .to_i method when used with nil and assures the following behavior:
|
@@ -28,6 +29,13 @@ def request_params | |||
end | |||
|
|||
def execute | |||
if concurrent && concurrent.to_i == 0 | |||
warn _("specify 1 or more concurrent hosts") | |||
return HammerCLI::EX_OK |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd prefer to
signal_usage_error(_("specify 1 or more concurrent hosts")) if (!concurrent.nil? && concurrent < 1)
to get proper exit code and error handling
Besides the minor things mentioned inline it looks good. Thanks @dudemcbacon! |
@dudemcbacon, could you please rebase? |
I have rebased this pull request and modified the code as suggested by @mbacovsky. |
@@ -12,6 +12,10 @@ class Command < HammerCLIForeman::Command | |||
|
|||
command_name 'SSH to hosts' | |||
option %w(-c --command), 'COMMAND', _('Command to execute'), :attribute_name => :command, :required => true | |||
option %w(-n --concurrent), 'CONCURRENCY', _('Number of concurrent SSH sessions'), :attribute_name => :concurrent do |o| | |||
Integer(o) | |||
o.nil? ? o : o.to_i |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this line is not neccessary, as the block is executed only if the parameter was set
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ahh, good catch. I guess I didn't think about it that much. I will remove it.
@dudemcbacon, thanks for the update! Looks good now! |
…hat SSH is run on; also updating gemspec dependency for net-ssh-multi to address race conditions affecting that gem and concurrency.
I have removed the line you commented on in the option block. |
The line you're referring to was to ensure that the concurrent variable was set to either nil or a number > 0. As you said in your inline comment, it's not necessary. If the option block is called it will be a number. If the option block is not called, it will be nil. If the integer is 0, it will be filtered by the signal_usage_error method. |
👍 @dudemcbacon, that makes sense. Thank you for your patience ;) 🍺 Merging... |
w00t! |
Adding concurrency option to control the number of concurrent hosts that SSH is run on.