Skip to content

Commit

Permalink
chore: Update charm libraries (#422)
Browse files Browse the repository at this point in the history
  • Loading branch information
telcobot authored Dec 16, 2024
1 parent 9c07dbc commit 789f3ca
Showing 1 changed file with 10 additions and 7 deletions.
17 changes: 10 additions & 7 deletions lib/charms/sdcore_nms_k8s/v0/sdcore_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,10 +106,10 @@ def _on_sdcore_config_relation_joined(self, event: RelationJoinedEvent):
import logging
from typing import Optional

from interface_tester.schema_base import DataBagSchema # type: ignore[import]
from interface_tester.schema_base import DataBagSchema
from ops.charm import CharmBase, CharmEvents, RelationBrokenEvent, RelationChangedEvent
from ops.framework import EventBase, EventSource, Handle, Object
from ops.model import Relation
from ops.model import ModelError, Relation
from pydantic import BaseModel, Field, ValidationError

# The unique Charmhub library identifier, never change it
Expand All @@ -120,7 +120,7 @@ def _on_sdcore_config_relation_joined(self, event: RelationJoinedEvent):

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

logger = logging.getLogger(__name__)

Expand Down Expand Up @@ -150,7 +150,7 @@ class SdcoreConfigProviderAppData(BaseModel):

class ProviderSchema(DataBagSchema):
"""The schema for the provider side of the sdcore-config interface."""
app: SdcoreConfigProviderAppData
app_data: SdcoreConfigProviderAppData


def data_is_valid(data: dict) -> bool:
Expand All @@ -163,7 +163,7 @@ def data_is_valid(data: dict) -> bool:
bool: True if data is valid, False otherwise.
"""
try:
ProviderSchema(app=data)
ProviderSchema(app_data=SdcoreConfigProviderAppData(**data))
return True
except ValidationError as e:
logger.error("Invalid data: %s", e)
Expand Down Expand Up @@ -207,7 +207,7 @@ class SdcoreConfigRequirerCharmEvents(CharmEvents):
class SdcoreConfigRequires(Object):
"""Class to be instantiated by the SD-Core config requirer charm."""

on = SdcoreConfigRequirerCharmEvents()
on = SdcoreConfigRequirerCharmEvents() # type: ignore

def __init__(self, charm: CharmBase, relation_name: str):
"""Init."""
Expand Down Expand Up @@ -336,4 +336,7 @@ def set_webui_url_in_all_relations(self, webui_url: str) -> None:
raise RuntimeError(f"Relation {self.relation_name} not created yet.")

for relation in relations:
relation.data[self.charm.app].update({"webui_url": webui_url})
try:
relation.data[self.charm.app].update({"webui_url": webui_url})
except ModelError as exc:
logger.error("Error updating the relation data: %s", str(exc))

0 comments on commit 789f3ca

Please sign in to comment.