chore: cleanup config override in infrastructure/tests.py
ci/woodpecker/push/woodpecker Pipeline failed
Details
ci/woodpecker/push/woodpecker Pipeline failed
Details
parent
ca8ffba55e
commit
8997d0ff0f
|
@ -13,6 +13,7 @@
|
||||||
# You should have received a copy of the GNU Affero General Public License
|
# You should have received a copy of the GNU Affero General Public License
|
||||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
|
import shutil
|
||||||
|
|
||||||
from django.test import TestCase, Client, override_settings
|
from django.test import TestCase, Client, override_settings
|
||||||
from django.conf import 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
|
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):
|
class InfraUtilTest(TestCase):
|
||||||
"""
|
"""
|
||||||
Tests billing system
|
Tests billing system
|
||||||
|
@ -34,17 +45,7 @@ class InfraUtilTest(TestCase):
|
||||||
register_util(t=self, username=self.username)
|
register_util(t=self, username=self.username)
|
||||||
create_configurations(t=self)
|
create_configurations(t=self)
|
||||||
|
|
||||||
@override_settings(
|
@override_settings(HOSTEA=custom_config(test_name="test_path_util"))
|
||||||
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",
|
|
||||||
},
|
|
||||||
}
|
|
||||||
}
|
|
||||||
)
|
|
||||||
def test_path_utils(self):
|
def test_path_utils(self):
|
||||||
infra = Infra()
|
infra = Infra()
|
||||||
subdomain = "foo"
|
subdomain = "foo"
|
||||||
|
@ -75,17 +76,7 @@ class InfraUtilTest(TestCase):
|
||||||
infra._hostscript_path(subdomain=subdomain),
|
infra._hostscript_path(subdomain=subdomain),
|
||||||
)
|
)
|
||||||
|
|
||||||
@override_settings(
|
@override_settings(HOSTEA=custom_config(test_name="test_add_vm"))
|
||||||
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",
|
|
||||||
},
|
|
||||||
}
|
|
||||||
}
|
|
||||||
)
|
|
||||||
def test_add_vm(self):
|
def test_add_vm(self):
|
||||||
infra = Infra()
|
infra = Infra()
|
||||||
c = Client()
|
c = Client()
|
||||||
|
@ -101,4 +92,4 @@ class InfraUtilTest(TestCase):
|
||||||
instance = Instance.objects.get(name=subdomain)
|
instance = Instance.objects.get(name=subdomain)
|
||||||
woodpecker_agent_secret = infra.add_vm(instance=instance)
|
woodpecker_agent_secret = infra.add_vm(instance=instance)
|
||||||
|
|
||||||
# infra.remove_vm(instance=instance)
|
infra.remove_vm(instance=instance)
|
||||||
|
|
|
@ -36,7 +36,7 @@ class Infra:
|
||||||
if not self.repo_path.exists():
|
if not self.repo_path.exists():
|
||||||
os.makedirs(self.repo_path)
|
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:
|
try:
|
||||||
self.repo = Repo(path=self.repo_path)
|
self.repo = Repo(path=self.repo_path)
|
||||||
except InvalidGitRepositoryError:
|
except InvalidGitRepositoryError:
|
||||||
|
|
Loading…
Reference in New Issue