-
Notifications
You must be signed in to change notification settings - Fork 179
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Chown Tool: remove broken shell.chown and replace with node.tools[Chown]
- Loading branch information
1 parent
a4e9a3c
commit 3365d7b
Showing
3 changed files
with
55 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
# Copyright (c) Microsoft Corporation. | ||
# Licensed under the MIT license. | ||
|
||
from pathlib import PurePath | ||
from typing import List | ||
|
||
from assertpy import assert_that | ||
|
||
from lisa.executable import Tool | ||
|
||
|
||
class Chown(Tool): | ||
@property | ||
def command(self) -> str: | ||
return "chown" | ||
|
||
def _check_exists(self) -> bool: | ||
return self.node.is_posix | ||
|
||
def change_owner( | ||
self, file: PurePath, user: str = "", group: str = "", recurse: bool = False | ||
) -> None: | ||
# from manpage: | ||
# chown [OPTION]... [OWNER][:[GROUP]] FILE... | ||
arguments: List[str] = [] | ||
|
||
# option for recursive chown for a folder | ||
if recurse: | ||
arguments.append("-R") | ||
|
||
# add [OWNER][:[GROUP]] | ||
if group: | ||
group = f":{group}" | ||
new_owner = f"{user}{group}" | ||
if new_owner: | ||
arguments.append(new_owner) | ||
|
||
# add FILE | ||
assert_that(str(file)).described_as( | ||
"chown: filepath was empty and file is a required argument" | ||
).is_true() | ||
arguments.append(f"{str(file)}") | ||
|
||
# execute chown | ||
self.run( | ||
parameters=" ".join(arguments), | ||
shell=True, | ||
sudo=True, | ||
expected_exit_code=0, | ||
expected_exit_code_failure_message=( | ||
f"Chown failed to change owner for {file}" | ||
), | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters