Skip to content

Commit 74484d9

Browse files
committed
replicaset downgrade: make version a positional argument
Closes #1073 @TarantoolBot title: replicaset downgrade: make version a positional argument The option `-v` (`--version`) is no longer used.
1 parent eef7cf5 commit 74484d9

File tree

3 files changed

+30
-30
lines changed

3 files changed

+30
-30
lines changed

CHANGELOG.md

+2
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
3434
- `tt coredump pack`: if `-e` option is omitted first search tarantool
3535
executable in tt environment then in `PATH` instead of using the hardcoded
3636
path `/usr/bin/tarantool`.
37+
- `tt replicaset downgrade`: make version a positional argument rather than
38+
using the mandatory option `-v` (`--version`).
3739

3840
### Fixed
3941

cli/cmd/replicaset.go

+20-22
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ package cmd
33
import (
44
"errors"
55
"fmt"
6-
"os"
76
"regexp"
87
"strings"
98

@@ -51,7 +50,6 @@ var (
5150

5251
chosenReplicasetAliases []string
5352
lsnTimeout int
54-
downgradeVersion string
5553

5654
replicasetUriHelp = " The URI can be specified in the following formats:\n" +
5755
" * [tcp://][username:password@][host:port]\n" +
@@ -90,33 +88,33 @@ func newUpgradeCmd() *cobra.Command {
9088

9189
// newDowngradeCmd creates a "replicaset downgrade" command.
9290
func newDowngradeCmd() *cobra.Command {
91+
validateVersion := func(i int) cobra.PositionalArgs {
92+
return func(cmd *cobra.Command, args []string) error {
93+
var versionPattern = regexp.MustCompile(`^\d+\.\d+\.\d+$`)
94+
if args[i] == "" {
95+
return errors.New("need to specify the version to downgrade to")
96+
} else if !versionPattern.MatchString(args[i]) {
97+
return errors.New("version must be in the format " +
98+
"'x.x.x', where x is a number")
99+
}
100+
return nil
101+
}
102+
}
103+
93104
cmd := &cobra.Command{
94-
Use: "downgrade (<APP_NAME> | <URI>) [flags]\n\n" +
105+
Use: "downgrade (<APP_NAME> | <URI>) VERSION [flags]\n\n" +
95106
replicasetUriHelp,
96107
DisableFlagsInUseLine: true,
97108
Short: "Downgrade tarantool cluster",
98109
Long: "Downgrade tarantool cluster.\n\n" +
99110
libconnect.EnvCredentialsHelp + "\n\n",
100111
Run: func(cmd *cobra.Command, args []string) {
101-
var versionPattern = regexp.MustCompile(`^\d+\.\d+\.\d+$`)
102-
if downgradeVersion == "" {
103-
err := errors.New("need to specify the version to downgrade " +
104-
"use --version (-v) option")
105-
util.HandleCmdErr(cmd, err)
106-
os.Exit(1)
107-
} else if !versionPattern.MatchString(downgradeVersion) {
108-
err := errors.New("--version (-v) must be in the format " +
109-
"'x.x.x', where x is a number")
110-
util.HandleCmdErr(cmd, err)
111-
os.Exit(1)
112-
}
113-
114112
cmdCtx.CommandName = cmd.Name()
115113
err := modules.RunCmd(&cmdCtx, cmd.CommandPath(), &modulesInfo,
116114
internalReplicasetDowngradeModule, args)
117115
util.HandleCmdErr(cmd, err)
118116
},
119-
Args: cobra.ExactArgs(1),
117+
Args: cobra.MatchAll(cobra.ExactArgs(2), validateVersion(1)),
120118
}
121119

122120
cmd.Flags().StringArrayVarP(&chosenReplicasetAliases, "replicaset", "r",
@@ -125,9 +123,6 @@ func newDowngradeCmd() *cobra.Command {
125123
cmd.Flags().IntVarP(&lsnTimeout, "timeout", "t", 5,
126124
"timeout for waiting the LSN synchronization (in seconds)")
127125

128-
cmd.Flags().StringVarP(&downgradeVersion, "version", "v", "",
129-
"version to downgrade the schema to")
130-
131126
addOrchestratorFlags(cmd)
132127
addTarantoolConnectFlags(cmd)
133128
return cmd
@@ -608,8 +603,11 @@ func internalReplicasetUpgradeModule(cmdCtx *cmdcontext.CmdCtx, args []string) e
608603

609604
// internalReplicasetDowngradeModule is a "upgrade" command for the replicaset module.
610605
func internalReplicasetDowngradeModule(cmdCtx *cmdcontext.CmdCtx, args []string) error {
606+
target := args[0]
607+
downgradeVersion := args[1]
608+
611609
var ctx replicasetCtx
612-
if err := replicasetFillCtx(cmdCtx, &ctx, args[0], false); err != nil {
610+
if err := replicasetFillCtx(cmdCtx, &ctx, target, false); err != nil {
613611
return err
614612
}
615613
if ctx.IsInstanceConnect {
@@ -625,7 +623,7 @@ func internalReplicasetDowngradeModule(cmdCtx *cmdcontext.CmdCtx, args []string)
625623
SslCiphers: replicasetSslCiphers,
626624
}
627625
var connOpts connector.ConnectOpts
628-
connOpts, _ = resolveConnectOpts(cmdCtx, cliOpts, &connectCtx, args[0])
626+
connOpts, _ = resolveConnectOpts(cmdCtx, cliOpts, &connectCtx, target)
629627

630628
return replicasetcmd.Downgrade(replicasetcmd.DiscoveryCtx{
631629
IsApplication: ctx.IsApplication,

test/integration/replicaset/test_replicaset_downgrade.py

+8-8
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ def test_downgrade_multi_master(tt_cmd, tmpdir_with_cfg):
6262
)
6363
assert file != ""
6464

65-
downgrade_cmd = [tt_cmd, "replicaset", "downgrade", app_name, "-v=3.0.0"]
65+
downgrade_cmd = [tt_cmd, "replicaset", "downgrade", app_name, "3.0.0"]
6666

6767
rc, out = run_command_and_get_output(downgrade_cmd, cwd=tmpdir)
6868
assert rc == 1
@@ -97,7 +97,7 @@ def test_downgrade_t2_app_dummy_replicaset(tt_cmd):
9797
assert file != ""
9898

9999
downgrade_cmd = [
100-
tt_cmd, "replicaset", "downgrade", app_name, "--custom", "-v=2.8.2"
100+
tt_cmd, "replicaset", "downgrade", app_name, "2.8.2", "--custom"
101101
]
102102
rc, out = run_command_and_get_output(downgrade_cmd, cwd=test_app_path)
103103
assert rc == 0
@@ -139,7 +139,7 @@ def test_cluster_replicasets(tt_cmd, tmp_path):
139139
cmd_master
140140
)
141141

142-
downgrade_cmd = [tt_cmd, "replicaset", "downgrade", app_name, "-t=15", "-v=2.11.1"]
142+
downgrade_cmd = [tt_cmd, "replicaset", "downgrade", app_name, "2.11.1", "-t=15"]
143143
rc, out = run_command_and_get_output(downgrade_cmd, cwd=tmp_path)
144144

145145
assert rc == 0
@@ -171,16 +171,16 @@ def test_downgrade_invalid_version(tt_cmd, tmp_path):
171171
app.build()
172172
app.start()
173173

174-
downgrade_cmd = [tt_cmd, "replicaset", "downgrade", app_name, "-t=15", "-v=1.1.1"]
174+
downgrade_cmd = [tt_cmd, "replicaset", "downgrade", app_name, "1.1.1", "-t=15"]
175175
rc, out = run_command_and_get_output(downgrade_cmd, cwd=tmp_path)
176176

177177
assert rc == 1
178178
assert "Version '1.1.1' is not allowed." in out
179179

180-
downgrade_cmd = [tt_cmd, "replicaset", "downgrade", app_name, "-t=15", "-v=3.0"]
180+
downgrade_cmd = [tt_cmd, "replicaset", "downgrade", app_name, "3.0", "-t=15"]
181181
rc, out = run_command_and_get_output(downgrade_cmd, cwd=tmp_path)
182182

183-
assert "--version (-v) must be in the format 'x.x.x', where x is a number" in out
183+
assert "version must be in the format 'x.x.x', where x is a number" in out
184184
finally:
185185
app.stop()
186186

@@ -215,7 +215,7 @@ def test_downgrade_remote_replicasets(tt_cmd, tmpdir_with_cfg):
215215
)
216216

217217
uri = "tcp://client:[email protected]:3301"
218-
upgrade_cmd = [tt_cmd, "replicaset", "downgrade", uri, "-t=15", "-v=2.11.1"]
218+
upgrade_cmd = [tt_cmd, "replicaset", "downgrade", uri, "2.11.1", "-t=15"]
219219
rc, out = run_command_and_get_output(upgrade_cmd, cwd=tmpdir)
220220
assert rc == 0
221221
assert "ok" in out
@@ -267,7 +267,7 @@ def have_buckets_created():
267267
assert wait_event(10, have_buckets_created)
268268

269269
app_dir = cartridge_app.workdir
270-
upgrade_cmd = [tt_cmd, "replicaset", "downgrade", cartridge_name, "-t=15", "-v=2.10.0"]
270+
upgrade_cmd = [tt_cmd, "replicaset", "downgrade", cartridge_name, "2.10.0", "-t=15"]
271271
rc, out = run_command_and_get_output(upgrade_cmd, cwd=app_dir)
272272
assert rc == 0
273273
assert "ok" in out

0 commit comments

Comments
 (0)