Skip to content
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

Remove MiqUtil.runcmd in favor of AwesomeSpawn #510

Merged
merged 1 commit into from
Feb 2, 2021

Conversation

Fryguy
Copy link
Member

@Fryguy Fryguy commented Jan 27, 2021

end

def self.runcmd_with_logging(cmd_str, opts, params = {})
def self.run_command_with_logging(cmd_str, opts, params = {})
Copy link
Member Author

Choose a reason for hiding this comment

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

Similarly here I renamed it for clarity. There are exactly 2 callers in core specs that stub runcmd_with_logging, which is why i need the alias below, but I'll remove that in a follow up.

@@ -28,7 +28,7 @@ def self.execute(ps_command)
ps_exec = exepath
command = "start /wait cmd /c #{ps_exec} #{ps_command}"
$log.debug "PowerShell: Running command: [#{command}]" if $log
ret = MiqUtil.runcmd(command).chomp
ret = AwesomeSpawn.run!(command, :combined_output => true).output.chomp
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 one (and the next one) are super-interesting, because there is no way for them to possibly work. start and taskkill are Windows commands, and so can't be run by AwesomeSpawn nor could they have been run by MiqUtil.runcmd. I converted it for now, but it's actually broken. I think the correct way to run it is with WMIHelper.connectServer.runProcess(command, true), but I'm not 100% sure and I have no idea how to test it.

Copy link
Member

Choose a reason for hiding this comment

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

I believe this code was used a long time ago when we had agents on clients for various reasons.

Searching for MiqPowerShell yields 3 results, only one of which is an actual caller. So, I believe we will be able to delete (in a future PR?) most of the guts of MiqPowerShell. If we try really hard, we can probably delete the whole module as the only remaining use for it is to convert strings. ;-)

Copy link
Member Author

Choose a reason for hiding this comment

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

Yeah, I'm not certain we really need it anymore either...hoping we can kill it in a future PR.

result = err.result
return err.to_s if continue_on_error == true && result.exit_status == 1

raise "Command:<#{result.command_line}> exited with status:<#{result.exit_status}>\nCommand output:\n#{err}"
Copy link
Member Author

Choose a reason for hiding this comment

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

Also note this whole error handling was a bunch of bugs beforehand. command_line standalone is an non-existent variable name, and $? was never set by runcmd

@miq-bot
Copy link
Member

miq-bot commented Jan 28, 2021

This pull request is not mergeable. Please rebase and repush.

@miq-bot
Copy link
Member

miq-bot commented Jan 28, 2021

Checked commit Fryguy@729d5c0 with ruby 2.6.3, rubocop 0.82.0, haml-lint 0.35.0, and yamllint
7 files checked, 1 offense detected

lib/gems/pending/util/win32/miq-powershell.rb

  • ❗ - Line 1, Col 1 - Naming/FileName - The name of this source file (miq-powershell.rb) should use snake_case.

@chessbyte chessbyte merged commit 6e65e82 into ManageIQ:master Feb 2, 2021
@NickLaMuro
Copy link
Member

NickLaMuro commented Feb 2, 2021

😍

@Fryguy I didn't even know this was being done! 100% approve making this change, and is a big tech debt win! 🎉

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants