Skip to content

Commit

Permalink
Merge pull request #4 from canonical/fix-metadata
Browse files Browse the repository at this point in the history
  • Loading branch information
arturo-seijas authored Sep 8, 2023
2 parents 880ea24 + 69a10c3 commit 8e9f778
Show file tree
Hide file tree
Showing 15 changed files with 104 additions and 77 deletions.
File renamed without changes.
5 changes: 2 additions & 3 deletions .github/workflows/integration_test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,9 @@ jobs:
secrets: inherit
with:
chaos-app-label: app.kubernetes.io/name=indico
chaos-enabled: true
chaos-enabled: false
chaos-experiments: pod-delete
extra-arguments: -m "not (requires_secrets)"
load-test-enabled: true
load-test-enabled: false
load-test-run-args: "-e LOAD_TEST_HOST=localhost"
zap-before-command: "curl -H \"Host: indico.local\" http://localhost/bootstrap --data-raw 'csrf_token=00000000-0000-0000-0000-000000000000&first_name=admin&last_name=admin&email=admin%40admin.com&username=admin&password=lunarlobster&confirm_password=lunarlobster&affiliation=Canonical'"
zap-enabled: true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,5 @@ on:

jobs:
publish-to-edge:
uses: canonical/operator-workflows/.github/workflows/test_and_publish_charm.yaml@main
uses: canonical/operator-workflows/.github/workflows/publish_charm.yaml@main
secrets: inherit
with:
integration-test-extra-arguments: -m "not (requires_secrets)"
trivy-image-config: "trivy.yaml"
10 changes: 0 additions & 10 deletions .github/workflows/test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,3 @@ jobs:
unit-tests:
uses: canonical/operator-workflows/.github/workflows/test.yaml@main
secrets: inherit
plugins-test:
name: Specific test for the plugin
runs-on: ubuntu-22.04
steps:
- uses: actions/checkout@v3
- name: Install tox
run: |
python -m pip install --upgrade pip
pip install tox
- run: tox -e plugins
2 changes: 2 additions & 0 deletions charmcraft.yaml
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# Copyright 2023 Canonical Ltd.
# See LICENSE file for licensing details.
# This file configures Charmcraft.
# See https://juju.is/docs/sdk/charmcraft-config for guidance.

Expand Down
2 changes: 2 additions & 0 deletions config.yaml
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# Copyright 2023 Canonical Ltd.
# See LICENSE file for licensing details.
# This file defines charm config options, and populates the Configure tab on Charmhub.
# If your charm does not require configuration options, delete this file entirely.
#
Expand Down
7 changes: 7 additions & 0 deletions metadata.yaml
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# Copyright 2023 Canonical Ltd.
# See LICENSE file for licensing details.
# This file populates the Overview on Charmhub.
# See https://juju.is/docs/sdk/metadata-reference for a checklist and guidance.

Expand All @@ -12,6 +14,11 @@ display-name: Charm Template

# (Required)
summary: A very short one-line summary of the charm.
docs: https://discourse.charmhub.io
issues: https://github.com/canonical/is-charms-template-repo/issues
maintainers:
- https://launchpad.net/~canonical-is-devops
source: https://github.com/canonical/is-charms-template-repo

description: |
A single sentence that says what the charm is, concisely and memorably.
Expand Down
41 changes: 36 additions & 5 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,19 +1,50 @@
[tool.bandit]
exclude_dirs = ["/venv/"]
[tool.bandit.assert_used]
skips = ["*/*test.py", "*/test_*.py", "*tests/*.py"]

# Testing tools configuration
[tool.coverage.run]
branch = true

# Formatting tools configuration
[tool.black]
line-length = 99
target-version = ["py38"]

[tool.coverage.report]
show_missing = true

# Linting tools configuration
[tool.flake8]
max-line-length = 99
max-doc-length = 99
max-complexity = 10
exclude = [".git", "__pycache__", ".tox", "build", "dist", "*.egg_info", "venv"]
select = ["E", "W", "F", "C", "N", "R", "D", "H"]
# Ignore W503, E501 because using black creates errors with this
# Ignore D107 Missing docstring in __init__
ignore = ["W503", "E501", "D107"]
# D100, D101, D102, D103: Ignore missing docstrings in tests
per-file-ignores = ["tests/*:D100,D101,D102,D103,D104,D205,D212,D415"]
docstring-convention = "google"

[tool.isort]
line_length = 99
profile = "black"

[tool.mypy]
ignore_missing_imports = true
explicit_package_bases = true
namespace_packages = true

[tool.pylint]
disable = "wrong-import-order"

[tool.pytest.ini_options]
minversion = "6.0"
log_cli_level = "INFO"

# Formatting tools configuration
[tool.black]
line-length = 99
target-version = ["py38"]

# Linting tools configuration
[tool.ruff]
line-length = 99
Expand Down
18 changes: 15 additions & 3 deletions src/charm.py
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
#!/usr/bin/env python3
# Copyright 2023 Mariyan Dimitrov

# Copyright 2023 Canonical Ltd.
# See LICENSE file for licensing details.
#

# Learn more at: https://juju.is/docs/sdk

"""Charm the service.
Expand All @@ -26,6 +27,11 @@ class IsCharmsTemplateCharm(ops.CharmBase):
"""Charm the service."""

def __init__(self, *args):
"""Construct.
Args:
args: Arguments passed to the CharmBase parent constructor.
"""
super().__init__(*args)
self.framework.observe(self.on.httpbin_pebble_ready, self._on_httpbin_pebble_ready)
self.framework.observe(self.on.config_changed, self._on_config_changed)
Expand All @@ -37,6 +43,9 @@ def _on_httpbin_pebble_ready(self, event: ops.PebbleReadyEvent):
environment configuration for your specific workload.
Learn more about interacting with Pebble at at https://juju.is/docs/sdk/pebble.
Args:
event: event triggering the handler.
"""
# Get a reference the container attribute on the PebbleReadyEvent
container = event.workload
Expand All @@ -55,6 +64,9 @@ def _on_config_changed(self, event: ops.ConfigChangedEvent):
this method.
Learn more about config at https://juju.is/docs/sdk/config
Args:
event: event triggering the handler.
"""
# Fetch the new config value
log_level = self.model.config["log-level"].lower()
Expand Down Expand Up @@ -100,4 +112,4 @@ def _pebble_layer(self):


if __name__ == "__main__": # pragma: nocover
ops.main(IsCharmsTemplateCharm)
ops.main.main(IsCharmsTemplateCharm)
13 changes: 13 additions & 0 deletions tests/conftest.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# Copyright 2023 Canonical Ltd.
# See LICENSE file for licensing details.

"""Fixtures for charm tests."""


def pytest_addoption(parser):
"""Parse additional pytest options.
Args:
parser: Pytest parser.
"""
parser.addoption("--charm-file", action="store")
2 changes: 2 additions & 0 deletions tests/integration/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# Copyright 2023 Canonical Ltd.
# See LICENSE file for licensing details.
22 changes: 13 additions & 9 deletions tests/integration/test_charm.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
#!/usr/bin/env python3
# Copyright 2023 Mariyan Dimitrov

# Copyright 2023 Canonical Ltd.
# See LICENSE file for licensing details.

"""Integration tests."""

import asyncio
import logging
from pathlib import Path
Expand All @@ -12,23 +15,24 @@

logger = logging.getLogger(__name__)

METADATA = yaml.safe_load(Path("./metadata.yaml").read_text())
METADATA = yaml.safe_load(Path("./metadata.yaml").read_text(encoding="utf-8"))
APP_NAME = METADATA["name"]


@pytest.mark.abort_on_fail
async def test_build_and_deploy(ops_test: OpsTest):
"""Build the charm-under-test and deploy it together with related charms.
async def test_build_and_deploy(ops_test: OpsTest, pytestconfig: pytest.Config):
"""Deploy the charm together with related charms.
Assert on the unit status before any relations/configurations take place.
"""
# Build and deploy charm from local source folder
charm = await ops_test.build_charm(".")
resources = {"httpbin-image": METADATA["resources"]["httpbin-image"]["upstream-source"]}

# Deploy the charm and wait for active/idle status
charm = pytestconfig.getoption("--charm-file")
resources = {"httpbin-image": METADATA["resources"]["httpbin-image"]["upstream-source"]}
assert ops_test.model
await asyncio.gather(
ops_test.model.deploy(charm, resources=resources, application_name=APP_NAME),
ops_test.model.deploy(
f"./{charm}", resources=resources, application_name=APP_NAME, series="jammy"
),
ops_test.model.wait_for_idle(
apps=[APP_NAME], status="active", raise_on_blocked=True, timeout=1000
),
Expand Down
2 changes: 2 additions & 0 deletions tests/unit/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# Copyright 2023 Canonical Ltd.
# See LICENSE file for licensing details.
11 changes: 9 additions & 2 deletions tests/unit/test_charm.py → tests/unit/test_base.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,24 @@
# Copyright 2023 Mariyan Dimitrov
# Copyright 2023 Canonical Ltd.
# See LICENSE file for licensing details.
#

# Learn more about testing at: https://juju.is/docs/sdk/testing

# pylint: disable=duplicate-code,missing-function-docstring
"""Unit tests."""

import unittest

import ops
import ops.testing

from charm import IsCharmsTemplateCharm


class TestCharm(unittest.TestCase):
"""Test class."""

def setUp(self):
"""Set up the testing environment."""
self.harness = ops.testing.Harness(IsCharmsTemplateCharm)
self.addCleanup(self.harness.cleanup)
self.harness.begin()
Expand Down
41 changes: 0 additions & 41 deletions tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ envlist = lint, unit, static, coverage-report
[vars]
src_path = {toxinidir}/src/
tst_path = {toxinidir}/tests/
plugins_path = {toxinidir}/indico_rock/plugins/
;lib_path = {toxinidir}/lib/charms/operator_name_with_underscores
all_path = {[vars]src_path} {[vars]tst_path}

Expand Down Expand Up @@ -70,46 +69,6 @@ commands =
mypy {[vars]all_path}
pylint {[vars]all_path}

[testenv:plugins]
description = Check plugins code against coding style standards
deps =
black
codespell
flake8<6.0.0
flake8-builtins
flake8-copyright<6.0.0
flake8-docstrings>=1.6.0
flake8-docstrings-complete>=1.0.3
flake8-test-docs>=1.0
indico==3.2
isort
mypy
pep8-naming
indico_rock/plugins/autocreate
indico_rock/plugins/anonymize
pydocstyle>=2.10
pylint
pyproject-flake8<6.0.0
pytest
pytest-asyncio
pytest-operator
requests
types-PyYAML
types-requests
-r{toxinidir}/requirements.txt
commands =
codespell {[vars]plugins_path} --skip {toxinidir}/.git --skip {toxinidir}/.tox \
--skip {toxinidir}/build --skip {toxinidir}/lib --skip {toxinidir}/venv \
--skip {toxinidir}/.mypy_cache --skip {toxinidir}/icon.svg \
--skip {toxinidir}/indico_rock/plugins/autocreate/.mypy_cache
--skip {toxinidir}/indico_rock/plugins/anonymize/.mypy_cache
# pflake8 wrapper supports config from pyproject.toml
pflake8 {[vars]plugins_path} --ignore=W503
isort --check-only --diff {[vars]plugins_path}
black --check --diff {[vars]plugins_path}
mypy {[vars]plugins_path}
pylint {[vars]plugins_path} --ignore-paths {[vars]plugins_path}/autocreate/build,{[vars]plugins_path}/anonymize/build

[testenv:unit]
description = Run unit tests
deps =
Expand Down

0 comments on commit 8e9f778

Please sign in to comment.