Skip to content

Commit

Permalink
tmp: debug test in ci
Browse files Browse the repository at this point in the history
  • Loading branch information
mandesero committed Nov 21, 2024
1 parent cc95fef commit 0a0b288
Show file tree
Hide file tree
Showing 3 changed files with 113 additions and 33 deletions.
25 changes: 25 additions & 0 deletions test/integration/replicaset/small_cluster_app/config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
credentials:
users:
client:
password: 'secret'
roles: [super]
guest:
roles: [super]

groups:
group-001:
replicasets:
replicaset-001:
instances:
storage-master:
iproto:
listen:
- uri: '127.0.0.1:3301'
database:
mode: rw
storage-replica:
iproto:
listen:
- uri: '127.0.0.1:3302'
database:
mode: ro
4 changes: 4 additions & 0 deletions test/integration/replicaset/small_cluster_app/instances.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
storage-master:

storage-replica:

117 changes: 84 additions & 33 deletions test/integration/replicaset/test_replicaset_upgrade.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
import os
import re
import shutil
import subprocess
import tempfile
import time

import pytest
from replicaset_helpers import stop_application
from vshard_cluster import VshardCluster

from utils import get_tarantool_version, run_command_and_get_output, wait_file
from utils import (control_socket, get_tarantool_version,
run_command_and_get_output, run_path, wait_file)

tarantool_major_version, _ = get_tarantool_version()

Expand Down Expand Up @@ -195,38 +196,88 @@ def test_upgrade_downgraded_cluster_replicasets(tt_cmd, tmp_path):
app.stop()


# @pytest.mark.skipif(tarantool_major_version < 3,
# reason="skip test with cluster config for Tarantool < 3")
# def _test_upgrade_remote_replicasets(tt_cmd, tmp_path):
# app_name = "vshard_app"
# replicasets = {
# "router-001": ["router-001-a"],
# "storage-001": ["storage-001-a", "storage-001-b"],
# "storage-002": ["storage-002-a", "storage-002-b"],
# }
# app = VshardCluster(tt_cmd, tmp_path, app_name)
# try:
# app.build()
# app.start()

# ip_port_pattern = r'\b(?:localhost|(?:\d{1,3}\.){3}\d{1,3}):\d+\b'
# instance_uri = {}
# for rs, insts in replicasets.items():
# for inst in insts:
# tmp = app.eval(inst, "require('config'):instance_uri().uri")
# print(f"{inst}:{tmp}")
# res = re.findall(
# ip_port_pattern,
# tmp
# )
# assert len(res) == 1
# instance_uri[inst] = res[0]

# for rs in replicasets:
# # It is enough to specify one of the instances from the replica set.
# inst = replicasets[rs][0]
# uri = f"tcp://client:secret@{instance_uri[inst]}"
# upgrade_cmd = [tt_cmd, "replicaset", "upgrade", uri, "-t=15"]
# rc, out = run_command_and_get_output(upgrade_cmd, cwd=tmp_path)
# assert rc == 0
# assert "ok" in out
# finally:
# app.stop()


def start_application(cmd, workdir, app_name, instances):
instance_process = subprocess.Popen(
cmd,
cwd=workdir,
stderr=subprocess.STDOUT,
stdout=subprocess.PIPE,
text=True
)
start_output = instance_process.stdout.read()
for inst in instances:
assert f"Starting an instance [{app_name}:{inst}]" in start_output


@pytest.mark.skipif(tarantool_major_version < 3,
reason="skip test with cluster config for Tarantool < 3")
def test_upgrade_remote_replicasets(tt_cmd, tmp_path):
app_name = "vshard_app"
replicasets = {
"router-001": ["router-001-a"],
"storage-001": ["storage-001-a", "storage-001-b"],
"storage-002": ["storage-002-a", "storage-002-b"],
}
app = VshardCluster(tt_cmd, tmp_path, app_name)
reason="skip cluster instances test for Tarantool < 3")
def test_upgrade_remote_replicasets(tt_cmd, tmpdir_with_cfg):
tmpdir = tmpdir_with_cfg
app_name = "small_cluster_app"
app_path = os.path.join(tmpdir, app_name)
shutil.copytree(os.path.join(os.path.dirname(__file__), app_name), app_path)

run_dir = os.path.join(tmpdir, app_name, run_path)
instances = ['storage-master', 'storage-replica']

try:
app.build()
app.start()
# Start an instance.
start_cmd = [tt_cmd, "start", app_name]
start_application(start_cmd, tmpdir, app_name, instances)

# Check status.
for inst in instances:
file = wait_file(os.path.join(run_dir, inst), 'tarantool.pid', [])
assert file != ""
file = wait_file(os.path.join(run_dir, inst), control_socket, [])
assert file != ""
time.sleep(3)
uri = "tcp://client:[email protected]:3301"
upgrade_cmd = [tt_cmd, "replicaset", "upgrade", uri, "-t=15"]
rc, out = run_command_and_get_output(upgrade_cmd, cwd=tmpdir)
assert rc == 0
assert "ok" in out

ip_port_pattern = r'\b(?:localhost|(?:\d{1,3}\.){3}\d{1,3}):\d+\b'
instance_uri = {}
for rs, insts in replicasets.items():
for inst in insts:
res = re.findall(
ip_port_pattern,
app.eval(inst, "require('config'):instance_uri().uri")
)
assert len(res) == 1
instance_uri[inst] = res[0]

for rs in replicasets:
# It is enough to specify one of the instances from the replica set.
inst = replicasets[rs][0]
uri = f"tcp://client:secret@{instance_uri[inst]}"
upgrade_cmd = [tt_cmd, "replicaset", "upgrade", uri, "-t=15"]
rc, out = run_command_and_get_output(upgrade_cmd, cwd=tmp_path)
assert rc == 0
assert "ok" in out
finally:
app.stop()
stop_cmd = [tt_cmd, "stop", app_name, "-y"]
stop_rc, stop_out = run_command_and_get_output(stop_cmd, cwd=tmpdir)
assert stop_rc == 0

0 comments on commit 0a0b288

Please sign in to comment.