Skip to content

Commit

Permalink
test: add tests for the 'tt upgrade' command
Browse files Browse the repository at this point in the history
This pacth adds a series of tests to validate the functionality of
the `tt upgrade` command.
  • Loading branch information
mandesero committed Sep 17, 2024
1 parent 8a88169 commit a30a1e5
Showing 1 changed file with 106 additions and 0 deletions.
106 changes: 106 additions & 0 deletions test/integration/upgrade/test_upgrade.py
Original file line number Diff line number Diff line change
@@ -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()

0 comments on commit a30a1e5

Please sign in to comment.