Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,14 @@ rounds: # rounds to run continuously, each round will be an iteration
tx_size: 200
```

#### Generating Config Files

To generate a config file from a template, you can use the `tmpl.py` script:

```bash
python3 ./scripts/tmpl.py ./tmpl/hotshot.testrpc.yaml.j2 ./tmpl/values/hotshot.yaml --num-nodes 10
```

## Usage


Expand Down
2 changes: 2 additions & 0 deletions scripts/requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
jinja2
pyyaml
39 changes: 39 additions & 0 deletions scripts/tmpl.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import argparse
import jinja2
import yaml

def render_template(template_path, values_path, num_nodes = 5):
"""
Renders a Jinja2 template with variables from a YAML file and prints the output.

Args:
template_path (str): The path to the Jinja2 template file.
values_path (str): The path to the YAML file with variables.
--num-nodes (int): The number of nodes to create.
"""
try:
with open(values_path, 'r') as f:
values = yaml.safe_load(f)

values['num_nodes'] = num_nodes
template_loader = jinja2.FileSystemLoader(searchpath="./")
env = jinja2.Environment(loader=template_loader)
template = env.get_template(template_path)

rendered_output = template.render(values)
print(rendered_output)
except FileNotFoundError as e:
print(f"Error: {e}")
except jinja2.exceptions.TemplateError as e:
print(f"Template rendering error: {e}")
except yaml.YAMLError as e:
print(f"YAML parsing error: {e}")

if __name__ == '__main__':
parser = argparse.ArgumentParser(description="Render a Jinja2 template with variables from a YAML file.")
parser.add_argument("tmpl", help="The path to the Jinja2 template file.")
parser.add_argument("values", help="The path to the YAML file with variables.")
parser.add_argument("--num-nodes", type=int, default=5, help="The number of nodes to create.")

args = parser.parse_args()
render_template(args.tmpl, args.values, args.num_nodes)
23 changes: 23 additions & 0 deletions tmpl/hotshot.testrpc.yaml.j2
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
interval: 1
iterations: 100
adapter: hotshot
args:
{%- if coordinator_addr %}
coordinator_url: {{ coordinator_addr }}:3030
{%- endif %}
num_of_nodes: {{ num_nodes }}
{%- if node_addr_tmpl %}
rpcs:
{%- for i in range(1, num_nodes + 1) %}
- http://{{ node_addr_tmpl | format(i) }}:{{ i + 5000 }}
{%- endfor %}
{%- endif %}
round_templates:
tmpl:
txs: {{ tx_per_sec }}
tx_size: {{ tx_size }}
rounds:
{%- for i in range(0, num_nodes) %}
- rpcs: [{{ i }}]
use_template: tmpl
{%- endfor %}
4 changes: 4 additions & 0 deletions tmpl/values/hotshot.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
coordinator_addr: coordinator
node_addr_tmpl: hotshot-%d
tx_per_sec: 100
tx_size: 1000