Skip to content

Commit

Permalink
cluster, dm: format semver input (#1009)
Browse files Browse the repository at this point in the history
* cluster, dm: format semver input

* utils: filter nightly version

* cluster: fix ci test

Co-authored-by: SIGSEGV <gnu.crazier@gmail.com>
Co-authored-by: Ti Prow Robot <71242396+ti-community-prow-bot@users.noreply.github.com>
  • Loading branch information
3 people committed Dec 31, 2020
1 parent 920f56d commit ad35eac
Show file tree
Hide file tree
Showing 8 changed files with 27 additions and 9 deletions.
5 changes: 4 additions & 1 deletion components/cluster/command/deploy.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,10 @@ func newDeploy() *cobra.Command {
}

clusterName := args[0]
version := args[1]
version, err := utils.FmtVer(args[1])
if err != nil {
return err
}
teleCommand = append(teleCommand, scrubClusterName(clusterName))
teleCommand = append(teleCommand, version)

Expand Down
6 changes: 5 additions & 1 deletion components/cluster/command/upgrade.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
package command

import (
"github.com/pingcap/tiup/pkg/utils"
"github.com/spf13/cobra"
)

Expand All @@ -27,7 +28,10 @@ func newUpgradeCmd() *cobra.Command {
}

clusterName := args[0]
version := args[1]
version, err := utils.FmtVer(args[1])
if err != nil {
return err
}
teleCommand = append(teleCommand, scrubClusterName(clusterName))
teleCommand = append(teleCommand, version)

Expand Down
5 changes: 4 additions & 1 deletion components/dm/command/deploy.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,10 @@ func newDeployCmd() *cobra.Command {
}

clusterName := args[0]
version := args[1]
version, err := utils.FmtVer(args[1])
if err != nil {
return err
}
topoFile := args[2]

if err := supportVersion(version); err != nil {
Expand Down
6 changes: 6 additions & 0 deletions pkg/utils/semver.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,12 @@ import (
// SemVer and fails to parse and convert it, an error is raised.
func FmtVer(ver string) (string, error) {
v := ver

// nightly version is an alias
if strings.ToLower(v) == "nightly" {
return v, nil
}

if !strings.HasPrefix(ver, "v") {
v = fmt.Sprintf("v%s", ver)
}
Expand Down
2 changes: 2 additions & 0 deletions pkg/utils/semver_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ func (s *TestSemverSuite) TestSemverc(c *C) {
{"0.0.1", "v0.0.1", true},
{"invalid", "vinvalid", false},
{"", "v", false},
{"nightly", "nightly", true},
{"Nightly", "Nightly", true},
}

for _, cas := range cases {
Expand Down
4 changes: 2 additions & 2 deletions tests/tiup-cluster/script/cmd_subtest.sh
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,9 @@ function cmd_subtest() {
tiup-cluster exec $name -N n3 --command "grep /home/tidb/my_kv_data /home/tidb/deploy/tikv-20160/scripts/run_tikv.sh"

# test patch overwrite
tiup-cluster $client --yes patch $name ~/.tiup/storage/cluster/packages/tidb-$version-linux-amd64.tar.gz -R tidb --overwrite
tiup-cluster $client --yes patch $name ~/.tiup/storage/cluster/packages/tidb-v$version-linux-amd64.tar.gz -R tidb --overwrite
# overwrite with the same tarball twice
tiup-cluster $client --yes patch $name ~/.tiup/storage/cluster/packages/tidb-$version-linux-amd64.tar.gz -R tidb --overwrite
tiup-cluster $client --yes patch $name ~/.tiup/storage/cluster/packages/tidb-v$version-linux-amd64.tar.gz -R tidb --overwrite

tiup-cluster $client --yes stop $name

Expand Down
4 changes: 2 additions & 2 deletions tests/tiup-cluster/test_cmd.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@ set -eu

source script/cmd_subtest.sh

echo "test cluster for verision v4.0.4 wo/ TLS, via easy ssh"
cmd_subtest v4.0.4 false false
echo "test cluster for verision v4.0.9 wo/ TLS, via easy ssh"
cmd_subtest 4.0.9 false false
4 changes: 2 additions & 2 deletions tests/tiup-cluster/test_cmd_tls_native_ssh.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ set -eu
source script/cmd_subtest.sh
export GO_FAILPOINTS='github.com/pingcap/tiup/pkg/cluster/executor/assertNativeSSH=return(true)'

echo "test cluster for verision v4.0.4 w/ TLS, via native ssh"
cmd_subtest v4.0.4 true true
echo "test cluster for verision v4.0.9 w/ TLS, via native ssh"
cmd_subtest v4.0.9 true true

unset GO_FAILPOINTS

0 comments on commit ad35eac

Please sign in to comment.