Skip to content

Commit

Permalink
[DPE-2610] Remove support of Juju 2.9 (#202)
Browse files Browse the repository at this point in the history
* Remove support of Juju 2.9

* Update juju settings for CI

* Remove juju 2.9 from pyproject.toml

* Update pyproject.toml

Co-authored-by: Mykola Marzhan <303592+delgod@users.noreply.github.com>

* Update tox.ini

Co-authored-by: Mykola Marzhan <303592+delgod@users.noreply.github.com>

* Update poetry.lock

* Update juju version in tox.ini

---------

Co-authored-by: Mykola Marzhan <303592+delgod@users.noreply.github.com>
  • Loading branch information
dmitry-ratushnyy and delgod authored Sep 26, 2023
1 parent 5610ceb commit 88d41b2
Show file tree
Hide file tree
Showing 10 changed files with 132 additions and 166 deletions.
3 changes: 2 additions & 1 deletion .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,8 @@ jobs:
provider: microk8s
channel: "1.27-strict/stable"
bootstrap-constraints: "cores=2 mem=2G"
bootstrap-options: "--agent-version 2.9.44"
juju-channel: 3.1/stable
bootstrap-options: "--agent-version 3.1.5"
- name: Download packed charm(s)
uses: actions/download-artifact@v3
with:
Expand Down
8 changes: 4 additions & 4 deletions lib/charms/mongodb/v0/mongodb_backups.py
Original file line number Diff line number Diff line change
Expand Up @@ -523,7 +523,7 @@ def _try_to_restore(self, backup_id: str) -> None:
restore_cmd = restore_cmd + remapping_args.split(" ")
self.charm.run_pbm_command(restore_cmd)
except (subprocess.CalledProcessError, ExecError) as e:
if type(e) == subprocess.CalledProcessError:
if type(e) is subprocess.CalledProcessError:
error_message = e.output.decode("utf-8")
else:
error_message = str(e.stderr)
Expand Down Expand Up @@ -560,7 +560,7 @@ def _try_to_backup(self):
)
return backup_id_match.group("backup_id") if backup_id_match else "N/A"
except (subprocess.CalledProcessError, ExecError) as e:
if type(e) == subprocess.CalledProcessError:
if type(e) is subprocess.CalledProcessError:
error_message = e.output.decode("utf-8")
else:
error_message = str(e.stderr)
Expand Down Expand Up @@ -636,13 +636,13 @@ def _get_backup_restore_operation_result(self, current_pbm_status, previous_pbm_
to contain the operation type (backup/restore) and the backup id.
"""
if (
type(current_pbm_status) == type(previous_pbm_status)
type(current_pbm_status) is type(previous_pbm_status)
and current_pbm_status.message == previous_pbm_status.message
):
return f"Operation is still in progress: '{current_pbm_status.message}'"

if (
type(previous_pbm_status) == MaintenanceStatus
type(previous_pbm_status) is MaintenanceStatus
and "backup id:" in previous_pbm_status.message
):
backup_id = previous_pbm_status.message.split("backup id:")[-1].strip()
Expand Down
171 changes: 105 additions & 66 deletions poetry.lock

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ lightkube = "^0.13.0"
pytest = "^7.3.1"
pytest-mock = "^3.11.1"
pytest-operator = "^0.27.0"
juju = "2.9.44.0 || 3.2.0.1"
juju = "3.2.2"
pytest-operator-cache = {git = "https://github.com/canonical/data-platform-workflows", tag = "v5", subdirectory = "python/pytest_plugins/pytest_operator_cache"}

[build-system]
Expand Down
10 changes: 10 additions & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -208,25 +208,33 @@ pyrsistent==0.19.3 ; python_full_version >= "3.8.10" and python_full_version < "
--hash=sha256:f0774bf48631f3a20471dd7c5989657b639fd2d285b861237ea9e82c36a415a9 \
--hash=sha256:f0e7c4b2f77593871e918be000b96c8107da48444d57005b6a6bc61fb4331b2c
pyyaml==6.0.1 ; python_full_version >= "3.8.10" and python_full_version < "4.0.0" \
--hash=sha256:04ac92ad1925b2cff1db0cfebffb6ffc43457495c9b3c39d3fcae417d7125dc5 \
--hash=sha256:062582fca9fabdd2c8b54a3ef1c978d786e0f6b3a1510e0ac93ef59e0ddae2bc \
--hash=sha256:0d3304d8c0adc42be59c5f8a4d9e3d7379e6955ad754aa9d6ab7a398b59dd1df \
--hash=sha256:1635fd110e8d85d55237ab316b5b011de701ea0f29d07611174a1b42f1444741 \
--hash=sha256:184c5108a2aca3c5b3d3bf9395d50893a7ab82a38004c8f61c258d4428e80206 \
--hash=sha256:18aeb1bf9a78867dc38b259769503436b7c72f7a1f1f4c93ff9a17de54319b27 \
--hash=sha256:1d4c7e777c441b20e32f52bd377e0c409713e8bb1386e1099c2415f26e479595 \
--hash=sha256:1e2722cc9fbb45d9b87631ac70924c11d3a401b2d7f410cc0e3bbf249f2dca62 \
--hash=sha256:1fe35611261b29bd1de0070f0b2f47cb6ff71fa6595c077e42bd0c419fa27b98 \
--hash=sha256:28c119d996beec18c05208a8bd78cbe4007878c6dd15091efb73a30e90539696 \
--hash=sha256:326c013efe8048858a6d312ddd31d56e468118ad4cdeda36c719bf5bb6192290 \
--hash=sha256:40df9b996c2b73138957fe23a16a4f0ba614f4c0efce1e9406a184b6d07fa3a9 \
--hash=sha256:42f8152b8dbc4fe7d96729ec2b99c7097d656dc1213a3229ca5383f973a5ed6d \
--hash=sha256:49a183be227561de579b4a36efbb21b3eab9651dd81b1858589f796549873dd6 \
--hash=sha256:4fb147e7a67ef577a588a0e2c17b6db51dda102c71de36f8549b6816a96e1867 \
--hash=sha256:50550eb667afee136e9a77d6dc71ae76a44df8b3e51e41b77f6de2932bfe0f47 \
--hash=sha256:510c9deebc5c0225e8c96813043e62b680ba2f9c50a08d3724c7f28a747d1486 \
--hash=sha256:5773183b6446b2c99bb77e77595dd486303b4faab2b086e7b17bc6bef28865f6 \
--hash=sha256:596106435fa6ad000c2991a98fa58eeb8656ef2325d7e158344fb33864ed87e3 \
--hash=sha256:6965a7bc3cf88e5a1c3bd2e0b5c22f8d677dc88a455344035f03399034eb3007 \
--hash=sha256:69b023b2b4daa7548bcfbd4aa3da05b3a74b772db9e23b982788168117739938 \
--hash=sha256:6c22bec3fbe2524cde73d7ada88f6566758a8f7227bfbf93a408a9d86bcc12a0 \
--hash=sha256:704219a11b772aea0d8ecd7058d0082713c3562b4e271b849ad7dc4a5c90c13c \
--hash=sha256:7e07cbde391ba96ab58e532ff4803f79c4129397514e1413a7dc761ccd755735 \
--hash=sha256:81e0b275a9ecc9c0c0c07b4b90ba548307583c125f54d5b6946cfee6360c733d \
--hash=sha256:855fb52b0dc35af121542a76b9a84f8d1cd886ea97c84703eaa6d88e37a2ad28 \
--hash=sha256:8d4e9c88387b0f5c7d5f281e55304de64cf7f9c0021a3525bd3b1c542da3b0e4 \
--hash=sha256:9046c58c4395dff28dd494285c82ba00b546adfc7ef001486fbf0324bc174fba \
--hash=sha256:9eb6caa9a297fc2c2fb8862bc5370d0303ddba53ba97e71f08023b6cd73d16a8 \
--hash=sha256:a0cd17c15d3bb3fa06978b4e8958dcdc6e0174ccea823003a106c7d4d7899ac5 \
Expand All @@ -241,7 +249,9 @@ pyyaml==6.0.1 ; python_full_version >= "3.8.10" and python_full_version < "4.0.0
--hash=sha256:bfdf460b1736c775f2ba9f6a92bca30bc2095067b8a9d77876d1fad6cc3b4a43 \
--hash=sha256:c8098ddcc2a85b61647b2590f825f3db38891662cfc2fc776415143f599bb859 \
--hash=sha256:d2b04aac4d386b172d5b9692e2d2da8de7bfb6c387fa4f801fbf6fb2e6ba4673 \
--hash=sha256:d483d2cdf104e7c9fa60c544d92981f12ad66a457afae824d146093b8c294c54 \
--hash=sha256:d858aa552c999bc8a8d57426ed01e40bef403cd8ccdd0fc5f6f04a00414cac2a \
--hash=sha256:e7d73685e87afe9f3b36c799222440d6cf362062f78be1013661b00c5c6f678b \
--hash=sha256:f003ed9ad21d6a4713f0a9b5a7a0a79e08dd0f221aff4525a2be4c346ee60aab \
--hash=sha256:f22ac1c3cac4dbc50079e965eba2c1058622631e526bd9afd45fedd49ba781fa \
--hash=sha256:faca3bdcf85b2fc05d06ff3fbc1f83e1391b3e724afa3feba7d13eeab355484c \
Expand Down
28 changes: 3 additions & 25 deletions src/charm.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@
OperatorUser,
)
from charms.prometheus_k8s.v0.prometheus_scrape import MetricsEndpointProvider
from ops import JujuVersion
from ops.charm import (
ActionEvent,
CharmBase,
Expand Down Expand Up @@ -849,14 +848,7 @@ def _juju_secret_get_key(self, scope: Scopes, key: str) -> Optional[str]:

def get_secret(self, scope: Scopes, key: str) -> Optional[str]:
"""Getting a secret."""
peer_data = self._peer_data(scope)

juju_version = JujuVersion.from_environ()

if juju_version.has_secrets:
return self._juju_secret_get_key(scope, key)
else:
return peer_data.get(key)
return self._juju_secret_get_key(scope, key)

def _juju_secret_set(self, scope: Scopes, key: str, value: str) -> str:
"""Helper function setting Juju secret."""
Expand Down Expand Up @@ -903,16 +895,7 @@ def set_secret(self, scope: Scopes, key: str, value: Optional[str]) -> Optional[
if not value:
return self.remove_secret(scope, key)

juju_version = JujuVersion.from_environ()

result = None
if juju_version.has_secrets:
result = self._juju_secret_set(scope, key, value)
else:
peer_data = self._peer_data(scope)
peer_data.update({key: value})

return result
return self._juju_secret_set(scope, key, value)

def _juju_secret_remove(self, scope: Scopes, key: str) -> None:
"""Remove a Juju 3.x secret."""
Expand All @@ -934,12 +917,7 @@ def _juju_secret_remove(self, scope: Scopes, key: str) -> None:

def remove_secret(self, scope, key) -> None:
"""Removing a secret."""
juju_version = JujuVersion.from_environ()
if juju_version.has_secrets:
return self._juju_secret_remove(scope, key)

peer_data = self._peer_data(scope)
del peer_data[key]
return self._juju_secret_remove(scope, key)

def restart_mongod_service(self):
"""Restart mongod service."""
Expand Down
44 changes: 0 additions & 44 deletions tests/conftest.py

This file was deleted.

17 changes: 0 additions & 17 deletions tests/integration/test_charm.py
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,6 @@ async def test_only_leader_can_set_while_all_can_read_password_secret(ops_test:
assert password2 == password


@pytest.mark.usefixtures("only_with_juju_secrets")
async def test_reset_and_get_password_secret_same_as_cli(ops_test: OpsTest) -> None:
"""Test verifies that we can set and retrieve the correct password using Juju 3.x secrets."""
new_password = str(uuid4())
Expand All @@ -159,21 +158,6 @@ async def test_reset_and_get_password_secret_same_as_cli(ops_test: OpsTest) -> N
assert data[secret_id]["content"]["Data"]["monitor-password"] == password


@pytest.mark.usefixtures("only_without_juju_secrets")
async def test_reset_and_get_password_no_secret(ops_test: OpsTest, mocker) -> None:
"""Test verifies that we can set and retrieve the correct password using Juju 2.x."""
new_password = str(uuid4())

# Re=setting existing password
leader_id = await get_leader_id(ops_test)
await set_password(ops_test, unit_id=leader_id, username="monitor", password=new_password)

# Getting back the pw programmatically
password = await get_password(ops_test, unit_id=leader_id, username="monitor")
assert password == new_password


@pytest.mark.usefixtures("only_with_juju_secrets")
async def test_empty_password(ops_test: OpsTest) -> None:
"""Test that the password can't be set to an empty string."""
leader_id = await get_leader_id(ops_test)
Expand All @@ -186,7 +170,6 @@ async def test_empty_password(ops_test: OpsTest) -> None:
assert password1 == password2


@pytest.mark.usefixtures("only_with_juju_secrets")
async def test_no_password_change_on_invalid_password(ops_test: OpsTest) -> None:
"""Test that in general, there is no change when password validation fails."""
leader_id = await get_leader_id(ops_test)
Expand Down
1 change: 0 additions & 1 deletion tests/unit/test_charm.py
Original file line number Diff line number Diff line change
Expand Up @@ -651,7 +651,6 @@ def test_set_reset_existing_password_app(self):
self.harness.charm.set_secret("app", "monitor-password", "blablabla")
assert self.harness.charm.get_secret("app", "monitor-password") == "blablabla"

@pytest.mark.usefixtures("only_with_juju_secrets")
@parameterized.expand([("app"), ("unit")])
def test_set_secret_returning_secret_id(self, scope):
secret_id = self.harness.charm.set_secret("app", "somekey", "bla")
Expand Down
14 changes: 7 additions & 7 deletions tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ pass_env =
CI
commands_pre =
poetry install --with integration
poetry run pip install juju==2.9.44.0
poetry run pip install juju==3.2.2
commands =
poetry run pytest -v --tb native --log-cli-level=INFO -s {posargs} {[vars]tests_path}/integration/test_charm.py

Expand All @@ -81,7 +81,7 @@ pass_env =
CI
commands_pre =
poetry install --with integration
poetry run pip install juju==2.9.44.0
poetry run pip install juju==3.2.2
commands =
poetry run pytest -v --tb native --log-cli-level=INFO -s --durations=0 {posargs} {[vars]tests_path}/integration/ha_tests/test_ha.py

Expand All @@ -92,7 +92,7 @@ pass_env =
CI
commands_pre =
poetry install --with integration
poetry run pip install juju==2.9.44.0
poetry run pip install juju==3.2.2
commands =
poetry run pytest -v --tb native --log-cli-level=INFO -s --durations=0 {posargs} {[vars]tests_path}/integration/metrics_tests/test_metrics.py

Expand All @@ -104,7 +104,7 @@ pass_env =
CI
commands_pre =
poetry install --with integration
poetry run pip install juju==2.9.44.0
poetry run pip install juju==3.2.2
commands =
poetry run pytest -v --tb native --log-cli-level=INFO -s --durations=0 {posargs} {[vars]tests_path}/integration/tls_tests/test_tls.py

Expand All @@ -115,7 +115,7 @@ pass_env =
CI
commands_pre =
poetry install --with integration
poetry run pip install juju==2.9.44.0
poetry run pip install juju==3.2.2
commands =
poetry run pytest -v --tb native --log-cli-level=INFO -s --durations=0 {posargs} {[vars]tests_path}/integration/relation_tests/test_charm_relations.py

Expand All @@ -126,7 +126,7 @@ pass_env =
CI
commands_pre =
poetry install --with integration
poetry run pip install juju==2.9.44.0
poetry run pip install juju==3.2.2
commands =
poetry run pytest -v --tb native --log-cli-level=INFO -s --durations=0 {posargs} {[vars]tests_path}/integration/test_teardown.py

Expand All @@ -137,7 +137,7 @@ pass_env =
CI
commands_pre =
poetry install --with integration
poetry run pip install juju==3.2.0.1
poetry run pip install juju==3.2.2
commands =
poetry run pytest -v --tb native --log-cli-level=INFO -s --durations=0 {posargs} {[vars]tests_path}/integration/backup_tests/test_backups.py

Expand Down

0 comments on commit 88d41b2

Please sign in to comment.