Commit b260918f authored by Cristiano Urban's avatar Cristiano Urban
Browse files

Added basic logging.

parent 33ed179e
Loading
Loading
Loading
Loading
+42 −13
Original line number Diff line number Diff line
@@ -7,6 +7,7 @@ import scp
import sys
import uuid

from config import Config
from tape_task import TapeTask


@@ -15,6 +16,19 @@ class TapeClient(object):

    # Constructor
    def __init__(self, host, port, user, keyFile):
        config = Config("/etc/vos_ts/vos_ts.conf")
        params = config.loadSection("logging")
        self.logger = logging.getLogger(__name__)
        logLevel = "logging." + params["log_level"]
        logFormat = params["log_format"]
        logFormatter = logging.Formatter(logFormat)
        self.logger.setLevel(eval(logLevel))
        redisLogHandler = RedisLogHandler()
        logStreamHandler = logging.StreamHandler()
        logStreamHandler.setFormatter(logFormatter)
        redisLogHandler.setFormatter(logFormatter)
        self.logger.addHandler(redisLogHandler)
        self.logger.addHandler(logStreamHandler)
        self.host = host
        self.port = port
        self.user = user
@@ -79,6 +93,7 @@ class TapeClient(object):
        Migrates to tape all files whose absolute path is 
        contained in 'fileList'.
        """
        self.logger.debug("Starting MIGRATE operation...")
        tmp = str(uuid.uuid1().hex) + "-vos_migrate.tmp"
        fp = open(tmp, "a")
        for f in fileList:
@@ -89,12 +104,16 @@ class TapeClient(object):
        cmd = f"{self.EEADM} migrate /tmp/{tmp} -p {tapePool}"
        stdin, stdout, stderr = self.client.exec_command(cmd)
        exitCode = stdout.channel.recv_exit_status()
        if not exitCode:
            self.logger.debug("MIGRATE operation COMPLETED.")
        else:
            self.logger.debug("MIGRATE operation FAILED.")
        
        # debug block...        
        out = open("tape_client_log.txt", "a")
        out.write("MIGRATE\n")
        out.write(f"exitCode: {exitCode}\n")
        out.close()
        #out = open("tape_client_log.txt", "a")
        #out.write("MIGRATE\n")
        #out.write(f"exitCode: {exitCode}\n")
        #out.close()
        
        return exitCode
    
@@ -103,6 +122,7 @@ class TapeClient(object):
        Recalls from tape all files whose absolute path is 
        contained in 'fileList'.
        """
        self.logger.debug("Starting RECALL operation...")
        tmp = str(uuid.uuid1().hex) + "-vos_recall.tmp"
        fp = open(tmp, "a")
        for f in fileList:
@@ -113,12 +133,16 @@ class TapeClient(object):
        cmd = f"{self.EEADM} recall /tmp/{tmp}"
        stdin, stdout, stderr = self.client.exec_command(cmd)
        exitCode = stdout.channel.recv_exit_status()
        if not exitCode:
            self.logger.debug("RECALL operation COMPLETED.")
        else:
            self.logger.debug("RECALL operation FAILED.")
        
        # debug block...
        out = open("tape_client_log.txt", "a")
        out.write("RECALL\n")
        out.write(f"exitCode: {exitCode}\n")
        out.close()
        #out = open("tape_client_log.txt", "a")
        #out.write("RECALL\n")
        #out.write(f"exitCode: {exitCode}\n")
        #out.close()
        
        return exitCode
    
@@ -127,15 +151,20 @@ class TapeClient(object):
        Recursively recalls from tape all the checksum files related to 
        the 'dirName' directory.
        """
        self.logger.debug("Starting RECALL_CHECKSUM operation...")
        cmd = f"find $(dirname {dirName}) -type f \( -iname \"*-md5sum.txt\" \) | {self.EEADM} recall"
        stdin, stdout, stderr = self.client.exec_command(cmd)
        exitCode = stdout.channel.recv_exit_status()
        if not exitCode:
            self.logger.debug("RECALL_CHECKSUM operation COMPLETED.")
        else:
            self.logger.debug("RECALL_CHECKSUM operation FAILED.")
        
        # debug block...
        out = open("tape_client_log.txt", "a")
        out.write("RECALL_CHECKSUM\n")
        out.write(f"exitCode: {exitCode}\n")
        out.close()
        #out = open("tape_client_log.txt", "a")
        #out.write("RECALL_CHECKSUM\n")
        #out.write(f"exitCode: {exitCode}\n")
        #out.close()
        
        return exitCode