-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
#!/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
.vscode
build
grafana.charm
-.coverage
+.coverage*
.stestr
cover
skip_missing_interpreters = False
[testenv]
-basepython = python3
+basepython = python3.8
setenv =
PYTHONHASHSEED=0
PYTHONPATH = {toxinidir}/src
.vscode
.tox
build
-keystone.charm
\ No newline at end of file
+keystone.charm
+.stestr
+.coverage*
+cover/
\ No newline at end of file
configure_pod = EventSource(ConfigurePodEvent)
+
class KeystoneCharm(CharmBase):
"""Keystone K8s Charm"""
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")
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.
--- /dev/null
+#!/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
--- /dev/null
+#!/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()
# 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/*
skip_missing_interpreters = False
[testenv]
-basepython = python3
+basepython = python3.8
setenv =
PYTHONHASHSEED=0
PYTHONPATH = {toxinidir}/src
skip_missing_interpreters = False
[testenv]
-basepython = python3
+basepython = python3.8
setenv =
PYTHONHASHSEED=0
PYTHONPATH = {toxinidir}/src
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
.vscode
build
nbi.charm
-.coverage
+.coverage*
.stestr
cover
\ No newline at end of file
skip_missing_interpreters = False
[testenv]
-basepython = python3
+basepython = python3.8
setenv =
PYTHONHASHSEED=0
PYTHONPATH = {toxinidir}/src
# 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
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")
--- /dev/null
+#!/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
--- /dev/null
+#!/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()
-# 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
-deps =
- black
- yamllint
+[testenv:unit]
commands =
- black --check --diff src
- yamllint .
-
-[testenv:pep8]
-basepython = python3
-deps=charm-tools
-commands = charm-proof
+ 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:func-noop]
-basepython = python3
+[testenv:lint]
+deps =
+ black
+ yamllint
+ flake8
commands =
- true
-
-[testenv:func]
-basepython = python3
-commands = functest-run-suite
-
-[testenv:func-smoke]
-basepython = python3
-commands = functest-run-suite --keep-model --smoke
+ 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/*
# 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
# 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__)
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)
--- /dev/null
+#!/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
--- /dev/null
+#!/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()
-# 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
-deps =
- black
- yamllint
+[testenv:unit]
commands =
- black --check --diff src
- yamllint .
-
-[testenv:pep8]
-basepython = python3
-deps=charm-tools
-commands = charm-proof
+ 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
+setenv =
+ {[testenv]setenv}
+ PYTHON=coverage run
-[testenv:func-noop]
-basepython = python3
+[testenv:lint]
+deps =
+ black
+ yamllint
+ flake8
commands =
- true
-
-[testenv:func]
-basepython = python3
-commands = functest-run-suite
-
-[testenv:func-smoke]
-basepython = python3
-commands = functest-run-suite --keep-model --smoke
+ 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/*
skip_missing_interpreters = False
[testenv]
-basepython = python3
+basepython = python3.8
setenv =
PYTHONHASHSEED=0
PYTHONPATH = {toxinidir}/src
skip_missing_interpreters = False
[testenv]
-basepython = python3
+basepython = python3.8
setenv =
PYTHONHASHSEED=0
PYTHONPATH = {toxinidir}/src
skip_missing_interpreters = False
[testenv]
-basepython = python3
+basepython = python3.8
setenv =
PYTHONHASHSEED=0
PYTHONPATH = {toxinidir}/src