Пример #1
0
def cmd_status(args):
    try:
        check_status()
        print 'lb-web-server is running.'
    except IOError as e:
        if e.errno == errno.ECONNREFUSED:
            raise lb_exception.LBServerOff(
                'lb-web-server: connection refused (most likely server is not running)'
            )
        raise lb_exception.LBServerOff("lb-web-server: unexpected error '%s'" %
                                       e)
    except:
        raise lb_exception.LBServerOff("lb-web-server: unexpected error '%s'" %
                                       e)
Пример #2
0
 def open(self):
     try:
         return super(Connection, self).open()
     except IOError as e:
         if e.errno == errno.ECONNREFUSED:
             raise lb_exception.LBServerOff(
                 'lb-server: connection refused (most likely server is not running)'
             )
         else:
             raise e
Пример #3
0
def check_status(args, interactive=None):

    try:
        conn = _get_conn(args).open()
        cmd = lb_command.CheckStatusCommand.from_args(conn, args, interactive)
        result = cmd.run()
    # could not connect to lb-server, this is an expected exception
    # print to stdout and return 1, as expected by lb-services
    except lb_exception.LBServerOff as off_error:
        print off_error
        return 1
    # something else went wrong, throw an exception
    except Exception as e:
        raise lb_exception.LBServerOff("lb-server: {0}".format(e.strerror))

    print "lb-server is running."

    answeredWorkspaces = []
    if len(result.res.status.workspaces):
        print "---"

    for ws in result.res.status.workspaces:
        answeredWorkspaces.append(ws.name)

        if ws.num_requests == -1:
            print "Workspace '%s' is closed." % (ws.name)
        elif ws.num_requests == 0:
            print "Workspace '%s' is idle." % (ws.name)
        else:
            print "Workspace '%s' is processing" % (
                ws.name), ws.num_requests, "request(s)."

        for req in ws.requests:
            print text_format.MessageToString(req)

        for info in ws.debug_info:
            print info

    for ws in cmd.workspaces:
        if ws not in answeredWorkspaces:
            print "Workspace '%s' does not exist." % (ws)

    if len(result.res.status.debug_info):
        print "---"
    for info in result.res.status.debug_info:
        print info,
Пример #4
0
def no_measure_service(args, extra, command_line):
    raise lb_exception.LBServerOff(ERROR_MSG)
Пример #5
0
def main(args=None, supp_int_stdout=True, supp_int_stderr=True, supp_test_report=False):
    """
    runs set of tests given optional 'args' argument or takes from command line.
    optional 'suppress' argument for suppressing output from interactive REPL
    """
    # supp_int_stdout, supp_int_stderr suppress any output from running tests 
    # so that only test results are printed
    # by default they are True

    # supp_test_report suppresses output from results printed between tests 
    # such as progress and time, however the summary is still printed 
    # by default this is False

    #Check that lb services is started
    conn = blox.connect.io.Connection(False)
    try:
        conn.open()
    except Exception:
        raise lb_exception.LBServerOff()

    start_time = time.time()
    thread_count = 1
    test_queue = Queue.Queue()
    test_queue.count = 0
    error_list = []
    count_dict = {State.SUCCESS: 0, State.FAILURE: 0, State.ERROR: 0}
    stdout_orig = sys.stdout
    stderr_orig = sys.stderr
    Test.print_function = sys.stdout

    if args.defaultFixtures:
        # create default setup and teardown
        setup = tempfile.NamedTemporaryFile(delete=False)
        setup.write('create --unique')
        setup.close()

        teardown = tempfile.NamedTemporaryFile(delete=False)
        teardown.write('close --destroy')
        teardown.close()

        Test.default_set_up = setup.name
        Test.default_tear_down = teardown.name

    # find suites and tests from command line arguments
    add_all_tests(args, test_queue)

    # if list option, print tests and then return
    if args.list:
        print_list(test_queue)
        return

    # suppress stdout and stderr from interactive
    if supp_int_stdout:
        sys.stdout = StringIO()
    if supp_int_stderr:
        sys.stderr = StringIO()
    if supp_test_report:
        Test.print_function = StringIO()

    # set thread count
    if args.sequential:
        thread_count = 1
    elif args.threads != None:
        thread_count = args.threads

    # spawn a pool of threads, and pass them queue instance
    for i in range(int(thread_count)):
        thread = ThreadTest(test_queue, error_list, count_dict,
                       args.noCleanup)
        thread.setDaemon(True)
        thread.start()

    Test.print_progress = args.progress
    Test.print_time = args.time

    # wait on the queue until everything has been processed
    while test_queue.count != 0:
        try:
            conn.open()
            time.sleep(0.1)
        except socket.error:
            raise lb_exception.LBServerOff()

    Test.default_set_up = None
    Test.default_tear_down = None

    # restore stdout and stderr
    sys.stdout = stdout_orig
    sys.stderr = stderr_orig

    print_summary(count_dict, error_list)
    print 'Script Elapsed Time: %.5fs' % (time.time() - start_time)
    if error_list:
        raise lb_exception.LBCommandError("%s errors detected." % len(error_list))