Skip to content

Commit 152206f

Browse files
authored
[MISC] Revert upgrade tests to 16/edge (#988)
* Switch back the upgrade tests * Bump libs * Bump lib version
1 parent f05b26c commit 152206f

File tree

6 files changed

+77
-59
lines changed

6 files changed

+77
-59
lines changed

lib/charms/grafana_k8s/v0/grafana_dashboard.py

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,7 @@ def __init__(self, *args):
219219
# Increment this PATCH version before using `charmcraft publish-lib` or reset
220220
# to 0 if you are raising the major API version
221221

222-
LIBPATCH = 43
222+
LIBPATCH = 44
223223

224224
PYDEPS = ["cosl >= 0.0.50"]
225225

@@ -1676,14 +1676,22 @@ def _set_default_data(self) -> None:
16761676

16771677
def set_peer_data(self, key: str, data: Any) -> None:
16781678
"""Put information into the peer data bucket instead of `StoredState`."""
1679-
self._charm.peers.data[self._charm.app][key] = json.dumps(data) # type: ignore[attr-defined]
1679+
peers = self._charm.peers # type: ignore[attr-defined]
1680+
if not peers or not peers.data:
1681+
logger.info("set_peer_data: no peer relation. Is the charm being installed/removed?")
1682+
return
1683+
peers.data[self._charm.app][key] = json.dumps(data) # type: ignore[attr-defined]
16801684

16811685
def get_peer_data(self, key: str) -> Any:
16821686
"""Retrieve information from the peer data bucket instead of `StoredState`."""
1683-
if rel := self._charm.peers: # type: ignore[attr-defined]
1684-
data = rel.data[self._charm.app].get(key, "")
1685-
return json.loads(data) if data else {}
1686-
return {}
1687+
peers = self._charm.peers # type: ignore[attr-defined]
1688+
if not peers or not peers.data:
1689+
logger.warning(
1690+
"get_peer_data: no peer relation. Is the charm being installed/removed?"
1691+
)
1692+
return {}
1693+
data = peers.data[self._charm.app].get(key, "")
1694+
return json.loads(data) if data else {}
16871695

16881696

16891697
class GrafanaDashboardAggregator(Object):

lib/charms/postgresql_k8s/v0/postgresql.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535

3636
# Increment this PATCH version before using `charmcraft publish-lib` or reset
3737
# to 0 if you are raising the major API version
38-
LIBPATCH = 53
38+
LIBPATCH = 55
3939

4040
# Groups to distinguish HBA access
4141
ACCESS_GROUP_IDENTITY = "identity_access"

lib/charms/prometheus_k8s/v0/prometheus_scrape.py

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -362,7 +362,7 @@ def _on_scrape_targets_changed(self, event):
362362

363363
# Increment this PATCH version before using `charmcraft publish-lib` or reset
364364
# to 0 if you are raising the major API version
365-
LIBPATCH = 52
365+
LIBPATCH = 53
366366

367367
# Version 0.0.53 needed for cosl.rules.generic_alert_groups
368368
PYDEPS = ["cosl>=0.0.53"]
@@ -1265,6 +1265,15 @@ def _dedupe_job_names(jobs: List[dict]):
12651265
return deduped_jobs
12661266

12671267

1268+
def _dedupe_list(items: List[Dict[str, Any]]) -> List[Dict[str, Any]]:
1269+
"""Deduplicate items in the list via object identity."""
1270+
unique_items = []
1271+
for item in items:
1272+
if item not in unique_items:
1273+
unique_items.append(item)
1274+
return unique_items
1275+
1276+
12681277
def _resolve_dir_against_charm_path(charm: CharmBase, *path_elements: str) -> str:
12691278
"""Resolve the provided path items against the directory of the main file.
12701279
@@ -1538,7 +1547,7 @@ def set_scrape_job_spec(self, _=None):
15381547
if self._forward_alert_rules:
15391548
alert_rules.add_path(self._alert_rules_path, recursive=True)
15401549
alert_rules.add(
1541-
generic_alert_groups.application_rules, group_name_prefix=self.topology.identifier
1550+
copy.deepcopy(generic_alert_groups.application_rules), group_name_prefix=self.topology.identifier
15421551
)
15431552
alert_rules_as_dict = alert_rules.as_dict()
15441553

@@ -1889,6 +1898,9 @@ def _set_prometheus_data(self, event: Optional[RelationJoinedEvent] = None):
18891898
)
18901899
groups.extend(alert_rules.as_dict()["groups"])
18911900

1901+
groups = _dedupe_list(groups)
1902+
jobs = _dedupe_list(jobs)
1903+
18921904
# Set scrape jobs and alert rules in relation data
18931905
relations = [event.relation] if event else self.model.relations[self._prometheus_relation]
18941906
for rel in relations:
@@ -2141,10 +2153,12 @@ def _on_alert_rules_changed(self, event):
21412153
self.set_alert_rule_data(app_name, unit_rules)
21422154

21432155
def set_alert_rule_data(self, name: str, unit_rules: dict, label_rules: bool = True) -> None:
2144-
"""Update alert rule data.
2156+
"""Consolidate incoming alert rules (from stored-state or event) with those from relation data.
21452157
2146-
The unit rules should be a dict, which is has additional Juju topology labels added. For
2158+
The unit rules should be a dict, which have additional Juju topology labels added. For
21472159
rules generated by the NRPE exporter, they are pre-labeled so lookups can be performed.
2160+
The unit rules are combined with the alert rules from relation data before being written
2161+
back to relation data and stored-state.
21482162
"""
21492163
if not self._charm.unit.is_leader():
21502164
return
@@ -2166,6 +2180,9 @@ def set_alert_rule_data(self, name: str, unit_rules: dict, label_rules: bool = T
21662180

21672181
if updated_group["name"] not in [g["name"] for g in groups]:
21682182
groups.append(updated_group)
2183+
2184+
groups = _dedupe_list(groups)
2185+
21692186
relation.data[self._charm.app]["alert_rules"] = json.dumps(
21702187
{"groups": groups if self._forward_alert_rules else []}
21712188
)
@@ -2216,6 +2233,8 @@ def remove_alert_rules(self, group_name: str, unit_name: str) -> None:
22162233
changed_group["rules"] = rules_kept # type: ignore
22172234
groups.append(changed_group)
22182235

2236+
groups = _dedupe_list(groups)
2237+
22192238
relation.data[self._charm.app]["alert_rules"] = json.dumps(
22202239
{"groups": groups if self._forward_alert_rules else []}
22212240
)

templates/patroni.yml.j2

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -165,24 +165,21 @@ postgresql:
165165
replication:
166166
password: {{ replication_password }}
167167
{%- if enable_tls %}
168-
sslrootcert: {{ conf_path }}/ca.pem
169-
sslcert: {{ conf_path }}/cert.pem
170-
sslkey: {{ conf_path }}/key.pem
168+
sslcert: {{ conf_path }}/nonexistent_cert.pem
169+
sslkey: {{ conf_path }}/nonexistent_key.pem
171170
{%- endif %}
172171
rewind:
173172
username: {{ rewind_user }}
174173
password: {{ rewind_password }}
175174
{%- if enable_tls %}
176-
sslrootcert: {{ conf_path }}/ca.pem
177-
sslcert: {{ conf_path }}/cert.pem
178-
sslkey: {{ conf_path }}/key.pem
175+
sslcert: {{ conf_path }}/nonexistent_cert.pem
176+
sslkey: {{ conf_path }}/nonexistent_key.pem
179177
{%- endif %}
180178
superuser:
181179
password: {{ superuser_password }}
182180
{%- if enable_tls %}
183-
sslrootcert: {{ conf_path }}/ca.pem
184-
sslcert: {{ conf_path }}/cert.pem
185-
sslkey: {{ conf_path }}/key.pem
181+
sslcert: {{ conf_path }}/nonexistent_cert.pem
182+
sslkey: {{ conf_path }}/nonexistent_key.pem
186183
{%- endif %}
187184
use_endpoints: true
188185
use_unix_socket: true

tests/integration/ha_tests/test_upgrade.py

Lines changed: 16 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# Copyright 2023 Canonical Ltd.
22
# See LICENSE file for licensing details.
33

4-
# import asyncio
4+
import asyncio
55
import logging
66
import shutil
77
from pathlib import Path
@@ -38,25 +38,21 @@
3838
@pytest.mark.abort_on_fail
3939
async def test_deploy_latest(ops_test: OpsTest) -> None:
4040
"""Simple test to ensure that the PostgreSQL and application charms get deployed."""
41-
# TODO: rollback to ops_test.model.deploy syntax when we release to edge.
42-
await ops_test.juju(
43-
"deploy",
44-
DATABASE_APP_NAME,
45-
"-n",
46-
3,
47-
"--channel",
48-
"16/edge/multiple-storages",
49-
"--trust",
50-
"--config",
51-
"profile=testing",
52-
"--base",
53-
CHARM_BASE_NOBLE,
54-
)
55-
await ops_test.model.deploy(
56-
APPLICATION_NAME,
57-
num_units=1,
58-
channel="latest/edge",
59-
base=CHARM_BASE,
41+
await asyncio.gather(
42+
ops_test.model.deploy(
43+
DATABASE_APP_NAME,
44+
num_units=3,
45+
channel="16/edge",
46+
trust=True,
47+
config={"profile": "testing"},
48+
base=CHARM_BASE_NOBLE,
49+
),
50+
ops_test.model.deploy(
51+
APPLICATION_NAME,
52+
num_units=1,
53+
channel="latest/edge",
54+
base=CHARM_BASE,
55+
),
6056
)
6157
logger.info("Wait for applications to become active")
6258
async with ops_test.fast_forward():

tests/integration/ha_tests/test_upgrade_from_stable.py

Lines changed: 17 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# Copyright 2023 Canonical Ltd.
22
# See LICENSE file for licensing details.
33

4-
# import asyncio
4+
import asyncio
55
import logging
66

77
import pytest
@@ -35,24 +35,22 @@
3535
@pytest.mark.abort_on_fail
3636
async def test_deploy_stable(ops_test: OpsTest) -> None:
3737
"""Simple test to ensure that the PostgreSQL and application charms get deployed."""
38-
# TODO: rollback to ops_test.model.deploy syntax when we release to stable.
39-
await ops_test.juju(
40-
"deploy",
41-
DATABASE_APP_NAME,
42-
"-n",
43-
3,
44-
# TODO: move to stable once we release.
45-
"--channel",
46-
"16/beta/multiple-storages",
47-
"--trust",
48-
"--base",
49-
CHARM_BASE_NOBLE,
50-
)
51-
await ops_test.model.deploy(
52-
APPLICATION_NAME,
53-
num_units=1,
54-
channel="latest/edge",
55-
base=CHARM_BASE,
38+
await asyncio.gather(
39+
ops_test.model.deploy(
40+
DATABASE_APP_NAME,
41+
num_units=3,
42+
# TODO: move to stable once we release.
43+
channel="16/edge",
44+
trust=True,
45+
config={"profile": "testing"},
46+
base=CHARM_BASE_NOBLE,
47+
),
48+
ops_test.model.deploy(
49+
APPLICATION_NAME,
50+
num_units=1,
51+
channel="latest/edge",
52+
base=CHARM_BASE,
53+
),
5654
)
5755
logger.info("Wait for applications to become active")
5856
async with ops_test.fast_forward():

0 commit comments

Comments
 (0)