Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: update the smoke test series/bases #1318

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,7 @@ venv
# Smoke test artifacts
*.tar.gz
*.charm
test/charms/test_smoke/.charmcraft_output_packages.txt
test/charms/test_smoke/requirements.txt
test/charms/test_smoke/charmcraft.yaml
juju-crashdump*.tar.xz
22 changes: 0 additions & 22 deletions test/charms/test_smoke/charmcraft.yaml

This file was deleted.

19 changes: 8 additions & 11 deletions test/charms/test_smoke/src/charm.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,25 +23,22 @@
"""

import logging
import typing

from ops.charm import CharmBase, EventBase
from ops.main import main
from ops.model import ActiveStatus
import ops

logger = logging.getLogger(__name__)


class SmokeCharm(CharmBase):
class SmokeCharm(ops.CharmBase):
"""Charm the service."""

def __init__(self, *args: typing.Any):
super().__init__(*args)
self.framework.observe(self.on.install, self._on_install)
def __init__(self, framework: ops.Framework):
super().__init__(framework)
framework.observe(self.on.install, self._on_install)

def _on_install(self, event: EventBase):
self.unit.status = ActiveStatus()
def _on_install(self, event: ops.EventBase):
self.unit.status = ops.ActiveStatus()


if __name__ == '__main__':
main(SmokeCharm)
ops.main(SmokeCharm)
52 changes: 44 additions & 8 deletions test/smoke/test_smoke.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,20 +16,56 @@

import logging

import pytest
from pytest_operator.plugin import OpsTest

logger = logging.getLogger(__name__)


async def test_smoke(ops_test: OpsTest):
# Verify that we can deploy charms from supported series.
CHARMCRAFT2_YAML = """
type: "charm"
bases:
- build-on:
- name: "ubuntu"
channel: "{base}"
run-on:
- name: "ubuntu"
channel: "{base}"
"""

# Build the charm. (We just build it for focal -- it *should* work to deploy it on
# older versions of Juju.)
CHARMCRAFT3_YAML = """
type: "charm"
base: ubuntu@{base}
platforms:
amd64:
parts:
charm:
plugin: charm
source: .
"""


@pytest.mark.parametrize(
'base,charmcraft_version,name',
(
('20.04', 2, 'focal'),
('22.04', 2, 'jammy'),
('24.04', 3, 'noble'),
),
)
async def test_smoke(ops_test: OpsTest, base: str, charmcraft_version: int, name: str):
"""Verify that we can build and deploy charms from supported bases."""
charmcraft_yaml = {
2: CHARMCRAFT2_YAML,
3: CHARMCRAFT3_YAML,
}[charmcraft_version].format(base=base)
with open('./test/charms/test_smoke/charmcraft.yaml', 'w') as outf:
outf.write(charmcraft_yaml)
charm = await ops_test.build_charm('./test/charms/test_smoke/')

for series in ['focal', 'bionic', 'xenial']:
app = await ops_test.model.deploy(charm, series=series, application_name=f'{series}-smoke')
await ops_test.model.wait_for_idle(timeout=600)
app = await ops_test.model.deploy(
charm, base=f'ubuntu@{base}', application_name=f'{name}-smoke'
)
await ops_test.model.wait_for_idle(timeout=600)

assert app.status == 'active', f"Series {series} failed with '{app.status}' status"
assert app.status == 'active', f"Base ubuntu@{base} failed with '{app.status}' status"
4 changes: 2 additions & 2 deletions tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ commands =

[testenv:smoke]
description = Run a smoke test against a Juju controller.
whitelist_externals = juju
allowlist_externals = juju
charmcraft
bash
deps =
Expand All @@ -108,7 +108,7 @@ deps =
pytest-operator~=0.23
commands =
# Build a source tarball for ops, and drop it into the root directory of the smoke test charm.
bash -c 'rm -vf ./test/charms/test_smoke/*.tar.gz # Cleanup old builds'
bash -c 'rm -vf ./test/charms/test_smoke/*.tar.gz'
python -m build --sdist --outdir={toxinidir}/test/charms/test_smoke/
# Inject the tarball into the smoke test charm's requirements.
bash -c 'echo "./$(ls -1 ./test/charms/test_smoke/ | grep tar.gz)" > ./test/charms/test_smoke/requirements.txt'
Expand Down
Loading