示例#1
0
文件: config.py 项目: yiu31802/ave
def t22(HOME):
    pretty = '%s t22' % __file__
    print(pretty)

    ave.config.create_default(HOME.path)
    path = os.path.join(HOME.path, '.ave', 'config', 'broker.json')
    with open(path, 'w') as f:
        json.dump({'logging': False}, f)
    sock, port = find_free_port()
    b = Broker(socket=sock, authkeys={'admin': 'key'}, home=HOME.path)
    b.start()

    r = RemoteBroker(('', port), home=HOME.path)

    try:
        r.stop()
        print('FAIL %s: stop() did not fail' % pretty)
        b.join()
        return False
    except Exception, e:
        if 'not authorized to make this call' not in str(e):
            print('FAIL %s: wrong error message: %s' % (pretty, str(e)))
            b.terminate()
            b.join()
            return False
示例#2
0
文件: broker.py 项目: yiu31802/ave
def t15(factory):
    pretty = '%s t15' % __file__
    print(pretty)

    ws_config = {
        'root'   : factory.HOME.path,
        'env'    : [],
        'tools'  : {},
        'flocker': {
            "ftp": {
                "password": "******",
                "store": "/srv/www/flocker",
                "port": 21,
                "timeout": 30,
                "user": "******"
            },
            "host": "cnbjlx20050",
            "enable" : True,
            "http": {
                "doc-root": "/srv/www",
                "port": 80
            }
        }
    }
    factory.write_config('workspace.json', json.dumps(ws_config))

    sock, port = find_free_port()
    # set remote explicitly to avoid reading config from disk
    broker = Broker(
        ('',port), sock, remote={}, authkeys={'admin':None}, hsl_paths=[],
        home=factory.HOME.path
    )
    broker.start()
    proc   = psutil.Process(broker.pid)
    remote = RemoteBroker(address=('',port), home=factory.HOME.path)

    l = remote.list_available() # just to make sure the connection is up
    del remote                  # client disconnects itself

    # check the CPU utilization of the broker through it's PID
    result = True
    for i in range(10):
        if 'get_cpu_percent' in dir(proc):
            load = proc.get_cpu_percent() * psutil.NUM_CPUS
        else:
            load = proc.cpu_percent() * psutil.cpu_count()
        if load > 90.0:
            print('FAIL %s: runaway CPU load: %f' % (pretty, load))
            result = False
            break
        time.sleep(0.3)

    broker.terminate()
    broker.join()

    return result
示例#3
0
文件: broker.py 项目: yiu31802/ave
def t1(factory):
    pretty = '%s t1' % __file__
    print(pretty)

    sock, port = find_free_port()
    sock.shutdown(socket.SHUT_RDWR)
    sock.close()

    for i in range(10):
        try:
            broker = Broker(('',port), home=factory.HOME.path)
            broker.start()
            remote = RemoteBroker(('',port), 5, 'admin_key', factory.HOME.path)
            remote.stop(__async__=True)
            broker.join()
        except Exception, e:
            print('FAIL %s: stopping broker %d failed: %s' % (pretty,i,str(e)))
            return False
示例#4
0
文件: config.py 项目: yiu31802/ave
def t23(HOME):
    pretty = '%s t23' % __file__
    print(pretty)

    ave.config.create_default(HOME.path)
    path = os.path.join(HOME.path, '.ave', 'config', 'broker.json')
    with open(path, 'w') as f:
        json.dump({'logging': False}, f)
    sock, port = find_free_port()
    b = Broker(socket=sock, authkeys={'admin': 'key'}, home=HOME.path)
    b.start()

    r = RemoteBroker(('', port), authkey='key', home=HOME.path)

    try:
        r.stop()
    except ConnectionClosed:
        pass  # good
    except Exception, e:
        print('FAIL %s: admin authkey not accepted: %s' % (pretty, str(e)))
        b.terminate()
        b.join()
        return False
示例#5
0
文件: config.py 项目: yiu31802/ave
    r = RemoteBroker(('', port), home=HOME.path)

    try:
        r.stop()
        print('FAIL %s: stop() did not fail' % pretty)
        b.join()
        return False
    except Exception, e:
        if 'not authorized to make this call' not in str(e):
            print('FAIL %s: wrong error message: %s' % (pretty, str(e)))
            b.terminate()
            b.join()
            return False

    b.terminate()
    b.join()
    return False


# check that calls to stop() are accepted if the client knows the admin authkey
@setup
def t23(HOME):
    pretty = '%s t23' % __file__
    print(pretty)

    ave.config.create_default(HOME.path)
    path = os.path.join(HOME.path, '.ave', 'config', 'broker.json')
    with open(path, 'w') as f:
        json.dump({'logging': False}, f)
    sock, port = find_free_port()
    b = Broker(socket=sock, authkeys={'admin': 'key'}, home=HOME.path)