Skip to content

Commit

Permalink
Create new fiveg_n2 library
Browse files Browse the repository at this point in the history
Update fiveg_nrf library
Pin macaroonbakery to 1.3.2
The next protobuf version 4.21.0 has the breaking changes with the existing code
https://protobuf.dev/news/2022-05-06/#python-updates

Signed-off-by: gatici <gulsum.atici@canonical.com>
  • Loading branch information
gatici committed Dec 8, 2023
1 parent 5ca17dc commit d57cede
Show file tree
Hide file tree
Showing 11 changed files with 38 additions and 37 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/main.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ jobs:
with:
filters: |
fiveg_n2:
- 'lib/charms/sdcore_amf/v0/fiveg_n2.py'
- 'lib/charms/sdcore_amf_k8s/v0/fiveg_n2.py'
publish-lib:
name: Publish Lib
Expand All @@ -63,5 +63,5 @@ jobs:
if: ${{ github.ref_name == 'main' }} && ${{ needs.changes.outputs.needs-publishing == 'true' }}
uses: canonical/sdcore-github-workflows/.github/workflows/publish-lib.yaml@main
with:
lib-name: "charms.sdcore_amf.v0.fiveg_n2"
lib-name: "charms.sdcore_amf_k8s.v0.fiveg_n2"
secrets: inherit
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# SD-Core AMF Operator for K8s
# SD-Core AMF Operator (k8s)
[![CharmHub Badge](https://charmhub.io/sdcore-amf-k8s/badge.svg)](https://charmhub.io/sdcore-amf-k8s)

Charmed Operator for SD-Core's Access and Mobility Management Function (AMF) for K8s.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
From a charm directory, fetch the library using `charmcraft`:
```shell
charmcraft fetch-lib charms.sdcore_amf.v0.fiveg_n2
charmcraft fetch-lib charms.sdcore_amf_k8s.v0.fiveg_n2
```
Add the following libraries to the charm's `requirements.txt` file:
Expand All @@ -30,7 +30,7 @@
from ops.charm import CharmBase
from ops.main import main
from charms.sdcore_amf.v0.fiveg_n2 import N2InformationAvailableEvent, N2Requires
from charms.sdcore_amf_k8s.v0.fiveg_n2 import N2InformationAvailableEvent, N2Requires
logger = logging.getLogger(__name__)
Expand Down Expand Up @@ -64,7 +64,7 @@ def _on_n2_information_available(self, event: N2InformationAvailableEvent):
from ops.charm import CharmBase, RelationJoinedEvent
from ops.main import main
from charms.sdcore_amf.v0.fiveg_n2 import N2Provides
from charms.sdcore_amf_k8s.v0.fiveg_n2 import N2Provides
class DummyFivegN2ProviderCharm(CharmBase):
Expand Down Expand Up @@ -105,12 +105,12 @@ def _on_fiveg_n2_relation_joined(self, event: RelationJoinedEvent):
from pydantic import BaseModel, Field, IPvAnyAddress, ValidationError

# The unique Charmhub library identifier, never change it
LIBID = "3bb439930da24fd09631af74f70ea394"
LIBID = "396917943b9b4b6989166b77c97a9fb8"

# Increment this major API version when introducing breaking changes
LIBAPI = 0

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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
From a charm directory, fetch the library using `charmcraft`:
```shell
charmcraft fetch-lib charms.sdcore_nrf.v0.fiveg_nrf
charmcraft fetch-lib charms.sdcore_nrf_k8s.v0.fiveg_nrf
```
Add the following libraries to the charm's `requirements.txt` file:
Expand All @@ -28,7 +28,7 @@
from ops.charm import CharmBase
from ops.main import main
from charms.sdcore_nrf.v0.fiveg_nrf import NRFAvailableEvent, NRFRequires
from charms.sdcore_nrf_k8s.v0.fiveg_nrf import NRFAvailableEvent, NRFRequires
logger = logging.getLogger(__name__)
Expand Down Expand Up @@ -58,7 +58,7 @@ def _on_nrf_available(self, event: NRFAvailableEvent):
from ops.charm import CharmBase, RelationJoinedEvent
from ops.main import main
from charms.sdcore_nrf.v0.fiveg_nrf import NRFProvides
from charms.sdcore_nrf_k8s.v0.fiveg_nrf import NRFProvides
class DummyFiveGNRFProviderCharm(CharmBase):
Expand Down Expand Up @@ -103,14 +103,14 @@ def _on_nrf_url_changed(
from pydantic import AnyHttpUrl, BaseModel, Field, ValidationError

# The unique Charmhub library identifier, never change it
LIBID = "cd132a12c2b34243bfd2bae8d08c32d6"
LIBID = "14746bb6f8d34accbeac27ea50ff4715"

# Increment this major API version when introducing breaking changes
LIBAPI = 0

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

PYDEPS = ["pydantic", "pytest-interface-tester"]

Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ profile = "black"
max-line-length = 99
max-doc-length = 99
max-complexity = 10
exclude = [".git", "__pycache__", ".tox", "build", "dist", "*.egg_info", "venv", "lib/charms/data_platform_libs", "lib/charms/observability_libs", "lib/charms/prometheus_k8s", "lib/charms/sdcore_nrf"]
exclude = [".git", "__pycache__", ".tox", "build", "dist", "*.egg_info", "venv", "lib/charms/data_platform_libs", "lib/charms/observability_libs", "lib/charms/prometheus_k8s", "lib/charms/sdcore_nrf_k8s"]
select = ["E", "W", "F", "C", "N", "R", "D", "H"]
# Ignore D107 Missing docstring in __init__
ignore = ["D107"]
Expand Down
4 changes: 2 additions & 2 deletions src/charm.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@
from charms.prometheus_k8s.v0.prometheus_scrape import ( # type: ignore[import]
MetricsEndpointProvider,
)
from charms.sdcore_amf.v0.fiveg_n2 import N2Provides # type: ignore[import]
from charms.sdcore_nrf.v0.fiveg_nrf import NRFRequires # type: ignore[import]
from charms.sdcore_amf_k8s.v0.fiveg_n2 import N2Provides # type: ignore[import]
from charms.sdcore_nrf_k8s.v0.fiveg_nrf import NRFRequires # type: ignore[import]
from charms.tls_certificates_interface.v2.tls_certificates import ( # type: ignore[import]
CertificateAvailableEvent,
CertificateExpiringEvent,
Expand Down
1 change: 1 addition & 0 deletions test-requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ flake8-docstrings
flake8-builtins
isort
juju
macaroonbakery==1.3.2 # https://protobuf.dev/news/2022-05-06/#python-updates
mypy
pep8-naming
pyproject-flake8
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
from ops import testing
from ops.charm import CharmBase, RelationJoinedEvent

from lib.charms.sdcore_amf.v0.fiveg_n2 import N2Provides
from lib.charms.sdcore_amf_k8s.v0.fiveg_n2 import N2Provides

METADATA = """
name: fiveg-n2-provider
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
from ops import testing
from ops.charm import CharmBase

from lib.charms.sdcore_amf.v0.fiveg_n2 import N2InformationAvailableEvent, N2Requires
from lib.charms.sdcore_amf_k8s.v0.fiveg_n2 import N2InformationAvailableEvent, N2Requires

METADATA = """
name: fiveg-n2-requirer
Expand All @@ -23,7 +23,7 @@

logger = logging.getLogger(__name__)

CHARM_LIB_PATH = "lib.charms.sdcore_amf.v0.fiveg_n2"
CHARM_LIB_PATH = "lib.charms.sdcore_amf_k8s.v0.fiveg_n2"


class DummyFivegN2Requires(CharmBase):
Expand Down
34 changes: 17 additions & 17 deletions tests/unit/test_charm.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ def test_given_certificates_relation_not_created_when_pebble_ready_then_status_i
)

@patch("charm.check_output")
@patch("charms.sdcore_nrf.v0.fiveg_nrf.NRFRequires.nrf_url", new_callable=PropertyMock)
@patch("charms.sdcore_nrf_k8s.v0.fiveg_nrf.NRFRequires.nrf_url", new_callable=PropertyMock)
@patch("charms.data_platform_libs.v0.data_interfaces.DatabaseRequires.is_resource_created")
def test_given_amf_charm_in_active_state_when_nrf_relation_breaks_then_status_is_blocked(
self,
Expand All @@ -111,7 +111,7 @@ def test_given_amf_charm_in_active_state_when_nrf_relation_breaks_then_status_is
)

@patch("charm.check_output")
@patch("charms.sdcore_nrf.v0.fiveg_nrf.NRFRequires.nrf_url", new_callable=PropertyMock)
@patch("charms.sdcore_nrf_k8s.v0.fiveg_nrf.NRFRequires.nrf_url", new_callable=PropertyMock)
@patch("charms.data_platform_libs.v0.data_interfaces.DatabaseRequires.is_resource_created")
def test_given_amf_charm_in_active_state_when_database_relation_breaks_then_status_is_blocked(
self,
Expand Down Expand Up @@ -202,7 +202,7 @@ def test_given_nrf_data_not_available_when_pebble_ready_then_status_is_waiting(
)

@patch("charm.generate_private_key")
@patch("charms.sdcore_nrf.v0.fiveg_nrf.NRFRequires.nrf_url", new_callable=PropertyMock)
@patch("charms.sdcore_nrf_k8s.v0.fiveg_nrf.NRFRequires.nrf_url", new_callable=PropertyMock)
@patch("charms.data_platform_libs.v0.data_interfaces.DatabaseRequires.is_resource_created")
def test_given_storage_not_attached_when_pebble_ready_then_status_is_waiting(
self, patch_is_resource_created, patch_nrf_url, patch_generate_private_key
Expand All @@ -226,7 +226,7 @@ def test_given_storage_not_attached_when_pebble_ready_then_status_is_waiting(

@patch("charm.check_output")
@patch("charm.generate_private_key")
@patch("charms.sdcore_nrf.v0.fiveg_nrf.NRFRequires.nrf_url", new_callable=PropertyMock)
@patch("charms.sdcore_nrf_k8s.v0.fiveg_nrf.NRFRequires.nrf_url", new_callable=PropertyMock)
@patch("charms.data_platform_libs.v0.data_interfaces.DatabaseRequires.is_resource_created")
def test_given_certificates_not_stored_when_pebble_ready_then_status_is_waiting(
self,
Expand Down Expand Up @@ -256,7 +256,7 @@ def test_given_certificates_not_stored_when_pebble_ready_then_status_is_waiting(

@patch("charm.check_output")
@patch("charm.generate_private_key")
@patch("charms.sdcore_nrf.v0.fiveg_nrf.NRFRequires.nrf_url", new_callable=PropertyMock)
@patch("charms.sdcore_nrf_k8s.v0.fiveg_nrf.NRFRequires.nrf_url", new_callable=PropertyMock)
@patch("charms.data_platform_libs.v0.data_interfaces.DatabaseRequires.is_resource_created")
def test_given_relations_created_and_database_available_and_nrf_data_available_and_certs_stored_when_pebble_ready_then_config_file_rendered_and_pushed_correctly( # noqa: E501
self,
Expand Down Expand Up @@ -292,7 +292,7 @@ def test_given_relations_created_and_database_available_and_nrf_data_available_a

@patch("charm.check_output")
@patch("charm.generate_private_key")
@patch("charms.sdcore_nrf.v0.fiveg_nrf.NRFRequires.nrf_url", new_callable=PropertyMock)
@patch("charms.sdcore_nrf_k8s.v0.fiveg_nrf.NRFRequires.nrf_url", new_callable=PropertyMock)
@patch("charms.data_platform_libs.v0.data_interfaces.DatabaseRequires.is_resource_created")
def test_given_content_of_config_file_changed_when_pebble_ready_then_config_file_is_rendered_and_pushed( # noqa: E501
self,
Expand Down Expand Up @@ -334,7 +334,7 @@ def test_given_content_of_config_file_changed_when_pebble_ready_then_config_file

@patch("charm.check_output")
@patch("charm.generate_private_key")
@patch("charms.sdcore_nrf.v0.fiveg_nrf.NRFRequires.nrf_url", new_callable=PropertyMock)
@patch("charms.sdcore_nrf_k8s.v0.fiveg_nrf.NRFRequires.nrf_url", new_callable=PropertyMock)
@patch("charms.data_platform_libs.v0.data_interfaces.DatabaseRequires.is_resource_created")
def test_given_content_of_config_file_not_changed_when_pebble_ready_then_config_file_is_not_pushed( # noqa: E501
self,
Expand Down Expand Up @@ -367,7 +367,7 @@ def test_given_content_of_config_file_not_changed_when_pebble_ready_then_config_
)

@patch("charm.check_output")
@patch("charms.sdcore_nrf.v0.fiveg_nrf.NRFRequires.nrf_url", new_callable=PropertyMock)
@patch("charms.sdcore_nrf_k8s.v0.fiveg_nrf.NRFRequires.nrf_url", new_callable=PropertyMock)
@patch("charms.data_platform_libs.v0.data_interfaces.DatabaseRequires.is_resource_created")
def test_given_relations_available_and_config_pushed_when_pebble_ready_then_pebble_is_applied_correctly( # noqa: E501
self,
Expand Down Expand Up @@ -415,7 +415,7 @@ def test_given_relations_available_and_config_pushed_when_pebble_ready_then_pebb
self.assertEqual(expected_plan, updated_plan)

@patch("charm.check_output")
@patch("charms.sdcore_nrf.v0.fiveg_nrf.NRFRequires.nrf_url", new_callable=PropertyMock)
@patch("charms.sdcore_nrf_k8s.v0.fiveg_nrf.NRFRequires.nrf_url", new_callable=PropertyMock)
@patch("charms.data_platform_libs.v0.data_interfaces.DatabaseRequires.is_resource_created")
def test_relations_available_and_config_pushed_and_pebble_updated_when_pebble_ready_then_status_is_active( # noqa: E501
self,
Expand Down Expand Up @@ -447,7 +447,7 @@ def test_relations_available_and_config_pushed_and_pebble_updated_when_pebble_re
)

@patch("charm.check_output")
@patch("charms.sdcore_nrf.v0.fiveg_nrf.NRFRequires.nrf_url", new_callable=PropertyMock)
@patch("charms.sdcore_nrf_k8s.v0.fiveg_nrf.NRFRequires.nrf_url", new_callable=PropertyMock)
def test_given_empty_ip_address_when_pebble_ready_then_status_is_waiting(
self,
patch_nrf_url,
Expand Down Expand Up @@ -489,7 +489,7 @@ def test_given_service_not_running_when_fiveg_n2_relation_joined_then_n2_informa
@patch("lightkube.core.client.GenericSyncClient", new=Mock)
@patch("lightkube.core.client.Client.get")
@patch("charm.check_output")
@patch("charms.sdcore_nrf.v0.fiveg_nrf.NRFRequires.nrf_url", new_callable=PropertyMock)
@patch("charms.sdcore_nrf_k8s.v0.fiveg_nrf.NRFRequires.nrf_url", new_callable=PropertyMock)
@patch("charms.data_platform_libs.v0.data_interfaces.DatabaseRequires.is_resource_created")
def test_given_n2_information_and_service_is_running_when_fiveg_n2_relation_joined_then_n2_information_is_in_relation_databag( # noqa: E501
self,
Expand Down Expand Up @@ -533,7 +533,7 @@ def test_given_n2_information_and_service_is_running_when_fiveg_n2_relation_join
@patch("lightkube.core.client.GenericSyncClient", new=Mock)
@patch("lightkube.core.client.Client.get")
@patch("charm.check_output")
@patch("charms.sdcore_nrf.v0.fiveg_nrf.NRFRequires.nrf_url", new_callable=PropertyMock)
@patch("charms.sdcore_nrf_k8s.v0.fiveg_nrf.NRFRequires.nrf_url", new_callable=PropertyMock)
@patch("charms.data_platform_libs.v0.data_interfaces.DatabaseRequires.is_resource_created")
def test_given_n2_information_and_service_is_running_and_n2_config_is_overriden_when_fiveg_n2_relation_joined_then_custom_n2_information_is_in_relation_databag( # noqa: E501
self,
Expand Down Expand Up @@ -580,7 +580,7 @@ def test_given_n2_information_and_service_is_running_and_n2_config_is_overriden_
@patch("lightkube.core.client.GenericSyncClient", new=Mock)
@patch("lightkube.core.client.Client.get")
@patch("charm.check_output")
@patch("charms.sdcore_nrf.v0.fiveg_nrf.NRFRequires.nrf_url", new_callable=PropertyMock)
@patch("charms.sdcore_nrf_k8s.v0.fiveg_nrf.NRFRequires.nrf_url", new_callable=PropertyMock)
@patch("charms.data_platform_libs.v0.data_interfaces.DatabaseRequires.is_resource_created")
def test_given_n2_information_and_service_is_running_and_lb_service_has_no_hostname_when_fiveg_n2_relation_joined_then_internal_service_hostname_is_used( # noqa: E501
self,
Expand Down Expand Up @@ -625,7 +625,7 @@ def test_given_n2_information_and_service_is_running_and_lb_service_has_no_hostn
@patch("lightkube.core.client.GenericSyncClient", new=Mock)
@patch("lightkube.core.client.Client.get")
@patch("charm.check_output")
@patch("charms.sdcore_nrf.v0.fiveg_nrf.NRFRequires.nrf_url", new_callable=PropertyMock)
@patch("charms.sdcore_nrf_k8s.v0.fiveg_nrf.NRFRequires.nrf_url", new_callable=PropertyMock)
@patch("charms.data_platform_libs.v0.data_interfaces.DatabaseRequires.is_resource_created")
def test_given_n2_information_and_service_is_running_and_metallb_service_is_not_available_when_fiveg_n2_relation_joined_then_amf_goes_in_blocked_state( # noqa: E501
self,
Expand Down Expand Up @@ -663,7 +663,7 @@ def test_given_n2_information_and_service_is_running_and_metallb_service_is_not_
@patch("lightkube.core.client.GenericSyncClient", new=Mock)
@patch("lightkube.core.client.Client.get")
@patch("charm.check_output")
@patch("charms.sdcore_nrf.v0.fiveg_nrf.NRFRequires.nrf_url", new_callable=PropertyMock)
@patch("charms.sdcore_nrf_k8s.v0.fiveg_nrf.NRFRequires.nrf_url", new_callable=PropertyMock)
@patch("charms.data_platform_libs.v0.data_interfaces.DatabaseRequires.is_resource_created")
def test_given_service_starts_running_after_n2_relation_joined_when_pebble_ready_then_n2_information_is_in_relation_databag( # noqa: E501
self,
Expand Down Expand Up @@ -713,7 +713,7 @@ def test_given_service_starts_running_after_n2_relation_joined_when_pebble_ready
@patch("lightkube.core.client.Client.get")
@patch("charm.generate_private_key")
@patch("charm.check_output")
@patch("charms.sdcore_nrf.v0.fiveg_nrf.NRFRequires.nrf_url", new_callable=PropertyMock)
@patch("charms.sdcore_nrf_k8s.v0.fiveg_nrf.NRFRequires.nrf_url", new_callable=PropertyMock)
@patch("charms.data_platform_libs.v0.data_interfaces.DatabaseRequires.is_resource_created")
def test_given_more_than_one_n2_requirers_join_n2_relation_when_service_starts_then_n2_information_is_in_relation_databag( # noqa: E501
self,
Expand Down Expand Up @@ -805,7 +805,7 @@ def test_given_certificates_are_stored_when_on_certificates_relation_broken_then
(root / "support/TLS/amf.csr").read_text()

@patch("charm.check_output")
@patch("charms.sdcore_nrf.v0.fiveg_nrf.NRFRequires.nrf_url", new_callable=PropertyMock)
@patch("charms.sdcore_nrf_k8s.v0.fiveg_nrf.NRFRequires.nrf_url", new_callable=PropertyMock)
@patch("charms.data_platform_libs.v0.data_interfaces.DatabaseRequires.is_resource_created")
def test_given_certificates_are_stored_when_on_certificates_relation_broken_then_status_is_blocked( # noqa: E501
self,
Expand Down
2 changes: 1 addition & 1 deletion tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ envlist = lint, unit, static
src_path = {toxinidir}/src/
unit_test_path = {toxinidir}/tests/unit/
integration_test_path = {toxinidir}/tests/integration/
lib_path = {toxinidir}/lib/charms/sdcore_amf/v0/
lib_path = {toxinidir}/lib/charms/sdcore_amf_k8s/v0/
all_path = {[vars]src_path} {[vars]unit_test_path} {[vars]integration_test_path} {[vars]lib_path}

[testenv]
Expand Down

0 comments on commit d57cede

Please sign in to comment.