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
Added a very basic smoke test. Run it with tox -e smoke
#800
Changes from 3 commits
614f6c6
10b1e2e
e555ab1
2862904
0e28783
c944bc2
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
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 |
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. | ||
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" |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
# Copyright 2022 Penelope Valentine Gale | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should the copyright not be Canonical? |
||
# 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: {} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. IIRC we can remove the file completely if there's no config |
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. | ||
|
||
Comment on lines
+1
to
+3
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Looks like maybe fixing this copyright line got missed before the merge? |
||
# 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 |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
#!/usr/bin/env python3 | ||
# | ||
# 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. | ||
|
||
"""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) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
# 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 pytest_operator.plugin import OpsTest | ||
|
||
logger = logging.getLogger(__name__) | ||
|
||
|
||
CURRENT_CHANNEL = '20.04' # Focal | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. where is this used? |
||
|
||
|
||
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']: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. use There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I started in on this, and it ended up adding a lot of complexity. The build needs to get moved into a separate routine, and then we need a data structure to track our charm artifact. None of that is difficult to write, but it didn't feel worthwhile to do so until this test gets more complex. |
||
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) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you include the QA steps info from the PR description here - the stuff about how to make sure your environment is prepared to run the tests. Also probably worth noting that same info as a comment inside tox.ini.