Skip to content

Commit 17753b6

Browse files
authored
[DPE-8550] Check juju version before removing revision and remove discourse charmers test (#1151)
* Check juju version before removing revision * Update redis series/bases * Use spread to collect tests * Install spread * Indico redis * Remove db admin test * Switch to common spread collection
1 parent f660c4f commit 17753b6

File tree

7 files changed

+39
-107
lines changed

7 files changed

+39
-107
lines changed

.github/workflows/integration_test.yaml

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,19 +19,24 @@ jobs:
1919
uses: actions/checkout@v5
2020
- name: Set up environment
2121
run: |
22-
sudo snap install charmcraft --classic
22+
sudo snap install go --classic
23+
go install github.com/snapcore/spread/cmd/spread@latest
2324
pipx install tox poetry
2425
- name: Collect spread jobs
2526
id: collect-jobs
2627
shell: python
2728
run: |
2829
import json
30+
import pathlib
2931
import os
3032
import subprocess
3133
3234
spread_jobs = (
3335
subprocess.run(
34-
["charmcraft", "test", "--list", "github-ci"], capture_output=True, check=True, text=True
36+
[pathlib.Path.home() / "go/bin/spread", "-list", "github-ci"],
37+
capture_output=True,
38+
check=True,
39+
text=True,
3540
)
3641
.stdout.strip()
3742
.split("\n")

src/charm.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@
6262
from lightkube.models.core_v1 import ServicePort, ServiceSpec
6363
from lightkube.models.meta_v1 import ObjectMeta
6464
from lightkube.resources.core_v1 import Endpoints, Node, Pod, Service
65-
from ops import main
65+
from ops import JujuVersion, main
6666
from ops.charm import (
6767
ActionEvent,
6868
HookEvent,
@@ -1365,6 +1365,12 @@ def promote_primary_unit(self, event: ActionEvent) -> None:
13651365
event.fail("Switchover failed or timed out, check the logs for details")
13661366

13671367
def _on_secret_remove(self, event: SecretRemoveEvent) -> None:
1368+
if self.model.juju_version < JujuVersion("3.6.11"):
1369+
logger.warning(
1370+
"Skipping secret revision removal due to https://github.com/juju/juju/issues/20782"
1371+
)
1372+
return
1373+
13681374
# A secret removal (entire removal, not just a revision removal) causes
13691375
# https://github.com/juju/juju/issues/20794. This check is to avoid the
13701376
# errors that would happen if we tried to remove the revision in that case

tests/integration/new_relations/test_new_relations_1.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@
2727
ANOTHER_DATABASE_APP_NAME = "another-database"
2828
DATA_INTEGRATOR_APP_NAME = "data-integrator"
2929
DISCOURSE_APP_NAME = "discourse-k8s"
30-
REDIS_APP_NAME = "redis-k8s"
3130
APP_NAMES = [APPLICATION_APP_NAME, DATABASE_APP_NAME, ANOTHER_DATABASE_APP_NAME]
3231
DATABASE_APP_METADATA = yaml.safe_load(Path("./metadata.yaml").read_text())
3332
FIRST_DATABASE_RELATION_NAME = "database"

tests/integration/new_relations/test_new_relations_2.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ async def test_discourse(ops_test: OpsTest):
6969
await gather(
7070
ops_test.model.deploy(DISCOURSE_APP_NAME, application_name=DISCOURSE_APP_NAME),
7171
ops_test.model.deploy(
72-
REDIS_APP_NAME, application_name=REDIS_APP_NAME, channel="latest/edge", base=CHARM_BASE
72+
REDIS_APP_NAME, application_name=REDIS_APP_NAME, channel="latest/edge", series="jammy"
7373
),
7474
)
7575

@@ -151,10 +151,10 @@ async def test_indico_datatabase(ops_test: OpsTest) -> None:
151151
series="focal",
152152
)
153153
await ops_test.model.deploy(
154-
"redis-k8s", channel="stable", application_name="redis-broker", base="ubuntu@20.04"
154+
REDIS_APP_NAME, application_name="redis-broker", channel="latest/edge", series="jammy"
155155
)
156156
await ops_test.model.deploy(
157-
"redis-k8s", channel="stable", application_name="redis-cache", base="ubuntu@20.04"
157+
REDIS_APP_NAME, application_name="redis-cache", channel="latest/edge", series="jammy"
158158
)
159159
await asyncio.gather(
160160
ops_test.model.relate("redis-broker", "indico:redis-broker"),

tests/integration/test_db_admin.py

Lines changed: 0 additions & 82 deletions
This file was deleted.

tests/spread/test_db_admin.py/task.yaml

Lines changed: 0 additions & 9 deletions
This file was deleted.

tests/unit/test_charm.py

Lines changed: 22 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
from charms.postgresql_k8s.v0.postgresql import PostgreSQLUpdateUserPasswordError
1212
from lightkube import ApiError
1313
from lightkube.resources.core_v1 import Endpoints, Pod, Service
14+
from ops import JujuVersion
1415
from ops.model import (
1516
ActiveStatus,
1617
BlockedStatus,
@@ -1905,13 +1906,25 @@ def test_get_ldap_parameters(harness):
19051906
_get_relation_data.reset_mock()
19061907

19071908

1908-
def test_on_secret_remove(harness):
1909-
event = Mock()
1910-
harness.charm._on_secret_remove(event)
1911-
event.remove_revision.assert_called_once_with()
1912-
event.reset_mock()
1909+
def test_on_secret_remove(harness, only_with_juju_secrets):
1910+
with (
1911+
patch("ops.model.Model.juju_version", new_callable=PropertyMock) as _juju_version,
1912+
):
1913+
event = Mock()
19131914

1914-
# No secret
1915-
event.secret.label = None
1916-
harness.charm._on_secret_remove(event)
1917-
assert not event.remove_revision.called
1915+
# New juju
1916+
_juju_version.return_value = JujuVersion("3.6.11")
1917+
harness.charm._on_secret_remove(event)
1918+
event.remove_revision.assert_called_once_with()
1919+
event.reset_mock()
1920+
1921+
# Old juju
1922+
_juju_version.return_value = JujuVersion("3.6.9")
1923+
harness.charm._on_secret_remove(event)
1924+
assert not event.remove_revision.called
1925+
event.reset_mock()
1926+
1927+
# No secret
1928+
event.secret.label = None
1929+
harness.charm._on_secret_remove(event)
1930+
assert not event.remove_revision.called

0 commit comments

Comments
 (0)