Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Problem: testground test case requires persistent volume #1522

Merged
merged 4 commits into from
Jul 24, 2024
Merged
Show file tree
Hide file tree
Changes from 3 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
12 changes: 10 additions & 2 deletions testground/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -75,14 +75,22 @@ mounts:

To simplify cluster setup, we are introducing a stateless mode.

## Generate Data Files Locally
## Generate data files locally

You need to have a `cronosd` in `PATH`.
You need to have the `cronosd` in `PATH`.

```bash
$ nix run github:crypto-org-chain/cronos#stateless-testcase gen /tmp/data/out 3 7
```

## Embed the data directory

Patch the image to embed the data directory, it produce a local image:

```bash
$ nix run github:crypto-org-chain/cronos#stateless-testcase patchimage cronos-testground:latest /tmp/data/out
```

## Run In Local Docker

```bash
Expand Down
32 changes: 24 additions & 8 deletions testground/benchmark/benchmark/stateless.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import json
import os
import shutil
import socket
import subprocess
import tempfile
from pathlib import Path
from typing import List

Expand All @@ -26,11 +28,11 @@
DEFAULT_CHAIN_ID = "cronos_777-1"
DEFAULT_DENOM = "basecro"
# the container must be deployed with the prefixed name
CONTAINER_PREFIX = "testplan-"
HOSTNAME_TEMPLATE = "testplan-{index}"


class CLI:
def gen(self, outdir: str, validators: int, fullnodes: int):
def gen(self, outdir: str, validators: int, fullnodes: int, hostname_template=HOSTNAME_TEMPLATE):

Check failure on line 35 in testground/benchmark/benchmark/stateless.py

View workflow job for this annotation

GitHub Actions / Lint python

./testground/benchmark/benchmark/stateless.py:35:13: BLK100 Black would make changes.

Check failure on line 35 in testground/benchmark/benchmark/stateless.py

View workflow job for this annotation

GitHub Actions / Lint python

./testground/benchmark/benchmark/stateless.py:35:89: E501 line too long (101 > 88 characters)
yihuang marked this conversation as resolved.
Show resolved Hide resolved
outdir = Path(outdir)
cli = ChainCommand(LOCAL_CRONOSD_PATH)
(outdir / VALIDATOR_GROUP).mkdir(parents=True, exist_ok=True)
Expand All @@ -39,12 +41,12 @@
peers = []
for i in range(validators):
print("init validator", i)
peers.append(init_node_local(cli, outdir, VALIDATOR_GROUP, i, i))
ip = hostname_template.format(index=i)
peers.append(init_node_local(cli, outdir, VALIDATOR_GROUP, i, ip))
for i in range(fullnodes):
print("init fullnode", i)
peers.append(
init_node_local(cli, outdir, FULLNODE_GROUP, i, i + validators)
)
ip = hostname_template.format(index=i+validators)
peers.append(init_node_local(cli, outdir, FULLNODE_GROUP, i, ip))

print("prepare genesis")
# use a full node directory to prepare the genesis file
Expand All @@ -59,6 +61,20 @@
peers, genesis, outdir, FULLNODE_GROUP, i, i + validators
)

def patchimage(self, toimage, src, dst="/data", fromimage="ghcr.io/crypto-org-chain/cronos-testground:latest"):

Check failure on line 64 in testground/benchmark/benchmark/stateless.py

View workflow job for this annotation

GitHub Actions / Lint python

./testground/benchmark/benchmark/stateless.py:64:89: E501 line too long (115 > 88 characters)
yihuang marked this conversation as resolved.
Show resolved Hide resolved
'''
combine data directory with an exiting image to produce a new image
'''
with tempfile.TemporaryDirectory() as tmpdir:
tmpdir = Path(tmpdir)
shutil.copytree(src, tmpdir / "out")
content = f'''FROM {fromimage}
ADD ./out {dst}
'''
print(content)
(tmpdir / "Dockerfile").write_text(content)
subprocess.run(["docker", "build", "-t", toimage, tmpdir])

yihuang marked this conversation as resolved.
Show resolved Hide resolved
def run(
self,
outdir: str,
Expand Down Expand Up @@ -100,12 +116,12 @@


def init_node_local(
cli: ChainCommand, outdir: Path, group: str, group_seq: int, global_seq: int
cli: ChainCommand, outdir: Path, group: str, group_seq: int, ip: str
) -> PeerPacket:
return init_node(
cli,
outdir / group / str(group_seq),
CONTAINER_PREFIX + str(global_seq),
ip,
DEFAULT_CHAIN_ID,
group,
group_seq,
Expand Down
5 changes: 1 addition & 4 deletions testground/benchmark/compositions/docker-compose.jsonnet
Original file line number Diff line number Diff line change
@@ -1,12 +1,9 @@
std.manifestYamlDoc({
services: {
['testplan-' + i]: {
image: 'ghcr.io/crypto-org-chain/cronos-testground:latest',
image: 'cronos-testground:latest',
command: 'stateless-testcase run /data 3 --num_accounts=10 --num_txs=1000',
container_name: 'testplan-' + i,
volumes: [
@'${DATADIR:-/tmp/data/out}:/data',
],
environment: {
JOB_COMPLETION_INDEX: i,
},
Expand Down
Loading