Discussion:
[Fab-user] HP switches and run() received nonzero return code -1 while executing
a***@free.fr
2016-11-17 15:42:46 UTC
Permalink
Hello,


I'm new here, and before writing this email I searched on the archives without success, so please excuse me if this question was already asked.

I'm trying to "display current-configuration" through ssh on HP 5820 series switches with this piece of code :

from fabric.api import *

env.user = 'toto'
env.hosts = ['192.168.72.10']
def displaycurr():
with settings(hide('warnings'), warn_only=True):
# below command is normally used to prevent the "more"
run('screen-length disable ', shell=False)
run('display current-configuration ', shell=False)


As written in the email's subject, every ran command returns a nonzero code, implying that even if I forced the "keep running" with the warn_only=True option, after each run command the ssh session is exited.
Therefore I lost the first command advantage and then I got the "more" during the second.

Same code (without warn_only) and the right Cisco commands does work well on Cisco switches.


By any chance, is there someone that experienced the same issue (not necessarily with HP switches) and managed to keep the ssh session opened between both commands?


Many Thanks,

Regards,


Alexandre
Brandon Whaley
2016-11-17 18:54:24 UTC
Permalink
Fabric was written with accessing *nix based servers in mind, so some
things it does don't work correctly with non-standard ssh implementations.
I'm not sure if HP is returning the -1 code or if Fabric is not getting one
at all and as such returns -1 as an error value. Either way, it sounds
like you'll always need to use warn_only=True for this device.

One of the biggest differences between an interactive ssh session and
Fabric is that when you use run(), while only one ssh connection is ever
made, a new command execution session is initiated over that connection for
each operation. That means things like environment variables are "fresh"
at every call to run(). I suspect this is why your "screen-length disable"
command does not take effect, since HP's docs state "Note that this command
is applicable to the current user only and when a user re-logs in, the
settings restore to the system default."

Have you tried sending newlines between two commands in the same run()?
That might be a workaround for you if the switch allows it.
Post by a***@free.fr
Hello,
I'm new here, and before writing this email I searched on the archives
without success, so please excuse me if this question was already asked.
I'm trying to "display current-configuration" through ssh on HP 5820
from fabric.api import *
env.user = 'toto'
env.hosts = ['192.168.72.10']
# below command is normally used to prevent the "more"
run('screen-length disable ', shell=False)
run('display current-configuration ', shell=False)
As written in the email's subject, every ran command returns a nonzero
code, implying that even if I forced the "keep running" with the
warn_only=True option, after each run command the ssh session is exited.
Therefore I lost the first command advantage and then I got the "more" during the second.
Same code (without warn_only) and the right Cisco commands does work well
on Cisco switches.
By any chance, is there someone that experienced the same issue (not
necessarily with HP switches) and managed to keep the ssh session opened
between both commands?
Many Thanks,
Regards,
Alexandre
_______________________________________________
Fab-user mailing list
https://lists.nongnu.org/mailman/listinfo/fab-user
Nathan M
2016-11-17 21:11:20 UTC
Permalink
Hi,

Instead of fiddling with fabric's ssh implementation, I would suggest two
course of action:
- find out why the binary is not returning 0 on success and fix the error
(easier said than done I know)
- if that's not possible, you can force a 0 return on your command, for
instance : run('screen-length disable || exit 0', shell=False)

Regards,
Nathan
a***@free.fr
2016-11-18 08:56:51 UTC
Permalink
Hello Brandon,


(sorry for the direct reply, I didn't notice that the To: wasn't to the ML)

Thank you for your reply.
Unfortunately sending newlines (or carriage return) between two commands inside one run() didn't help.
Since between each run() I'm loosing my execution session, are you aware about another ssh module for Python that doesn't have this behaviour?

Many Thanks,

Regards,


Alexandre


----- Original Message -----
From: "Brandon Whaley" <***@gmail.com>
To: "a hocquel" <***@free.fr>, fab-***@nongnu.org
Sent: Thursday, 17 November, 2016 7:54:24 PM
Subject: Re: [Fab-user] HP switches and run() received nonzero return code -1 while executing


Fabric was written with accessing *nix based servers in mind, so some things it does don't work correctly with non-standard ssh implementations. I'm not sure if HP is returning the -1 code or if Fabric is not getting one at all and as such returns -1 as an error value. Either way, it sounds like you'll always need to use warn_only=True for this device.


One of the biggest differences between an interactive ssh session and Fabric is that when you use run(), while only one ssh connection is ever made, a new command execution session is initiated over that connection for each operation. That means things like environment variables are "fresh" at every call to run(). I suspect this is why your "screen-length disable" command does not take effect, since HP's docs state "Note that this command is applicable to the current user only and when a user re-logs in, the settings restore to the system default."


Have you tried sending newlines between two commands in the same run()? That might be a workaround for you if the switch allows it.


On Thu, Nov 17, 2016 at 10:43 AM < ***@free.fr > wrote:


Hello,


I'm new here, and before writing this email I searched on the archives without success, so please excuse me if this question was already asked.

I'm trying to "display current-configuration" through ssh on HP 5820 series switches with this piece of code :

from fabric.api import *

env.user = 'toto'
env.hosts = ['192.168.72.10']
def displaycurr():
with settings(hide('warnings'), warn_only=True):
# below command is normally used to prevent the "more"
run('screen-length disable ', shell=False)
run('display current-configuration ', shell=False)


As written in the email's subject, every ran command returns a nonzero code, implying that even if I forced the "keep running" with the warn_only=True option, after each run command the ssh session is exited.
Therefore I lost the first command advantage and then I got the "more" during the second.

Same code (without warn_only) and the right Cisco commands does work well on Cisco switches.


By any chance, is there someone that experienced the same issue (not necessarily with HP switches) and managed to keep the ssh session opened between both commands?


Many Thanks,

Regards,


Alexandre




_______________________________________________
Fab-user mailing list
Fab-***@nongnu.org
https://lists.nongnu.org/mailman/listinfo/fab-user
Brandon Whaley
2016-11-18 15:00:01 UTC
Permalink
You may be able to use the underlying paramiko library that Fabric itself
relies on, but I don't have any personal experience with it.
Post by a***@free.fr
Hello Brandon,
(sorry for the direct reply, I didn't notice that the To: wasn't to the ML)
Thank you for your reply.
Unfortunately sending newlines (or carriage return) between two commands
inside one run() didn't help.
Since between each run() I'm loosing my execution session, are you aware
about another ssh module for Python that doesn't have this behaviour?
Many Thanks,
Regards,
Alexandre
----- Original Message -----
Sent: Thursday, 17 November, 2016 7:54:24 PM
Subject: Re: [Fab-user] HP switches and run() received nonzero return code
-1 while executing
Fabric was written with accessing *nix based servers in mind, so some
things it does don't work correctly with non-standard ssh implementations.
I'm not sure if HP is returning the -1 code or if Fabric is not getting one
at all and as such returns -1 as an error value. Either way, it sounds like
you'll always need to use warn_only=True for this device.
One of the biggest differences between an interactive ssh session and
Fabric is that when you use run(), while only one ssh connection is ever
made, a new command execution session is initiated over that connection for
each operation. That means things like environment variables are "fresh" at
every call to run(). I suspect this is why your "screen-length disable"
command does not take effect, since HP's docs state "Note that this command
is applicable to the current user only and when a user re-logs in, the
settings restore to the system default."
Have you tried sending newlines between two commands in the same run()?
That might be a workaround for you if the switch allows it.
Hello,
I'm new here, and before writing this email I searched on the archives
without success, so please excuse me if this question was already asked.
I'm trying to "display current-configuration" through ssh on HP 5820
from fabric.api import *
env.user = 'toto'
env.hosts = ['192.168.72.10']
# below command is normally used to prevent the "more"
run('screen-length disable ', shell=False)
run('display current-configuration ', shell=False)
As written in the email's subject, every ran command returns a nonzero
code, implying that even if I forced the "keep running" with the
warn_only=True option, after each run command the ssh session is exited.
Therefore I lost the first command advantage and then I got the "more" during the second.
Same code (without warn_only) and the right Cisco commands does work well
on Cisco switches.
By any chance, is there someone that experienced the same issue (not
necessarily with HP switches) and managed to keep the ssh session opened
between both commands?
Many Thanks,
Regards,
Alexandre
_______________________________________________
Fab-user mailing list
https://lists.nongnu.org/mailman/listinfo/fab-user
_______________________________________________
Fab-user mailing list
https://lists.nongnu.org/mailman/listinfo/fab-user
Jeff Forcier
2016-11-18 16:57:54 UTC
Permalink
Grump, I didn't read the rest of the thread hard enough. If newlines don't
work I'd double check the manual for your switch in case that continuation
option exists - otherwise, as mentioned, you may be out of luck :( SSH
simply isn't built the way you need it to be.
This isn't a limitation of Fabric itself, but is specific to how SSH works
- to encapsulate each command as a discrete result of output, exit code,
etc, one must use a distinct command-execution call to the SSH daemon for
each command. (This is in the FAQ as http://www.fabfile.org/faq.
html#my-cd-workon-export-etc-calls-don-t-seem-to-work though the title is
a bit specific.)
If your use case can deal with that limitation - i.e. if your intent is to
just run the commands and not do programmatic things with its output or
exit codes partway through - you could try submitting a multiline string as
run("""screen-length disable
display current-configuration""")
(Or use '\n', etc.)
How well that will work depends on how your switch's shell behaves with
that style of 'batched' input.
If the switch's shell supports any sort of single-line continuations (like
'&&' or ';' in typical Unix shells) that's another approach. You could
leverage the 'with prefix()' feature of Fabric then too (
http://docs.fabfile.org/en/latest/api/core/context_
managers.html#fabric.context_managers.prefix).
Good luck,
Jeff
Post by Brandon Whaley
You may be able to use the underlying paramiko library that Fabric itself
relies on, but I don't have any personal experience with it.
Post by a***@free.fr
Hello Brandon,
(sorry for the direct reply, I didn't notice that the To: wasn't to the ML)
Thank you for your reply.
Unfortunately sending newlines (or carriage return) between two commands
inside one run() didn't help.
Since between each run() I'm loosing my execution session, are you aware
about another ssh module for Python that doesn't have this behaviour?
Many Thanks,
Regards,
Alexandre
----- Original Message -----
Sent: Thursday, 17 November, 2016 7:54:24 PM
Subject: Re: [Fab-user] HP switches and run() received nonzero return
code -1 while executing
Fabric was written with accessing *nix based servers in mind, so some
things it does don't work correctly with non-standard ssh implementations.
I'm not sure if HP is returning the -1 code or if Fabric is not getting one
at all and as such returns -1 as an error value. Either way, it sounds like
you'll always need to use warn_only=True for this device.
One of the biggest differences between an interactive ssh session and
Fabric is that when you use run(), while only one ssh connection is ever
made, a new command execution session is initiated over that connection for
each operation. That means things like environment variables are "fresh" at
every call to run(). I suspect this is why your "screen-length disable"
command does not take effect, since HP's docs state "Note that this command
is applicable to the current user only and when a user re-logs in, the
settings restore to the system default."
Have you tried sending newlines between two commands in the same run()?
That might be a workaround for you if the switch allows it.
Hello,
I'm new here, and before writing this email I searched on the archives
without success, so please excuse me if this question was already asked.
I'm trying to "display current-configuration" through ssh on HP 5820
from fabric.api import *
env.user = 'toto'
env.hosts = ['192.168.72.10']
# below command is normally used to prevent the "more"
run('screen-length disable ', shell=False)
run('display current-configuration ', shell=False)
As written in the email's subject, every ran command returns a nonzero
code, implying that even if I forced the "keep running" with the
warn_only=True option, after each run command the ssh session is exited.
Therefore I lost the first command advantage and then I got the "more"
during the second.
Same code (without warn_only) and the right Cisco commands does work
well on Cisco switches.
By any chance, is there someone that experienced the same issue (not
necessarily with HP switches) and managed to keep the ssh session opened
between both commands?
Many Thanks,
Regards,
Alexandre
_______________________________________________
Fab-user mailing list
https://lists.nongnu.org/mailman/listinfo/fab-user
_______________________________________________
Fab-user mailing list
https://lists.nongnu.org/mailman/listinfo/fab-user
_______________________________________________
Fab-user mailing list
https://lists.nongnu.org/mailman/listinfo/fab-user
--
Jeff Forcier
Unix sysadmin; Python engineer
http://bitprophet.org
--
Jeff Forcier
Unix sysadmin; Python engineer
http://bitprophet.org
Loading...