Skip to content

Commit

Permalink
Merge pull request #11 from canonical/test-changed-config-server
Browse files Browse the repository at this point in the history
[DPE-3085] Test changed config server
  • Loading branch information
delgod authored Dec 14, 2023
2 parents b73f862 + 8275d29 commit d25620d
Show file tree
Hide file tree
Showing 4 changed files with 78 additions and 79 deletions.
87 changes: 25 additions & 62 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -66,92 +66,55 @@ jobs:
permissions:
actions: write # Needed to manage GitHub Actions cache

gh-hosted-collect-integration-tests:
name: (GH hosted) Collect integration test groups
needs:
- lint
- unit-test
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Install tox & poetry
run: |
pipx install tox
pipx install poetry
- name: Select test stability level
id: select-test-stability
run: |
if [[ "${{ github.event_name }}" == "schedule" ]]
then
echo Running unstable and stable tests
echo "mark_expression=" >> "$GITHUB_OUTPUT"
else
echo Skipping unstable tests
echo "mark_expression=not unstable" >> "$GITHUB_OUTPUT"
fi
- name: Collect test groups
id: collect-groups
run: tox run -e integration -- tests/integration -m '${{ steps.select-test-stability.outputs.mark_expression }}' --collect-groups
outputs:
groups: ${{ steps.collect-groups.outputs.groups }}

gh-hosted-integration-test:
integration-test:
strategy:
fail-fast: false
matrix:
groups: ${{ fromJSON(needs.gh-hosted-collect-integration-tests.outputs.groups) }}
ubuntu-versions:
# Update whenever charmcraft.yaml is changed
- series: focal
bases-index: 0
- series: jammy
bases-index: 1
juju-snap-channel: ["3.1/stable"]
include:
- juju-snap-channel: "3.1/stable"
agent-version: "3.1.6"
libjuju-version: "3.2.2"
name: ${{ matrix.juju-snap-channel }} - (GH hosted) ${{ matrix.groups.job_name }} | ${{ matrix.ubuntu-versions.series }}
tox-environments:
- integration-charm
name: ${{ matrix.tox-environments }}
needs:
- lint
- unit-test
- lib-check
- build
- gh-hosted-collect-integration-tests
runs-on: ubuntu-latest
timeout-minutes: 120
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Install tox & poetry
run: |
pipx install tox
pipx install poetry
- name: Setup operator environment
# TODO: Replace with custom image on self-hosted runner
uses: charmed-kubernetes/actions-operator@main
with:
provider: lxd
bootstrap-options: "--agent-version ${{ matrix.agent-version }}"
juju-channel: ${{ matrix.juju-snap-channel }}
- name: Update python-libjuju version
if: ${{ matrix.libjuju-version == '2.9.44.1' }}
run: poetry add --lock --group integration juju@'${{ matrix.libjuju-version }}'
juju-channel: 3.1/stable
bootstrap-options: "--agent-version 3.1.6"
- name: Download packed charm(s)
uses: actions/download-artifact@v3
with:
name: ${{ needs.build.outputs.artifact-name }}
- name: Select test stability level
id: select-test-stability
- name: Free disk space
run: |
echo "Free disk space before cleanup"
df -T
# free space in the runner
sudo rm -rf /usr/share/dotnet
sudo rm -rf /opt/ghc
sudo rm -rf /usr/local/share/boost
sudo rm -rf "$AGENT_TOOLSDIRECTORY"
echo "Free disk space after cleanup"
df -T
- name: Select tests
id: select-tests
run: |
if [[ "${{ github.event_name }}" == "schedule" ]]
if [ "${{ github.event_name }}" == "schedule" ]
then
echo Running unstable and stable tests
echo "mark_expression=" >> "$GITHUB_OUTPUT"
echo "mark_expression=" >> $GITHUB_OUTPUT
else
echo Skipping unstable tests
echo "mark_expression=not unstable" >> "$GITHUB_OUTPUT"
echo "mark_expression=not unstable" >> $GITHUB_OUTPUT
fi
- name: Run integration tests
run: tox run -e integration -- "${{ matrix.groups.path_to_test_file }}" --group="${{ matrix.groups.group_number }}" -m '${{ steps.select-test-stability.outputs.mark_expression }}' --mysql-router-charm-series=${{ matrix.ubuntu-versions.series }} --mysql-router-charm-bases-index=${{ matrix.ubuntu-versions.bases-index }}
env:
LIBJUJU_VERSION_SPECIFIER: ${{ matrix.libjuju-version }}
run: tox run -e ${{ matrix.tox-environments }} -- -m '${{ steps.select-tests.outputs.mark_expression }}'
20 changes: 10 additions & 10 deletions poetry.lock

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

49 changes: 42 additions & 7 deletions tests/integration/test_charm.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
APPLICATION_APP_NAME = "application"
MONGOS_APP_NAME = "mongos"
CLUSTER_REL_NAME = "cluster"
MONGODB_CHARM_NAME = "mongodb"

CONFIG_SERVER_APP_NAME = "config-server"
SHARD_APP_NAME = "shard"
Expand All @@ -30,11 +31,23 @@ async def test_build_and_deploy(ops_test: OpsTest) -> None:
num_units=0,
application_name=MONGOS_APP_NAME,
)
await ops_test.model.deploy(
MONGODB_CHARM_NAME,
application_name=CONFIG_SERVER_APP_NAME,
channel="6/edge",
revision=142,
config={"role": "config-server"},
)
await ops_test.model.deploy(
MONGODB_CHARM_NAME,
application_name=SHARD_APP_NAME,
channel="6/edge",
revision=142,
config={"role": "shard"},
)

await ops_test.model.wait_for_idle(
apps=[
APPLICATION_APP_NAME,
],
apps=[APPLICATION_APP_NAME, SHARD_APP_NAME, CONFIG_SERVER_APP_NAME],
idle_period=10,
raise_on_blocked=False,
)
Expand All @@ -57,8 +70,6 @@ async def test_waits_for_config_server(ops_test: OpsTest) -> None:


@pytest.mark.abort_on_fail
# wait for 6/edge charm on mongodb to be updated before running this test on CI
@pytest.mark.skip()
async def test_mongos_starts_with_config_server(ops_test: OpsTest) -> None:
# prepare sharded cluster
await ops_test.model.wait_for_idle(
Expand Down Expand Up @@ -93,10 +104,34 @@ async def test_mongos_starts_with_config_server(ops_test: OpsTest) -> None:


@pytest.mark.abort_on_fail
# wait for 6/edge charm on mongodb to be updated before running this test on CI
@pytest.mark.skip()
async def test_mongos_has_user(ops_test: OpsTest) -> None:
# prepare sharded cluster
mongos_unit = ops_test.model.applications[MONGOS_APP_NAME].units[0]
mongos_running = await check_mongos(ops_test, mongos_unit, auth=True)
assert mongos_running, "Mongos is not currently running."


@pytest.mark.abort_on_fail
async def test_mongos_updates_config_db(ops_test: OpsTest) -> None:
# completely change the hosts that mongos was connected to
await ops_test.model.applications[CONFIG_SERVER_APP_NAME].add_units(count=1)
await ops_test.model.wait_for_idle(
apps=[CONFIG_SERVER_APP_NAME],
status="active",
timeout=1000,
)

# destroy the unit we were initially connected to
await ops_test.model.applications[CONFIG_SERVER_APP_NAME].destroy_units(
f"{CONFIG_SERVER_APP_NAME}/0"
)
await ops_test.model.wait_for_idle(
apps=[CONFIG_SERVER_APP_NAME],
status="active",
timeout=1000,
)

# prepare sharded cluster
mongos_unit = ops_test.model.applications[MONGOS_APP_NAME].units[0]
mongos_running = await check_mongos(ops_test, mongos_unit, auth=True)
assert mongos_running, "Mongos is not currently running."
1 change: 1 addition & 0 deletions tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -77,5 +77,6 @@ pass_env =
CI
CI_PACKED_CHARMS
commands =
poetry export --only main,charm-libs --output requirements.txt --without-hashes
poetry install --with integration
poetry run pytest -vv --tb native --log-cli-level=INFO -s {posargs} {[vars]tests_path}/integration/{env:TEST_FILE}

0 comments on commit d25620d

Please sign in to comment.