Skip to content

Commit 0d7a03a

Browse files
[DPE -3096] Fix profile limit memory config option (#306)
* Update data-platform-workflows to v7 * Fix profile limit memory config option Signed-off-by: Marcelo Henrique Neppel <[email protected]> * Update related unit test Signed-off-by: Marcelo Henrique Neppel <[email protected]> * Add CRAFT_SHARED_CACHE env variable to charmcraft pack wrapper Signed-off-by: Marcelo Henrique Neppel <[email protected]> --------- Signed-off-by: Marcelo Henrique Neppel <[email protected]> Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
1 parent 153c8db commit 0d7a03a

File tree

10 files changed

+56
-20
lines changed

10 files changed

+56
-20
lines changed

.github/workflows/ci.yaml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ on:
2222
jobs:
2323
lint:
2424
name: Lint
25-
uses: canonical/data-platform-workflows/.github/workflows/lint.yaml@v6.3.2
25+
uses: canonical/data-platform-workflows/.github/workflows/lint.yaml@v7.0.0
2626

2727
unit-test:
2828
name: Unit test charm
@@ -42,7 +42,7 @@ jobs:
4242

4343
build:
4444
name: Build charm
45-
uses: canonical/data-platform-workflows/.github/workflows/build_charms_with_cache.yaml@v6.3.2
45+
uses: canonical/data-platform-workflows/.github/workflows/build_charms_with_cache.yaml@v7.0.0
4646
permissions:
4747
actions: write # Needed to manage GitHub Actions cache
4848

@@ -60,7 +60,7 @@ jobs:
6060
- lint
6161
- unit-test
6262
- build
63-
uses: canonical/data-platform-workflows/.github/workflows/integration_test_charm.yaml@v6.3.2
63+
uses: canonical/data-platform-workflows/.github/workflows/integration_test_charm.yaml@v7.0.0
6464
with:
6565
artifact-name: ${{ needs.build.outputs.artifact-name }}
6666
cloud: lxd

.github/workflows/release.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,14 +24,14 @@ jobs:
2424

2525
build:
2626
name: Build charm
27-
uses: canonical/data-platform-workflows/.github/workflows/build_charm_without_cache.yaml@v6.3.2
27+
uses: canonical/data-platform-workflows/.github/workflows/build_charm_without_cache.yaml@v7.0.0
2828

2929
release:
3030
name: Release charm
3131
needs:
3232
- ci-tests
3333
- build
34-
uses: canonical/data-platform-workflows/.github/workflows/release_charm.yaml@v6.3.2
34+
uses: canonical/data-platform-workflows/.github/workflows/release_charm.yaml@v7.0.0
3535
with:
3636
channel: 14/edge
3737
artifact-name: ${{ needs.build.outputs.artifact-name }}

.github/workflows/sync_issue_to_jira.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ on:
99
jobs:
1010
sync:
1111
name: Sync GitHub issue to Jira
12-
uses: canonical/data-platform-workflows/.github/workflows/sync_issue_to_jira.yaml@v6.3.2
12+
uses: canonical/data-platform-workflows/.github/workflows/sync_issue_to_jira.yaml@v7.0.0
1313
with:
1414
jira-base-url: https://warthogs.atlassian.net
1515
jira-project-key: DPE

config.yaml

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -228,11 +228,19 @@ options:
228228
type: string
229229
default: production
230230
profile-limit-memory:
231+
type: int
232+
description: |
233+
[DEPRECTATED] Use profile_limit_memory instead. Amount of memory in Megabytes to limit PostgreSQL
234+
and associated process to. If unset, this will be decided according to the default memory limit
235+
in the selected profile. Only comes into effect when the `production` profile is selected. This
236+
config option cannot be set at the same time as profile_limit_memory.
237+
profile_limit_memory:
231238
type: int
232239
description: |
233240
Amount of memory in Megabytes to limit PostgreSQL and associated process to.
234241
If unset, this will be decided according to the default memory limit in the selected profile.
235-
Only comes into effect when the `production` profile is selected.
242+
Only comes into effect when the `production` profile is selected. This config option cannot be
243+
set at the same time as profile-limit-memory.
236244
request_date_style:
237245
description: |
238246
Sets the display format for date and time values. Allowed formats are explained

poetry.lock

Lines changed: 9 additions & 8 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pyproject.toml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -65,10 +65,10 @@ optional = true
6565

6666
[tool.poetry.group.integration.dependencies]
6767
pytest = "^7.4.0"
68-
pytest-github-secrets = {git = "https://github.com/canonical/data-platform-workflows", tag = "v6.3.2", subdirectory = "python/pytest_plugins/github_secrets"}
68+
pytest-github-secrets = {git = "https://github.com/canonical/data-platform-workflows", tag = "v7.0.0", subdirectory = "python/pytest_plugins/github_secrets"}
6969
pytest-operator = "^0.29.0"
70-
pytest-operator-cache = {git = "https://github.com/canonical/data-platform-workflows", tag = "v6.3.2", subdirectory = "python/pytest_plugins/pytest_operator_cache"}
71-
pytest-operator-groups = {git = "https://github.com/canonical/data-platform-workflows", tag = "v6.3.2", subdirectory = "python/pytest_plugins/pytest_operator_groups"}
70+
pytest-operator-cache = {git = "https://github.com/canonical/data-platform-workflows", tag = "v7.0.0", subdirectory = "python/pytest_plugins/pytest_operator_cache"}
71+
pytest-operator-groups = {git = "https://github.com/canonical/data-platform-workflows", tag = "v7.0.0", subdirectory = "python/pytest_plugins/pytest_operator_groups"}
7272
juju = "^3.2.2"
7373
boto3 = "^1.28.70"
7474
tenacity = "^8.2.3"

src/charm.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1369,6 +1369,14 @@ def _is_workload_running(self) -> bool:
13691369

13701370
def update_config(self, is_creating_backup: bool = False) -> bool:
13711371
"""Updates Patroni config file based on the existence of the TLS files."""
1372+
if (
1373+
self.model.config.get("profile-limit-memory") is not None
1374+
and self.model.config.get("profile_limit_memory") is not None
1375+
):
1376+
raise ValueError(
1377+
"Both profile-limit-memory and profile_limit_memory are set. Please use only one of them."
1378+
)
1379+
13721380
enable_tls = self.is_tls_enabled
13731381
limit_memory = None
13741382
if self.config.profile_limit_memory:

src/config.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,7 @@ def profile_limit_memory_validator(cls, value: int) -> Optional[int]:
204204
if value < 128:
205205
raise ValueError("PostgreSQL Charm requires at least 128MB")
206206
if value > 9999999:
207-
raise ValueError("`profile-limit-memory` limited to 7 digits (9999999MB)")
207+
raise ValueError("`profile_limit_memory` limited to 7 digits (9999999MB)")
208208

209209
return value
210210

tests/unit/test_charm.py

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1164,11 +1164,28 @@ def test_update_config(
11641164
with patch.object(PostgresqlOperatorCharm, "postgresql", Mock()) as postgresql_mock:
11651165
# Mock some properties.
11661166
postgresql_mock.is_tls_enabled = PropertyMock(side_effect=[False, False, False, False])
1167-
_is_workload_running.side_effect = [True, True, False, True]
1167+
_is_workload_running.side_effect = [False, False, True, True, False, True]
11681168
_member_started.side_effect = [True, True, False]
11691169
postgresql_mock.build_postgresql_parameters.return_value = {"test": "test"}
11701170

1171+
# Test when only one of the two config options for profile limit memory is set.
1172+
self.harness.update_config({"profile-limit-memory": 1000})
1173+
self.charm.update_config()
1174+
1175+
# Test when only one of the two config options for profile limit memory is set.
1176+
self.harness.update_config(
1177+
{"profile_limit_memory": 1000}, unset={"profile-limit-memory"}
1178+
)
1179+
self.charm.update_config()
1180+
1181+
# Test when the two config options for profile limit memory are set at the same time.
1182+
_render_patroni_yml_file.reset_mock()
1183+
self.harness.update_config({"profile-limit-memory": 1000})
1184+
with self.assertRaises(ValueError):
1185+
self.charm.update_config()
1186+
11711187
# Test without TLS files available.
1188+
self.harness.update_config(unset={"profile-limit-memory", "profile_limit_memory"})
11721189
self.harness.update_relation_data(
11731190
self.rel_id, self.charm.unit.name, {"tls": "enabled"}
11741191
) # Mock some data in the relation to test that it change.

tox.ini

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ allowlist_externals =
1919

2020
[testenv:{build,pack-wrapper}]
2121
# Wrap `charmcraft pack`
22+
pass_env =
23+
CRAFT_SHARED_CACHE
2224
allowlist_externals =
2325
{[testenv]allowlist_externals}
2426
charmcraft

0 commit comments

Comments
 (0)