diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml new file mode 100644 index 00000000..c7c00b91 --- /dev/null +++ b/.github/workflows/ci.yaml @@ -0,0 +1,41 @@ +name: Testing + +on: + pull_request: + + +jobs: + lint: + name: Lint + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v2 + - name: Install dependencies + run: python3 -m pip install tox + - name: Run linters + run: tox -e lint + + unit-test: + name: Unit tests + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v2 + - name: Install dependencies + run: python -m pip install tox + - name: Run tests + run: tox -e unit + + integration-test-lxd: + name: Integration tests for (lxd) + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v2 + - name: Setup operator environment + uses: charmed-kubernetes/actions-operator@main + with: + provider: lxd + - name: Run integration tests + run: tox -e integration diff --git a/.github/workflows/release.yaml b/.github/workflows/release.yaml index 4a60d364..93e8a27a 100644 --- a/.github/workflows/release.yaml +++ b/.github/workflows/release.yaml @@ -20,48 +20,10 @@ jobs: credentials: "${{ secrets.CHARMHUB_TOKEN }}" # FIXME: current token will expire in 2023-07-04 github-token: "${{ secrets.GITHUB_TOKEN }}" - lint: - name: Lint - runs-on: ubuntu-latest - steps: - - name: Checkout - uses: actions/checkout@v2 - - name: Install dependencies - run: python3 -m pip install tox - - name: Run linters - run: tox -e lint - - unit-test: - name: Unit tests - runs-on: ubuntu-latest - steps: - - name: Checkout - uses: actions/checkout@v2 - - name: Install dependencies - run: python -m pip install tox - - name: Run tests - run: tox -e unit - - integration-test-lxd: - name: Integration tests for (lxd) - runs-on: ubuntu-latest - steps: - - name: Checkout - uses: actions/checkout@v2 - - name: Setup operator environment - uses: charmed-kubernetes/actions-operator@main - with: - provider: lxd - - name: Run integration tests - run: tox -e integration - release-to-charmhub: name: Release to CharmHub needs: - lib-check - - lint - - unit-test - - integration-test-lxd runs-on: ubuntu-latest steps: - name: Checkout diff --git a/src/charm.py b/src/charm.py index da2e55eb..411438d7 100755 --- a/src/charm.py +++ b/src/charm.py @@ -10,7 +10,6 @@ import subprocess from charms.kafka.v0.kafka_snap import KafkaSnap -from kafka_provides import KafkaProvider from ops.charm import CharmBase, RelationEvent, RelationJoinedEvent from ops.framework import EventBase from ops.main import main @@ -24,6 +23,7 @@ from connection_check import broker_active, zookeeper_connected from kafka_config import KafkaConfig +from kafka_provider import KafkaProvider logger = logging.getLogger(__name__) diff --git a/tests/integration/app-charm/src/charm.py b/tests/integration/app-charm/src/charm.py index c6235cd7..a30759a2 100755 --- a/tests/integration/app-charm/src/charm.py +++ b/tests/integration/app-charm/src/charm.py @@ -42,11 +42,7 @@ def _on_start(self, _) -> None: self.unit.status = ActiveStatus() def _set_data(self, _) -> None: - if not self.unit.is_leader(): - return - - # reasonable confidence there won't be conflicting chroots - self.relation.data[self.app].update({"password": "thisisatestpassword"}) + return def _log(self, event: RelationEvent): return diff --git a/tests/integration/helpers.py b/tests/integration/helpers.py index efe5b67b..620ed344 100644 --- a/tests/integration/helpers.py +++ b/tests/integration/helpers.py @@ -44,7 +44,7 @@ def get_zookeeper_connection(unit_name: str, model_full_name: str) -> Tuple[List for info in relations_info: if info["endpoint"] == "cluster": for key in info["application-data"].keys(): - if re.match(r"(relation\-[/d]+)", key): + if re.match(r"(relation\-[\d]+)", key): usernames.append(key) if info["endpoint"] == "zookeeper": zookeeper_uri = info["application-data"]["uris"] diff --git a/tests/integration/test_charm.py b/tests/integration/test_charm.py index 68460575..161341e4 100644 --- a/tests/integration/test_charm.py +++ b/tests/integration/test_charm.py @@ -16,9 +16,9 @@ async def test_build_and_deploy(ops_test: OpsTest): kafka_charm = await ops_test.build_charm(".") await asyncio.gather( ops_test.model.deploy( - "zookeeper", channel="edge", application_name="zookeeper", num_units=3 + "zookeeper", channel="edge", application_name="zookeeper", num_units=1 ), - ops_test.model.deploy(kafka_charm, application_name="kafka", num_units=3), + ops_test.model.deploy(kafka_charm, application_name="kafka", num_units=1), ) await ops_test.model.wait_for_idle(apps=["kafka", "zookeeper"]) assert ops_test.model.applications["kafka"].status == "waiting" diff --git a/tests/integration/test_kafka_provider.py b/tests/integration/test_kafka_provider.py index 15380409..9c93aae8 100644 --- a/tests/integration/test_kafka_provider.py +++ b/tests/integration/test_kafka_provider.py @@ -20,7 +20,7 @@ @pytest.fixture(scope="module") def usernames(): - return {} + return set() @pytest.mark.abort_on_fail @@ -30,9 +30,9 @@ async def test_deploy_charms_relate_active(ops_test: OpsTest, usernames): await asyncio.gather( ops_test.model.deploy( - "zookeeper", channel="edge", application_name="zookeeper", num_units=3 + "zookeeper", channel="edge", application_name="zookeeper", num_units=1 ), - ops_test.model.deploy(zk_charm, application_name=APP_NAME, num_units=3), + ops_test.model.deploy(zk_charm, application_name=APP_NAME, num_units=1), ops_test.model.deploy(app_charm, application_name=DUMMY_NAME_1, num_units=1), ) await ops_test.model.wait_for_idle(apps=[APP_NAME, DUMMY_NAME_1, ZK]) @@ -47,7 +47,7 @@ async def test_deploy_charms_relate_active(ops_test: OpsTest, usernames): returned_usernames, zookeeper_uri = get_zookeeper_connection( unit_name="kafka/0", model_full_name=ops_test.model_full_name ) - usernames.add(returned_usernames) + usernames.update(returned_usernames) for username in usernames: check_user( @@ -71,7 +71,7 @@ async def test_deploy_multiple_charms_relate_active(ops_test: OpsTest, usernames returned_usernames, zookeeper_uri = get_zookeeper_connection( unit_name="kafka/0", model_full_name=ops_test.model_full_name ) - usernames.add(returned_usernames) + usernames.update(returned_usernames) for username in usernames: check_user( @@ -87,7 +87,7 @@ async def test_remove_application_removes_user(ops_test: OpsTest, usernames): await ops_test.model.wait_for_idle(apps=[APP_NAME]) assert ops_test.model.applications[APP_NAME].status == "active" - usernames, zookeeper_uri = get_zookeeper_connection( + _, zookeeper_uri = get_zookeeper_connection( unit_name="kafka/0", model_full_name=ops_test.model_full_name ) diff --git a/tox.ini b/tox.ini index 85ae6975..4ce452f1 100644 --- a/tox.ini +++ b/tox.ini @@ -29,9 +29,10 @@ description = Short refresh script for charm-dev commands = /bin/bash -ec "juju destroy-model {[vars]application} --force --destroy-storage --no-wait" /bin/bash -ec "juju add-model {[vars]application}" - /bin/bash -ec "juju deploy zookeeper --channel latest/edge -n 3 --revision 66" + /bin/bash -ec "juju deploy zookeeper --channel edge -n 3" /bin/bash -ec "charmcraft pack" /bin/bash -ec "juju deploy ./*.charm -n 3" + /bin/bash -ec "juju relate kafka zookeeper" [testenv:fmt] description = Apply coding style standards to code