Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added a very basic smoke test. Run it with
tox -e smoke
This requires a development box with an active juju controller, and charmcraft installed. The smoke test will build the "smoke" charm in test/charms/test_smoke and try to deploy xenial, bionic and focal versions of the charm. There are a few wonky things about this, including how we inject the current ops package, and the fact that we test with just the focal version of the charm. Future versions of this smoke test should clear those wonky bits up, as well as add automation.
- Loading branch information
Showing
8 changed files
with
155 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,3 +11,8 @@ venv | |
.vscode | ||
.coverage | ||
/.tox | ||
|
||
# Smoke test artifacts | ||
*.tar.gz | ||
*.charm | ||
test/charms/test_smoke/requirements.txt |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
# smoke | ||
|
||
## Description | ||
|
||
A simple test charm for running smoke tests. | ||
|
||
## Usage | ||
|
||
Run `tox -e smoke` in the root directory of this repository to build and deploy this charm. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
# Learn more about charmcraft.yaml configuration at: | ||
# https://juju.is/docs/sdk/charmcraft-config | ||
type: "charm" | ||
bases: | ||
- build-on: | ||
- name: "ubuntu" | ||
channel: "20.04" | ||
run-on: | ||
- name: "ubuntu" | ||
channel: "20.04" | ||
- build-on: | ||
- name: "ubuntu" | ||
channel: "18.04" | ||
run-on: | ||
- name: "ubuntu" | ||
channel: "18.04" | ||
- build-on: | ||
- name: "ubuntu" | ||
channel: "16.04" | ||
run-on: | ||
- name: "ubuntu" | ||
channel: "16.04" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
# Copyright 2022 Penelope Valentine Gale | ||
# See LICENSE file for licensing details. | ||
# | ||
# TEMPLATE-TODO: change this example to suit your needs. | ||
# If you don't need a config, you can remove the file entirely. | ||
# It ties in to the example _on_config_changed handler in src/charm.py | ||
# | ||
# Learn more about config at: https://juju.is/docs/sdk/config | ||
|
||
options: {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
# Copyright 2022 Penelope Valentine Gale | ||
# See LICENSE file for licensing details. | ||
|
||
# For a complete list of supported options, see: | ||
# https://juju.is/docs/sdk/metadata-reference | ||
name: smoke | ||
display-name: | | ||
smoke | ||
description: | | ||
smoke test charm | ||
summary: | | ||
basic minimal charm for running smoke tests |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
#!/usr/bin/env python3 | ||
# Copyright 2022 Penelope Valentine Gale | ||
# See LICENSE file for licensing details. | ||
# | ||
# Learn more at: https://juju.is/docs/sdk | ||
|
||
"""Charm the service. | ||
Refer to the following post for a quick-start guide that will help you | ||
develop a new k8s charm using the Operator Framework: | ||
https://discourse.charmhub.io/t/4208 | ||
""" | ||
|
||
import logging | ||
|
||
from ops.charm import CharmBase | ||
from ops.main import main | ||
from ops.model import ActiveStatus | ||
|
||
logger = logging.getLogger(__name__) | ||
|
||
|
||
class SmokeCharm(CharmBase): | ||
"""Charm the service.""" | ||
|
||
def __init__(self, *args): | ||
super().__init__(*args) | ||
self.framework.observe(self.on.install, self._on_install) | ||
|
||
def _on_install(self, event): | ||
self.unit.status = ActiveStatus() | ||
|
||
if __name__ == "__main__": | ||
main(SmokeCharm) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
# Copyright 2022 Canonical Ltd. | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
# | ||
# Learn more about testing at: https://juju.is/docs/sdk/testing | ||
|
||
import logging | ||
from pathlib import Path | ||
|
||
from pytest_operator.plugin import OpsTest | ||
|
||
|
||
logger = logging.getLogger(__name__) | ||
|
||
|
||
CURRENT_CHANNEL = '20.04' # Focal | ||
|
||
|
||
async def test_smoke(ops_test: OpsTest): | ||
# Verify that we can deploy charms from supported series. | ||
|
||
# Build the charm. (We just build it for focal -- it *should* work to deploy it on | ||
# older versions of Juju.) | ||
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="{}-smoke".format(series)) | ||
await ops_test.model.wait_for_idle(timeout=600) | ||
|
||
assert app.status == "active", "Series {} failed with '{}' status".format( | ||
series, app.status) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters