Add tox tests for osm charms in devops
Change-Id: Ibbf1154e514bf8a91ed6d19b6bbf5fce0079da0c
Signed-off-by: David Garcia <david.garcia@canonical.com>
diff --git a/Dockerfile b/Dockerfile
index d08f3bb..ffc3613 100644
--- a/Dockerfile
+++ b/Dockerfile
@@ -1,3 +1,24 @@
-FROM ubuntu:16.04
+# Copyright 2021 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.
+#
+# For those usages not covered by the Apache License, Version 2.0 please
+# contact: legal@canonical.com
+#
+# To get in touch with the maintainers, please contact:
+# osm-charmers@lists.launchpad.net
+##
-RUN apt-get update && apt-get -y install git build-essential dh-make
+FROM ubuntu:18.04
+
+RUN apt-get update && apt-get -y install git build-essential dh-make tox python python3.8 python3-dev python3-pip
diff --git a/devops-stages/stage-test.sh b/devops-stages/stage-test.sh
index 1a24852..3e5196f 100755
--- a/devops-stages/stage-test.sh
+++ b/devops-stages/stage-test.sh
@@ -1 +1,26 @@
#!/bin/sh
+# Copyright 2021 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.
+
+set -eux
+CURRENT_DIR=`pwd`
+
+# Execute tests for charms
+CHARM_PATH="./installers/charm"
+CHARM_NAMES="keystone lcm mon nbi ng-ui pla pol prometheus ro"
+for charm in $CHARM_NAMES; do
+ cd $CHARM_PATH/$charm
+ tox --recreate
+ cd $CURRENT_DIR
+done
\ No newline at end of file
diff --git a/installers/charm/grafana/.gitignore b/installers/charm/grafana/.gitignore
index 3ca6f3a..01ec352 100644
--- a/installers/charm/grafana/.gitignore
+++ b/installers/charm/grafana/.gitignore
@@ -23,6 +23,6 @@
.vscode
build
grafana.charm
-.coverage
+.coverage*
.stestr
cover
diff --git a/installers/charm/grafana/tox.ini b/installers/charm/grafana/tox.ini
index 12a1f85..069cf10 100644
--- a/installers/charm/grafana/tox.ini
+++ b/installers/charm/grafana/tox.ini
@@ -26,7 +26,7 @@
skip_missing_interpreters = False
[testenv]
-basepython = python3
+basepython = python3.8
setenv =
PYTHONHASHSEED=0
PYTHONPATH = {toxinidir}/src
diff --git a/installers/charm/keystone/.gitignore b/installers/charm/keystone/.gitignore
index 97fc8b4..43fcb62 100644
--- a/installers/charm/keystone/.gitignore
+++ b/installers/charm/keystone/.gitignore
@@ -14,4 +14,7 @@
.vscode
.tox
build
-keystone.charm
\ No newline at end of file
+keystone.charm
+.stestr
+.coverage*
+cover/
\ No newline at end of file
diff --git a/installers/charm/keystone/src/charm.py b/installers/charm/keystone/src/charm.py
index 637461e..d5c169b 100755
--- a/installers/charm/keystone/src/charm.py
+++ b/installers/charm/keystone/src/charm.py
@@ -68,6 +68,7 @@
configure_pod = EventSource(ConfigurePodEvent)
+
class KeystoneCharm(CharmBase):
"""Keystone K8s Charm"""
@@ -142,7 +143,7 @@
event (EventBase): DB relation event to access database
information.
"""
- if not event.unit in event.relation.data:
+ if event.unit not in event.relation.data:
return
relation_data = event.relation.data[event.unit]
db_host = relation_data.get("host")
@@ -168,7 +169,6 @@
self.state.db_password = db_password
self.on.configure_pod.emit()
-
def _on_db_relation_departed(self, event: EventBase) -> NoReturn:
"""Clears data from db relation.
diff --git a/installers/charm/keystone/tests/__init__.py b/installers/charm/keystone/tests/__init__.py
new file mode 100644
index 0000000..6004c6d
--- /dev/null
+++ b/installers/charm/keystone/tests/__init__.py
@@ -0,0 +1,31 @@
+#!/usr/bin/env python3
+# Copyright 2020 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.
+#
+# For those usages not covered by the Apache License, Version 2.0 please
+# contact: legal@canonical.com
+#
+# To get in touch with the maintainers, please contact:
+# osm-charmers@lists.launchpad.net
+##
+
+"""Init mocking for unit tests."""
+
+# import sys
+# import mock
+
+# sys.path.append("src")
+
+# oci_image = mock.MagicMock()
+# sys.modules["oci_image"] = oci_image
diff --git a/installers/charm/keystone/tests/test_charm.py b/installers/charm/keystone/tests/test_charm.py
new file mode 100644
index 0000000..8cb8604
--- /dev/null
+++ b/installers/charm/keystone/tests/test_charm.py
@@ -0,0 +1,46 @@
+#!/usr/bin/env python3
+# Copyright 2020 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.
+#
+# For those usages not covered by the Apache License, Version 2.0 please
+# contact: legal@canonical.com
+#
+# To get in touch with the maintainers, please contact:
+# osm-charmers@lists.launchpad.net
+##
+
+from typing import NoReturn
+import unittest
+
+from ops.testing import Harness
+
+from charm import KeystoneCharm
+
+
+class TestCharm(unittest.TestCase):
+ """Keystone Charm unit tests."""
+
+ def setUp(self) -> NoReturn:
+ """Test setup"""
+ self.harness = Harness(KeystoneCharm)
+ self.harness.set_leader(is_leader=True)
+ self.harness.begin()
+
+ def test_on_start_without_relations(self) -> NoReturn:
+ """Test installation without any relation."""
+ self.harness.charm.on.config_changed.emit()
+
+
+if __name__ == "__main__":
+ unittest.main()
diff --git a/installers/charm/keystone/tox.ini b/installers/charm/keystone/tox.ini
index cff5193..781f74e 100644
--- a/installers/charm/keystone/tox.ini
+++ b/installers/charm/keystone/tox.ini
@@ -1,47 +1,82 @@
# Copyright 2020 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
+# 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
+# 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.
+# 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.
+#
+# For those usages not covered by the Apache License, Version 2.0 please
+# contact: legal@canonical.com
+#
+# To get in touch with the maintainers, please contact:
+# osm-charmers@lists.launchpad.net
+##
+
[tox]
-envlist = pep8
skipsdist = True
+envlist = unit, lint
+sitepackages = False
+skip_missing_interpreters = False
[testenv]
-setenv = VIRTUAL_ENV={envdir}
- PYTHONHASHSEED=0
-install_command =
- pip install {opts} {packages}
+basepython = python3.8
+setenv =
+ PYTHONHASHSEED=0
+ PYTHONPATH = {toxinidir}/src
+ CHARM_NAME = keystone
[testenv:build]
-basepython = python3
passenv=HTTP_PROXY HTTPS_PROXY NO_PROXY
-whitelist_externals = charmcraft
- rm
- unzip
+whitelist_externals =
+ charmcraft
+ rm
+ unzip
commands =
- rm -rf release
- charmcraft build
- unzip keystone.charm -d release
+ rm -rf release keystone.charm
+ charmcraft build
+ unzip keystone.charm -d release
+
+[testenv:unit]
+commands =
+ coverage erase
+ stestr run --slowest --test-path=./tests --top-dir=./
+ coverage combine
+ coverage html -d cover
+ coverage xml -o cover/coverage.xml
+ coverage report
+deps =
+ coverage
+ stestr
+ mock
+ ops
+ -rrequirements.txt
+setenv =
+ {[testenv]setenv}
+ PYTHON=coverage run
[testenv:lint]
-basepython = python3
deps =
- black
- yamllint
- flake8
+ black
+ yamllint
+ flake8
commands =
- black --check --diff . --exclude "build/|.tox/|mod/|lib/"
- yamllint .
- flake8 . --max-line-length=100 --exclude "build/ .tox/ mod/ lib/"
+ black --check --diff . --exclude "build/|.tox/|mod/|lib/|release/"
+ yamllint .
+ flake8 . --max-line-length=100 --ignore="E501,W503,W504,F722" --exclude "build/ .tox/ mod/ lib/ release/"
-[testenv:venv]
-commands = {posargs}
+[coverage:run]
+branch = True
+concurrency = multiprocessing
+parallel = True
+source =
+ .
+omit =
+ .tox/*
+ tests/*
diff --git a/installers/charm/lcm/tox.ini b/installers/charm/lcm/tox.ini
index bc7ee37..068b4c5 100644
--- a/installers/charm/lcm/tox.ini
+++ b/installers/charm/lcm/tox.ini
@@ -26,7 +26,7 @@
skip_missing_interpreters = False
[testenv]
-basepython = python3
+basepython = python3.8
setenv =
PYTHONHASHSEED=0
PYTHONPATH = {toxinidir}/src
diff --git a/installers/charm/mon/tox.ini b/installers/charm/mon/tox.ini
index 0b1ab82..7ddaf8d 100644
--- a/installers/charm/mon/tox.ini
+++ b/installers/charm/mon/tox.ini
@@ -26,7 +26,7 @@
skip_missing_interpreters = False
[testenv]
-basepython = python3
+basepython = python3.8
setenv =
PYTHONHASHSEED=0
PYTHONPATH = {toxinidir}/src
@@ -66,10 +66,9 @@
yamllint
flake8
commands =
- black --check --diff . --exclude "build/|.tox/|mod/|lib/"
+ black --check --diff . --exclude "build/|.tox/|mod/|lib/|release/"
yamllint .
- flake8 . --max-line-length=100 --ignore="E501,W503,W504,F722" --exclude "build/ .tox/ mod/ lib/"
-
+ flake8 . --max-line-length=100 --ignore="E501,W503,W504,F722" --exclude "build/ .tox/ mod/ lib/ release/"
[coverage:run]
branch = True
concurrency = multiprocessing
diff --git a/installers/charm/nbi/.gitignore b/installers/charm/nbi/.gitignore
index f920a7f..05bdb52 100644
--- a/installers/charm/nbi/.gitignore
+++ b/installers/charm/nbi/.gitignore
@@ -23,6 +23,6 @@
.vscode
build
nbi.charm
-.coverage
+.coverage*
.stestr
cover
\ No newline at end of file
diff --git a/installers/charm/nbi/tox.ini b/installers/charm/nbi/tox.ini
index b7b0912..5989669 100644
--- a/installers/charm/nbi/tox.ini
+++ b/installers/charm/nbi/tox.ini
@@ -26,7 +26,7 @@
skip_missing_interpreters = False
[testenv]
-basepython = python3
+basepython = python3.8
setenv =
PYTHONHASHSEED=0
PYTHONPATH = {toxinidir}/src
diff --git a/installers/charm/ng-ui/.gitignore b/installers/charm/ng-ui/.gitignore
index dfaa805..9c7c049 100644
--- a/installers/charm/ng-ui/.gitignore
+++ b/installers/charm/ng-ui/.gitignore
@@ -13,4 +13,7 @@
# limitations under the License.
.vscode
build
-ng-ui.charm
\ No newline at end of file
+ng-ui.charm
+.stestr
+.coverage*
+cover/
\ No newline at end of file
diff --git a/installers/charm/ng-ui/src/charm.py b/installers/charm/ng-ui/src/charm.py
index 21102e4..944d8ce 100755
--- a/installers/charm/ng-ui/src/charm.py
+++ b/installers/charm/ng-ui/src/charm.py
@@ -93,7 +93,7 @@
Args:
event (EventBase): NBI relation event.
"""
- if not event.unit in event.relation.data:
+ if event.unit not in event.relation.data:
return
relation_data = event.relation.data[event.unit]
nbi_host = relation_data.get("host")
diff --git a/installers/charm/ng-ui/tests/__init__.py b/installers/charm/ng-ui/tests/__init__.py
new file mode 100644
index 0000000..6004c6d
--- /dev/null
+++ b/installers/charm/ng-ui/tests/__init__.py
@@ -0,0 +1,31 @@
+#!/usr/bin/env python3
+# Copyright 2020 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.
+#
+# For those usages not covered by the Apache License, Version 2.0 please
+# contact: legal@canonical.com
+#
+# To get in touch with the maintainers, please contact:
+# osm-charmers@lists.launchpad.net
+##
+
+"""Init mocking for unit tests."""
+
+# import sys
+# import mock
+
+# sys.path.append("src")
+
+# oci_image = mock.MagicMock()
+# sys.modules["oci_image"] = oci_image
diff --git a/installers/charm/ng-ui/tests/test_charm.py b/installers/charm/ng-ui/tests/test_charm.py
new file mode 100644
index 0000000..1cde2df
--- /dev/null
+++ b/installers/charm/ng-ui/tests/test_charm.py
@@ -0,0 +1,46 @@
+#!/usr/bin/env python3
+# Copyright 2020 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.
+#
+# For those usages not covered by the Apache License, Version 2.0 please
+# contact: legal@canonical.com
+#
+# To get in touch with the maintainers, please contact:
+# osm-charmers@lists.launchpad.net
+##
+
+from typing import NoReturn
+import unittest
+
+from ops.testing import Harness
+
+from charm import NgUiCharm
+
+
+class TestCharm(unittest.TestCase):
+ """PLA Charm unit tests."""
+
+ def setUp(self) -> NoReturn:
+ """Test setup"""
+ self.harness = Harness(NgUiCharm)
+ self.harness.set_leader(is_leader=True)
+ self.harness.begin()
+
+ def test_on_start_without_relations(self) -> NoReturn:
+ """Test installation without any relation."""
+ self.harness.charm.on.config_changed.emit()
+
+
+if __name__ == "__main__":
+ unittest.main()
diff --git a/installers/charm/ng-ui/tox.ini b/installers/charm/ng-ui/tox.ini
index 1c22bd5..e60f0b8 100644
--- a/installers/charm/ng-ui/tox.ini
+++ b/installers/charm/ng-ui/tox.ini
@@ -1,65 +1,82 @@
-# Copyright 2020 Canonical Ltd.
+# Copyright 2020 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
+# 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
+# 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.
+# 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.
+#
+# For those usages not covered by the Apache License, Version 2.0 please
+# contact: legal@canonical.com
+#
+# To get in touch with the maintainers, please contact:
+# osm-charmers@lists.launchpad.net
+##
+
[tox]
-envlist = pep8
skipsdist = True
+envlist = unit, lint
+sitepackages = False
+skip_missing_interpreters = False
[testenv]
-setenv = VIRTUAL_ENV={envdir}
- PYTHONHASHSEED=0
-whitelist_externals = juju
-passenv = HOME TERM CS_API_* OS_* AMULET_*
-install_command =
- pip install {opts} {packages}
+basepython = python3.8
+setenv =
+ PYTHONHASHSEED=0
+ PYTHONPATH = {toxinidir}/src
+ CHARM_NAME = ng-ui
[testenv:build]
-basepython = python3
passenv=HTTP_PROXY HTTPS_PROXY NO_PROXY
-whitelist_externals = charmcraft
- rm
- unzip
+whitelist_externals =
+ charmcraft
+ rm
+ unzip
commands =
- rm -rf release
- charmcraft build
- unzip ng-ui.charm -d release
+ rm -rf release ng-ui.charm
+ charmcraft build
+ unzip ng-ui.charm -d release
-[testenv:black]
-basepython = python3
+[testenv:unit]
+commands =
+ coverage erase
+ stestr run --slowest --test-path=./tests --top-dir=./
+ coverage combine
+ coverage html -d cover
+ coverage xml -o cover/coverage.xml
+ coverage report
deps =
- black
- yamllint
+ coverage
+ stestr
+ mock
+ ops
+ -rrequirements.txt
+setenv =
+ {[testenv]setenv}
+ PYTHON=coverage run
+
+[testenv:lint]
+deps =
+ black
+ yamllint
+ flake8
commands =
- black --check --diff src
- yamllint .
+ black --check --diff . --exclude "build/|.tox/|mod/|lib/|release/"
+ yamllint .
+ flake8 . --max-line-length=100 --ignore="E501,W503,W504,F722" --exclude "build/ .tox/ mod/ lib/ release/"
-[testenv:pep8]
-basepython = python3
-deps=charm-tools
-commands = charm-proof
-
-[testenv:func-noop]
-basepython = python3
-commands =
- true
-
-[testenv:func]
-basepython = python3
-commands = functest-run-suite
-
-[testenv:func-smoke]
-basepython = python3
-commands = functest-run-suite --keep-model --smoke
-
-[testenv:venv]
-commands = {posargs}
+[coverage:run]
+branch = True
+concurrency = multiprocessing
+parallel = True
+source =
+ .
+omit =
+ .tox/*
+ tests/*
diff --git a/installers/charm/pla/.gitignore b/installers/charm/pla/.gitignore
index db6d41a..dad4b21 100644
--- a/installers/charm/pla/.gitignore
+++ b/installers/charm/pla/.gitignore
@@ -13,4 +13,7 @@
# limitations under the License.
.vscode
build
-pla.charm
\ No newline at end of file
+pla.charm
+.stestr
+.coverage*
+cover/
\ No newline at end of file
diff --git a/installers/charm/pla/src/charm.py b/installers/charm/pla/src/charm.py
index 16e7303..6847580 100755
--- a/installers/charm/pla/src/charm.py
+++ b/installers/charm/pla/src/charm.py
@@ -13,21 +13,17 @@
# See the License for the specific language governing permissions and
# limitations under the License.
-from glob import glob
import logging
-from pathlib import Path
-from string import Template
-import sys
from ops.charm import CharmBase
-from ops.framework import StoredState, Object
+from ops.framework import StoredState
from ops.main import main
from ops.model import (
ActiveStatus,
MaintenanceStatus,
WaitingStatus,
)
-
+from typing import NoReturn
logger = logging.getLogger(__name__)
@@ -35,8 +31,8 @@
class PLACharm(CharmBase):
state = StoredState()
- def __init__(self, framework, key):
- super().__init__(framework, key)
+ def __init__(self, *args) -> NoReturn:
+ super().__init__(*args)
self.state.set_default(spec=None)
self.state.set_default(kafka_host=None)
self.state.set_default(kafka_port=None)
diff --git a/installers/charm/pla/tests/__init__.py b/installers/charm/pla/tests/__init__.py
new file mode 100644
index 0000000..6004c6d
--- /dev/null
+++ b/installers/charm/pla/tests/__init__.py
@@ -0,0 +1,31 @@
+#!/usr/bin/env python3
+# Copyright 2020 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.
+#
+# For those usages not covered by the Apache License, Version 2.0 please
+# contact: legal@canonical.com
+#
+# To get in touch with the maintainers, please contact:
+# osm-charmers@lists.launchpad.net
+##
+
+"""Init mocking for unit tests."""
+
+# import sys
+# import mock
+
+# sys.path.append("src")
+
+# oci_image = mock.MagicMock()
+# sys.modules["oci_image"] = oci_image
diff --git a/installers/charm/pla/tests/test_charm.py b/installers/charm/pla/tests/test_charm.py
new file mode 100644
index 0000000..dbc7be3
--- /dev/null
+++ b/installers/charm/pla/tests/test_charm.py
@@ -0,0 +1,46 @@
+#!/usr/bin/env python3
+# Copyright 2020 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.
+#
+# For those usages not covered by the Apache License, Version 2.0 please
+# contact: legal@canonical.com
+#
+# To get in touch with the maintainers, please contact:
+# osm-charmers@lists.launchpad.net
+##
+
+from typing import NoReturn
+import unittest
+
+from ops.testing import Harness
+
+from charm import PLACharm
+
+
+class TestCharm(unittest.TestCase):
+ """PLA Charm unit tests."""
+
+ def setUp(self) -> NoReturn:
+ """Test setup"""
+ self.harness = Harness(PLACharm)
+ self.harness.set_leader(is_leader=True)
+ self.harness.begin()
+
+ def test_on_start_without_relations(self) -> NoReturn:
+ """Test installation without any relation."""
+ self.harness.charm.on.config_changed.emit()
+
+
+if __name__ == "__main__":
+ unittest.main()
diff --git a/installers/charm/pla/tox.ini b/installers/charm/pla/tox.ini
index 678a5ec..32d78d3 100644
--- a/installers/charm/pla/tox.ini
+++ b/installers/charm/pla/tox.ini
@@ -1,67 +1,81 @@
-# Copyright 2020 Canonical Ltd.
+# Copyright 2020 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
+# 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
+# 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.
+# 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.
+#
+# For those usages not covered by the Apache License, Version 2.0 please
+# contact: legal@canonical.com
+#
+# To get in touch with the maintainers, please contact:
+# osm-charmers@lists.launchpad.net
+##
[tox]
-envlist = pep8
skipsdist = True
+envlist = unit, lint
+sitepackages = False
+skip_missing_interpreters = False
[testenv]
-setenv = VIRTUAL_ENV={envdir}
- PYTHONHASHSEED=0
-whitelist_externals = juju
-passenv = HOME TERM CS_API_* OS_* AMULET_*
-install_command =
- pip install {opts} {packages}
-
+basepython = python3.8
+setenv =
+ PYTHONHASHSEED=0
+ PYTHONPATH = {toxinidir}/src
+ CHARM_NAME = pla
[testenv:build]
-basepython = python3
passenv=HTTP_PROXY HTTPS_PROXY NO_PROXY
-whitelist_externals = charmcraft
- rm
- unzip
+whitelist_externals =
+ charmcraft
+ rm
+ unzip
commands =
- rm -rf release
- charmcraft build
- unzip pla.charm -d release
+ rm -rf release pla.charm
+ charmcraft build
+ unzip pla.charm -d release
-[testenv:black]
-basepython = python3
+[testenv:unit]
+commands =
+ coverage erase
+ stestr run --slowest --test-path=./tests --top-dir=./
+ coverage combine
+ coverage html -d cover
+ coverage xml -o cover/coverage.xml
+ coverage report
deps =
- black
- yamllint
+ coverage
+ stestr
+ mock
+ ops
+setenv =
+ {[testenv]setenv}
+ PYTHON=coverage run
+
+[testenv:lint]
+deps =
+ black
+ yamllint
+ flake8
commands =
- black --check --diff src
- yamllint .
+ black --check --diff . --exclude "build/|.tox/|mod/|lib/|release/"
+ yamllint .
+ flake8 . --max-line-length=100 --ignore="E501,W503,W504,F722" --exclude "build/ .tox/ mod/ lib/ release/"
-[testenv:pep8]
-basepython = python3
-deps=charm-tools
-commands = charm-proof
-
-[testenv:func-noop]
-basepython = python3
-commands =
- true
-
-[testenv:func]
-basepython = python3
-commands = functest-run-suite
-
-[testenv:func-smoke]
-basepython = python3
-commands = functest-run-suite --keep-model --smoke
-
-[testenv:venv]
-commands = {posargs}
+[coverage:run]
+branch = True
+concurrency = multiprocessing
+parallel = True
+source =
+ .
+omit =
+ .tox/*
+ tests/*
diff --git a/installers/charm/pol/tox.ini b/installers/charm/pol/tox.ini
index 25bf830..ae324f8 100644
--- a/installers/charm/pol/tox.ini
+++ b/installers/charm/pol/tox.ini
@@ -26,7 +26,7 @@
skip_missing_interpreters = False
[testenv]
-basepython = python3
+basepython = python3.8
setenv =
PYTHONHASHSEED=0
PYTHONPATH = {toxinidir}/src
diff --git a/installers/charm/prometheus/tox.ini b/installers/charm/prometheus/tox.ini
index a7625a6..5491c07 100644
--- a/installers/charm/prometheus/tox.ini
+++ b/installers/charm/prometheus/tox.ini
@@ -26,7 +26,7 @@
skip_missing_interpreters = False
[testenv]
-basepython = python3
+basepython = python3.8
setenv =
PYTHONHASHSEED=0
PYTHONPATH = {toxinidir}/src
diff --git a/installers/charm/ro/tox.ini b/installers/charm/ro/tox.ini
index 4446145..8fd07d3 100644
--- a/installers/charm/ro/tox.ini
+++ b/installers/charm/ro/tox.ini
@@ -26,7 +26,7 @@
skip_missing_interpreters = False
[testenv]
-basepython = python3
+basepython = python3.8
setenv =
PYTHONHASHSEED=0
PYTHONPATH = {toxinidir}/src