Skip to content

Commit

Permalink
Update to ops 2.1.1 (#102)
Browse files Browse the repository at this point in the history
* libs and deps update

* Check alias with get

* Remove obsoleted test harness flag

* Test charms are optional groups

* Copying over getting aliases from data-interfaces lib test
  • Loading branch information
dragomirp authored Mar 6, 2023
1 parent 1fcd7e2 commit 484fad0
Show file tree
Hide file tree
Showing 16 changed files with 2,548 additions and 1,203 deletions.
51 changes: 37 additions & 14 deletions lib/charms/data_platform_libs/v0/data_interfaces.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright 2022 Canonical Ltd.
# Copyright 2023 Canonical Ltd.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -280,7 +280,6 @@ def _on_topic_requested(self, event: TopicRequestedEvent):

import json
import logging
import os
from abc import ABC, abstractmethod
from collections import namedtuple
from datetime import datetime
Expand All @@ -304,7 +303,9 @@ def _on_topic_requested(self, event: TopicRequestedEvent):

# Increment this PATCH version before using `charmcraft publish-lib` or reset
# to 0 if you are raising the major API version
LIBPATCH = 4
LIBPATCH = 7

PYDEPS = ["ops>=2.0.0"]

logger = logging.getLogger(__name__)

Expand Down Expand Up @@ -501,12 +502,6 @@ def fetch_relation_data(self) -> dict:
a dict of the values stored in the relation data bag
for all relation instances (indexed by the relation ID).
"""
if "-relation-broken" in os.environ.get("JUJU_HOOK_NAME", ""):
# read more in https://bugs.launchpad.net/juju/+bug/1960934
raise RuntimeError(
"`fetch_relation_data` cannot be used in `*-relation-broken` events"
)

data = {}
for relation in self.relations:
data[relation.id] = {
Expand Down Expand Up @@ -544,7 +539,19 @@ def _diff(self, event: RelationChangedEvent) -> Diff:
@property
def relations(self) -> List[Relation]:
"""The list of Relation instances associated with this relation_name."""
return list(self.charm.model.relations[self.relation_name])
return [
relation
for relation in self.charm.model.relations[self.relation_name]
if self._is_relation_active(relation)
]

@staticmethod
def _is_relation_active(relation: Relation):
try:
_ = repr(relation.data)
return True
except RuntimeError:
return False

@staticmethod
def _is_resource_created_for_relation(relation: Relation):
Expand All @@ -564,12 +571,28 @@ def is_resource_created(self, relation_id: Optional[int] = None) -> bool:
Returns:
True or False
Raises:
IndexError: If relation_id is provided but that relation does not exist
"""
if relation_id:
return self._is_resource_created_for_relation(self.relations[relation_id])
if relation_id is not None:
try:
relation = [relation for relation in self.relations if relation.id == relation_id][
0
]
return self._is_resource_created_for_relation(relation)
except IndexError:
raise IndexError(f"relation id {relation_id} cannot be accessed")
else:
return all(
[self._is_resource_created_for_relation(relation) for relation in self.relations]
return (
all(
[
self._is_resource_created_for_relation(relation)
for relation in self.relations
]
)
if self.relations
else False
)


Expand Down
4 changes: 2 additions & 2 deletions lib/charms/data_platform_libs/v0/s3.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright 2022 Canonical Ltd.
# Copyright 2023 Canonical Ltd.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -139,7 +139,7 @@ def _on_credential_gone(self, event: CredentialsGoneEvent):

# Increment this PATCH version before using `charmcraft publish-lib` or reset
# to 0 if you are raising the major API version
LIBPATCH = 1
LIBPATCH = 2

logger = logging.getLogger(__name__)

Expand Down
261 changes: 131 additions & 130 deletions poetry.lock

Large diffs are not rendered by default.

16 changes: 11 additions & 5 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,15 @@ repository = "https://github.com/canonical/postgresql-k8s-operator"
python = "^3.8.10"
ops = "^2.0"
pgconnstr = "^1.0.1"
tenacity = "^8.2.1"
cryptography = "^39.0.1"
tenacity = "^8.2.2"
cryptography = "^39.0.2"
jsonschema = "^4.17.3"
jinja2 = "^3.1.2"
lightkube = "^0.12.0"
lightkube-models = "^1.26.0.4"
requests = "^2.28.2"
boto3 = "^1.26.84"
# psycopg2 = "^2.9.5" # Injected in charmcraft.yaml
boto3 = "^1.26.69"

[tool.poetry.group.fmt.dependencies]
black = "^22.12.0"
Expand All @@ -40,7 +40,7 @@ codespell = "^2.2.2"

[tool.poetry.group.unit.dependencies]
coverage = {extras = ["toml"], version = "^7.0.5"}
pytest = "^7.1.1"
pytest = "^7.2.2"
pytest-asyncio = "^0.20.3"

[tool.poetry.group.integration.dependencies]
Expand All @@ -50,9 +50,15 @@ pytest-operator = "^0.23.0"
juju = "^2" # Latest juju 2
psycopg2 = {version = "^2.9.5", extras = ["binary"]}

[tool.poetry.group.ha_charm]
optional = true

[tool.poetry.group.ha_charm.dependencies]
ops = "^2.0"
tenacity = "^8.2.1"
tenacity = "^8.2.2"

[tool.poetry.group.relation_charm]
optional = true

[tool.poetry.group.relation_charm.dependencies]
ops = "^2.0"
Expand Down
87 changes: 45 additions & 42 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@ anyio==3.6.2 ; python_full_version >= "3.8.10" and python_full_version < "4.0.0"
attrs==22.2.0 ; python_full_version >= "3.8.10" and python_full_version < "4.0.0" \
--hash=sha256:29e95c7f6778868dbd49170f98f8818f78f3dc5e0e37c0b1f474e3561b240836 \
--hash=sha256:c9227bfc2f01993c03f68db37d1d15c9690188323c067c641f1a35ca58185f99
boto3==1.26.69 ; python_full_version >= "3.8.10" and python_full_version < "4.0.0" \
--hash=sha256:9a0a29179957cb26fa8c3c1fddf66b18efaeaf633e08db5fb53815ffb0421419 \
--hash=sha256:eb8cde24a4c5755c35126e8cd460e6b51c63d04292419e7e95721232720c7e5b
botocore==1.29.69 ; python_full_version >= "3.8.10" and python_full_version < "4.0.0" \
--hash=sha256:2a4ab8bcb3177daa425019e125c09996b9a6a1a62bb0baaaeeb86ffd552719cc \
--hash=sha256:7e1bebca013544fbc298cb58603bfccd5f71b49c720a5c33c07cf5dfc8145a1f
boto3==1.26.84 ; python_full_version >= "3.8.10" and python_full_version < "4.0.0" \
--hash=sha256:7ab7bb335b726e2f472b5c050028198d16338560c83c40b2bd2bd4e4018ec802 \
--hash=sha256:d97176a7ffb37539bc53671cb0bf1c5b304f1c78bbd748553df549a9d4f92a9e
botocore==1.29.84 ; python_full_version >= "3.8.10" and python_full_version < "4.0.0" \
--hash=sha256:0f976427ad0a2602624ba784b5db328a865c2e9e0cc1bb6d8cffb6c0a2d177e1 \
--hash=sha256:a36f7f6f8eae5dbd4a1cc8cb6fc747f6315500541181eff2093ee0529fc8e4bc
certifi==2022.12.7 ; python_full_version >= "3.8.10" and python_version < "4" \
--hash=sha256:35824b4c3a97115964b408844d64aa14db1cc518f6562e8d7261699d1350a9e3 \
--hash=sha256:4ad3232f5e926d6718ec31cfc1fcadfde020920e278684144551c91769c7bc18
Expand Down Expand Up @@ -167,30 +167,30 @@ charset-normalizer==3.0.1 ; python_full_version >= "3.8.10" and python_version <
--hash=sha256:f97e83fa6c25693c7a35de154681fcc257c1c41b38beb0304b9c4d2d9e164479 \
--hash=sha256:f9d0c5c045a3ca9bedfc35dca8526798eb91a07aa7a2c0fee134c6c6f321cbd7 \
--hash=sha256:ff6f3db31555657f3163b15a6b7c6938d08df7adbfc9dd13d9d19edad678f1e8
cryptography==39.0.1 ; python_full_version >= "3.8.10" and python_full_version < "4.0.0" \
--hash=sha256:0f8da300b5c8af9f98111ffd512910bc792b4c77392a9523624680f7956a99d4 \
--hash=sha256:35f7c7d015d474f4011e859e93e789c87d21f6f4880ebdc29896a60403328f1f \
--hash=sha256:4789d1e3e257965e960232345002262ede4d094d1a19f4d3b52e48d4d8f3b885 \
--hash=sha256:5aa67414fcdfa22cf052e640cb5ddc461924a045cacf325cd164e65312d99502 \
--hash=sha256:5d2d8b87a490bfcd407ed9d49093793d0f75198a35e6eb1a923ce1ee86c62b41 \
--hash=sha256:6687ef6d0a6497e2b58e7c5b852b53f62142cfa7cd1555795758934da363a965 \
--hash=sha256:6f8ba7f0328b79f08bdacc3e4e66fb4d7aab0c3584e0bd41328dce5262e26b2e \
--hash=sha256:706843b48f9a3f9b9911979761c91541e3d90db1ca905fd63fee540a217698bc \
--hash=sha256:807ce09d4434881ca3a7594733669bd834f5b2c6d5c7e36f8c00f691887042ad \
--hash=sha256:83e17b26de248c33f3acffb922748151d71827d6021d98c70e6c1a25ddd78505 \
--hash=sha256:96f1157a7c08b5b189b16b47bc9db2332269d6680a196341bf30046330d15388 \
--hash=sha256:aec5a6c9864be7df2240c382740fcf3b96928c46604eaa7f3091f58b878c0bb6 \
--hash=sha256:b0afd054cd42f3d213bf82c629efb1ee5f22eba35bf0eec88ea9ea7304f511a2 \
--hash=sha256:c5caeb8188c24888c90b5108a441c106f7faa4c4c075a2bcae438c6e8ca73cef \
--hash=sha256:ced4e447ae29ca194449a3f1ce132ded8fcab06971ef5f618605aacaa612beac \
--hash=sha256:d1f6198ee6d9148405e49887803907fe8962a23e6c6f83ea7d98f1c0de375695 \
--hash=sha256:e124352fd3db36a9d4a21c1aa27fd5d051e621845cb87fb851c08f4f75ce8be6 \
--hash=sha256:e422abdec8b5fa8462aa016786680720d78bdce7a30c652b7fadf83a4ba35336 \
--hash=sha256:ef8b72fa70b348724ff1218267e7f7375b8de4e8194d1636ee60510aae104cd0 \
--hash=sha256:f0c64d1bd842ca2633e74a1a28033d139368ad959872533b1bab8c80e8240a0c \
--hash=sha256:f24077a3b5298a5a06a8e0536e3ea9ec60e4c7ac486755e5fb6e6ea9b3500106 \
--hash=sha256:fdd188c8a6ef8769f148f88f859884507b954cc64db6b52f66ef199bb9ad660a \
--hash=sha256:fe913f20024eb2cb2f323e42a64bdf2911bb9738a15dba7d3cce48151034e3a8
cryptography==39.0.2 ; python_full_version >= "3.8.10" and python_full_version < "4.0.0" \
--hash=sha256:103e8f7155f3ce2ffa0049fe60169878d47a4364b277906386f8de21c9234aa1 \
--hash=sha256:23df8ca3f24699167daf3e23e51f7ba7334d504af63a94af468f468b975b7dd7 \
--hash=sha256:2725672bb53bb92dc7b4150d233cd4b8c59615cd8288d495eaa86db00d4e5c06 \
--hash=sha256:30b1d1bfd00f6fc80d11300a29f1d8ab2b8d9febb6ed4a38a76880ec564fae84 \
--hash=sha256:35d658536b0a4117c885728d1a7032bdc9a5974722ae298d6c533755a6ee3915 \
--hash=sha256:50cadb9b2f961757e712a9737ef33d89b8190c3ea34d0fb6675e00edbe35d074 \
--hash=sha256:5f8c682e736513db7d04349b4f6693690170f95aac449c56f97415c6980edef5 \
--hash=sha256:6236a9610c912b129610eb1a274bdc1350b5df834d124fa84729ebeaf7da42c3 \
--hash=sha256:788b3921d763ee35dfdb04248d0e3de11e3ca8eb22e2e48fef880c42e1f3c8f9 \
--hash=sha256:8bc0008ef798231fac03fe7d26e82d601d15bd16f3afaad1c6113771566570f3 \
--hash=sha256:8f35c17bd4faed2bc7797d2a66cbb4f986242ce2e30340ab832e5d99ae60e011 \
--hash=sha256:b49a88ff802e1993b7f749b1eeb31134f03c8d5c956e3c125c75558955cda536 \
--hash=sha256:bc0521cce2c1d541634b19f3ac661d7a64f9555135e9d8af3980965be717fd4a \
--hash=sha256:bc5b871e977c8ee5a1bbc42fa8d19bcc08baf0c51cbf1586b0e87a2694dde42f \
--hash=sha256:c43ac224aabcbf83a947eeb8b17eaf1547bce3767ee2d70093b461f31729a480 \
--hash=sha256:d15809e0dbdad486f4ad0979753518f47980020b7a34e9fc56e8be4f60702fac \
--hash=sha256:d7d84a512a59f4412ca8549b01f94be4161c94efc598bf09d027d67826beddc0 \
--hash=sha256:e029b844c21116564b8b61216befabca4b500e6816fa9f0ba49527653cae2108 \
--hash=sha256:e8a0772016feeb106efd28d4a328e77dc2edae84dfbac06061319fdb669ff828 \
--hash=sha256:e944fe07b6f229f4c1a06a7ef906a19652bdd9fd54c761b0ff87e83ae7a30354 \
--hash=sha256:eb40fe69cfc6f5cdab9a5ebd022131ba21453cf7b8a7fd3631f45bbf52bed612 \
--hash=sha256:fa507318e427169ade4e9eccef39e9011cdc19534f55ca2f36ec3f388c1f70f3 \
--hash=sha256:ffd394c7896ed7821a6d13b24657c6a34b6e2650bd84ae063cf11ccffa4f1a97
h11==0.14.0 ; python_full_version >= "3.8.10" and python_full_version < "4.0.0" \
--hash=sha256:8f19fbbe99e72420ff35c00b27a34cb9937e902a8b810e2c88300c6f0a3b699d \
--hash=sha256:e3fe4ac4b851c468cc8363d500db52c2ead036020723024a109d37346efaa761
Expand All @@ -203,9 +203,9 @@ httpx==0.23.3 ; python_full_version >= "3.8.10" and python_full_version < "4.0.0
idna==3.4 ; python_full_version >= "3.8.10" and python_version < "4" \
--hash=sha256:814f528e8dead7d329833b91c5faa87d60bf71824cd12a7530b5526063d02cb4 \
--hash=sha256:90b77e79eaa3eba6de819a0c442c0b4ceefc341a7a2ab77d7562bf49f425c5c2
importlib-resources==5.10.2 ; python_full_version >= "3.8.10" and python_version < "3.9" \
--hash=sha256:7d543798b0beca10b6a01ac7cafda9f822c54db9e8376a6bf57e0cbd74d486b6 \
--hash=sha256:e4a96c8cc0339647ff9a5e0550d9f276fc5a01ffa276012b58ec108cfd7b8484
importlib-resources==5.12.0 ; python_full_version >= "3.8.10" and python_version < "3.9" \
--hash=sha256:4be82589bf5c1d7999aedf2a45159d10cb3ca4f19b2271f8792bc8e6da7b22f6 \
--hash=sha256:7b1deeebbf351c7578e09bf2f63fa2ce8b5ffec296e0d349139d43cca061a81a
jinja2==3.1.2 ; python_full_version >= "3.8.10" and python_full_version < "4.0.0" \
--hash=sha256:31351a702a408a9e7595a8fc6150fc3f43bb6bf7e319770cbc0db9df9437e852 \
--hash=sha256:6088930bfe239f0e6710546ab9c19c9ef35e29792895fed6e6e31a023a182a61
Expand Down Expand Up @@ -272,9 +272,9 @@ markupsafe==2.1.2 ; python_full_version >= "3.8.10" and python_full_version < "4
--hash=sha256:f1cd098434e83e656abf198f103a8207a8187c0fc110306691a2e94a78d0abb2 \
--hash=sha256:f2bfb563d0211ce16b63c7cb9395d2c682a23187f54c3d79bfec33e6705473c6 \
--hash=sha256:f8ffb705ffcf5ddd0e80b65ddf7bed7ee4f5a441ea7d3419e861a12eaf41af58
ops==2.0.0 ; python_full_version >= "3.8.10" and python_full_version < "4.0.0" \
--hash=sha256:39d61bc6e2e71eb120de3037fee549c547ce68300688bbc6de7b76b6041a9065 \
--hash=sha256:f0eebaa321a139395912afa686d7091fc11150010cf375d38b135b9a499be2f2
ops==2.1.1 ; python_full_version >= "3.8.10" and python_full_version < "4.0.0" \
--hash=sha256:b2802068557c64121bf50ccfe101b043ed08c02ac5f958e55752c476b09de63d \
--hash=sha256:bed9f14b785efaa83f89b9c76b87bd1b3b82b0350c453b41dce778b39c7410b4
pgconnstr==1.0.1 ; python_full_version >= "3.8.10" and python_full_version < "4.0.0" \
--hash=sha256:0656129961ae879675d0842f5237db82d31ce59c7b3211b051c33e37a864826e \
--hash=sha256:0f65830e7e3b76adf4390a8592ee52343171a17caef7436257e7bc81c44e21a7
Expand Down Expand Up @@ -371,12 +371,15 @@ six==1.16.0 ; python_full_version >= "3.8.10" and python_full_version < "4.0.0"
sniffio==1.3.0 ; python_full_version >= "3.8.10" and python_full_version < "4.0.0" \
--hash=sha256:e60305c5e5d314f5389259b7f22aaa33d8f7dee49763119234af3755c55b9101 \
--hash=sha256:eecefdce1e5bbfb7ad2eeaabf7c1eeb404d7757c379bd1f7e5cce9d8bf425384
tenacity==8.2.1 ; python_full_version >= "3.8.10" and python_full_version < "4.0.0" \
--hash=sha256:c7bb4b86425b977726a7b49971542d4f67baf72096597d283f3ffd01f33b92df \
--hash=sha256:dd1b769ca7002fda992322939feca5bee4fa11f39146b0af14e0b8d9f27ea854
tenacity==8.2.2 ; python_full_version >= "3.8.10" and python_full_version < "4.0.0" \
--hash=sha256:2f277afb21b851637e8f52e6a613ff08734c347dc19ade928e519d7d2d8569b0 \
--hash=sha256:43af037822bd0029025877f3b2d97cc4d7bb0c2991000a3d59d71517c5c969e0
urllib3==1.26.14 ; python_full_version >= "3.8.10" and python_version < "4" \
--hash=sha256:076907bf8fd355cde77728471316625a4d2f7e713c125f51953bb5b3eecf4f72 \
--hash=sha256:75edcdc2f7d85b137124a6c3c9fc3933cdeaa12ecb9a6a959f22797a0feca7e1
zipp==3.13.0 ; python_full_version >= "3.8.10" and python_version < "3.9" \
--hash=sha256:23f70e964bc11a34cef175bc90ba2914e1e4545ea1e3e2f67c079671883f9cb6 \
--hash=sha256:e8b2a36ea17df80ffe9e2c4fda3f693c3dad6df1697d3cd3af232db680950b0b
websocket-client==1.5.1 ; python_full_version >= "3.8.10" and python_full_version < "4.0.0" \
--hash=sha256:3f09e6d8230892547132177f575a4e3e73cfdf06526e20cc02aa1c3b47184d40 \
--hash=sha256:cdf5877568b7e83aa7cf2244ab56a3213de587bbe0ce9d8b9600fc77b455d89e
zipp==3.15.0 ; python_full_version >= "3.8.10" and python_version < "3.9" \
--hash=sha256:112929ad649da941c23de50f356a2b5570c954b65150642bccdd66bf194d224b \
--hash=sha256:48904fc76a60e542af151aded95726c1a5c34ed43ab4134b597665c86d7ad556
Loading

0 comments on commit 484fad0

Please sign in to comment.