コード例 #1
0
ファイル: test_util.py プロジェクト: Ssekhar2017/ipyparallel
def test_disambiguate_ip():
    # garbage in, garbage out
    public_ip = public_ips()[0]
    assert util.disambiguate_ip_address('garbage') == 'garbage'
    assert util.disambiguate_ip_address('0.0.0.0', socket.gethostname()) == localhost()
    wontresolve = 'this.wontresolve.dns'
    assert util.disambiguate_ip_address('0.0.0.0', wontresolve) == wontresolve
    assert util.disambiguate_ip_address('0.0.0.0', public_ip) == localhost()
コード例 #2
0
def test_disambiguate_ip():
    # garbage in, garbage out
    public_ip = public_ips()[0]
    assert util.disambiguate_ip_address('garbage') == 'garbage'
    assert util.disambiguate_ip_address('0.0.0.0',
                                        socket.gethostname()) == localhost()
    wontresolve = 'this.wontresolve.dns'
    assert util.disambiguate_ip_address('0.0.0.0', wontresolve) == wontresolve
    assert util.disambiguate_ip_address('0.0.0.0', public_ip) == localhost()
コード例 #3
0
ファイル: test_util.py プロジェクト: zjzsu2000/ipyparallel
def test_disambiguate_ip(warn_mock):
    # garbage in, garbage out
    public_ip = public_ips()[0]
    assert util.disambiguate_ip_address('garbage') == 'garbage'
    assert util.disambiguate_ip_address('0.0.0.0',
                                        socket.gethostname()) == localhost()
    wontresolve = 'this.wontresolve.dns'
    assert util.disambiguate_ip_address('0.0.0.0', wontresolve) == wontresolve
    assert warn_mock.called_once_with(
        'IPython could not determine IPs for {}: '
        '[Errno -2] Name or service not known'.format(wontresolve),
        RuntimeWarning)
    assert util.disambiguate_ip_address('0.0.0.0', public_ip) == localhost()
コード例 #4
0
    def load_connection_file(self):
        """load config from a JSON connector file,
        at a *lower* priority than command-line/config files.

        Same content can be specified in $IPP_CONNECTION_INFO env
        """
        config = self.config

        if self.connection_info_env:
            self.log.info("Loading connection info from $IPP_CONNECTION_INFO")
            d = json.loads(self.connection_info_env)
        else:
            self.log.info("Loading connection file %r", self.url_file)
            with open(self.url_file) as f:
                d = json.load(f)

        # allow hand-override of location for disambiguation
        # and ssh-server
        if 'IPEngine.location' not in self.cli_config:
            self.location = d['location']
        if 'ssh' in d and not self.sshserver:
            self.sshserver = d.get("ssh")

        proto, ip = d['interface'].split('://')
        ip = disambiguate_ip_address(ip, self.location)
        d['interface'] = f'{proto}://{ip}'

        if d.get('curve_serverkey'):
            # connection file takes precedence over env, if present and defined
            self.curve_serverkey = d['curve_serverkey'].encode('ascii')
        if self.curve_serverkey:
            self.log.info("Using CurveZMQ security")
            self._ensure_curve_keypair()
        else:
            self.log.warning("Not using CurveZMQ security")

        # DO NOT allow override of basic URLs, serialization, or key
        # JSON file takes top priority there
        if d.get('key') or 'key' not in config.Session:
            config.Session.key = d.get('key', '').encode('utf8')
        config.Session.signature_scheme = d['signature_scheme']

        self.registration_url = f"{d['interface']}:{d['registration']}"

        config.Session.packer = d['pack']
        config.Session.unpacker = d['unpack']
        self.session = Session(parent=self)

        self.log.debug("Config changed:")
        self.log.debug("%r", config)
        self.connection_info = d
コード例 #5
0
ファイル: ipengineapp.py プロジェクト: CaptainAL/Spyder
 def load_connector_file(self):
     """load config from a JSON connector file,
     at a *lower* priority than command-line/config files.
     """
     
     self.log.info("Loading url_file %r", self.url_file)
     config = self.config
     
     with open(self.url_file) as f:
         num_tries = 0
         max_tries = 5
         d = ""
         while not d:
             try:
                 d = json.loads(f.read())
             except ValueError:
                 if num_tries > max_tries:
                     raise
                 num_tries += 1
                 time.sleep(0.5)
     
     # allow hand-override of location for disambiguation
     # and ssh-server
     if 'EngineFactory.location' not in config:
         config.EngineFactory.location = d['location']
     if 'EngineFactory.sshserver' not in config:
         config.EngineFactory.sshserver = d.get('ssh')
     
     location = config.EngineFactory.location
     
     proto, ip = d['interface'].split('://')
     ip = disambiguate_ip_address(ip, location)
     d['interface'] = '%s://%s' % (proto, ip)
     
     # DO NOT allow override of basic URLs, serialization, or key
     # JSON file takes top priority there
     config.Session.key = cast_bytes(d['key'])
     config.Session.signature_scheme = d['signature_scheme']
     
     config.EngineFactory.url = d['interface'] + ':%i' % d['registration']
     
     config.Session.packer = d['pack']
     config.Session.unpacker = d['unpack']
     
     self.log.debug("Config changed:")
     self.log.debug("%r", config)
     self.connection_info = d
コード例 #6
0
ファイル: ipengineapp.py プロジェクト: kevinegan31/pySINDy
    def load_connector_file(self):
        """load config from a JSON connector file,
        at a *lower* priority than command-line/config files.
        """

        self.log.info("Loading url_file %r", self.url_file)
        config = self.config

        with open(self.url_file) as f:
            num_tries = 0
            max_tries = 5
            d = ""
            while not d:
                try:
                    d = json.loads(f.read())
                except ValueError:
                    if num_tries > max_tries:
                        raise
                    num_tries += 1
                    time.sleep(0.5)

        # allow hand-override of location for disambiguation
        # and ssh-server
        if 'EngineFactory.location' not in config:
            config.EngineFactory.location = d['location']
        if 'EngineFactory.sshserver' not in config:
            config.EngineFactory.sshserver = d.get('ssh')

        location = config.EngineFactory.location

        proto, ip = d['interface'].split('://')
        ip = disambiguate_ip_address(ip, location)
        d['interface'] = '%s://%s' % (proto, ip)

        # DO NOT allow override of basic URLs, serialization, or key
        # JSON file takes top priority there
        config.Session.key = cast_bytes(d['key'])
        config.Session.signature_scheme = d['signature_scheme']

        config.EngineFactory.url = d['interface'] + ':%i' % d['registration']

        config.Session.packer = d['pack']
        config.Session.unpacker = d['unpack']

        self.log.debug("Config changed:")
        self.log.debug("%r", config)
        self.connection_info = d