From 0a0b2885a30e2a7b777654c1433922515e21563c Mon Sep 17 00:00:00 2001 From: Maksim Tiushev Date: Thu, 21 Nov 2024 15:49:26 +0000 Subject: [PATCH] tmp: debug test in ci --- .../replicaset/small_cluster_app/config.yaml | 25 ++++ .../small_cluster_app/instances.yml | 4 + .../replicaset/test_replicaset_upgrade.py | 117 +++++++++++++----- 3 files changed, 113 insertions(+), 33 deletions(-) create mode 100644 test/integration/replicaset/small_cluster_app/config.yaml create mode 100644 test/integration/replicaset/small_cluster_app/instances.yml diff --git a/test/integration/replicaset/small_cluster_app/config.yaml b/test/integration/replicaset/small_cluster_app/config.yaml new file mode 100644 index 000000000..31a9edc1c --- /dev/null +++ b/test/integration/replicaset/small_cluster_app/config.yaml @@ -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 diff --git a/test/integration/replicaset/small_cluster_app/instances.yml b/test/integration/replicaset/small_cluster_app/instances.yml new file mode 100644 index 000000000..6eae339ec --- /dev/null +++ b/test/integration/replicaset/small_cluster_app/instances.yml @@ -0,0 +1,4 @@ +storage-master: + +storage-replica: + diff --git a/test/integration/replicaset/test_replicaset_upgrade.py b/test/integration/replicaset/test_replicaset_upgrade.py index 0a457d349..ac1ef2a2d 100644 --- a/test/integration/replicaset/test_replicaset_upgrade.py +++ b/test/integration/replicaset/test_replicaset_upgrade.py @@ -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() @@ -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:secret@127.0.0.1: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