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

[libjuju-3.1] Add provision to configure credentials via .zaza.yaml #642

Merged
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 @@ -24,6 +24,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 @@ -33,6 +34,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 @@ -260,6 +260,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 @@ -43,6 +43,7 @@ def prepare(model_name, test_directory=None):
model_name,
config=deployment_env.get_model_settings(),
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,
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 @@ -129,6 +129,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