Use fanout replication config for the local test environment

In preparation to have more than two Gerrit primary nodes,
do not use replicas remote definition in replication.config anymore
and rely on fanout configuration style.

Change-Id: I4d99c941e573b1d7cf0fd41f792313f01ea09e94
diff --git a/setup_local_env/configs/replication.config b/setup_local_env/configs/replication.config
index ff0c248..7aa26fc 100644
--- a/setup_local_env/configs/replication.config
+++ b/setup_local_env/configs/replication.config
@@ -1,15 +1,3 @@
-[remote "$REPLICA_INSTANCE_ID"]
-    $PULL_REPLICATION_URL
-    $PULL_REPLICATION_API_URL
-    fetch = +refs/*:refs/*
-    mirror = true
-    timeout = 600
-    rescheduleDelay = 15
-    replicationDelay = $REPLICATION_DELAY_SEC
-    createMissingRepositories = true
-    replicateProjectDeletions = true
-    replicateHiddenProjects = true
-    threads = 5
 [gerrit]
     autoReload = true
     replicateOnStartup = false
diff --git a/setup_local_env/configs/replication.remote b/setup_local_env/configs/replication.remote
new file mode 100644
index 0000000..5724708
--- /dev/null
+++ b/setup_local_env/configs/replication.remote
@@ -0,0 +1,12 @@
+[remote]
+    $PULL_REPLICATION_URL
+    $PULL_REPLICATION_API_URL
+    fetch = +refs/*:refs/*
+    mirror = true
+    timeout = 600
+    rescheduleDelay = 15
+    replicationDelay = $REPLICATION_DELAY_SEC
+    createMissingRepositories = true
+    replicateProjectDeletions = true
+    replicateHiddenProjects = true
+    threads = 5
\ No newline at end of file
diff --git a/setup_local_env/setup.sh b/setup_local_env/setup.sh
index 2673d3b..05e854f 100755
--- a/setup_local_env/setup.sh
+++ b/setup_local_env/setup.sh
@@ -78,6 +78,23 @@
   done
 }
 
+function copy_replication_remote_file {
+  fanout_template_file=$SCRIPT_DIR/configs/replication.remote
+
+  CONFIG_TEST_SITE=$1
+  export REPLICATION_HTTPD_PORT=$2
+  export REPLICATION_HOSTNAME=$3
+  export PULL_REPLICATION_URL=$(get_pull_replication_url $REPLICATION_HOSTNAME)
+  export PULL_REPLICATION_API_URL=$(get_pull_replication_api_url $REPLICATION_HOSTNAME)
+  export REPLICA_INSTANCE_ID=$4
+  fanout_file=$REPLICA_INSTANCE_ID.config
+
+  mkdir -p $CONFIG_TEST_SITE/replication
+
+  echo "Replacing variables for file $fanout_template_file and copying to $CONFIG_TEST_SITE/replication/$fanout_file"
+  cat $fanout_template_file | envsubst | sed 's/#{name}#/${name}/g' > $CONFIG_TEST_SITE/replication/$fanout_file
+}
+
 function start_ha_proxy {
 
   export HA_GERRIT_CANONICAL_HOSTNAME=$GERRIT_CANONICAL_HOSTNAME
@@ -136,10 +153,11 @@
 
   # Set config SITE1
   copy_config_files $CONFIG_TEST_SITE_1 $GERRIT_SITE1_HTTPD_PORT $LOCATION_TEST_SITE_1 $GERRIT_SITE1_SSHD_PORT $GERRIT_SITE2_HTTPD_PORT $GERRIT_SITE1_HOSTNAME $GERRIT_SITE2_HOSTNAME $GERRIT_SITE1_REMOTE_DEBUG_PORT $GERRIT_SITE1_INSTANCE_ID $GERRIT_SITE2_INSTANCE_ID
-
+  copy_replication_remote_file $CONFIG_TEST_SITE_1 $GERRIT_SITE2_HTTPD_PORT $GERRIT_SITE2_HOSTNAME $GERRIT_SITE2_INSTANCE_ID
 
   # Set config SITE2
   copy_config_files $CONFIG_TEST_SITE_2 $GERRIT_SITE2_HTTPD_PORT $LOCATION_TEST_SITE_2 $GERRIT_SITE2_SSHD_PORT $GERRIT_SITE1_HTTPD_PORT $GERRIT_SITE1_HOSTNAME $GERRIT_SITE2_HOSTNAME $GERRIT_SITE2_REMOTE_DEBUG_PORT $GERRIT_SITE2_INSTANCE_ID $GERRIT_SITE1_INSTANCE_ID
+  copy_replication_remote_file $CONFIG_TEST_SITE_2 $GERRIT_SITE1_HTTPD_PORT $GERRIT_SITE1_HOSTNAME $GERRIT_SITE1_INSTANCE_ID
 }
 
 function is_docker_desktop {