8000 uninstall: add tt uninstall tcm command by dmyger · Pull Request #1160 · tarantool/tt · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

uninstall: add tt uninstall tcm command #1160

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
May 19, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
manager (TCM) in the customer zone or local `distfiles` directory.
- `tt install tcm` - the command performs an install for tarantool cluster
manager (TCM) from the customer zone or local `distfiles` directory.
- `tt uninstall tcm [version]` - the command removes installed tarantool
cluster manager from the `bin` directory.
- `tt tcm status`: added command to check TCM runtime status (modes: `watchdog` or `interactive`).
- `tt tcm stop`: add command for graceful termination of TCM processes (modes: `watchdog` or `interactive`).

Expand Down
24 changes: 24 additions & 0 deletions cli/cmd/uninstall.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,29 @@ func newUninstallTarantoolDevCmd() *cobra.Command {
return tntCmd
}

// newUninstallTcmCmd creates a command to install tarantool-ee.
func newUninstallTcmCmd() *cobra.Command {
tntCmd := &cobra.Command{
Use: search.ProgramTcm.String() + " [version]",
Short: "Uninstall tarantool cluster manager",
Run: RunModuleFunc(InternalUninstallModule),
Args: cobra.MaximumNArgs(1),
ValidArgsFunction: func(
cmd *cobra.Command,
args []string,
toComplete string,
) ([]string, cobra.ShellCompDirective) {
if len(args) > 0 {
return []string{}, cobra.ShellCompDirectiveNoFileComp
}
return uninstall.GetList(cliOpts, cmd.Name()),
cobra.ShellCompDirectiveNoFileComp
},
}

return tntCmd
}

// NewUninstallCmd creates uninstall command.
func NewUninstallCmd() *cobra.Command {
uninstallCmd := &cobra.Command{
Expand All @@ -106,6 +129,7 @@ func NewUninstallCmd() *cobra.Command {
newUninstallTarantoolCmd(),
newUninstallTarantoolEeCmd(),
newUninstallTarantoolDevCmd(),
newUninstallTcmCmd(),
)

return uninstallCmd
Expand Down
61 changes: 30 additions & 31 deletions cli/uninstall/uninstall.go
Original file line number Diff line number Diff line change
9E7A Expand Up @@ -6,6 +6,7 @@ import (
"os"
"path/filepath"
"regexp"
"slices"
"strings"

"github.com/tarantool/tt/cli/install"
Expand All @@ -18,13 +19,10 @@ import (
"github.com/tarantool/tt/cli/version"
)

var progRegexp = "(?P<prog>" +
search.ProgramTt.String() + "|" +
search.ProgramCe.String() + "|" +
search.ProgramEe.String() + ")"

const (
verRegexp = "(?P<ver>.*)"
progRegexp = "(?P<prog>.+)"

verRegexp = "(?P<ver>.+)"

MajorMinorPatchRegexp = `^[0-9]+\.[0-9]+\.[0-9]+`
)
Expand All @@ -34,7 +32,8 @@ var errNotInstalled = errors.New("program is not installed")
// remove removes binary/directory and symlinks from directory.
// It returns true if symlink was removed, error.
func remove(program search.Program, programVersion string, directory string,
cmdCtx *cmdcontext.CmdCtx) (bool, error) {
cmdCtx *cmdcontext.CmdCtx,
) (bool, error) {
var linkPath string
var err error

Expand Down Expand Up @@ -94,7 +93,8 @@ func UninstallProgram(
programVersion string,
binDst string,
headerDst string,
cmdCtx *cmdcontext.CmdCtx) error {
cmdCtx *cmdcontext.CmdCtx,
) error {
log.Infof("Removing binary...")
var err error

Expand Down Expand Up @@ -236,12 +236,12 @@ func GetList(cliOpts *config.CliOpts, program string) []string {
}

// searchLatestVersion searches for the latest installed version of the program.
func searchLatestVersion(linkName, binDst, headerDst string) (string, error) {
var programsToSearch []string
if linkName == "tarantool" {
programsToSearch = []string{search.ProgramCe.String(), search.ProgramEe.String()}
} else {
programsToSearch = []string{linkName}
//
// Note: Searching `tarantool` EE or Dev versions may lead to found the latest CE version.
func searchLatestVersion(program search.Program, binDst, headerDst string) (string, error) {
programsToSearch := []string{program.Exec()}
if program.IsTarantool() && program.Exec() != program.String() {
programsToSearch = append(programsToSearch, program.String())
}

programRegex := regexp.MustCompile(
Expand All @@ -255,7 +255,6 @@ func searchLatestVersion(linkName, binDst, headerDst string) (string, error) {

latestVersionInfo := version.Version{}
latestVersion := ""
hashFound := false
latestHash := ""

for _, binary := range binaries {
Expand All @@ -272,31 +271,31 @@ func searchLatestVersion(linkName, binDst, headerDst string) (string, error) {
}

programName := matches["prog"]

// Need to find the program in the list of suitable.
if util.Find(programsToSearch, programName) == -1 {
if !slices.Contains(programsToSearch, programName) {
continue
}
isRightFormat, _ := util.IsValidCommitHash(matches["ver"])

if isRightFormat {
if hashFound {
continue
}
if strings.Contains(programName, "tarantool") {
// Check for headers.
if _, err := os.Stat(filepath.Join(headerDst, binaryName)); os.IsNotExist(err) {
continue
if latestHash == "" {
isHash, _ := util.IsValidCommitHash(matches["ver"])
if isHash {
if program.IsTarantool() {
// Same version of headers is required to activate the Tarantool binary.
if _, err := os.Stat(filepath.Join(headerDst, binaryName)); os.IsNotExist(err) {
continue
}
}
latestHash = binaryName
continue
}
hashFound = true
latestHash = binaryName
continue
}

ver, err := version.Parse(matches["ver"])
if err != nil {
log.Debugf("%q skipped: wrong version format", binaryName)
continue
}
if strings.Contains(programName, "tarantool") {
if program.IsTarantool() {
// Check for headers.
if _, err := os.Stat(filepath.Join(headerDst, binaryName)); os.IsNotExist(err) {
continue
Expand All @@ -318,7 +317,7 @@ func searchLatestVersion(linkName, binDst, headerDst string) (string, error) {
func switchProgramToLatestVersion(program search.Program, binDst, headerDst string) error {
linkName := program.Exec()

progToSwitch, err := searchLatestVersion(linkName, binDst, headerDst)
progToSwitch, err := searchLatestVersion(program, binDst, headerDst)
if err != nil {
return err
}
Expand Down
22 changes: 11 additions & 11 deletions cli/uninstall/uninstall_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ func TestGetList(t *testing.T) {
cfgData := []byte("tt:\n app:\n bin_dir: " + binDir)
cfgPath := filepath.Join(workDir, "tt.yaml")

err = os.WriteFile(cfgPath, cfgData, 0400)
err = os.WriteFile(cfgPath, cfgData, 0o400)
require.NoError(t, err)

files := []string{
Expand Down Expand Up @@ -65,7 +65,7 @@ func TestGetList(t *testing.T) {
func TestSearchLatestVersion(t *testing.T) {
type testCase struct {
name string
linkName string
program search.Program
binDst string
headerDst string
expectedVer string
Expand All @@ -75,57 +75,57 @@ func TestSearchLatestVersion(t *testing.T) {
cases := []testCase{
{
name: "basic",
linkName: "tarantool",
program: search.ProgramCe,
binDst: "./testdata/bin_basic",
headerDst: "./testdata/inc_basic",
expectedVer: "tarantool_3.0.0-entrypoint",
},
{
name: "no includes",
linkName: "tarantool",
program: search.ProgramEe,
binDst: "./testdata/bin_basic",
headerDst: "./testdata/inc_invalid",
expectedVer: "tarantool-ee_2.8.4-0-r510",
},
{
name: "tarantool-dev",
linkName: "tarantool",
program: search.ProgramCe,
binDst: "./testdata/bin_dev",
headerDst: "./testdata/inc_basic",
expectedVer: "",
},
{
name: "hash version",
linkName: "tarantool",
program: search.ProgramCe,
binDst: "./testdata/bin_hash",
headerDst: "./testdata/inc_hash",
expectedVer: "tarantool_aaaaaaa",
},
{
name: "hash invalid headers",
linkName: "tarantool",
program: search.ProgramCe,
binDst: "./testdata/bin_hash",
headerDst: "./testdata/inc_invalid_hash",
expectedVer: "tarantool_bbbbbbb",
},
{
name: "tt, include-dir basic",
linkName: "tt",
program: search.ProgramTt,
binDst: "./testdata/bin_basic",
headerDst: "./testdata/inc_basic",
expectedVer: "tt_2.0.0",
},
// Test that include dir doesn't affect the search for `tt`.
{
name: "tt, include-dir invalid",
linkName: "tt",
program: search.ProgramTt,
binDst: "./testdata/bin_basic",
headerDst: "./testdata/inc_invalid",
expectedVer: "tt_2.0.0",
},
{
name: "filename as a bin dir",
linkName: "tt",
program: search.ProgramTt,
binDst: "./testdata/bin_basic/tarantool",
headerDst: "./testdata/inc_basic",
isErr: true,
Expand All @@ -134,7 +134,7 @@ func TestSearchLatestVersion(t *testing.T) {

for _, tc := range cases {
t.Run(tc.name, func(t *testing.T) {
ver, err := searchLatestVersion(tc.linkName, tc.binDst, tc.headerDst)
ver, err := searchLatestVersion(tc.program, tc.binDst, tc.headerDst)
if !tc.isErr {
assert.NoError(t, err)
assert.Equal(t, tc.expectedVer, ver)
Expand Down
2 changes: 2 additions & 0 deletions cli/util/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,8 @@ func JoinAbspath(paths ...string) (string, error) {
}

// Find find index of specified string in the slice.
//
// Deprecated: use [slices.Index] or [slices.Contains] instead.
func Find(src []string, find string) int {
for i, elem := range src {
if find == elem {
Expand Down
Loading
Loading
0