#50074 Issue 50071 - Set ports in local_simple_allocate function
Closed 3 years ago by spichugi. Opened 5 years ago by spichugi.
spichugi/389-ds-base local_allocate_ports  into  master

@@ -85,6 +85,7 @@ 

  from lib389.paths import Paths

  from lib389.nss_ssl import NssSsl

  from lib389.tasks import BackupTask, RestoreTask

+ from lib389.dseldif import DSEldif

  

  # mixin

  # from lib389.tools import DirSrvTools
@@ -431,8 +432,13 @@ 

  

          # We must also alloc host and ports for some manipulation tasks

          self.host = socket.gethostname()

-         # self.port ...

-         # self.sslport ...

+ 

+         dse_ldif = DSEldif(self)

+         port = dse_ldif.get(DN_CONFIG, "nsslapd-port", single=True)

+         sslport = dse_ldif.get(DN_CONFIG, "nsslapd-secureport", single=True)

+ 

+         self.port = int(port) if port is not None else None

+         self.sslport = int(sslport) if sslport is not None else None

  

          self.binddn = binddn

          self.bindpw = password

file modified
+3 -6
@@ -89,13 +89,10 @@ 

          except ValueError:

              return None

  

+         vals = list(attr_data.values())

          if single:

-             vals = list(attr_data.values())

-             if len(vals) > 0:

-                 return vals[0]

-             else:

-                 return None

-         return attr_data.values()

+             return vals[0] if len(vals) > 0 else None

+         return vals

  

      def add(self, entry_dn, attr, value):

          """Add an attribute under a given entry

@@ -78,7 +78,8 @@ 

      subprocess.check_call(["systemctl", "disable", "dirsrv@{}".format(dirsrv.serverid)])

  

      # Remove selinux port label

-     selinux_label_port(dirsrv.port, remove_label=True)

+     if dirsrv.port is not None:

+         selinux_label_port(dirsrv.port, remove_label=True)

      if dirsrv.sslport is not None:

          selinux_label_port(dirsrv.sslport, remove_label=True)

  

@@ -9,12 +9,14 @@ 

  import os

  import subprocess

  import pytest

+ import logging

+ from lib389 import DirSrv

  from lib389.instance.remove import remove_ds_instance

  from lib389._constants import ReplicaRole

  from lib389.topologies import create_topology

  

  

- @pytest.fixture(scope="module")

+ @pytest.fixture(scope="function")

  def topology_st(request):

      """Create DS standalone instance"""

  
@@ -28,11 +30,17 @@ 

      return topology

  

  

- def test_basic(topology_st):

+ @pytest.mark.parametrize("simple_allocate", (True, False))

+ def test_basic(topology_st, simple_allocate):

      """Check that all DS directories and systemd items were removed"""

  

      inst = topology_st.standalone

  

+     # FreeIPA uses local_simple_allocate for the removal process

+     if simple_allocate:

+         inst = DirSrv(verbose=inst.verbose)

+         inst.local_simple_allocate(topology_st.standalone.serverid)

+ 

      remove_ds_instance(inst)

  

      paths = [inst.ds_paths.backup_dir,
@@ -51,3 +59,5 @@ 

          subprocess.check_output(['systemctl', 'is-enabled', 'dirsrv@{}'.format(inst.serverid)], encoding='utf-8')

      except subprocess.CalledProcessError as ex:

          assert "disabled" in ex.output

+ 

+ 

Description: remove_ds_instance function require DirSrv
object having port and sslport defined for semanage remove
label operation. We should set it in local_simple_allocate too.
Fix DSEldif.get function so it returns a list instead of a view
(Python 3 change).

https://pagure.io/389-ds-base/issue/50071

Reviewed by: ?

The patch looks good. But if nsslapd-port is not found in dse.ldif, then 'int(None)' may return an exception. Should not test 'port' ?

I'd just do self.sslport = int(sslport) if sslport else None. Same for the self.port as Thierry suggested.

rebased onto d4f39c4a1f058c1b28122dc5519e550f341f82c0

5 years ago

Ack for d4f39c4, thanks for the changes!

rebased onto 1698dd8

5 years ago

Pull-Request has been merged by spichugi

5 years ago

389-ds-base is moving from Pagure to Github. This means that new issues and pull requests
will be accepted only in 389-ds-base's github repository.

This pull request has been cloned to Github as issue and is available here:
- https://github.com/389ds/389-ds-base/issues/3133

If you want to continue to work on the PR, please navigate to the github issue,
download the patch from the attachments and file a new pull request.

Thank you for understanding. We apologize for all inconvenience.

Pull-Request has been closed by spichugi

3 years ago