From 8997d0ff0f14b57f4d0bb09c25f79762455d1890 Mon Sep 17 00:00:00 2001 From: realaravinth Date: Mon, 27 Jun 2022 04:37:56 +0530 Subject: [PATCH] chore: cleanup config override in infrastructure/tests.py --- infrastructure/tests.py | 37 ++++++++++++++----------------------- infrastructure/utils.py | 2 +- 2 files changed, 15 insertions(+), 24 deletions(-) diff --git a/infrastructure/tests.py b/infrastructure/tests.py index f6cd742..c8f5ac4 100644 --- a/infrastructure/tests.py +++ b/infrastructure/tests.py @@ -13,6 +13,7 @@ # You should have received a copy of the GNU Affero General Public License # along with this program. If not, see . from pathlib import Path +import shutil from django.test import TestCase, Client, override_settings from django.conf import settings @@ -24,6 +25,16 @@ from accounts.tests import register_util, login_util from dash.tests import create_configurations, create_instance_util +def custom_config(test_name: str): + c = settings.HOSTEA + path = Path(f"/tmp/hostea/dashboard/{c}/repo") + if path.exists(): + print(f"[!] {path} exists, deleting.") + shutil.rmtree(path) + c["INFRA"]["HOSTEA_REPO"]["PATH"] = str(path) + return c + + class InfraUtilTest(TestCase): """ Tests billing system @@ -34,17 +45,7 @@ class InfraUtilTest(TestCase): register_util(t=self, username=self.username) create_configurations(t=self) - @override_settings( - HOSTEA={ - "INFRA": { - "HOSTEA_REPO": { - "PATH": "/tmp/hostea/dashboard/test_path_util/repo/", - "REMOTE": "git@git.batsense.net:realaravinth/dummy-hostea-dash-test", - "SSH_KEY": "/src/atm/.ssh/aravinth", - }, - } - } - ) + @override_settings(HOSTEA=custom_config(test_name="test_path_util")) def test_path_utils(self): infra = Infra() subdomain = "foo" @@ -75,17 +76,7 @@ class InfraUtilTest(TestCase): infra._hostscript_path(subdomain=subdomain), ) - @override_settings( - HOSTEA={ - "INFRA": { - "HOSTEA_REPO": { - "PATH": "/tmp/hostea/dashboard/test_add_vm/repo/", - "REMOTE": "git@git.batsense.net:realaravinth/dummy-hostea-dash-test", - "SSH_KEY": "/src/atm/.ssh/aravinth", - }, - } - } - ) + @override_settings(HOSTEA=custom_config(test_name="test_add_vm")) def test_add_vm(self): infra = Infra() c = Client() @@ -101,4 +92,4 @@ class InfraUtilTest(TestCase): instance = Instance.objects.get(name=subdomain) woodpecker_agent_secret = infra.add_vm(instance=instance) - # infra.remove_vm(instance=instance) + infra.remove_vm(instance=instance) diff --git a/infrastructure/utils.py b/infrastructure/utils.py index cd47054..edc441b 100644 --- a/infrastructure/utils.py +++ b/infrastructure/utils.py @@ -36,7 +36,7 @@ class Infra: if not self.repo_path.exists(): os.makedirs(self.repo_path) - self.ssh_cmd = f"ssh -i {conf['SSH_KEY']}" + self.ssh_cmd = f"/usr/bin/ssh -oStrictHostKeyChecking=no -i {conf['SSH_KEY']}" try: self.repo = Repo(path=self.repo_path) except InvalidGitRepositoryError: