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

Allow ApplicationFacade set_config with non-string values #540

Merged
merged 2 commits into from
Sep 15, 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
7 changes: 6 additions & 1 deletion juju/application.py
Original file line number Diff line number Diff line change
Expand Up @@ -517,7 +517,12 @@ async def set_config(self, config):
log.debug(
'Setting config for %s: %s', self.name, config)

return await app_facade.Set(application=self.name, options=config)
str_config = {}
for k, v in config.items():
if v.get('value') is not None:
str_config[k] = str(v.get('value'))

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

async def reset_config(self, to_default):
"""
Expand Down
25 changes: 25 additions & 0 deletions tests/integration/test_application.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,31 @@ async def test_action(event_loop):
assert 'backup' in actions.keys()


@base.bootstrapped
@pytest.mark.asyncio
async def test_get_set_config(event_loop):
async with base.CleanModel() as model:
ubuntu_app = await model.deploy(
'percona-cluster',
application_name='mysql',
series='xenial',
channel='stable',
config={
'tuning-level': 'safest',
},
constraints={
'arch': 'amd64',
'mem': 256 * MB,
},
)

config = await ubuntu_app.get_config()
await ubuntu_app.set_config(config)

config2 = await ubuntu_app.get_config()
assert config == config2


@base.bootstrapped
@pytest.mark.asyncio
async def test_status_is_not_unset(event_loop):
Expand Down
64 changes: 40 additions & 24 deletions tests/unit/test_bundle.py
Original file line number Diff line number Diff line change
Expand Up @@ -1001,29 +1001,45 @@ async def __call__(self, *args, **kwargs):

bundle = await handler._handle_local_charms(bundle, bundle_dir)

model.add_local_resources.assert_has_calls([
mock.call(
"oci-image-charm",
"charm_uri",
yaml.load(Path("tests/integration/oci-image-charm/metadata.yaml").read_text(), Loader=yaml.FullLoader),
resources={"oci-image": "ubuntu:latest"},
),
mock.call(
"oci-image-charm-2",
"charm_uri",
yaml.load(Path("tests/integration/oci-image-charm-no-series/metadata.yaml").read_text(), Loader=yaml.FullLoader),
resources={"oci-image": "ubuntu:latest"},
),
mock.call(
"oci-image-charm-3",
"charm_uri",
yaml.load(Path("tests/integration/oci-image-charm-no-series/metadata.yaml").read_text(), Loader=yaml.FullLoader),
resources={"oci-image": "ubuntu:latest"},
)]
# TODO: for some reason 'assert_has_calls' is failing in
# Python3.5, refactor this with 'assert_has_calls' when
# Python3.5 support is dropped

m1 = mock.call(
"oci-image-charm",
"charm_uri",
yaml.load(Path("tests/integration/oci-image-charm/metadata.yaml").read_text(), Loader=yaml.FullLoader),
resources={"oci-image": "ubuntu:latest"},
)
model.add_local_charm_dir.assert_has_calls([
mock.call(charm_path_1, "focal"),
mock.call(charm_path_2, "focal"),
mock.call(charm_path_2, "focal")
])

m2 = mock.call(
"oci-image-charm-2",
"charm_uri",
yaml.load(Path("tests/integration/oci-image-charm-no-series/metadata.yaml").read_text(), Loader=yaml.FullLoader),
resources={"oci-image": "ubuntu:latest"},
)

m3 = mock.call(
"oci-image-charm-3",
"charm_uri",
yaml.load(Path("tests/integration/oci-image-charm-no-series/metadata.yaml").read_text(), Loader=yaml.FullLoader),
resources={"oci-image": "ubuntu:latest"},
)

m_add_local_resources_calls = model.add_local_resources.mock_calls
assert len(m_add_local_resources_calls) == 3
assert m1 in m_add_local_resources_calls and \
m2 in m_add_local_resources_calls and \
m3 in m_add_local_resources_calls

mc_1 = mock.call(charm_path_1, "focal")
mc_2 = mock.call(charm_path_2, "focal")
mc_3 = mock.call(charm_path_2, "focal")

m_add_local_charm_dir_calls = model.add_local_charm_dir.mock_calls
assert len(m_add_local_charm_dir_calls) == 3
assert mc_1 in m_add_local_charm_dir_calls and \
mc_2 in m_add_local_charm_dir_calls and \
mc_3 in m_add_local_charm_dir_calls

assert bundle["applications"]["oci-image-charm"]["resources"]["oci-image"] == "id"