Issue #12614 has been updated by Chris Price.

File 12614.patch added
Status changed from Unreviewed to Accepted

Spoke with Daniel and Nan about this ticket; we are all in agreement that 
changing the code to be tolerant of either of the two prompts sounds like a 
valid solution.  However, we don't have a particularly easy way to test this 
against the range of devices that it could be in use on.

The code:

<pre>
expect(options[:prompt] || default_prompt)
</pre>

is intended to only match one specific prompt; it prefers the one explicitly 
passed in via "options" if provided, and falls back to the default_prompt 
otherwise.

The "expect" method does support regular expressions, though, so this code 
could probably be changed to use a regular expression that would match either 
prompt.

I've attached a patch against 2.7.10 that might accomplish this; it's just a 
stab in the dark, hasn't been tested at all other than to confirm it doesn't 
break our existing unit tests.  In order to consider merging it into the main 
codebase we'd probably need to add a few tests to telnet_spec.rb and also to 
test this against a few devices.

Gary, if you are able to apply this patch, test it against your device, and let 
us know how it goes--that would be very helpful information.
----------------------------------------
Bug #12614: Possible problem in util/network_device/transport/telnet.rb
https://projects.puppetlabs.com/issues/12614#change-54854

Author: Gary Richards
Status: Accepted
Priority: Normal
Assignee: 
Category: network
Target version: 
Affected Puppet version: 2.7.10
Keywords: 
Branch: 


Hi,

I think there's a bug in util/network_device/transport/telnet.rb

I've been trying to modify a copy of the existing cisco network code work with 
HP Procurve switches and spent a little while trying to work out why I couldn't 
get the enable part to work.

in util/network_device/cisco/device.rb, in the enable method:
    transport.command("enable", :prompt => /^Password:/)

It just so happens the switch I was using to test my changes doesn't have an 
enable password. So when you type 'enable' you get dumped back into slightly 
changed prompt.

Now looking at the code in util/network_device/transport/telnet.rb
    def command(cmd, options = {})
      send(cmd)
      expect(options[:prompt] || default_prompt) do |output|
        yield output if block_given?
      end
    end
    
I think that's supposed to expect either the passed in prompt or the default 
prompt.

Now as suggested, the code that calls enable expects a prompt of Password: so 
looking at the above code, that should match Password: or the default prompt. 
So according to my calculations... that should mean that my switch, which 
doesn't require a password be entered should work with the same code. But it 
doesn't seem to work.

The prompt is never matched. I modified the code in 
util/network_device/cisco/device.rb, in the enable method by removing the 
prompt (to make sure that it only matches the default prompt):
    transport.command("enable")

Lo and behold it matches the default prompt and the enable method works fine.

That suggests to me that the
    options[:prompt] || default_prompt

Part of the code doesn't work however the original developer expected?

I guess it's possible that on cisco devices it's not possible to have no 
password for enable (I have no cisco device to check on)? Regardless of that, 
it's possible this code may be used some somewhere else either now or in the 
future where someone expects it to match a specific prompt or the default 
prompt and it might not work?


-- 
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