From e557b402b60b1c84929c8c50f18b2941aab67490 Mon Sep 17 00:00:00 2001 From: Blake Harnden <32446120+bharnden@users.noreply.github.com> Date: Fri, 25 Feb 2022 14:46:03 -0800 Subject: [PATCH] daemon: fix PhysicalNode instantiation issues, remove old functions that are no longer use and update session to use the new variation --- daemon/core/emulator/session.py | 8 ++++++-- daemon/core/nodes/base.py | 33 +-------------------------------- daemon/core/nodes/physical.py | 26 ++++++++------------------ 3 files changed, 15 insertions(+), 52 deletions(-) diff --git a/daemon/core/emulator/session.py b/daemon/core/emulator/session.py index 46f9a04f..60d52f82 100644 --- a/daemon/core/emulator/session.py +++ b/daemon/core/emulator/session.py @@ -694,7 +694,11 @@ class Session: self.run_hook(hook) def add_node_file( - self, node_id: int, src_path: Path, file_path: Path, data: str + self, + node_id: int, + src_path: Optional[Path], + file_path: Path, + data: Optional[str], ) -> None: """ Add a file to a node. @@ -707,7 +711,7 @@ class Session: """ node = self.get_node(node_id, CoreNode) if src_path is not None: - node.addfile(src_path, file_path) + node.copy_file(src_path, file_path) elif data is not None: node.create_file(file_path, data) diff --git a/daemon/core/nodes/base.py b/daemon/core/nodes/base.py index 3b5cd04e..fa3c063c 100644 --- a/daemon/core/nodes/base.py +++ b/daemon/core/nodes/base.py @@ -271,18 +271,6 @@ class CoreNodeBase(NodeBase): """ raise NotImplementedError - @abc.abstractmethod - def addfile(self, src_path: Path, file_path: Path) -> None: - """ - Add a file. - - :param src_path: source file path - :param file_path: file name to add - :return: nothing - :raises CoreCommandError: when a non-zero exit status occurs - """ - raise NotImplementedError - @abc.abstractmethod def cmd(self, args: str, wait: bool = True, shell: bool = False) -> str: """ @@ -847,28 +835,9 @@ class CoreNode(CoreNodeBase): self.ifup(iface_id) return self.get_iface(iface_id) - def addfile(self, src_path: Path, file_path: Path) -> None: - """ - Add a file. - - :param src_path: source file path - :param file_path: file name to add - :return: nothing - :raises CoreCommandError: when a non-zero exit status occurs - """ - logger.info("adding file from %s to %s", src_path, file_path) - directory = file_path.parent - if self.server is None: - self.client.check_cmd(f"mkdir -p {directory}") - self.client.check_cmd(f"mv {src_path} {file_path}") - self.client.check_cmd("sync") - else: - self.host_cmd(f"mkdir -p {directory}") - self.server.remote_put(src_path, file_path) - def _find_parent_path(self, path: Path) -> Optional[Path]: """ - Check if there is an existing mounted parent directory created for this node. + Check if there is a mounted parent directory created for this node. :param path: existing parent path to use :return: exist parent path if exists, None otherwise diff --git a/daemon/core/nodes/physical.py b/daemon/core/nodes/physical.py index 5c1cfe2e..0a686da8 100644 --- a/daemon/core/nodes/physical.py +++ b/daemon/core/nodes/physical.py @@ -187,21 +187,17 @@ class PhysicalNode(CoreNodeBase): except CoreCommandError: logger.exception("unmounting failed for %s", target_path) - def nodefile(self, file_path: Path, contents: str, mode: int = 0o644) -> None: - host_path = self.host_path(file_path) - directory = host_path.parent - if not directory.is_dir(): - directory.mkdir(parents=True, mode=0o755) - with host_path.open("w") as f: - f.write(contents) - host_path.chmod(mode) - logger.info("created nodefile: '%s'; mode: 0%o", host_path, mode) - def cmd(self, args: str, wait: bool = True, shell: bool = False) -> str: return self.host_cmd(args, wait=wait) - def addfile(self, src_path: str, file_path: str) -> None: - raise CoreError("physical node does not support addfile") + def create_dir(self, dir_path: Path) -> None: + raise CoreError("physical node does not support creating directories") + + def create_file(self, file_path: Path, contents: str, mode: int = 0o644) -> None: + raise CoreError("physical node does not support creating files") + + def copy_file(self, src_path: Path, dst_path: Path, mode: int = None) -> None: + raise CoreError("physical node does not support copying files") class Rj45Node(CoreNodeBase): @@ -430,12 +426,6 @@ class Rj45Node(CoreNodeBase): def termcmdstring(self, sh: str) -> str: raise CoreError("rj45 does not support terminal commands") - def addfile(self, src_path: str, file_path: str) -> None: - raise CoreError("rj45 does not support addfile") - - def nodefile(self, file_path: str, contents: str, mode: int = 0o644) -> None: - raise CoreError("rj45 does not support nodefile") - def cmd(self, args: str, wait: bool = True, shell: bool = False) -> str: raise CoreError("rj45 does not support cmds")