From 63e8bf512795875a26bf3381150b6fcfe18fb091 Mon Sep 17 00:00:00 2001 From: Claudia Beresford Date: Thu, 11 Nov 2021 15:40:09 +0000 Subject: [PATCH] Fix teardown It was not working because I was using params from the wrong object. Needs to be on the metal. --- test/tools/metal.py | 20 ++++++++++---------- test/tools/test.py | 12 +++++------- 2 files changed, 15 insertions(+), 17 deletions(-) diff --git a/test/tools/metal.py b/test/tools/metal.py index 02536931..4615ad96 100644 --- a/test/tools/metal.py +++ b/test/tools/metal.py @@ -121,20 +121,20 @@ def run_ssh_command(self, cmd, cwd, allow_error=True): raise result.to_error() self.logger.info("command exited with code %d", result.return_code) - def delete_all(self, project, device, key): - if device != None: - device.delete() - self.logger.info(f"deleted device {device.hostname}") + def delete_all(self): + if self.device is not None: + self.device.delete() + self.logger.info(f"deleted device {self.device.hostname}") - if key != None: - key.delete() + if self.key is not None: + self.key.delete() os.remove(self.private_key_path) os.remove(self.public_key_path) - self.logger.info(f"deleted key {key.label}") + self.logger.info(f"deleted key {self.key.label}") - if project != None: - project.delete() - self.logger.info(f"deleted project {project.name}") + if self.project is not None: + self.project.delete() + self.logger.info(f"deleted project {self.project.name}") def new_shell(self, ip): shell = spur.SshShell( diff --git a/test/tools/test.py b/test/tools/test.py index e9510b5d..b3ef4fc7 100644 --- a/test/tools/test.py +++ b/test/tools/test.py @@ -12,19 +12,15 @@ def __init__(self, auth_token, config): self.skip_teardown = self.testCfg['skip_teardown'] self.dev_id = devCfg['id'] self.dev_ip = None - self.project = None - self.key = None - self.device = None def __enter__(self): return self def __exit__(self, *args, **kwargs): - if self.skip_teardown == False: - self.teardown() + self.teardown() def setup(self): - if self.dev_id != None: + if self.dev_id is not None: self.fetch_infra() else: self.create_infra() @@ -46,7 +42,9 @@ def run_tests(self): pass def teardown(self): - self.welder.delete_all(self.project, self.device, self.key) + if self.skip_teardown: + return + self.welder.delete_all() def create_infra(self): self.dev_ip = self.welder.create_all()