diff options
author | Bartek Grzybowski <b.grzybowski@partner.samsung.com> | 2020-06-08 14:25:44 +0200 |
---|---|---|
committer | Bartek Grzybowski <b.grzybowski@partner.samsung.com> | 2020-06-10 06:39:05 +0000 |
commit | 138b1990ee124c00a482e756460f83944ba19a0a (patch) | |
tree | 7b05f228db714a465abafe30642cd7bfcdce9a19 /test/mocks/mass-pnf-sim/MassPnfSim.py | |
parent | 304f31c5fd3fdf273a867aca564b67bd2391e6ba (diff) |
Add internal routine for logs archiving
Change-Id: Ibbb2b4aa71f0ca477b7129e4037cee031e44ae91
Issue-ID: INT-1617
Signed-off-by: Bartek Grzybowski <b.grzybowski@partner.samsung.com>
Diffstat (limited to 'test/mocks/mass-pnf-sim/MassPnfSim.py')
-rwxr-xr-x | test/mocks/mass-pnf-sim/MassPnfSim.py | 28 |
1 files changed, 26 insertions, 2 deletions
diff --git a/test/mocks/mass-pnf-sim/MassPnfSim.py b/test/mocks/mass-pnf-sim/MassPnfSim.py index a96520546..cdf97fcf9 100755 --- a/test/mocks/mass-pnf-sim/MassPnfSim.py +++ b/test/mocks/mass-pnf-sim/MassPnfSim.py @@ -4,11 +4,12 @@ from subprocess import run, CalledProcessError import argparse import ipaddress from sys import exit -from os import chdir, getcwd, path, popen, kill -from shutil import copytree, rmtree +from os import chdir, getcwd, path, popen, kill, mkdir +from shutil import copytree, rmtree, move from json import loads, dumps from yaml import load, SafeLoader from glob import glob +from time import strftime from docker import from_env from requests import get, codes, post from requests.exceptions import MissingSchema, InvalidSchema, InvalidURL, ConnectionError, ConnectTimeout @@ -191,6 +192,29 @@ class MassPnfSim: else: return [self.existing_sim_instances] + def _archive_logs(self, sim_dir): + '''Helper function to archive simulator logs or create the log dir''' + old_pwd = getcwd() + try: + chdir(sim_dir) + if path.isdir('logs'): + arch_dir = f"logs/archive_{strftime('%Y-%m-%d_%T')}" + mkdir(arch_dir) + self.logger.debug(f'Created {arch_dir}') + # Collect file list to move + self.logger.debug('Archiving log files') + for fpattern in ['*.log', '*.xml']: + for f in glob('logs/' + fpattern): + # Move files from list to arch dir + move(f, arch_dir) + self.logger.debug(f'Moving {f} to {arch_dir}') + else: + mkdir('logs') + self.logger.debug("Logs dir didn't exist, created") + chdir(old_pwd) + except FileNotFoundError: + self.logger.error(f"Directory {sim_dir} not found") + def bootstrap(self): self.logger.info("Bootstrapping PNF instances") |