Esempio n. 1
0
 def test5(self):
     "dns_lookup_forward('lcg-bdii.cern.ch')"
     res = samutils.dns_lookup_forward('lcg-bdii.cern.ch')
     if len(res) < 1:
         self.fail("Expected a list of IPs. Got %r." % res)
     for ip in res:
         if not re.match('^128.142*', ip):
             self.fail("Expected ['127.0.0.1'], got %s" % res)
Esempio n. 2
0
 def test5(self):
     "dns_lookup_forward('lcg-bdii.cern.ch')"
     res = samutils.dns_lookup_forward('lcg-bdii.cern.ch')
     if len(res) < 1:
         self.fail("Expected a list of IPs. Got %r." % res)
     for ip in res:
         if not re.match('^128.142*', ip):
             self.fail("Expected ['127.0.0.1'], got %s" % res)
Esempio n. 3
0
def get_working_ldap(ldaps, net_timeout=LDAP_TIMEOUT_NETWORK):
    """Test given list of LDAP servers and return a first working one as IP
    address.

    Depending on availability uses either LDAP API or CLI.

    @param  ldaps: list of LDAP endpoints (ldap://<hostname>:[<port>]).
    @type ldaps: L{list}
    @param net_timeout: connection timeout (default: L{LDAP_TIMEOUT_NETWORK}).
    @type net_timeout: L{int}

    @return:
      - on success:
          - C{endpoint} - first working LDAP endpoint as IP address
    @rtype: L{str}

    @raises LookupError,TypeError,ValueError:
      - LookupError - if no working endpoints found.
      - TypeError - L{ldaps} must be a list object.
      - ValueError - list of empty endpoints or empty list is given.
    """

    if not isinstance(ldaps, list):
        raise TypeError('ldaps should be a list object.')
    l = len(ldaps)
    if l == 0:
        raise ValueError('Empty LDAP endpoints list given (%s()).' % \
                         sys._getframe(0).f_code.co_name)
    else:
        i = 0
        for v in ldaps:
            if not v:
                i += 1
        if i == l:
            raise ValueError('List of empty LDAP endpoints given (%s()).' % \
                             sys._getframe(0).f_code.co_name)
    failed_ldaps = {}
    for ldap_url in ldaps:
        proto, hostname, port = samutils.parse_uri3(ldap_url)
        try:
            ips = samutils.dns_lookup_forward(hostname)
        except IOError, e:
            # Forward DNS resolution failed. Continue with the next host.
            failed_ldaps[ldap_url] = str(e)
            continue
        else:
            for ip in ips:
                ldap_url_ip = '%s%s:%s' %(proto or '', ip, port)
                if LDAP_LIB:
                    rc, error = __ldap_bind_API(ldap_url_ip, net_timeout)
                    if rc:
                        return ldap_url_ip
                else:
                    rc, error = __ldap_bind_CLI(ldap_url_ip, net_timeout)
                    if rc:
                        return ldap_url_ip
                host_ip = samutils.ldap_url2hostname_ip(ldap_url_ip)
                failed_ldaps[host_ip] = error
Esempio n. 4
0
def get_working_ldap(ldaps, net_timeout=LDAP_TIMEOUT_NETWORK):
    """Test given list of LDAP servers and return a first working one as IP
    address.

    Depending on availability uses either LDAP API or CLI.

    @param  ldaps: list of LDAP endpoints (ldap://<hostname>:[<port>]).
    @type ldaps: L{list}
    @param net_timeout: connection timeout (default: L{LDAP_TIMEOUT_NETWORK}).
    @type net_timeout: L{int}

    @return:
      - on success:
          - C{endpoint} - first working LDAP endpoint as IP address
    @rtype: L{str}

    @raises LookupError,TypeError,ValueError:
      - LookupError - if no working endpoints found.
      - TypeError - L{ldaps} must be a list object.
      - ValueError - list of empty endpoints or empty list is given.
    """

    if not isinstance(ldaps, list):
        raise TypeError('ldaps should be a list object.')
    l = len(ldaps)
    if l == 0:
        raise ValueError('Empty LDAP endpoints list given (%s()).' % \
                         sys._getframe(0).f_code.co_name)
    else:
        i = 0
        for v in ldaps:
            if not v:
                i += 1
        if i == l:
            raise ValueError('List of empty LDAP endpoints given (%s()).' % \
                             sys._getframe(0).f_code.co_name)
    failed_ldaps = {}
    for ldap_url in ldaps:
        proto, hostname, port = samutils.parse_uri3(ldap_url)
        try:
            ips = samutils.dns_lookup_forward(hostname)
        except IOError, e:
            # Forward DNS resolution failed. Continue with the next host.
            failed_ldaps[ldap_url] = str(e)
            continue
        else:
            for ip in ips:
                ldap_url_ip = '%s%s:%s' % (proto or '', ip, port)
                if LDAP_LIB:
                    rc, error = __ldap_bind_API(ldap_url_ip, net_timeout)
                    if rc:
                        return ldap_url_ip
                else:
                    rc, error = __ldap_bind_CLI(ldap_url_ip, net_timeout)
                    if rc:
                        return ldap_url_ip
                host_ip = samutils.ldap_url2hostname_ip(ldap_url_ip)
                failed_ldaps[host_ip] = error
Esempio n. 5
0
 def test4(self):
     "dns_lookup_forward('127.0.0.1')"
     res = samutils.dns_lookup_forward('127.0.0.1')
     self.failUnlessEqual(res, ['127.0.0.1'],
                          "Expected ['127.0.0.1'], got %s" % res)
Esempio n. 6
0
 def test4(self):
     "dns_lookup_forward('127.0.0.1')"
     res = samutils.dns_lookup_forward('127.0.0.1')
     self.failUnlessEqual(res, ['127.0.0.1'],
                          "Expected ['127.0.0.1'], got %s" % res)