Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add provision to configure credentials via .zaza.yaml #641

Merged
merged 1 commit into from
Jan 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions doc/source/runningcharmtests.rst
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ via a .zaza.yaml file, eg.::
---
region: my-region-name
cloud: my-cloud
credential: my-credential

The above configuration is required to run Zaza on a multi cloud / region Juju
controller.
Expand Down
2 changes: 2 additions & 0 deletions unit_tests/test_zaza_charm_lifecycle_prepare.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ def test_prepare(self):
self.patch_object(lc_prepare.deployment_env, 'get_model_constraints')
self.patch_object(lc_prepare.deployment_env, 'get_cloud_region')
self.patch_object(lc_prepare.deployment_env, 'get_cloud_name')
self.patch_object(lc_prepare.deployment_env, 'get_credential_name')
self.patch_object(lc_prepare.zaza.model, 'set_model_constraints')
self.get_model_settings.return_value = {'default-series': 'hardy'}
self.get_model_constraints.return_value = {'image-stream': 'released'}
Expand All @@ -35,6 +36,7 @@ def test_prepare(self):
config={
'default-series': 'hardy'},
cloud_name=None,
credential_name=None,
region=None)
self.set_model_constraints.assert_called_once_with(
constraints={'image-stream': 'released'},
Expand Down
19 changes: 19 additions & 0 deletions unit_tests/utilities/test_deployment_env.py
Original file line number Diff line number Diff line change
Expand Up @@ -350,6 +350,25 @@ def test_get_cloud_name_default(self):
deployment_env.get_cloud_name(),
None)

def test_get_credential_name(self):
self.patch_object(
deployment_env,
'get_setup_file_contents',
return_value={
'credential': 'test'})
self.assertEqual(
deployment_env.get_credential_name(),
'test')

def test_get_credential_name_default(self):
self.patch_object(
deployment_env,
'get_setup_file_contents',
return_value={})
self.assertEqual(
deployment_env.get_credential_name(),
None)

def test_get_tmpdir(self):
self.patch_object(deployment_env.os, 'mkdir')
self.patch_object(deployment_env.os.path, 'exists')
Expand Down
1 change: 1 addition & 0 deletions zaza/charm_lifecycle/prepare.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ def prepare(model_name, model_alias='default_alias', test_directory=None):
model_name,
config=deployment_env.get_model_settings(model_alias),
cloud_name=deployment_env.get_cloud_name(),
credential_name=deployment_env.get_credential_name(),
region=deployment_env.get_cloud_region())
zaza.model.set_model_constraints(
model_name=model_name,
Expand Down
10 changes: 8 additions & 2 deletions zaza/controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@


async def async_add_model(
model_name, config=None, cloud_name=None, region=None):
model_name, config=None, cloud_name=None, credential_name=None, region=None
):
"""Add a model to the current controller.

:param model_name: Name to give the new model.
Expand All @@ -39,7 +40,12 @@ async def async_add_model(
await controller.connect()
logging.debug("Adding model {}".format(model_name))
model = await controller.add_model(
model_name, config=config, cloud_name=cloud_name, region=region)
model_name,
config=config,
cloud_name=cloud_name,
credential_name=credential_name,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Normally, I'd suggest that this was:

credential_name=credential_name or None,

to force it to None if it is "not-truthy" to be really explicit about what is passed, but I've checked the python-libjuju and it only does a truthy check on credential_name anyway. Oh well.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's a good suggestion! I was mostly following the layout of the other parameters 😄

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's a good suggestion! I was mostly following the layout of the other parameters 😄

And I think that's really reasonable as well! :-)

region=region,
)
# issue/135 It is necessary to disconnect the model here or async spews
# tracebacks even during a successful run.
await model.disconnect()
Expand Down
9 changes: 9 additions & 0 deletions zaza/utilities/deployment_env.py
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,15 @@ def get_cloud_name():
return get_setup_file_contents().get('cloud')


def get_credential_name():
"""Return a configured credential name to support multi-cloud controllers.

:returns: A string configured in .zaza.yaml or None
:rtype: Union[str, None]
"""
return get_setup_file_contents().get('credential')


def get_cloud_region():
"""Return a configured region name to support multi-cloud controllers.

Expand Down
Loading