Skip to content
/ etcd Public
forked from etcd-io/etcd

Commit

Permalink
e2e: add 'TestReleaseUpgradeV2ToV3'
Browse files Browse the repository at this point in the history
To test etcd-io#6309.
  • Loading branch information
gyuho committed Aug 30, 2016
1 parent 9bb0b51 commit 32aba9a
Show file tree
Hide file tree
Showing 3 changed files with 90 additions and 6 deletions.
2 changes: 1 addition & 1 deletion e2e/etcd_config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ func TestEtcdExampleConfig(t *testing.T) {
if err != nil {
t.Fatal(err)
}
if err = waitReadyExpectProc(proc, false); err != nil {
if err = waitReadyExpectProc(proc, false, false); err != nil {
t.Fatal(err)
}
if err = proc.Stop(); err != nil {
Expand Down
56 changes: 56 additions & 0 deletions e2e/etcd_release_upgrade_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ package e2e
import (
"fmt"
"os"
"sync"
"testing"
"time"

Expand Down Expand Up @@ -86,3 +87,58 @@ func TestReleaseUpgrade(t *testing.T) {
}
}
}

func TestReleaseUpgradeV2ToV3(t *testing.T) {
lastReleaseBinary := binDir + "/etcd-last-release-v2.3"
if !fileutil.Exist(lastReleaseBinary) {
t.Skipf("%q does not exist", lastReleaseBinary)
}

defer testutil.AfterTest(t)

copiedCfg := configNoTLS
copiedCfg.execPath = lastReleaseBinary
copiedCfg.snapCount = 3
copiedCfg.isV2Migrate = true

epc, err := newEtcdProcessCluster(&copiedCfg)
if err != nil {
t.Fatalf("could not start etcd process cluster (%v)", err)
}
defer func() {
if errC := epc.Close(); errC != nil {
t.Fatalf("error closing etcd processes (%v)", errC)
}
}()

var kvs []kv
for i := 0; i < 10; i++ {
kvs = append(kvs, kv{key: fmt.Sprintf("foo%d", i), val: "bar"})
}
for i := range kvs {
if err := etcdctlSet(epc, kvs[i].key, kvs[i].val); err != nil {
t.Fatalf("#%d: etcdctlSet error (%v)", i, err)
}
}

for i := range epc.procs {
if err := epc.procs[i].Stop(); err != nil {
t.Fatalf("#%d: error closing etcd process (%v)", i, err)
}
epc.procs[i].cfg.execPath = binDir + "/etcd"
epc.procs[i].cfg.keepDataDir = true
epc.procs[i].cfg.isV2Migrate = false
}

var wg sync.WaitGroup
wg.Add(len(epc.procs))
for i := range epc.procs {
go func(i int) {
if err := epc.procs[i].Restart(); err != nil {
t.Fatalf("error restarting etcd process (%v)", err)
}
wg.Done()
}(i)
}
wg.Wait()
}
38 changes: 33 additions & 5 deletions e2e/etcd_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -126,8 +126,10 @@ type etcdProcess struct {
}

type etcdProcessConfig struct {
execPath string
args []string
execPath string
isV2Migrate bool

args []string

dataDirPath string
keepDataDir bool
Expand All @@ -145,6 +147,8 @@ type etcdProcessConfig struct {

type etcdProcessClusterConfig struct {
execPath string
isV2Migrate bool

dataDirPath string
keepDataDir bool

Expand Down Expand Up @@ -201,7 +205,18 @@ func newEtcdProcess(cfg *etcdProcessConfig) (*etcdProcess, error) {
}
}

child, err := spawnCmd(append([]string{cfg.execPath}, cfg.args...))
var nargs []string
if !cfg.isV2Migrate { // remove deprecated flags
for _, arg := range cfg.args {
if !strings.HasPrefix(arg, "--experimental") {
nargs = append(nargs, arg)
}
}
} else {
nargs = cfg.args
}

child, err := spawnCmd(append([]string{cfg.execPath}, nargs...))
if err != nil {
return nil, err
}
Expand All @@ -215,6 +230,10 @@ func (cfg *etcdProcessClusterConfig) etcdProcessConfigs() []*etcdProcessConfig {
privateKeyPath = certDir + "/server.key.insecure"
caPath = certDir + "/ca.crt"

if !cfg.isV2Migrate && strings.HasSuffix(cfg.execPath, "last-release-v2.3") {
panic("could not run v2.3 binary")
}

if cfg.basePort == 0 {
cfg.basePort = etcdProcessBasePort
}
Expand Down Expand Up @@ -245,6 +264,7 @@ func (cfg *etcdProcessClusterConfig) etcdProcessConfigs() []*etcdProcessConfig {
var curl, curltls string
port := cfg.basePort + 2*i
curlHost := fmt.Sprintf("localhost:%d", port)
grpcHost := fmt.Sprintf("localhost:%d", port-200)

switch cfg.clientTLS {
case clientNonTLS, clientTLS:
Expand Down Expand Up @@ -289,10 +309,15 @@ func (cfg *etcdProcessClusterConfig) etcdProcessConfigs() []*etcdProcessConfig {
if cfg.noStrictReconfig {
args = append(args, "--strict-reconfig-check=false")
}
if cfg.isV2Migrate {
args = append(args, "--experimental-v3demo=true")
args = append(args, "--experimental-gRPC-addr="+grpcHost)
}

args = append(args, cfg.tlsArgs()...)
etcdCfgs[i] = &etcdProcessConfig{
execPath: cfg.execPath,
isV2Migrate: cfg.isV2Migrate,
args: args,
dataDirPath: dataDirPath,
keepDataDir: cfg.keepDataDir,
Expand Down Expand Up @@ -451,14 +476,17 @@ func (ep *etcdProcess) Stop() error {

func (ep *etcdProcess) waitReady() error {
defer close(ep.donec)
return waitReadyExpectProc(ep.proc, ep.cfg.isProxy)
return waitReadyExpectProc(ep.proc, ep.cfg.isProxy, ep.cfg.isV2Migrate)
}

func waitReadyExpectProc(exproc *expect.ExpectProcess, isProxy bool) error {
func waitReadyExpectProc(exproc *expect.ExpectProcess, isProxy, isV2 bool) error {
readyStrs := []string{"enabled capabilities for version", "published"}
if isProxy {
readyStrs = []string{"httpproxy: endpoints found"}
}
if isV2 {
readyStrs = []string{"published"}
}
c := 0
matchSet := func(l string) bool {
for _, s := range readyStrs {
Expand Down

0 comments on commit 32aba9a

Please sign in to comment.