From 48dcd0af6237e33ad03ad3ca61fed0be5fc5141e Mon Sep 17 00:00:00 2001 From: Mikhail Elhimov Date: Wed, 25 Dec 2024 03:00:05 +0300 Subject: [PATCH] coredump pack: use tt env if omitted `-e` flag Closes #1069 @TarantoolBot document Title: `tt coredump pack` first search tarantool executable in tt env --- CHANGELOG.md | 5 +-- cli/cmd/coredump.go | 29 +++++++++++----- test/integration/coredump/test_coredump.py | 40 ++++++++++++++++------ 3 files changed, 53 insertions(+), 21 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 4ba1d1805..4ecd2a5a2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -26,8 +26,9 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0. * Cluster config for tarantool3-based cluster applications. - `tt logrotate`: don't exit at non-running instance, just warn and proceed with the other instances, like `tt stop` and `tt kill` do. -- `tt coredump pack`: by default tarantool executable path is obtained from - `PATH` instead of using the hardcoded path `/usr/bin/tarantool`. +- `tt coredump pack`: if `-e` option is omitted first search tarantool + executable in tt environment then in `PATH` instead of using the hardcoded + path `/usr/bin/tarantool`. ### Fixed diff --git a/cli/cmd/coredump.go b/cli/cmd/coredump.go index a84a1c22b..bc578568e 100644 --- a/cli/cmd/coredump.go +++ b/cli/cmd/coredump.go @@ -2,7 +2,9 @@ package cmd import ( "github.com/spf13/cobra" + "github.com/tarantool/tt/cli/cmdcontext" "github.com/tarantool/tt/cli/coredump" + "github.com/tarantool/tt/cli/modules" "github.com/tarantool/tt/cli/util" ) @@ -25,15 +27,10 @@ func NewCoredumpCmd() *cobra.Command { Use: "pack COREDUMP", Short: "pack tarantool coredump into tar.gz archive", Run: func(cmd *cobra.Command, args []string) { - err := coredump.Pack(args[0], - coredumpPackExecutable, - coredumpPackOutputDirectory, - coredumpPackPID, - coredumpPackTime, - ) - if err != nil { - util.HandleCmdErr(cmd, err) - } + cmdCtx.CommandName = cmd.Name() + err := modules.RunCmd(&cmdCtx, cmd.CommandPath(), &modulesInfo, + internalCoredumpPackModule, args) + util.HandleCmdErr(cmd, err) }, Args: cobra.ExactArgs(1), } @@ -80,3 +77,17 @@ func NewCoredumpCmd() *cobra.Command { return cmd } + +// internalCoredumpPackModule is a default "pack" command for the coredump module. +func internalCoredumpPackModule(cmdCtx *cmdcontext.CmdCtx, args []string) error { + executable := coredumpPackExecutable + if coredumpPackExecutable == "" { + executable = cmdCtx.Cli.TarantoolCli.Executable + } + return coredump.Pack(args[0], + executable, + coredumpPackOutputDirectory, + coredumpPackPID, + coredumpPackTime, + ) +} diff --git a/test/integration/coredump/test_coredump.py b/test/integration/coredump/test_coredump.py index a87c68017..e56b3e9c0 100644 --- a/test/integration/coredump/test_coredump.py +++ b/test/integration/coredump/test_coredump.py @@ -132,27 +132,47 @@ def test_coredump_pack(tt_cmd, tmp_path, coredump): assert re.search(r"Core was successfully packed.", output) +def check_tarantool_in_archive(tmp_path, expected_tarantool): + archives = list(tmp_path.glob("*.tar.gz")) + assert len(archives) == 1 + + # Extract Tarantool executable and check its version. + rc = subprocess.run(["tar", "xzf", archives[0], "--wildcards", "tarantool-core-*/tarantool"], + cwd=tmp_path).returncode + assert rc == 0 + unpacked_tarantools = list(tmp_path.glob("tarantool-core-*/tarantool")) + assert len(unpacked_tarantools) == 1 + version = get_tarantool_version(unpacked_tarantools[0]) + assert version == get_tarantool_version(expected_tarantool) + + @pytest.mark.skipif(skip_coredump_cond, reason=skip_coredump_reason) @pytest.mark.slow def test_coredump_pack_executable(tt_cmd, tmp_path, coredump_alt, tmpdir_with_tarantool): tarantool_bin = tmpdir_with_tarantool / 'bin' / 'tarantool' - version_expected = get_tarantool_version(tarantool_bin) cmd = [tt_cmd, "coredump", "pack", "-e", tarantool_bin, coredump_alt] rc, output = run_command_and_get_output(cmd, cwd=tmp_path) assert rc == 0 assert re.search(r"Core was successfully packed.", output) - archives = list(tmp_path.glob("*.tar.gz")) - assert len(archives) == 1 - # Extract Tarantool executable and check its version. - rc = subprocess.run(["tar", "xzf", archives[0], "--wildcards", "*/tarantool"], - cwd=tmp_path).returncode + check_tarantool_in_archive(tmp_path, tarantool_bin) + + +@pytest.mark.skipif(skip_coredump_cond, reason=skip_coredump_reason) +@pytest.mark.slow +def test_coredump_pack_executable_tt_env(tt_cmd, tmp_path, coredump_alt, tmpdir_with_tarantool): + tarantool_bin = tmpdir_with_tarantool / 'bin' / 'tarantool' + + assert subprocess.run([tt_cmd, "init"], cwd=tmp_path).returncode == 0 + os.symlink(tarantool_bin, tmp_path / 'bin' / 'tarantool') + + cmd = [tt_cmd, "coredump", "pack", coredump_alt] + rc, output = run_command_and_get_output(cmd, cwd=tmp_path) assert rc == 0 - unpacked_tarantools = list(tmp_path.glob("*/tarantool")) - assert len(unpacked_tarantools) == 1 - version = get_tarantool_version(unpacked_tarantools[0]) - assert version == version_expected + assert re.search(r"Core was successfully packed.", output) + + check_tarantool_in_archive(tmp_path, tarantool_bin) def test_coredump_unpack_no_arg(tt_cmd, tmp_path):