Skip to content

Commit

Permalink
add Scanner, UnitTestScanner, ValgrindScanner
Browse files Browse the repository at this point in the history
1. add 'run_unit_test' to Remote
2. create util/scanner.py
3. new exception: UnitTestError
4. add `lxml` dependency in setup.cfg

Signed-off-by: Vallari Agrawal <[email protected]>
  • Loading branch information
VallariAg committed Oct 9, 2023
1 parent 54e62bc commit a0224e7
Show file tree
Hide file tree
Showing 5 changed files with 266 additions and 2 deletions.
1 change: 1 addition & 0 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ install_requires =
httplib2
humanfriendly
lupa
lxml
ndg-httpsclient
netaddr
paramiko
Expand Down
24 changes: 24 additions & 0 deletions teuthology/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -212,3 +212,27 @@ class NoRemoteError(Exception):

def __str__(self):
return self.message


class UnitTestError(Exception):
"""
Exception thrown on unit test failure
"""
def __init__(self, exitstatus=None, node=None, label=None, message=None):
self.exitstatus = exitstatus
self.node = node
self.label = label
self.message = message

def __str__(self):
prefix = "Unit test failed"
if self.label:
prefix += " ({label})".format(label=self.label)
if self.node:
prefix += " on {node}".format(node=self.node)
if self.exitstatus:
prefix += " with status {status}".format(status=self.exitstatus)
return "{prefix}: '{message}'".format(
prefix=prefix,
message=self.message,
)
21 changes: 19 additions & 2 deletions teuthology/orchestra/remote.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@
from teuthology.orchestra.opsys import OS
import teuthology.provision
from teuthology import misc
from teuthology.exceptions import CommandFailedError
from teuthology.exceptions import CommandFailedError, UnitTestError
from teuthology.util.scanner import UnitTestScanner
from teuthology.misc import host_shortname
import errno
import re
Expand Down Expand Up @@ -523,6 +524,20 @@ def run(self, **kwargs):
r.remote = self
return r

def run_unit_test(self, xml_path_regex, output_yaml, **kwargs):
try:
r = self.run(**kwargs)
except CommandFailedError as exc:
if xml_path_regex:
error_msg = UnitTestScanner(remote=self).scan_and_write(xml_path_regex, output_yaml)
if error_msg:
raise UnitTestError(
exitstatus=exc.exitstatus, node=exc.node,
label=exc.label, message=error_msg
)
raise exc
return r

def _sftp_put_file(self, local_path, remote_path):
"""
Use the paramiko.SFTPClient to put a file. Returns the remote filename.
Expand All @@ -543,12 +558,14 @@ def _sftp_get_file(self, remote_path, local_path):
sftp.get(remote_path, local_path)
return local_path

def _sftp_open_file(self, remote_path):
def _sftp_open_file(self, remote_path, mode=None):
"""
Use the paramiko.SFTPClient to open a file. Returns a
paramiko.SFTPFile object.
"""
sftp = self.ssh.open_sftp()
if mode:
return sftp.open(remote_path, mode)
return sftp.open(remote_path)

def _sftp_get_size(self, remote_path):
Expand Down
Loading

0 comments on commit a0224e7

Please sign in to comment.