Skip to content

Commit

Permalink
added string interpolation to deploy groups
Browse files Browse the repository at this point in the history
  • Loading branch information
mjksmith committed Feb 16, 2016
1 parent 33a14ff commit 17d5c94
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 0 deletions.
12 changes: 12 additions & 0 deletions paasta_tools/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,18 @@ def __init__(self, cluster, instance, service, config_dict, branch_dict):
self.cluster = cluster
self.instance = instance
self.service = service
config_interpolation_keys = ('deploy_group',)
interpolation_facts = self.__get_interpolation_facts()
for key in config_interpolation_keys:
if key in self.config_dict:
self.config_dict[key] = self.config_dict[key].format(**interpolation_facts)

def __get_interpolation_facts(self):
return {
'cluster': self.cluster,
'instance': self.instance,
'service': self.service,
}

def get_cluster(self):
return self.cluster
Expand Down
30 changes: 30 additions & 0 deletions tests/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -776,6 +776,36 @@ def test_get_disk_default(self):
)
assert fake_conf.get_disk() == 1024

def test_deploy_group_default(self):
fake_conf = utils.InstanceConfig(
service='',
instance='fake_instance',
cluster='fake_cluster',
config_dict={},
branch_dict={},
)
assert fake_conf.get_deploy_group() == 'fake_cluster.fake_instance'

def test_deploy_group_if_config(self):
fake_conf = utils.InstanceConfig(
service='',
instance='',
cluster='',
config_dict={'deploy_group': 'fake_deploy_group'},
branch_dict={},
)
assert fake_conf.get_deploy_group() == 'fake_deploy_group'

def test_deploy_group_string_interpolation(self):
fake_conf = utils.InstanceConfig(
service='',
instance='',
cluster='fake_cluster',
config_dict={'deploy_group': 'cluster_is_{cluster}'},
branch_dict={},
)
assert fake_conf.get_deploy_group() == 'cluster_is_fake_cluster'

def test_get_cmd_default(self):
fake_conf = utils.InstanceConfig(
service='',
Expand Down

0 comments on commit 17d5c94

Please sign in to comment.