etcd_release_upgrade_test.go 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. // Copyright 2016 The etcd Authors
  2. //
  3. // Licensed under the Apache License, Version 2.0 (the "License");
  4. // you may not use this file except in compliance with the License.
  5. // You may obtain a copy of the License at
  6. //
  7. // http://www.apache.org/licenses/LICENSE-2.0
  8. //
  9. // Unless required by applicable law or agreed to in writing, software
  10. // distributed under the License is distributed on an "AS IS" BASIS,
  11. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. // See the License for the specific language governing permissions and
  13. // limitations under the License.
  14. package e2e
  15. import (
  16. "fmt"
  17. "os"
  18. "testing"
  19. "time"
  20. "github.com/coreos/etcd/pkg/fileutil"
  21. "github.com/coreos/etcd/pkg/testutil"
  22. )
  23. // TestReleaseUpgrade ensures that changes to master branch does not affect
  24. // upgrade from latest etcd releases.
  25. func TestReleaseUpgrade(t *testing.T) {
  26. lastReleaseBinary := "../bin/etcd-last-release"
  27. if !fileutil.Exist(lastReleaseBinary) {
  28. t.Skipf("%q does not exist", lastReleaseBinary)
  29. }
  30. defer testutil.AfterTest(t)
  31. copiedCfg := configNoTLS
  32. copiedCfg.execPath = lastReleaseBinary
  33. copiedCfg.snapCount = 3
  34. epc, err := newEtcdProcessCluster(&copiedCfg)
  35. if err != nil {
  36. t.Fatalf("could not start etcd process cluster (%v)", err)
  37. }
  38. defer func() {
  39. if errC := epc.Close(); errC != nil {
  40. t.Fatalf("error closing etcd processes (%v)", errC)
  41. }
  42. }()
  43. os.Setenv("ETCDCTL_API", "3")
  44. defer os.Unsetenv("ETCDCTL_API")
  45. cx := ctlCtx{
  46. t: t,
  47. cfg: configNoTLS,
  48. dialTimeout: 7 * time.Second,
  49. quorum: true,
  50. epc: epc,
  51. }
  52. var kvs []kv
  53. for i := 0; i < 5; i++ {
  54. kvs = append(kvs, kv{key: fmt.Sprintf("foo%d", i), val: "bar"})
  55. }
  56. for i := range kvs {
  57. if err := ctlV3Put(cx, kvs[i].key, kvs[i].val, ""); err != nil {
  58. cx.t.Fatalf("#%d: ctlV3Put error (%v)", i, err)
  59. }
  60. }
  61. for i := range epc.procs {
  62. if err := epc.procs[i].Stop(); err != nil {
  63. t.Fatalf("#%d: error closing etcd process (%v)", i, err)
  64. }
  65. epc.procs[i].cfg.execPath = "../bin/etcd"
  66. epc.procs[i].cfg.keepDataDir = true
  67. if err := epc.procs[i].Restart(); err != nil {
  68. t.Fatalf("error restarting etcd process (%v)", err)
  69. }
  70. for j := range kvs {
  71. if err := ctlV3Get(cx, []string{kvs[j].key}, []kv{kvs[j]}...); err != nil {
  72. cx.t.Fatalf("#%d-%d: ctlV3Get error (%v)", i, j, err)
  73. }
  74. }
  75. }
  76. }