-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test: add tests for the 'tt upgrade' command
This pacth adds a series of tests to validate the functionality of the `tt upgrade` command.
- Loading branch information
Showing
1 changed file
with
106 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() |