feat & fix: don't append enough commands to hostscript and fix service.yml path
ci/woodpecker/push/woodpecker Pipeline was successful Details

wip-hostea-domain
Aravinth Manivannan 2022-06-28 14:47:21 +05:30
parent d4ab0156a7
commit e4a7310c79
Signed by: realaravinth
GPG Key ID: AD9F0F08E855ED88
2 changed files with 14 additions and 6 deletions

View File

@ -36,9 +36,8 @@ from .utils import Infra
def custom_config(test_name: str): def custom_config(test_name: str):
c = settings.HOSTEA c = settings.HOSTEA
path = Path(f"/tmp/hostea/dashboard/{c}/repo") path = Path(f"/tmp/hostea/dashboard/{test_name}/repo")
if path.exists(): if path.exists():
print(f"[!] {path} exists, deleting.")
shutil.rmtree(path) shutil.rmtree(path)
c["INFRA"]["HOSTEA_REPO"]["PATH"] = str(path) c["INFRA"]["HOSTEA_REPO"]["PATH"] = str(path)
return c return c
@ -81,7 +80,7 @@ class InfraUtilTest(TestCase):
) )
self.assertEqual( self.assertEqual(
base.joinpath(f"inventory/hosts-scripts/{subdomain}-host.sh"), base.joinpath(f"hosts-scripts/{subdomain}-host.sh"),
infra._hostscript_path(subdomain=subdomain), infra._hostscript_path(subdomain=subdomain),
) )

View File

@ -101,7 +101,8 @@ class Infra:
""" """
utility method: hostscript file for a subdomain utility method: hostscript file for a subdomain
""" """
return self.repo_path.joinpath(f"hosts-scripts/{subdomain}-host.sh") path = self.repo_path.joinpath(f"hosts-scripts/{subdomain}-host.sh")
return path
def write_hostscript(self, subdomain: str, content: str): def write_hostscript(self, subdomain: str, content: str):
""" """
@ -152,7 +153,7 @@ class Infra:
if not host_vars_dir.exists(): if not host_vars_dir.exists():
os.makedirs(host_vars_dir) os.makedirs(host_vars_dir)
hostscript_path = self.repo_path.joinpath("inventory/hosts-scripts/") hostscript_path = self.repo_path.joinpath("hosts-scripts/")
if not hostscript_path.exists(): if not hostscript_path.exists():
os.makedirs(hostscript_path) os.makedirs(hostscript_path)
@ -213,7 +214,7 @@ class Infra:
) )
service = self._service_path(subdomain) service = self._service_path(subdomain)
with open(backup, "w", encoding="utf-8") as f: with open(service, "w", encoding="utf-8") as f:
f.write( f.write(
render_to_string( render_to_string(
"infrastructure/yml/service.yml", context={"subdomain": subdomain} "infrastructure/yml/service.yml", context={"subdomain": subdomain}
@ -222,6 +223,10 @@ class Infra:
# hostscript = self.repo_path.join("inventory/hosts-scripts/{instance.name}-host.sh") # hostscript = self.repo_path.join("inventory/hosts-scripts/{instance.name}-host.sh")
hostscript = self._hostscript_path(subdomain)
with open(hostscript, "w", encoding="utf-8") as f:
f.write("\n")
self.write_hostscript( self.write_hostscript(
subdomain=subdomain, subdomain=subdomain,
content=render_to_string( content=render_to_string(
@ -250,6 +255,10 @@ class Infra:
service = self._service_path(subdomain) service = self._service_path(subdomain)
os.remove(service) os.remove(service)
hostscript = self._hostscript_path(subdomain)
with open(hostscript, "w", encoding="utf-8") as f:
f.write("\n")
self.write_hostscript( self.write_hostscript(
subdomain=subdomain, subdomain=subdomain,
content=render_to_string( content=render_to_string(