Skip to content

Commit

Permalink
Upgrade dependencies
Browse files Browse the repository at this point in the history
  • Loading branch information
Mehdi-Bendriss committed May 24, 2024
1 parent 7edec05 commit 4a8f80f
Show file tree
Hide file tree
Showing 22 changed files with 79 additions and 58 deletions.
20 changes: 19 additions & 1 deletion .github/workflows/release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,32 @@ jobs:
with:
fetch-depth: 0
- name: Check libs
uses: canonical/charming-actions/check-libraries@2.1.1
uses: canonical/charming-actions/check-libraries@2.4.0
with:
credentials: "${{ secrets.CHARMHUB_TOKEN }}" # FIXME: current token will expire in 2023-07-04
github-token: "${{ secrets.GITHUB_TOKEN }}"

ci-tests:
uses: ./.github/workflows/ci.yaml

release-libraries:
name: Release libraries
needs:
- ci-tests
- lib-check
runs-on: ubuntu-latest
timeout-minutes: 60
steps:
- name: Checkout
uses: actions/checkout@v3
with:
fetch-depth: 0
- name: Release charm libraries
uses: canonical/charming-actions/[email protected]
with:
credentials: ${{ secrets.CHARMHUB_TOKEN }}
github-token: ${{ secrets.GITHUB_TOKEN }}

release-to-charmhub:
name: Release to CharmHub
needs:
Expand Down
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@
same "printed page" as the copyright notice for easier
identification within third-party archives.

Copyright 2022 Canonical Ltd.
Copyright 2024 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
2 changes: 1 addition & 1 deletion actions.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright 2022 Canonical Ltd.
# Copyright 2024 Canonical Ltd.
# See LICENSE file for licensing details.

check-service:
Expand Down
2 changes: 1 addition & 1 deletion charmcraft.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright 2022 Canonical Ltd.
# Copyright 2024 Canonical Ltd.
# See LICENSE file for licensing details.

type: charm
Expand Down
2 changes: 1 addition & 1 deletion config.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright 2022 Canonical Ltd.
# Copyright 2024 Canonical Ltd.
# See LICENSE file for licensing details.

options:
Expand Down
18 changes: 10 additions & 8 deletions lib/charms/redis_k8s/v0/redis.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
```
from charms.redis_k8s.v0.redis import RedisRequires
```
Define the following attributes in charm charm class for the library to be able to work with it
Define the following attributes in charm class for the library to be able to work with it
```
on = RedisRelationCharmEvents()
```
Expand All @@ -28,6 +28,7 @@
import socket
from typing import Dict, Optional

from ops import RelationDataContent
from ops.charm import CharmEvents
from ops.framework import EventBase, EventSource, Object

Expand All @@ -39,11 +40,12 @@

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

logger = logging.getLogger(__name__)

DEFAULT_REALTION_NAME = "redis"
DEFAULT_RELATION_NAME = "redis"


class RedisRelationUpdatedEvent(EventBase):
"""An event for the redis relation having been updated."""
Expand All @@ -56,7 +58,7 @@ class RedisRelationCharmEvents(CharmEvents):

class RedisRequires(Object):

def __init__(self, charm, relation_name: str = DEFAULT_REALTION_NAME):
def __init__(self, charm, relation_name: str = DEFAULT_RELATION_NAME):
"""A class implementing the redis requires relation."""
super().__init__(charm, relation_name)
self.framework.observe(charm.on[relation_name].relation_joined, self._on_relation_changed)
Expand All @@ -73,13 +75,13 @@ def _on_relation_changed(self, event):
# Trigger an event that our charm can react to.
self.charm.on.redis_relation_updated.emit()

def _on_relation_broken(self, event):
def _on_relation_broken(self, _):
"""Handle the relation broken event."""
# Trigger an event that our charm can react to.
self.charm.on.redis_relation_updated.emit()

@property
def relation_data(self) -> Optional[Dict[str, str]]:
def relation_data(self) -> Optional[RelationDataContent]:
"""Retrieve the relation data.
Returns:
Expand Down Expand Up @@ -109,7 +111,7 @@ def url(self) -> Optional[str]:
class RedisProvides(Object):
def __init__(self, charm, port):
"""A class implementing the redis provides relation."""
super().__init__(charm, DEFAULT_REALTION_NAME)
super().__init__(charm, DEFAULT_RELATION_NAME)
self.framework.observe(charm.on.redis_relation_changed, self._on_relation_changed)
self._port = port
self._charm = charm
Expand All @@ -128,7 +130,7 @@ def _bind_address(self, event):
relation = self.model.get_relation(event.relation.name, event.relation.id)
if address := self.model.get_binding(relation).network.bind_address:
return address
return self.app.name
return self._charm.app.name

def _get_master_ip(self) -> str:
"""Gets the ip of the current redis master."""
Expand Down
2 changes: 1 addition & 1 deletion metadata.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright 2022 Canonical Ltd.
# Copyright 2024 Canonical Ltd.
# See LICENSE file for licensing details.

name: redis-k8s
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright 2022 Canonical Ltd.
# Copyright 2024 Canonical Ltd.
# See LICENSE file for licensing details.

# Testing tools configuration
Expand Down
11 changes: 5 additions & 6 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
# This file is part of the Redis k8s Charm for Juju.
# Copyright 2022 Canonical Ltd.
# Copyright 2024 Canonical Ltd.
# See LICENSE file for licensing details.

ops~=2.3.0
redis~=4.3.4
jinja2==3.1.1
tenacity==8.0.1
ops==2.13.0
redis==5.0.4
jinja2==3.1.4
tenacity==8.3.0
21 changes: 11 additions & 10 deletions src/charm.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#!/usr/bin/env python3
# Copyright 2022 Canonical Ltd.
# Copyright 2024 Canonical Ltd.
# See LICENSE file for licensing details.

"""Charm code for Redis service."""
Expand Down Expand Up @@ -183,7 +183,7 @@ def _config_changed(self, event: EventBase) -> None:
return

self._update_layer()
self.sentinel._update_sentinel_layer()
self.sentinel.update_layer()

# update_layer will set a Waiting status if Pebble is not ready
if not isinstance(self.unit.status, ActiveStatus):
Expand Down Expand Up @@ -258,7 +258,7 @@ def _peer_relation_departed(self, event):
if not self._is_failover_finished():
msg = "Failover didn't finish, deferring"
logger.info(msg)
self.unit.status == WaitingStatus(msg)
self.unit.status = WaitingStatus(msg)
event.defer()
return

Expand All @@ -267,7 +267,7 @@ def _peer_relation_departed(self, event):
except RedisError as e:
msg = f"Error on failover: {e}"
logger.error(msg)
self.unit.status == BlockedStatus(msg)
self.unit.status = BlockedStatus(msg)
return

logger.info("Resetting sentinel")
Expand Down Expand Up @@ -302,7 +302,7 @@ def _update_layer(self) -> None:
self.unit.status = WaitingStatus("Waiting for Pebble in workload container")
return

if not self._valid_app_databag():
if not self.valid_app_databag():
self.unit.status = WaitingStatus("Waiting for peer data to be updated")
return

Expand Down Expand Up @@ -385,7 +385,7 @@ def _redis_extra_flags(self) -> str:

return " ".join(extra_flags)

def _redis_check(self) -> None:
def _redis_check(self) -> bool:
"""Checks if the Redis database is active."""
try:
with self._redis_client() as redis:
Expand Down Expand Up @@ -459,7 +459,7 @@ def current_master(self) -> Optional[str]:
"""Get the current master."""
return self._peers.data[self.app].get(LEADER_HOST_KEY)

def _valid_app_databag(self) -> bool:
def valid_app_databag(self) -> bool:
"""Check if the peer databag has been populated.
Returns:
Expand All @@ -474,14 +474,15 @@ def _valid_app_databag(self) -> bool:

return bool(password and self.current_master)

def _generate_password(self) -> str:
@staticmethod
def _generate_password() -> str:
"""Generate a random 16 character password string.
Returns:
A random password string.
"""
choices = string.ascii_letters + string.digits
password = "".join([secrets.choice(choices) for i in range(16)])
password = "".join([secrets.choice(choices) for _ in range(16)])
return password

def _get_password(self) -> Optional[str]:
Expand Down Expand Up @@ -517,7 +518,7 @@ def _store_certificates(self) -> None:
for cert_path in cert_paths:
with open(cert_path, "r") as f:
container.push(
(f"{self._storage_path}/{cert_path.name}"),
f"{self._storage_path}/{cert_path.name}",
f,
make_dirs=True,
permissions=0o600,
Expand Down
2 changes: 1 addition & 1 deletion src/literals.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#!/usr/bin/env python3
# Copyright 2022 Canonical Ltd.
# Copyright 2024 Canonical Ltd.
# See LICENSE file for licensing details.

"""Literals used by the Redis charm."""
Expand Down
13 changes: 7 additions & 6 deletions src/sentinel.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#!/usr/bin/env python3
# Copyright 2022 Canonical Ltd.
# Copyright 2024 Canonical Ltd.
# See LICENSE file for licensing details.


Expand Down Expand Up @@ -45,14 +45,14 @@ def __init__(self, charm) -> None:

def _sentinel_pebble_ready(self, event) -> None:
"""Handle pebble ready event for sentinel container."""
self._update_sentinel_layer()
self.update_layer()

# update layer should leave the unit in active status
if not isinstance(self.charm.unit.status, ActiveStatus):
event.defer()
return

def _update_sentinel_layer(self) -> None:
def update_layer(self) -> None:
"""Update the Pebble layer.
Checks the current container Pebble layer. If the layer is different
Expand All @@ -64,21 +64,22 @@ def _update_sentinel_layer(self) -> None:
self.charm.unit.status = WaitingStatus("Waiting for Pebble in sentinel container")
return

if not self.charm._valid_app_databag():
if not self.charm.valid_app_databag():
self.charm.unit.status = WaitingStatus("Databag has not been populated")
return

# copy sentinel config file to the container
self._render_sentinel_config_file()

# Create the new config layer
new_layer = self._sentinel_layer()
new_layer = self._layer()

# Update the Pebble configuration Layer
container.add_layer("sentinel", new_layer, combine=True)
container.replan()

def _sentinel_layer(self) -> Layer:
@staticmethod
def _layer() -> Layer:
"""Create the Pebble configuration layer for Redis Sentinel.
Returns:
Expand Down
2 changes: 1 addition & 1 deletion tests/integration/__init__.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
# This file is part of the Redis k8s Charm for Juju.
# Copyright 2022 Canonical Ltd.
# Copyright 2024 Canonical Ltd.
2 changes: 1 addition & 1 deletion tests/integration/conftest.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright 2022 Canonical Ltd.
# Copyright 2024 Canonical Ltd.
# See LICENSE file for licensing details.

from .helpers import NUM_UNITS
Expand Down
10 changes: 5 additions & 5 deletions tests/integration/helpers.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#!/usr/bin/env python3
# Copyright 2022 Canonical Ltd.
# Copyright 2024 Canonical Ltd.
# See LICENSE file for licensing details.

"""Helpers for integration tests."""
Expand Down Expand Up @@ -29,11 +29,11 @@
logger = logging.getLogger(__name__)


async def scale(ops_test: OpsTest, scale: int) -> None:
async def scale(ops_test: OpsTest, count: int) -> None:
"""Scale the application to the provided number and wait for idle."""
await ops_test.model.applications[APP_NAME].scale(scale=scale)
await ops_test.model.applications[APP_NAME].scale(scale=count)
await ops_test.model.block_until(
lambda: len(ops_test.model.applications[APP_NAME].units) == scale
lambda: len(ops_test.model.applications[APP_NAME].units) == count
)

# Wait for model to settle
Expand Down Expand Up @@ -148,7 +148,7 @@ def get_unit_number(unit_name: str) -> str:
before=before_log(logger, logging.DEBUG),
)
def query_url(url: str):
"""Connect to a url and return the result."""
"""Connect to an url and return the result."""
logger.info("Trying to connect to: {}".format(url))
response = urlopen(url)

Expand Down
2 changes: 1 addition & 1 deletion tests/integration/test_charm.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#!/usr/bin/env python3
# Copyright 2022 Canonical Ltd.
# Copyright 2024 Canonical Ltd.
# See LICENSE file for licensing details.

import logging
Expand Down
2 changes: 1 addition & 1 deletion tests/integration/test_password.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#!/usr/bin/env python3
# Copyright 2022 Canonical Ltd.
# Copyright 2024 Canonical Ltd.
# See LICENSE file for licensing details.

import logging
Expand Down
2 changes: 1 addition & 1 deletion tests/integration/test_redis_relation.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#!/usr/bin/env python3
# Copyright 2022 Canonical Ltd.
# Copyright 2024 Canonical Ltd.
# See LICENSE file for licensing details.

import asyncio
Expand Down
6 changes: 3 additions & 3 deletions tests/integration/test_scaling.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#!/usr/bin/env python3
# Copyright 2022 Canonical Ltd.
# Copyright 2024 Canonical Ltd.
# See LICENSE file for licensing details.

import logging
Expand Down Expand Up @@ -80,7 +80,7 @@ async def test_scale_up_replication_after_failover(ops_test: OpsTest):
timeout=60,
)

await ops_test.model.applications[APP_NAME].scale(scale=NUM_UNITS + 1)
await ops_test.model.applications[APP_NAME].scale(count=NUM_UNITS + 1)
await ops_test.model.block_until(
lambda: len(ops_test.model.applications[APP_NAME].units) == NUM_UNITS + 1,
timeout=300,
Expand Down Expand Up @@ -150,7 +150,7 @@ async def test_scale_down_departing_master(ops_test: OpsTest):
last_redis.close()

# SCALE DOWN #
await scale(ops_test, scale=NUM_UNITS)
await scale(ops_test, count=NUM_UNITS)

# Check that the initial key is still replicated across units
for i in range(NUM_UNITS):
Expand Down
2 changes: 1 addition & 1 deletion tests/unit/__init__.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
# This file is part of the Redis k8s Charm for Juju.
# Copyright 2022 Canonical Ltd.
# Copyright 2024 Canonical Ltd.
Loading

0 comments on commit 4a8f80f

Please sign in to comment.