From c753dc5f89180d11c1049f6398d74a4f99d7acd5 Mon Sep 17 00:00:00 2001 From: David Garcia Date: Wed, 17 Mar 2021 15:28:47 +0100 Subject: [PATCH] Fix 1473 and add vca_model_config_* to lcm charm Changes in all operator charms: - Optimize deps for tox environments - Add import-order-style to flake8 - Optimize .jujuignore to reduce the size of charm artifacts OSM LCM charm: - Added vca_model_config_* options Added bundle example for using a bundle Updated the bundles and pin the new versions in the installer Change-Id: Ic6591354fa5d1b5f43383215b2f0df13eb28ce67 Signed-off-by: David Garcia --- installers/charm/bundles/osm-ha/bundle.yaml | 20 +- installers/charm/bundles/osm/bundle.yaml | 20 +- installers/charm/grafana/.jujuignore | 8 +- .../charm/grafana/requirements-test.txt | 13 +- installers/charm/grafana/src/charm.py | 34 ++- installers/charm/grafana/tests/__init__.py | 2 + installers/charm/grafana/tests/test_charm.py | 4 +- installers/charm/grafana/tox.ini | 60 ++--- installers/charm/keystone/.jujuignore | 8 +- .../charm/keystone/requirements-test.txt | 13 +- installers/charm/keystone/src/charm.py | 24 +- installers/charm/keystone/tests/__init__.py | 2 + installers/charm/keystone/tests/test_charm.py | 5 +- installers/charm/keystone/tox.ini | 58 ++--- installers/charm/lcm/.jujuignore | 8 +- installers/charm/lcm/config.yaml | 212 +++++++++++++++++- installers/charm/lcm/requirements-test.txt | 13 +- installers/charm/lcm/src/charm.py | 84 +++++-- installers/charm/lcm/tests/__init__.py | 1 + installers/charm/lcm/tests/test_charm.py | 111 ++++++++- installers/charm/lcm/tox.ini | 58 ++--- installers/charm/local_osm_bundle_proxy.yaml | 200 +++++++++++++++++ installers/charm/mon/.jujuignore | 8 +- installers/charm/mon/config.yaml | 2 +- installers/charm/mon/requirements-test.txt | 13 +- installers/charm/mon/src/charm.py | 21 +- installers/charm/mon/tests/__init__.py | 1 + installers/charm/mon/tests/test_charm.py | 6 +- installers/charm/mon/tests/test_pod_spec.py | 5 +- installers/charm/mon/tox.ini | 58 ++--- installers/charm/nbi/.gitignore | 5 - installers/charm/nbi/.jujuignore | 8 +- installers/charm/nbi/requirements-test.txt | 13 +- installers/charm/nbi/src/charm.py | 27 +-- installers/charm/nbi/tests/__init__.py | 1 + installers/charm/nbi/tests/test_charm.py | 5 +- installers/charm/nbi/tox.ini | 58 ++--- installers/charm/ng-ui/.gitignore | 7 - installers/charm/ng-ui/.jujuignore | 8 +- installers/charm/ng-ui/requirements-test.txt | 13 +- installers/charm/ng-ui/src/charm.py | 21 +- installers/charm/ng-ui/tests/__init__.py | 2 + installers/charm/ng-ui/tests/test_charm.py | 4 +- installers/charm/ng-ui/tox.ini | 60 ++--- installers/charm/pla/.jujuignore | 8 +- installers/charm/pla/requirements-test.txt | 13 +- installers/charm/pla/src/charm.py | 13 +- installers/charm/pla/tests/__init__.py | 2 + installers/charm/pla/tests/test_charm.py | 5 +- installers/charm/pla/tox.ini | 58 ++--- installers/charm/pol/.jujuignore | 8 +- installers/charm/pol/requirements-test.txt | 13 +- installers/charm/pol/src/charm.py | 13 +- installers/charm/pol/tests/__init__.py | 2 + installers/charm/pol/tests/test_charm.py | 4 +- installers/charm/pol/tox.ini | 58 ++--- installers/charm/prometheus/.jujuignore | 8 +- .../charm/prometheus/requirements-test.txt | 13 +- installers/charm/prometheus/src/charm.py | 16 +- installers/charm/prometheus/tests/__init__.py | 2 + .../charm/prometheus/tests/test_charm.py | 4 +- installers/charm/prometheus/tox.ini | 58 ++--- installers/charm/ro/.jujuignore | 8 +- installers/charm/ro/requirements-test.txt | 12 +- installers/charm/ro/src/charm.py | 16 +- installers/charm/ro/tests/__init__.py | 2 + installers/charm/ro/tests/test_charm.py | 4 +- installers/charm/ro/tox.ini | 58 ++--- installers/charmed_install.sh | 10 +- 69 files changed, 1128 insertions(+), 584 deletions(-) create mode 100644 installers/charm/local_osm_bundle_proxy.yaml diff --git a/installers/charm/bundles/osm-ha/bundle.yaml b/installers/charm/bundles/osm-ha/bundle.yaml index d3a586a8..9ee71954 100644 --- a/installers/charm/bundles/osm-ha/bundle.yaml +++ b/installers/charm/bundles/osm-ha/bundle.yaml @@ -83,7 +83,7 @@ applications: gui-x: 0 gui-y: 0 nbi: - charm: "cs:~charmed-osm/nbi-5" + charm: "cs:~charmed-osm/nbi-6" scale: 3 series: kubernetes options: @@ -94,7 +94,7 @@ applications: gui-x: 0 gui-y: -250 ro: - charm: "cs:~charmed-osm/ro-0" + charm: "cs:~charmed-osm/ro-1" scale: 3 series: kubernetes options: @@ -103,14 +103,14 @@ applications: gui-x: -300 gui-y: 250 ng-ui: - charm: "cs:~charmed-osm/ng-ui-16" + charm: "cs:~charmed-osm/ng-ui-17" scale: 3 series: kubernetes annotations: gui-x: 600 gui-y: 0 lcm: - charm: "cs:~charmed-osm/lcm-0" + charm: "cs:~charmed-osm/lcm-2" scale: 3 series: kubernetes options: @@ -120,7 +120,7 @@ applications: gui-x: -300 gui-y: 0 mon: - charm: "cs:~charmed-osm/mon-1" + charm: "cs:~charmed-osm/mon-2" scale: 1 series: kubernetes options: @@ -131,7 +131,7 @@ applications: gui-x: 300 gui-y: 0 pol: - charm: "cs:~charmed-osm/pol-0" + charm: "cs:~charmed-osm/pol-1" scale: 3 series: kubernetes options: @@ -140,7 +140,7 @@ applications: gui-x: -300 gui-y: 500 pla: - charm: "cs:~charmed-osm/pla-6" + charm: "cs:~charmed-osm/pla-7" scale: 3 series: kubernetes options: @@ -149,7 +149,7 @@ applications: gui-x: 600 gui-y: -250 prometheus: - charm: "cs:~charmed-osm/prometheus-0" + charm: "cs:~charmed-osm/prometheus-1" scale: 1 series: kubernetes storage: @@ -160,14 +160,14 @@ applications: gui-x: 300 gui-y: 250 grafana: - charm: "cs:~charmed-osm/grafana-0" + charm: "cs:~charmed-osm/grafana-1" scale: 3 series: kubernetes annotations: gui-x: 300 gui-y: 500 keystone: - charm: "cs:~charmed-osm/keystone-4" + charm: "cs:~charmed-osm/keystone-5" scale: 1 series: kubernetes annotations: diff --git a/installers/charm/bundles/osm/bundle.yaml b/installers/charm/bundles/osm/bundle.yaml index b210a40d..404ed566 100644 --- a/installers/charm/bundles/osm/bundle.yaml +++ b/installers/charm/bundles/osm/bundle.yaml @@ -76,7 +76,7 @@ applications: gui-x: 0 gui-y: 0 nbi: - charm: "cs:~charmed-osm/nbi-5" + charm: "cs:~charmed-osm/nbi-6" scale: 1 series: kubernetes options: @@ -87,7 +87,7 @@ applications: gui-x: 0 gui-y: -250 ro: - charm: "cs:~charmed-osm/ro-0" + charm: "cs:~charmed-osm/ro-1" scale: 1 series: kubernetes options: @@ -96,14 +96,14 @@ applications: gui-x: -300 gui-y: 250 ng-ui: - charm: "cs:~charmed-osm/ng-ui-16" + charm: "cs:~charmed-osm/ng-ui-17" scale: 1 series: kubernetes annotations: gui-x: 600 gui-y: 0 lcm: - charm: "cs:~charmed-osm/lcm-0" + charm: "cs:~charmed-osm/lcm-2" scale: 1 series: kubernetes options: @@ -113,7 +113,7 @@ applications: gui-x: -300 gui-y: 0 mon: - charm: "cs:~charmed-osm/mon-1" + charm: "cs:~charmed-osm/mon-2" scale: 1 series: kubernetes options: @@ -124,7 +124,7 @@ applications: gui-x: 300 gui-y: 0 pol: - charm: "cs:~charmed-osm/pol-0" + charm: "cs:~charmed-osm/pol-1" scale: 1 series: kubernetes options: @@ -133,7 +133,7 @@ applications: gui-x: -300 gui-y: 500 pla: - charm: "cs:~charmed-osm/pla-6" + charm: "cs:~charmed-osm/pla-7" scale: 1 series: kubernetes options: @@ -142,7 +142,7 @@ applications: gui-x: 600 gui-y: -250 prometheus: - charm: "cs:~charmed-osm/prometheus-0" + charm: "cs:~charmed-osm/prometheus-1" scale: 1 series: kubernetes storage: @@ -153,14 +153,14 @@ applications: gui-x: 300 gui-y: 250 grafana: - charm: "cs:~charmed-osm/grafana-0" + charm: "cs:~charmed-osm/grafana-1" scale: 1 series: kubernetes annotations: gui-x: 300 gui-y: 500 keystone: - charm: "cs:~charmed-osm/keystone-4" + charm: "cs:~charmed-osm/keystone-5" scale: 1 series: kubernetes annotations: diff --git a/installers/charm/grafana/.jujuignore b/installers/charm/grafana/.jujuignore index bf04eb47..3ae3e7dc 100644 --- a/installers/charm/grafana/.jujuignore +++ b/installers/charm/grafana/.jujuignore @@ -22,7 +22,13 @@ venv .vscode build -prometheus.charm +*.charm .coverage +coverage.xml +.gitignore .stestr cover +release +tests/ +requirements* +tox.ini diff --git a/installers/charm/grafana/requirements-test.txt b/installers/charm/grafana/requirements-test.txt index d7585f3e..cf61dd4e 100644 --- a/installers/charm/grafana/requirements-test.txt +++ b/installers/charm/grafana/requirements-test.txt @@ -17,15 +17,4 @@ # # To get in touch with the maintainers, please contact: # osm-charmers@lists.launchpad.net -## --r requirements.txt -coverage -stestr -mock -black -yamllint -flake8 -safety -requests-mock -asynctest -nose2 \ No newline at end of file +mock==4.0.3 diff --git a/installers/charm/grafana/src/charm.py b/installers/charm/grafana/src/charm.py index d61873c7..d10ccf23 100755 --- a/installers/charm/grafana/src/charm.py +++ b/installers/charm/grafana/src/charm.py @@ -22,33 +22,25 @@ # pylint: disable=E0213 -import logging -from typing import Optional, NoReturn from ipaddress import ip_network +import logging +from pathlib import Path +from string import Template +from typing import NoReturn, Optional +from urllib.parse import urlparse from ops.main import main - from opslib.osm.charm import CharmedOsmBase, RelationsMissing - +from opslib.osm.interfaces.prometheus import PrometheusClient from opslib.osm.pod import ( - IngressResourceV3Builder, - FilesV3Builder, ContainerV3Builder, + FilesV3Builder, + IngressResourceV3Builder, PodSpecV3Builder, ) +from opslib.osm.validator import ModelValidator, validator -from opslib.osm.validator import ( - ModelValidator, - validator, -) - -from opslib.osm.interfaces.prometheus import PrometheusClient - -from urllib.parse import urlparse -from string import Template -from pathlib import Path - logger = logging.getLogger(__name__) PORT = 3000 @@ -90,8 +82,12 @@ class GrafanaCharm(CharmedOsmBase): super().__init__(*args, oci_image="image") self.prometheus_client = PrometheusClient(self, "prometheus") - self.framework.observe(self.on["prometheus"].relation_changed, self.configure_pod) - self.framework.observe(self.on["prometheus"].relation_broken, self.configure_pod) + self.framework.observe( + self.on["prometheus"].relation_changed, self.configure_pod + ) + self.framework.observe( + self.on["prometheus"].relation_broken, self.configure_pod + ) def _build_dashboard_files(self, config: ConfigModel): files_builder = FilesV3Builder() diff --git a/installers/charm/grafana/tests/__init__.py b/installers/charm/grafana/tests/__init__.py index 4fd849a5..0967ea68 100644 --- a/installers/charm/grafana/tests/__init__.py +++ b/installers/charm/grafana/tests/__init__.py @@ -23,6 +23,8 @@ """Init mocking for unit tests.""" import sys + + import mock sys.path.append("src") diff --git a/installers/charm/grafana/tests/test_charm.py b/installers/charm/grafana/tests/test_charm.py index 07beb4aa..4e269df9 100644 --- a/installers/charm/grafana/tests/test_charm.py +++ b/installers/charm/grafana/tests/test_charm.py @@ -23,10 +23,10 @@ import sys from typing import NoReturn import unittest -from ops.model import ActiveStatus, BlockedStatus -from ops.testing import Harness from charm import GrafanaCharm +from ops.model import ActiveStatus, BlockedStatus +from ops.testing import Harness class TestCharm(unittest.TestCase): diff --git a/installers/charm/grafana/tox.ini b/installers/charm/grafana/tox.ini index 1f9442e3..dc4074f2 100644 --- a/installers/charm/grafana/tox.ini +++ b/installers/charm/grafana/tox.ini @@ -21,21 +21,32 @@ ####################################################################################### [tox] -envlist = flake8, cover, pylint, safety, yamllint -skipsdist = True +envlist = black, cover, flake8, pylint, yamllint, safety +skipsdist = true + +[tox:jenkins] +toxworkdir = /tmp/.tox [testenv] basepython = python3.8 -setenv = - VIRTUAL_ENV={envdir} - PYTHONHASHSEED=0 - PYTHONPATH = {toxinidir}/src +setenv = VIRTUAL_ENV={envdir} + PYTHONDONTWRITEBYTECODE = 1 deps = -r{toxinidir}/requirements.txt + +####################################################################################### +[testenv:black] +deps = black +commands = + black --check --diff src/ tests/ + + ####################################################################################### [testenv:cover] deps = {[testenv]deps} -r{toxinidir}/requirements-test.txt + coverage + nose2 commands = sh -c 'rm -f nosetests.xml' coverage erase @@ -45,21 +56,14 @@ commands = coverage xml -o coverage.xml --omit=*tests* whitelist_externals = sh -####################################################################################### -[testenv:safety] -setenv = - LC_ALL=C.UTF-8 - LANG=C.UTF-8 -deps = {[testenv]deps} - -r{toxinidir}/requirements-test.txt -commands = - - safety check --full-report ####################################################################################### [testenv:flake8] -deps = flake8 +deps = flake8 + flake8-import-order commands = - flake8 src/ tests/ + flake8 src/ tests/ --exclude=*pod_spec* + ####################################################################################### [testenv:pylint] @@ -67,14 +71,19 @@ deps = {[testenv]deps} -r{toxinidir}/requirements-test.txt pylint commands = - pylint -E src + pylint -E src/ tests/ + ####################################################################################### -[testenv:black] +[testenv:safety] +setenv = + LC_ALL=C.UTF-8 + LANG=C.UTF-8 deps = {[testenv]deps} - -r{toxinidir}/requirements-test.txt - black -commands = black --check --diff . --exclude "build/|.tox/|mod/|lib/" + safety +commands = + - safety check --full-report + ####################################################################################### [testenv:yamllint] @@ -86,9 +95,7 @@ commands = yamllint . ####################################################################################### [testenv:build] passenv=HTTP_PROXY HTTPS_PROXY NO_PROXY -deps = {[testenv]deps} - -r{toxinidir}/requirements-test.txt - charmcraft +deps = charmcraft whitelist_externals = charmcraft cp @@ -112,4 +119,5 @@ exclude = max-line-length = 120 show-source = True builtins = _ - +max-complexity = 10 +import-order-style = google diff --git a/installers/charm/keystone/.jujuignore b/installers/charm/keystone/.jujuignore index bf04eb47..3ae3e7dc 100644 --- a/installers/charm/keystone/.jujuignore +++ b/installers/charm/keystone/.jujuignore @@ -22,7 +22,13 @@ venv .vscode build -prometheus.charm +*.charm .coverage +coverage.xml +.gitignore .stestr cover +release +tests/ +requirements* +tox.ini diff --git a/installers/charm/keystone/requirements-test.txt b/installers/charm/keystone/requirements-test.txt index d7585f3e..cf61dd4e 100644 --- a/installers/charm/keystone/requirements-test.txt +++ b/installers/charm/keystone/requirements-test.txt @@ -17,15 +17,4 @@ # # To get in touch with the maintainers, please contact: # osm-charmers@lists.launchpad.net -## --r requirements.txt -coverage -stestr -mock -black -yamllint -flake8 -safety -requests-mock -asynctest -nose2 \ No newline at end of file +mock==4.0.3 diff --git a/installers/charm/keystone/src/charm.py b/installers/charm/keystone/src/charm.py index 72d70906..a8c69fe6 100755 --- a/installers/charm/keystone/src/charm.py +++ b/installers/charm/keystone/src/charm.py @@ -23,33 +23,25 @@ # pylint: disable=E0213 -import json -import logging -from cryptography.fernet import Fernet from datetime import datetime -from typing import Optional, NoReturn, List, Tuple from ipaddress import ip_network +import json +import logging +from typing import List, NoReturn, Optional, Tuple from urllib.parse import urlparse +from cryptography.fernet import Fernet from ops.main import main - from opslib.osm.charm import CharmedOsmBase, RelationsMissing - +from opslib.osm.interfaces.keystone import KeystoneServer +from opslib.osm.interfaces.mysql import MysqlClient from opslib.osm.pod import ( ContainerV3Builder, - PodSpecV3Builder, FilesV3Builder, IngressResourceV3Builder, + PodSpecV3Builder, ) - - -from opslib.osm.validator import ( - ModelValidator, - validator, -) - -from opslib.osm.interfaces.mysql import MysqlClient -from opslib.osm.interfaces.keystone import KeystoneServer +from opslib.osm.validator import ModelValidator, validator logger = logging.getLogger(__name__) diff --git a/installers/charm/keystone/tests/__init__.py b/installers/charm/keystone/tests/__init__.py index d0d973ae..ca37e3b9 100644 --- a/installers/charm/keystone/tests/__init__.py +++ b/installers/charm/keystone/tests/__init__.py @@ -23,6 +23,8 @@ """Init mocking for unit tests.""" import sys + + import mock sys.path.append("src") diff --git a/installers/charm/keystone/tests/test_charm.py b/installers/charm/keystone/tests/test_charm.py index 756a5e42..d16e75d7 100644 --- a/installers/charm/keystone/tests/test_charm.py +++ b/installers/charm/keystone/tests/test_charm.py @@ -23,10 +23,11 @@ import sys from typing import NoReturn import unittest -from ops.model import ActiveStatus, BlockedStatus -from ops.testing import Harness + from charm import KeystoneCharm +from ops.model import ActiveStatus, BlockedStatus +from ops.testing import Harness class TestCharm(unittest.TestCase): diff --git a/installers/charm/keystone/tox.ini b/installers/charm/keystone/tox.ini index 1f9442e3..d0d25709 100644 --- a/installers/charm/keystone/tox.ini +++ b/installers/charm/keystone/tox.ini @@ -21,21 +21,32 @@ ####################################################################################### [tox] -envlist = flake8, cover, pylint, safety, yamllint -skipsdist = True +envlist = black, cover, flake8, pylint, yamllint, safety +skipsdist = true + +[tox:jenkins] +toxworkdir = /tmp/.tox [testenv] basepython = python3.8 -setenv = - VIRTUAL_ENV={envdir} - PYTHONHASHSEED=0 - PYTHONPATH = {toxinidir}/src +setenv = VIRTUAL_ENV={envdir} + PYTHONDONTWRITEBYTECODE = 1 deps = -r{toxinidir}/requirements.txt + +####################################################################################### +[testenv:black] +deps = black +commands = + black --check --diff src/ tests/ + + ####################################################################################### [testenv:cover] deps = {[testenv]deps} -r{toxinidir}/requirements-test.txt + coverage + nose2 commands = sh -c 'rm -f nosetests.xml' coverage erase @@ -45,36 +56,34 @@ commands = coverage xml -o coverage.xml --omit=*tests* whitelist_externals = sh -####################################################################################### -[testenv:safety] -setenv = - LC_ALL=C.UTF-8 - LANG=C.UTF-8 -deps = {[testenv]deps} - -r{toxinidir}/requirements-test.txt -commands = - - safety check --full-report ####################################################################################### [testenv:flake8] -deps = flake8 +deps = flake8 + flake8-import-order commands = flake8 src/ tests/ + ####################################################################################### [testenv:pylint] deps = {[testenv]deps} -r{toxinidir}/requirements-test.txt pylint commands = - pylint -E src + pylint -E src/ tests/ + ####################################################################################### -[testenv:black] +[testenv:safety] +setenv = + LC_ALL=C.UTF-8 + LANG=C.UTF-8 deps = {[testenv]deps} - -r{toxinidir}/requirements-test.txt - black -commands = black --check --diff . --exclude "build/|.tox/|mod/|lib/" + safety +commands = + - safety check --full-report + ####################################################################################### [testenv:yamllint] @@ -86,9 +95,7 @@ commands = yamllint . ####################################################################################### [testenv:build] passenv=HTTP_PROXY HTTPS_PROXY NO_PROXY -deps = {[testenv]deps} - -r{toxinidir}/requirements-test.txt - charmcraft +deps = charmcraft whitelist_externals = charmcraft cp @@ -112,4 +119,5 @@ exclude = max-line-length = 120 show-source = True builtins = _ - +; max-complexity = 10 +import-order-style = google diff --git a/installers/charm/lcm/.jujuignore b/installers/charm/lcm/.jujuignore index bf04eb47..3ae3e7dc 100644 --- a/installers/charm/lcm/.jujuignore +++ b/installers/charm/lcm/.jujuignore @@ -22,7 +22,13 @@ venv .vscode build -prometheus.charm +*.charm .coverage +coverage.xml +.gitignore .stestr cover +release +tests/ +requirements* +tox.ini diff --git a/installers/charm/lcm/config.yaml b/installers/charm/lcm/config.yaml index 4c823d16..6301622e 100644 --- a/installers/charm/lcm/config.yaml +++ b/installers/charm/lcm/config.yaml @@ -32,9 +32,9 @@ options: type: string description: "The VCA user name." default: "admin" - vca_password: + vca_secret: type: string - description: "The VCA user password." + description: "The VCA user secret." default: "secret" vca_pubkey: type: string @@ -63,3 +63,211 @@ options: description: "Log Level" type: string default: "INFO" + vca_model_config_agent_metadata_url: + description: The URL of the private stream. + type: string + vca_model_config_agent_stream: + description: | + The stream to use for deploy/upgrades of agents. + See additional info below. + type: string + vca_model_config_apt_ftp_proxy: + description: The APT FTP proxy for the model. + type: string + vca_model_config_apt_http_proxy: + description: The APT HTTP proxy for the model. + type: string + vca_model_config_apt_https_proxy: + description: The APT HTTPS proxy for the model. + type: string + vca_model_config_apt_mirror: + description: The APT mirror for the model. + type: string + vca_model_config_apt_no_proxy: + description: The APT no proxy for the model. + type: string + vca_model_config_automatically_retry_hooks: + description: Set the policy on retying failed hooks. + type: boolean + vca_model_config_backup_dir: + description: Backup directory + type: string + vca_model_config_cloudinit_userdata: + description: Cloudinit userdata + type: string + vca_model_config_container_image_metadata_url: + description: | + Corresponds to 'image-metadata-url' (see below) for cloud-hosted + KVM guests or LXD containers. Not needed for the localhost cloud. + type: string + vca_model_config_container_image_stream: + description: | + Corresponds to 'image-stream' (see below) for cloud-hosted KVM + guests or LXD containers. Not needed for the localhost cloud. + type: string + vca_model_config_container_inherit_properties: + description: | + Set parameters to be inherited from a machine toits hosted + containers (KVM or LXD). + type: string + vca_model_config_container_networking_method: + description: | + The FAN networking mode to use. Default values can be provider-specific. + type: string + vca_model_config_default_series: + description: The default series of Ubuntu to use for deploying charms. + type: string + vca_model_config_default_space: + description: | + The space used as the default binding when deploying charms. + Will be "alpha" by default. + type: string + vca_model_config_development: + description: Set whether the model is in development mode. + type: boolean + vca_model_config_disable_network_management: + description: | + Set whether to give network control to the provider instead + of Juju controlling configuration. + type: boolean + vca_model_config_egress_subnets: + description: Egress subnets + type: string + vca_model_config_enable_os_refresh_update: + description: | + Set whether newly provisioned instances should run their + respective OS's update capability. + type: boolean + vca_model_config_enable_os_upgrade: + description: | + Set whether newly provisioned instances should run their + respective OS's upgrade capability. + type: boolean + vca_model_config_fan_config: + description: | + The FAN overlay and underlay networks in + CIDR notation (space-separated). + type: string + vca_model_config_firewall_mode: + description: The mode to use for network firewalling. + type: string + vca_model_config_ftp_proxy: + description: | + The FTP proxy value to configure on instances, + in the FTP_PROXY environment variable. + type: string + vca_model_config_http_proxy: + description: | + The HTTP proxy value to configure on instances, + in the HTTP_PROXY environment variable. + type: string + vca_model_config_https_proxy: + description: | + The HTTPS proxy value to configure on instances, + in the HTTPS_PROXY environment variable. + type: string + vca_model_config_ignore_machine_addresses: + description: | + When true, the machine worker will not look up + or discover any machine addresses. + type: boolean + vca_model_config_image_metadata_url: + description: | + The URL at which the metadata used to locate + OS image ids is located. + type: string + vca_model_config_image_stream: + description: | + The simplestreams stream used to identify which image + ids to search when starting an instance. + type: string + vca_model_config_juju_ftp_proxy: + description: The charm-centric FTP proxy value. + type: string + vca_model_config_juju_http_proxy: + description: The charm-centric HTTP proxy value. + type: string + vca_model_config_juju_https_proxy: + description: The charm-centric HTTPS proxy value. + type: string + vca_model_config_juju_no_proxy: + description: The charm-centric no-proxy value. + type: string + vca_model_config_logforward_enabled: + description: Set whether the log forward function is enabled. + type: boolean + vca_model_config_logging_config: + description: | + The configuration string to use when configuring Juju agent logging + type: string + vca_model_config_lxd_snap_channel: + description: LXD snap channel + type: string + vca_model_config_max_action_results_age: + description: The maximum aget for status action results entries + type: string + vca_model_config_max_action_results_size: + description: The maximum size for status action results entries + type: string + vca_model_config_max_status_history_age: + description: | + The maximum age for status history entries before they are pruned, + in a human-readable time format. + type: string + vca_model_config_max_status_history_size: + description: | + The maximum size for the status history collection, + in human-readable memory format. + type: string + vca_model_config_net_bond_reconfigure_delay: + description: Net bond reconfigure delay + type: int + vca_model_config_no_proxy: + description: List of domain addresses not to be proxied (comma-separated). + type: string + vca_model_config_provisioner_harvest_mode: + description: Set what to do with unknown machines. + type: string + vca_model_config_proxy_ssh: + description: | + Set whether SSH commands should be proxied through the API server. + type: boolean + vca_model_config_snap_http_proxy: + description: The snap-centric HTTP proxy value. + type: string + vca_model_config_snap_https_proxy: + description: The snap-centric HTTPS proxy value. + type: string + vca_model_config_snap_store_assertions: + description: | + The collection of snap store assertions. + Each entry should contain the snap store ID. + type: string + vca_model_config_snap_store_proxy: + description: The snap store ID. + type: string + vca_model_config_snap_store_proxy_url: + description: The snap store proxy url + type: string + vca_model_config_ssl_hostname_verification: + description: Set whether SSL hostname verification is enabled. + type: boolean + vca_model_config_test_mode: + description: | + Set whether the model is intended for testing. + If true, accessing the charm store does not affect + statistical data of the store. + type: boolean + vca_model_config_transmit_vendor_metrics: + description: | + Set whether the controller will send metrics collected from + this model for use in anonymized aggregate analytics. + type: boolean + vca_model_config_update_status_hook_interval: + description: | + The run frequency of the update-status hook. + The value has a random +/- 20% offset applied to avoid hooks + for all units firing at once. Value change only honoured + during controller and model creation + (bootstrap --config and add-model --config). + type: string diff --git a/installers/charm/lcm/requirements-test.txt b/installers/charm/lcm/requirements-test.txt index d7585f3e..cf61dd4e 100644 --- a/installers/charm/lcm/requirements-test.txt +++ b/installers/charm/lcm/requirements-test.txt @@ -17,15 +17,4 @@ # # To get in touch with the maintainers, please contact: # osm-charmers@lists.launchpad.net -## --r requirements.txt -coverage -stestr -mock -black -yamllint -flake8 -safety -requests-mock -asynctest -nose2 \ No newline at end of file +mock==4.0.3 diff --git a/installers/charm/lcm/src/charm.py b/installers/charm/lcm/src/charm.py index 270a5479..e9552fd1 100755 --- a/installers/charm/lcm/src/charm.py +++ b/installers/charm/lcm/src/charm.py @@ -24,25 +24,16 @@ import logging -from typing import Optional, NoReturn +from typing import NoReturn, Optional -from ops.main import main +from ops.main import main from opslib.osm.charm import CharmedOsmBase, RelationsMissing - -from opslib.osm.pod import ( - ContainerV3Builder, - PodSpecV3Builder, -) - -from opslib.osm.validator import ( - ModelValidator, - validator, -) - +from opslib.osm.interfaces.http import HttpClient from opslib.osm.interfaces.kafka import KafkaClient from opslib.osm.interfaces.mongo import MongoClient -from opslib.osm.interfaces.http import HttpClient +from opslib.osm.pod import ContainerV3Builder, PodSpecV3Builder +from opslib.osm.validator import ModelValidator, validator logger = logging.getLogger(__name__) @@ -54,7 +45,7 @@ class ConfigModel(ModelValidator): vca_host: str vca_port: int vca_user: str - vca_password: str + vca_secret: str vca_pubkey: str vca_cacert: str vca_cloud: str @@ -62,6 +53,60 @@ class ConfigModel(ModelValidator): database_commonkey: str log_level: str vca_apiproxy: Optional[str] + # Model-config options + vca_model_config_agent_metadata_url: Optional[str] + vca_model_config_agent_stream: Optional[str] + vca_model_config_apt_ftp_proxy: Optional[str] + vca_model_config_apt_http_proxy: Optional[str] + vca_model_config_apt_https_proxy: Optional[str] + vca_model_config_apt_mirror: Optional[str] + vca_model_config_apt_no_proxy: Optional[str] + vca_model_config_automatically_retry_hooks: Optional[bool] + vca_model_config_backup_dir: Optional[str] + vca_model_config_cloudinit_userdata: Optional[str] + vca_model_config_container_image_metadata_url: Optional[str] + vca_model_config_container_image_stream: Optional[str] + vca_model_config_container_inherit_properties: Optional[str] + vca_model_config_container_networking_method: Optional[str] + vca_model_config_default_series: Optional[str] + vca_model_config_default_space: Optional[str] + vca_model_config_development: Optional[bool] + vca_model_config_disable_network_management: Optional[bool] + vca_model_config_egress_subnets: Optional[str] + vca_model_config_enable_os_refresh_update: Optional[bool] + vca_model_config_enable_os_upgrade: Optional[bool] + vca_model_config_fan_config: Optional[str] + vca_model_config_firewall_mode: Optional[str] + vca_model_config_ftp_proxy: Optional[str] + vca_model_config_http_proxy: Optional[str] + vca_model_config_https_proxy: Optional[str] + vca_model_config_ignore_machine_addresses: Optional[bool] + vca_model_config_image_metadata_url: Optional[str] + vca_model_config_image_stream: Optional[str] + vca_model_config_juju_ftp_proxy: Optional[str] + vca_model_config_juju_http_proxy: Optional[str] + vca_model_config_juju_https_proxy: Optional[str] + vca_model_config_juju_no_proxy: Optional[str] + vca_model_config_logforward_enabled: Optional[bool] + vca_model_config_logging_config: Optional[str] + vca_model_config_lxd_snap_channel: Optional[str] + vca_model_config_max_action_results_age: Optional[str] + vca_model_config_max_action_results_size: Optional[str] + vca_model_config_max_status_history_age: Optional[str] + vca_model_config_max_status_history_size: Optional[str] + vca_model_config_net_bond_reconfigure_delay: Optional[str] + vca_model_config_no_proxy: Optional[str] + vca_model_config_provisioner_harvest_mode: Optional[str] + vca_model_config_proxy_ssh: Optional[bool] + vca_model_config_snap_http_proxy: Optional[str] + vca_model_config_snap_https_proxy: Optional[str] + vca_model_config_snap_store_assertions: Optional[str] + vca_model_config_snap_store_proxy: Optional[str] + vca_model_config_snap_store_proxy_url: Optional[str] + vca_model_config_ssl_hostname_verification: Optional[bool] + vca_model_config_test_mode: Optional[bool] + vca_model_config_transmit_vendor_metrics: Optional[bool] + vca_model_config_update_status_hook_interval: Optional[str] @validator("log_level") def validate_log_level(cls, v): @@ -136,7 +181,7 @@ class LcmCharm(CharmedOsmBase): "OSMLCM_VCA_PORT": config.vca_port, "OSMLCM_VCA_USER": config.vca_user, "OSMLCM_VCA_PUBKEY": config.vca_pubkey, - "OSMLCM_VCA_SECRET": config.vca_password, + "OSMLCM_VCA_SECRET": config.vca_secret, "OSMLCM_VCA_CACERT": config.vca_cacert, "OSMLCM_VCA_CLOUD": config.vca_cloud, "OSMLCM_VCA_K8S_CLOUD": config.vca_k8s_cloud, @@ -145,6 +190,13 @@ class LcmCharm(CharmedOsmBase): if config.vca_apiproxy: container_builder.add_env("OSMLCM_VCA_APIPROXY", config.vca_apiproxy) + model_config_envs = { + f"OSMLCM_{k.upper()}": v + for k, v in self.config.items() + if k.startswith("vca_model_config") + } + if model_config_envs: + container_builder.add_envs(model_config_envs) container = container_builder.build() # Add container to pod spec pod_spec_builder.add_container(container) diff --git a/installers/charm/lcm/tests/__init__.py b/installers/charm/lcm/tests/__init__.py index d0d973ae..ee5553b0 100644 --- a/installers/charm/lcm/tests/__init__.py +++ b/installers/charm/lcm/tests/__init__.py @@ -23,6 +23,7 @@ """Init mocking for unit tests.""" import sys + import mock sys.path.append("src") diff --git a/installers/charm/lcm/tests/test_charm.py b/installers/charm/lcm/tests/test_charm.py index bff3cee2..831e1762 100644 --- a/installers/charm/lcm/tests/test_charm.py +++ b/installers/charm/lcm/tests/test_charm.py @@ -23,10 +23,11 @@ import sys from typing import NoReturn import unittest -from ops.model import ActiveStatus, BlockedStatus -from ops.testing import Harness from charm import LcmCharm +import mock +from ops.model import ActiveStatus, BlockedStatus +from ops.testing import Harness class TestCharm(unittest.TestCase): @@ -42,7 +43,7 @@ class TestCharm(unittest.TestCase): "vca_host": "192.168.0.13", "vca_port": 17070, "vca_user": "admin", - "vca_password": "admin", + "vca_secret": "admin", "vca_pubkey": "key", "vca_cacert": "cacert", "vca_cloud": "cloud", @@ -88,6 +89,110 @@ class TestCharm(unittest.TestCase): # Verifying status self.assertNotIsInstance(self.harness.charm.unit.status, BlockedStatus) + def test_build_pod_spec( + self, + ) -> NoReturn: + expected_config = { + "OSMLCM_GLOBAL_LOGLEVEL": self.config["log_level"], + "OSMLCM_DATABASE_COMMONKEY": self.config["database_commonkey"], + } + expected_config.update( + { + f"OSMLCM_{k.upper()}": v + for k, v in self.config.items() + if k.startswith("vca_") + } + ) + self.harness.charm._check_missing_dependencies = mock.Mock() + pod_spec = self.harness.charm.build_pod_spec( + {"imageDetails": {"imagePath": "lcm-image"}} + ) + actual_config = pod_spec["containers"][0]["envConfig"] + + self.assertDictContainsSubset( + expected_config, + actual_config, + ) + for config_key in actual_config: + self.assertNotIn("VCA_MODEL_CONFIG", config_key) + + def test_build_pod_spec_with_model_config( + self, + ) -> NoReturn: + self.harness.update_config( + { + "vca_model_config_agent_metadata_url": "string", + "vca_model_config_agent_stream": "string", + "vca_model_config_apt_ftp_proxy": "string", + "vca_model_config_apt_http_proxy": "string", + "vca_model_config_apt_https_proxy": "string", + "vca_model_config_apt_mirror": "string", + "vca_model_config_apt_no_proxy": "string", + "vca_model_config_automatically_retry_hooks": False, + "vca_model_config_backup_dir": "string", + "vca_model_config_cloudinit_userdata": "string", + "vca_model_config_container_image_metadata_url": "string", + "vca_model_config_container_image_stream": "string", + "vca_model_config_container_inherit_properties": "string", + "vca_model_config_container_networking_method": "string", + "vca_model_config_default_series": "string", + "vca_model_config_default_space": "string", + "vca_model_config_development": False, + "vca_model_config_disable_network_management": False, + "vca_model_config_egress_subnets": "string", + "vca_model_config_enable_os_refresh_update": False, + "vca_model_config_enable_os_upgrade": False, + "vca_model_config_fan_config": "string", + "vca_model_config_firewall_mode": "string", + "vca_model_config_ftp_proxy": "string", + "vca_model_config_http_proxy": "string", + "vca_model_config_https_proxy": "string", + "vca_model_config_ignore_machine_addresses": False, + "vca_model_config_image_metadata_url": "string", + "vca_model_config_image_stream": "string", + "vca_model_config_juju_ftp_proxy": "string", + "vca_model_config_juju_http_proxy": "string", + "vca_model_config_juju_https_proxy": "string", + "vca_model_config_juju_no_proxy": "string", + "vca_model_config_logforward_enabled": False, + "vca_model_config_logging_config": "string", + "vca_model_config_lxd_snap_channel": "string", + "vca_model_config_max_action_results_age": "string", + "vca_model_config_max_action_results_size": "string", + "vca_model_config_max_status_history_age": "string", + "vca_model_config_max_status_history_size": "string", + "vca_model_config_net_bond_reconfigure_delay": "string", + "vca_model_config_no_proxy": "string", + "vca_model_config_provisioner_harvest_mode": "string", + "vca_model_config_proxy_ssh": False, + "vca_model_config_snap_http_proxy": "string", + "vca_model_config_snap_https_proxy": "string", + "vca_model_config_snap_store_assertions": "string", + "vca_model_config_snap_store_proxy": "string", + "vca_model_config_snap_store_proxy_url": "string", + "vca_model_config_ssl_hostname_verification": False, + "vca_model_config_test_mode": False, + "vca_model_config_transmit_vendor_metrics": False, + "vca_model_config_update_status_hook_interval": "string", + } + ) + expected_config = { + f"OSMLCM_{k.upper()}": v + for k, v in self.config.items() + if k.startswith("vca_model_config_") + } + + self.harness.charm._check_missing_dependencies = mock.Mock() + pod_spec = self.harness.charm.build_pod_spec( + {"imageDetails": {"imagePath": "lcm-image"}} + ) + actual_config = pod_spec["containers"][0]["envConfig"] + + self.assertDictContainsSubset( + expected_config, + actual_config, + ) + def initialize_kafka_relation(self): kafka_relation_id = self.harness.add_relation("kafka", "kafka") self.harness.add_relation_unit(kafka_relation_id, "kafka/0") diff --git a/installers/charm/lcm/tox.ini b/installers/charm/lcm/tox.ini index 1f9442e3..30e0ea8c 100644 --- a/installers/charm/lcm/tox.ini +++ b/installers/charm/lcm/tox.ini @@ -21,21 +21,32 @@ ####################################################################################### [tox] -envlist = flake8, cover, pylint, safety, yamllint -skipsdist = True +envlist = black, cover, flake8, pylint, yamllint, safety +skipsdist = true + +[tox:jenkins] +toxworkdir = /tmp/.tox [testenv] basepython = python3.8 -setenv = - VIRTUAL_ENV={envdir} - PYTHONHASHSEED=0 - PYTHONPATH = {toxinidir}/src +setenv = VIRTUAL_ENV={envdir} + PYTHONDONTWRITEBYTECODE = 1 deps = -r{toxinidir}/requirements.txt + +####################################################################################### +[testenv:black] +deps = black +commands = + black --check --diff src/ tests/ + + ####################################################################################### [testenv:cover] deps = {[testenv]deps} -r{toxinidir}/requirements-test.txt + coverage + nose2 commands = sh -c 'rm -f nosetests.xml' coverage erase @@ -45,36 +56,34 @@ commands = coverage xml -o coverage.xml --omit=*tests* whitelist_externals = sh -####################################################################################### -[testenv:safety] -setenv = - LC_ALL=C.UTF-8 - LANG=C.UTF-8 -deps = {[testenv]deps} - -r{toxinidir}/requirements-test.txt -commands = - - safety check --full-report ####################################################################################### [testenv:flake8] -deps = flake8 +deps = flake8 + flake8-import-order commands = flake8 src/ tests/ + ####################################################################################### [testenv:pylint] deps = {[testenv]deps} -r{toxinidir}/requirements-test.txt pylint commands = - pylint -E src + pylint -E src/ tests/ + ####################################################################################### -[testenv:black] +[testenv:safety] +setenv = + LC_ALL=C.UTF-8 + LANG=C.UTF-8 deps = {[testenv]deps} - -r{toxinidir}/requirements-test.txt - black -commands = black --check --diff . --exclude "build/|.tox/|mod/|lib/" + safety +commands = + - safety check --full-report + ####################################################################################### [testenv:yamllint] @@ -86,9 +95,7 @@ commands = yamllint . ####################################################################################### [testenv:build] passenv=HTTP_PROXY HTTPS_PROXY NO_PROXY -deps = {[testenv]deps} - -r{toxinidir}/requirements-test.txt - charmcraft +deps = charmcraft whitelist_externals = charmcraft cp @@ -112,4 +119,5 @@ exclude = max-line-length = 120 show-source = True builtins = _ - +max-complexity = 10 +import-order-style = google diff --git a/installers/charm/local_osm_bundle_proxy.yaml b/installers/charm/local_osm_bundle_proxy.yaml new file mode 100644 index 00000000..d3285224 --- /dev/null +++ b/installers/charm/local_osm_bundle_proxy.yaml @@ -0,0 +1,200 @@ +# 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. +description: Single instance OSM bundle +bundle: kubernetes +variables: + proxy: &proxy http://91.189.89.11:3128 + no-proxy: &no_proxy 127.0.0.1,localhost,::1,10.131.15.1/24,10.152.183.0/24,10.1.0.0/16 +applications: + zookeeper-k8s: + charm: "cs:~charmed-osm/zookeeper-k8s" + channel: "stable" + scale: 1 + series: kubernetes + storage: + database: 100M + annotations: + gui-x: 0 + gui-y: 550 + mariadb-k8s: + charm: "cs:~charmed-osm/mariadb-k8s" + channel: "stable" + scale: 1 + series: kubernetes + storage: + database: 50M + options: + password: manopw + root_password: osm4u + user: mano + annotations: + gui-x: -250 + gui-y: -200 + kafka-k8s: + charm: "cs:~charmed-osm/kafka-k8s" + channel: "stable" + scale: 1 + series: kubernetes + storage: + database: 100M + annotations: + gui-x: 0 + gui-y: 300 + mongodb-k8s: + charm: "cs:~charmed-osm/mongodb-k8s" + channel: "stable" + scale: 1 + series: kubernetes + storage: + database: 50M + options: + replica-set: rs0 + namespace: osm + enable-sidecar: true + annotations: + gui-x: 0 + gui-y: 50 + nbi: + charm: "./nbi/build" + scale: 1 + series: kubernetes + options: + database_commonkey: osm + auth_backend: keystone + annotations: + gui-x: 0 + gui-y: -200 + ro: + charm: "./ro/build" + scale: 1 + series: kubernetes + annotations: + gui-x: -250 + gui-y: 300 + ng-ui: + charm: "./ng-ui/build" + scale: 1 + series: kubernetes + annotations: + gui-x: 500 + gui-y: 100 + lcm: + charm: "./lcm/build" + scale: 1 + series: kubernetes + options: + database_commonkey: osm + vca_model_config_no_proxy: *no_proxy + vca_model_config_juju_no_proxy: *no_proxy + vca_model_config_apt_no_proxy: *no_proxy + vca_model_config_juju_http_proxy: *proxy + vca_model_config_juju_https_proxy: *proxy + vca_model_config_apt_http_proxy: *proxy + vca_model_config_apt_https_proxy: *proxy + vca_model_config_snap_http_proxy: *proxy + vca_model_config_snap_https_proxy: *proxy + annotations: + gui-x: -250 + gui-y: 50 + mon: + charm: "./mon/build" + scale: 1 + series: kubernetes + options: + database_commonkey: osm + annotations: + gui-x: 250 + gui-y: 50 + pol: + charm: "./pol/build" + scale: 1 + series: kubernetes + annotations: + gui-x: -250 + gui-y: 550 + pla: + charm: "./pla/build" + scale: 1 + series: kubernetes + annotations: + gui-x: 500 + gui-y: -200 + prometheus: + charm: "./prometheus/build" + channel: "stable" + scale: 1 + series: kubernetes + storage: + data: 50M + options: + default-target: "mon:8000" + annotations: + gui-x: 250 + gui-y: 300 + grafana: + charm: "./grafana/build" + channel: "stable" + scale: 1 + series: kubernetes + annotations: + gui-x: 250 + gui-y: 550 + keystone: + charm: "./keystone/build" + scale: 1 + series: kubernetes + annotations: + gui-x: -250 + gui-y: 550 +relations: + - - grafana:prometheus + - prometheus:prometheus + - - kafka-k8s:zookeeper + - zookeeper-k8s:zookeeper + - - keystone:db + - mariadb-k8s:mysql + - - lcm:kafka + - kafka-k8s:kafka + - - lcm:mongodb + - mongodb-k8s:mongo + - - ro:ro + - lcm:ro + - - ro:kafka + - kafka-k8s:kafka + - - ro:mongodb + - mongodb-k8s:mongo + - - pol:kafka + - kafka-k8s:kafka + - - pol:mongodb + - mongodb-k8s:mongo + - - mon:mongodb + - mongodb-k8s:mongo + - - mon:kafka + - kafka-k8s:kafka + - - pla:kafka + - kafka-k8s:kafka + - - pla:mongodb + - mongodb-k8s:mongo + - - nbi:mongodb + - mongodb-k8s:mongo + - - nbi:kafka + - kafka-k8s:kafka + - - nbi:prometheus + - prometheus:prometheus + - - nbi:keystone + - keystone:keystone + - - mon:prometheus + - prometheus:prometheus + - - ng-ui:nbi + - nbi:nbi diff --git a/installers/charm/mon/.jujuignore b/installers/charm/mon/.jujuignore index bf04eb47..3ae3e7dc 100644 --- a/installers/charm/mon/.jujuignore +++ b/installers/charm/mon/.jujuignore @@ -22,7 +22,13 @@ venv .vscode build -prometheus.charm +*.charm .coverage +coverage.xml +.gitignore .stestr cover +release +tests/ +requirements* +tox.ini diff --git a/installers/charm/mon/config.yaml b/installers/charm/mon/config.yaml index 2fffbc5f..53914974 100644 --- a/installers/charm/mon/config.yaml +++ b/installers/charm/mon/config.yaml @@ -52,7 +52,7 @@ options: type: string description: "The VCA user name." default: "admin" - vca_password: + vca_secret: type: string description: "The VCA user password." default: "secret" diff --git a/installers/charm/mon/requirements-test.txt b/installers/charm/mon/requirements-test.txt index d7585f3e..cf61dd4e 100644 --- a/installers/charm/mon/requirements-test.txt +++ b/installers/charm/mon/requirements-test.txt @@ -17,15 +17,4 @@ # # To get in touch with the maintainers, please contact: # osm-charmers@lists.launchpad.net -## --r requirements.txt -coverage -stestr -mock -black -yamllint -flake8 -safety -requests-mock -asynctest -nose2 \ No newline at end of file +mock==4.0.3 diff --git a/installers/charm/mon/src/charm.py b/installers/charm/mon/src/charm.py index 26dee3ff..d0145d4f 100755 --- a/installers/charm/mon/src/charm.py +++ b/installers/charm/mon/src/charm.py @@ -26,24 +26,15 @@ import logging from typing import NoReturn -from ops.main import main +from ops.main import main from opslib.osm.charm import CharmedOsmBase, RelationsMissing - -from opslib.osm.pod import ( - ContainerV3Builder, - PodSpecV3Builder, -) - -from opslib.osm.validator import ( - ModelValidator, - validator, -) - from opslib.osm.interfaces.kafka import KafkaClient +from opslib.osm.interfaces.keystone import KeystoneClient from opslib.osm.interfaces.mongo import MongoClient from opslib.osm.interfaces.prometheus import PrometheusClient -from opslib.osm.interfaces.keystone import KeystoneClient +from opslib.osm.pod import ContainerV3Builder, PodSpecV3Builder +from opslib.osm.validator import ModelValidator, validator logger = logging.getLogger(__name__) @@ -55,7 +46,7 @@ class ConfigModel(ModelValidator): keystone_enabled: bool vca_host: str vca_user: str - vca_password: str + vca_secret: str vca_cacert: str database_commonkey: str log_level: str @@ -146,7 +137,7 @@ class MonCharm(CharmedOsmBase): # VCA configuration "OSMMON_VCA_HOST": config.vca_host, "OSMMON_VCA_USER": config.vca_user, - "OSMMON_VCA_SECRET": config.vca_password, + "OSMMON_VCA_SECRET": config.vca_secret, "OSMMON_VCA_CACERT": config.vca_cacert, "OSMMON_GRAFANA_URL": config.grafana_url, "OSMMON_GRAFANA_USER": config.grafana_user, diff --git a/installers/charm/mon/tests/__init__.py b/installers/charm/mon/tests/__init__.py index d0d973ae..ee5553b0 100644 --- a/installers/charm/mon/tests/__init__.py +++ b/installers/charm/mon/tests/__init__.py @@ -23,6 +23,7 @@ """Init mocking for unit tests.""" import sys + import mock sys.path.append("src") diff --git a/installers/charm/mon/tests/test_charm.py b/installers/charm/mon/tests/test_charm.py index 5d6f1a06..858ff7cb 100644 --- a/installers/charm/mon/tests/test_charm.py +++ b/installers/charm/mon/tests/test_charm.py @@ -23,10 +23,10 @@ import sys from typing import NoReturn import unittest -from ops.model import ActiveStatus, BlockedStatus -from ops.testing import Harness from charm import MonCharm +from ops.model import ActiveStatus, BlockedStatus +from ops.testing import Harness class TestCharm(unittest.TestCase): @@ -41,7 +41,7 @@ class TestCharm(unittest.TestCase): self.config = { "vca_host": "192.168.0.13", "vca_user": "admin", - "vca_password": "admin", + "vca_secret": "admin", "vca_cacert": "cacert", "database_commonkey": "commonkey", "log_level": "INFO", diff --git a/installers/charm/mon/tests/test_pod_spec.py b/installers/charm/mon/tests/test_pod_spec.py index 6f61916f..86a3d169 100644 --- a/installers/charm/mon/tests/test_pod_spec.py +++ b/installers/charm/mon/tests/test_pod_spec.py @@ -199,8 +199,9 @@ class TestPodSpec(unittest.TestCase): "OSMMON_DATABASE_DRIVER": "mongo", "OSMMON_DATABASE_URI": relation_state["database_uri"], "OSMMON_DATABASE_COMMONKEY": config["database_commonkey"], - "OSMMON_PROMETHEUS_URL": - f"http://{relation_state['prometheus_host']}:{relation_state['prometheus_port']}", + "OSMMON_PROMETHEUS_URL": ( + f"http://{relation_state['prometheus_host']}:{relation_state['prometheus_port']}" + ), "OSMMON_VCA_HOST": config["vca_host"], "OSMMON_VCA_USER": config["vca_user"], "OSMMON_VCA_SECRET": config["vca_password"], diff --git a/installers/charm/mon/tox.ini b/installers/charm/mon/tox.ini index 1f9442e3..30e0ea8c 100644 --- a/installers/charm/mon/tox.ini +++ b/installers/charm/mon/tox.ini @@ -21,21 +21,32 @@ ####################################################################################### [tox] -envlist = flake8, cover, pylint, safety, yamllint -skipsdist = True +envlist = black, cover, flake8, pylint, yamllint, safety +skipsdist = true + +[tox:jenkins] +toxworkdir = /tmp/.tox [testenv] basepython = python3.8 -setenv = - VIRTUAL_ENV={envdir} - PYTHONHASHSEED=0 - PYTHONPATH = {toxinidir}/src +setenv = VIRTUAL_ENV={envdir} + PYTHONDONTWRITEBYTECODE = 1 deps = -r{toxinidir}/requirements.txt + +####################################################################################### +[testenv:black] +deps = black +commands = + black --check --diff src/ tests/ + + ####################################################################################### [testenv:cover] deps = {[testenv]deps} -r{toxinidir}/requirements-test.txt + coverage + nose2 commands = sh -c 'rm -f nosetests.xml' coverage erase @@ -45,36 +56,34 @@ commands = coverage xml -o coverage.xml --omit=*tests* whitelist_externals = sh -####################################################################################### -[testenv:safety] -setenv = - LC_ALL=C.UTF-8 - LANG=C.UTF-8 -deps = {[testenv]deps} - -r{toxinidir}/requirements-test.txt -commands = - - safety check --full-report ####################################################################################### [testenv:flake8] -deps = flake8 +deps = flake8 + flake8-import-order commands = flake8 src/ tests/ + ####################################################################################### [testenv:pylint] deps = {[testenv]deps} -r{toxinidir}/requirements-test.txt pylint commands = - pylint -E src + pylint -E src/ tests/ + ####################################################################################### -[testenv:black] +[testenv:safety] +setenv = + LC_ALL=C.UTF-8 + LANG=C.UTF-8 deps = {[testenv]deps} - -r{toxinidir}/requirements-test.txt - black -commands = black --check --diff . --exclude "build/|.tox/|mod/|lib/" + safety +commands = + - safety check --full-report + ####################################################################################### [testenv:yamllint] @@ -86,9 +95,7 @@ commands = yamllint . ####################################################################################### [testenv:build] passenv=HTTP_PROXY HTTPS_PROXY NO_PROXY -deps = {[testenv]deps} - -r{toxinidir}/requirements-test.txt - charmcraft +deps = charmcraft whitelist_externals = charmcraft cp @@ -112,4 +119,5 @@ exclude = max-line-length = 120 show-source = True builtins = _ - +max-complexity = 10 +import-order-style = google diff --git a/installers/charm/nbi/.gitignore b/installers/charm/nbi/.gitignore index 21a2062e..2885df27 100644 --- a/installers/charm/nbi/.gitignore +++ b/installers/charm/nbi/.gitignore @@ -22,14 +22,9 @@ venv .vscode build -<<<<<<< HEAD -nbi.charm -.coverage* -======= *.charm .coverage coverage.xml ->>>>>>> WIP: Improve osm charms .stestr cover release \ No newline at end of file diff --git a/installers/charm/nbi/.jujuignore b/installers/charm/nbi/.jujuignore index bf04eb47..3ae3e7dc 100644 --- a/installers/charm/nbi/.jujuignore +++ b/installers/charm/nbi/.jujuignore @@ -22,7 +22,13 @@ venv .vscode build -prometheus.charm +*.charm .coverage +coverage.xml +.gitignore .stestr cover +release +tests/ +requirements* +tox.ini diff --git a/installers/charm/nbi/requirements-test.txt b/installers/charm/nbi/requirements-test.txt index d7585f3e..cf61dd4e 100644 --- a/installers/charm/nbi/requirements-test.txt +++ b/installers/charm/nbi/requirements-test.txt @@ -17,15 +17,4 @@ # # To get in touch with the maintainers, please contact: # osm-charmers@lists.launchpad.net -## --r requirements.txt -coverage -stestr -mock -black -yamllint -flake8 -safety -requests-mock -asynctest -nose2 \ No newline at end of file +mock==4.0.3 diff --git a/installers/charm/nbi/src/charm.py b/installers/charm/nbi/src/charm.py index 9d62fe2f..7efc5b0d 100755 --- a/installers/charm/nbi/src/charm.py +++ b/installers/charm/nbi/src/charm.py @@ -23,32 +23,25 @@ # pylint: disable=E0213 -import logging -from typing import Optional, NoReturn from ipaddress import ip_network +import logging +from typing import NoReturn, Optional from urllib.parse import urlparse -from ops.main import main +from ops.main import main from opslib.osm.charm import CharmedOsmBase, RelationsMissing - +from opslib.osm.interfaces.http import HttpServer +from opslib.osm.interfaces.kafka import KafkaClient +from opslib.osm.interfaces.keystone import KeystoneClient +from opslib.osm.interfaces.mongo import MongoClient +from opslib.osm.interfaces.prometheus import PrometheusClient from opslib.osm.pod import ( ContainerV3Builder, - PodSpecV3Builder, IngressResourceV3Builder, + PodSpecV3Builder, ) - - -from opslib.osm.validator import ( - ModelValidator, - validator, -) - -from opslib.osm.interfaces.kafka import KafkaClient -from opslib.osm.interfaces.mongo import MongoClient -from opslib.osm.interfaces.prometheus import PrometheusClient -from opslib.osm.interfaces.keystone import KeystoneClient -from opslib.osm.interfaces.http import HttpServer +from opslib.osm.validator import ModelValidator, validator logger = logging.getLogger(__name__) diff --git a/installers/charm/nbi/tests/__init__.py b/installers/charm/nbi/tests/__init__.py index d0d973ae..ee5553b0 100644 --- a/installers/charm/nbi/tests/__init__.py +++ b/installers/charm/nbi/tests/__init__.py @@ -23,6 +23,7 @@ """Init mocking for unit tests.""" import sys + import mock sys.path.append("src") diff --git a/installers/charm/nbi/tests/test_charm.py b/installers/charm/nbi/tests/test_charm.py index be24aa6d..c4e857fe 100644 --- a/installers/charm/nbi/tests/test_charm.py +++ b/installers/charm/nbi/tests/test_charm.py @@ -23,10 +23,11 @@ import sys from typing import NoReturn import unittest -from ops.model import ActiveStatus, BlockedStatus -from ops.testing import Harness + from charm import NbiCharm +from ops.model import ActiveStatus, BlockedStatus +from ops.testing import Harness class TestCharm(unittest.TestCase): diff --git a/installers/charm/nbi/tox.ini b/installers/charm/nbi/tox.ini index 1f9442e3..30e0ea8c 100644 --- a/installers/charm/nbi/tox.ini +++ b/installers/charm/nbi/tox.ini @@ -21,21 +21,32 @@ ####################################################################################### [tox] -envlist = flake8, cover, pylint, safety, yamllint -skipsdist = True +envlist = black, cover, flake8, pylint, yamllint, safety +skipsdist = true + +[tox:jenkins] +toxworkdir = /tmp/.tox [testenv] basepython = python3.8 -setenv = - VIRTUAL_ENV={envdir} - PYTHONHASHSEED=0 - PYTHONPATH = {toxinidir}/src +setenv = VIRTUAL_ENV={envdir} + PYTHONDONTWRITEBYTECODE = 1 deps = -r{toxinidir}/requirements.txt + +####################################################################################### +[testenv:black] +deps = black +commands = + black --check --diff src/ tests/ + + ####################################################################################### [testenv:cover] deps = {[testenv]deps} -r{toxinidir}/requirements-test.txt + coverage + nose2 commands = sh -c 'rm -f nosetests.xml' coverage erase @@ -45,36 +56,34 @@ commands = coverage xml -o coverage.xml --omit=*tests* whitelist_externals = sh -####################################################################################### -[testenv:safety] -setenv = - LC_ALL=C.UTF-8 - LANG=C.UTF-8 -deps = {[testenv]deps} - -r{toxinidir}/requirements-test.txt -commands = - - safety check --full-report ####################################################################################### [testenv:flake8] -deps = flake8 +deps = flake8 + flake8-import-order commands = flake8 src/ tests/ + ####################################################################################### [testenv:pylint] deps = {[testenv]deps} -r{toxinidir}/requirements-test.txt pylint commands = - pylint -E src + pylint -E src/ tests/ + ####################################################################################### -[testenv:black] +[testenv:safety] +setenv = + LC_ALL=C.UTF-8 + LANG=C.UTF-8 deps = {[testenv]deps} - -r{toxinidir}/requirements-test.txt - black -commands = black --check --diff . --exclude "build/|.tox/|mod/|lib/" + safety +commands = + - safety check --full-report + ####################################################################################### [testenv:yamllint] @@ -86,9 +95,7 @@ commands = yamllint . ####################################################################################### [testenv:build] passenv=HTTP_PROXY HTTPS_PROXY NO_PROXY -deps = {[testenv]deps} - -r{toxinidir}/requirements-test.txt - charmcraft +deps = charmcraft whitelist_externals = charmcraft cp @@ -112,4 +119,5 @@ exclude = max-line-length = 120 show-source = True builtins = _ - +max-complexity = 10 +import-order-style = google diff --git a/installers/charm/ng-ui/.gitignore b/installers/charm/ng-ui/.gitignore index ecfb4dc1..493739ef 100644 --- a/installers/charm/ng-ui/.gitignore +++ b/installers/charm/ng-ui/.gitignore @@ -22,16 +22,9 @@ venv .vscode build -<<<<<<< HEAD -ng-ui.charm -.stestr -.coverage* -cover/ -======= *.charm .coverage coverage.xml .stestr cover release ->>>>>>> WIP: Improve osm charms diff --git a/installers/charm/ng-ui/.jujuignore b/installers/charm/ng-ui/.jujuignore index bf04eb47..3ae3e7dc 100644 --- a/installers/charm/ng-ui/.jujuignore +++ b/installers/charm/ng-ui/.jujuignore @@ -22,7 +22,13 @@ venv .vscode build -prometheus.charm +*.charm .coverage +coverage.xml +.gitignore .stestr cover +release +tests/ +requirements* +tox.ini diff --git a/installers/charm/ng-ui/requirements-test.txt b/installers/charm/ng-ui/requirements-test.txt index d7585f3e..cf61dd4e 100644 --- a/installers/charm/ng-ui/requirements-test.txt +++ b/installers/charm/ng-ui/requirements-test.txt @@ -17,15 +17,4 @@ # # To get in touch with the maintainers, please contact: # osm-charmers@lists.launchpad.net -## --r requirements.txt -coverage -stestr -mock -black -yamllint -flake8 -safety -requests-mock -asynctest -nose2 \ No newline at end of file +mock==4.0.3 diff --git a/installers/charm/ng-ui/src/charm.py b/installers/charm/ng-ui/src/charm.py index 4d2bb85d..bf301f32 100755 --- a/installers/charm/ng-ui/src/charm.py +++ b/installers/charm/ng-ui/src/charm.py @@ -23,32 +23,25 @@ # pylint: disable=E0213 -import logging -from typing import Optional, NoReturn from ipaddress import ip_network +import logging +from pathlib import Path +from string import Template +from typing import NoReturn, Optional from urllib.parse import urlparse from ops.main import main - from opslib.osm.charm import CharmedOsmBase, RelationsMissing - +from opslib.osm.interfaces.http import HttpClient from opslib.osm.pod import ( ContainerV3Builder, - PodSpecV3Builder, FilesV3Builder, IngressResourceV3Builder, + PodSpecV3Builder, ) +from opslib.osm.validator import ModelValidator, validator -from opslib.osm.validator import ( - ModelValidator, - validator, -) - -from opslib.osm.interfaces.http import HttpClient -from string import Template -from pathlib import Path - logger = logging.getLogger(__name__) diff --git a/installers/charm/ng-ui/tests/__init__.py b/installers/charm/ng-ui/tests/__init__.py index d0d973ae..ca37e3b9 100644 --- a/installers/charm/ng-ui/tests/__init__.py +++ b/installers/charm/ng-ui/tests/__init__.py @@ -23,6 +23,8 @@ """Init mocking for unit tests.""" import sys + + import mock sys.path.append("src") diff --git a/installers/charm/ng-ui/tests/test_charm.py b/installers/charm/ng-ui/tests/test_charm.py index d9a4d3e6..5b5327bc 100644 --- a/installers/charm/ng-ui/tests/test_charm.py +++ b/installers/charm/ng-ui/tests/test_charm.py @@ -23,10 +23,10 @@ import sys from typing import NoReturn import unittest -from ops.model import ActiveStatus, BlockedStatus -from ops.testing import Harness from charm import NgUiCharm +from ops.model import ActiveStatus, BlockedStatus +from ops.testing import Harness class TestCharm(unittest.TestCase): diff --git a/installers/charm/ng-ui/tox.ini b/installers/charm/ng-ui/tox.ini index 1f9442e3..dc4074f2 100644 --- a/installers/charm/ng-ui/tox.ini +++ b/installers/charm/ng-ui/tox.ini @@ -21,21 +21,32 @@ ####################################################################################### [tox] -envlist = flake8, cover, pylint, safety, yamllint -skipsdist = True +envlist = black, cover, flake8, pylint, yamllint, safety +skipsdist = true + +[tox:jenkins] +toxworkdir = /tmp/.tox [testenv] basepython = python3.8 -setenv = - VIRTUAL_ENV={envdir} - PYTHONHASHSEED=0 - PYTHONPATH = {toxinidir}/src +setenv = VIRTUAL_ENV={envdir} + PYTHONDONTWRITEBYTECODE = 1 deps = -r{toxinidir}/requirements.txt + +####################################################################################### +[testenv:black] +deps = black +commands = + black --check --diff src/ tests/ + + ####################################################################################### [testenv:cover] deps = {[testenv]deps} -r{toxinidir}/requirements-test.txt + coverage + nose2 commands = sh -c 'rm -f nosetests.xml' coverage erase @@ -45,21 +56,14 @@ commands = coverage xml -o coverage.xml --omit=*tests* whitelist_externals = sh -####################################################################################### -[testenv:safety] -setenv = - LC_ALL=C.UTF-8 - LANG=C.UTF-8 -deps = {[testenv]deps} - -r{toxinidir}/requirements-test.txt -commands = - - safety check --full-report ####################################################################################### [testenv:flake8] -deps = flake8 +deps = flake8 + flake8-import-order commands = - flake8 src/ tests/ + flake8 src/ tests/ --exclude=*pod_spec* + ####################################################################################### [testenv:pylint] @@ -67,14 +71,19 @@ deps = {[testenv]deps} -r{toxinidir}/requirements-test.txt pylint commands = - pylint -E src + pylint -E src/ tests/ + ####################################################################################### -[testenv:black] +[testenv:safety] +setenv = + LC_ALL=C.UTF-8 + LANG=C.UTF-8 deps = {[testenv]deps} - -r{toxinidir}/requirements-test.txt - black -commands = black --check --diff . --exclude "build/|.tox/|mod/|lib/" + safety +commands = + - safety check --full-report + ####################################################################################### [testenv:yamllint] @@ -86,9 +95,7 @@ commands = yamllint . ####################################################################################### [testenv:build] passenv=HTTP_PROXY HTTPS_PROXY NO_PROXY -deps = {[testenv]deps} - -r{toxinidir}/requirements-test.txt - charmcraft +deps = charmcraft whitelist_externals = charmcraft cp @@ -112,4 +119,5 @@ exclude = max-line-length = 120 show-source = True builtins = _ - +max-complexity = 10 +import-order-style = google diff --git a/installers/charm/pla/.jujuignore b/installers/charm/pla/.jujuignore index bf04eb47..3ae3e7dc 100644 --- a/installers/charm/pla/.jujuignore +++ b/installers/charm/pla/.jujuignore @@ -22,7 +22,13 @@ venv .vscode build -prometheus.charm +*.charm .coverage +coverage.xml +.gitignore .stestr cover +release +tests/ +requirements* +tox.ini diff --git a/installers/charm/pla/requirements-test.txt b/installers/charm/pla/requirements-test.txt index d7585f3e..cf61dd4e 100644 --- a/installers/charm/pla/requirements-test.txt +++ b/installers/charm/pla/requirements-test.txt @@ -17,15 +17,4 @@ # # To get in touch with the maintainers, please contact: # osm-charmers@lists.launchpad.net -## --r requirements.txt -coverage -stestr -mock -black -yamllint -flake8 -safety -requests-mock -asynctest -nose2 \ No newline at end of file +mock==4.0.3 diff --git a/installers/charm/pla/src/charm.py b/installers/charm/pla/src/charm.py index 4f463bf6..15ae0958 100755 --- a/installers/charm/pla/src/charm.py +++ b/installers/charm/pla/src/charm.py @@ -27,21 +27,14 @@ import logging from typing import NoReturn from ops.main import main - from opslib.osm.charm import CharmedOsmBase, RelationsMissing - +from opslib.osm.interfaces.kafka import KafkaClient +from opslib.osm.interfaces.mongo import MongoClient from opslib.osm.pod import ( ContainerV3Builder, PodSpecV3Builder, ) - -from opslib.osm.validator import ( - ModelValidator, - validator, -) - -from opslib.osm.interfaces.kafka import KafkaClient -from opslib.osm.interfaces.mongo import MongoClient +from opslib.osm.validator import ModelValidator, validator logger = logging.getLogger(__name__) diff --git a/installers/charm/pla/tests/__init__.py b/installers/charm/pla/tests/__init__.py index d0d973ae..ca37e3b9 100644 --- a/installers/charm/pla/tests/__init__.py +++ b/installers/charm/pla/tests/__init__.py @@ -23,6 +23,8 @@ """Init mocking for unit tests.""" import sys + + import mock sys.path.append("src") diff --git a/installers/charm/pla/tests/test_charm.py b/installers/charm/pla/tests/test_charm.py index b1a78203..80cb3158 100644 --- a/installers/charm/pla/tests/test_charm.py +++ b/installers/charm/pla/tests/test_charm.py @@ -23,10 +23,11 @@ import sys from typing import NoReturn import unittest -from ops.model import ActiveStatus, BlockedStatus -from ops.testing import Harness + from charm import PlaCharm +from ops.model import ActiveStatus, BlockedStatus +from ops.testing import Harness class TestCharm(unittest.TestCase): diff --git a/installers/charm/pla/tox.ini b/installers/charm/pla/tox.ini index 1f9442e3..30e0ea8c 100644 --- a/installers/charm/pla/tox.ini +++ b/installers/charm/pla/tox.ini @@ -21,21 +21,32 @@ ####################################################################################### [tox] -envlist = flake8, cover, pylint, safety, yamllint -skipsdist = True +envlist = black, cover, flake8, pylint, yamllint, safety +skipsdist = true + +[tox:jenkins] +toxworkdir = /tmp/.tox [testenv] basepython = python3.8 -setenv = - VIRTUAL_ENV={envdir} - PYTHONHASHSEED=0 - PYTHONPATH = {toxinidir}/src +setenv = VIRTUAL_ENV={envdir} + PYTHONDONTWRITEBYTECODE = 1 deps = -r{toxinidir}/requirements.txt + +####################################################################################### +[testenv:black] +deps = black +commands = + black --check --diff src/ tests/ + + ####################################################################################### [testenv:cover] deps = {[testenv]deps} -r{toxinidir}/requirements-test.txt + coverage + nose2 commands = sh -c 'rm -f nosetests.xml' coverage erase @@ -45,36 +56,34 @@ commands = coverage xml -o coverage.xml --omit=*tests* whitelist_externals = sh -####################################################################################### -[testenv:safety] -setenv = - LC_ALL=C.UTF-8 - LANG=C.UTF-8 -deps = {[testenv]deps} - -r{toxinidir}/requirements-test.txt -commands = - - safety check --full-report ####################################################################################### [testenv:flake8] -deps = flake8 +deps = flake8 + flake8-import-order commands = flake8 src/ tests/ + ####################################################################################### [testenv:pylint] deps = {[testenv]deps} -r{toxinidir}/requirements-test.txt pylint commands = - pylint -E src + pylint -E src/ tests/ + ####################################################################################### -[testenv:black] +[testenv:safety] +setenv = + LC_ALL=C.UTF-8 + LANG=C.UTF-8 deps = {[testenv]deps} - -r{toxinidir}/requirements-test.txt - black -commands = black --check --diff . --exclude "build/|.tox/|mod/|lib/" + safety +commands = + - safety check --full-report + ####################################################################################### [testenv:yamllint] @@ -86,9 +95,7 @@ commands = yamllint . ####################################################################################### [testenv:build] passenv=HTTP_PROXY HTTPS_PROXY NO_PROXY -deps = {[testenv]deps} - -r{toxinidir}/requirements-test.txt - charmcraft +deps = charmcraft whitelist_externals = charmcraft cp @@ -112,4 +119,5 @@ exclude = max-line-length = 120 show-source = True builtins = _ - +max-complexity = 10 +import-order-style = google diff --git a/installers/charm/pol/.jujuignore b/installers/charm/pol/.jujuignore index bf04eb47..3ae3e7dc 100644 --- a/installers/charm/pol/.jujuignore +++ b/installers/charm/pol/.jujuignore @@ -22,7 +22,13 @@ venv .vscode build -prometheus.charm +*.charm .coverage +coverage.xml +.gitignore .stestr cover +release +tests/ +requirements* +tox.ini diff --git a/installers/charm/pol/requirements-test.txt b/installers/charm/pol/requirements-test.txt index d7585f3e..cf61dd4e 100644 --- a/installers/charm/pol/requirements-test.txt +++ b/installers/charm/pol/requirements-test.txt @@ -17,15 +17,4 @@ # # To get in touch with the maintainers, please contact: # osm-charmers@lists.launchpad.net -## --r requirements.txt -coverage -stestr -mock -black -yamllint -flake8 -safety -requests-mock -asynctest -nose2 \ No newline at end of file +mock==4.0.3 diff --git a/installers/charm/pol/src/charm.py b/installers/charm/pol/src/charm.py index ce1a25e5..d339e1ce 100755 --- a/installers/charm/pol/src/charm.py +++ b/installers/charm/pol/src/charm.py @@ -27,21 +27,14 @@ import logging from typing import NoReturn from ops.main import main - from opslib.osm.charm import CharmedOsmBase, RelationsMissing - +from opslib.osm.interfaces.kafka import KafkaClient +from opslib.osm.interfaces.mongo import MongoClient from opslib.osm.pod import ( ContainerV3Builder, PodSpecV3Builder, ) - -from opslib.osm.validator import ( - ModelValidator, - validator, -) - -from opslib.osm.interfaces.kafka import KafkaClient -from opslib.osm.interfaces.mongo import MongoClient +from opslib.osm.validator import ModelValidator, validator logger = logging.getLogger(__name__) diff --git a/installers/charm/pol/tests/__init__.py b/installers/charm/pol/tests/__init__.py index d0d973ae..ca37e3b9 100644 --- a/installers/charm/pol/tests/__init__.py +++ b/installers/charm/pol/tests/__init__.py @@ -23,6 +23,8 @@ """Init mocking for unit tests.""" import sys + + import mock sys.path.append("src") diff --git a/installers/charm/pol/tests/test_charm.py b/installers/charm/pol/tests/test_charm.py index 22143978..32b1acd6 100644 --- a/installers/charm/pol/tests/test_charm.py +++ b/installers/charm/pol/tests/test_charm.py @@ -23,10 +23,10 @@ import sys from typing import NoReturn import unittest -from ops.model import ActiveStatus, BlockedStatus -from ops.testing import Harness from charm import PolCharm +from ops.model import ActiveStatus, BlockedStatus +from ops.testing import Harness class TestCharm(unittest.TestCase): diff --git a/installers/charm/pol/tox.ini b/installers/charm/pol/tox.ini index 1f9442e3..30e0ea8c 100644 --- a/installers/charm/pol/tox.ini +++ b/installers/charm/pol/tox.ini @@ -21,21 +21,32 @@ ####################################################################################### [tox] -envlist = flake8, cover, pylint, safety, yamllint -skipsdist = True +envlist = black, cover, flake8, pylint, yamllint, safety +skipsdist = true + +[tox:jenkins] +toxworkdir = /tmp/.tox [testenv] basepython = python3.8 -setenv = - VIRTUAL_ENV={envdir} - PYTHONHASHSEED=0 - PYTHONPATH = {toxinidir}/src +setenv = VIRTUAL_ENV={envdir} + PYTHONDONTWRITEBYTECODE = 1 deps = -r{toxinidir}/requirements.txt + +####################################################################################### +[testenv:black] +deps = black +commands = + black --check --diff src/ tests/ + + ####################################################################################### [testenv:cover] deps = {[testenv]deps} -r{toxinidir}/requirements-test.txt + coverage + nose2 commands = sh -c 'rm -f nosetests.xml' coverage erase @@ -45,36 +56,34 @@ commands = coverage xml -o coverage.xml --omit=*tests* whitelist_externals = sh -####################################################################################### -[testenv:safety] -setenv = - LC_ALL=C.UTF-8 - LANG=C.UTF-8 -deps = {[testenv]deps} - -r{toxinidir}/requirements-test.txt -commands = - - safety check --full-report ####################################################################################### [testenv:flake8] -deps = flake8 +deps = flake8 + flake8-import-order commands = flake8 src/ tests/ + ####################################################################################### [testenv:pylint] deps = {[testenv]deps} -r{toxinidir}/requirements-test.txt pylint commands = - pylint -E src + pylint -E src/ tests/ + ####################################################################################### -[testenv:black] +[testenv:safety] +setenv = + LC_ALL=C.UTF-8 + LANG=C.UTF-8 deps = {[testenv]deps} - -r{toxinidir}/requirements-test.txt - black -commands = black --check --diff . --exclude "build/|.tox/|mod/|lib/" + safety +commands = + - safety check --full-report + ####################################################################################### [testenv:yamllint] @@ -86,9 +95,7 @@ commands = yamllint . ####################################################################################### [testenv:build] passenv=HTTP_PROXY HTTPS_PROXY NO_PROXY -deps = {[testenv]deps} - -r{toxinidir}/requirements-test.txt - charmcraft +deps = charmcraft whitelist_externals = charmcraft cp @@ -112,4 +119,5 @@ exclude = max-line-length = 120 show-source = True builtins = _ - +max-complexity = 10 +import-order-style = google diff --git a/installers/charm/prometheus/.jujuignore b/installers/charm/prometheus/.jujuignore index bf04eb47..3ae3e7dc 100644 --- a/installers/charm/prometheus/.jujuignore +++ b/installers/charm/prometheus/.jujuignore @@ -22,7 +22,13 @@ venv .vscode build -prometheus.charm +*.charm .coverage +coverage.xml +.gitignore .stestr cover +release +tests/ +requirements* +tox.ini diff --git a/installers/charm/prometheus/requirements-test.txt b/installers/charm/prometheus/requirements-test.txt index d7585f3e..cf61dd4e 100644 --- a/installers/charm/prometheus/requirements-test.txt +++ b/installers/charm/prometheus/requirements-test.txt @@ -17,15 +17,4 @@ # # To get in touch with the maintainers, please contact: # osm-charmers@lists.launchpad.net -## --r requirements.txt -coverage -stestr -mock -black -yamllint -flake8 -safety -requests-mock -asynctest -nose2 \ No newline at end of file +mock==4.0.3 diff --git a/installers/charm/prometheus/src/charm.py b/installers/charm/prometheus/src/charm.py index 3d72cace..47533ddf 100755 --- a/installers/charm/prometheus/src/charm.py +++ b/installers/charm/prometheus/src/charm.py @@ -22,30 +22,26 @@ # pylint: disable=E0213 -import logging -from typing import Optional, NoReturn from ipaddress import ip_network +import logging +from typing import NoReturn, Optional +from urllib.parse import urlparse from ops.framework import EventBase from ops.main import main - from opslib.osm.charm import CharmedOsmBase - +from opslib.osm.interfaces.prometheus import PrometheusServer from opslib.osm.pod import ( - IngressResourceV3Builder, - FilesV3Builder, ContainerV3Builder, + FilesV3Builder, + IngressResourceV3Builder, PodSpecV3Builder, ) - - from opslib.osm.validator import ( ModelValidator, validator, ) -from opslib.osm.interfaces.prometheus import PrometheusServer -from urllib.parse import urlparse logger = logging.getLogger(__name__) diff --git a/installers/charm/prometheus/tests/__init__.py b/installers/charm/prometheus/tests/__init__.py index d0d973ae..ca37e3b9 100644 --- a/installers/charm/prometheus/tests/__init__.py +++ b/installers/charm/prometheus/tests/__init__.py @@ -23,6 +23,8 @@ """Init mocking for unit tests.""" import sys + + import mock sys.path.append("src") diff --git a/installers/charm/prometheus/tests/test_charm.py b/installers/charm/prometheus/tests/test_charm.py index b1848bdd..dd8b732c 100644 --- a/installers/charm/prometheus/tests/test_charm.py +++ b/installers/charm/prometheus/tests/test_charm.py @@ -23,10 +23,10 @@ import sys from typing import NoReturn import unittest -from ops.model import ActiveStatus -from ops.testing import Harness from charm import PrometheusCharm +from ops.model import ActiveStatus +from ops.testing import Harness class TestCharm(unittest.TestCase): diff --git a/installers/charm/prometheus/tox.ini b/installers/charm/prometheus/tox.ini index 1f9442e3..30e0ea8c 100644 --- a/installers/charm/prometheus/tox.ini +++ b/installers/charm/prometheus/tox.ini @@ -21,21 +21,32 @@ ####################################################################################### [tox] -envlist = flake8, cover, pylint, safety, yamllint -skipsdist = True +envlist = black, cover, flake8, pylint, yamllint, safety +skipsdist = true + +[tox:jenkins] +toxworkdir = /tmp/.tox [testenv] basepython = python3.8 -setenv = - VIRTUAL_ENV={envdir} - PYTHONHASHSEED=0 - PYTHONPATH = {toxinidir}/src +setenv = VIRTUAL_ENV={envdir} + PYTHONDONTWRITEBYTECODE = 1 deps = -r{toxinidir}/requirements.txt + +####################################################################################### +[testenv:black] +deps = black +commands = + black --check --diff src/ tests/ + + ####################################################################################### [testenv:cover] deps = {[testenv]deps} -r{toxinidir}/requirements-test.txt + coverage + nose2 commands = sh -c 'rm -f nosetests.xml' coverage erase @@ -45,36 +56,34 @@ commands = coverage xml -o coverage.xml --omit=*tests* whitelist_externals = sh -####################################################################################### -[testenv:safety] -setenv = - LC_ALL=C.UTF-8 - LANG=C.UTF-8 -deps = {[testenv]deps} - -r{toxinidir}/requirements-test.txt -commands = - - safety check --full-report ####################################################################################### [testenv:flake8] -deps = flake8 +deps = flake8 + flake8-import-order commands = flake8 src/ tests/ + ####################################################################################### [testenv:pylint] deps = {[testenv]deps} -r{toxinidir}/requirements-test.txt pylint commands = - pylint -E src + pylint -E src/ tests/ + ####################################################################################### -[testenv:black] +[testenv:safety] +setenv = + LC_ALL=C.UTF-8 + LANG=C.UTF-8 deps = {[testenv]deps} - -r{toxinidir}/requirements-test.txt - black -commands = black --check --diff . --exclude "build/|.tox/|mod/|lib/" + safety +commands = + - safety check --full-report + ####################################################################################### [testenv:yamllint] @@ -86,9 +95,7 @@ commands = yamllint . ####################################################################################### [testenv:build] passenv=HTTP_PROXY HTTPS_PROXY NO_PROXY -deps = {[testenv]deps} - -r{toxinidir}/requirements-test.txt - charmcraft +deps = charmcraft whitelist_externals = charmcraft cp @@ -112,4 +119,5 @@ exclude = max-line-length = 120 show-source = True builtins = _ - +max-complexity = 10 +import-order-style = google diff --git a/installers/charm/ro/.jujuignore b/installers/charm/ro/.jujuignore index bf04eb47..3ae3e7dc 100644 --- a/installers/charm/ro/.jujuignore +++ b/installers/charm/ro/.jujuignore @@ -22,7 +22,13 @@ venv .vscode build -prometheus.charm +*.charm .coverage +coverage.xml +.gitignore .stestr cover +release +tests/ +requirements* +tox.ini diff --git a/installers/charm/ro/requirements-test.txt b/installers/charm/ro/requirements-test.txt index 1da01c85..cf61dd4e 100644 --- a/installers/charm/ro/requirements-test.txt +++ b/installers/charm/ro/requirements-test.txt @@ -17,14 +17,4 @@ # # To get in touch with the maintainers, please contact: # osm-charmers@lists.launchpad.net --r requirements.txt -coverage -stestr -mock -black -yamllint -flake8 -safety -requests-mock -asynctest -nose2 \ No newline at end of file +mock==4.0.3 diff --git a/installers/charm/ro/src/charm.py b/installers/charm/ro/src/charm.py index ae92d983..6851600c 100755 --- a/installers/charm/ro/src/charm.py +++ b/installers/charm/ro/src/charm.py @@ -26,23 +26,15 @@ import logging from typing import NoReturn from ops.main import main - from opslib.osm.charm import CharmedOsmBase, RelationsMissing - +from opslib.osm.interfaces.kafka import KafkaClient +from opslib.osm.interfaces.mongo import MongoClient +from opslib.osm.interfaces.mysql import MysqlClient from opslib.osm.pod import ( ContainerV3Builder, PodSpecV3Builder, ) - - -from opslib.osm.validator import ( - ModelValidator, - validator, -) - -from opslib.osm.interfaces.kafka import KafkaClient -from opslib.osm.interfaces.mysql import MysqlClient -from opslib.osm.interfaces.mongo import MongoClient +from opslib.osm.validator import ModelValidator, validator logger = logging.getLogger(__name__) diff --git a/installers/charm/ro/tests/__init__.py b/installers/charm/ro/tests/__init__.py index d0d973ae..ca37e3b9 100644 --- a/installers/charm/ro/tests/__init__.py +++ b/installers/charm/ro/tests/__init__.py @@ -23,6 +23,8 @@ """Init mocking for unit tests.""" import sys + + import mock sys.path.append("src") diff --git a/installers/charm/ro/tests/test_charm.py b/installers/charm/ro/tests/test_charm.py index 4f14aff8..4610b259 100644 --- a/installers/charm/ro/tests/test_charm.py +++ b/installers/charm/ro/tests/test_charm.py @@ -23,10 +23,10 @@ import sys from typing import NoReturn import unittest -from ops.model import ActiveStatus, BlockedStatus -from ops.testing import Harness from charm import RoCharm +from ops.model import ActiveStatus, BlockedStatus +from ops.testing import Harness class TestCharm(unittest.TestCase): diff --git a/installers/charm/ro/tox.ini b/installers/charm/ro/tox.ini index 1f9442e3..30e0ea8c 100644 --- a/installers/charm/ro/tox.ini +++ b/installers/charm/ro/tox.ini @@ -21,21 +21,32 @@ ####################################################################################### [tox] -envlist = flake8, cover, pylint, safety, yamllint -skipsdist = True +envlist = black, cover, flake8, pylint, yamllint, safety +skipsdist = true + +[tox:jenkins] +toxworkdir = /tmp/.tox [testenv] basepython = python3.8 -setenv = - VIRTUAL_ENV={envdir} - PYTHONHASHSEED=0 - PYTHONPATH = {toxinidir}/src +setenv = VIRTUAL_ENV={envdir} + PYTHONDONTWRITEBYTECODE = 1 deps = -r{toxinidir}/requirements.txt + +####################################################################################### +[testenv:black] +deps = black +commands = + black --check --diff src/ tests/ + + ####################################################################################### [testenv:cover] deps = {[testenv]deps} -r{toxinidir}/requirements-test.txt + coverage + nose2 commands = sh -c 'rm -f nosetests.xml' coverage erase @@ -45,36 +56,34 @@ commands = coverage xml -o coverage.xml --omit=*tests* whitelist_externals = sh -####################################################################################### -[testenv:safety] -setenv = - LC_ALL=C.UTF-8 - LANG=C.UTF-8 -deps = {[testenv]deps} - -r{toxinidir}/requirements-test.txt -commands = - - safety check --full-report ####################################################################################### [testenv:flake8] -deps = flake8 +deps = flake8 + flake8-import-order commands = flake8 src/ tests/ + ####################################################################################### [testenv:pylint] deps = {[testenv]deps} -r{toxinidir}/requirements-test.txt pylint commands = - pylint -E src + pylint -E src/ tests/ + ####################################################################################### -[testenv:black] +[testenv:safety] +setenv = + LC_ALL=C.UTF-8 + LANG=C.UTF-8 deps = {[testenv]deps} - -r{toxinidir}/requirements-test.txt - black -commands = black --check --diff . --exclude "build/|.tox/|mod/|lib/" + safety +commands = + - safety check --full-report + ####################################################################################### [testenv:yamllint] @@ -86,9 +95,7 @@ commands = yamllint . ####################################################################################### [testenv:build] passenv=HTTP_PROXY HTTPS_PROXY NO_PROXY -deps = {[testenv]deps} - -r{toxinidir}/requirements-test.txt - charmcraft +deps = charmcraft whitelist_externals = charmcraft cp @@ -112,4 +119,5 @@ exclude = max-line-length = 120 show-source = True builtins = _ - +max-complexity = 10 +import-order-style = google diff --git a/installers/charmed_install.sh b/installers/charmed_install.sh index e1967061..b36d582d 100755 --- a/installers/charmed_install.sh +++ b/installers/charmed_install.sh @@ -25,8 +25,8 @@ PATH=/snap/bin:${PATH} MODEL_NAME=osm -OSM_BUNDLE=cs:osm-58 -OSM_HA_BUNDLE=cs:osm-ha-43 +OSM_BUNDLE=cs:osm-60 +OSM_HA_BUNDLE=cs:osm-ha-45 TAG=testing-daily function check_arguments(){ @@ -306,7 +306,7 @@ function create_overlay() { sudo snap install yq local HOME=/home/$USER local vca_user=$(cat $HOME/.local/share/juju/accounts.yaml | yq e .controllers.$CONTROLLER_NAME.user - ) - local vca_password=$(cat $HOME/.local/share/juju/accounts.yaml | yq e .controllers.$CONTROLLER_NAME.password - ) + local vca_secret=$(cat $HOME/.local/share/juju/accounts.yaml | yq e .controllers.$CONTROLLER_NAME.password - ) local vca_host=$(cat $HOME/.local/share/juju/controllers.yaml | yq e .controllers.$CONTROLLER_NAME.api-endpoints[0] - | cut -d ":" -f 1) local vca_port=$(cat $HOME/.local/share/juju/controllers.yaml | yq e .controllers.$CONTROLLER_NAME.api-endpoints[0] - | cut -d ":" -f 2) local vca_pubkey=\"$(cat $HOME/.local/share/juju/ssh/juju_id_rsa.pub)\" @@ -323,7 +323,7 @@ applications: lcm: options: vca_user: $vca_user - vca_password: $vca_password + vca_secret: $vca_secret vca_host: $vca_host vca_port: $vca_port vca_pubkey: $vca_pubkey @@ -333,7 +333,7 @@ applications: mon: options: vca_user: $vca_user - vca_password: $vca_password + vca_secret: $vca_secret vca_host: $vca_host vca_cacert: $vca_cacert EOF -- 2.25.1