From d680be4f261d4c580fcdf75abe11cfc29003915d Mon Sep 17 00:00:00 2001 From: David Garcia Date: Tue, 17 Aug 2021 11:03:55 +0200 Subject: [PATCH] Add charmcraft.yaml debug_mode to charmed-osm - Added a debug_mode option to lcm, mon, nbi, pol, and ro charms - Added a script to prepare pods for debugging: - setup .ssh/config to easily ssh from vscode to the pods - Added a README that explains how to prepare the environment for testing Change-Id: Ieb56b565c15e61c68ad000b60897abd27e1eeb0e Signed-off-by: David Garcia --- installers/charm/build.sh | 10 +- installers/charm/bundles/osm-ha/bundle.yaml | 20 ++-- installers/charm/bundles/osm/bundle.yaml | 20 ++-- installers/charm/grafana/charmcraft.yaml | 37 ++++++ installers/charm/grafana/src/charm.py | 14 +-- .../default_dashboards.yaml | 0 .../default_datasources.yaml | 0 .../kafka_exporter_dashboard.json | 0 .../mongodb_exporter_dashboard.json | 0 .../mysql_exporter_dashboard.json | 0 .../nodes_exporter_dashboard.json | 0 .../summary_dashboard.json | 0 installers/charm/grafana/tox.ini | 9 +- .../charm/kafka-exporter/charmcraft.yaml | 37 ++++++ installers/charm/kafka-exporter/src/charm.py | 2 +- .../kafka_exporter_dashboard.json | 0 installers/charm/kafka-exporter/tox.ini | 8 +- installers/charm/keystone/charmcraft.yaml | 37 ++++++ installers/charm/keystone/tox.ini | 8 +- installers/charm/lcm/charmcraft.yaml | 37 ++++++ installers/charm/lcm/config.yaml | 10 ++ installers/charm/lcm/src/charm.py | 31 ++++- installers/charm/lcm/tox.ini | 8 +- installers/charm/mon/charmcraft.yaml | 37 ++++++ installers/charm/mon/config.yaml | 10 ++ installers/charm/mon/src/charm.py | 49 +++++++- installers/charm/mon/tox.ini | 8 +- .../charm/mongodb-exporter/charmcraft.yaml | 37 ++++++ .../charm/mongodb-exporter/src/charm.py | 2 +- .../mongodb_exporter_dashboard.json | 0 installers/charm/mongodb-exporter/tox.ini | 8 +- .../charm/mysqld-exporter/charmcraft.yaml | 37 ++++++ installers/charm/mysqld-exporter/src/charm.py | 2 +- .../mysql_exporter_dashboard.json | 0 installers/charm/mysqld-exporter/tox.ini | 8 +- installers/charm/nbi/charmcraft.yaml | 37 ++++++ installers/charm/nbi/config.yaml | 10 ++ installers/charm/nbi/src/charm.py | 30 ++++- installers/charm/nbi/tox.ini | 8 +- installers/charm/ng-ui/charmcraft.yaml | 37 ++++++ installers/charm/ng-ui/src/charm.py | 2 +- .../default => templates/default.template} | 0 installers/charm/ng-ui/tox.ini | 9 +- installers/charm/pla/charmcraft.yaml | 37 ++++++ installers/charm/pla/tox.ini | 8 +- installers/charm/pol/charmcraft.yaml | 37 ++++++ installers/charm/pol/config.yaml | 10 ++ installers/charm/pol/src/charm.py | 29 ++++- installers/charm/pol/tox.ini | 8 +- installers/charm/prometheus/charmcraft.yaml | 37 ++++++ installers/charm/prometheus/tox.ini | 9 +- installers/charm/ro/charmcraft.yaml | 37 ++++++ installers/charm/ro/config.yaml | 10 ++ installers/charm/ro/src/charm.py | 45 ++++++- installers/charm/ro/tox.ini | 8 +- tools/debug/charmed/README.md | 113 ++++++++++++++++++ tools/debug/charmed/prepare_pods.sh | 50 ++++++++ 57 files changed, 975 insertions(+), 82 deletions(-) create mode 100644 installers/charm/grafana/charmcraft.yaml rename installers/charm/grafana/{files => templates}/default_dashboards.yaml (100%) rename installers/charm/grafana/{files => templates}/default_datasources.yaml (100%) rename installers/charm/grafana/{files => templates}/kafka_exporter_dashboard.json (100%) rename installers/charm/grafana/{files => templates}/mongodb_exporter_dashboard.json (100%) rename installers/charm/grafana/{files => templates}/mysql_exporter_dashboard.json (100%) rename installers/charm/grafana/{files => templates}/nodes_exporter_dashboard.json (100%) rename installers/charm/grafana/{files => templates}/summary_dashboard.json (100%) create mode 100644 installers/charm/kafka-exporter/charmcraft.yaml rename installers/charm/kafka-exporter/{files => templates}/kafka_exporter_dashboard.json (100%) create mode 100644 installers/charm/keystone/charmcraft.yaml create mode 100644 installers/charm/lcm/charmcraft.yaml create mode 100644 installers/charm/mon/charmcraft.yaml create mode 100644 installers/charm/mongodb-exporter/charmcraft.yaml rename installers/charm/mongodb-exporter/{files => templates}/mongodb_exporter_dashboard.json (100%) create mode 100644 installers/charm/mysqld-exporter/charmcraft.yaml rename installers/charm/mysqld-exporter/{files => templates}/mysql_exporter_dashboard.json (100%) create mode 100644 installers/charm/nbi/charmcraft.yaml create mode 100644 installers/charm/ng-ui/charmcraft.yaml rename installers/charm/ng-ui/{files/default => templates/default.template} (100%) create mode 100644 installers/charm/pla/charmcraft.yaml create mode 100644 installers/charm/pol/charmcraft.yaml create mode 100644 installers/charm/prometheus/charmcraft.yaml create mode 100644 installers/charm/ro/charmcraft.yaml create mode 100644 tools/debug/charmed/README.md create mode 100755 tools/debug/charmed/prepare_pods.sh diff --git a/installers/charm/build.sh b/installers/charm/build.sh index 06a6d65c..65dd87da 100755 --- a/installers/charm/build.sh +++ b/installers/charm/build.sh @@ -14,17 +14,15 @@ # limitations under the License. function build() { - cd $1 && tox -e build && cd .. + cd $1 && tox -qe build && cd .. } -charms="ro nbi pla pol mon lcm ng-ui keystone grafana prometheus keystone mariadb-k8s mongodb-k8s zookeeper-k8s kafka-k8s mongodb-exporter kafka-exporter mysqld-exporter" +charms="ro nbi pla pol mon lcm ng-ui keystone grafana prometheus mariadb-k8s mongodb-k8s zookeeper-k8s kafka-k8s mongodb-exporter kafka-exporter mysqld-exporter" if [ -z `which charmcraft` ]; then sudo snap install charmcraft --edge fi for charm_directory in $charms; do - echo "Building charm $charm_directory..." - # cd $charm_directory - build $charm_directory - # cd .. + build $charm_directory & done +wait \ No newline at end of file diff --git a/installers/charm/bundles/osm-ha/bundle.yaml b/installers/charm/bundles/osm-ha/bundle.yaml index 88115fa4..a7ebc38f 100644 --- a/installers/charm/bundles/osm-ha/bundle.yaml +++ b/installers/charm/bundles/osm-ha/bundle.yaml @@ -78,7 +78,7 @@ applications: gui-x: 0 gui-y: 0 nbi: - charm: "cs:~charmed-osm/nbi-13" + charm: "cs:~charmed-osm/nbi-16" scale: 3 series: kubernetes options: @@ -89,7 +89,7 @@ applications: gui-x: 0 gui-y: -250 ro: - charm: "cs:~charmed-osm/ro-5" + charm: "cs:~charmed-osm/ro-8" scale: 3 series: kubernetes options: @@ -98,14 +98,14 @@ applications: gui-x: -300 gui-y: 250 ng-ui: - charm: "cs:~charmed-osm/ng-ui-22" + charm: "cs:~charmed-osm/ng-ui-23" scale: 3 series: kubernetes annotations: gui-x: 600 gui-y: 0 lcm: - charm: "cs:~charmed-osm/lcm-10" + charm: "cs:~charmed-osm/lcm-13" scale: 3 series: kubernetes options: @@ -115,7 +115,7 @@ applications: gui-x: -300 gui-y: 0 mon: - charm: "cs:~charmed-osm/mon-6" + charm: "cs:~charmed-osm/mon-9" scale: 1 series: kubernetes options: @@ -126,7 +126,7 @@ applications: gui-x: 300 gui-y: 0 pol: - charm: "cs:~charmed-osm/pol-5" + charm: "cs:~charmed-osm/pol-8" scale: 3 series: kubernetes options: @@ -135,7 +135,7 @@ applications: gui-x: -300 gui-y: 500 pla: - charm: "cs:~charmed-osm/pla-10" + charm: "cs:~charmed-osm/pla-11" scale: 3 series: kubernetes options: @@ -144,7 +144,7 @@ applications: gui-x: 600 gui-y: -250 prometheus: - charm: "cs:~charmed-osm/prometheus-5" + charm: "cs:~charmed-osm/prometheus-6" scale: 1 series: kubernetes storage: @@ -155,14 +155,14 @@ applications: gui-x: 300 gui-y: 250 grafana: - charm: "cs:~charmed-osm/grafana-5" + charm: "cs:~charmed-osm/grafana-6" scale: 3 series: kubernetes annotations: gui-x: 300 gui-y: 500 keystone: - charm: "cs:~charmed-osm/keystone-11" + charm: "cs:~charmed-osm/keystone-12" scale: 1 series: kubernetes annotations: diff --git a/installers/charm/bundles/osm/bundle.yaml b/installers/charm/bundles/osm/bundle.yaml index d867f1b7..36322fe2 100644 --- a/installers/charm/bundles/osm/bundle.yaml +++ b/installers/charm/bundles/osm/bundle.yaml @@ -71,7 +71,7 @@ applications: gui-x: 0 gui-y: 0 nbi: - charm: "cs:~charmed-osm/nbi-13" + charm: "cs:~charmed-osm/nbi-16" scale: 1 series: kubernetes options: @@ -82,7 +82,7 @@ applications: gui-x: 0 gui-y: -250 ro: - charm: "cs:~charmed-osm/ro-5" + charm: "cs:~charmed-osm/ro-8" scale: 1 series: kubernetes options: @@ -91,14 +91,14 @@ applications: gui-x: -300 gui-y: 250 ng-ui: - charm: "cs:~charmed-osm/ng-ui-22" + charm: "cs:~charmed-osm/ng-ui-23" scale: 1 series: kubernetes annotations: gui-x: 600 gui-y: 0 lcm: - charm: "cs:~charmed-osm/lcm-10" + charm: "cs:~charmed-osm/lcm-13" scale: 1 series: kubernetes options: @@ -108,7 +108,7 @@ applications: gui-x: -300 gui-y: 0 mon: - charm: "cs:~charmed-osm/mon-6" + charm: "cs:~charmed-osm/mon-9" scale: 1 series: kubernetes options: @@ -119,7 +119,7 @@ applications: gui-x: 300 gui-y: 0 pol: - charm: "cs:~charmed-osm/pol-5" + charm: "cs:~charmed-osm/pol-8" scale: 1 series: kubernetes options: @@ -128,7 +128,7 @@ applications: gui-x: -300 gui-y: 500 pla: - charm: "cs:~charmed-osm/pla-10" + charm: "cs:~charmed-osm/pla-11" scale: 1 series: kubernetes options: @@ -137,7 +137,7 @@ applications: gui-x: 600 gui-y: -250 prometheus: - charm: "cs:~charmed-osm/prometheus-5" + charm: "cs:~charmed-osm/prometheus-6" scale: 1 series: kubernetes storage: @@ -148,14 +148,14 @@ applications: gui-x: 300 gui-y: 250 grafana: - charm: "cs:~charmed-osm/grafana-5" + charm: "cs:~charmed-osm/grafana-6" scale: 1 series: kubernetes annotations: gui-x: 300 gui-y: 500 keystone: - charm: "cs:~charmed-osm/keystone-11" + charm: "cs:~charmed-osm/keystone-12" scale: 1 series: kubernetes annotations: diff --git a/installers/charm/grafana/charmcraft.yaml b/installers/charm/grafana/charmcraft.yaml new file mode 100644 index 00000000..0a285a9d --- /dev/null +++ b/installers/charm/grafana/charmcraft.yaml @@ -0,0 +1,37 @@ +# 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 +## + +type: charm +bases: + - build-on: + - name: ubuntu + channel: "20.04" + architectures: ["amd64"] + run-on: + - name: ubuntu + channel: "20.04" + architectures: + - amd64 + - aarch64 + - arm64 +parts: + charm: + build-packages: [git] diff --git a/installers/charm/grafana/src/charm.py b/installers/charm/grafana/src/charm.py index 9bc612e0..87776aa9 100755 --- a/installers/charm/grafana/src/charm.py +++ b/installers/charm/grafana/src/charm.py @@ -108,15 +108,15 @@ class GrafanaCharm(CharmedOsmBase): files_builder = FilesV3Builder() files_builder.add_file( "dashboard_osm.yaml", - Path("files/default_dashboards.yaml").read_text(), + Path("templates/default_dashboards.yaml").read_text(), ) if config.osm_dashboards: osm_dashboards_mapping = { - "kafka_exporter_dashboard.json": "files/kafka_exporter_dashboard.json", - "mongodb_exporter_dashboard.json": "files/mongodb_exporter_dashboard.json", - "mysql_exporter_dashboard.json": "files/mysql_exporter_dashboard.json", - "nodes_exporter_dashboard.json": "files/nodes_exporter_dashboard.json", - "summary_dashboard.json": "files/summary_dashboard.json", + "kafka_exporter_dashboard.json": "templates/kafka_exporter_dashboard.json", + "mongodb_exporter_dashboard.json": "templates/mongodb_exporter_dashboard.json", + "mysql_exporter_dashboard.json": "templates/mysql_exporter_dashboard.json", + "nodes_exporter_dashboard.json": "templates/nodes_exporter_dashboard.json", + "summary_dashboard.json": "templates/summary_dashboard.json", } for file_name, path in osm_dashboards_mapping.items(): files_builder.add_file(file_name, Path(path).read_text()) @@ -126,7 +126,7 @@ class GrafanaCharm(CharmedOsmBase): files_builder = FilesV3Builder() files_builder.add_file( "datasource_prometheus.yaml", - Template(Path("files/default_datasources.yaml").read_text()).substitute( + Template(Path("templates/default_datasources.yaml").read_text()).substitute( prometheus_host=self.prometheus_client.hostname, prometheus_port=self.prometheus_client.port, ), diff --git a/installers/charm/grafana/files/default_dashboards.yaml b/installers/charm/grafana/templates/default_dashboards.yaml similarity index 100% rename from installers/charm/grafana/files/default_dashboards.yaml rename to installers/charm/grafana/templates/default_dashboards.yaml diff --git a/installers/charm/grafana/files/default_datasources.yaml b/installers/charm/grafana/templates/default_datasources.yaml similarity index 100% rename from installers/charm/grafana/files/default_datasources.yaml rename to installers/charm/grafana/templates/default_datasources.yaml diff --git a/installers/charm/grafana/files/kafka_exporter_dashboard.json b/installers/charm/grafana/templates/kafka_exporter_dashboard.json similarity index 100% rename from installers/charm/grafana/files/kafka_exporter_dashboard.json rename to installers/charm/grafana/templates/kafka_exporter_dashboard.json diff --git a/installers/charm/grafana/files/mongodb_exporter_dashboard.json b/installers/charm/grafana/templates/mongodb_exporter_dashboard.json similarity index 100% rename from installers/charm/grafana/files/mongodb_exporter_dashboard.json rename to installers/charm/grafana/templates/mongodb_exporter_dashboard.json diff --git a/installers/charm/grafana/files/mysql_exporter_dashboard.json b/installers/charm/grafana/templates/mysql_exporter_dashboard.json similarity index 100% rename from installers/charm/grafana/files/mysql_exporter_dashboard.json rename to installers/charm/grafana/templates/mysql_exporter_dashboard.json diff --git a/installers/charm/grafana/files/nodes_exporter_dashboard.json b/installers/charm/grafana/templates/nodes_exporter_dashboard.json similarity index 100% rename from installers/charm/grafana/files/nodes_exporter_dashboard.json rename to installers/charm/grafana/templates/nodes_exporter_dashboard.json diff --git a/installers/charm/grafana/files/summary_dashboard.json b/installers/charm/grafana/templates/summary_dashboard.json similarity index 100% rename from installers/charm/grafana/files/summary_dashboard.json rename to installers/charm/grafana/templates/summary_dashboard.json diff --git a/installers/charm/grafana/tox.ini b/installers/charm/grafana/tox.ini index dc4074f2..d3e139dc 100644 --- a/installers/charm/grafana/tox.ini +++ b/installers/charm/grafana/tox.ini @@ -95,19 +95,22 @@ commands = yamllint . ####################################################################################### [testenv:build] passenv=HTTP_PROXY HTTPS_PROXY NO_PROXY -deps = charmcraft whitelist_externals = charmcraft - cp + sh commands = charmcraft build - cp -r build release + sh -c 'ubuntu_version=20.04; \ + architectures="amd64-aarch64-arm64"; \ + charm_name=`cat metadata.yaml | grep -E "^name: " | cut -f 2 -d " "`; \ + mv $charm_name"_ubuntu-"$ubuntu_version-$architectures.charm $charm_name.charm' ####################################################################################### [flake8] ignore = W291, W293, + W503, E123, E125, E226, diff --git a/installers/charm/kafka-exporter/charmcraft.yaml b/installers/charm/kafka-exporter/charmcraft.yaml new file mode 100644 index 00000000..0a285a9d --- /dev/null +++ b/installers/charm/kafka-exporter/charmcraft.yaml @@ -0,0 +1,37 @@ +# 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 +## + +type: charm +bases: + - build-on: + - name: ubuntu + channel: "20.04" + architectures: ["amd64"] + run-on: + - name: ubuntu + channel: "20.04" + architectures: + - amd64 + - aarch64 + - arm64 +parts: + charm: + build-packages: [git] diff --git a/installers/charm/kafka-exporter/src/charm.py b/installers/charm/kafka-exporter/src/charm.py index fd24964f..21477816 100755 --- a/installers/charm/kafka-exporter/src/charm.py +++ b/installers/charm/kafka-exporter/src/charm.py @@ -137,7 +137,7 @@ class KafkaExporterCharm(CharmedOsmBase): if self.unit.is_leader(): self.dashboard_target.publish_info( name="osm-kafka", - dashboard=Path("files/kafka_exporter_dashboard.json").read_text(), + dashboard=Path("templates/kafka_exporter_dashboard.json").read_text(), ) def _check_missing_dependencies(self, config: ConfigModel): diff --git a/installers/charm/kafka-exporter/files/kafka_exporter_dashboard.json b/installers/charm/kafka-exporter/templates/kafka_exporter_dashboard.json similarity index 100% rename from installers/charm/kafka-exporter/files/kafka_exporter_dashboard.json rename to installers/charm/kafka-exporter/templates/kafka_exporter_dashboard.json diff --git a/installers/charm/kafka-exporter/tox.ini b/installers/charm/kafka-exporter/tox.ini index f207ac34..c341c8e4 100644 --- a/installers/charm/kafka-exporter/tox.ini +++ b/installers/charm/kafka-exporter/tox.ini @@ -95,13 +95,15 @@ commands = yamllint . ####################################################################################### [testenv:build] passenv=HTTP_PROXY HTTPS_PROXY NO_PROXY -deps = charmcraft whitelist_externals = charmcraft - cp + sh commands = charmcraft build - cp -r build release + sh -c 'ubuntu_version=20.04; \ + architectures="amd64-aarch64-arm64"; \ + charm_name=`cat metadata.yaml | grep -E "^name: " | cut -f 2 -d " "`; \ + mv $charm_name"_ubuntu-"$ubuntu_version-$architectures.charm $charm_name.charm' ####################################################################################### [flake8] diff --git a/installers/charm/keystone/charmcraft.yaml b/installers/charm/keystone/charmcraft.yaml new file mode 100644 index 00000000..0a285a9d --- /dev/null +++ b/installers/charm/keystone/charmcraft.yaml @@ -0,0 +1,37 @@ +# 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 +## + +type: charm +bases: + - build-on: + - name: ubuntu + channel: "20.04" + architectures: ["amd64"] + run-on: + - name: ubuntu + channel: "20.04" + architectures: + - amd64 + - aarch64 + - arm64 +parts: + charm: + build-packages: [git] diff --git a/installers/charm/keystone/tox.ini b/installers/charm/keystone/tox.ini index cb37bc87..65376160 100644 --- a/installers/charm/keystone/tox.ini +++ b/installers/charm/keystone/tox.ini @@ -95,13 +95,15 @@ commands = yamllint . ####################################################################################### [testenv:build] passenv=HTTP_PROXY HTTPS_PROXY NO_PROXY -deps = charmcraft whitelist_externals = charmcraft - cp + sh commands = charmcraft build - cp -r build release + sh -c 'ubuntu_version=20.04; \ + architectures="amd64-aarch64-arm64"; \ + charm_name=`cat metadata.yaml | grep -E "^name: " | cut -f 2 -d " "`; \ + mv $charm_name"_ubuntu-"$ubuntu_version-$architectures.charm $charm_name.charm' ####################################################################################### [flake8] diff --git a/installers/charm/lcm/charmcraft.yaml b/installers/charm/lcm/charmcraft.yaml new file mode 100644 index 00000000..0a285a9d --- /dev/null +++ b/installers/charm/lcm/charmcraft.yaml @@ -0,0 +1,37 @@ +# 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 +## + +type: charm +bases: + - build-on: + - name: ubuntu + channel: "20.04" + architectures: ["amd64"] + run-on: + - name: ubuntu + channel: "20.04" + architectures: + - amd64 + - aarch64 + - arm64 +parts: + charm: + build-packages: [git] diff --git a/installers/charm/lcm/config.yaml b/installers/charm/lcm/config.yaml index 27c43e5f..becbc4a0 100644 --- a/installers/charm/lcm/config.yaml +++ b/installers/charm/lcm/config.yaml @@ -280,3 +280,13 @@ options: ImagePullPolicy configuration for the pod. Possible values: always, ifnotpresent, never default: always + debug_mode: + description: | + If true, debug mode is activated. It means that the service will not run, + and instead, the command for the container will be a `sleep infinity`. + type: boolean + default: false + debug_pubkey: + description: | + Public SSH key that will be injected to the application pod. + type: string diff --git a/installers/charm/lcm/src/charm.py b/installers/charm/lcm/src/charm.py index 9d7f5529..af407e92 100755 --- a/installers/charm/lcm/src/charm.py +++ b/installers/charm/lcm/src/charm.py @@ -139,8 +139,13 @@ class ConfigModel(ModelValidator): class LcmCharm(CharmedOsmBase): def __init__(self, *args) -> NoReturn: - super().__init__(*args, oci_image="image") - + super().__init__( + *args, + oci_image="image", + debug_mode_config_key="debug_mode", + debug_pubkey_config_key="debug_pubkey", + vscode_workspace=VSCODE_WORKSPACE, + ) self.kafka_client = KafkaClient(self, "kafka") self.framework.observe(self.on["kafka"].relation_changed, self.configure_pod) self.framework.observe(self.on["kafka"].relation_broken, self.configure_pod) @@ -244,6 +249,28 @@ class LcmCharm(CharmedOsmBase): return pod_spec_builder.build() +VSCODE_WORKSPACE = { + "folders": [ + {"path": "/usr/lib/python3/dist-packages/osm_lcm"}, + {"path": "/usr/lib/python3/dist-packages/osm_n2vc"}, + {"path": "/usr/lib/python3/dist-packages/osm_common"}, + ], + "settings": {}, + "launch": { + "version": "0.2.0", + "configurations": [ + { + "name": "LCM", + "type": "python", + "request": "launch", + "module": "osm_lcm.lcm", + "justMyCode": False, + } + ], + }, +} + + if __name__ == "__main__": main(LcmCharm) diff --git a/installers/charm/lcm/tox.ini b/installers/charm/lcm/tox.ini index f207ac34..c341c8e4 100644 --- a/installers/charm/lcm/tox.ini +++ b/installers/charm/lcm/tox.ini @@ -95,13 +95,15 @@ commands = yamllint . ####################################################################################### [testenv:build] passenv=HTTP_PROXY HTTPS_PROXY NO_PROXY -deps = charmcraft whitelist_externals = charmcraft - cp + sh commands = charmcraft build - cp -r build release + sh -c 'ubuntu_version=20.04; \ + architectures="amd64-aarch64-arm64"; \ + charm_name=`cat metadata.yaml | grep -E "^name: " | cut -f 2 -d " "`; \ + mv $charm_name"_ubuntu-"$ubuntu_version-$architectures.charm $charm_name.charm' ####################################################################################### [flake8] diff --git a/installers/charm/mon/charmcraft.yaml b/installers/charm/mon/charmcraft.yaml new file mode 100644 index 00000000..0a285a9d --- /dev/null +++ b/installers/charm/mon/charmcraft.yaml @@ -0,0 +1,37 @@ +# 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 +## + +type: charm +bases: + - build-on: + - name: ubuntu + channel: "20.04" + architectures: ["amd64"] + run-on: + - name: ubuntu + channel: "20.04" + architectures: + - amd64 + - aarch64 + - arm64 +parts: + charm: + build-packages: [git] diff --git a/installers/charm/mon/config.yaml b/installers/charm/mon/config.yaml index ee593ffa..b8477b17 100644 --- a/installers/charm/mon/config.yaml +++ b/installers/charm/mon/config.yaml @@ -93,3 +93,13 @@ options: ImagePullPolicy configuration for the pod. Possible values: always, ifnotpresent, never default: always + debug_mode: + description: | + If true, debug mode is activated. It means that the service will not run, + and instead, the command for the container will be a `sleep infinity`. + type: boolean + default: false + debug_pubkey: + description: | + Public SSH key that will be injected to the application pod. + type: string diff --git a/installers/charm/mon/src/charm.py b/installers/charm/mon/src/charm.py index 1b7c74b6..f253c093 100755 --- a/installers/charm/mon/src/charm.py +++ b/installers/charm/mon/src/charm.py @@ -119,7 +119,13 @@ class ConfigModel(ModelValidator): class MonCharm(CharmedOsmBase): def __init__(self, *args) -> NoReturn: - super().__init__(*args, oci_image="image") + super().__init__( + *args, + oci_image="image", + debug_mode_config_key="debug_mode", + debug_pubkey_config_key="debug_pubkey", + vscode_workspace=VSCODE_WORKSPACE, + ) self.kafka_client = KafkaClient(self, "kafka") self.framework.observe(self.on["kafka"].relation_changed, self.configure_pod) @@ -239,5 +245,46 @@ class MonCharm(CharmedOsmBase): return pod_spec_builder.build() +VSCODE_WORKSPACE = { + "folders": [ + {"path": "/usr/lib/python3/dist-packages/osm_mon"}, + {"path": "/usr/lib/python3/dist-packages/osm_common"}, + {"path": "/usr/lib/python3/dist-packages/n2vc"}, + ], + "settings": {}, + "launch": { + "version": "0.2.0", + "configurations": [ + { + "name": "MON Server", + "type": "python", + "request": "launch", + "module": "osm_mon.cmd.mon_server", + "justMyCode": False, + }, + { + "name": "MON evaluator", + "type": "python", + "request": "launch", + "module": "osm_mon.cmd.mon_evaluator", + "justMyCode": False, + }, + { + "name": "MON collector", + "type": "python", + "request": "launch", + "module": "osm_mon.cmd.mon_collector", + "justMyCode": False, + }, + { + "name": "MON dashboarder", + "type": "python", + "request": "launch", + "module": "osm_mon.cmd.mon_dashboarder", + "justMyCode": False, + }, + ], + }, +} if __name__ == "__main__": main(MonCharm) diff --git a/installers/charm/mon/tox.ini b/installers/charm/mon/tox.ini index f207ac34..c341c8e4 100644 --- a/installers/charm/mon/tox.ini +++ b/installers/charm/mon/tox.ini @@ -95,13 +95,15 @@ commands = yamllint . ####################################################################################### [testenv:build] passenv=HTTP_PROXY HTTPS_PROXY NO_PROXY -deps = charmcraft whitelist_externals = charmcraft - cp + sh commands = charmcraft build - cp -r build release + sh -c 'ubuntu_version=20.04; \ + architectures="amd64-aarch64-arm64"; \ + charm_name=`cat metadata.yaml | grep -E "^name: " | cut -f 2 -d " "`; \ + mv $charm_name"_ubuntu-"$ubuntu_version-$architectures.charm $charm_name.charm' ####################################################################################### [flake8] diff --git a/installers/charm/mongodb-exporter/charmcraft.yaml b/installers/charm/mongodb-exporter/charmcraft.yaml new file mode 100644 index 00000000..0a285a9d --- /dev/null +++ b/installers/charm/mongodb-exporter/charmcraft.yaml @@ -0,0 +1,37 @@ +# 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 +## + +type: charm +bases: + - build-on: + - name: ubuntu + channel: "20.04" + architectures: ["amd64"] + run-on: + - name: ubuntu + channel: "20.04" + architectures: + - amd64 + - aarch64 + - arm64 +parts: + charm: + build-packages: [git] diff --git a/installers/charm/mongodb-exporter/src/charm.py b/installers/charm/mongodb-exporter/src/charm.py index f4c232a9..ad596c33 100755 --- a/installers/charm/mongodb-exporter/src/charm.py +++ b/installers/charm/mongodb-exporter/src/charm.py @@ -144,7 +144,7 @@ class MongodbExporterCharm(CharmedOsmBase): if self.unit.is_leader(): self.dashboard_target.publish_info( name="osm-mongodb", - dashboard=Path("files/mongodb_exporter_dashboard.json").read_text(), + dashboard=Path("templates/mongodb_exporter_dashboard.json").read_text(), ) def _check_missing_dependencies(self, config: ConfigModel): diff --git a/installers/charm/mongodb-exporter/files/mongodb_exporter_dashboard.json b/installers/charm/mongodb-exporter/templates/mongodb_exporter_dashboard.json similarity index 100% rename from installers/charm/mongodb-exporter/files/mongodb_exporter_dashboard.json rename to installers/charm/mongodb-exporter/templates/mongodb_exporter_dashboard.json diff --git a/installers/charm/mongodb-exporter/tox.ini b/installers/charm/mongodb-exporter/tox.ini index f207ac34..c341c8e4 100644 --- a/installers/charm/mongodb-exporter/tox.ini +++ b/installers/charm/mongodb-exporter/tox.ini @@ -95,13 +95,15 @@ commands = yamllint . ####################################################################################### [testenv:build] passenv=HTTP_PROXY HTTPS_PROXY NO_PROXY -deps = charmcraft whitelist_externals = charmcraft - cp + sh commands = charmcraft build - cp -r build release + sh -c 'ubuntu_version=20.04; \ + architectures="amd64-aarch64-arm64"; \ + charm_name=`cat metadata.yaml | grep -E "^name: " | cut -f 2 -d " "`; \ + mv $charm_name"_ubuntu-"$ubuntu_version-$architectures.charm $charm_name.charm' ####################################################################################### [flake8] diff --git a/installers/charm/mysqld-exporter/charmcraft.yaml b/installers/charm/mysqld-exporter/charmcraft.yaml new file mode 100644 index 00000000..0a285a9d --- /dev/null +++ b/installers/charm/mysqld-exporter/charmcraft.yaml @@ -0,0 +1,37 @@ +# 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 +## + +type: charm +bases: + - build-on: + - name: ubuntu + channel: "20.04" + architectures: ["amd64"] + run-on: + - name: ubuntu + channel: "20.04" + architectures: + - amd64 + - aarch64 + - arm64 +parts: + charm: + build-packages: [git] diff --git a/installers/charm/mysqld-exporter/src/charm.py b/installers/charm/mysqld-exporter/src/charm.py index adbb5197..a351d2bb 100755 --- a/installers/charm/mysqld-exporter/src/charm.py +++ b/installers/charm/mysqld-exporter/src/charm.py @@ -144,7 +144,7 @@ class MysqlExporterCharm(CharmedOsmBase): if self.unit.is_leader(): self.dashboard_target.publish_info( name="osm-mysql", - dashboard=Path("files/mysql_exporter_dashboard.json").read_text(), + dashboard=Path("templates/mysql_exporter_dashboard.json").read_text(), ) def _check_missing_dependencies(self, config: ConfigModel): diff --git a/installers/charm/mysqld-exporter/files/mysql_exporter_dashboard.json b/installers/charm/mysqld-exporter/templates/mysql_exporter_dashboard.json similarity index 100% rename from installers/charm/mysqld-exporter/files/mysql_exporter_dashboard.json rename to installers/charm/mysqld-exporter/templates/mysql_exporter_dashboard.json diff --git a/installers/charm/mysqld-exporter/tox.ini b/installers/charm/mysqld-exporter/tox.ini index f207ac34..c341c8e4 100644 --- a/installers/charm/mysqld-exporter/tox.ini +++ b/installers/charm/mysqld-exporter/tox.ini @@ -95,13 +95,15 @@ commands = yamllint . ####################################################################################### [testenv:build] passenv=HTTP_PROXY HTTPS_PROXY NO_PROXY -deps = charmcraft whitelist_externals = charmcraft - cp + sh commands = charmcraft build - cp -r build release + sh -c 'ubuntu_version=20.04; \ + architectures="amd64-aarch64-arm64"; \ + charm_name=`cat metadata.yaml | grep -E "^name: " | cut -f 2 -d " "`; \ + mv $charm_name"_ubuntu-"$ubuntu_version-$architectures.charm $charm_name.charm' ####################################################################################### [flake8] diff --git a/installers/charm/nbi/charmcraft.yaml b/installers/charm/nbi/charmcraft.yaml new file mode 100644 index 00000000..0a285a9d --- /dev/null +++ b/installers/charm/nbi/charmcraft.yaml @@ -0,0 +1,37 @@ +# 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 +## + +type: charm +bases: + - build-on: + - name: ubuntu + channel: "20.04" + architectures: ["amd64"] + run-on: + - name: ubuntu + channel: "20.04" + architectures: + - amd64 + - aarch64 + - arm64 +parts: + charm: + build-packages: [git] diff --git a/installers/charm/nbi/config.yaml b/installers/charm/nbi/config.yaml index 9c353661..89e248dc 100644 --- a/installers/charm/nbi/config.yaml +++ b/installers/charm/nbi/config.yaml @@ -78,3 +78,13 @@ options: ImagePullPolicy configuration for the pod. Possible values: always, ifnotpresent, never default: always + debug_mode: + description: | + If true, debug mode is activated. It means that the service will not run, + and instead, the command for the container will be a `sleep infinity`. + type: boolean + default: false + debug_pubkey: + description: | + Public SSH key that will be injected to the application pod. + type: string diff --git a/installers/charm/nbi/src/charm.py b/installers/charm/nbi/src/charm.py index 938a75a0..0e360738 100755 --- a/installers/charm/nbi/src/charm.py +++ b/installers/charm/nbi/src/charm.py @@ -116,7 +116,13 @@ class ConfigModel(ModelValidator): class NbiCharm(CharmedOsmBase): def __init__(self, *args) -> NoReturn: - super().__init__(*args, oci_image="image") + super().__init__( + *args, + oci_image="image", + debug_mode_config_key="debug_mode", + debug_pubkey_config_key="debug_pubkey", + vscode_workspace=VSCODE_WORKSPACE, + ) self.kafka_client = KafkaClient(self, "kafka") self.framework.observe(self.on["kafka"].relation_changed, self.configure_pod) @@ -296,5 +302,27 @@ class NbiCharm(CharmedOsmBase): return pod_spec_builder.build() +VSCODE_WORKSPACE = { + "folders": [ + {"path": "/usr/lib/python3/dist-packages/osm_nbi"}, + {"path": "/usr/lib/python3/dist-packages/osm_common"}, + {"path": "/usr/lib/python3/dist-packages/osm_im"}, + ], + "settings": {}, + "launch": { + "version": "0.2.0", + "configurations": [ + { + "name": "NBI", + "type": "python", + "request": "launch", + "module": "osm_nbi.nbi", + "justMyCode": False, + } + ], + }, +} + + if __name__ == "__main__": main(NbiCharm) diff --git a/installers/charm/nbi/tox.ini b/installers/charm/nbi/tox.ini index f207ac34..c341c8e4 100644 --- a/installers/charm/nbi/tox.ini +++ b/installers/charm/nbi/tox.ini @@ -95,13 +95,15 @@ commands = yamllint . ####################################################################################### [testenv:build] passenv=HTTP_PROXY HTTPS_PROXY NO_PROXY -deps = charmcraft whitelist_externals = charmcraft - cp + sh commands = charmcraft build - cp -r build release + sh -c 'ubuntu_version=20.04; \ + architectures="amd64-aarch64-arm64"; \ + charm_name=`cat metadata.yaml | grep -E "^name: " | cut -f 2 -d " "`; \ + mv $charm_name"_ubuntu-"$ubuntu_version-$architectures.charm $charm_name.charm' ####################################################################################### [flake8] diff --git a/installers/charm/ng-ui/charmcraft.yaml b/installers/charm/ng-ui/charmcraft.yaml new file mode 100644 index 00000000..0a285a9d --- /dev/null +++ b/installers/charm/ng-ui/charmcraft.yaml @@ -0,0 +1,37 @@ +# 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 +## + +type: charm +bases: + - build-on: + - name: ubuntu + channel: "20.04" + architectures: ["amd64"] + run-on: + - name: ubuntu + channel: "20.04" + architectures: + - amd64 + - aarch64 + - arm64 +parts: + charm: + build-packages: [git] diff --git a/installers/charm/ng-ui/src/charm.py b/installers/charm/ng-ui/src/charm.py index cf0b0910..56644f2e 100755 --- a/installers/charm/ng-ui/src/charm.py +++ b/installers/charm/ng-ui/src/charm.py @@ -116,7 +116,7 @@ class NgUiCharm(CharmedOsmBase): files_builder = FilesV3Builder() files_builder.add_file( "default", - Template(Path("files/default").read_text()).substitute( + Template(Path("templates/default.template").read_text()).substitute( port=config.port, server_name=config.server_name, max_file_size=config.max_file_size, diff --git a/installers/charm/ng-ui/files/default b/installers/charm/ng-ui/templates/default.template similarity index 100% rename from installers/charm/ng-ui/files/default rename to installers/charm/ng-ui/templates/default.template diff --git a/installers/charm/ng-ui/tox.ini b/installers/charm/ng-ui/tox.ini index dc4074f2..d3e139dc 100644 --- a/installers/charm/ng-ui/tox.ini +++ b/installers/charm/ng-ui/tox.ini @@ -95,19 +95,22 @@ commands = yamllint . ####################################################################################### [testenv:build] passenv=HTTP_PROXY HTTPS_PROXY NO_PROXY -deps = charmcraft whitelist_externals = charmcraft - cp + sh commands = charmcraft build - cp -r build release + sh -c 'ubuntu_version=20.04; \ + architectures="amd64-aarch64-arm64"; \ + charm_name=`cat metadata.yaml | grep -E "^name: " | cut -f 2 -d " "`; \ + mv $charm_name"_ubuntu-"$ubuntu_version-$architectures.charm $charm_name.charm' ####################################################################################### [flake8] ignore = W291, W293, + W503, E123, E125, E226, diff --git a/installers/charm/pla/charmcraft.yaml b/installers/charm/pla/charmcraft.yaml new file mode 100644 index 00000000..0a285a9d --- /dev/null +++ b/installers/charm/pla/charmcraft.yaml @@ -0,0 +1,37 @@ +# 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 +## + +type: charm +bases: + - build-on: + - name: ubuntu + channel: "20.04" + architectures: ["amd64"] + run-on: + - name: ubuntu + channel: "20.04" + architectures: + - amd64 + - aarch64 + - arm64 +parts: + charm: + build-packages: [git] diff --git a/installers/charm/pla/tox.ini b/installers/charm/pla/tox.ini index f207ac34..c341c8e4 100644 --- a/installers/charm/pla/tox.ini +++ b/installers/charm/pla/tox.ini @@ -95,13 +95,15 @@ commands = yamllint . ####################################################################################### [testenv:build] passenv=HTTP_PROXY HTTPS_PROXY NO_PROXY -deps = charmcraft whitelist_externals = charmcraft - cp + sh commands = charmcraft build - cp -r build release + sh -c 'ubuntu_version=20.04; \ + architectures="amd64-aarch64-arm64"; \ + charm_name=`cat metadata.yaml | grep -E "^name: " | cut -f 2 -d " "`; \ + mv $charm_name"_ubuntu-"$ubuntu_version-$architectures.charm $charm_name.charm' ####################################################################################### [flake8] diff --git a/installers/charm/pol/charmcraft.yaml b/installers/charm/pol/charmcraft.yaml new file mode 100644 index 00000000..0a285a9d --- /dev/null +++ b/installers/charm/pol/charmcraft.yaml @@ -0,0 +1,37 @@ +# 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 +## + +type: charm +bases: + - build-on: + - name: ubuntu + channel: "20.04" + architectures: ["amd64"] + run-on: + - name: ubuntu + channel: "20.04" + architectures: + - amd64 + - aarch64 + - arm64 +parts: + charm: + build-packages: [git] diff --git a/installers/charm/pol/config.yaml b/installers/charm/pol/config.yaml index 7b64f574..3264ca30 100644 --- a/installers/charm/pol/config.yaml +++ b/installers/charm/pol/config.yaml @@ -38,3 +38,13 @@ options: ImagePullPolicy configuration for the pod. Possible values: always, ifnotpresent, never default: always + debug_mode: + description: | + If true, debug mode is activated. It means that the service will not run, + and instead, the command for the container will be a `sleep infinity`. + type: boolean + default: false + debug_pubkey: + description: | + Public SSH key that will be injected to the application pod. + type: string diff --git a/installers/charm/pol/src/charm.py b/installers/charm/pol/src/charm.py index 727ffbeb..d1341c11 100755 --- a/installers/charm/pol/src/charm.py +++ b/installers/charm/pol/src/charm.py @@ -85,7 +85,13 @@ class ConfigModel(ModelValidator): class PolCharm(CharmedOsmBase): def __init__(self, *args) -> NoReturn: - super().__init__(*args, oci_image="image") + super().__init__( + *args, + oci_image="image", + debug_mode_config_key="debug_mode", + debug_pubkey_config_key="debug_pubkey", + vscode_workspace=VSCODE_WORKSPACE, + ) self.kafka_client = KafkaClient(self, "kafka") self.framework.observe(self.on["kafka"].relation_changed, self.configure_pod) @@ -156,5 +162,26 @@ class PolCharm(CharmedOsmBase): return pod_spec_builder.build() +VSCODE_WORKSPACE = { + "folders": [ + {"path": "/usr/lib/python3/dist-packages/osm_policy_module"}, + {"path": "/usr/lib/python3/dist-packages/osm_common"}, + ], + "settings": {}, + "launch": { + "version": "0.2.0", + "configurations": [ + { + "name": "POL", + "type": "python", + "request": "launch", + "module": "osm_policy_module.cmd.policy_module_agent", + "justMyCode": False, + } + ], + }, +} + + if __name__ == "__main__": main(PolCharm) diff --git a/installers/charm/pol/tox.ini b/installers/charm/pol/tox.ini index f207ac34..c341c8e4 100644 --- a/installers/charm/pol/tox.ini +++ b/installers/charm/pol/tox.ini @@ -95,13 +95,15 @@ commands = yamllint . ####################################################################################### [testenv:build] passenv=HTTP_PROXY HTTPS_PROXY NO_PROXY -deps = charmcraft whitelist_externals = charmcraft - cp + sh commands = charmcraft build - cp -r build release + sh -c 'ubuntu_version=20.04; \ + architectures="amd64-aarch64-arm64"; \ + charm_name=`cat metadata.yaml | grep -E "^name: " | cut -f 2 -d " "`; \ + mv $charm_name"_ubuntu-"$ubuntu_version-$architectures.charm $charm_name.charm' ####################################################################################### [flake8] diff --git a/installers/charm/prometheus/charmcraft.yaml b/installers/charm/prometheus/charmcraft.yaml new file mode 100644 index 00000000..0a285a9d --- /dev/null +++ b/installers/charm/prometheus/charmcraft.yaml @@ -0,0 +1,37 @@ +# 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 +## + +type: charm +bases: + - build-on: + - name: ubuntu + channel: "20.04" + architectures: ["amd64"] + run-on: + - name: ubuntu + channel: "20.04" + architectures: + - amd64 + - aarch64 + - arm64 +parts: + charm: + build-packages: [git] diff --git a/installers/charm/prometheus/tox.ini b/installers/charm/prometheus/tox.ini index 30e0ea8c..c341c8e4 100644 --- a/installers/charm/prometheus/tox.ini +++ b/installers/charm/prometheus/tox.ini @@ -95,19 +95,22 @@ commands = yamllint . ####################################################################################### [testenv:build] passenv=HTTP_PROXY HTTPS_PROXY NO_PROXY -deps = charmcraft whitelist_externals = charmcraft - cp + sh commands = charmcraft build - cp -r build release + sh -c 'ubuntu_version=20.04; \ + architectures="amd64-aarch64-arm64"; \ + charm_name=`cat metadata.yaml | grep -E "^name: " | cut -f 2 -d " "`; \ + mv $charm_name"_ubuntu-"$ubuntu_version-$architectures.charm $charm_name.charm' ####################################################################################### [flake8] ignore = W291, W293, + W503, E123, E125, E226, diff --git a/installers/charm/ro/charmcraft.yaml b/installers/charm/ro/charmcraft.yaml new file mode 100644 index 00000000..0a285a9d --- /dev/null +++ b/installers/charm/ro/charmcraft.yaml @@ -0,0 +1,37 @@ +# 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 +## + +type: charm +bases: + - build-on: + - name: ubuntu + channel: "20.04" + architectures: ["amd64"] + run-on: + - name: ubuntu + channel: "20.04" + architectures: + - amd64 + - aarch64 + - arm64 +parts: + charm: + build-packages: [git] diff --git a/installers/charm/ro/config.yaml b/installers/charm/ro/config.yaml index 5bb0362a..98284382 100644 --- a/installers/charm/ro/config.yaml +++ b/installers/charm/ro/config.yaml @@ -76,3 +76,13 @@ options: ImagePullPolicy configuration for the pod. Possible values: always, ifnotpresent, never default: always + debug_mode: + description: | + If true, debug mode is activated. It means that the service will not run, + and instead, the command for the container will be a `sleep infinity`. + type: boolean + default: false + debug_pubkey: + description: | + Public SSH key that will be injected to the application pod. + type: string diff --git a/installers/charm/ro/src/charm.py b/installers/charm/ro/src/charm.py index d87007e7..52123937 100755 --- a/installers/charm/ro/src/charm.py +++ b/installers/charm/ro/src/charm.py @@ -121,7 +121,13 @@ class RoCharm(CharmedOsmBase): def __init__(self, *args) -> NoReturn: """Prometheus Charm constructor.""" - super().__init__(*args, oci_image="image") + super().__init__( + *args, + oci_image="image", + debug_mode_config_key="debug_mode", + debug_pubkey_config_key="debug_pubkey", + vscode_workspace=VSCODE_WORKSPACE, + ) self.kafka_client = KafkaClient(self, "kafka") self.framework.observe(self.on["kafka"].relation_changed, self.configure_pod) @@ -284,5 +290,42 @@ class RoCharm(CharmedOsmBase): return pod_spec_builder.build() +VSCODE_WORKSPACE = { + "folders": [ + {"path": "/usr/lib/python3/dist-packages/osm_ng_ro"}, + {"path": "/usr/lib/python3/dist-packages/osm_common"}, + {"path": "/usr/lib/python3/dist-packages/osm_ro_plugin"}, + {"path": "/usr/lib/python3/dist-packages/osm_rosdn_arista_cloudvision"}, + {"path": "/usr/lib/python3/dist-packages/osm_rosdn_dpb"}, + {"path": "/usr/lib/python3/dist-packages/osm_rosdn_dynpac"}, + {"path": "/usr/lib/python3/dist-packages/osm_rosdn_floodlightof"}, + {"path": "/usr/lib/python3/dist-packages/osm_rosdn_ietfl2vpn"}, + {"path": "/usr/lib/python3/dist-packages/osm_rosdn_juniper_contrail"}, + {"path": "/usr/lib/python3/dist-packages/osm_rosdn_odlof"}, + {"path": "/usr/lib/python3/dist-packages/osm_rosdn_onos_vpls"}, + {"path": "/usr/lib/python3/dist-packages/osm_rosdn_onosof"}, + {"path": "/usr/lib/python3/dist-packages/osm_rovim_aws"}, + {"path": "/usr/lib/python3/dist-packages/osm_rovim_azure"}, + {"path": "/usr/lib/python3/dist-packages/osm_rovim_fos"}, + {"path": "/usr/lib/python3/dist-packages/osm_rovim_opennebula"}, + {"path": "/usr/lib/python3/dist-packages/osm_rovim_openstack"}, + {"path": "/usr/lib/python3/dist-packages/osm_rovim_openvim"}, + {"path": "/usr/lib/python3/dist-packages/osm_rovim_vmware"}, + ], + "launch": { + "configurations": [ + { + "module": "osm_ng_ro.ro_main", + "name": "NG RO", + "request": "launch", + "type": "python", + "justMyCode": False, + } + ], + "version": "0.2.0", + }, + "settings": {}, +} + if __name__ == "__main__": main(RoCharm) diff --git a/installers/charm/ro/tox.ini b/installers/charm/ro/tox.ini index f207ac34..c341c8e4 100644 --- a/installers/charm/ro/tox.ini +++ b/installers/charm/ro/tox.ini @@ -95,13 +95,15 @@ commands = yamllint . ####################################################################################### [testenv:build] passenv=HTTP_PROXY HTTPS_PROXY NO_PROXY -deps = charmcraft whitelist_externals = charmcraft - cp + sh commands = charmcraft build - cp -r build release + sh -c 'ubuntu_version=20.04; \ + architectures="amd64-aarch64-arm64"; \ + charm_name=`cat metadata.yaml | grep -E "^name: " | cut -f 2 -d " "`; \ + mv $charm_name"_ubuntu-"$ubuntu_version-$architectures.charm $charm_name.charm' ####################################################################################### [flake8] diff --git a/tools/debug/charmed/README.md b/tools/debug/charmed/README.md new file mode 100644 index 00000000..1330454f --- /dev/null +++ b/tools/debug/charmed/README.md @@ -0,0 +1,113 @@ + + +# Debugging Charmed OSM + +This document aims to provide the OSM community an easy way of testing and debugging OSM. + +Benefits: + +- Use upstream published images for debugging: No need to build local images anymore. +- Easily configure modules for debugging_mode: `juju config debug_mode=True debug_pubkey="ssh-rsa ..."`. +- Debug in K8s: All pods (the debugged ones and the rest) will be running always in K8s. +- Seemless setup: VSCode will connect through SSH to the pods. + +## Install OSM + +Download the installer: + +```bash +wget http://osm-download.etsi.org/ftp/osm-10.0-ten/install_osm.sh +chmod +x install_osm.sh +``` + +Install OSM from master (tag=testing-daily): + +```bash +./install_osm.sh -R testing-daily -r testing --charmed +``` + +Install OSM from a specific tag: + +```bash +./install_osm.sh -R testing-daily -r testing --charmed --tag +``` + +## Debugging + +Once the Charmed OSM installation has finished, you can select which applications you want to run with the debug mode. + +- lcm: `juju config lcm debug_mode=True debug_pubkey="ssh-rsa ..."` +- mon: `juju config mon debug_mode=True debug_pubkey="ssh-rsa ..."` +- nbi: `juju config nbi debug_mode=True debug_pubkey="ssh-rsa ..."` +- ro: `juju config ro debug_mode=True debug_pubkey="ssh-rsa ..."` +- pol: `juju config pol debug_mode=True debug_pubkey="ssh-rsa ..."` + +Enabling the debug_mode will put a `sleep infinity` as the entrypoint of the container. That way, we can later connect to the pod through SSH in VSCode, and run the entrypoint of the application from the debugger. + +### Prepare pods + +Preparing the pods includes setting up the ~/.ssh/config so the VSCode can easily discover which ssh hosts are available + +Just execute: + +```bash +./prepare_pods.sh +``` + +> NOTE: The public key that will be used will be `$HOME/.ssh/id_rsa.pub`. If you want to use a different one, add the absolute path to it as a first argument: `./prepare_pods.sh /path/to/key.pub`. + +### Connect to Pods + +In VScode, navigate to [Remote Explorer](https://code.visualstudio.com/docs/remote/ssh#_remember-hosts-and-advanced-settings), and select the pod to which you want to connect. + +You should be able to see the following hosts in the Remote Explorer: + +- lcm +- mon +- nbi +- ro +- pol + +Right click on the host, and "Connect to host in a New Window". + +### Add workspace + +The `./prepare_pods.sh` script adds a workspace to the `/root` folder of each pod, with the following name: `.code-workspace`. + +In the window of the connected host, go to `File/Open Workspace...`. Then select the `.code-workspace` file. + +### Run and Debug + +Go to extensions and install the Python extension. It will be installed in the remote pod. + +Now we need to add a [debug configuration](https://code.visualstudio.com/docs/editor/debugging). For that, go to the Run and Debug tab, and click on `create a launch.json file`. + +Now you will be asked to select a folder in your workspace. Select the folder of the main component: + +- LCM: select osm_lcm +- MON: select osm_mon +- NBI: select osm_nbi +- RO: select osm_ng_ro +- POL: select osm_policy_module + +Then select `Python` as the environment. And finally, select `Module` and enter the module of the component you are going to test (LCM example: osm_lcm.lcm) diff --git a/tools/debug/charmed/prepare_pods.sh b/tools/debug/charmed/prepare_pods.sh new file mode 100755 index 00000000..8f740e4f --- /dev/null +++ b/tools/debug/charmed/prepare_pods.sh @@ -0,0 +1,50 @@ +#!/bin/bash +# 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 +## + +MODULES="lcm pol mon ro nbi" + + +PUBLIC_KEY=${1:-$HOME/.ssh/id_rsa.pub} +echo "Using $PUBLIC_KEY key." +[ -f $PUBLIC_KEY ] || (echo "$PUBLIC_KEY file does not exist" && exit 1) +PUBLIC_KEY_CONTENT=`cat $PUBLIC_KEY` + +mkdir -p ~/.ssh/config.d +echo "" | tee ~/.ssh/config.d/osm + + +for module in $MODULES; do + if [[ `juju config -m osm $module debug_mode` == "true" ]]; then + pod_name=`microk8s.kubectl -n osm get pods | grep -E "^$module-" | grep -v operator | cut -d " " -f 1` + pod_ip=`microk8s.kubectl -n osm get pods $pod_name -o yaml | yq .status.podIP` + echo "Host $module + HostName $pod_ip + User root + # StrictHostKeyChecking no + IdentityFile $PUBLIC_KEY" | tee -a ~/.ssh/config.d/osm + fi +done + + +import_osm_config="Include config.d/osm" +touch ~/.ssh/config +grep "$import_osm_config" ~/.ssh/config || ( echo -e "$import_osm_config\n$(cat ~/.ssh/config)" > ~/.ssh/config ) \ No newline at end of file -- 2.25.1