diff --git a/.github/workflows/codeql-analysis.yml b/.github/workflows/codeql-analysis.yml index 17bb7d38..68a79306 100644 --- a/.github/workflows/codeql-analysis.yml +++ b/.github/workflows/codeql-analysis.yml @@ -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 diff --git a/.github/workflows/dependabot_pr.yaml b/.github/workflows/dependabot_pr.yaml index 528785bd..17556b1c 100644 --- a/.github/workflows/dependabot_pr.yaml +++ b/.github/workflows/dependabot_pr.yaml @@ -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 diff --git a/.github/workflows/issues.yaml b/.github/workflows/issues.yaml index f38c29f8..c3568813 100644 --- a/.github/workflows/issues.yaml +++ b/.github/workflows/issues.yaml @@ -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 }} diff --git a/.github/workflows/main.yaml b/.github/workflows/main.yaml index 639ed271..fa53b0ca 100644 --- a/.github/workflows/main.yaml +++ b/.github/workflows/main.yaml @@ -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 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 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 unit-tests-with-coverage: - uses: canonical/sdcore-github-workflows/.github/workflows/unit-test.yaml@v0.0.1 + uses: canonical/sdcore-github-workflows/.github/workflows/unit-test.yaml@v1.0.0 + + build: + needs: + - lint-report + - static-analysis + - unit-tests-with-coverage + uses: canonical/sdcore-github-workflows/.github/workflows/build.yaml@v1.0.0 + secrets: inherit integration-test: - uses: canonical/sdcore-github-workflows/.github/workflows/integration-test-with-multus.yaml@v0.0.1 - with: - charm-file-name: "sdcore-upf-k8s_ubuntu-22.04-amd64.charm" + needs: + - build + uses: canonical/sdcore-github-workflows/.github/workflows/integration-test-with-multus.yaml@v1.0.0 publish-charm: name: Publish Charm @@ -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-upf-k8s_ubuntu-22.04-amd64.charm" track-name: 1.5 secrets: CHARMCRAFT_AUTH: ${{ secrets.CHARMCRAFT_AUTH }} @@ -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-upf-k8s_ubuntu-22.04-amd64.charm" track-name: 1.5 secrets: CHARMCRAFT_AUTH: ${{ secrets.CHARMCRAFT_AUTH }} @@ -81,7 +87,7 @@ jobs: - publish-charm - fiveg-n3-lib-needs-publishing if: ${{ github.ref_name == 'main' }} - uses: canonical/sdcore-github-workflows/.github/workflows/publish-lib.yaml@v0.0.1 + uses: canonical/sdcore-github-workflows/.github/workflows/publish-lib.yaml@v1.0.0 with: lib-name: "charms.sdcore_upf_k8s.v0.fiveg_n3" secrets: inherit @@ -105,7 +111,7 @@ jobs: - publish-charm - fiveg-n4-lib-needs-publishing if: ${{ github.ref_name == 'main' }} - uses: canonical/sdcore-github-workflows/.github/workflows/publish-lib.yaml@v0.0.1 + uses: canonical/sdcore-github-workflows/.github/workflows/publish-lib.yaml@v1.0.0 with: lib-name: "charms.sdcore_upf_k8s.v0.fiveg_n4" secrets: inherit diff --git a/.github/workflows/promote.yaml b/.github/workflows/promote.yaml index 6db6223e..d138b3fd 100644 --- a/.github/workflows/promote.yaml +++ b/.github/workflows/promote.yaml @@ -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 }} diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 1b0fd773..65cc0ba9 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -51,10 +51,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 diff --git a/tests/integration/conftest.py b/tests/integration/conftest.py new file mode 100644 index 00000000..f5543e38 --- /dev/null +++ b/tests/integration/conftest.py @@ -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}") diff --git a/tests/integration/test_integration.py b/tests/integration/test_integration.py index 35e55816..e50ef7bc 100644 --- a/tests/integration/test_integration.py +++ b/tests/integration/test_integration.py @@ -29,9 +29,10 @@ async def _deploy_grafana_agent(ops_test: OpsTest): @pytest.fixture(scope="module") -async def build_and_deploy(ops_test): - """Build the charm-under-test and deploy it.""" - charm = await ops_test.build_charm(".") +async def deploy(ops_test: OpsTest, request): + """Deploy required components.""" + assert ops_test.model + charm = Path(request.config.getoption("--charm_path")).resolve() resources = { "bessd-image": METADATA["resources"]["bessd-image"]["upstream-source"], "pfcp-agent-image": METADATA["resources"]["pfcp-agent-image"]["upstream-source"], @@ -46,10 +47,8 @@ async def build_and_deploy(ops_test): @pytest.mark.abort_on_fail -async def test_given_charm_is_built_when_deployed_then_status_is_active( - ops_test, - build_and_deploy, -): +async def test_given_charm_is_built_when_deployed_then_status_is_active(ops_test: OpsTest, deploy): + assert ops_test.model await ops_test.model.integrate( relation1=f"{APP_NAME}:logging", relation2=GRAFANA_AGENT_APP_NAME )