Skip to content

Commit

Permalink
chore: Building charm in independent step (#136)
Browse files Browse the repository at this point in the history
  • Loading branch information
Gmerold authored Apr 26, 2024
1 parent 63a5790 commit 614a544
Show file tree
Hide file tree
Showing 8 changed files with 78 additions and 30 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/codeql-analysis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@ on:
jobs:
codeql:
name: CodeQL Analysis
uses: canonical/sdcore-github-workflows/.github/workflows/codeql-analysis.yml@v0.0.1
uses: canonical/sdcore-github-workflows/.github/workflows/codeql-analysis.yml@v1.0.0
2 changes: 1 addition & 1 deletion .github/workflows/dependabot_pr.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,4 @@ permissions:

jobs:
auto-merge:
uses: canonical/sdcore-github-workflows/.github/workflows/dependabot_pr.yaml@v0.0.1
uses: canonical/sdcore-github-workflows/.github/workflows/dependabot_pr.yaml@v1.0.0
2 changes: 1 addition & 1 deletion .github/workflows/issues.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@ on:
jobs:
update:
name: Update Issue
uses: canonical/sdcore-github-workflows/.github/workflows/issues.yaml@v0.0.1
uses: canonical/sdcore-github-workflows/.github/workflows/issues.yaml@v1.0.0
secrets:
JIRA_URL: ${{ secrets.JIRA_URL }}
30 changes: 18 additions & 12 deletions .github/workflows/main.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,26 +10,34 @@ on:

jobs:
check-libraries:
uses: canonical/sdcore-github-workflows/.github/workflows/check-libraries.yaml@v0.0.1
uses: canonical/sdcore-github-workflows/.github/workflows/check-libraries.yaml@v1.0.0
secrets:
CHARMCRAFT_AUTH: ${{ secrets.CHARMCRAFT_AUTH }}

lint-report:
uses: canonical/sdcore-github-workflows/.github/workflows/lint-report.yaml@v0.0.1
uses: canonical/sdcore-github-workflows/.github/workflows/lint-report.yaml@v1.0.0

terraform-check:
uses: canonical/sdcore-github-workflows/.github/workflows/terraform.yaml@v0.0.1
uses: canonical/sdcore-github-workflows/.github/workflows/terraform.yaml@v1.0.0

static-analysis:
uses: canonical/sdcore-github-workflows/.github/workflows/static-analysis.yaml@v0.0.1
uses: canonical/sdcore-github-workflows/.github/workflows/static-analysis.yaml@v1.0.0

unit-tests-with-coverage:
uses: canonical/sdcore-github-workflows/.github/workflows/[email protected]
uses: canonical/sdcore-github-workflows/.github/workflows/[email protected]

build:
needs:
- lint-report
- static-analysis
- unit-tests-with-coverage
uses: canonical/sdcore-github-workflows/.github/workflows/[email protected]
secrets: inherit

integration-test:
uses: canonical/sdcore-github-workflows/.github/workflows/[email protected]
with:
charm-file-name: "sdcore-udr-k8s_ubuntu-22.04-amd64.charm"
needs:
- build
uses: canonical/sdcore-github-workflows/.github/workflows/[email protected]

publish-charm:
name: Publish Charm
Expand All @@ -39,9 +47,8 @@ jobs:
- unit-tests-with-coverage
- integration-test
if: ${{ github.ref_name == 'main' }}
uses: canonical/sdcore-github-workflows/.github/workflows/publish-charm.yaml@v0.0.1
uses: canonical/sdcore-github-workflows/.github/workflows/publish-charm.yaml@v1.0.0
with:
charm-file-name: "sdcore-udr-k8s_ubuntu-22.04-amd64.charm"
track-name: 1.5
secrets:
CHARMCRAFT_AUTH: ${{ secrets.CHARMCRAFT_AUTH }}
Expand All @@ -54,10 +61,9 @@ jobs:
- unit-tests-with-coverage
- integration-test
if: ${{ (github.ref_name != 'main') && (github.event_name == 'push') }}
uses: canonical/sdcore-github-workflows/.github/workflows/publish-charm.yaml@v0.0.1
uses: canonical/sdcore-github-workflows/.github/workflows/publish-charm.yaml@v1.0.0
with:
branch-name: ${{ github.ref_name }}
charm-file-name: "sdcore-udr-k8s_ubuntu-22.04-amd64.charm"
track-name: 1.5
secrets:
CHARMCRAFT_AUTH: ${{ secrets.CHARMCRAFT_AUTH }}
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/promote.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ on:
jobs:
promote:
name: Promote Charm
uses: canonical/sdcore-github-workflows/.github/workflows/promote.yaml@v0.0.1
uses: canonical/sdcore-github-workflows/.github/workflows/promote.yaml@v1.0.0
with:
promotion: ${{ github.event.inputs.promotion }}
track-name: ${{ github.event.inputs.track-name }}
Expand Down
12 changes: 8 additions & 4 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,14 @@ There are some pre-configured environments
that can be used for linting and formatting code when you're preparing contributions to the charm:

```shell
tox -e lint # code style
tox -e static # static analysis
tox -e unit # unit tests
tox -e integration # integration tests
tox -e lint # code style
tox -e static # static analysis
tox -e unit # unit tests
tox -e integration -- --charm_path=PATH_TO_BUILD_CHARM # integration tests
```

```note
Integration tests require the charm to be built with `charmcraft pack` first.
```

## Build
Expand Down
38 changes: 38 additions & 0 deletions tests/integration/conftest.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
#!/usr/bin/env python3
# Copyright 2024 Canonical Ltd.
# See LICENSE file for licensing details.

import os

import pytest


def pytest_addoption(parser: pytest.Parser) -> None:
"""Add options to the pytest command line.
This is a pytest hook that is called when the pytest command line is being parsed.
Args:
parser: The pytest command line parser.
"""
parser.addoption(
"--charm_path",
action="store",
default=None,
help="Path to the charm under test"
)


def pytest_configure(config: pytest.Config) -> None:
"""Validate the options provided by the user.
This is a pytest hook that is called after command line options have been parsed.
Args:
config: The pytest configuration object.
"""
charm_path = str(config.getoption("--charm_path"))
if not charm_path:
pytest.exit("The --charm_path option is required. Tests aborted.")
if not os.path.exists(charm_path):
pytest.exit(f"The path specified for the charm under test does not exist: {charm_path}")
20 changes: 10 additions & 10 deletions tests/integration/test_integration.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,8 @@ async def setup(self, ops_test: OpsTest):

@pytest.fixture(scope="module")
@pytest.mark.abort_on_fail
async def build_and_deploy_charm(self, ops_test: OpsTest):
charm = await ops_test.build_charm(".")
async def deploy(self, ops_test: OpsTest, request):
charm = Path(request.config.getoption("--charm_path")).resolve()
resources = {"udr-image": METADATA["resources"]["udr-image"]["upstream-source"]}
assert ops_test.model
await ops_test.model.deploy(
Expand Down Expand Up @@ -97,13 +97,13 @@ async def _deploy_sdcore_nrf_operator(ops_test: OpsTest):
)

@pytest.mark.abort_on_fail
async def test_wait_for_blocked_status(self, ops_test: OpsTest, setup, build_and_deploy_charm):
async def test_wait_for_blocked_status(self, ops_test: OpsTest, setup, deploy):
assert ops_test.model
await ops_test.model.wait_for_idle(apps=[APPLICATION_NAME], status="blocked", timeout=1000)

@pytest.mark.abort_on_fail
async def test_relate_and_wait_for_idle(
self, ops_test: OpsTest, setup, build_and_deploy_charm
self, ops_test: OpsTest, setup, deploy
):
assert ops_test.model
await ops_test.model.integrate(
Expand All @@ -128,15 +128,15 @@ async def test_relate_and_wait_for_idle(

@pytest.mark.abort_on_fail
async def test_remove_nrf_and_wait_for_blocked_status(
self, ops_test: OpsTest, setup, build_and_deploy_charm
self, ops_test: OpsTest, setup, deploy
):
assert ops_test.model
await ops_test.model.remove_application(NRF_APPLICATION_NAME, block_until_done=True)
await ops_test.model.wait_for_idle(apps=[APPLICATION_NAME], status="blocked", timeout=60)

@pytest.mark.abort_on_fail
async def test_restore_nrf_and_wait_for_active_status(
self, ops_test: OpsTest, setup, build_and_deploy_charm
self, ops_test: OpsTest, setup, deploy
):
assert ops_test.model
await self._deploy_sdcore_nrf_operator(ops_test)
Expand All @@ -151,15 +151,15 @@ async def test_restore_nrf_and_wait_for_active_status(

@pytest.mark.abort_on_fail
async def test_remove_tls_and_wait_for_blocked_status(
self, ops_test: OpsTest, build_and_deploy_charm
self, ops_test: OpsTest, deploy
):
assert ops_test.model
await ops_test.model.remove_application(TLS_PROVIDER_CHARM_NAME, block_until_done=True)
await ops_test.model.wait_for_idle(apps=[APPLICATION_NAME], status="blocked", timeout=60)

@pytest.mark.abort_on_fail
async def test_restore_tls_and_wait_for_active_status(
self, ops_test: OpsTest, build_and_deploy_charm
self, ops_test: OpsTest, deploy
):
assert ops_test.model
await self._deploy_tls_provider(ops_test)
Expand All @@ -173,7 +173,7 @@ async def test_restore_tls_and_wait_for_active_status(
)
@pytest.mark.abort_on_fail
async def test_remove_database_and_wait_for_blocked_status(
self, ops_test: OpsTest, build_and_deploy_charm
self, ops_test: OpsTest, deploy
):
assert ops_test.model
await ops_test.model.remove_application(DB_APPLICATION_NAME, block_until_done=True)
Expand All @@ -184,7 +184,7 @@ async def test_remove_database_and_wait_for_blocked_status(
)
@pytest.mark.abort_on_fail
async def test_restore_database_and_wait_for_active_status(
self, ops_test: OpsTest, build_and_deploy_charm
self, ops_test: OpsTest, deploy
):
assert ops_test.model
await self._deploy_mongodb(ops_test)
Expand Down

0 comments on commit 614a544

Please sign in to comment.