summaryrefslogtreecommitdiff
path: root/validation/validlib/spc300.py
diff options
context:
space:
mode:
authorJean-Philippe NOEL2013-01-15 17:21:42 +0100
committerJean-Philippe NOEL2013-02-13 12:01:33 +0100
commit78ffeda1fe3f1857ab1fa9d54287c95f2984cee1 (patch)
tree58481d0cc7660ddd7b956c9a96c4ac3a5480126e /validation/validlib/spc300.py
parent91874baf44eb70e4dce9f540114e0a06b1fd57d5 (diff)
validation/validlib: retrieve the traces on SPC300 plugs, refs #3127
Diffstat (limited to 'validation/validlib/spc300.py')
-rw-r--r--validation/validlib/spc300.py82
1 files changed, 81 insertions, 1 deletions
diff --git a/validation/validlib/spc300.py b/validation/validlib/spc300.py
index 964a3ab646..439a9417d8 100644
--- a/validation/validlib/spc300.py
+++ b/validation/validlib/spc300.py
@@ -2,11 +2,16 @@
"""Module allowing to command and control the plug SPC300"""
+import gzip
+import tarfile
+import tempfile
+import shutil
import telnetlib
-import power_strip
import os
import re
+
import hpav_test
+import power_strip
#Must contain only MSTAR plugs
config = {
@@ -32,6 +37,12 @@ config = {
(1, 2): ("139", "138", "140", "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 = {}
@@ -195,6 +206,61 @@ def trace_is_present(key, interface_index):
def clean_trace(key, interface_index):
r_execute((key, 0), "rm " + trace_pattern)
+def get_trace_file_path(directory, zip_file_name, suffix):
+ assert re.search("^trace_\d+\.gz$", zip_file_name) is not None
+ 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):
+ """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)
+
+ # Retrieve the tar file of traces in the temporary directory
+ tar_file_name = os.path.basename(tempfile.NamedTemporaryFile().name)
+ (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"] + " " + \
+ 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)
+
+ # Delete the tar file so that only the traces remain
+ os.remove(tar_file_path)
+
+ # Check that there are indeed traces
+ files_names = os.listdir(trace_directory)
+ assert files_names != []
+
+ # Build the suffix
+ try:
+ (_, _, suffix) = key
+ except:
+ suffix = config["plugs"][key][0]
+
+ # Copy the 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)
+ shutil.copy(src_file_path, dest_file_path)
+
+ # Delete the temporary directory
+ shutil.rmtree(trace_directory)
+
################################################################################
# Internal functions
################################################################################
@@ -238,6 +304,17 @@ def slow_ping(key, interface_index):
n = n + 1
return (result, n)
+def unzip(zip_file_path):
+ zip_file_handler = gzip.open(zip_file_path, 'rb')
+ zip_file_content = zip_file_handler.read()
+ zip_file_handler.close()
+ return zip_file_content
+
+def untar(tar_file_path, destination_directory):
+ assert tarfile.is_tarfile(tar_file_path)
+ tar_file_content = tarfile.open(tar_file_path)
+ tar_file_content.extractall(destination_directory)
+
if __name__ == "__main__":
assert get_role("CCO = main\nSTATUS = authenticated") == "CCO"
try:
@@ -277,3 +354,6 @@ if __name__ == "__main__":
"PLC Driver: eoc-0.7.10\n"
"PLC Firmware: eoc-0.7.11\n"
"bar")
+ assert "/tmp/trace_slave_13_1.gz" == get_trace_file_path("/tmp",
+ "trace_1.gz",
+ "slave_13")