Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

NAS-130858 / 24.10-RC.1 / remove file exclusion from ixdiagnose on enterprise systems (by themylogin) #219

Merged
merged 1 commit into from
Aug 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions ixdiagnose/plugins/metrics/command.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ def execute_impl(self) -> Tuple[List, str]:
cmd_context = []
metric_report = []
for cmd in self.cmds:
cmd.execution_context = self.execution_context
start_time = time.time()
cp = cmd.execute()
report = {
Expand Down
39 changes: 25 additions & 14 deletions ixdiagnose/plugins/system_state.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,20 +53,30 @@ def get_root_ds(client: None, resource_type: str) -> dict:
return report


def usr_postprocess(lines: str) -> str:
result = []
for line in lines.splitlines():
try:
filename = line.split(maxsplit=1)[1].strip()
except IndexError:
pass
else:
if can_be_modified(filename):
continue
class UsrPostprocess:
def __init__(self):
self.is_enterprise = None

result.append(line)
def __call__(self, execution_context, lines: str) -> str:
if self.is_enterprise is None:
self.is_enterprise = execution_context['middleware_client'].call('system.is_enterprise')

return "\n".join(result)
if self.is_enterprise:
return lines

result = []
for line in lines.splitlines():
try:
filename = line.split(maxsplit=1)[1].strip()
except IndexError:
pass
else:
if can_be_modified(filename):
continue

result.append(line)

return "\n".join(result)


def can_be_modified(filename: str) -> bool:
Expand Down Expand Up @@ -155,8 +165,9 @@ class SystemState(Plugin):
CommandMetric(f'{ds.split("/")[-1]}_dataset_diff', [
Command(
['zfs', 'diff', f'{ds}@pristine'],
f'changes of {ds} dataset', serializable=False,
postprocess=usr_postprocess if ds.split('/')[-1] == 'usr' else None
f'changes of {ds} dataset',
serializable=False,
postprocess=UsrPostprocess() if ds.split('/')[-1] == 'usr' else None,
)],
)
for ds in get_ds_list()
Expand Down
7 changes: 4 additions & 3 deletions ixdiagnose/utils/command.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from collections.abc import Callable
import subprocess
from typing import Optional, Union
from typing import Any, Optional, Union

from .run import run

Expand All @@ -10,7 +10,7 @@ class Command:
def __init__(
self, command: Union[str, list], description: str, serializable: bool = True,
safe_returncodes: list = None, env: Optional[dict] = None, max_lines: Optional[int] = None,
postprocess: Optional[Callable[[str], str]] = None,
postprocess: Optional[Callable[[Any, str], str]] = None,
):
self.command: Union[str, list] = command
self.description: str = description
Expand All @@ -19,12 +19,13 @@ def __init__(
self.serializable: bool = serializable
self.safe_returncodes: list = safe_returncodes or [0]
self.postprocess = postprocess
self.execution_context: Any = None

def execute(self) -> subprocess.CompletedProcess:
cp = run(self.command, check=False, env=self.env)
if cp.returncode in self.safe_returncodes:
if self.postprocess:
cp.stdout = self.postprocess(cp.stdout)
cp.stdout = self.postprocess(self.execution_context, cp.stdout)
if self.max_lines:
cp.stdout = "\n".join(cp.stdout.splitlines()[:self.max_lines])
return cp
Loading