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