From c1c23296a958cf48e1ab1758d3bc0d4aea06f87e Mon Sep 17 00:00:00 2001
From: Simon Pichugin <spichugi@redhat.com>
Date: Fri, 13 Jan 2017 16:20:45 +0100
Subject: [PATCH] Ticket 47747 - Add topology_i2 and topology_i3

Description: Add two more topologies with two and three standalone
instances. It would be more logical to call it "instance1", etc.,
but we areforced to use "standalone1" terminology for the compatibility
and efficiency.

You can refer to the instances with topology_i2.ins["standalon1"] dict.

Also you can enable a replication using REPLICAID_STANDALONE_* constants.

https://fedorahosted.org/389/ticket/47747

Reviewed by: ?
---
 lib389/_constants.py |   1 +
 lib389/topologies.py | 143 +++++++++++++++++++++++++++++++++++++++++++++++----
 2 files changed, 135 insertions(+), 9 deletions(-)

diff --git a/lib389/_constants.py b/lib389/_constants.py
index e247634..72d44f1 100644
--- a/lib389/_constants.py
+++ b/lib389/_constants.py
@@ -247,6 +247,7 @@ for i in range(port_start, port_start + number_of_instances):
     exec("PORT_STANDALONE{0} = {1}".format(N, i))
     exec("SECUREPORT_STANDALONE{0} = {1}".format(N, i + 24700))
     exec("SERVERID_STANDALONE{0} = {1}".format(N, "\"standalone_{0}\"".format(N)))
+    exec("REPLICAID_STANDALONE_{0} = {1}".format(N, 65535))
 
 # For compatibility
 HOST_STANDALONE = HOST_STANDALONE1
diff --git a/lib389/topologies.py b/lib389/topologies.py
index 7880fb6..54230c2 100644
--- a/lib389/topologies.py
+++ b/lib389/topologies.py
@@ -6,11 +6,12 @@
 # See LICENSE for details.
 # --- END COPYRIGHT BLOCK ---
 #
-import os
+import logging
 import sys
 import time
-import logging
+
 import pytest
+
 from lib389 import DirSrv
 from lib389._constants import *
 from lib389.properties import *
@@ -24,10 +25,13 @@ log = logging.getLogger(__name__)
 
 
 class TopologyMain(object):
-    def __init__(self, standalone=None, masters=None,
+    def __init__(self, standalones=None, masters=None,
                  consumers=None, hubs=None):
-        if standalone:
-            self.standalone = standalone
+        if standalones:
+            if isinstance(standalones, dict):
+                self.ins = standalones
+            else:
+                self.standalone = standalones
         if masters:
             self.ms = masters
         if consumers:
@@ -44,9 +48,9 @@ def topology_st(request):
         standalone = DirSrv(verbose=True)
     else:
         standalone = DirSrv(verbose=False)
-    args_instance[SER_HOST] = HOST_STANDALONE
-    args_instance[SER_PORT] = PORT_STANDALONE
-    args_instance[SER_SERVERID_PROP] = SERVERID_STANDALONE
+    args_instance[SER_HOST] = HOST_STANDALONE1
+    args_instance[SER_PORT] = PORT_STANDALONE1
+    args_instance[SER_SERVERID_PROP] = SERVERID_STANDALONE1
     args_instance[SER_CREATION_SUFFIX] = DEFAULT_SUFFIX
     args_standalone = args_instance.copy()
     standalone.allocate(args_standalone)
@@ -64,7 +68,128 @@ def topology_st(request):
 
     request.addfinalizer(fin)
 
-    return TopologyMain(standalone=standalone)
+    return TopologyMain(standalones=standalone)
+
+
+@pytest.fixture(scope="module")
+def topology_i2(request):
+    """Create two instance DS deployment"""
+
+    if DEBUGGING:
+        standalone = DirSrv(verbose=True)
+    else:
+        standalone = DirSrv(verbose=False)
+    args_instance[SER_HOST] = HOST_STANDALONE1
+    args_instance[SER_PORT] = PORT_STANDALONE1
+    args_instance[SER_SERVERID_PROP] = SERVERID_STANDALONE1
+    args_instance[SER_CREATION_SUFFIX] = DEFAULT_SUFFIX
+    args_standalone = args_instance.copy()
+    standalone.allocate(args_standalone)
+    instance_standalone = standalone.exists()
+    if instance_standalone:
+        standalone.delete()
+    standalone.create()
+    standalone.open()
+
+    if DEBUGGING:
+        standalone2 = DirSrv(verbose=True)
+    else:
+        standalone2 = DirSrv(verbose=False)
+    args_instance[SER_HOST] = HOST_STANDALONE2
+    args_instance[SER_PORT] = PORT_STANDALONE2
+    args_instance[SER_SERVERID_PROP] = SERVERID_STANDALONE2
+    args_instance[SER_CREATION_SUFFIX] = DEFAULT_SUFFIX
+    args_standalone2 = args_instance.copy()
+    standalone2.allocate(args_standalone2)
+    instance_standalone2 = standalone2.exists()
+    if instance_standalone2:
+        standalone2.delete()
+    standalone2.create()
+    standalone2.open()
+
+    def fin():
+        if DEBUGGING:
+            standalone.stop()
+            standalone2.stop()
+        else:
+            standalone.delete()
+            standalone2.delete()
+
+    request.addfinalizer(fin)
+
+    return TopologyMain(standalones={"standalone1": standalone, "standalone2": standalone2})
+
+
+@pytest.fixture(scope="module")
+def topology_i3(request):
+    """Create three instance DS deployment"""
+
+    # Creating standalone instance ...
+    if DEBUGGING:
+        standalone = DirSrv(verbose=True)
+    else:
+        standalone = DirSrv(verbose=False)
+    args_instance[SER_HOST] = HOST_STANDALONE1
+    args_instance[SER_PORT] = PORT_STANDALONE1
+    args_instance[SER_SERVERID_PROP] = SERVERID_STANDALONE1
+    args_instance[SER_CREATION_SUFFIX] = DEFAULT_SUFFIX
+    args_standalone = args_instance.copy()
+    standalone.allocate(args_standalone)
+    instance_standalone = standalone.exists()
+    if instance_standalone:
+        standalone.delete()
+    standalone.create()
+    standalone.open()
+
+    # Creating standalone instance 2...
+    if DEBUGGING:
+        standalone2 = DirSrv(verbose=True)
+    else:
+        standalone2 = DirSrv(verbose=False)
+    args_instance[SER_HOST] = HOST_STANDALONE2
+    args_instance[SER_PORT] = PORT_STANDALONE2
+    args_instance[SER_SERVERID_PROP] = SERVERID_STANDALONE2
+    args_instance[SER_CREATION_SUFFIX] = DEFAULT_SUFFIX
+    args_standalone2 = args_instance.copy()
+    standalone2.allocate(args_standalone2)
+    instance_standalone2 = standalone2.exists()
+    if instance_standalone2:
+        standalone2.delete()
+    standalone2.create()
+    standalone2.open()
+
+    # Creating standalone instance 3...
+    if DEBUGGING:
+        standalone3 = DirSrv(verbose=True)
+    else:
+        standalone3 = DirSrv(verbose=False)
+    args_instance[SER_HOST] = HOST_STANDALONE3
+    args_instance[SER_PORT] = PORT_STANDALONE3
+    args_instance[SER_SERVERID_PROP] = SERVERID_STANDALONE3
+    args_instance[SER_CREATION_SUFFIX] = DEFAULT_SUFFIX
+    args_standalone3 = args_instance.copy()
+    standalone3.allocate(args_standalone3)
+    instance_standalone3 = standalone3.exists()
+    if instance_standalone3:
+        standalone3.delete()
+    standalone3.create()
+    standalone3.open()
+
+    def fin():
+        if DEBUGGING:
+            standalone.stop()
+            standalone2.stop()
+            standalone3.stop()
+        else:
+            standalone.delete()
+            standalone2.delete()
+            standalone3.delete()
+
+    request.addfinalizer(fin)
+
+    return TopologyMain(standalones={"standalone1": standalone,
+                                     "standalone2": standalone2,
+                                     "standalone3": standalone3})
 
 
 @pytest.fixture(scope="module")
-- 
2.9.3

