From f2b1483c7d56666c4186183463fff516f5f99900 Mon Sep 17 00:00:00 2001 From: Bartek Grzybowski Date: Mon, 25 May 2020 00:47:35 -0700 Subject: Drop shell 'rm' command and use 'rmtree' native Python routine Change-Id: Id5487723b8eb6fdc065ffe712907f9a715f610c5 Issue-ID: INT-1577 Signed-off-by: Bartek Grzybowski --- test/mocks/mass-pnf-sim/MassPnfSim.py | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) (limited to 'test/mocks/mass-pnf-sim') diff --git a/test/mocks/mass-pnf-sim/MassPnfSim.py b/test/mocks/mass-pnf-sim/MassPnfSim.py index dde622ac9..d15b69551 100755 --- a/test/mocks/mass-pnf-sim/MassPnfSim.py +++ b/test/mocks/mass-pnf-sim/MassPnfSim.py @@ -1,11 +1,11 @@ #!/usr/bin/env python3 import logging -import subprocess +from subprocess import run, CalledProcessError import argparse import ipaddress from sys import exit from os import chdir, getcwd, path -from shutil import copytree +from shutil import copytree, rmtree from json import dumps from glob import glob from requests import get @@ -139,11 +139,11 @@ class MassPnfSim: old_pwd = getcwd() try: chdir(dir_context) - subprocess.run(cmd, check=True, shell=True) + run(cmd, check=True, shell=True) chdir(old_pwd) except FileNotFoundError: self.logger.error(f"Directory {dir_context} not found") - except subprocess.CalledProcessError as e: + except CalledProcessError as e: exit(e.returncode) def _enum_sim_instances(self): @@ -223,7 +223,8 @@ class MassPnfSim: def clean(self): self.logger.info('Cleaning simulators workdirs') - self._run_cmd(f"rm -rf {self.sim_dirname_pattern}*") + for sim_id in range(self.existing_sim_instances): + rmtree(f"{self.sim_dirname_pattern}{sim_id}") @_MassPnfSim_Decorators.do_action('Starting', './simulator.sh start') def start(self): -- cgit 1.2.3-korg