Skip to content

Commit

Permalink
Add test config grammar for per app overlay ppa.
Browse files Browse the repository at this point in the history
In some circumstances we want to install packages from overlay PPA
on specific applications and not across the whole model.

Add configuration grammar, actual implementation of generic setup
step will follow in subsequent patch.

Signed-off-by: Frode Nordahl <[email protected]>
  • Loading branch information
fnordahl committed Oct 22, 2024
1 parent ae5e9f7 commit e2140aa
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 5 deletions.
25 changes: 25 additions & 0 deletions unit_tests/utilities/test_deployment_env.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,31 @@ def test_get_overlay_ppas(self):
])
)

config = collections.OrderedDict(
{
'overlay_ppas': {
'application': [
'ppa:app-ppav1',
{
'source': 'app-ppav2',
'key': 'app-bar',
},
]
},
}
)
get_options_mock.return_value = ro_types.resolve_immutable(config)
self.assertIsNone(
deployment_env.get_overlay_ppas()
)
self.assertEqual(
deployment_env.get_overlay_ppas(application='application'),
ro_types.ReadOnlyList([
'ppa:app-ppav1',
{'source': 'app-ppav2', 'key': 'app-bar'},
])
)

def test_get_cloudinit_userdata(self):
with mock.patch.object(deployment_env, 'get_overlay_ppas',
return_value=None):
Expand Down
35 changes: 30 additions & 5 deletions zaza/utilities/deployment_env.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ def parse_option_list_string(option_list, delimiter=None):
return settings


def get_overlay_ppas(model_alias='default_alias'):
def get_overlay_ppas(model_alias='default_alias', application=None):
"""Get overlay_ppas from global_config.
In the config file for the tests, the tests_options.overlay_ppa option
Expand All @@ -95,20 +95,45 @@ def get_overlay_ppas(model_alias='default_alias'):
Please refer to docstring of parse_overlay_ppa function for more
information.
When application is provided, additional grammar to constrain the
overlay PPA to specific applications is supported, for example:
overlay_ppas:
myapp:
- ppa:mylpuser/myppa
myotherapp:
- source: fakesource
key: fakekey
:param model_alias: Name of model alias, defaults to 'default_alias'.
:type model_alias: Option[str]
:param application: Name of application to retrieve config for.
:type application: Option[str]
:returns: List of overlay PPAs.
:rtype: Option[List[Any]]
"""
config = zaza.global_options.get_options()
try:
return config[model_alias].overlay_ppas
config_overlay_ppas = config[model_alias].overlay_ppas
except KeyError:
try:
return config.overlay_ppas
config_overlay_ppas = config.overlay_ppas
except KeyError:
pass
return None
return None

if application:
try:
return config_overlay_ppas[application]
except (KeyError, TypeError):
return None

# Avoid returning application dictionary when overlay_ppas config is
# Dict-like object and application is not requested.
try:
config_overlay_ppas.get(None)
return None
except AttributeError:
return config_overlay_ppas


def _parse_overlay_ppa_v1(overlay_ppa):
Expand Down

0 comments on commit e2140aa

Please sign in to comment.