c4kBuild is working

This commit is contained in:
Michael Jerger 2023-04-29 20:03:21 +02:00
parent 2a4a2d25d8
commit 331b3bba6e
2 changed files with 24 additions and 34 deletions

View file

@ -53,23 +53,26 @@ class C4kBuild(DevopsBuild):
raise ValueError(f"C4kBuild requires BuildType.C4K") raise ValueError(f"C4kBuild requires BuildType.C4K")
def update_runtime_config(self, dns_record: DnsRecord): def update_runtime_config(self, dns_record: DnsRecord):
c4k_build = self.repo.get_c4k(self.project) devops = self.repo.get_devops(self.project)
c4k_build.update_runtime_config(dns_record) devops.specialized_builds[BuildType.C4K].update_runtime_config(dns_record)
self.repo.set_c4k(self.project, c4k_build) self.repo.set_devops(self.project, devops)
def write_c4k_config(self): def write_c4k_config(self):
build = self.repo.get_devops(self.project) devops = self.repo.get_devops(self.project)
c4k_build = self.repo.get_c4k(self.project) path = devops.build_path() + "/out_c4k_config.yaml"
path = build.build_path() + "/out_c4k_config.yaml" self.file_api.write_yaml_to_file(
self.file_api.write_yaml_to_file(path, c4k_build.config()) path, devops.specialized_builds[BuildType.C4K].config()
)
def write_c4k_auth(self): def write_c4k_auth(self):
build = self.repo.get_devops(self.project) devops = self.repo.get_devops(self.project)
c4k_build = self.repo.get_c4k(self.project) path = devops.build_path() + "/out_c4k_auth.yaml"
path = build.build_path() + "/out_c4k_auth.yaml" self.file_api.write_yaml_to_file(
self.file_api.write_yaml_to_file(path, c4k_build.c4k_mixin_auth) path, devops.specialized_builds[BuildType.C4K].auth()
)
def c4k_apply(self, dry_run=False): def c4k_apply(self, dry_run=False):
build = self.repo.get_devops(self.project) devops = self.repo.get_devops(self.project)
c4k_build = self.repo.get_c4k(self.project) return self.execution_api.execute(
return self.execution_api.execute(c4k_build.command(build), dry_run) devops.specialized_builds[BuildType.C4K].command(devops), dry_run
)

View file

@ -5,10 +5,6 @@ from src.main.python.ddadevops.c4k_build import C4kBuild, add_c4k_mixin_config
from .domain.test_helper import devops_config from .domain.test_helper import devops_config
class MyC4kBuild(C4kBuild):
pass
def test_c4k_mixin(tmp_path): def test_c4k_mixin(tmp_path):
build_dir = "build" build_dir = "build"
project_name = "testing-project" project_name = "testing-project"
@ -16,7 +12,7 @@ def test_c4k_mixin(tmp_path):
tmp_path_str = str(tmp_path) tmp_path_str = str(tmp_path)
project = Project(tmp_path_str, name=project_name) project = Project(tmp_path_str, name=project_name)
sut = MyC4kBuild( sut = C4kBuild(
project, project,
devops_config( devops_config(
{ {
@ -25,27 +21,18 @@ def test_c4k_mixin(tmp_path):
"module": "c4k-test", "module": "c4k-test",
"c4k_config": {"a": 1, "b": 2}, "c4k_config": {"a": 1, "b": 2},
"c4k_auth": {"c": 3, "d": 4}, "c4k_auth": {"c": 3, "d": 4},
"grafana_cloud_user": "user", "c4k_grafana_cloud_user": "user",
"grafana_cloud_password": "password", "c4k_grafana_cloud_password": "password",
'grafana_cloud_url': "https://prometheus-prod-01-eu-west-0.grafana.net/api/prom/push",
} }
), ),
) )
sut.initialize_build_dir() sut.initialize_build_dir()
assert ( assert sut.build_path() == f"{tmp_path_str}/target/name/c4k-test"
sut.build_path() == f"{tmp_path_str}/target/mybuild/c4k-test"
)
# TODO: mv this to domain test
# sut.update_runtime_config(DnsRecord("test.de", ipv6="1::"))
# assert "fqdn" in sut.specialized_builds[BuildType.C4K].config()
# assert "mon-cfg" in sut.specialized_builds[BuildType.C4K].config()
# assert "mon-auth" in sut.specialized_builds[BuildType.C4K].c4k_mixin_auth
sut.update_runtime_config(DnsRecord("test.de", ipv6="::1"))
sut.write_c4k_config() sut.write_c4k_config()
assert os.path.exists(f"{mixin.build_path()}/out_c4k_config.yaml") assert os.path.exists(f"{sut.build_path()}/out_c4k_config.yaml")
sut.write_c4k_auth() sut.write_c4k_auth()
assert os.path.exists(f"{mixin.build_path()}/out_c4k_auth.yaml") assert os.path.exists(f"{sut.build_path()}/out_c4k_auth.yaml")