summaryrefslogtreecommitdiff
path: root/validation/validlib/spc300.py
diff options
context:
space:
mode:
authorJean-Philippe NOEL2013-02-15 14:59:28 +0100
committerJean-Philippe NOEL2013-02-21 11:59:30 +0100
commit11b40b23ecbb251559d97e6d8ed4f230a654be9a (patch)
tree75e5fdcfa66c3d1e82c57a34637419b0d725e6dc /validation/validlib/spc300.py
parent1a2b011d08dc0fbcf5f3746e4cc43a1b518d8c8a (diff)
validation: retrieve the traces in P2P, refs #3777
Diffstat (limited to 'validation/validlib/spc300.py')
-rw-r--r--validation/validlib/spc300.py73
1 files changed, 48 insertions, 25 deletions
diff --git a/validation/validlib/spc300.py b/validation/validlib/spc300.py
index cf0e7f2d56..06040c693c 100644
--- a/validation/validlib/spc300.py
+++ b/validation/validlib/spc300.py
@@ -15,6 +15,7 @@ import hpav_test
import power_strip
import list_utils
import plug
+import ssh
#Must contain only MSTAR plugs
config = {
@@ -48,18 +49,12 @@ config = {
(1, 3, "plug_2"): ("153", None, None, "spr310"),
(2, 1): ("136", "135", "137", "spr310"),
(2, 2): ("145", "144", "146", "spr310")
- },
- "ftp_server":{
- #Address of the local FTP server viewed from the plugs
- "address":"192.168.10.254",
- #Root directory of the local FTP server
- "root":"/var/all_ftp"
}
}
mac_addresses = {}
#Pattern of the files containing the traces
-trace_pattern = "/usr/local/trace/trace*gz"
+trace_pattern = "/usr/local/trace/trace_*.gz"
def update_config(new_config):
"""Update the configuration"""
@@ -282,39 +277,58 @@ def get_trace_file_path(directory, zip_file_name, suffix):
trace_file_name = zip_file_name.replace("trace", "trace_" + suffix)
return os.path.join(directory, trace_file_name)
-def dump_trace(key, directory, interface_index = 0):
+def random_string():
+ return os.path.basename(tempfile.NamedTemporaryFile().name)
+
+def dump_trace(key, dest_directory, ftp_server, interface_index = 0):
"""Retrieve the traces present on the plug and dump them in the directory"""
# No need to dump anything if there are no traces on the plug
if not trace_is_present(key, interface_index):
return
- # Create a temporary directory under the FTP directory
- trace_directory = tempfile.mkdtemp(dir = config["ftp_server"]["root"])
- ftp_trace_directory = os.path.basename(trace_directory)
+ # Create a temporary remote directory
+ ftp_trace_directory = random_string()
+ remote_trace_directory = os.path.join(ftp_server["root"],
+ ftp_trace_directory)
+ ssh.call(ftp_server["user"], ftp_server["non_plc_ip_address"],
+ "mkdir " + remote_trace_directory)
- # Retrieve the tar file of traces in the temporary directory
- tar_file_name = os.path.basename(tempfile.NamedTemporaryFile().name)
+ # Retrieve the tar file of traces in the remote temporary directory
+ tar_file_name = random_string()
(trace_directory_on_plug, file_pattern) = os.path.split(trace_pattern)
commands = \
["cd " + trace_directory_on_plug,
"tar -cf " + tar_file_name + " " + file_pattern,
"ftpput -u spidcom -p spidcom " + \
- config["ftp_server"]["address"] + " " + \
+ ftp_server["plc_ip_address"] + " " + \
os.path.join(ftp_trace_directory, tar_file_name) + " " + \
tar_file_name,
"rm " + tar_file_name]
r_execute((key, interface_index), commands)
- # Untar the traces
- tar_file_path = os.path.join(trace_directory, tar_file_name)
- untar(tar_file_path, trace_directory)
+ # Create a local temporary directory
+ local_trace_directory = os.path.join("/tmp", ftp_trace_directory)
+ os.mkdir(local_trace_directory)
+
+ # Copy the remote file locally
+ remote_tar_file_path = os.path.join(remote_trace_directory, tar_file_name)
+ ssh.cp(ftp_server["user"], ftp_server["non_plc_ip_address"],
+ remote_tar_file_path, local_trace_directory)
+
+ # Remove the remote temporary directory
+ ssh.call(ftp_server["user"], ftp_server["non_plc_ip_address"],
+ "rm -rf " + remote_trace_directory)
- # Delete the tar file so that only the traces remain
- os.remove(tar_file_path)
+ # Untar the traces locally
+ local_tar_file_path = os.path.join(local_trace_directory, tar_file_name)
+ untar(local_tar_file_path, local_trace_directory)
+
+ # Delete the local tar file so that only the traces remain
+ os.remove(local_tar_file_path)
# Check that there are indeed traces
- files_names = os.listdir(trace_directory)
+ files_names = os.listdir(local_trace_directory)
assert files_names != []
# Build the suffix
@@ -323,14 +337,23 @@ def dump_trace(key, directory, interface_index = 0):
except:
suffix = config["plugs"][key][0]
- # Copy the files
+ # Create the destination directory if it does not exist
+ if os.path.exists(dest_directory) == False:
+ os.mkdir(dest_directory)
+
+ # Remove the old traces files, if any
+ for file_name in os.listdir(dest_directory):
+ if os.path.splitext(file_name) == os.path.splitext(trace_pattern):
+ os.remove(os.path.join(dest_directory, file_name)
+
+ # Copy the new traces files
for file_name in files_names:
- src_file_path = os.path.join(trace_directory, file_name)
- dest_file_path = get_trace_file_path(directory, file_name, suffix)
+ src_file_path = os.path.join(local_trace_directory, file_name)
+ dest_file_path = get_trace_file_path(dest_directory, file_name, suffix)
shutil.copy(src_file_path, dest_file_path)
- # Delete the temporary directory
- shutil.rmtree(trace_directory)
+ # Delete the local temporary directory
+ shutil.rmtree(local_trace_directory)
################################################################################
# Internal functions