示例#1
0
 def __wait_for_connection(self, timeout):
     lurl = ldapurl.LDAPUrl(self.uri)
     if lurl.urlscheme == 'ldapi':
         wait_for_open_socket(lurl.hostport, timeout)
     else:
         (host,port) = lurl.hostport.split(':')
         wait_for_open_ports(host, int(port), timeout)
示例#2
0
 def restart(self, dm_password, live_run):
     dsrestart = DSRestart()
     socket_name = '/var/run/slapd-%s.socket' % \
         api.env.realm.replace('.','-')
     if live_run:
         self.destroy_context()
         dsrestart.create_instance()
         wait_for_open_socket(socket_name)
         self.create_context(dm_password)
     else:
         self.log.warn("Test mode, skipping restart")
示例#3
0
 def restart(self, dm_password, live_run):
     dsrestart = DSRestart()
     socket_name = '/var/run/slapd-%s.socket' % \
         api.env.realm.replace('.','-')
     if live_run:
         self.destroy_context()
         dsrestart.create_instance()
         wait_for_open_socket(socket_name)
         self.create_context(dm_password)
     else:
         self.log.warn("Test mode, skipping restart")
示例#4
0
    def wait_for_open_ports(self, instance_name=""):
        if instance_name.endswith('.service'):
            instance_name = instance_name[:-8]
        if instance_name.startswith('dirsrv@'):
            instance_name = instance_name[7:]

        if instance_name:

            ipautil.wait_for_open_socket(
                paths.SLAPD_INSTANCE_SOCKET_TEMPLATE % instance_name,
                self.api.env.startup_timeout)
        else:
            super(RedHatDirectoryService, self).wait_for_open_ports()
示例#5
0
 def __wait(self, instance_name, wait, ldapi):
     if ldapi:
         instance_name = self.service_instance(instance_name)
         if instance_name.endswith('.service'):
             instance_name = instance_name[:-8]
         if instance_name.startswith('dirsrv'):
             # this is intentional, return the empty string if the instance
             # name is 'dirsrv'
             instance_name = instance_name[7:]
         if not instance_name:
             ldapi = False
     if ldapi:
         yield False
         socket_name = paths.SLAPD_INSTANCE_SOCKET_TEMPLATE % instance_name
         ipautil.wait_for_open_socket(socket_name,
                                      self.api.env.startup_timeout)
     else:
         yield wait
示例#6
0
 def __wait(self, instance_name, wait, ldapi):
     if ldapi:
         instance_name = self.service_instance(instance_name)
         if instance_name.endswith('.service'):
             instance_name = instance_name[:-8]
         if instance_name.startswith('dirsrv'):
             # this is intentional, return the empty string if the instance
             # name is 'dirsrv'
             instance_name = instance_name[7:]
         if not instance_name:
             ldapi = False
     if ldapi:
         yield False
         socket_name = paths.SLAPD_INSTANCE_SOCKET_TEMPLATE % instance_name
         ipautil.wait_for_open_socket(socket_name,
                                      self.api.env.startup_timeout)
     else:
         yield wait
示例#7
0
def get_config(dirsrv):
    base = DN(
        ("cn", api.env.host),
        ("cn", "masters"),
        ("cn", "ipa"),
        ("cn", "etc"),
        api.env.basedn,
    )
    srcfilter = LDAPClient.combine_filters(
        [
            LDAPClient.make_filter({"objectClass": "ipaConfigObject"}),
            LDAPClient.make_filter(
                {"ipaConfigString": [ENABLED_SERVICE, HIDDEN_SERVICE]},
                rules=LDAPClient.MATCH_ANY,
            ),
        ],
        rules=LDAPClient.MATCH_ALL,
    )
    attrs = ["cn", "ipaConfigString"]
    if not dirsrv.is_running():
        raise IpactlError(
            "Failed to get list of services to probe status:\n"
            "Directory Server is stopped",
            3,
        )

    try:
        # The start/restart functions already wait for the server to be
        # started. What we are doing with this wait is really checking to see
        # if the server is listening at all.
        lurl = ldapurl.LDAPUrl(api.env.ldap_uri)
        if lurl.urlscheme == "ldapi":
            wait_for_open_socket(lurl.hostport,
                                 timeout=api.env.startup_timeout)
        else:
            (host, port) = lurl.hostport.split(":")
            wait_for_open_ports(host, [int(port)],
                                timeout=api.env.startup_timeout)
        con = LDAPClient(api.env.ldap_uri)
        con.external_bind()
        res = con.get_entries(
            base,
            filter=srcfilter,
            attrs_list=attrs,
            scope=con.SCOPE_SUBTREE,
            time_limit=10,
        )
    except errors.NetworkError:
        # LSB status code 3: program is not running
        raise IpactlError(
            "Failed to get list of services to probe status:\n"
            "Directory Server is stopped",
            3,
        )
    except errors.NotFound:
        masters_list = []
        dn = DN(("cn", "masters"), ("cn", "ipa"), ("cn", "etc"),
                api.env.basedn)
        attrs = ["cn"]
        try:
            entries = con.get_entries(dn, con.SCOPE_ONELEVEL, attrs_list=attrs)
        except Exception as e:
            masters_list.append("No master found because of error: %s" %
                                str(e))
        else:
            for master_entry in entries:
                masters_list.append(master_entry.single_value["cn"])

        masters = "\n".join(masters_list)

        raise IpactlError(
            "Failed to get list of services to probe status!\n"
            "Configured hostname '%s' does not match any master server in "
            "LDAP:\n%s" % (api.env.host, masters))
    except Exception as e:
        raise IpactlError(
            "Unknown error when retrieving list of services from LDAP: %s" %
            str(e))

    svc_list = []

    for entry in res:
        name = entry.single_value["cn"]
        for p in entry["ipaConfigString"]:
            if p.startswith("startOrder "):
                try:
                    order = int(p.split()[1])
                except ValueError:
                    raise IpactlError("Expected order as integer in: %s:%s" %
                                      (name, p))
        svc_list.append([order, name])

    ordered_list = []
    for order, svc in sorted(svc_list):
        if svc in service.SERVICE_LIST:
            ordered_list.append(service.SERVICE_LIST[svc].systemd_name)
    return deduplicate(ordered_list)
示例#8
0
 def restart_ds(self):
     dirsrv = services.knownservices.dirsrv
     self.log.debug('Restarting directory server to apply updates')
     dirsrv.restart()
     wait_for_open_socket(self.socket_name)
示例#9
0
 def restart_ds(self):
     dirsrv = services.knownservices.dirsrv
     self.log.info('Restarting directory server to apply updates')
     dirsrv.restart()
     wait_for_open_socket(self.socket_name)