2016-05-13 06:51:48 +03:00
|
|
|
// Copyright 2016 The etcd Authors
|
2016-04-14 21:42:57 +03:00
|
|
|
//
|
|
|
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
// you may not use this file except in compliance with the License.
|
|
|
|
// You may obtain a copy of the License at
|
|
|
|
//
|
|
|
|
// http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
//
|
|
|
|
// Unless required by applicable law or agreed to in writing, software
|
|
|
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
// See the License for the specific language governing permissions and
|
|
|
|
// limitations under the License.
|
|
|
|
|
|
|
|
package e2e
|
|
|
|
|
|
|
|
import (
|
2017-08-02 03:40:26 +03:00
|
|
|
"context"
|
|
|
|
"fmt"
|
2016-04-14 21:42:57 +03:00
|
|
|
"net/url"
|
|
|
|
"testing"
|
2017-08-02 03:40:26 +03:00
|
|
|
"time"
|
|
|
|
|
2018-08-29 03:13:25 +03:00
|
|
|
"go.etcd.io/etcd/clientv3"
|
2016-04-14 21:42:57 +03:00
|
|
|
)
|
|
|
|
|
|
|
|
func TestCtlV3EndpointHealth(t *testing.T) { testCtl(t, endpointHealthTest, withQuorum()) }
|
|
|
|
func TestCtlV3EndpointStatus(t *testing.T) { testCtl(t, endpointStatusTest, withQuorum()) }
|
2017-08-02 03:40:26 +03:00
|
|
|
func TestCtlV3EndpointHashKV(t *testing.T) { testCtl(t, endpointHashKVTest, withQuorum()) }
|
2016-04-14 21:42:57 +03:00
|
|
|
|
|
|
|
func endpointHealthTest(cx ctlCtx) {
|
|
|
|
if err := ctlV3EndpointHealth(cx); err != nil {
|
|
|
|
cx.t.Fatalf("endpointStatusTest ctlV3EndpointHealth error (%v)", err)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func ctlV3EndpointHealth(cx ctlCtx) error {
|
|
|
|
cmdArgs := append(cx.PrefixArgs(), "endpoint", "health")
|
|
|
|
lines := make([]string, cx.epc.cfg.clusterSize)
|
|
|
|
for i := range lines {
|
|
|
|
lines[i] = "is healthy"
|
|
|
|
}
|
|
|
|
return spawnWithExpects(cmdArgs, lines...)
|
|
|
|
}
|
|
|
|
|
|
|
|
func endpointStatusTest(cx ctlCtx) {
|
|
|
|
if err := ctlV3EndpointStatus(cx); err != nil {
|
|
|
|
cx.t.Fatalf("endpointStatusTest ctlV3EndpointStatus error (%v)", err)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func ctlV3EndpointStatus(cx ctlCtx) error {
|
|
|
|
cmdArgs := append(cx.PrefixArgs(), "endpoint", "status")
|
|
|
|
var eps []string
|
2017-07-15 02:03:04 +03:00
|
|
|
for _, ep := range cx.epc.EndpointsV3() {
|
2016-04-14 21:42:57 +03:00
|
|
|
u, _ := url.Parse(ep)
|
|
|
|
eps = append(eps, u.Host)
|
|
|
|
}
|
|
|
|
return spawnWithExpects(cmdArgs, eps...)
|
|
|
|
}
|
2017-08-02 03:40:26 +03:00
|
|
|
|
|
|
|
func endpointHashKVTest(cx ctlCtx) {
|
|
|
|
if err := ctlV3EndpointHashKV(cx); err != nil {
|
|
|
|
cx.t.Fatalf("endpointHashKVTest ctlV3EndpointHashKV error (%v)", err)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func ctlV3EndpointHashKV(cx ctlCtx) error {
|
|
|
|
eps := cx.epc.EndpointsV3()
|
|
|
|
|
|
|
|
// get latest hash to compare
|
|
|
|
cli, err := clientv3.New(clientv3.Config{
|
|
|
|
Endpoints: eps,
|
|
|
|
DialTimeout: 3 * time.Second,
|
|
|
|
})
|
|
|
|
if err != nil {
|
|
|
|
cx.t.Fatal(err)
|
|
|
|
}
|
|
|
|
defer cli.Close()
|
|
|
|
hresp, err := cli.HashKV(context.TODO(), eps[0], 0)
|
|
|
|
if err != nil {
|
|
|
|
cx.t.Fatal(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
cmdArgs := append(cx.PrefixArgs(), "endpoint", "hashkv")
|
|
|
|
var ss []string
|
|
|
|
for _, ep := range cx.epc.EndpointsV3() {
|
|
|
|
u, _ := url.Parse(ep)
|
|
|
|
ss = append(ss, fmt.Sprintf("%s, %d", u.Host, hresp.Hash))
|
|
|
|
}
|
|
|
|
return spawnWithExpects(cmdArgs, ss...)
|
|
|
|
}
|