Skip to content

Commit

Permalink
Merge pull request #122 from msimonin/fix-121
Browse files Browse the repository at this point in the history
expand topology when loading the config
  • Loading branch information
rcherrueau authored Apr 24, 2017
2 parents 1e55bc4 + e2f0bbb commit eb8f79d
Show file tree
Hide file tree
Showing 4 changed files with 63 additions and 1 deletion.
31 changes: 31 additions & 0 deletions enos/tests/utils/test_extra.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,37 @@ def test_expand_groups_with_weird_name(self):
self.assertEquals(3, len(expanded))


class TestBuildResources(unittest.TestCase):

def test_build_resources(self):
topology = {
"grp1": {
"a":{
"control": 1,
}
},
"grp2": {
"a":{
"compute": 10,
}
},
"grp3": {
"a":{
"compute": 10,
}
}
}

resources_expected = {
"a": {
"control": 1,
"compute": 20
}
}
resources_actual = build_resources(topology)
self.assertDictEqual(resources_expected, resources_actual)


class TestBuildRoles(unittest.TestCase):

def setUp(self):
Expand Down
29 changes: 29 additions & 0 deletions enos/tests/utils/test_provider.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,35 @@
from enos.utils.provider import *
import copy

class TestLoadConfig(unittest.TestCase):
def test_load_config_with_topology(self):
config = {
'topology':{
'grp1': {
'a':{
'control': 1,
}
},
'grp[2-6]': {
'a':{
'compute': 10,
}
}
},
'provider': 'test_provider'
}
expected_resources = {
'resources': {
"a": {
"control": 1,
"compute": 50
}
}
}
conf = load_config(config, default_config={}, default_provider_config={})
self.assertDictEqual(expected_resources['resources'], conf['resources'])


class TestLoadProviderConfig(unittest.TestCase):
def test_load_provider_config_nest_type(self):
provider_config = 'myprovider'
Expand Down
2 changes: 2 additions & 0 deletions enos/utils/extra.py
Original file line number Diff line number Diff line change
Expand Up @@ -255,6 +255,8 @@ def build_resources(topology):
"""Build the resource list
For now we are just aggregating all the resources
This could be part of a flat resource builder
NOTE: topology must be expanded before calling build_resources
"""

def merge_add(cluster_roles, roles):
Expand Down
2 changes: 1 addition & 1 deletion enos/utils/provider.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ def load_config(config, default_config={}, default_provider_config={}):
conf['topology'] = expand_topology(config['topology'])
# We are here using a flat combination of the resource
# resulting in (probably) deploying one single region
conf['resources'] = build_resources(config['topology'])
conf['resources'] = build_resources(conf['topology'])

conf['provider'] = load_provider_config(
conf['provider'],
Expand Down

0 comments on commit eb8f79d

Please sign in to comment.