-
Notifications
You must be signed in to change notification settings - Fork 123
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
Implement the new test check watchdog
#2412
Conversation
A building block for #1523 - it needs more testing, I started a test but it's not enough, and I need to get more input from users and owners of existing tools to do things correctly. And documentation, of course. |
e908fd3
to
05f7d30
Compare
Just stating obvious: Add 'nmap-ncat' (where 'nc' belongs) as a Require to tmt.spec. It is not guaranteed to be on the system. |
Good point, even though I'm not anywhere near even thinking about requirements, I would definitely forget to do add it :) |
88b7b9f
to
6da1466
Compare
8fcea56
to
adfe36a
Compare
274811a
to
670d144
Compare
adfe36a
to
a58c92d
Compare
0c9410b
to
bc5122b
Compare
bc5122b
to
d88d03a
Compare
3048fc8
to
2f8b595
Compare
Should we 'hide' watchdog messages (via log topic) from the log.txt? Otherwise the log.txt will be full of
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
some small thing from me
Tough question. I for one do not care that much about content of the log file, there's already plenty of stuff that makes it less usable for me, namely output of tests. So I'm not that worried. But I get the point, and there might be ways how to reduce it. E.g. those three lines from stderr are completely useless, interesting only when Not sure I'd like to block this PR on reducing verbosity, but I'd be very happy to help reduce it. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
@lukaszachy would something like this make things better? diff --git a/tmt/checks/watchdog.py b/tmt/checks/watchdog.py
index 00c2cb7b..9815d19d 100644
--- a/tmt/checks/watchdog.py
+++ b/tmt/checks/watchdog.py
@@ -200,12 +200,7 @@ class WatchdogCheck(Check):
guest_context.ping_failures = 0
- report_progress(
- log,
- 'ping',
- report,
- command_output=ping_output
- )
+ report_progress(log, 'ping', report)
def _handle_output(ping_output: str) -> None:
""" Process ``ping`` output and decide on its outcome """
@@ -243,7 +238,8 @@ class WatchdogCheck(Check):
'-c',
str(self.ping_packets),
invocation.guest.primary_address) .run(cwd=Path.cwd(),
- logger=logger)
+ logger=logger,
+ stream_output=False)
_handle_output(output.stdout or '')
@@ -313,12 +309,7 @@ class WatchdogCheck(Check):
guest_context.ssh_ping_failures = 0
- report_progress(
- log,
- 'ssh-ping',
- report,
- command_output=ncat_output
- )
+ report_progress(log, 'ssh-ping', report)
try:
assert invocation.guest.primary_address is not None # narrow type
@@ -327,7 +318,8 @@ class WatchdogCheck(Check):
'-zv',
invocation.guest.primary_address,
str(invocation.guest.port or 22)) .run(cwd=Path.cwd(),
- logger=logger)
+ logger=logger,
+ stream_output=False)
_success(output.stderr or '')
diff --git a/tmt/utils.py b/tmt/utils.py
index 38015b11..cc9c82ca 100644
--- a/tmt/utils.py
+++ b/tmt/utils.py
@@ -965,7 +965,8 @@ class StreamLogger(Thread):
*,
stream: Optional[IO[bytes]] = None,
logger: Optional[tmt.log.LoggingFunction] = None,
- click_context: Optional[click.Context] = None) -> None:
+ click_context: Optional[click.Context] = None,
+ stream_output: bool = True) -> None:
super().__init__(daemon=True)
self.stream = stream
@@ -973,6 +974,7 @@ class StreamLogger(Thread):
self.log_header = log_header
self.logger = logger
self.click_context = click_context
+ self.stream_output = stream_output
def run(self) -> None:
if self.stream is None:
@@ -986,7 +988,7 @@ class StreamLogger(Thread):
for _line in self.stream:
line = _line.decode('utf-8', errors='replace')
- if line != '':
+ if line != '' and self.stream_output:
self.logger(
self.log_header,
line.rstrip('\n'),
@@ -1155,6 +1157,7 @@ class Command:
friendly_command: Optional[str] = None,
log: Optional[tmt.log.LoggingFunction] = None,
silent: bool = False,
+ stream_output: bool = True,
caller: Optional['Common'] = None,
logger: tmt.log.Logger) -> CommandOutput:
"""
@@ -1277,7 +1280,8 @@ class Command:
'out',
stream=process.stdout,
logger=output_logger,
- click_context=click.get_current_context(silent=True))
+ click_context=click.get_current_context(silent=True),
+ stream_output=stream_output)
if join:
stderr_logger: StreamLogger = UnusedStreamLogger('err')
@@ -1287,7 +1291,8 @@ class Command:
'err',
stream=process.stderr,
logger=output_logger,
- click_context=click.get_current_context(silent=True))
+ click_context=click.get_current_context(silent=True),
+ stream_output=stream_output)
stdout_logger.start()
stderr_logger.start()
@@ -1347,6 +1352,15 @@ class Command:
if process.returncode != 0:
logger.debug(f"Command returned '{process.returncode}'.", level=3)
+ if not stream_output:
+ if stdout is not None:
+ for line in stdout.splitlines():
+ output_logger('out', value=line, color='yellow', level=3)
+
+ if stderr is not None:
+ for line in stderr.splitlines():
+ output_logger('err', value=line, color='yellow', level=3)
+
raise RunError(
f"Command '{friendly_command or str(self)}' returned {process.returncode}.",
self, |
@happz Much better. thanks. |
Ok, I’ll make a PR out of it |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks very nice! Thanks for implementing this. Added just a few comments plus:
- would be good to mention this new feature in the release notes
- shall we update the
check
json schema as well with the new keys?
Right, I forgot about these two:
Added in 410efea.
Yes, but it won't be that simple, I forgot we need to turn this part of the specification to load schema for plugins. It's lucky accident that |
Understood. So, I guess, we won't block this pull request on that. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the changes. I just fixed a typo in cd22384 plus added the provision-only
tag to the avc
test as it needs root
so it should not be run by default.
Ture, it does need root-level access, but it seems to be running fine in our tests so far, e.g. https://artifacts.dev.testing-farm.io/be3c3e72-d3b6-492d-b34b-bfc46cf3977e/work-basicvfupy5_c/plans/features/basic/execute/data/guest/default-0/tests/test/check/avc-33/output.txt |
Yeah, but that is an unnecessary duplication as it is already running under |
Aha, I wasn't aware there's |
Pull Request Checklist