-
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.
Part of #316
- Loading branch information
Showing
4 changed files
with
265 additions
and
9 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
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,73 @@ | ||
package replicasetcmd | ||
|
||
import ( | ||
"fmt" | ||
|
||
"github.com/apex/log" | ||
"github.com/tarantool/tt/cli/replicaset" | ||
"github.com/tarantool/tt/cli/running" | ||
) | ||
|
||
// BootstrapCtx describes context to bootstrap an instance or application. | ||
type BootstapCtx struct { | ||
// ReplicasetsFile is a Cartridge replicasets file. | ||
ReplicasetsFile string | ||
// Orchestrator is a forced orchestator choice. | ||
Orchestrator replicaset.Orchestrator | ||
// RunningCtx is an application running context. | ||
RunningCtx running.RunningCtx | ||
// Timeout describes a timeout in seconds. | ||
// We keep int as it can be passed to the target instance. | ||
Timeout int | ||
// BootstrapVShard is true when the vshard must be bootstrapped. | ||
BootstrapVShard bool | ||
// Instance is an instance name to bootstrap. | ||
Instance string | ||
// Replicaset is a replicaset name for an instance bootstrapping. | ||
Replicaset string | ||
} | ||
|
||
// Bootstrap bootstraps an instance or application. | ||
func Bootstrap(ctx BootstapCtx) error { | ||
if ctx.Instance != "" { | ||
if ctx.Replicaset == "" { | ||
return fmt.Errorf("the replicaset must be specified to bootstrap an instance") | ||
} | ||
} else { | ||
if ctx.Replicaset != "" { | ||
return fmt.Errorf( | ||
"the replicaset can not be specified in the case of application bootstrapping") | ||
} | ||
} | ||
|
||
orchestratorType, err := getApplicationOrchestrator(ctx.Orchestrator, | ||
ctx.RunningCtx) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
orchestrator, err := makeApplicationOrchestrator(orchestratorType, | ||
ctx.RunningCtx, nil, nil) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
err = orchestrator.Bootstrap(replicaset.BootstrapCtx{ | ||
ReplicasetsFile: ctx.ReplicasetsFile, | ||
Timeout: ctx.Timeout, | ||
Instance: ctx.Instance, | ||
Replicaset: ctx.Replicaset, | ||
BootstrapVShard: ctx.BootstrapVShard, | ||
}) | ||
if err == nil { | ||
// Re-discovery and log topology. | ||
replicasets, err := orchestrator.Discovery(replicaset.SkipCache) | ||
if err != nil { | ||
return err | ||
} | ||
statusReplicasets(replicasets) | ||
fmt.Println() | ||
log.Info("Done.") | ||
} | ||
return err | ||
} |
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
124 changes: 124 additions & 0 deletions
124
test/integration/replicaset/test_replicaset_bootstrap.py
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,124 @@ | ||
import os | ||
import re | ||
import shutil | ||
|
||
import pytest | ||
|
||
from utils import get_tarantool_version, run_command_and_get_output, wait_file | ||
|
||
tarantool_major_version, tarantool_minor_version = get_tarantool_version() | ||
|
||
|
||
@pytest.mark.skipif(tarantool_major_version > 2, | ||
reason="skip custom test for Tarantool > 2") | ||
@pytest.mark.parametrize("case", [["--config", "--custom"], | ||
["--custom", "--cartridge"], | ||
["--config", "--cartridge"], | ||
["--config", "--custom", "--cartridge"]]) | ||
def test_bootstrap(tt_cmd, tmpdir_with_cfg, case): | ||
cmd = [tt_cmd, "rs", "bootstrap"] + case + ["app:instance"] | ||
rc, out = run_command_and_get_output(cmd, cwd=tmpdir_with_cfg) | ||
assert rc == 1 | ||
assert re.search(r" ⨯ only one type of orchestrator can be forced", out) | ||
|
||
|
||
@pytest.mark.skipif(tarantool_major_version > 2, | ||
reason="skip custom test for Tarantool > 2") | ||
def test_bootstrap_no_instance(tt_cmd, tmpdir_with_cfg): | ||
tmpdir = tmpdir_with_cfg | ||
app_name = "test_custom_app" | ||
app_path = os.path.join(tmpdir, app_name) | ||
shutil.copytree(os.path.join(os.path.dirname(__file__), app_name), app_path) | ||
|
||
status_cmd = [tt_cmd, "rs", "bootstrap", "test_custom_app:unexist"] | ||
rc, out = run_command_and_get_output(status_cmd, cwd=tmpdir_with_cfg) | ||
assert rc == 1 | ||
assert re.search(r" ⨯ instance \"unexist\" not found", out) | ||
|
||
|
||
@pytest.mark.skipif(tarantool_major_version > 2, | ||
reason="skip custom test for Tarantool > 2") | ||
@pytest.mark.parametrize("flag", [None, "--custom"]) | ||
def test_bootstrap_custom_app(tt_cmd, tmpdir_with_cfg, flag): | ||
tmpdir = tmpdir_with_cfg | ||
app_name = "test_custom_app" | ||
app_path = os.path.join(tmpdir, app_name) | ||
shutil.copytree(os.path.join(os.path.dirname(__file__), app_name), app_path) | ||
try: | ||
# Start a cluster. | ||
start_cmd = [tt_cmd, "start", app_name] | ||
rc, out = run_command_and_get_output(start_cmd, cwd=tmpdir) | ||
assert rc == 0 | ||
|
||
# Check for start. | ||
file = wait_file(os.path.join(tmpdir, app_name), 'ready', []) | ||
assert file != "" | ||
|
||
cmd = [tt_cmd, "rs", "bootstrap"] | ||
if flag: | ||
cmd.append(flag) | ||
cmd.append("test_custom_app") | ||
|
||
rc, out = run_command_and_get_output(cmd, cwd=tmpdir) | ||
assert rc == 1 | ||
expected = '⨯ bootstrap is not supported for an application by "custom" orchestrator' | ||
assert expected in out | ||
finally: | ||
stop_cmd = [tt_cmd, "stop", app_name] | ||
rc, _ = run_command_and_get_output(stop_cmd, cwd=tmpdir) | ||
assert rc == 0 | ||
|
||
|
||
@pytest.mark.skipif(tarantool_major_version > 2, | ||
reason="skip custom test for Tarantool > 2") | ||
def test_bootstrap_instance_no_replicaset_specified(tt_cmd, tmpdir_with_cfg): | ||
tmpdir = tmpdir_with_cfg | ||
app_name = "test_custom_app" | ||
app_path = os.path.join(tmpdir, app_name) | ||
shutil.copytree(os.path.join(os.path.dirname(__file__), app_name), app_path) | ||
try: | ||
# Start a cluster. | ||
start_cmd = [tt_cmd, "start", app_name] | ||
rc, out = run_command_and_get_output(start_cmd, cwd=tmpdir) | ||
assert rc == 0 | ||
|
||
# Check for start. | ||
file = wait_file(os.path.join(tmpdir, app_name), 'ready', []) | ||
assert file != "" | ||
|
||
cmd = [tt_cmd, "rs", "bootstrap", "test_custom_app:test_custom_app"] | ||
rc, out = run_command_and_get_output(cmd, cwd=tmpdir) | ||
assert rc != 0 | ||
assert "⨯ the replicaset must be specified to bootstrap an instance" in out | ||
finally: | ||
stop_cmd = [tt_cmd, "stop", app_name] | ||
rc, _ = run_command_and_get_output(stop_cmd, cwd=tmpdir) | ||
assert rc == 0 | ||
|
||
|
||
@pytest.mark.skipif(tarantool_major_version > 2, | ||
reason="skip custom test for Tarantool > 2") | ||
def test_bootstrap_app_replicaset_specified(tt_cmd, tmpdir_with_cfg): | ||
tmpdir = tmpdir_with_cfg | ||
app_name = "test_custom_app" | ||
app_path = os.path.join(tmpdir, app_name) | ||
shutil.copytree(os.path.join(os.path.dirname(__file__), app_name), app_path) | ||
try: | ||
# Start a cluster. | ||
start_cmd = [tt_cmd, "start", app_name] | ||
rc, out = run_command_and_get_output(start_cmd, cwd=tmpdir) | ||
assert rc == 0 | ||
|
||
# Check for start. | ||
file = wait_file(os.path.join(tmpdir, app_name), 'ready', []) | ||
assert file != "" | ||
|
||
cmd = [tt_cmd, "rs", "bootstrap", "--replicaset", "r1", "test_custom_app"] | ||
rc, out = run_command_and_get_output(cmd, cwd=tmpdir) | ||
assert rc != 0 | ||
expected = "⨯ the replicaset can not be specified in the case of application bootstrapping" | ||
assert expected in out | ||
finally: | ||
stop_cmd = [tt_cmd, "stop", app_name] | ||
rc, _ = run_command_and_get_output(stop_cmd, cwd=tmpdir) | ||
assert rc == 0 |