Fix bug 1799: Add hostpath mount option in OSM charms
[osm/devops.git] / tools / debug / charmed / README.md
index 1330454..93bf7ee 100644 (file)
@@ -30,6 +30,7 @@ Benefits:
 - Easily configure modules for debugging_mode: `juju config <module> 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.
+- Keep your changes save: Possibility to mount local module to the container; all the changes will be saved automatically to your local filesystem.
 
 ## Install OSM
 
@@ -56,25 +57,64 @@ Install OSM from a specific tag:
 
 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 ..."`
+```bash
+# LCM
+juju config lcm debug_mode=True  debug_pubkey="`cat ~/.ssh/id_rsa.pub`"
+# MON
+juju config mon debug_mode=True  debug_pubkey="`cat ~/.ssh/id_rsa.pub`"
+# NBI
+juju config nbi debug_mode=True  debug_pubkey="`cat ~/.ssh/id_rsa.pub`"
+# RO
+juju config ro debug_mode=True  debug_pubkey="`cat ~/.ssh/id_rsa.pub`"
+# POL
+juju config pol debug_mode=True  debug_pubkey="`cat ~/.ssh/id_rsa.pub`"
+```
 
 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
+### Mounting local modules
+
+The Charmed OSM Debugging mode allows you to mount local modules to the desired charms. The following commands show which modules can be mounted in each charm.
+
+```bash
+LCM_LOCAL_PATH="/path/to/LCM"
+N2VC_LOCAL_PATH="/path/to/N2VC"
+NBI_LOCAL_PATH="/path/to/NBI"
+RO_LOCAL_PATH="/path/to/RO"
+MON_LOCAL_PATH="/path/to/MON"
+POL_LOCAL_PATH="/path/to/POL"
+COMMON_LOCAL_PATH="/path/to/common"
+
+# LCM
+juju config lcm debug_lcm_local_path=$LCM_LOCAL_PATH
+juju config lcm debug_n2vc_local_path=$N2VC_LOCAL_PATH
+juju config lcm debug_common_local_path=$COMMON_LOCAL_PATH
+# MON
+juju config mon debug_mon_local_path=$MON_LOCAL_PATH
+juju config mon debug_n2vc_local_path=$N2VC_LOCAL_PATH
+juju config mon debug_common_local_path=$COMMON_LOCAL_PATH
+# NBI
+juju config nbi debug_nbi_local_path=$LCM_LOCAL_PATH
+juju config nbi debug_common_local_path=$COMMON_LOCAL_PATH
+# RO
+juju config ro debug_ro_local_path=$RO_LOCAL_PATH
+juju config ro debug_common_local_path=$COMMON_LOCAL_PATH
+# POL
+juju config pol debug_pol_local_path=$POL_LOCAL_PATH
+juju config pol debug_common_local_path=$COMMON_LOCAL_PATH
+```
 
-Preparing the pods includes setting up the ~/.ssh/config so the VSCode can easily discover which ssh hosts are available
+### Generate SSH config file
+
+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
+./generate_ssh_config.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`.
+> 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: `./generate_ssh_config.sh /path/to/key.pub`.
 
 ### Connect to Pods
 
@@ -92,22 +132,16 @@ 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: `<module>.code-workspace`.
+The `./generate_ssh_config.sh` script adds a workspace to the `/root` folder of each pod, with the following name: `debug.code-workspace`.
 
-In the window of the connected host, go to `File/Open Workspace...`. Then select the `<module>.code-workspace` file.
+In the window of the connected host, go to `File/Open Workspace from File...`. Then select the `debug.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`.
+Open the `Terminal` tab, and the Python extension will be automatically downloaded. It will be installed in the remote pod.
 
-Now you will be asked to select a folder in your workspace. Select the folder of the main component:
+Go to the `Explorer (ctrl + shift + E)` to see the module folders in the charm. You can add breakpoints and start debugging. 
 
-- LCM: select osm_lcm
-- MON: select osm_mon
-- NBI: select osm_nbi
-- RO: select osm_ng_ro
-- POL: select osm_policy_module
+Go to the `Run and Debug (ctrl + shift + D)` and press `F5` to start the main entrypoint of the charm.
 
-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)
+Happy debugging!