From 41a73bf0470053d5553605076374c9cb821d2a77 Mon Sep 17 00:00:00 2001
From: Yagnesh Setti Subramanian <settiy@microsoft.com>
Date: Tue, 7 Jan 2025 10:56:13 -0800
Subject: [PATCH 1/2] Enable redirection when starting a network

---
 tests/start_network.py | 32 ++++++++++++++++++++++++++++++++
 1 file changed, 32 insertions(+)

diff --git a/tests/start_network.py b/tests/start_network.py
index 80287d8a6334..aab3666bed5a 100644
--- a/tests/start_network.py
+++ b/tests/start_network.py
@@ -30,6 +30,20 @@ def run(args):
         for host_desc in host_descs:
             interface = infra.interfaces.RPCInterface.from_args(args)
             interface.parse_from_str(host_desc)
+            
+            if args.redirection_kind == "node-by-role":
+                LOG.warning("Redirection with node-by-role is enabled")
+                interface.redirections = infra.interfaces.RedirectionConfig(
+                    to_primary = infra.interfaces.NodeByRoleResolver(),
+                    to_backup = infra.interfaces.NodeByRoleResolver(),
+                )
+            elif args.redirection_kind == "static-address":
+                LOG.warning("Redirection with static-address is enabled")
+                interface.redirections = infra.interfaces.RedirectionConfig(
+                    to_primary = infra.interfaces.StaticAddressResolver(args.primary_hostname),
+                    to_backup = infra.interfaces.StaticAddressResolver(args.backup_hostname),
+                )
+
             hosts.append(
                 infra.interfaces.HostSpec(
                     rpc_interfaces={infra.interfaces.PRIMARY_RPC_INTERFACE: interface}
@@ -209,11 +223,29 @@ def add(parser):
             type=int,
             default=0,
         )
+        parser.add_argument(
+            "--redirection-kind",
+            default='node-by-role',
+            choices=['node-by-role','static-address'],
+            help="The redirection kind to use in lieu of forwarding. Either node-by-role or static-address",
+        )
+        parser.add_argument(
+            "--primary-hostname",
+            help="The primary hostname to set when --redirection-kind is set to static-address",
+        )
+        parser.add_argument(
+            "--backup-hostname",
+            help="The backup hostname to set when --redirection-kind is set to static-address",
+        )
 
     args = infra.e2e_args.cli_args(add)
     if args.recover and not all([args.ledger_dir, args.common_dir]):
         print("Error: --recover requires --ledger-dir and --common-dir arguments.")
         sys.exit(1)
+        
+    if args.redirection_kind == "static-address" and not all([args.primary_hostname, args.backup_hostname]):
+        print("Error: --redirection-kind static-address requires --primary-hostname and --backup-hostname arguments.")
+        sys.exit(1)
 
     if args.common_dir is not None:
         args.common_dir = os.path.abspath(args.common_dir)

From e24bbc3fac64b5f2ac50b88892db7eb4215ea8b8 Mon Sep 17 00:00:00 2001
From: msftsettiy <settiy@microsoft.com>
Date: Tue, 7 Jan 2025 13:13:01 -0800
Subject: [PATCH 2/2] Reformatting

---
 tests/start_network.py | 28 ++++++++++++++++++----------
 1 file changed, 18 insertions(+), 10 deletions(-)

diff --git a/tests/start_network.py b/tests/start_network.py
index aab3666bed5a..a41b4ca02e69 100644
--- a/tests/start_network.py
+++ b/tests/start_network.py
@@ -30,18 +30,22 @@ def run(args):
         for host_desc in host_descs:
             interface = infra.interfaces.RPCInterface.from_args(args)
             interface.parse_from_str(host_desc)
-            
+
             if args.redirection_kind == "node-by-role":
                 LOG.warning("Redirection with node-by-role is enabled")
                 interface.redirections = infra.interfaces.RedirectionConfig(
-                    to_primary = infra.interfaces.NodeByRoleResolver(),
-                    to_backup = infra.interfaces.NodeByRoleResolver(),
+                    to_primary=infra.interfaces.NodeByRoleResolver(),
+                    to_backup=infra.interfaces.NodeByRoleResolver(),
                 )
             elif args.redirection_kind == "static-address":
                 LOG.warning("Redirection with static-address is enabled")
                 interface.redirections = infra.interfaces.RedirectionConfig(
-                    to_primary = infra.interfaces.StaticAddressResolver(args.primary_hostname),
-                    to_backup = infra.interfaces.StaticAddressResolver(args.backup_hostname),
+                    to_primary=infra.interfaces.StaticAddressResolver(
+                        args.primary_hostname
+                    ),
+                    to_backup=infra.interfaces.StaticAddressResolver(
+                        args.backup_hostname
+                    ),
                 )
 
             hosts.append(
@@ -225,8 +229,8 @@ def add(parser):
         )
         parser.add_argument(
             "--redirection-kind",
-            default='node-by-role',
-            choices=['node-by-role','static-address'],
+            default="node-by-role",
+            choices=["node-by-role", "static-address"],
             help="The redirection kind to use in lieu of forwarding. Either node-by-role or static-address",
         )
         parser.add_argument(
@@ -242,9 +246,13 @@ def add(parser):
     if args.recover and not all([args.ledger_dir, args.common_dir]):
         print("Error: --recover requires --ledger-dir and --common-dir arguments.")
         sys.exit(1)
-        
-    if args.redirection_kind == "static-address" and not all([args.primary_hostname, args.backup_hostname]):
-        print("Error: --redirection-kind static-address requires --primary-hostname and --backup-hostname arguments.")
+
+    if args.redirection_kind == "static-address" and not all(
+        [args.primary_hostname, args.backup_hostname]
+    ):
+        print(
+            "Error: --redirection-kind static-address requires --primary-hostname and --backup-hostname arguments."
+        )
         sys.exit(1)
 
     if args.common_dir is not None: