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

Fix integration tests #544

Merged
merged 4 commits into from
Sep 17, 2021
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
12 changes: 9 additions & 3 deletions juju/application.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
from .status import derive_status
from .annotationhelper import _get_annotations, _set_annotations
from .client import client
from .errors import JujuError
from .errors import JujuError, JujuApplicationConfigError
from .bundle import get_charm_series
from .placement import parse as parse_placement

Expand Down Expand Up @@ -519,8 +519,14 @@ async def set_config(self, config):

str_config = {}
for k, v in config.items():
if v.get('value') is not None:
str_config[k] = str(v.get('value'))
if isinstance(v, str):
str_config[k] = v
elif isinstance(v, dict):
# pairs with a value of None are ignored
if v.get('value', False):
str_config[k] = str(v.get('value'))
else:
raise JujuApplicationConfigError(config, [k, v])

await app_facade.Set(application=self.name, options=str_config)

Expand Down
22 changes: 22 additions & 0 deletions juju/errors.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,3 +77,25 @@ class JujuAppError(JujuError):

class JujuUnitError(JujuError):
pass


class JujuConfigError(JujuError):
"""Exception raised during processing a configuration key-value pair
in a config set for an application.
"""
def __init__(self, config, config_pair, message=None):
self.config = config
self.config_pair = config_pair
if message is None:
self.message = "Couldn't process the value of a config pair : %s, value of type %s" % (self.config_pair, type(self.config_pair[1]))
else:
self.message = message
super().__init__(self.message)


class JujuApplicationConfigError(JujuConfigError):
pass


class JujuModelConfigError(JujuConfigError):
pass
6 changes: 5 additions & 1 deletion juju/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
from .constraints import parse as parse_constraints
from .controller import Controller
from .delta import get_entity_class, get_entity_delta
from .errors import JujuAPIError, JujuError
from .errors import JujuAPIError, JujuError, JujuModelConfigError
from .errors import JujuAppError, JujuUnitError, JujuAgentError, JujuMachineError
from .exceptions import DeadEntityException
from .names import is_valid_application
Expand Down Expand Up @@ -2163,6 +2163,10 @@ async def set_config(self, config):
for key, value in config.items():
if isinstance(value, ConfigValue):
new_conf[key] = value.value
elif isinstance(value, str):
new_conf[key] = value
else:
raise JujuModelConfigError("Expected either a string or a ConfigValue as a config value, found : %s of type %s" % (value, type(value)))
await config_facade.ModelSet(config=new_conf)

async def set_constraints(self, constraints):
Expand Down