pytest_mh.utils.fs
Classes
|
Perform file system operations on remote host. |
- class pytest_mh.utils.fs.LinuxFileSystem(*args, **kwargs)
Bases:
MultihostReentrantUtility[MultihostHost]Perform file system operations on remote host.
All changes are automatically reverted when a test is finished.
- Parameters:
host (MultihostHost) – Remote host instance.
- mkdir(path: str, *, mode: str | None = None, user: str | None = None, group: str | None = None) None
Create directory on remote host.
- mkdir_p(path: str, *, mode: str | None = None, user: str | None = None, group: str | None = None) None
Create directory on remote host, including all missing parent directories.
- mktmp(contents: str | None = None, *, mode: str | None = None, user: str | None = None, group: str | None = None, dedent: bool = True) str
Create temporary file on remote host.
- Parameters:
contents (str | None) – File contents to write.
mode (str | None, optional) – Access mode (chmod value), defaults to None
user (str | None, optional) – Owner, defaults to None
group (str | None, optional) – Group, defaults to None
dedent (bool, optional) – Automatically dedent and strip file contents, defaults to True
- Raises:
OSError – If the file can not be created.
- Returns:
Temporary file path.
- Return type:
- write(path: str, contents: str, *, mode: str | None = None, user: str | None = None, group: str | None = None, dedent: bool = True) None
Write to a remote file.
- Parameters:
path (str) – File path.
contents (str) – File contents to write.
mode (str | None, optional) – Access mode (chmod value), defaults to None
user (str | None, optional) – Owner, defaults to None
group (str | None, optional) – Group, defaults to None
dedent (bool, optional) – Automatically dedent and strip file contents, defaults to True
- touch(path: str, *, mode: str | None = None, user: str | None = None, group: str | None = None) None
Touch a remote file.
- Parameters:
- copy(srcpath: str, dstpath: str, *, mode: str | None = None, user: str | None = None, group: str | None = None) None
Copy a remote file @srcpath to remote @dstpath.
- Parameters:
srcpath (str) – Remote source file path.
dstpath (str) – Remote destination file path.
mode (str | None, optional) – Access mode (chmod value), defaults to None
user (str | None, optional) – Owner, defaults to None
group (str | None, optional) – Group, defaults to None
dedent (bool, optional) – Automatically dedent and strip file contents, defaults to True
- upload(local_path: str, remote_path: str, *, mode: str | None = None, user: str | None = None, group: str | None = None) None
Upload local file.
- upload_to_tmp(local_path: str, *, mode: str | None = None, user: str | None = None, group: str | None = None) str
Upload local file to a new temporary file on remote host.
- download_files(paths: list[str], local_path: str) None
Download multiple files from remote host. The files are stored in single gzipped tarball on the local machine. The remote file path may contain glob pattern.
- backup(path: str) bool
Backup file or directory.
The path is automatically restored from the backup when a test is finished.
Note
It is also possible that the file or directory does not exist. In that case, the path is removed during the teardown process to remove any file or directory that might have been created.
- restore(path: str) bool
Restore file or directory from previous backup.
Note
It is also possible that the file or directory does not exist. In that case, the path is removed to remove any file or directory that might have been created.
- wc(file: str, lines: bool = False, word: bool = False, bytes: bool = False, chars: bool = False) ProcessResult
Print newline, word, and byte counts for specific file.
Output example without additional arguments:
67 564 3514 file_name- Parameters:
file (str) – File whose content is counted
lines (bool, optional) – Print the newline counts, defaults to False
word (bool, optional) – Print the word counts, defaults to False
bytes (bool, optional) – Print the byte counts, defaults to False
chars (bool, optional) – Print the character counts, defaults to False
- Returns:
Result of process
- Return type:
- diff(path1: str, path2: str, *, brief: bool = False, recursive: bool = False, ignore_case: bool = False, args: list[str] | None = None) ProcessResult
Compare files line by line. Exit status is 0 if inputs are the same, 1 if different, 2 if trouble.
- Parameters:
path1 (str) – Path to file or directory to be compared
path2 (str) – Path to file or directory to be compared
brief (bool, optional) – Report only when files differ, but do not print the diff itself, defaults to False
recursive (bool, optional) – Recursively compare any subdirectories found, defaults to False
ignore_case (bool, optional) – Ignore case differences in file contents, defaults to False
args (list[str] | None, optional) – Additional options, defaults to None
- Returns:
Result of process
- Return type:
- chmod(mode: str, path: str, args: list[str] | None = None) ProcessResult
Change file/folder mode bits. Mode can be specified in two ways: octal number e.g. “666”, “444” or a symbolic representation of changes e.g. “u=rw,go=r”, “go-rw”
- Parameters:
- Returns:
Result of process
- Return type:
- chown(path: str, user: str | None = None, group: str | None = None, args: list[str] | None = None) ProcessResult
Change file owner and group.
- Parameters:
- Returns:
Result of process
- Return type: