Hi all,
I went to troubles while using the SSH probe: my command line was too long, and SSH probe split it at 150 characters. But it was just in the middle of a replacement string in my “sed” command… and of course the result was not the one I expected.
So I would like to suggest the following patch in file testerman/plugins/probe/ssh/SshProbe.py:
--- SshProbe.py.orig 2012-02-10 17:24:27.561633678 +0100
+++ SshProbe.py 2012-02-10 17:50:59.539372205 +0100
@@ -285,11 +285,13 @@
status = None
try:
# Split the command on multiple lines - the pseudo terminal may limit it ??
- i = 0
size = MAX_TERMINAL_LINE_LENGTH
splitcmd = []
- while i < len(self._command):
- splitcmd.append(self._command[i:i+size])
+ presplitcmd = self._command.split('\n')
+ for cmd in presplitcmd:
+ i = 0
+ while i < len(cmd):
+ splitcmd.append(cmd[i:i+size])
i += size
self._ssh.sendline('\\\n'.join(splitcmd))
Thanks,
Mathias
�
Hi all,
�
I went to troubles while using the SSH probe: my command line was too long, and SSH probe split it at 150 characters. But it was just in the middle of a replacement string in my �sed� command� and of course the result was not the one I expected.
So I would like to suggest the following patch in file testerman/plugins/probe/ssh/SshProbe.py:
�
--- SshProbe.py.orig��� 2012-02-10 17:24:27.561633678 +0100
+++ SshProbe.py 2012-02-10 17:50:59.539372205 +0100
@@ -285,11 +285,13 @@
��������������� status = None
��������������� try:
����������������������� # Split the command on multiple lines - the pseudo terminal may limit it ??
-���������������������� i = 0
����������������������� size = MAX_TERMINAL_LINE_LENGTH
����������������������� splitcmd = []
-���������������������� while i < len(self._command):
-������������������������������ splitcmd.append(self._command[i:i+size])
+���������������������� presplitcmd = self._command.split('\n')
+���������������������� for cmd in presplitcmd:
+������������������������������ i = 0
+��������� ���������������������while i < len(cmd):
+�������������������������������������� splitcmd.append(cmd[i:i+size])
������������������������������� i += size
�
����������������������� self._ssh.sendline('\\\n'.join(splitcmd))
�
Thanks,
Mathias
Sure,
Here was the situation before I tried to patch SSH probe:
I have a class which is in charge of replacing values in configuration files; in this class the function “changeValue” build the command line, and ask SSH probe to run the command remotely (this is done in sendSshCmd method):
class RemoteConfFileManager:
…
def changeValue(self, modifications, separator = '='):
"""
Change the value of the key in a configuration-like file
@param modifications: list of tuple (<name>, <newValue>) where name is the name
of the key entry to change, and <newValue> is the new value for that entry key
@type modifications: tuple
@param separator: caracter used to separate key and value in target file format.
@type separator: string
@return: True if changes succeed, False otherwise.
@rtype: boolean
"""
_sedCmd = ""
for _pair in modifications:
_sedCmd += " -e 's|^%s.*%s.*|%s%s%s|'" % (_pair[0], separator, _pair[0], separator, _pair[1])
_ret, _output = ongManager.sendSshCmd(sshPort = self._sshPort, cmd = "sed -i %s %s" % (_sedCmd, self._remoteFileName),
expectedResult = not_(pattern(r'No such file or directory')))
if not _ret:
log("changeValue fails:\n%s" % _output)
return _ret
In my ATS, I then do something like this:
remoteConfFileManager.changeValue([ ("ManagementServer.URL", "http://%s/openacs/acs" % acsIpPort), ("ManagementServer.STUNEnable", "false") ])
so my command line looks like:
sed -i -e 's|^ManagementServer.URL.*=.*|ManagementServer.URL=http://10.10.12.216:8181/openacs/acs|' -e 's|^ManagementServer.STUNEnable.*=.*|ManagementServer.STUNEnable=false|' /home/ong//install/factory/cfg/tr069Settings.cfg
My configuration file looks like this:
ManagementServer.URL=http://openacs-server.actility.com:8181/openacs/acs
ManagementServer.STUNEnable=true
and I got the following result with the original ssh probe:
ManagementServer.URL=http://10.10.12.216:8181/openacs/acs
Managemen
tServer.STUNEnable=false
So additionally to the patch I propose, I also modified my function this way:
def changeValue(self, modifications, separator = '='):
"""
Change the value of the key in a configuration-like file
@param modifications: list of tuple (<name>, <newValue>) where name is the name
of the key entry to change, and <newValue> is the new value for that entry key
@type modifications: tuple
@param separator: caracter used to separate key and value in target file format.
@type separator: string
@return: True if changes succeed, False otherwise.
@rtype: boolean
"""
_sedCmd = ""
for _pair in modifications:
_sedCmd += " -e 's|^%s.*%s.*|%s%s%s|' \n" % (_pair[0], separator, _pair[0], separator, _pair[1])
_ret, _output = ongManager.sendSshCmd(sshPort = self._sshPort, cmd = "sed -i %s %s" % (_sedCmd, self._remoteFileName),
expectedResult = not_(pattern(r'No such file or directory')))
if not _ret:
log("changeValue fails:\n%s" % _output)
return _ret
maybe ‘\n’ is not the better choice here…
Mathias
From: Sebastien Lefevre [mailto:seb.l...@gmail.com]
Sent: samedi 11 février 2012 14:18
To: testerm...@googlegroups.com
Cc: mathias louiset
Subject: Re: [testerman-users] patch proposal on Ssh probe
Hi Mathias,
would you share the command line you're trying to execute ?
Actually, the patch you proposed breaks user-provided multiline commands; I played a little around it to keep this support, but would like to test with your specific case to understand why the initial version did not work with you.
thanks,
-seb
Le 10/02/2012 18:21, mathias louiset a écrit :
Hi all,
I went to troubles while using the SSH probe: my command line was too long, and SSH probe split it at 150 characters. But it was just in the middle of a replacement string in my “sed” command… and of course the result was not the one I expected.
So I would like to suggest the following patch in file testerman/plugins/probe/ssh/SshProbe.py:
--- SshProbe.py.orig 2012-02-10 17:24:27.561633678 +0100
+++ SshProbe.py 2012-02-10 17:50:59.539372205 +0100
@@ -285,11 +285,13 @@
status = None
try:
# Split the command on multiple lines - the pseudo terminal may limit it ??
- i = 0
Sure,
�
Here was the situation before I tried to patch SSH probe:
�
I have a class which is in charge of replacing values in configuration files; in this class the function �changeValue� build the command line, and ask SSH probe to run the command remotely (this is done in sendSshCmd method):
�������������������������������
class RemoteConfFileManager:
�
��������������� def changeValue(self, modifications, separator = '='):
������������������������������� """
������������������������������� Change the value of the key in a configuration-like file
������������������������������� @param modifications: list of tuple (<name>, <newValue>) where name is the name
������������������������������� of the key entry to change, and <newValue> is the new value for that entry key
������������������������������� @type modifications: tuple
������������������������������� @param separator: caracter used to separate key and value in target file format.
������������������������������� @type separator: string
������������������������������� @return: True if changes succeed, False otherwise.
������������������������������� @rtype: boolean
������������������������������� """
������������������������������� _sedCmd = ""
������������������������������� for _pair in modifications:
����������������������������������������������� _sedCmd += " -e 's|^%s.*%s.*|%s%s%s|'" % (_pair[0], separator, _pair[0], separator, _pair[1])
������������������������������� _ret, _output = ongManager.sendSshCmd(sshPort = self._sshPort, cmd = "sed -i %s %s" % (_sedCmd, self._remoteFileName),
����������������������������������������������� expectedResult = not_(pattern(r'No such file or directory')))
������������������������������� if not _ret:
����������������������������������������������� log("changeValue fails:\n%s" % _output)
�������������������������������
������������������������������� return _ret
�������������������������������
�
In my ATS, I then do something like this:
remoteConfFileManager.changeValue([ ("ManagementServer.URL", "http://%s/openacs/acs" % acsIpPort), ("ManagementServer.STUNEnable", "false")� ])
�
so my command line looks like:
sed -i -e 's|^ManagementServer.URL.*=.*|ManagementServer.URL=http://10.10.12.216:8181/openacs/acs|' -e 's|^ManagementServer.STUNEnable.*=.*|ManagementServer.STUNEnable=false|' /home/ong//install/factory/cfg/tr069Settings.cfg
�
My configuration file looks like this:
ManagementServer.URL=http://openacs-server.actility.com:8181/openacs/acs
ManagementServer.STUNEnable=true
�
and I got the following result with the original ssh probe:
ManagementServer.URL=http://10.10.12.216:8181/openacs/acs
Managemen
tServer.STUNEnable=false
�
�
So additionally to the patch I propose, I also modified my function this way:
��������������� def changeValue(self, modifications, separator = '='):
������������������������������� """
������������������������������� Change the value of the key in a configuration-like file
������������������������������� @param modifications: list of tuple (<name>, <newValue>) where name is the name
������������������������������� of the key entry to change, and <newValue> is the new value for that entry key
������������������������������� @type modifications: tuple
������������������������������� @param separator: caracter used to separate key and value in target file format.
������������������������������� @type separator: string
������������������������������� @return: True if changes succeed, False otherwise.
������������������������������� @rtype: boolean
������������������������������� """
������������������������������� _sedCmd = ""
������������������������������� for _pair in modifications:
����������������������������������������������� _sedCmd += " -e 's|^%s.*%s.*|%s%s%s|' \n" % (_pair[0], separator, _pair[0], separator, _pair[1])
������������������������������� _ret, _output = ongManager.sendSshCmd(sshPort = self._sshPort, cmd = "sed -i %s %s" % (_sedCmd, self._remoteFileName),
����������������������������������������������� expectedResult = not_(pattern(r'No such file or directory')))
������������������������������� if not _ret:
����������������������������������������������� log("changeValue fails:\n%s" % _output)
�������������������������������
������������������������������� return _ret
�������������������������������
�
�
maybe �\n� is not the better choice here�
�
Mathias
�
From: Sebastien Lefevre [mailto:seb.l...@gmail.com]
Sent: samedi 11 f�vrier 2012 14:18
To: testerm...@googlegroups.com
Cc: mathias louiset
Subject: Re: [testerman-users] patch proposal on Ssh probe
�
Hi Mathias,
would you share the command line you're trying to execute ?
Actually, the patch you proposed breaks user-provided multiline commands; I played a little around it to keep this support, but would like to test with your specific case to understand why the initial version did not work with you.
thanks,
-seb
Le 10/02/2012 18:21, mathias louiset a �crit�:
�
Hi all,
�
I went to troubles while using the SSH probe: my command line was too long, and SSH probe split it at 150 characters. But it was just in the middle of a replacement string in my �sed� command� and of course the result was not the one I expected.
So I would like to suggest the following patch in file testerman/plugins/probe/ssh/SshProbe.py:
�
--- SshProbe.py.orig��� 2012-02-10 17:24:27.561633678 +0100
+++ SshProbe.py 2012-02-10 17:50:59.539372205 +0100
@@ -285,11 +285,13 @@
��������������� status = None