Skip to content

Commit

Permalink
Merge pull request #473 from freyes/expose-model-name
Browse files Browse the repository at this point in the history
Add 'model_name' configuration option.
  • Loading branch information
ajkavanagh authored Jan 13, 2022
2 parents e15cc85 + eac1950 commit f6bae71
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
8 changes: 7 additions & 1 deletion unit_tests/test_zaza_charm_lifecycle_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -162,12 +162,18 @@ def test_get_environment_deploy_single_aliased(self):
{'alias': 'bundle'}),
expect)

def test_generate_model_name(self):
@mock.patch('zaza.utilities.deployment_env.get_setup_file_contents')
def test_generate_model_name(self, get_setup_file_contents):
get_setup_file_contents.return_value = {}
self.patch_object(lc_utils.uuid, "uuid4")
self.uuid4.return_value = "longer-than-12characters"
self.assertEqual(lc_utils.generate_model_name(),
"zaza-12characters")

get_setup_file_contents.return_value = {'model_name': 'mymodel-$UUID'}
self.assertEqual(lc_utils.generate_model_name(),
"mymodel-12characters")

def test_get_charm_config(self):
self.patch("builtins.open",
new_callable=mock.mock_open(),
Expand Down
9 changes: 8 additions & 1 deletion zaza/charm_lifecycle/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,18 @@
import sys
import yaml

from string import Template

import zaza.global_options
import zaza.utilities.deployment_env as deployment_env


BUNDLE_DIR = "./tests/bundles/"
DEFAULT_TEST_DIR = "./tests"
DEFAULT_CONFIG_YAML = "tests.yaml"
DEFAULT_TEST_CONFIG = "./{}/{}".format(DEFAULT_TEST_DIR, DEFAULT_CONFIG_YAML)
DEFAULT_MODEL_ALIAS = "default_alias"
DEFAULT_MODEL_NAME = 'zaza-$UUID'
DEFAULT_DEPLOY_NAME = 'default{}'

RAW_BUNDLE = "raw-bundle"
Expand Down Expand Up @@ -486,7 +490,10 @@ def generate_model_name():
:returns: Model name
:rtype: str
"""
return 'zaza-{}'.format(str(uuid.uuid4())[-12:])
model_name_fmt = deployment_env.get_setup_file_contents().get(
"model_name", DEFAULT_MODEL_NAME)
tpl = Template(model_name_fmt)
return tpl.safe_substitute({"UUID": str(uuid.uuid4())[-12:]})


def check_output_logging(cmd):
Expand Down

0 comments on commit f6bae71

Please sign in to comment.