def filedump( self, description, contents, slaveid=None, mode="w", contents_base64=False, display_type="primary", display_glyph=None, file_type=None, dont_write=False, os_filename=None, group_id=None, test_name=None, test_location=None, ): if not slaveid: slaveid = "Master" test_ident = "{}/{}".format( self.store[slaveid]["test_location"], self.store[slaveid]["test_name"] ) artifacts = [] if os_filename is None: safe_name = re.sub(r"\s+", "_", normalize_text(safe_string(description))) os_filename = self.ident + "-" + safe_name os_filename = os.path.join(self.store[slaveid]["artifact_path"], os_filename) if file_type is not None and "screenshot" in file_type: os_filename = os_filename + ".png" elif file_type is not None and ( "_tb" in file_type or "traceback" in file_type or file_type == "log" ): os_filename = os_filename + ".log" elif file_type is not None and file_type == "html": os_filename = os_filename + ".html" elif file_type is not None and file_type == "video": os_filename = os_filename + ".ogv" else: os_filename = os_filename + ".txt" artifacts.append( { "file_type": file_type, "display_type": display_type, "display_glyph": display_glyph, "description": description, "os_filename": os_filename, "group_id": group_id, } ) if not dont_write: if os.path.isfile(os_filename): os.remove(os_filename) with open(os_filename, mode) as f: if contents_base64: contents = base64.b64decode(contents) f.write(contents) return None, {"artifacts": {test_ident: {"files": artifacts}}}
def filedump( self, description, contents, slaveid=None, mode="w", contents_base64=False, display_type="primary", display_glyph=None, file_type=None, dont_write=False, os_filename=None, group_id=None, test_name=None, test_location=None, ): if not slaveid: slaveid = "Master" test_ident = "{}/{}".format(self.store[slaveid]["test_location"], self.store[slaveid]["test_name"]) artifacts = [] if os_filename is None: safe_name = re.sub(r"\s+", "_", normalize_text(safe_string(description))) os_filename = self.ident + "-" + safe_name os_filename = os.path.join(self.store[slaveid]["artifact_path"], os_filename) if file_type is not None and "screenshot" in file_type: os_filename = os_filename + ".png" elif file_type is not None and ("_tb" in file_type or "traceback" in file_type or file_type == "log"): os_filename = os_filename + ".log" elif file_type is not None and file_type == "html": os_filename = os_filename + ".html" elif file_type is not None and file_type == "video": os_filename = os_filename + ".ogv" else: os_filename = os_filename + ".txt" artifacts.append({ "file_type": file_type, "display_type": display_type, "display_glyph": display_glyph, "description": description, "os_filename": os_filename, "group_id": group_id, }) if not dont_write: if os.path.isfile(os_filename): os.remove(os_filename) with open(os_filename, mode) as f: if contents_base64: contents = base64.b64decode(contents) f.write(contents) return None, {"artifacts": {test_ident: {"files": artifacts}}}
def detect_system_type(vm): if hasattr(vm, 'ssh'): system_release = safe_string(vm.ssh.run_command("cat /etc/os-release").output) all_systems_dict = RPM_BASED.values() + DEB_BASED.values() for systems_type in all_systems_dict: if systems_type['id'].lower() in system_release.lower(): return systems_type else: return WINDOWS
def main(): with open("{}/setup.txt".format(os.environ['ARTIFACTOR_DIR'])) as f: data = f.read() coverage = 0.0 try: with open("{}/coverage_result.txt".format(os.environ['CFME_REPO_DIR'])) as f: data = f.read().strip("\n") coverage = float(data) except Exception: pass print(sys.argv[1], sys.argv[2], coverage) post_task_result(sys.argv[1], sys.argv[2], safe_string(data), coverage)
def main(): with open("{}/setup.txt".format(os.environ['ARTIFACTOR_DIR'])) as f: data = f.read() coverage = 0.0 try: with open("{}/coverage_result.txt".format( os.environ['CFME_REPO_DIR'])) as f: data = f.read().strip("\n") coverage = float(data) except Exception: pass print(sys.argv[1], sys.argv[2], coverage) post_task_result(sys.argv[1], sys.argv[2], safe_string(data), coverage)
def pytest_exception_interact(node, call, report): from cfme.fixtures.pytest_store import store from six.moves.http_client import BadStatusLine from socket import error val = safe_string(call.excinfo.value) if isinstance(call.excinfo.value, (URLError, BadStatusLine, error)): logger.error("internal Exception:\n %s", str(call.excinfo)) from cfme.utils.browser import manager manager.start() # start will quit first and cycle wharf as well last_lines = "\n".join(report.longreprtext.split("\n")[-4:]) short_tb = '{}\n{}\n{}'.format( last_lines, call.excinfo.type.__name__, val.encode('ascii', 'xmlcharrefreplace') ) fire_art_test_hook( node, 'filedump', description="Traceback", contents=report.longreprtext, file_type="traceback", display_type="danger", display_glyph="align-justify", group_id="pytest-exception", slaveid=store.slaveid) fire_art_test_hook( node, 'filedump', description="Short traceback", contents=short_tb, file_type="short_tb", display_type="danger", display_glyph="align-justify", group_id="pytest-exception", slaveid=store.slaveid) exception_name = call.excinfo.type.__name__ exception_lineno = call.excinfo.traceback[-1].lineno exception_filename = str(call.excinfo.traceback[-1].path).replace( project_path.strpath + "/", '' ) exception_location = "{}:{}".format(exception_filename, exception_lineno) fire_art_test_hook( node, 'tb_info', exception=exception_name, file_line=exception_location, short_tb=short_tb, slave_id=store.slaveid ) # base64 encoded to go into a data uri, same for screenshots tb = report.longreprtext if not isinstance(tb, six.binary_type): tb = tb.encode('utf-8') full_tb = base64.b64encode(tb) # errors are when exceptions are thrown outside of the test call phase report.when = getattr(report, 'when', 'setup') is_error = report.when != 'call' template_data = { 'name': node.name, 'file': node.fspath, 'is_error': is_error, 'fail_stage': report.when, 'short_tb': short_tb, 'full_tb': full_tb, } # Before trying to take a screenshot, we used to check if one of the browser_fixtures was # in this node's fixturenames, but that was too limited and preventing the capture of # screenshots. If removing that conditional now makes this too broad, we should consider # an isinstance(val, WebDriverException) check in addition to the browser fixture check that # exists here in commit 825ef50fd84a060b58d7e4dc316303a8b61b35d2 screenshot = take_screenshot() template_data['screenshot'] = screenshot.png template_data['screenshot_error'] = screenshot.error if screenshot.png: fire_art_test_hook( node, 'filedump', description="Exception screenshot", file_type="screenshot", mode="wb", contents_base64=True, contents=template_data['screenshot'], display_glyph="camera", group_id="pytest-exception", slaveid=store.slaveid) if screenshot.error: fire_art_test_hook( node, 'filedump', description="Screenshot error", mode="w", contents_base64=False, contents=template_data['screenshot_error'], display_type="danger", group_id="pytest-exception", slaveid=store.slaveid) failed_test_tracking['tests'].append(template_data) if is_error: failed_test_tracking['total_errored'] += 1 else: failed_test_tracking['total_failed'] += 1
#!/usr/bin/env python2 from __future__ import print_function import os import sys from cfme.utils import safe_string from cfme.utils.trackerbot import post_task_result with open("{}/setup.txt".format(os.environ['ARTIFACTOR_DIR'])) as f: data = f.read() coverage = 0.0 try: with open("{}/coverage_result.txt".format(os.environ['CFME_REPO_DIR'])) as f: data = f.read().strip("\n") coverage = float(data) except: pass print(sys.argv[1], sys.argv[2], coverage) post_task_result(sys.argv[1], sys.argv[2], safe_string(data), coverage)
def pytest_exception_interact(node, call, report): from fixtures.pytest_store import store from six.moves.http_client import BadStatusLine from socket import error val = safe_string(call.excinfo.value.message).decode('utf-8', 'ignore') if isinstance(call.excinfo.value, (URLError, BadStatusLine, error)): logger.error("internal Exception:\n %s", str(call.excinfo)) from cfme.utils.browser import manager manager.start() # start will quit first and cycle wharf as well last_lines = "\n".join(report.longreprtext.split("\n")[-4:]) short_tb = '{}\n{}\n{}'.format( last_lines, call.excinfo.type.__name__, val.encode('ascii', 'xmlcharrefreplace') ) fire_art_test_hook( node, 'filedump', description="Traceback", contents=report.longreprtext, file_type="traceback", display_type="danger", display_glyph="align-justify", group_id="pytest-exception", slaveid=store.slaveid) fire_art_test_hook( node, 'filedump', description="Short traceback", contents=short_tb, file_type="short_tb", display_type="danger", display_glyph="align-justify", group_id="pytest-exception", slaveid=store.slaveid) exception_name = call.excinfo.type.__name__ exception_lineno = call.excinfo.traceback[-1].lineno exception_filename = str(call.excinfo.traceback[-1].path).replace( project_path.strpath + "/", '' ) exception_location = "{}:{}".format(exception_filename, exception_lineno) fire_art_test_hook( node, 'tb_info', exception=exception_name, file_line=exception_location, short_tb=short_tb, slave_id=store.slaveid ) # base64 encoded to go into a data uri, same for screenshots full_tb = report.longreprtext.encode('base64').strip() # errors are when exceptions are thrown outside of the test call phase report.when = getattr(report, 'when', 'setup') is_error = report.when != 'call' template_data = { 'name': node.name, 'file': node.fspath, 'is_error': is_error, 'fail_stage': report.when, 'short_tb': short_tb, 'full_tb': full_tb, } # Before trying to take a screenshot, we used to check if one of the browser_fixtures was # in this node's fixturenames, but that was too limited and preventing the capture of # screenshots. If removing that conditional now makes this too broad, we should consider # an isinstance(val, WebDriverException) check in addition to the browser fixture check that # exists here in commit 825ef50fd84a060b58d7e4dc316303a8b61b35d2 screenshot = take_screenshot() template_data['screenshot'] = screenshot.png template_data['screenshot_error'] = screenshot.error if screenshot.png: fire_art_test_hook( node, 'filedump', description="Exception screenshot", file_type="screenshot", mode="wb", contents_base64=True, contents=template_data['screenshot'], display_glyph="camera", group_id="pytest-exception", slaveid=store.slaveid) if screenshot.error: fire_art_test_hook( node, 'filedump', description="Screenshot error", mode="w", contents_base64=False, contents=template_data['screenshot_error'], display_type="danger", group_id="pytest-exception", slaveid=store.slaveid) failed_test_tracking['tests'].append(template_data) if is_error: failed_test_tracking['total_errored'] += 1 else: failed_test_tracking['total_failed'] += 1
def filter(self, record): if self.prefix: record.msg = "{0}{1}".format(safe_string(self.prefix), safe_string(record.msg)) return True
#!/usr/bin/env python2 from __future__ import print_function import os import sys from cfme.utils import safe_string from cfme.utils.trackerbot import post_task_result with open("{}/setup.txt".format(os.environ['ARTIFACTOR_DIR'])) as f: data = f.read() coverage = 0.0 try: with open("{}/coverage_result.txt".format( os.environ['CFME_REPO_DIR'])) as f: data = f.read().strip("\n") coverage = float(data) except: pass print(sys.argv[1], sys.argv[2], coverage) post_task_result(sys.argv[1], sys.argv[2], safe_string(data), coverage)
def test_safe_string(source, result): assert safe_string(source) == result