diff --git a/infrastructure/tests.py b/infrastructure/tests.py index d71ea48..f4a748e 100644 --- a/infrastructure/tests.py +++ b/infrastructure/tests.py @@ -36,9 +36,8 @@ from .utils import Infra def custom_config(test_name: str): c = settings.HOSTEA - path = Path(f"/tmp/hostea/dashboard/{c}/repo") + path = Path(f"/tmp/hostea/dashboard/{test_name}/repo") if path.exists(): - print(f"[!] {path} exists, deleting.") shutil.rmtree(path) c["INFRA"]["HOSTEA_REPO"]["PATH"] = str(path) return c @@ -81,7 +80,7 @@ class InfraUtilTest(TestCase): ) self.assertEqual( - base.joinpath(f"inventory/hosts-scripts/{subdomain}-host.sh"), + base.joinpath(f"hosts-scripts/{subdomain}-host.sh"), infra._hostscript_path(subdomain=subdomain), ) diff --git a/infrastructure/utils.py b/infrastructure/utils.py index 70d378f..301e210 100644 --- a/infrastructure/utils.py +++ b/infrastructure/utils.py @@ -101,7 +101,8 @@ class Infra: """ 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): """ @@ -152,7 +153,7 @@ class Infra: if not host_vars_dir.exists(): 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(): os.makedirs(hostscript_path) @@ -213,7 +214,7 @@ class Infra: ) 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( render_to_string( "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._hostscript_path(subdomain) + with open(hostscript, "w", encoding="utf-8") as f: + f.write("\n") + self.write_hostscript( subdomain=subdomain, content=render_to_string( @@ -250,6 +255,10 @@ class Infra: service = self._service_path(subdomain) os.remove(service) + hostscript = self._hostscript_path(subdomain) + with open(hostscript, "w", encoding="utf-8") as f: + f.write("\n") + self.write_hostscript( subdomain=subdomain, content=render_to_string(