Add remote_edit method into virttest/remote.py.#526
Conversation
|
@cevich please take a look and give me a some feedback. |
|
Hi @yangdongsheng do you have some examples where this function would be used? Because it all looks too complicated to me, but maybe I'm wrong... Additionally is this targeted for small files and few patterns, or do you intend to modify large files too? Because the code is not what I'd call optimized. |
|
Thanx @ldoktor for your comment. Yes, in some conditions we need to edit a remote file. I think I should add a edit_file function in virttest/utils_misc.py at first to edit file on local host, Yes, the pattern&value method to edit file is not convenient to users, but the functionality to edit remote file is necessary I think. Do you agree? Could you give me some suggestion to make this function more pretty? |
|
Yes I agree these functions might be valuable. My first thought was Anyway after a decent consideration I can see the benefit of having unified way for all OSs. In order to make the call simple I'd imagine those variants:
using of re.sub() and re.match is a common way and should be a readable enough in test so I guess we could use that. Also from what you describe it's going to be used on cfg files so the optimization is not a big issue (although to speed things up you might use Examples: cat /etc/exports /home/medic 192.168.122.0/24(rw,all_squash,anonuid=1000,anongid=1000,async,insecure) APPEND, '/tmp/a/ 192.168.122.0/24(rw,all_squash,anonuid=1000,anongid=1000,async,insecure)' SUB r'\/tmp\/a\S+.*\n?' DEL '/home/medic 192.168.122.0/24(rw,all_squash,anonuid=1000,anongid=1000,async,insecure)' cat /etc/exports |
|
Also one more thing, the backup files needs to be renamed in case we backup the same file from multiple guests or the same file multiple times... |
|
I think there will always be cases where this or that tool or method is better suited for some operation. Also, many modifications are dependant on success of prior operations. A one-by-one approach with many conditional calls to this function and keeping track of multiple backups, possibly from several hosts, could quickly become quite cumbersome. @yumingfei and I have been discussing this problem off-and-on for a while now. Based on that, and my tinkering around, I think extremely simple solutions are best here. How about a function or class that behaves like this:
We can stick these scripts into a test-specific directory under A slightly more complicated alternative is to use something like the inspect module to pull the code out of a class defined within the test-module, ship that over to the remote system, and execute it (somehow). I did a POC on this, hooked up to a SimpleXMLRPCServer instance running on the guest. It was "cool", and provided a shared namespace, but I think simple is probably better. |
|
👍 for simple solution with one concern. If I understand it correctly you want to create script which would modify the file on the target machine. If you wanted to do it on windows, you'd have to use windows cmd script (which is not that rich as linux bash) as if I'm not mistaken python is not automatically installed in windows. About the multiple backups I can imagine another solution. We could use a class. You'd specify the changes and would be able to revert back to the original file. Also on Anyway I agree that simplest solution is always the best as everybody who just wants to know what this test does should understand it and not study autotest internals to understand that this weird call just changes the default initlevel to 5. |
|
Hi ldoktor https://github.com/ldoktor
|
|
Yes, rename backup files is necessary. Thanx On 06/11/2013 06:41 PM, Lukáš Doktor wrote:
|
|
@cevich @yumingfei and @ldoktor |
|
I'd support the methods I described in #526 (comment)
The function should return the path to the backup. For matching use compiled regexp. (a = re.compile, a.sub(...)). But that's only my idea, don't take it too seriously. |
|
Ahh ya, forgot about Windows and cmd. I would love it if we could reduce out of control dependencies :D Seriously though, we do have some things we can count on, including a python environment. But I'm not sure we have many tests which must run using exactly the same parameters on multi-OS. I think it's okay to have different variants and scripts for different OSs, as long as they meet the same requirements for test. If that makes sense. |
|
I'd rather copy to local and modify it, because we may lose control to modified files if remote host is disconnect during executing scripts. |
A class to handle remote file. Currently, we support three operations on remote file. add: append lines in to file. sub: replace string which match pattern to repl. remove: delete lines that match pattern. Signed-off-by: yangdongsheng <yangds.fnst@cn.fujitsu.com>
Signed-off-by: yangdongsheng <yangds.fnst@cn.fujitsu.com>
|
@cevich @yumingfei and @ldoktor |
|
My first impression based on review is very nice. I only pointed out that using For consideration we could add libguestfs support later to modify non-running VMs (eg. when we screw-up some setting and the VM won't boot afterwards...) |
|
Thanx @ldoktor for your review and helpful comment. |
|
Hi maitainers: |
|
OK I tested it on a boot test and it worked fine. People just have to be careful to use list of strings and not strings itself (I'd maybe consider check for simple string and in that case warn user or even throw exception as it's currently it accepts it and iterates over chars... (that's why I first thought it's broken) Anyway it works fine as it is now and we can add new features later. @cevich you already saw this one, would you please take a look on it? (Additionally might I ask you to take care of the merge? I'll work from train tomorrow and I might not be able to connect) Acked-by: Lukáš Doktor ldoktor@redhat.com |
|
^^ check_patch also found indentation mistake which needs to be taken care of during merge |
(1).Change uuid to tempfile to build a unique filename. (2).Add a __del__ method for unittest class to remove remote_file. Signed-off-by: yangdongsheng <yangds.fnst@cn.fujitsu.com> Fix indenting error in remote.py. Signed-off-by: yangdongsheng <yangds.fnst@cn.fujitsu.com>
|
@ldoktor |
|
Hi @ldoktor , would you take a look at this pull request? I think it is ready to go. Thanx :) |
Add remote_edit method into virttest/remote.py.
|
This patch looks good to me. checked it with check_patch.py, and run the unit test for it. Everything seems fine. And as it already Acked by @ldoktor. So merge it. Thanks @yangdongsheng |
Signed-off-by: yangdongsheng yangds.fnst@cn.fujitsu.com