Skip to content

Commit

Permalink
coredump pack: use tt env if omitted -e flag
Browse files Browse the repository at this point in the history
Closes #1069

@TarantoolBot document
Title: `tt coredump pack` first search tarantool executable in tt env
  • Loading branch information
elhimov committed Dec 26, 2024
1 parent 337b24d commit 48dcd0a
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 21 deletions.
5 changes: 3 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
29 changes: 20 additions & 9 deletions cli/cmd/coredump.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)

Expand All @@ -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),
}
Expand Down Expand Up @@ -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,
)
}
40 changes: 30 additions & 10 deletions test/integration/coredump/test_coredump.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down

0 comments on commit 48dcd0a

Please sign in to comment.