commit 843411ca29a67ab28321b291b314863ebb8a67dd
Author: Radek Pazdera <rpazdera(a)redhat.com>
Date: Thu Nov 8 16:17:42 2012 +0100
NetTest: Adding copy-to-slave capability
This patch introduces a function at controller that will copy a
local file to a remote location using the rpc channel.
Files are copied in 1M large chunks.
Signed-off-by: Radek Pazdera <rpazdera(a)redhat.com>
NetTest/NetTestController.py | 16 ++++++++++++++++
NetTest/NetTestSlave.py | 30 ++++++++++++++++++++++++++++++
2 files changed, 46 insertions(+), 0 deletions(-)
---
diff --git a/NetTest/NetTestController.py b/NetTest/NetTestController.py
index c66abb0..c01eecd 100644
--- a/NetTest/NetTestController.py
+++ b/NetTest/NetTestController.py
@@ -15,6 +15,7 @@ import logging
import socket
import os
import pickle
+from xmlrpclib import Binary
from Common.Logs import Logs, log_exc_traceback
from Common.SshUtils import scp_from_remote
from pprint import pprint, pformat
@@ -550,3 +551,18 @@ class NetTestController:
data['address'] = '(' + address + ')'
record = logging.makeLogRecord(data)
logger.handle(record)
+
+ def _copy_to_slave(self, local_path, machine_id, remote_path=None):
+ self._rpc_call(machine_id, "start_copy", remote_path)
+ f = open(local_path, "r+b")
+
+ while True:
+ data = f.read(1024*1024) # 1MB buffer
+ if len(data) == 0:
+ break
+
+ self._rpc_call(machine_id, "copy_part", Binary(data))
+
+ # return remote path
+ rpath = self._rpc_call(machine_id, "finish_copy")
+ return rpath
diff --git a/NetTest/NetTestSlave.py b/NetTest/NetTestSlave.py
index 822dc37..988dc00 100644
--- a/NetTest/NetTestSlave.py
+++ b/NetTest/NetTestSlave.py
@@ -15,6 +15,7 @@ from Common.Logs import Logs, log_exc_traceback
import signal
import select, logging
import os
+from tempfile import NamedTemporaryFile
from Common.PacketCapture import PacketCapture
from Common.XmlRpc import Server
from SimpleXMLRPCServer import SimpleXMLRPCRequestHandler
@@ -37,6 +38,8 @@ class NetTestSlaveXMLRPC:
self._netconfig = NetConfig()
self._command_context = command_context
+ self._copy_target = None
+
def hello(self):
return "hello"
@@ -133,6 +136,33 @@ class NetTestSlaveXMLRPC:
self._command_context.cleanup()
return True
+ def start_copy(self, filename=None):
+ if self._copy_target:
+ return False
+
+ if filename:
+ self._copy_target = open(filename, "w+b")
+ else:
+ self._copy_target = NamedTemporaryFile("w+b", delete=False)
+
+ return True
+
+ def copy_part(self, binary_data):
+ if self._copy_target:
+ self._copy_target.write(binary_data.data)
+ return True
+
+ return False
+
+ def finish_copy(self):
+ if self._copy_target:
+ name = self._copy_target.name
+ del self._copy_target
+ self._copy_target = None
+ return name
+
+ return ""
+
class MySimpleXMLRPCServer(Server):
def __init__(self, command_context, *args, **kwargs):
self._finished = False
Show replies by date