Exemplo n.º 1
0
 def art_log(self, level_name, message, kwargs):
     art_log_record = {
         'level': level_name,
         'message': safe_string(message),
         'extra': kwargs.get('extra', '')
     }
     self.artifactor.fire_hook('log_message', log_record=art_log_record, slaveid=self.slaveid)
Exemplo n.º 2
0
 def art_log(self, level_name, message, kwargs):
     art_log_record = {
         'level': level_name,
         'message': safe_string(message),
         'extra': kwargs.get('extra', '')
     }
     self.artifactor.fire_hook('log_message', log_record=art_log_record, slaveid=self.slaveid)
Exemplo n.º 3
0
    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 slaveid is not None:
            if not slaveid:
                slaveid = "Master"
            test_ident = "{}/{}".format(self.store[slaveid]['test_location'],
                                        self.store[slaveid]['test_name'])
        else:
            test_ident = "{}/{}".format(test_location, 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}}}
Exemplo n.º 4
0
def pytest_exception_interact(node, call, report):
    from fixtures.artifactor_plugin import SLAVEID
    name, location = get_test_idents(node)
    val = safe_string(call.excinfo.value.message).decode('utf-8', 'ignore')
    short_tb = '{}\n{}'.format(
        call.excinfo.type.__name__, val.encode('ascii', 'xmlcharrefreplace'))
    art_client.fire_hook('filedump', test_location=location, test_name=name,
        description="Traceback", contents=str(report.longrepr), file_type="traceback",
        display_type="danger", display_glyph="align-justify", group_id="pytest-exception",
        slaveid=SLAVEID)
    art_client.fire_hook('filedump', test_location=location, test_name=name,
        description="Short traceback", contents=short_tb, file_type="short_tb",
        display_type="danger", display_glyph="align-justify", group_id="pytest-exception",
        slaveid=SLAVEID)

    # base64 encoded to go into a data uri, same for screenshots
    full_tb = str(report.longrepr).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:
        art_client.fire_hook('filedump', test_location=location, test_name=name,
            description="Exception screenshot", file_type="screenshot", mode="wb",
            contents_base64=True, contents=template_data['screenshot'], display_glyph="camera",
            group_id="pytest-exception", slaveid=SLAVEID)
    if screenshot.error:
        art_client.fire_hook('filedump', test_location=location, test_name=name,
            description="Screenshot error", mode="w", contents_base64=False,
            contents=template_data['screenshot_error'], display_type="danger",
            group_id="pytest-exception", slaveid=SLAVEID)

    failed_test_tracking['tests'].append(template_data)
    if is_error:
        failed_test_tracking['total_errored'] += 1
    else:
        failed_test_tracking['total_failed'] += 1
Exemplo n.º 5
0
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 x in all_systems_dict:
            if x['id'].lower() in system_release.lower():
                return x
    else:
        return WINDOWS
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 x in all_systems_dict:
            if x['id'].lower() in system_release.lower():
                return x
    else:
        return WINDOWS
Exemplo n.º 7
0
    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 slaveid is not None:
            if not slaveid:
                slaveid = "Master"
            test_ident = "{}/{}".format(self.store[slaveid]['test_location'],
                self.store[slaveid]['test_name'])
        else:
            test_ident = "{}/{}".format(test_location, 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}}}
Exemplo n.º 8
0
 def process(self, msg, kwargs):
     # frames
     # 0: call to nth_frame_info
     # 1: adapter process method (this method)
     # 2: adapter logging method
     # 3: original logging call
     msg = safe_string(msg)
     frameinfo = nth_frame_info(3)
     extra = kwargs.get('extra', {})
     # add extra data if needed
     if not extra.get('source_file'):
         if frameinfo.filename:
             extra['source_file'] = get_rel_path(frameinfo.filename)
             extra['source_lineno'] = frameinfo.lineno
         else:
             # calling frame didn't have a filename
             extra['source_file'] = 'unknown'
             extra['source_lineno'] = 0
     kwargs['extra'] = extra
     return msg, kwargs
Exemplo n.º 9
0
 def process(self, msg, kwargs):
     # frames
     # 0: call to nth_frame_info
     # 1: adapter process method (this method)
     # 2: adapter logging method
     # 3: original logging call
     msg = safe_string(msg)
     frameinfo = nth_frame_info(3)
     extra = kwargs.get('extra', {})
     # add extra data if needed
     if not extra.get('source_file'):
         if frameinfo.filename:
             extra['source_file'] = get_rel_path(frameinfo.filename)
             extra['source_lineno'] = frameinfo.lineno
         else:
             # calling frame didn't have a filename
             extra['source_file'] = 'unknown'
             extra['source_lineno'] = 0
     kwargs['extra'] = extra
     return msg, kwargs
Exemplo n.º 10
0
def test_safe_string(source, result):
    assert safe_string(source) == result
Exemplo n.º 11
0
 def filter(self, record):
     if self.prefix:
         record.msg = "{0}{1}".format(safe_string(self.prefix), safe_string(record.msg))
     return True
Exemplo n.º 12
0
#!/usr/bin/env python2
from __future__ import print_function
import os
import sys

from utils import safe_string
from 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)
Exemplo n.º 13
0
#!/usr/bin/env python2
from __future__ import print_function
import os
import sys

from utils import safe_string
from 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)
Exemplo n.º 14
0
 def filter(self, record):
     if self.prefix:
         record.msg = "{0}{1}".format(safe_string(self.prefix),
                                      safe_string(record.msg))
     return True
Exemplo n.º 15
0
 def art_log(self, level_name, message, kwargs):
     art_log_record = {"level": level_name, "message": safe_string(message), "extra": kwargs.get("extra", "")}
     self.artifactor.fire_hook("log_message", log_record=art_log_record, slaveid=self.slaveid)
Exemplo n.º 16
0
def pytest_exception_interact(node, call, report):
    from fixtures.pytest_store import store
    from httplib import BadStatusLine
    from socket import error
    import urllib2

    val = safe_string(call.excinfo.value.message).decode('utf-8', 'ignore')

    if isinstance(call.excinfo.value, (urllib2.URLError, BadStatusLine, error)):
        logger.error("internal Exception:\n %s", str(call.excinfo))
        from utils.browser import manager
        manager.start()  # start will quit first and cycle wharf as well

    short_tb = '{}\n{}'.format(
        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)

    # 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
Exemplo n.º 17
0
def test_safe_string(source, result):
    assert safe_string(source) == result