From a30a1e506956044bef30bd7cb076f93bc2d76d44 Mon Sep 17 00:00:00 2001 From: Maksim Tiushev Date: Thu, 12 Sep 2024 16:00:52 +0000 Subject: [PATCH] test: add tests for the 'tt upgrade' command This pacth adds a series of tests to validate the functionality of the `tt upgrade` command. --- test/integration/upgrade/test_upgrade.py | 106 +++++++++++++++++++++++ 1 file changed, 106 insertions(+) create mode 100644 test/integration/upgrade/test_upgrade.py diff --git a/test/integration/upgrade/test_upgrade.py b/test/integration/upgrade/test_upgrade.py new file mode 100644 index 000000000..560ebc443 --- /dev/null +++ b/test/integration/upgrade/test_upgrade.py @@ -0,0 +1,106 @@ +import re + +import pytest +from vshard_cluster import VshardCluster + +from utils import get_tarantool_version, run_command_and_get_output + +tarantool_major_version, _ = get_tarantool_version() + + +@pytest.mark.skipif(tarantool_major_version < 3, + reason="skip test with cluster config for Tarantool < 3") +def test_upgrade_all_replicasets(tt_cmd, tmp_path): + replicasets = [ + "router-001", + "storage-001", + "storage-002", + ] + app = VshardCluster(tt_cmd, tmp_path, "vshard_app") + try: + app.build() + app.start() + + upgrade_cmd = [tt_cmd, "upgrade"] + upgrade_rc, upgrade_out = run_command_and_get_output( + upgrade_cmd, + cwd=app.env_dir + ) + assert upgrade_rc == 0 + + upgrade_out = upgrade_out.strip().split('\n') + assert len(upgrade_out) == len(replicasets) + + for i in range(len(replicasets)): + match = re.search(r"•\s*(.*?):\s*(.*)", upgrade_out[i]) + assert match.group(1) in replicasets + assert match.group(2) == "ok" + + finally: + app.stop() + + +@pytest.mark.skipif(tarantool_major_version < 3, + reason="skip test with cluster config for Tarantool < 3") +def test_upgrade_specify_replicasets(tt_cmd, tmp_path): + app = VshardCluster(tt_cmd, tmp_path, "vshard_app") + try: + app.build() + app.start() + + upgrade_cmd = [tt_cmd, "upgrade", "--replicaset", "storage-001"] + upgrade_rc, upgrade_out = run_command_and_get_output( + upgrade_cmd, + cwd=app.env_dir + ) + assert upgrade_rc == 0 + + upgrade_out = upgrade_out.strip().split('\n') + assert len(upgrade_out) == 1 + assert upgrade_out[0] == "• storage-001: ok" + + finally: + app.stop() + + +@pytest.mark.skipif(tarantool_major_version < 3, + reason="skip test with cluster config for Tarantool < 3") +def test_upgrade_error_no_master(tt_cmd, tmp_path): + app = VshardCluster(tt_cmd, tmp_path, "vshard_app") + try: + app.build() + app.start() + _ = app.eval("storage-001-a", lua="box.cfg{read_only=true}") + + upgrade_cmd = [tt_cmd, "upgrade"] + upgrade_rc, upgrade_out = run_command_and_get_output( + upgrade_cmd, + cwd=app.env_dir + ) + assert upgrade_rc != 0 + assert "[storage-001]: has not master instance" in upgrade_out + + finally: + app.stop() + + +@pytest.mark.skipif(tarantool_major_version < 3, + reason="skip test with cluster config for Tarantool < 3") +def test_upgrade_error_multi_master(tt_cmd, tmp_path): + app = VshardCluster(tt_cmd, tmp_path, "vshard_app") + try: + app.build() + app.start() + _ = app.eval("storage-001-b", lua="box.cfg{read_only=false}") + + upgrade_cmd = [tt_cmd, "upgrade"] + upgrade_rc, upgrade_out = run_command_and_get_output( + upgrade_cmd, + cwd=app.env_dir + ) + assert upgrade_rc != 0 + assert ("[storage-001]: vshard_app:storage-001-a and vshard_app:storage-001-b " + "are both masters") in upgrade_out + + finally: + app.stop()