refactor to dedicated parameters
This commit is contained in:
parent
1bcc8908e9
commit
d650f67dbf
3 changed files with 44 additions and 33 deletions
src
|
@ -2,8 +2,8 @@ import deprecation
|
||||||
from .domain import Devops
|
from .domain import Devops
|
||||||
from .infrastructure import ProjectRepository, FileApi
|
from .infrastructure import ProjectRepository, FileApi
|
||||||
|
|
||||||
@deprecation.deprecated(deprecated_in="3.2")
|
@deprecation.deprecated(deprecated_in="3.2",
|
||||||
# create objects direct instead
|
details="create objects direct instead")
|
||||||
def create_devops_build_config(
|
def create_devops_build_config(
|
||||||
stage, project_root_path, module, build_dir_name="target"
|
stage, project_root_path, module, build_dir_name="target"
|
||||||
):
|
):
|
||||||
|
@ -19,7 +19,7 @@ def create_devops_build_config(
|
||||||
def get_devops_build(project):
|
def get_devops_build(project):
|
||||||
return project.get_property("devops_build")
|
return project.get_property("devops_build")
|
||||||
|
|
||||||
|
@deprecation.deprecated(deprecated_in="3.2")
|
||||||
# TODO: Remove from here!
|
# TODO: Remove from here!
|
||||||
def get_tag_from_latest_commit():
|
def get_tag_from_latest_commit():
|
||||||
try:
|
try:
|
||||||
|
@ -35,22 +35,27 @@ def get_tag_from_latest_commit():
|
||||||
|
|
||||||
|
|
||||||
class DevopsBuild:
|
class DevopsBuild:
|
||||||
def __init__(self, project, config):
|
def __init__(self, project, config: map = None, devops: Devops = None):
|
||||||
self.project = project
|
self.project = project
|
||||||
self.file_api = FileApi()
|
self.file_api = FileApi()
|
||||||
self.repo = ProjectRepository()
|
self.repo = ProjectRepository()
|
||||||
config.update({"name": project.name})
|
config.update({"name": project.name})
|
||||||
build = Devops(config)
|
if not devops:
|
||||||
self.repo.set_devops(self.project, build)
|
devops = Devops(stage = config['stage'],
|
||||||
|
project_root_path = config['project_root_path'],
|
||||||
|
module = config['module'],
|
||||||
|
name =project.name,
|
||||||
|
build_dir_name=config['build_dir_name'])
|
||||||
|
self.repo.set_devops(self.project, devops)
|
||||||
|
|
||||||
def name(self):
|
def name(self):
|
||||||
build = self.repo.get_devops(self.project)
|
devops = self.repo.get_devops(self.project)
|
||||||
return build.name
|
return devops.name
|
||||||
|
|
||||||
def build_path(self):
|
def build_path(self):
|
||||||
build = self.repo.get_devops(self.project)
|
devops = self.repo.get_devops(self.project)
|
||||||
return build.build_path()
|
return devops.build_path()
|
||||||
|
|
||||||
def initialize_build_dir(self):
|
def initialize_build_dir(self):
|
||||||
build = self.repo.get_devops(self.project)
|
devops = self.repo.get_devops(self.project)
|
||||||
self.file_api.clean_dir(build.build_path())
|
self.file_api.clean_dir(devops.build_path())
|
||||||
|
|
|
@ -33,12 +33,14 @@ class DnsRecord(Validateable):
|
||||||
|
|
||||||
|
|
||||||
class Devops(Validateable):
|
class Devops(Validateable):
|
||||||
def __init__(self, config):
|
def __init__(self, stage, project_root_path, module, name=None, build_dir_name="target"):
|
||||||
self.stage = config["stage"]
|
self.stage = stage
|
||||||
self.name = config["name"]
|
self.name = name
|
||||||
self.project_root_path = config["project_root_path"]
|
self.project_root_path = project_root_path
|
||||||
self.module = config["module"]
|
self.module = module
|
||||||
self.build_dir_name = config["build_dir_name"]
|
if not name:
|
||||||
|
self.name = module
|
||||||
|
self.build_dir_name = build_dir_name
|
||||||
# Deprecated - no longer use generic stack ...
|
# Deprecated - no longer use generic stack ...
|
||||||
self.stack = {}
|
self.stack = {}
|
||||||
|
|
||||||
|
|
|
@ -45,22 +45,28 @@ def test_should_validate_DnsRecord():
|
||||||
sut = DnsRecord(None)
|
sut = DnsRecord(None)
|
||||||
assert not sut.is_valid()
|
assert not sut.is_valid()
|
||||||
|
|
||||||
sut = DnsRecord('name')
|
sut = DnsRecord("name")
|
||||||
assert not sut.is_valid()
|
assert not sut.is_valid()
|
||||||
|
|
||||||
sut = DnsRecord('name', ipv4='1.2.3.4')
|
sut = DnsRecord("name", ipv4="1.2.3.4")
|
||||||
assert sut.is_valid()
|
assert sut.is_valid()
|
||||||
|
|
||||||
sut = DnsRecord('name', ipv6='1::')
|
sut = DnsRecord("name", ipv6="1::")
|
||||||
assert sut.is_valid()
|
assert sut.is_valid()
|
||||||
|
|
||||||
|
|
||||||
def test_c4k_build_should_update_fqdn(tmp_path):
|
def test_devops_buildpath():
|
||||||
project = Project(str(tmp_path), name="name")
|
sut = Devops(
|
||||||
|
stage="test", project_root_path="../../..", module="cloud", name="meissa"
|
||||||
|
)
|
||||||
|
assert "../../../target/meissa/cloud" == sut.build_path()
|
||||||
|
|
||||||
|
|
||||||
|
def test_c4k_build_should_update_fqdn():
|
||||||
project_config = {
|
project_config = {
|
||||||
"stage": "test",
|
"stage": "test",
|
||||||
"name": "name",
|
"name": "name",
|
||||||
"project_root_path": str(tmp_path),
|
"project_root_path": "mypath",
|
||||||
"module": "module",
|
"module": "module",
|
||||||
"build_dir_name": "target",
|
"build_dir_name": "target",
|
||||||
}
|
}
|
||||||
|
@ -77,7 +83,7 @@ def test_c4k_build_should_update_fqdn(tmp_path):
|
||||||
grafana_cloud_user="user",
|
grafana_cloud_user="user",
|
||||||
grafana_cloud_password="password",
|
grafana_cloud_password="password",
|
||||||
)
|
)
|
||||||
build = Devops(project_config)
|
|
||||||
sut = C4k(project_config)
|
sut = C4k(project_config)
|
||||||
sut.update_runtime_config(DnsRecord("test.de", ipv6="1::"))
|
sut.update_runtime_config(DnsRecord("test.de", ipv6="1::"))
|
||||||
|
|
||||||
|
@ -101,8 +107,9 @@ def test_c4k_build_should_update_fqdn(tmp_path):
|
||||||
} == sut.c4k_mixin_auth
|
} == sut.c4k_mixin_auth
|
||||||
|
|
||||||
|
|
||||||
def test_c4k_build_should_calculate_command(tmp_path):
|
def test_c4k_build_should_calculate_command():
|
||||||
project = Project(str(tmp_path), name="name")
|
devops = Devops(stage="test", project_root_path='',
|
||||||
|
module="module", name="name")
|
||||||
project_config = {
|
project_config = {
|
||||||
"stage": "test",
|
"stage": "test",
|
||||||
"name": "name",
|
"name": "name",
|
||||||
|
@ -117,14 +124,13 @@ def test_c4k_build_should_calculate_command(tmp_path):
|
||||||
grafana_cloud_user="user",
|
grafana_cloud_user="user",
|
||||||
grafana_cloud_password="password",
|
grafana_cloud_password="password",
|
||||||
)
|
)
|
||||||
build = Devops(project_config)
|
|
||||||
sut = C4k(project_config)
|
sut = C4k(project_config)
|
||||||
assert (
|
assert (
|
||||||
"c4k-module-standalone.jar "
|
"c4k-module-standalone.jar "
|
||||||
+ "/target/name/module/out_c4k_config.yaml "
|
+ "/target/name/module/out_c4k_config.yaml "
|
||||||
+ "/target/name/module/out_c4k_auth.yaml > "
|
+ "/target/name/module/out_c4k_auth.yaml > "
|
||||||
+ "/target/name/module/out_module.yaml"
|
+ "/target/name/module/out_module.yaml"
|
||||||
== sut.command(build)
|
== sut.command(devops)
|
||||||
)
|
)
|
||||||
|
|
||||||
project_config = {
|
project_config = {
|
||||||
|
@ -142,13 +148,11 @@ def test_c4k_build_should_calculate_command(tmp_path):
|
||||||
grafana_cloud_user="user",
|
grafana_cloud_user="user",
|
||||||
grafana_cloud_password="password",
|
grafana_cloud_password="password",
|
||||||
)
|
)
|
||||||
build = Devops(project_config)
|
|
||||||
sut = C4k(project_config)
|
sut = C4k(project_config)
|
||||||
assert (
|
assert (
|
||||||
"c4k-executabel_name-standalone.jar "
|
"c4k-executabel_name-standalone.jar "
|
||||||
+ "/target/name/module/out_c4k_config.yaml "
|
+ "/target/name/module/out_c4k_config.yaml "
|
||||||
+ "/target/name/module/out_c4k_auth.yaml > "
|
+ "/target/name/module/out_c4k_auth.yaml > "
|
||||||
+ "/target/name/module/out_module.yaml"
|
+ "/target/name/module/out_module.yaml"
|
||||||
== sut.command(build)
|
== sut.command(devops)
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue