コード例 #1
0
 def __init__(self,
              address,
              socket,
              remote,
              handsets,
              relays,
              stacks,
              authkeys,
              ws_cfg,
              adoption,
              fdtx_path,
              hsl_paths=None,
              alloc=True,
              autoshare=False,
              home=None,
              slow_down=0):
     Broker.__init__(self,
                     address,
                     socket,
                     remote,
                     authkeys,
                     stacks,
                     ws_cfg,
                     adoption,
                     fdtx_path,
                     hsl_paths,
                     home,
                     logging=False)
     self.handsets = handsets
     self.relays = relays
     self.alloc = alloc
     self.autoshare = autoshare
     self.slow_down = slow_down
コード例 #2
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
コード例 #3
0
ファイル: config.py プロジェクト: yiu31802/ave
def t6(HOME):
    pretty = '%s t6' % __file__
    print(pretty)

    # build the mock config files. any valid workspace configuration will do
    ave.config.create_default(HOME.path)
    path = os.path.join(HOME.path, '.ave', 'config', 'workspace.json')
    with open(path, 'w') as f:
        config = {
            'root': '~/workspaces',
            'env': [],
            'tools': {},
            'flocker': FLOCKER
        }
        json.dump(config, f)

    # invalid content. "root" has wrong type
    path = os.path.join(HOME.path, '.ave', 'config', 'broker.json')
    with open(path, 'w') as f:
        f.write('{ "host": "a.hostname.net", "port": 4001 }')

    try:
        b = Broker(home=HOME.path)
    except Exception, e:
        traceback.print_exc()
        print('FAIL %s: Broker.__init__() failed: %s' % (pretty, str(e)))
        return False
コード例 #4
0
ファイル: config.py プロジェクト: yiu31802/ave
def t19(HOME):
    pretty = '%s t19' % __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:
        config = {  # try to use non-string authkey
            'remote': {
                'host': '0.0.0.0',
                'port': 1,
                'policy': 'share',
                'authkey': None
            }
        }
        json.dump(config, f)

    try:
        b = Broker(home=HOME.path)
        print('FAIL %s: Broker.__init__() did not fail' % pretty)
        return False
    except Exception, e:
        if 'remote sharing authkey must be a string' not in str(e):
            print('FAIL %s: wrong error message: %s' % (pretty, str(e)))
            return False
コード例 #5
0
ファイル: config.py プロジェクト: yiu31802/ave
def t7(HOME):
    pretty = '%s t7' % __file__
    print(pretty)

    # build the mock config files. invalid content. "stacks" has wrong type
    ave.config.create_default(HOME.path)
    path = os.path.join(HOME.path, '.ave', 'config', 'broker.json')
    with open(path, 'w') as f:
        config = {
            'stacks': 'nost a list',
            'root': '~/workspaces',
            'env': [],
            'tools': {},
            'flocker': FLOCKER
        }
        json.dump(config, f)

    try:
        b = Broker(home=HOME.path)
        print('FAIL %s: Broker.__init__() did not fail' % pretty)
        return False
    except Exception, e:
        if not str(e).startswith('broker attribute "stacks" must be on the'):
            print('FAIL %s: wrong error message: %s' % (pretty, str(e)))
            return False
コード例 #6
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
コード例 #7
0
ファイル: config.py プロジェクト: yiu31802/ave
def t2(HOME):
    pretty = '%s t2' % __file__
    print(pretty)

    try:
        b = Broker(home=HOME.path)
        print('FAIL %s: Broker.__init__() did not fail' % pretty)
        return False
    except Exception, e:
        if 'no such configuration file: %s' % HOME.path not in str(e):
            print('FAIL %s: wrong error message: %s' % (pretty, str(e)))
            return False
コード例 #8
0
ファイル: config.py プロジェクト: yiu31802/ave
def t3(HOME):
    pretty = '%s t3' % __file__
    print(pretty)

    # build the mock config file (broken)
    path = os.path.join(HOME.path, '.ave', 'config', 'broker.json')
    with open(path, 'w') as f:
        f.write('{ "port": 4001 ')  # missing end bracket

    try:
        Broker(home=HOME.path)
        print('FAIL %s: Broker.__init__() did not fail' % pretty)
        return False
    except Exception, e:
        if 'could not load broker configuration file: Expecting' not in str(e):
            print('FAIL %s: wrong error message: %s' % (pretty, str(e)))
            return False
コード例 #9
0
ファイル: config.py プロジェクト: yiu31802/ave
def t11(HOME):
    pretty = '%s t11' % __file__
    print(pretty)

    # any valid workspace configuration will do
    ave.config.create_default(HOME.path)
    path = os.path.join(HOME.path, '.ave', 'config', 'workspace.json')

    with open(path, 'w') as f:
        config = {
            'root': '~/workspaces',
            'env': [],
            'tools': {},
            'flocker': FLOCKER
        }
        json.dump(config, f)

    config = {
        'stacks': [[{
            'type': 'handset',
            'serial': '1234'
        }, {
            'type': 'relay',
            'uid': 'a'
        }],
                   [{
                       'type': 'testdrive',
                       'uid': 'a'
                   }, {
                       'type': 'relay',
                       'uid': 'b'
                   }, {
                       'type': 'handset',
                       'imei': 'c'
                   }]]
    }
    # valid content. broker initialization should not fail
    path = os.path.join(HOME.path, '.ave', 'config', 'broker.json')
    with open(path, 'w') as f:
        f.write(json.dumps(config))

    try:
        b = Broker(home=HOME.path)
    except Exception, e:
        print('FAIL %s: Broker.__init__() failed: %s' % (pretty, str(e)))
        return False
コード例 #10
0
 def _make_broker(self, sock, port):
     return Broker(address=('', port),
                   socket=sock,
                   remote=None,
                   home=self.HOME.path,
                   ws_cfg={
                       'root': self.HOME.path,
                       'env': [],
                       'tools': {
                           'sleep': '/bin/sleep'
                       },
                       'pretty': 'broker',
                       'flocker': {
                           'host': 'any',
                           'port': 40000003
                       }
                   })
コード例 #11
0
ファイル: config.py プロジェクト: yiu31802/ave
def t10(HOME):
    pretty = '%s t10' % __file__
    print(pretty)

    # invalid content. stacked profile does not contain unique identifiers
    ave.config.create_default(HOME.path)
    path = os.path.join(HOME.path, '.ave', 'config', 'broker.json')
    with open(path, 'w') as f:
        f.write('{ "stacks": [[{"serial":"1", "pretty":"hallon"}]] }')

    try:
        b = Broker(home=HOME.path)
        print('FAIL %s: Broker.__init__() did not fail' % pretty)
        return False
    except Exception, e:
        if not str(e).startswith('the stacked profile "{u\'serial\': u\'1\','):
            print('FAIL %s: wrong error message: %s' % (pretty, str(e)))
            return False
コード例 #12
0
ファイル: config.py プロジェクト: yiu31802/ave
def t8(HOME):
    pretty = '%s t8' % __file__
    print(pretty)

    # invalid content. stacked profiles have wrong type
    ave.config.create_default(HOME.path)
    path = os.path.join(HOME.path, '.ave', 'config', 'broker.json')
    with open(path, 'w') as f:
        f.write('{ "stacks": ["not a profile", ["also","not"]] }')

    try:
        b = Broker(home=HOME.path)
        print('FAIL %s: Broker.__init__() did not fail' % pretty)
        return False
    except Exception, e:
        if not str(e).startswith('broker attribute "stacks" must be on the'):
            print('FAIL %s: wrong error message: %s' % (pretty, str(e)))
            return False
コード例 #13
0
ファイル: config.py プロジェクト: yiu31802/ave
def t20(HOME):
    pretty = '%s t20' % __file__
    print(pretty)

    ave.config.create_default(HOME.path)
    path = os.path.join(HOME.path, '.ave', 'config', 'authkeys.json')
    with open(path, 'w') as f:
        config = []  # try to use non-dict
        json.dump(config, f)

    try:
        b = Broker(home=HOME.path)
        print('FAIL %s: Broker.__init__() did not fail' % pretty)
        return False
    except Exception, e:
        if 'authkeys.json: contents is not a dictionary' not in unicode(e):
            print('FAIL %s: wrong error message: %s' % (pretty, unicode(e)))
            return False
コード例 #14
0
ファイル: config.py プロジェクト: yiu31802/ave
def t4(HOME):
    pretty = '%s t4' % __file__
    print(pretty)

    # build the mock config file with invalid content. "root" has wrong type
    ave.config.create_default(HOME.path)
    path = os.path.join(HOME.path, '.ave', 'config', 'broker.json')
    with open(path, 'w') as f:
        f.write('{ "host": 1 }')

    try:
        Broker(home=HOME.path)
        print('FAIL %s: Broker.__init__() did not fail' % pretty)
        return False
    except Exception, e:
        if not str(e).endswith('current value=1 (type=<type \'int\'>)'):
            print('FAIL %s: wrong error message: %s' % (pretty, str(e)))
            return False
コード例 #15
0
ファイル: config.py プロジェクト: yiu31802/ave
def t16(HOME):
    pretty = '%s t16' % __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:
        config = {'remote': {'host': '0.0.0.0', 'port': 1, 'policy': None}}
        json.dump(config, f)

    try:
        b = Broker(home=HOME.path)
        print('FAIL %s: Broker.__init__() did not fail' % pretty)
        return False
    except Exception, e:
        if not str(e).startswith(
                'broker attribute "remote" must be on the fo'):
            print('FAIL %s: wrong error message: %s' % (pretty, str(e)))
            return False
コード例 #16
0
ファイル: config.py プロジェクト: yiu31802/ave
def t21(HOME):
    pretty = '%s t21' % __file__
    print(pretty)

    ave.config.create_default(HOME.path)
    path = os.path.join(HOME.path, '.ave', 'config', 'authkeys.json')
    with open(path, 'w') as f:
        config = {  # try to use non-string account key
            'admin': 1.2
        }
        json.dump(config, f)

    try:
        b = Broker(home=HOME.path)
        print('FAIL %s: Broker.__init__() did not fail' % pretty)
        return False
    except Exception, e:
        if 'value of "admin" is not a string' not in unicode(e):
            print('FAIL %s: wrong error message: %s' % (pretty, unicode(e)))
            return False
コード例 #17
0
ファイル: config.py プロジェクト: yiu31802/ave
def t12(HOME):
    pretty = '%s t12' % __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:
        config = {
            'remote': {
                'host': '0.0.0.0',
                'port': 1,
                'policy': 'forward'
            }
        }
        json.dump(config, f)

    try:
        b = Broker(home=HOME.path)
    except Exception, e:
        print('FAIL %s: Broker.__init__() 1 failed: %s' % (pretty, str(e)))
        return False
コード例 #18
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
コード例 #19
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
コード例 #20
0
 def update_sharing(self):
     if self.slow_down:
         time.sleep(self.slow_down)
     Broker.update_sharing(self)
コード例 #21
0
 def close_session(self, authkey):
     Broker.close_session(self, authkey)
コード例 #22
0
ファイル: config.py プロジェクト: yiu31802/ave
        print('FAIL %s: Broker.__init__() 1 failed: %s' % (pretty, str(e)))
        return False

    with open(path, 'w') as f:
        config = {
            'remote': {
                'host': 'å.ä.ö',
                'port': 00001,
                'policy': 'share',
                'authkey': 'admin_key'
            }
        }
        json.dump(config, f)

    try:
        b = Broker(home=HOME.path)
    except Exception, e:
        print('FAIL %s: Broker.__init__() 2 failed: %s' % (pretty, str(e)))
        return False

    path = os.path.join(HOME.path, '.ave', 'config', 'broker.json')
    with open(path, 'w') as f:
        json.dump({'remote': None}, f)

    try:
        b = Broker(home=HOME.path)
    except Exception, e:
        print('FAIL %s: Broker.__init__() 3 failed: %s' % (pretty, str(e)))
        return False

    return True
コード例 #23
0
ファイル: daemon.py プロジェクト: yiu31802/ave
 def initialize(self):
     self.write_pid_file()
     Broker.initialize(self)
コード例 #24
0
ファイル: daemon.py プロジェクト: yiu31802/ave
 def __init__(self, adoption=None, fdtx_path=None):
     Broker.__init__(self, adoption=adoption, fdtx_path=fdtx_path)
     self.input = open('/dev/null', 'r')
     self.output = open(LOG_PATH, mode='a+', buffering=0)
コード例 #25
0
ファイル: daemon.py プロジェクト: yiu31802/ave
 def close_fds(self, exclude):
     exclude.append(self.input.fileno())
     exclude.append(self.output.fileno())
     Broker.close_fds(self, exclude)
コード例 #26
0
ファイル: daemon.py プロジェクト: yiu31802/ave
 def start(self):
     Broker.start(self, daemonize=True)