예제 #1
0
    def _healthcheck(self):
        target = self.target
        target.power.off()
        power = target.power.get()
        if power != False:
            raise tc.failed_e("power should be False, reported %s" % power)

        target.report_pass("power is reported correctly as %s" % power)

        target.power.on()
        power = target.power.get()
        state, substate, components = target.power.list()
        if power != True:
            raise tc.failed_e("power should be True, reported %s" % power,
                              dict(state = state, substate = substate,
                                   components = components, power = power))
        target.report_pass("power is reported correctly as %s" % power)

        target.power.cycle()
        components = target.power.list()
        target.report_pass("power components listed",
                           dict(components = components))

        target.power.off()
        power = target.power.get()
        if power != False:
            raise tc.failed_e("power should be False, reported %s" % power)
        target.report_pass("power is reported correctly as %s" % power)
예제 #2
0
    def _healthcheck(self):
        target = self.target
        l0 = target.store.list()
        target.report_pass("got existing list of files", dict(l0 = l0))

        tmpname = commonl.mkid(str(id(target))) + ".1"
        target.store.upload(tmpname, __file__)
        target.report_pass("uploaded file %s" % tmpname)
        l = target.store.list()
        # remove elements we knew existed (there might be other
        # processes in parallel using this )
        l = list(set(l) - set(l0))
        if len(l) != 1:
            raise tc.failed_e(
                "after uploading one file, %d are listed; expected 1" % len(l),
                dict(l = l))
        if l[0] != tmpname:
            raise tc.failed_e(
                "after uploading file, name differs, expected %s" % tmpname,
                dict(l = l))
        target.report_pass("listed afer uploading one")

        tmpname2 = commonl.mkid(str(id(target))) + ".2"
        target.store.upload(tmpname2, __file__)
        target.report_pass("uploaded second file %s" % tmpname2)
        l = target.store.list()
        l = list(set(l) - set(l0))
        if len(l) != 2:
            raise tc.failed_e(
                "after uploading another file, %d are listed, expected 2" % len(l),
                dict(l = l))
        if tmpname2 not in l:
            raise tc.failed_e(
                "after uploading file, can't find %s" % tmpname2,
                dict(l = l))
        target.report_pass("listed after uploading second file", dict(l = l))

        target.store.delete(tmpname)
        l = target.store.list()
        if tmpname in l:
            raise tc.failed_e(
                "after removing %s, still can find it in listing" % tmpname,
                dict(l = l))
        target.report_pass("removed %s" % tmpname)

        target.store.delete(tmpname2)
        l = target.store.list()
        if tmpname2 in l:
            raise tc.failed_e(
                "after removing %s, still can find it in listing" % tmpname2,
                dict(l = l))
        l = list(set(l) - set(l0))
        if l:
            raise tc.failed_e(
                "after removing all, list is not empty", dict(l = l))
        target.report_pass("all files removed report empty list")
def console_rx_eval(expecter,
                    target,
                    regex,
                    console=None,
                    _timeout=None,
                    result=None,
                    uid=None):
    """
    Check what came on a console and act on it

    :param str uid: (optional) identifier to use to store offset data
    """

    if hasattr(regex, "pattern"):
        what = regex.pattern
    else:
        what = regex
        regex = re.compile(re.escape(regex))

    if not uid:
        uid = console_mk_uid(target, what, console, _timeout, result)

    console_id_name, console_code = console_mk_code(target, console)
    # These were set by the poller
    of = expecter.buffers.get(console_code, None)
    if of == None:
        # FIXME: debug lof output here? expecter->tc backlink?
        return None
    ofd = of.fileno()
    ts = time.time()

    # Get the offset we saved before as the last part where we looked
    # at. If none, then get the last offset the poller has
    # recorded. Otherwise, just default to look from the start
    # Note the idea is each eval function has a different offset where
    # it is looking at. Likewise the poller for each console.
    offset_poller_code = "offset_" + console_code
    offset = expecter.buffers_persistent.get(
        uid, expecter.buffers_persistent.get(offset_poller_code, 0))
    if _timeout != False:
        timeout = expecter.timeout if _timeout == None else _timeout

        # We can do timeout checks that provide better information
        # than a generic 'timeout'
        if ts - expecter.ts0 > timeout:
            of.seek(offset)  # so we report console from where searched
            raise tc.error_e(
                "expected console output '%s' from console '%s:%s' " \
                "NOT FOUND after %.1f s" \
                % (what, target.id, console_id_name, ts - expecter.ts0),
                { 'target': target, "console output": of })

    # mmap the whole file (which doesn't alter the file pointer)
    #
    # We have to mmap as the file might be getting huge and thus,
    # reading line by line might be dumb.
    #
    # However, we only search starting at @offset, which is set later
    # to the last success searching we had. So we shan't really map
    # the whole file, shall map on demand.

    stat_info = os.fstat(ofd)
    if stat_info.st_size == 0:  # Nothing to read
        return None

    with contextlib.closing(
            mmap.mmap(of.fileno(), 0, mmap.MAP_PRIVATE, mmap.PROT_READ,
                      0)) as mapping:
        target.report_info("looking for `%s` in console %s:%s @%d-%d at "
                           "%.2fs [%s]" %
                           (what, target.fullid, console_id_name, offset,
                            stat_info.st_size, ts - expecter.ts0, of.name),
                           dlevel=3)
        m = regex.search(mapping[offset:])
        if m:
            new_offset = offset + m.end()
            expecter.buffers_persistent[uid] = new_offset
            if result == None or result == "pass":
                # raising pass gets stopped at expecter.run(), so we
                # print instead, so we can see the console
                offset_tip = of.tell()  # we report console from where searched
                of.seek(offset)  # so we report console from where searched
                target.report_pass(
                    "found expected `%s` in console `%s:%s` at %.2fs @%d" %
                    (what, target.fullid, console_id_name, ts - expecter.ts0,
                     offset + m.start()), {"console output": of},
                    dlevel=1,
                    alevel=2)
                of.seek(offset_tip)
                raise tc.pass_e(
                    "found expected `%s` in console `%s:%s` at %.2fs" %
                    (what, target.fullid, console_id_name, ts - expecter.ts0),
                    {'target': target})
            elif result == "fail":
                of.seek(offset)  # so we report console from where searched
                raise tc.failed_e(
                    "found expected (for failure) `%s` in console "
                    "`%s:%s` at %.2fs" %
                    (what, target.fullid, console_id_name, ts - expecter.ts0),
                    {
                        'target': target,
                        "console output": of
                    })
            elif result == "error" or result == "errr":
                of.seek(offset)  # so we report console from where searched
                raise tc.error_e(
                    "found expected (for error) `%s` in console "
                    "`%s:%s` at %.2fs" %
                    (what, target.fullid, console_id_name, ts - expecter.ts0),
                    {
                        'target': target,
                        "console output": of
                    })
            elif result == "skip":
                of.seek(offset)  # so we report console from where searched
                raise tc.skip_e(
                    "found expected (for skip) `%s` in console "
                    "'%s:%s' at %.2fs" %
                    (what, target.fullid, console_id_name, ts - expecter.ts0),
                    {
                        'target': target,
                        "console output": of
                    })
            else:
                of.seek(offset)  # so we report console from where searched
                raise tc.blocked_e("BUG: invalid result requested (%s)" %
                                   result)
    return None
예제 #4
0
    def _healthcheck(self):
        target = self.target
        interconnects = target.rt.get('interconnects', {})
        if interconnects == {}:
            target.report_skip("skipping tunnel healthcheck,"
                               " no IP connectivity in configuration, ")
            return
        target = self.target
        tunnels = target.tunnel.list()
        for protocol, ip_address, target_port, server_port in tunnels:
            target.report_info(
                "removing existing tunnel %s %s -> %s:%s" %
                (protocol, server_port, ip_address, target_port))
            target.tunnel.remove(target_port, ip_address, protocol)

        server_port_22 = target.tunnel.add(22)
        target.report_pass("added tunnel to port 22")

        tunnels = target.tunnel.list()
        if len(tunnels) != 1:
            raise tc.failed_e(
                "list() lists %d tunnels; expected 1" % len(tunnels),
                dict(tunnels=tunnels))
        target.report_pass("list() lists only one tunnel")
        if server_port_22 not in tunnels \
           or tunnels[server_port_22].get("port", None) != 22:
            raise tc.failed_e(
                "list() didn't report target port as 22 as requested",
                dict(tunnels=tunnels))
        target.report_pass("list() reports tunnel to 22 as requested")

        server_port_23 = target.tunnel.add(23)
        target.report_pass("added tunnel to port 23")

        tunnels = target.tunnel.list()

        if len(tunnels) != 2:
            raise tc.failed_e(
                "list() lists %d tunnels; expected 2" % len(tunnels),
                dict(tunnels=tunnels))
        target.report_pass("list() lists two tunnels")
        if server_port_22 not in tunnels \
           or tunnels[server_port_22].get("port", None) != 22:
            raise tc.failed_e(
                "list() didn't report target port as 22 as requested",
                dict(tunnels=tunnels))
        if server_port_23 not in tunnels \
           or tunnels[server_port_23].get("port", None) != 23:
            raise tc.failed_e(
                "list() didn't report target port as 23 as requested",
                dict(tunnels=tunnels))
        target.report_pass("list() reports tunnel to 22 and 23 as requested")

        target.tunnel.remove(22)
        target.report_pass("removed tunnel to port 22")
        tunnels = target.tunnel.list()
        if len(tunnels) != 1:
            raise tc.failed_e(
                "list() lists %d tunnels; expected 1" % len(tunnels),
                dict(tunnels=tunnels))

        # leftover tunnel is the one to port 23
        if server_port_23 not in tunnels \
           or tunnels[server_port_23].get("port", None) != 23:
            raise tc.failed_e(
                "list() didn't report target port as 23 as requested",
                dict(tunnels=tunnels))
        target.report_pass("list() lists only tunnel to port 23")
        target.tunnel.remove(23)
        target.report_pass("removed tunnel to port 23")
        tunnels = target.tunnel.list()
        if len(tunnels) != 0:
            raise tc.failed_e(
                "list() reports %d tunnels; expected none" % len(tunnels),
                dict(tunnels=tunnels))
        target.report_pass("no tunnels listed after removing all")
예제 #5
0
파일: expecter.py 프로젝트: intel/tcf
def console_rx_eval(expecter, target,
                    regex, console = None, _timeout = None, result = None,
                    uid = None):
    """
    Check what came on a console and act on it

    :param str uid: (optional) identifier to use to store offset data
    """

    if hasattr(regex, "pattern"):
        what = regex.pattern
    else:
        what = regex
        regex = re.compile(re.escape(regex))

    if not uid:
        uid = console_mk_uid(target, what, console, _timeout, result)

    console_id_name, console_code = console_mk_code(target, console)
    # These were set by the poller
    of = expecter.buffers.get(console_code, None)
    if of == None:
        # FIXME: debug lof output here? expecter->tc backlink?
        return None
    ofd = of.fileno()
    ts = time.time()

    # Get the offset we saved before as the last part where we looked
    # at. If none, then get the last offset the poller has
    # recorded. Otherwise, just default to look from the start
    # Note the idea is each eval function has a different offset where
    # it is looking at. Likewise the poller for each console.
    offset_poller_code = "offset_" + console_code
    offset = expecter.buffers_persistent.get(
        uid,
        expecter.buffers_persistent.get(offset_poller_code, 0))
    if _timeout != False:
        timeout = expecter.timeout if _timeout == None else _timeout

        # We can do timeout checks that provide better information
        # than a generic 'timeout'
        if ts - expecter.ts0 > timeout:
            of.seek(offset)	# so we report console from where searched
            raise tc.error_e(
                "expected console output '%s' from console '%s:%s' " \
                "NOT FOUND after %.1f s" \
                % (what, target.id, console_id_name, ts - expecter.ts0),
                { 'target': target, "console output": of })

    # mmap the whole file (which doesn't alter the file pointer)
    #
    # We have to mmap as the file might be getting huge and thus,
    # reading line by line might be dumb.
    #
    # However, we only search starting at @offset, which is set later
    # to the last success searching we had. So we shan't really map
    # the whole file, shall map on demand.

    stat_info = os.fstat(ofd)
    if stat_info.st_size == 0:	# Nothing to read
        return None

    with contextlib.closing(mmap.mmap(of.fileno(), 0, mmap.MAP_PRIVATE,
                                      mmap.PROT_READ, 0)) as mapping:
        target.report_info("looking for `%s` in console %s:%s @%d-%d at "
                           "%.2fs [%s]"
                           % (what, target.fullid, console_id_name, offset,
                              stat_info.st_size, ts - expecter.ts0, of.name),
                           dlevel = 3)
        m = regex.search(mapping[offset:])
        if m:
            new_offset = offset + m.end()
            expecter.buffers_persistent[uid] = new_offset
            if result == None or result == "pass":
                # raising pass gets stopped at expecter.run(), so we
                # print instead, so we can see the console
                offset_tip = of.tell()	# we report console from where searched
                of.seek(offset)	# so we report console from where searched
                target.report_pass(
                    "found expected `%s` in console `%s:%s` at %.2fs"
                    % (what, target.fullid, console_id_name,
                       ts - expecter.ts0),
                    { "console output": of }, dlevel = 1, alevel = 2)
                of.seek(offset_tip)
                raise tc.pass_e(
                    "found expected `%s` in console `%s:%s` at %.2fs"
                    % (what, target.fullid, console_id_name,
                       ts - expecter.ts0),
                    {'target': target })
            elif result == "fail":
                of.seek(offset)	# so we report console from where searched
                raise tc.failed_e(
                    "found expected (for failure) `%s` in console "
                    "`%s:%s` at %.2fs"
                    % (what, target.fullid, console_id_name,
                       ts - expecter.ts0),
                    { 'target': target, "console output": of })
            elif result == "error" or result == "errr":
                of.seek(offset)	# so we report console from where searched
                raise tc.error_e(
                    "found expected (for error) `%s` in console "
                    "`%s:%s` at %.2fs"
                    % (what, target.fullid, console_id_name,
                       ts - expecter.ts0),
                    { 'target': target, "console output": of })
            elif result == "skip":
                of.seek(offset)	# so we report console from where searched
                raise tc.skip_e(
                    "found expected (for skip) `%s` in console "
                    "'%s:%s' at %.2fs"
                    % (what, target.fullid, console_id_name,
                       ts - expecter.ts0),
                    { 'target': target, "console output": of })
            else:
                of.seek(offset)	# so we report console from where searched
                raise tc.blocked_e(
                    "BUG: invalid result requested (%s)" % result)
    return None