2 Library generating configuration/initial files.
4 The purpose of this library is about to customize conf file creation for special
5 use cases while testing, e.g. non replicated shards.
12 def _parse_input(file_name):
13 """Parses given file and returns it's pyhocon object.
16 :param file_name: path to the filename
19 :returns pyhocon_obj: parsed content of the given file
21 return pyhocon.ConfigFactory.parse_file(file_name)
24 def generate_akka(original_file, node_idx=1, nodes_ip_list=['127.0.0.1']):
25 """Generates akka.conf content.
28 :param original_file: path to the filename, normally expecting file from system/org/opendaylight...
29 sal-clustering-config-<version>-akkaconf.xml
30 :param node_idx: cluster node index for which the file is generated
31 :param nodes_ip_list: list of luster nodes ip addresses
34 :returns str: akka.conf content
37 conf = _parse_input(original_file)
38 conf['odl-cluster-data']['akka']['remote']['netty']['tcp']['hostname'] = nodes_ip_list[node_idx-1]
39 seed_nodes = [u'akka.tcp://opendaylight-cluster-data@{}:2550'.format(ip) for ip in nodes_ip_list]
40 conf['odl-cluster-data']['akka']['cluster']['seed-nodes'] = seed_nodes
41 conf['odl-cluster-data']['akka']['cluster']['roles'] = ["member-{}".format(node_idx)]
42 return pyhocon.tool.HOCONConverter.to_hocon(conf)
45 def generate_modules(original_file, name='', namespace=''):
46 """Generates modules.conf content.
48 If name and namespace parameters are filled, exactly one module item is added to the content of orginal file.
49 If more modules needed, then use this keyword more times with storing temp file after each addition and use
50 it as <original_file> in the next step.
53 :param original_files: path to the filename, normally expecting file from system/org/opendaylight...
54 sal-clustering-config-<version>-moduleconf.xml
55 :param name: name of the new, addional shard
56 :param namespace: namespace of the new, addional shard
59 :returns str: modules.conf content
61 conf = _parse_input(original_file)
62 if name != '' and namespace != '':
63 conf['modules'].append(
64 pyhocon.ConfigTree([("name", name), ("namespace", namespace), ("shard-strategy", "module")]))
65 return pyhocon.tool.HOCONConverter.to_hocon(conf)
68 def generate_module_shards(original_file, nodes=1, shard_name='', replicas=[]):
69 """Generates module-shards.conf content.
71 If shard_name and replicas parameters are filled, exactly one shard item is added to the content of orginal file.
72 If more shards needed, then use this keyword more times with storing temp file after each addition and use it as
73 <original_file> in the next step.
76 :param file_name: path to the filename, normally expecting file from system/org/opendaylight...
77 sal-clustering-config-<version>-moduleshardconf.xml
78 :param: nodes: number of nodes in the cluster
79 :param shard_name: new name of the additional shard
80 :param replicas: list of member indexes which should keep shard replicas
83 :returns str: module-shards.conf content
85 conf = _parse_input(original_file)
86 for module_shard in conf['module-shards']:
87 module_shard["shards"][0]["replicas"] = ["member-{}".format(i+1) for i in range(int(nodes))]
88 if shard_name != '' and replicas != []:
89 conf['module-shards'].append(
90 pyhocon.ConfigTree([("name", shard_name),
91 ("shards", [pyhocon.ConfigTree(
92 [("name", shard_name),
93 ("replicas", ["member-{}".format(i) for i in replicas])])])]))
94 return pyhocon.tool.HOCONConverter.to_hocon(conf)