Fix the JSONRPC read service issue
[integration/test.git] / csit / libraries / ConfGen.py
index e9ff96196ba03af119399370a80ca05ab0acd5dc..a181314f02acf2c7d40b25d12432ab398801065d 100644 (file)
@@ -21,7 +21,7 @@ def _parse_input(file_name):
     return pyhocon.ConfigFactory.parse_file(file_name)
 
 
-def generate_akka(original_file, node_idx=1, nodes_ip_list=['127.0.0.1']):
+def generate_akka(original_file, node_idx=1, nodes_ip_list=["127.0.0.1"]):
     """Generates akka.conf content.
 
     Args:
@@ -35,14 +35,21 @@ def generate_akka(original_file, node_idx=1, nodes_ip_list=['127.0.0.1']):
     """
 
     conf = _parse_input(original_file)
-    conf['odl-cluster-data']['akka']['remote']['netty']['tcp']['hostname'] = nodes_ip_list[node_idx-1]
-    seed_nodes = [u'akka.tcp://opendaylight-cluster-data@{}:2550'.format(ip) for ip in nodes_ip_list]
-    conf['odl-cluster-data']['akka']['cluster']['seed-nodes'] = seed_nodes
-    conf['odl-cluster-data']['akka']['cluster']['roles'] = ["member-{}".format(node_idx)]
+    conf["odl-cluster-data"]["akka"]["remote"]["netty"]["tcp"][
+        "hostname"
+    ] = nodes_ip_list[node_idx - 1]
+    seed_nodes = [
+        u"akka.tcp://opendaylight-cluster-data@{}:2550".format(ip)
+        for ip in nodes_ip_list
+    ]
+    conf["odl-cluster-data"]["akka"]["cluster"]["seed-nodes"] = seed_nodes
+    conf["odl-cluster-data"]["akka"]["cluster"]["roles"] = [
+        "member-{}".format(node_idx)
+    ]
     return pyhocon.tool.HOCONConverter.to_hocon(conf)
 
 
-def generate_modules(original_file, name='', namespace=''):
+def generate_modules(original_file, name="", namespace=""):
     """Generates modules.conf content.
 
     If name and namespace parameters are filled, exactly one module item is added to the content of orginal file.
@@ -59,13 +66,16 @@ def generate_modules(original_file, name='', namespace=''):
         :returns str: modules.conf content
     """
     conf = _parse_input(original_file)
-    if name != '' and namespace != '':
-        conf['modules'].append(
-            pyhocon.ConfigTree([("name", name), ("namespace", namespace), ("shard-strategy", "module")]))
+    if name != "" and namespace != "":
+        conf["modules"].append(
+            pyhocon.ConfigTree(
+                [("name", name), ("namespace", namespace), ("shard-strategy", "module")]
+            )
+        )
     return pyhocon.tool.HOCONConverter.to_hocon(conf)
 
 
-def generate_module_shards(original_file, nodes=1, shard_name='', replicas=[]):
+def generate_module_shards(original_file, nodes=1, shard_name="", replicas=[]):
     """Generates module-shards.conf content.
 
     If shard_name and replicas parameters are filled, exactly one shard item is added to the content of orginal file.
@@ -83,12 +93,30 @@ def generate_module_shards(original_file, nodes=1, shard_name='', replicas=[]):
         :returns str: module-shards.conf content
     """
     conf = _parse_input(original_file)
-    for module_shard in conf['module-shards']:
-        module_shard["shards"][0]["replicas"] = ["member-{}".format(i+1) for i in range(int(nodes))]
-    if shard_name != '' and replicas != []:
-        conf['module-shards'].append(
-            pyhocon.ConfigTree([("name", shard_name),
-                                ("shards", [pyhocon.ConfigTree(
-                                    [("name", shard_name),
-                                     ("replicas", ["member-{}".format(i) for i in replicas])])])]))
+    for module_shard in conf["module-shards"]:
+        module_shard["shards"][0]["replicas"] = [
+            "member-{}".format(i + 1) for i in range(int(nodes))
+        ]
+    if shard_name != "" and replicas != []:
+        conf["module-shards"].append(
+            pyhocon.ConfigTree(
+                [
+                    ("name", shard_name),
+                    (
+                        "shards",
+                        [
+                            pyhocon.ConfigTree(
+                                [
+                                    ("name", shard_name),
+                                    (
+                                        "replicas",
+                                        ["member-{}".format(i) for i in replicas],
+                                    ),
+                                ]
+                            )
+                        ],
+                    ),
+                ]
+            )
+        )
     return pyhocon.tool.HOCONConverter.to_hocon(conf)