Skip to content

Commit

Permalink
Problem: testground test case requires persistent volume (#1522)
Browse files Browse the repository at this point in the history
* Problem: testground test case requires persistent volume

Solution:
- persistent volume is a headache in k8s cluster, but we can embed the data directory into image to avoid that.

* cleanup

* lint

* nix develop -c black .

---------

Co-authored-by: mmsqe <[email protected]>
  • Loading branch information
yihuang and mmsqe authored Jul 24, 2024
1 parent 983a5a6 commit 1972437
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 14 deletions.
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
44 changes: 36 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,17 @@
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,
):
outdir = Path(outdir)
cli = ChainCommand(LOCAL_CRONOSD_PATH)
(outdir / VALIDATOR_GROUP).mkdir(parents=True, exist_ok=True)
Expand All @@ -39,12 +47,12 @@ def gen(self, outdir: str, validators: int, fullnodes: int):
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 +67,26 @@ def gen(self, outdir: str, validators: int, fullnodes: int):
peers, genesis, outdir, FULLNODE_GROUP, i, i + validators
)

def patchimage(
self,
toimage,
src,
dst="/data",
fromimage="ghcr.io/crypto-org-chain/cronos-testground:latest",
):
"""
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])

def run(
self,
outdir: str,
Expand Down Expand Up @@ -100,12 +128,12 @@ def run(


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

0 comments on commit 1972437

Please sign in to comment.