v1_migration_test.go 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  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. fmt.Println("DATA_DIR =", nodepath)
  21. // Copy over fixture files.
  22. c := exec.Command("cp", "-rf", fixturepath, nodepath)
  23. if out, err := c.CombinedOutput(); err != nil {
  24. fmt.Println(">>>>>>\n", string(out), "<<<<<<")
  25. panic("Fixture initialization error:" + err.Error())
  26. }
  27. procAttr := new(os.ProcAttr)
  28. procAttr.Files = []*os.File{nil, os.Stdout, os.Stderr}
  29. args := []string{"etcd", fmt.Sprintf("-d=%s", nodepath)}
  30. args = append(args, "-c", "127.0.0.1:4001")
  31. args = append(args, "-s", "127.0.0.1:7001")
  32. process, err := os.StartProcess(EtcdBinPath, args, procAttr)
  33. if err != nil {
  34. t.Fatal("start process failed:" + err.Error())
  35. return
  36. }
  37. defer process.Kill()
  38. time.Sleep(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, 200, "")
  44. }
  45. // Ensure that we can start a v2 cluster from the logs of a v1 cluster.
  46. func TestV1ClusterMigration(t *testing.T) {
  47. path, _ := ioutil.TempDir("", "etcd-")
  48. os.RemoveAll(path)
  49. defer os.RemoveAll(path)
  50. nodes := []string{"node0", "node2"}
  51. for i, node := range nodes {
  52. nodepath := filepath.Join(path, node)
  53. fixturepath, _ := filepath.Abs(filepath.Join("../fixtures/v1.cluster/", node))
  54. fmt.Println("FIXPATH =", fixturepath)
  55. fmt.Println("NODEPATH =", nodepath)
  56. os.MkdirAll(filepath.Dir(nodepath), 0777)
  57. // Copy over fixture files.
  58. c := exec.Command("cp", "-rf", fixturepath, nodepath)
  59. if out, err := c.CombinedOutput(); err != nil {
  60. fmt.Println(">>>>>>\n", string(out), "<<<<<<")
  61. panic("Fixture initialization error:" + err.Error())
  62. }
  63. procAttr := new(os.ProcAttr)
  64. procAttr.Files = []*os.File{nil, os.Stdout, os.Stderr}
  65. args := []string{"etcd", fmt.Sprintf("-d=%s", nodepath)}
  66. args = append(args, "-c", fmt.Sprintf("127.0.0.1:%d", 4001 + i))
  67. args = append(args, "-s", fmt.Sprintf("127.0.0.1:%d", 7001 + i))
  68. process, err := os.StartProcess(EtcdBinPath, args, procAttr)
  69. if err != nil {
  70. t.Fatal("start process failed:" + err.Error())
  71. return
  72. }
  73. defer process.Kill()
  74. time.Sleep(time.Second)
  75. }
  76. // Ensure deleted message is removed.
  77. resp, err := tests.Get("http://localhost:4001/v2/keys/message")
  78. body := tests.ReadBody(resp)
  79. assert.Nil(t, err, "")
  80. assert.Equal(t, resp.StatusCode, 400, )
  81. assert.Equal(t, string(body), `{"errorCode":100,"message":"Key Not Found","cause":"/message","index":11}`+"\n")
  82. // Ensure TTL'd message is removed.
  83. resp, err = tests.Get("http://localhost:4001/v2/keys/foo")
  84. body = tests.ReadBody(resp)
  85. assert.Nil(t, err, "")
  86. assert.Equal(t, resp.StatusCode, 200, "")
  87. assert.Equal(t, string(body), `{"action":"get","key":"/foo","value":"one","modifiedIndex":9}`)
  88. }