コード例 #1
0
    def __expect_exception(self, value, exception):
        try:
            SocketAddress.parse(value)
            suffix = ', not succeed'
        except exception:
            return
        except:
            exc = sys.exc_info()[0]
            suffix = ', not ' + exc.__name__

        self.fail('SocketAddress.parse("' + str(value) + '") should raise ' +
                  exception.__name__ + suffix)
コード例 #2
0
ファイル: argsparser.py プロジェクト: U0001F3A2/golem
def parse_http_addr(ctx, param, value):
    del ctx, param
    if value:
        try:
            http_prefix = 'https://'
            if not value.startswith(http_prefix):
                raise click.BadParameter("Address without https:// prefix"
                                         "specified: {}".format(value))
            SocketAddress.parse(value[len(http_prefix):])
            return value
        except ipaddress.AddressValueError as e:
            raise click.BadParameter(
                "Invalid network address specified: {}".format(e))
    return None
コード例 #3
0
ファイル: node.py プロジェクト: scorpilix/Golemtest
 def parse_rpc_address(ctx, param, value):
     del ctx, param
     if value:
         try:
             return SocketAddress.parse(value)
         except AddressValueError as e:
             raise click.BadParameter(
                 "Invalid RPC address specified: {}".format(e.message))
コード例 #4
0
 def test_many_peers(self, config_logging, mock_node):
     addr1 = '10.30.10.216:40111'
     addr2 = '10.30.10.214:3333'
     runner = CliRunner()
     args = self.args + ['--peer', addr1, '--peer', addr2]
     return_value = runner.invoke(start, args, catch_exceptions=False)
     self.assertEqual(return_value.exit_code, 0)
     mock_node.assert_has_calls(
         [call().run(use_rpc=True),
          call().add_tasks([])], any_order=True)
     call_names = [name for name, arg, kwarg in mock_node.mock_calls]
     self.assertTrue('().connect_with_peers' in call_names)
     peer_num = call_names.index('().connect_with_peers')
     peer_arg = mock_node.mock_calls[peer_num][1][0]
     self.assertEqual(len(peer_arg), 2)
     self.assertEqual(peer_arg[0], SocketAddress.parse(addr1))
     self.assertEqual(peer_arg[1], SocketAddress.parse(addr2))
コード例 #5
0
 def __expect_valid(self, value):
     if value[0] == '[':
         addr, port = value.split(']:')
         addr = addr[1:]
     else:
         addr, port = value.split(':')
     a = SocketAddress.parse(value)
     self.assertTrue(a.address == addr)
     self.assertTrue(a.port == int(port))
コード例 #6
0
ファイル: node.py プロジェクト: scorpilix/Golemtest
 def parse_peer(ctx, param, value):
     del ctx, param
     addresses = []
     for arg in value:
         try:
             addresses.append(SocketAddress.parse(arg))
         except AddressValueError as e:
             raise click.BadParameter(
                 "Invalid peer address specified: {}".format(e.message))
     return addresses
コード例 #7
0
ファイル: argsparser.py プロジェクト: U0001F3A2/golem
def parse_rpc_address(ctx, param, value):
    del ctx, param
    value = to_unicode(value)
    if value:
        try:
            return SocketAddress.parse(value)
        except ipaddress.AddressValueError as e:
            raise click.BadParameter(
                "Invalid RPC address specified: {}".format(e))
    return None
コード例 #8
0
def dispatch(args):
    if len(args) == 4 and args[1] == REQUESTING_NODE_KIND:
        # I'm a requesting node,
        # second arg is the data dir,
        # third arg is the number of subtasks.
        run_requesting_node(args[2], int(args[3]))
    elif len(args) in [4, 5] and args[1] == COMPUTING_NODE_KIND:
        # I'm a computing node,
        # second arg is the data dir,
        # third arg is the address to connect to,
        # forth arg is the timeout (optional).
        fail_after = float(args[4]) if len(args) == 5 else None
        run_computing_node(args[2], SocketAddress.parse(args[3]),
                           fail_after=fail_after)
    elif len(args) == 1:
        # I'm the main script, run simulation
        error_msg = run_simulation(num_computing_nodes=2, num_subtasks=4,
                                   timeout=120)
        if error_msg:
            print("Dummy task computation failed:", error_msg)
            sys.exit(1)