X-Git-Url: https://osm.etsi.org/gitweb/?a=blobdiff_plain;f=installers%2Fcharm%2Fosm-ng-ui%2Flib%2Fcharms%2Fosm_libs%2Fv0%2Futils.py;h=df3da94e8ec3083a273ee76b69ea8e873b8db30a;hb=354ca211482bd96656590e4ce2bfb307421b2090;hp=3feed7d737f954338effcb719bc8de10d88500dc;hpb=7da7a3343ea03386d498eaa6b6a93eb3f770d6cd;p=osm%2Fdevops.git diff --git a/installers/charm/osm-ng-ui/lib/charms/osm_libs/v0/utils.py b/installers/charm/osm-ng-ui/lib/charms/osm_libs/v0/utils.py index 3feed7d7..df3da94e 100644 --- a/installers/charm/osm-ng-ui/lib/charms/osm_libs/v0/utils.py +++ b/installers/charm/osm-ng-ui/lib/charms/osm_libs/v0/utils.py @@ -107,6 +107,7 @@ class MyCharm(CharmBase): - Get pod IP with `get_pod_ip()` """ +from dataclasses import dataclass import logging import secrets import socket @@ -136,7 +137,7 @@ LIBAPI = 0 # Increment this PATCH version before using `charmcraft publish-lib` or reset # to 0 if you are raising the major API version -LIBPATCH = 1 +LIBPATCH = 3 logger = logging.getLogger(__name__) @@ -231,17 +232,30 @@ wait """ +@dataclass +class SubModule: + """Represent RO Submodules.""" + sub_module_path: str + container_path: str + + class HostPath: """Represents a hostpath.""" - - def __init__(self, config: str, container_path: str) -> None: + def __init__(self, config: str, container_path: str, submodules: dict = None) -> None: mount_path_items = config.split("-") mount_path_items.reverse() self.mount_path = "/" + "/".join(mount_path_items) self.config = config - self.container_path = container_path - self.module_name = container_path.split("/")[-1] - + self.sub_module_dict = {} + if submodules: + for submodule in submodules.keys(): + self.sub_module_dict[submodule] = SubModule( + sub_module_path=self.mount_path + "/" + submodule, + container_path=submodules[submodule], + ) + else: + self.container_path = container_path + self.module_name = container_path.split("/")[-1] class DebugMode(Object): """Class to handle the debug-mode.""" @@ -416,15 +430,28 @@ class DebugMode(Object): # Add symlinks to mounted hostpaths for hostpath in mounted_hostpaths: logger.debug(f"adding symlink for {hostpath.config}") - self.container.exec(["rm", "-rf", hostpath.container_path]).wait_output() - self.container.exec( - [ - "ln", - "-s", - f"{hostpath.mount_path}/{hostpath.module_name}", - hostpath.container_path, - ] - ) + if len(hostpath.sub_module_dict) > 0: + for sub_module in hostpath.sub_module_dict.keys(): + self.container.exec(["rm", "-rf", hostpath.sub_module_dict[sub_module].container_path]).wait_output() + self.container.exec( + [ + "ln", + "-s", + hostpath.sub_module_dict[sub_module].sub_module_path, + hostpath.sub_module_dict[sub_module].container_path, + ] + ) + + else: + self.container.exec(["rm", "-rf", hostpath.container_path]).wait_output() + self.container.exec( + [ + "ln", + "-s", + f"{hostpath.mount_path}/{hostpath.module_name}", + hostpath.container_path, + ] + ) def _configure_hostpaths(self, hostpaths: List[HostPath]): client = Client() @@ -510,7 +537,7 @@ class DebugMode(Object): pod_ip: str, user: str = "root", workspace_path: str = "/debug.code-workspace", - ) -> None: + ) -> str: return f"code --remote ssh-remote+{user}@{pod_ip} {workspace_path}" def _restart(self):