Skip to content

Commit

Permalink
Merge pull request #663 from javacruft/feat/private-ppas
Browse files Browse the repository at this point in the history
Add support for Private PPA
  • Loading branch information
ajkavanagh authored Jul 22, 2024
2 parents d960b29 + 158adaf commit 9b47144
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 5 deletions.
26 changes: 24 additions & 2 deletions unit_tests/utilities/test_deployment_env.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,24 @@ def test_get_overlay_ppas(self):
get_options_mock.return_value = ro_types.resolve_immutable(config)
self.assertEqual(deployment_env.get_overlay_ppas(), None)

config = collections.OrderedDict(
{
'overlay_ppas': [
{
'source': "foo",
'key': "bar",
}
]
}
)
get_options_mock.return_value = ro_types.resolve_immutable(config)
self.assertEqual(
deployment_env.get_overlay_ppas(),
ro_types.ReadOnlyList([
{'source': 'foo', 'key': 'bar'}
])
)

def test_get_cloudinit_userdata(self):
with mock.patch.object(deployment_env, 'get_overlay_ppas',
return_value=None):
Expand All @@ -92,7 +110,10 @@ def test_get_cloudinit_userdata(self):
deployment_env.get_cloudinit_userdata(),
cloudinit_userdata)
with mock.patch.object(deployment_env, 'get_overlay_ppas',
return_value=['ppa:ppa0', 'ppa:ppa1']):
return_value=[
'ppa:ppa0',
{'source': 'foo', 'key': 'bar'},
]):
preferences_file = "/etc/apt/preferences.d/proposed-updates"
cloud_config = {
'apt': {
Expand All @@ -101,7 +122,8 @@ def test_get_cloudinit_userdata(self):
'source': 'ppa:ppa0'
},
'overlay-ppa-1': {
'source': 'ppa:ppa1'
'source': 'foo',
'key': 'bar',
}
}
},
Expand Down
27 changes: 24 additions & 3 deletions zaza/utilities/deployment_env.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,18 @@ def get_overlay_ppas(model_alias='default_alias'):
overlay_ppas:
- ppa:ubuntu-security-proposed/ppa
alternatively more complex sources can also be used (for
example when accessing a Private PPA):
tests_options:
model_alias:
overlay_ppas:
- source: "deb https://user:[email protected]"
key: |
-----BEGIN PGP PUBLIC KEY BLOCK-----
....
-----END PGP PUBLIC KEY BLOCK-----
:param model: Name of model alias
:type bundle: str
:returns: List of overlay PPAs
Expand Down Expand Up @@ -145,9 +157,18 @@ def get_cloudinit_userdata(model_alias='default_alias'):
overlay_ppas = get_overlay_ppas(model_alias)
if overlay_ppas:
for index, overlay_ppa in enumerate(overlay_ppas):
cloud_config['apt']['sources']["overlay-ppa-{}".format(index)] = {
'source': overlay_ppa
}
try:
# NOTE: support private PPAs with source and key keys.
cloud_config['apt']['sources']["overlay-ppa-{}".format(index)] = { # noqa
'source': overlay_ppa['source'],
'key': overlay_ppa['key'],
}
except (KeyError, TypeError):
# NOTE: simple ppa:xxx/yyy format for backwards compatibility
cloud_config['apt']['sources']["overlay-ppa-{}".format(index)] = { # noqa
'source': overlay_ppa
}

cloudinit_userdata = "#cloud-config\n{}".format(
yaml.safe_dump(cloud_config))
return cloudinit_userdata
Expand Down

0 comments on commit 9b47144

Please sign in to comment.