From: Luca Vizzarro <luca.vizzarro@arm.com>
To: dev@dpdk.org
Cc: Stephen Hemminger <stephen@networkplumber.org>,
Luca Vizzarro <luca.vizzarro@arm.com>,
Paul Szczepanek <paul.szczepanek@arm.com>,
Patrick Robb <probb@iol.unh.edu>
Subject: [PATCH v2 2/3] dts: add facility to change file permissions
Date: Tue, 6 May 2025 14:29:32 +0100 [thread overview]
Message-ID: <20250506132933.1580584-3-luca.vizzarro@arm.com> (raw)
In-Reply-To: <20250506132933.1580584-1-luca.vizzarro@arm.com>
Add an abstraction to handle file permissions for the remote.
Signed-off-by: Luca Vizzarro <luca.vizzarro@arm.com>
Reviewed-by: Paul Szczepanek <paul.szczepanek@arm.com>
---
dts/framework/testbed_model/os_session.py | 34 ++++++++++++++++++++
dts/framework/testbed_model/posix_session.py | 11 ++++++-
2 files changed, 44 insertions(+), 1 deletion(-)
diff --git a/dts/framework/testbed_model/os_session.py b/dts/framework/testbed_model/os_session.py
index 354c607357..869d575f0e 100644
--- a/dts/framework/testbed_model/os_session.py
+++ b/dts/framework/testbed_model/os_session.py
@@ -26,6 +26,7 @@
from abc import ABC, abstractmethod
from collections.abc import Iterable
from dataclasses import dataclass
+from enum import Flag, auto
from pathlib import Path, PurePath, PurePosixPath
from framework.config.node import NodeConfiguration
@@ -44,6 +45,33 @@
from .port import Port
+class FilePermissions(Flag):
+ """The permissions for a file and/or directory."""
+
+ #:
+ OTHERS_EXECUTE = auto()
+ #:
+ OTHERS_WRITE = auto()
+ #:
+ OTHERS_READ = auto()
+ #:
+ GROUP_EXECUTE = auto()
+ #:
+ GROUP_WRITE = auto()
+ #:
+ GROUP_READ = auto()
+ #:
+ OWNER_EXECUTE = auto()
+ #:
+ OWNER_WRITE = auto()
+ #:
+ OWNER_READ = auto()
+
+ def to_octal(self) -> str:
+ """Convert this flag to an octal representation."""
+ return format(self.value, "03o")
+
+
@dataclass(slots=True, frozen=True)
class OSSessionInfo:
"""Supplemental OS session information.
@@ -313,6 +341,12 @@ def copy_dir_to(
These patterns are used with `fnmatch.fnmatch` to filter out files.
"""
+ @abstractmethod
+ def change_permissions(
+ self, remote_path: PurePath, permissions: FilePermissions, recursive: bool = False
+ ) -> None:
+ """Change the permissions of the given path."""
+
@abstractmethod
def remove_remote_file(self, remote_file_path: str | PurePath, force: bool = True) -> None:
"""Remove remote file, by default remove forcefully.
diff --git a/dts/framework/testbed_model/posix_session.py b/dts/framework/testbed_model/posix_session.py
index 2d2701e1cf..fcd2faad6b 100644
--- a/dts/framework/testbed_model/posix_session.py
+++ b/dts/framework/testbed_model/posix_session.py
@@ -26,7 +26,7 @@
)
from .cpu import Architecture
-from .os_session import OSSession, OSSessionInfo
+from .os_session import FilePermissions, OSSession, OSSessionInfo
class PosixSession(OSSession):
@@ -146,6 +146,15 @@ def copy_dir_to(
self.extract_remote_tarball(remote_tar_path)
self.remove_remote_file(remote_tar_path)
+ def change_permissions(
+ self, remote_path: PurePath, permissions: FilePermissions, recursive: bool = False
+ ) -> None:
+ """Overrides :meth:`~.os_session.OSSession.change_permissions`."""
+ self.send_command(
+ f"chmod {'-R ' if recursive else ''}{permissions.to_octal()} {remote_path}",
+ privileged=True,
+ )
+
def remove_remote_file(self, remote_file_path: str | PurePath, force: bool = True) -> None:
"""Overrides :meth:`~.os_session.OSSession.remove_remote_dir`."""
opts = PosixSession.combine_short_options(f=force)
--
2.43.0
next prev parent reply other threads:[~2025-05-06 13:31 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-03-31 15:57 [PATCH 0/2] dts: add packet capture test suite Thomas Wilks
2025-03-31 15:57 ` [PATCH 1/2] " Thomas Wilks
2025-04-10 17:04 ` Dean Marx
2025-04-10 22:46 ` Stephen Hemminger
2025-03-31 15:58 ` [PATCH 2/2] dts: import lldp package in scapy Thomas Wilks
2025-04-10 17:06 ` Dean Marx
2025-05-06 13:29 ` [PATCH v2 0/3] dts: add packet capture test suite Luca Vizzarro
2025-05-06 13:29 ` [PATCH v2 1/3] dts: import lldp package in scapy Luca Vizzarro
2025-05-06 13:29 ` Luca Vizzarro [this message]
2025-05-06 13:29 ` [PATCH v2 3/3] dts: add packet capture test suite Luca Vizzarro
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20250506132933.1580584-3-luca.vizzarro@arm.com \
--to=luca.vizzarro@arm.com \
--cc=dev@dpdk.org \
--cc=paul.szczepanek@arm.com \
--cc=probb@iol.unh.edu \
--cc=stephen@networkplumber.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).