Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add support bionic #29

Merged
merged 18 commits into from
Aug 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 21 additions & 6 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -32,32 +32,44 @@ jobs:

lint:
name: Lint
runs-on: ubuntu-22.04
runs-on: ubuntu-20.04
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Set up Python 3.6
uses: actions/setup-python@v5
with:
python-version: 3.6
- name: Install dependencies
run: python3 -m pip install tox
- name: Run linters
run: tox -e lint

static-analysis:
name: Static Analysis
runs-on: ubuntu-22.04
runs-on: ubuntu-20.04
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Set up Python 3.6
uses: actions/setup-python@v5
with:
python-version: 3.6
- name: Install dependencies
run: python3 -m pip install tox
- name: Run static analysis
run: tox -e static-charm

unit-test:
name: Unit tests
runs-on: ubuntu-latest
runs-on: ubuntu-20.04
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Set up Python 3.6
uses: actions/setup-python@v5
with:
python-version: 3.6
- name: Install dependencies
run: python3 -m pip install tox
- name: Run tests
Expand All @@ -68,8 +80,7 @@ jobs:
fail-fast: true
matrix:
bases:
- [email protected]
- [email protected]
- [email protected]
name: Integration tests (LXD) | ${{ matrix.bases }}
runs-on: ubuntu-latest
needs:
Expand All @@ -79,10 +90,14 @@ jobs:
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Set up Python 3.12
uses: actions/setup-python@v5
with:
python-version: 3.12
- name: Setup operator environment
uses: charmed-kubernetes/actions-operator@main
with:
provider: lxd
juju-channel: 3/stable
juju-channel: 2.9/stable
- name: Run tests
run: tox run -e integration -- --charm-base=${{ matrix.bases }}
46 changes: 3 additions & 43 deletions charmcraft.yaml
Original file line number Diff line number Diff line change
@@ -1,60 +1,20 @@
---
type: "charm"
name: lldpd
title: LLDPd Operator
summary: An operator that provides lldpd.
description: |
An operator charm that provides the link-layer discover protocol (LLDP) services.
This operator installs and manages the lldpd package and services.

LLDP is a layer 2 neighbor discovery protocol that allows devices to advertise their
device information to their neighbors.

LLDP is generally disabled by default on linux bridges and may not allow for transmission
of LLDP packets by default. As such, the use of this LLDP in an environment configured
with linux bridging may need additional tweaks at the host level.

requires:
juju-info:
interface: juju-info
scope: container
master:
interface: lldp
provides:
nrpe-external-master:
interface: nrpe-external-master
scope: container
subordinate: true

bases:
- build-on:
- name: "ubuntu"
channel: "22.04"
architectures: [amd64]
run-on:
- name: "ubuntu"
channel: "22.04"
architectures: [amd64]
- build-on:
- name: "ubuntu"
channel: "22.04"
architectures: [arm64]
run-on:
- name: "ubuntu"
channel: "22.04"
architectures: [arm64]
- build-on:
- name: "ubuntu"
channel: "20.04"
architectures: [amd64]
run-on:
- name: "ubuntu"
channel: "20.04"
channel: "18.04"
architectures: [amd64]
- build-on:
- name: "ubuntu"
channel: "20.04"
architectures: [arm64]
run-on:
- name: "ubuntu"
channel: "20.04"
channel: "18.04"
architectures: [arm64]
28 changes: 28 additions & 0 deletions metadata.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
---
name: lldpd
title: LLDPd Operator
summary: An operator that provides lldpd.
description: |
An operator charm that provides the link-layer discovery protocol (LLDP) services.
This operator installs and manages the lldpd package and services.

LLDP is a layer 2 neighbor discovery protocol that allows devices to advertise their
device information to their neighbors.

LLDP is generally disabled by default on Linux bridges which block the transmission
of LLDP packets by default. As such, the use of this LLDP in an environment configured
with Linux bridging may need additional tweaks at the host level.

requires:
juju-info:
interface: juju-info
scope: container
master:
interface: lldp

provides:
nrpe-external-master:
interface: nrpe-external-master
scope: container

subordinate: true
3 changes: 2 additions & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
ops >= 1.4.0
ops < 2
websocket_client <= 1.6.4
16 changes: 12 additions & 4 deletions src/charm.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,10 @@
import logging
import os
import subprocess
from typing import cast

from ops.charm import CharmBase
from ops.framework import StoredState
from ops.charm import CharmBase, RelationChangedEvent, RelationJoinedEvent
from ops.framework import EventSource, ObjectEvents, StoredState
from ops.main import main
from ops.model import ActiveStatus, MaintenanceStatus
from charms.operator_libs_linux.v0 import apt
Expand All @@ -37,6 +38,13 @@
logger = logging.getLogger(__name__)


class LldpCharmEvents(ObjectEvents):
"""Declare relation-specific events for the type checker."""

nrpe_external_master_relation_changed = EventSource(RelationChangedEvent)
nrpe_external_master_relation_joined = EventSource(RelationJoinedEvent)


class LldpdCharm(CharmBase):
"""Charm to deploy and manage lldpd"""

Expand All @@ -48,11 +56,11 @@ def __init__(self, *args):
self.framework.observe(self.on.upgrade_charm, self.on_upgrade_charm)
self.framework.observe(self.on.config_changed, self.on_config_changed)
self.framework.observe(
self.on.nrpe_external_master_relation_changed,
cast(LldpCharmEvents, self.on).nrpe_external_master_relation_changed,
self.on_nrpe_external_master_relation_changed,
)
self.framework.observe(
self.on.nrpe_external_master_relation_joined,
cast(LldpCharmEvents, self.on).nrpe_external_master_relation_joined,
self.on_nrpe_external_master_relation_changed,
)

Expand Down
6 changes: 3 additions & 3 deletions tests/integration/test_charm.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ async def test_build_and_deploy(
"ubuntu",
application_name="ubuntu",
num_units=NUM_UNITS,
base=charm_base,
series="bionic",
),
ops_test.model.deploy(
str(lldpd),
Expand All @@ -55,8 +55,8 @@ async def test_build_and_deploy(
),
)

# Integrate lldpd with ubuntu
await ops_test.model.integrate("ubuntu:juju-info", "lldpd:juju-info")
# Relate lldpd with ubuntu
await ops_test.model.relate("ubuntu:juju-info", "lldpd:juju-info")
async with ops_test.fast_forward():
await ops_test.model.wait_for_idle(
apps=["lldpd", "ubuntu"], status="active", timeout=1800
Expand Down
26 changes: 10 additions & 16 deletions tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,15 @@
[tox]
skipsdist=True
skip_missing_interpreters = True
envlist = lint, static-{charm,lib}, unit
envlist = lint, static-charm, static-lib, unit

[vars]
src_path = {toxinidir}/src
tst_path = {toxinidir}/tests
all_path = {[vars]src_path} {[vars]tst_path}

[testenv]
basepython = python3.6
setenv =
PYTHONPATH = {toxinidir}:{toxinidir}/lib:{[vars]src_path}
PYTHONBREAKPOINT=ipdb.set_trace
Expand All @@ -30,35 +31,26 @@ passenv =
description = Apply coding style standards to code
deps =
black
ruff
commands =
ruff --fix {[vars]all_path}
black {[vars]all_path}

[testenv:lint]
description = Check code against coding style standards
deps =
black
ruff
codespell
commands =
codespell --skip .git --skip .tox --skip build --skip lib --skip venv --skip .mypy_cache {toxinidir}
ruff {[vars]all_path}
black --check --diff {[vars]all_path}

[testenv:static-{charm,lib}]
description = Run static analysis checks
[testenv:static-charm]
description = Run static analysis checks for charm
deps =
pyright
charm: -r{toxinidir}/requirements.txt
lib: ops
lib: jinja2
unit: {[testenv:unit]deps}
integration: {[testenv:integration]deps}
ops
jinja2
commands =
charm: pyright {[vars]src_path} {posargs}
lib: pyright --pythonversion 3.8 {[vars]src_path} {posargs}
lib: /usr/bin/env sh -c 'for m in $(git diff main --name-only {[vars]lib_path}); do if ! git diff main $m | grep -q "+LIBPATCH\|+LIBAPI"; then echo "You forgot to bump the version on $m!"; exit 1; fi; done'
# /usr/bin/env sh -c 'for m in $(git diff main --name-only {[vars]src_path}); do if ! git diff main $m | grep -q "+LIBPATCH\|+LIBAPI"; then echo "You forgot to bump the version on $m!"; exit 1; fi; done'
allowlist_externals = /usr/bin/env

[testenv:unit]
Expand All @@ -74,9 +66,11 @@ commands =
coverage report

[testenv:integration]
# To support bionic, juju should be below libjuju 3.0
description = Run integration tests
basepython = python3.12
deps =
juju<=3.3.0,>=3.0
juju < 3.0.0
pytest
pytest-operator
pytest-order
Expand Down
Loading