Issue #8475 has been updated by Jeff McCune.

Status changed from Accepted to Needs Decision

# Need Decision #

The ssh_remote_execute method is a thin wrapper to Net::SSH.start which is 
difficult to mock.

Reading online, I'm not sure if we should be mocking API's we don't own.  The 
recommendation seems to be implement a thin wrapper and mock that wrapper, 
which we've already done.

I couldn't quickly figure out how to add coverage for this code:

<pre>
    # This is the single place to make SSH calls.  It will handle collecting 
STDOUT
    # in a line oriented manner, printing it to debug log destination and 
checking the
    # exit code of the remote call.  This should also make it much easier to do 
unit testing on
    # all of the other methods that need this functionality.  Finally, it 
should provide
    # one place to swap out the back end SSH implementation if need be.
    def ssh_remote_execute(server, login, command, keyfile = nil)
      Puppet.info "Executing remote command ..."
      Puppet.debug "Command: #{command}"
      buffer = String.new
      exit_code = nil
      Net::SSH.start(server, login, :keys => [ keyfile ]) do |session|
        session.open_channel do |channel|
          channel.on_data do |ch, data|
            buffer << data
            if buffer =~ /\n/
              lines = buffer.split("\n")
              buffer = lines.length > 1 ? lines.pop : String.new
              lines.each do |line|
                Puppet.debug(line)
              end
            end
          end
          channel.on_eof do |ch|
            # Display anything remaining in the buffer
            unless buffer.empty?
              Puppet.debug(buffer)
            end
          end
          channel.on_request("exit-status") do |ch, data|
            exit_code = data.read_long
            Puppet.debug("SSH Command Exit Code: #{exit_code}")
          end
          # Finally execute the command
          channel.exec(command)
        end
      end
      Puppet.info "Executing remote command ... Done"
      exit_code
    end
</pre>
----------------------------------------
Refactor #8475: Add test coverage for ssh_remote_execute method
https://projects.puppetlabs.com/issues/8475

Author: Jeff McCune
Status: Needs Decision
Priority: Normal
Assignee: Jeff McCune
Category: cloudpack
Target version: 0.6.0
Keywords: 
Branch: 


# Overview #

With the refactor done in #8369 much of the behavior of the install action is 
easier to test.  However, we're missing test coverage for the 
`ssh_remote_execute` method and in particular if sudo is prepended to the 
execution command if we aren't running as root.


-- 
You have received this notification because you have either subscribed to it, 
or are involved in it.
To change your notification preferences, please click here: 
http://projects.puppetlabs.com/my/account

-- 
You received this message because you are subscribed to the Google Groups 
"Puppet Bugs" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/puppet-bugs?hl=en.

Reply via email to