v1_migration_test.go 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. package test
  2. import (
  3. "fmt"
  4. "io/ioutil"
  5. "os"
  6. "os/exec"
  7. "path/filepath"
  8. "testing"
  9. "time"
  10. "github.com/coreos/etcd/tests"
  11. "github.com/stretchr/testify/assert"
  12. )
  13. // Ensure that we can start a v2 node from the log of a v1 node.
  14. func TestV1SoloMigration(t *testing.T) {
  15. path, _ := ioutil.TempDir("", "etcd-")
  16. os.MkdirAll(path, 0777)
  17. defer os.RemoveAll(path)
  18. nodepath := filepath.Join(path, "node0")
  19. fixturepath, _ := filepath.Abs("../fixtures/v1.solo/node0")
  20. // Copy over fixture files.
  21. c := exec.Command("cp", "-rf", fixturepath, nodepath)
  22. if out, err := c.CombinedOutput(); err != nil {
  23. fmt.Println(">>>>>>\n", string(out), "<<<<<<")
  24. panic("Fixture initialization error:" + err.Error())
  25. }
  26. procAttr := new(os.ProcAttr)
  27. procAttr.Files = []*os.File{nil, os.Stdout, os.Stderr}
  28. args := []string{"etcd", fmt.Sprintf("-d=%s", nodepath)}
  29. args = append(args, "-c", "127.0.0.1:4001")
  30. args = append(args, "-s", "127.0.0.1:7001")
  31. process, err := os.StartProcess(EtcdBinPath, args, procAttr)
  32. if err != nil {
  33. t.Fatal("start process failed:" + err.Error())
  34. return
  35. }
  36. defer process.Kill()
  37. time.Sleep(time.Second)
  38. time.Sleep(120 * time.Second)
  39. // Ensure deleted message is removed.
  40. resp, err := tests.Get("http://localhost:4001/v2/keys/message")
  41. tests.ReadBody(resp)
  42. assert.Nil(t, err, "")
  43. assert.Equal(t, resp.StatusCode, 404, "")
  44. // Ensure TTL'd message is removed.
  45. resp, err = tests.Get("http://localhost:4001/v2/keys/foo")
  46. tests.ReadBody(resp)
  47. assert.Nil(t, err, "")
  48. assert.Equal(t, resp.StatusCode, 404, "")
  49. }
  50. // Ensure that we can start a v2 cluster from the logs of a v1 cluster.
  51. func TestV1ClusterMigration(t *testing.T) {
  52. path, _ := ioutil.TempDir("", "etcd-")
  53. os.RemoveAll(path)
  54. defer os.RemoveAll(path)
  55. nodes := []string{"node0", "node2"}
  56. for i, node := range nodes {
  57. nodepath := filepath.Join(path, node)
  58. fixturepath, _ := filepath.Abs(filepath.Join("../fixtures/v1.cluster/", node))
  59. fmt.Println("FIXPATH =", fixturepath)
  60. fmt.Println("NODEPATH =", nodepath)
  61. os.MkdirAll(filepath.Dir(nodepath), 0777)
  62. // Copy over fixture files.
  63. c := exec.Command("cp", "-rf", fixturepath, nodepath)
  64. if out, err := c.CombinedOutput(); err != nil {
  65. fmt.Println(">>>>>>\n", string(out), "<<<<<<")
  66. panic("Fixture initialization error:" + err.Error())
  67. }
  68. procAttr := new(os.ProcAttr)
  69. procAttr.Files = []*os.File{nil, os.Stdout, os.Stderr}
  70. args := []string{"etcd", fmt.Sprintf("-d=%s", nodepath)}
  71. args = append(args, "-c", fmt.Sprintf("127.0.0.1:%d", 4001 + i))
  72. args = append(args, "-s", fmt.Sprintf("127.0.0.1:%d", 7001 + i))
  73. process, err := os.StartProcess(EtcdBinPath, args, procAttr)
  74. if err != nil {
  75. t.Fatal("start process failed:" + err.Error())
  76. return
  77. }
  78. defer process.Kill()
  79. time.Sleep(time.Second)
  80. }
  81. time.Sleep(120 * time.Second)
  82. // Ensure deleted message is removed.
  83. resp, err := tests.Get("http://localhost:4001/v2/keys/message")
  84. tests.ReadBody(resp)
  85. assert.Nil(t, err, "")
  86. assert.Equal(t, resp.StatusCode, 404, "")
  87. // Ensure TTL'd message is removed.
  88. resp, err = tests.Get("http://localhost:4001/v2/keys/foo")
  89. tests.ReadBody(resp)
  90. assert.Nil(t, err, "")
  91. assert.Equal(t, resp.StatusCode, 404, "")
  92. }