Skip to content

Commit

Permalink
clean: make output more compact
Browse files Browse the repository at this point in the history
The tt clean output where cumbersome, so it was made more compact.
Now, without the tt -V flag, the output will be compact and clear.
  • Loading branch information
Japsty authored and psergee committed Sep 9, 2024
1 parent ba846d8 commit 243afa7
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 26 deletions.
23 changes: 9 additions & 14 deletions cli/cmd/clean.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package cmd

import (
"fmt"
"errors"
"os"
"path/filepath"

Expand All @@ -16,6 +16,7 @@ import (
)

var forceRemove bool
var ErrCanceledByUser = errors.New("canceled by user")

// NewCleanCmd creates clean command.
func NewCleanCmd() *cobra.Command {
Expand Down Expand Up @@ -74,16 +75,6 @@ func clean(run *running.InstanceCtx) error {
}
}

if len(removeFiles) == 0 {
log.Infof("Already cleaned.\n")
return nil
}

log.Infof("List of files to delete:\n")
for file, _ := range removeFiles {
log.Infof("%s", file)
}

if !forceRemove {
confirm, err = util.AskConfirm(os.Stdin, "\nConfirm")
if err != nil {
Expand All @@ -97,12 +88,13 @@ func clean(run *running.InstanceCtx) error {
if err != nil {
return err
}
log.Debugf("removed %q", file)
}

return nil
}

return fmt.Errorf("canceled by user")
return ErrCanceledByUser
}

// internalCleanModule is a default clean module.
Expand All @@ -122,13 +114,16 @@ func internalCleanModule(cmdCtx *cmdcontext.CmdCtx, args []string) error {
var statusMsg string

err := clean(&run)
if err != nil {
if errors.Is(err, ErrCanceledByUser) {
statusMsg = ErrCanceledByUser.Error()
} else if err != nil {
statusMsg = "[ERR] " + err.Error()
} else {
statusMsg = "[OK]"
}

log.Infof("%s: cleaning...\t%s", run.InstName, statusMsg)
log.Infof("%s%c%s...\t%s", run.AppName, running.InstanceDelimiter, run.InstName,
statusMsg)
} else {
log.Infof("instance `%s` must be stopped", run.InstName)
}
Expand Down
25 changes: 13 additions & 12 deletions test/integration/running/test_running.py
Original file line number Diff line number Diff line change
Expand Up @@ -175,19 +175,20 @@ def test_logrotate(tt_cmd, tmpdir_with_cfg):
assert instance_process_rc == 0


def assert_file_cleaned(filepath, cmd_out):
def assert_file_cleaned(filepath, instance_name, cmd_out):
# https://github.com/tarantool/tt/issues/735
assert len(re.findall(r"• " + str(filepath), cmd_out)) == 1
assert len(re.findall(r"• " + instance_name, cmd_out)) == 1
assert os.path.exists(filepath) is False


def test_clean(tt_cmd, tmpdir_with_cfg):
tmpdir = tmpdir_with_cfg
test_app_path = os.path.join(os.path.dirname(__file__), "test_data_app", "test_data_app.lua")
app_name = "test_data_app"
test_app_path = os.path.join(os.path.dirname(__file__), app_name, "test_data_app.lua")
shutil.copy(test_app_path, tmpdir)

# Start an instance.
start_cmd = [tt_cmd, "start", "test_data_app"]
start_cmd = [tt_cmd, "start", app_name]
instance_process = subprocess.Popen(
start_cmd,
cwd=tmpdir,
Expand All @@ -199,9 +200,9 @@ def test_clean(tt_cmd, tmpdir_with_cfg):
assert re.search(r"Starting an instance", start_output)

# Wait until application is ready.
lib_dir = os.path.join(tmpdir, "test_data_app", lib_path, "test_data_app")
run_dir = os.path.join(tmpdir, "test_data_app", run_path, "test_data_app")
log_dir = os.path.join(tmpdir, "test_data_app", log_path, "test_data_app")
lib_dir = os.path.join(tmpdir, app_name, lib_path, app_name)
run_dir = os.path.join(tmpdir, app_name, run_path, app_name)
log_dir = os.path.join(tmpdir, app_name, log_path, app_name)

file = wait_file(lib_dir, initial_snap, [])
assert file != ""
Expand All @@ -216,13 +217,13 @@ def test_clean(tt_cmd, tmpdir_with_cfg):
assert file != ""

# Check that clean warns about application is running.
clean_cmd = [tt_cmd, "clean", "test_data_app", "--force"]
clean_cmd = [tt_cmd, "clean", app_name, "--force"]
clean_rc, clean_out = run_command_and_get_output(clean_cmd, cwd=tmpdir)
assert clean_rc == 0
assert re.search(r"instance `test_data_app` must be stopped", clean_out)

# Stop the Instance.
stop_cmd = [tt_cmd, "stop", "-y", "test_data_app"]
stop_cmd = [tt_cmd, "stop", "-y", app_name]
stop_rc, stop_out = run_command_and_get_output(stop_cmd, cwd=tmpdir)
assert stop_rc == 0
assert re.search(r"The Instance test_data_app \(PID = \d+\) has been terminated\.", stop_out)
Expand All @@ -236,9 +237,9 @@ def test_clean(tt_cmd, tmpdir_with_cfg):
assert clean_rc == 0
assert re.search(r"\[ERR\]", clean_out) is None

assert_file_cleaned(os.path.join(log_dir, log_file), clean_out)
assert_file_cleaned(os.path.join(lib_dir, initial_snap), clean_out)
assert_file_cleaned(os.path.join(lib_dir, initial_xlog), clean_out)
assert_file_cleaned(os.path.join(log_dir, log_file), app_name, clean_out)
assert_file_cleaned(os.path.join(lib_dir, initial_snap), app_name, clean_out)
assert_file_cleaned(os.path.join(lib_dir, initial_xlog), app_name, clean_out)


def test_running_base_functionality_working_dir_app(tt_cmd):
Expand Down

0 comments on commit 243afa7

Please sign in to comment.