Skip to content

Commit

Permalink
[MISC] Enable arm64, tweak renovate and enable allure (#196)
Browse files Browse the repository at this point in the history
* Enable arm64, tweak renovate and enable allure

* Add codecov

* Ignore logging coverage

* Unit tests
  • Loading branch information
dragomirp authored Apr 3, 2024
1 parent 0791812 commit 26e9e87
Show file tree
Hide file tree
Showing 10 changed files with 143 additions and 21 deletions.
10 changes: 10 additions & 0 deletions .github/codecov.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
github_checks:
annotations: false
coverage:
status:
project:
default:
target: 70%
patch:
default:
target: 33%
58 changes: 55 additions & 3 deletions .github/renovate.json5
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"$schema": "https://docs.renovatebot.com/renovate-schema.json",
"extends": ["github>canonical/data-platform//renovate_presets/charm.json5"],
"reviewers": ["dragomirp", "marceloneppel", "taurus-forever"],
"reviewers": ["dragomirp", "lucasgameiroborges", "marceloneppel", "taurus-forever"],
"packageRules": [
// Later rules override earlier rules
{
Expand All @@ -10,12 +10,64 @@
}, {
"matchPackageNames": ["python"],
"allowedVersions": "<3.11"
},
{
"matchDepNames": ["Juju 2"],
"matchPackageNames": ["juju/juju"],
"allowedVersions": "<3.0.0",
"extractVersion": "^v(?<version>.*)$",
"groupName": "Juju 2"
},
{
"matchDepNames": ["Juju 3"],
"matchPackageNames": ["juju/juju"],
"allowedVersions": "<3.2.0",
"extractVersion": "^v(?<version>.*)$",
"groupName": "Juju 3"
},
{
"matchDepNames": ["libjuju 2"],
"matchPackageNames": ["juju"],
"matchManagers": ["regex"],
"matchDatasources": ["pypi"],
"versioning": "loose",
"allowedVersions": "<3",
"groupName": "Juju 2"
}
],
"regexManagers": [
{
"fileMatch": ["(^|/)([\\w-]*)charmcraft\\.ya?ml$"],
"matchStrings": ["- (?<depName>.*?)(?:\\[.*?\\])?==(?<currentValue>.*?) +# renovate"],
"customType": "regex",
"fileMatch": ["^(workflow-templates|\\.github/workflows)/[^/]+\\.ya?ml$"],
"matchStrings": [
"(- agent: )(?<currentValue>.*?) +# renovate: latest juju 2"
],
"depNameTemplate": "Juju 2",
"packageNameTemplate": "juju/juju",
"datasourceTemplate": "github-releases",
"versioningTemplate": "loose",
"extractVersionTemplate": "Juju release"
},
{
"customType": "regex",
"fileMatch": ["^(workflow-templates|\\.github/workflows)/[^/]+\\.ya?ml$"],
"matchStrings": [
"(- agent: )(?<currentValue>.*?) +# renovate: latest juju 3"
],
"depNameTemplate": "Juju 3",
"packageNameTemplate": "juju/juju",
"datasourceTemplate": "github-releases",
"versioningTemplate": "loose",
"extractVersionTemplate": "Juju release"
},
{
"customType": "regex",
"fileMatch": ["^(workflow-templates|\\.github/workflows)/[^/]+\\.ya?ml$"],
"matchStrings": [
"(libjuju: )==(?<currentValue>.*?) +# renovate: latest libjuju 2"
],
"depNameTemplate": "libjuju 2",
"packageNameTemplate": "juju",
"datasourceTemplate": "pypi",
"versioningTemplate": "loose"
}
Expand Down
10 changes: 7 additions & 3 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ jobs:
pipx install poetry
- name: Run tests
run: tox run -e unit
- name: Upload Coverage to Codecov
uses: codecov/codecov-action@v3

build:
name: Build charm
Expand All @@ -50,9 +52,11 @@ jobs:
fail-fast: false
matrix:
juju:
- agent: 2.9.46
libjuju: ^2
- agent: 3.1.7
- agent: 2.9.47 # renovate: latest juju 2
libjuju: ==2.9.46.1 # renovate: latest libjuju 2
allure: false
- agent: 3.1.7 # renovate: latest juju 3
allure: true
name: Integration test charm | ${{ matrix.juju.agent }}
needs:
- lint
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ build/
*.charm
.tox/
.coverage
coverage.xml
__pycache__/
*.py[cod]
*.ini
Expand Down
24 changes: 12 additions & 12 deletions charmcraft.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,18 @@

type: charm
bases:
- build-on:
- name: "ubuntu"
channel: "20.04"
run-on:
- name: "ubuntu"
channel: "20.04"
- build-on:
- name: "ubuntu"
channel: "22.04"
run-on:
- name: "ubuntu"
channel: "22.04"
- name: ubuntu
channel: "20.04"
architectures: [amd64]
- name: ubuntu
channel: "20.04"
architectures: [arm64]
- name: ubuntu
channel: "22.04"
architectures: [amd64]
- name: ubuntu
channel: "22.04"
architectures: [arm64]

parts:
charm:
Expand Down
32 changes: 31 additions & 1 deletion poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 6 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -70,10 +70,12 @@ pytest-github-secrets = {git = "https://github.com/canonical/data-platform-workf
pytest-operator = "^0.34.0"
pytest-operator-cache = {git = "https://github.com/canonical/data-platform-workflows", tag = "v13.0.0", subdirectory = "python/pytest_plugins/pytest_operator_cache"}
pytest-operator-groups = {git = "https://github.com/canonical/data-platform-workflows", tag = "v13.0.0", subdirectory = "python/pytest_plugins/pytest_operator_groups"}
juju = "^3.3.0.0"
# renovate caret doesn't work: https://github.com/renovatebot/renovate/issues/26940
juju = "<=3.4.0.0"
tenacity = "*"
mailmanclient = "^3.3.5"
psycopg2-binary = "^2.9.9"
allure-pytest = "^2.13.5"

[build-system]
requires = ["poetry-core>=1.0.0"]
Expand All @@ -85,6 +87,9 @@ branch = true

[tool.coverage.report]
show_missing = true
exclude_lines = [
"logger\\.debug"
]

[tool.pytest.ini_options]
minversion = "6.0"
Expand Down
2 changes: 1 addition & 1 deletion tests/integration/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ async def pgb_charm_focal(ops_test: OpsTest):
@pytest.fixture(scope="module")
async def pgb_charm_jammy(ops_test: OpsTest):
"""Build the pgbouncer charm."""
return await ops_test.build_charm(".", bases_index=1)
return await ops_test.build_charm(".", bases_index=2)


@pytest.fixture()
Expand Down
19 changes: 19 additions & 0 deletions tests/unit/relations/test_db.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import unittest
from unittest.mock import Mock, PropertyMock, patch

from ops.model import Unit
from ops.testing import Harness

from charm import PgBouncerCharm
Expand Down Expand Up @@ -276,3 +277,21 @@ def test_on_relation_broken(

_delete_user.assert_called_once_with(username)
_set_rel_dbs.assert_called_once_with({})

def test_get_allowed_subnets(self):
rel = self.charm.model.get_relation("db", self.db_rel_id)
for key in rel.data.keys():
if isinstance(key, Unit):
rel.data[key]["egress-subnets"] = "10.0.0.10,10.0.0.11"

assert "10.0.0.10,10.0.0.11" == self.charm.legacy_db_relation.get_allowed_subnets(rel)

def test_get_allowed_units(self):
rel = self.charm.model.get_relation("db", self.db_rel_id)

assert "client_app/0" == self.charm.legacy_db_relation.get_allowed_units(rel)

def test_get_external_app(self):
rel = self.charm.model.get_relation("db", self.db_rel_id)

assert "client_app" == self.charm.legacy_db_relation.get_external_app(rel).name
1 change: 1 addition & 0 deletions tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ commands =
poetry run coverage run --source={[vars]src_path} \
-m pytest -v --tb native -s {posargs} {[vars]tests_path}/unit
poetry run coverage report
poetry run coverage xml

[testenv:integration]
description = Run integration tests
Expand Down

0 comments on commit 26e9e87

Please sign in to comment.