-
Notifications
You must be signed in to change notification settings - Fork 9.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
e2e grpcproxy tests #8277
Merged
heyitsanthony
merged 11 commits into
etcd-io:master
from
heyitsanthony:test-e2e-grpcproxy
Jul 21, 2017
Merged
e2e grpcproxy tests #8277
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
5c6a6bd
e2e: refactor to support -tags cluster_proxy
heyitsanthony 7c22d35
etcdmain: support grpc-proxy/gateway compiled with -tags cov
heyitsanthony 426ad25
transport: include InsecureSkipVerify in TLSInfo
heyitsanthony 5d6c6ad
etcdmain: use client tls info for v2 proxy client connections
heyitsanthony d5a0d4d
etcdmain, embed: --auto-peer-tls and --auto-tls for v2 proxy
heyitsanthony 1365f87
etcdmain: cleanup grpcproxy; support different certs for proxy/etcd
heyitsanthony efbee9d
etcdmain: support --auto-tls and --insecure-skip-verify in grpcproxy
heyitsanthony c5447c2
etcdmain: support crl in grpcproxy
heyitsanthony 1dcae41
grpcproxy: return nil on receiving snapshot EOF
heyitsanthony 107828d
test: support -tags cluster_proxy for e2e tests
heyitsanthony 954ec4d
e2e: fix range indexing for args2env conversion
heyitsanthony File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
// Copyright 2017 The etcd Authors | ||
// | ||
// 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. | ||
|
||
// +build !cluster_proxy | ||
|
||
package e2e | ||
|
||
func newEtcdProcess(cfg *etcdServerProcessConfig) (etcdProcess, error) { | ||
return newEtcdServerProcess(cfg) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,278 @@ | ||
// Copyright 2017 The etcd Authors | ||
// | ||
// 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. | ||
|
||
// +build cluster_proxy | ||
|
||
package e2e | ||
|
||
import ( | ||
"fmt" | ||
"net" | ||
"net/url" | ||
"os" | ||
"strconv" | ||
"strings" | ||
|
||
"github.com/coreos/etcd/pkg/expect" | ||
) | ||
|
||
type proxyEtcdProcess struct { | ||
etcdProc etcdProcess | ||
proxyV2 *proxyV2Proc | ||
proxyV3 *proxyV3Proc | ||
} | ||
|
||
func newEtcdProcess(cfg *etcdServerProcessConfig) (etcdProcess, error) { | ||
return newProxyEtcdProcess(cfg) | ||
} | ||
|
||
func newProxyEtcdProcess(cfg *etcdServerProcessConfig) (*proxyEtcdProcess, error) { | ||
ep, err := newEtcdServerProcess(cfg) | ||
if err != nil { | ||
return nil, err | ||
} | ||
pep := &proxyEtcdProcess{ | ||
etcdProc: ep, | ||
proxyV2: newProxyV2Proc(cfg), | ||
proxyV3: newProxyV3Proc(cfg), | ||
} | ||
return pep, nil | ||
} | ||
|
||
func (p *proxyEtcdProcess) Config() *etcdServerProcessConfig { return p.etcdProc.Config() } | ||
|
||
func (p *proxyEtcdProcess) EndpointsV2() []string { return p.proxyV2.endpoints() } | ||
func (p *proxyEtcdProcess) EndpointsV3() []string { return p.proxyV3.endpoints() } | ||
|
||
func (p *proxyEtcdProcess) Start() error { | ||
if err := p.etcdProc.Start(); err != nil { | ||
return err | ||
} | ||
if err := p.proxyV2.Start(); err != nil { | ||
return err | ||
} | ||
return p.proxyV3.Start() | ||
} | ||
|
||
func (p *proxyEtcdProcess) Restart() error { | ||
if err := p.etcdProc.Restart(); err != nil { | ||
return err | ||
} | ||
if err := p.proxyV2.Restart(); err != nil { | ||
return err | ||
} | ||
return p.proxyV3.Restart() | ||
} | ||
|
||
func (p *proxyEtcdProcess) Stop() error { | ||
err := p.proxyV2.Stop() | ||
if v3err := p.proxyV3.Stop(); err == nil { | ||
err = v3err | ||
} | ||
if eerr := p.etcdProc.Stop(); eerr != nil && err == nil { | ||
// fails on go-grpc issue #1384 | ||
if !strings.Contains(eerr.Error(), "exit status 2") { | ||
err = eerr | ||
} | ||
} | ||
return err | ||
} | ||
|
||
func (p *proxyEtcdProcess) Close() error { | ||
err := p.proxyV2.Close() | ||
if v3err := p.proxyV3.Close(); err == nil { | ||
err = v3err | ||
} | ||
if eerr := p.etcdProc.Close(); eerr != nil && err == nil { | ||
// fails on go-grpc issue #1384 | ||
if !strings.Contains(eerr.Error(), "exit status 2") { | ||
err = eerr | ||
} | ||
} | ||
return err | ||
} | ||
|
||
func (p *proxyEtcdProcess) WithStopSignal(sig os.Signal) os.Signal { | ||
p.proxyV3.WithStopSignal(sig) | ||
p.proxyV3.WithStopSignal(sig) | ||
return p.etcdProc.WithStopSignal(sig) | ||
} | ||
|
||
type proxyProc struct { | ||
execPath string | ||
args []string | ||
ep string | ||
donec chan struct{} | ||
|
||
proc *expect.ExpectProcess | ||
} | ||
|
||
func (pp *proxyProc) endpoints() []string { return []string{pp.ep} } | ||
|
||
func (pp *proxyProc) start() error { | ||
if pp.proc != nil { | ||
panic("already started") | ||
} | ||
proc, err := spawnCmd(append([]string{pp.execPath}, pp.args...)) | ||
if err != nil { | ||
return err | ||
} | ||
pp.proc = proc | ||
return nil | ||
} | ||
|
||
func (pp *proxyProc) waitReady(readyStr string) error { | ||
defer close(pp.donec) | ||
return waitReadyExpectProc(pp.proc, []string{readyStr}) | ||
} | ||
|
||
func (pp *proxyProc) Stop() error { | ||
if pp.proc == nil { | ||
return nil | ||
} | ||
if err := pp.proc.Stop(); err != nil && !strings.Contains(err.Error(), "exit status 1") { | ||
// v2proxy exits with status 1 on auto tls; not sure why | ||
return err | ||
} | ||
pp.proc = nil | ||
<-pp.donec | ||
pp.donec = make(chan struct{}) | ||
return nil | ||
} | ||
|
||
func (pp *proxyProc) WithStopSignal(sig os.Signal) os.Signal { | ||
ret := pp.proc.StopSignal | ||
pp.proc.StopSignal = sig | ||
return ret | ||
} | ||
|
||
func (pp *proxyProc) Close() error { return pp.Stop() } | ||
|
||
type proxyV2Proc struct { | ||
proxyProc | ||
dataDir string | ||
} | ||
|
||
func proxyListenURL(cfg *etcdServerProcessConfig, portOffset int) string { | ||
u, err := url.Parse(cfg.acurl) | ||
if err != nil { | ||
panic(err) | ||
} | ||
host, port, _ := net.SplitHostPort(u.Host) | ||
p, _ := strconv.ParseInt(port, 10, 16) | ||
u.Host = fmt.Sprintf("%s:%d", host, int(p)+portOffset) | ||
return u.String() | ||
} | ||
|
||
func newProxyV2Proc(cfg *etcdServerProcessConfig) *proxyV2Proc { | ||
listenAddr := proxyListenURL(cfg, 2) | ||
name := fmt.Sprintf("testname-proxy-%p", cfg) | ||
args := []string{ | ||
"--name", name, | ||
"--proxy", "on", | ||
"--listen-client-urls", listenAddr, | ||
"--initial-cluster", cfg.name + "=" + cfg.purl.String(), | ||
} | ||
return &proxyV2Proc{ | ||
proxyProc{ | ||
execPath: cfg.execPath, | ||
args: append(args, cfg.tlsArgs...), | ||
ep: listenAddr, | ||
donec: make(chan struct{}), | ||
}, | ||
name + ".etcd", | ||
} | ||
} | ||
|
||
func (v2p *proxyV2Proc) Start() error { | ||
os.RemoveAll(v2p.dataDir) | ||
if err := v2p.start(); err != nil { | ||
return err | ||
} | ||
return v2p.waitReady("httpproxy: endpoints found") | ||
} | ||
|
||
func (v2p *proxyV2Proc) Restart() error { | ||
if err := v2p.Stop(); err != nil { | ||
return err | ||
} | ||
return v2p.Start() | ||
} | ||
|
||
func (v2p *proxyV2Proc) Stop() error { | ||
if err := v2p.proxyProc.Stop(); err != nil { | ||
return err | ||
} | ||
// v2 proxy caches members; avoid reuse of directory | ||
return os.RemoveAll(v2p.dataDir) | ||
} | ||
|
||
type proxyV3Proc struct { | ||
proxyProc | ||
} | ||
|
||
func newProxyV3Proc(cfg *etcdServerProcessConfig) *proxyV3Proc { | ||
listenAddr := proxyListenURL(cfg, 3) | ||
args := []string{ | ||
"grpc-proxy", | ||
"start", | ||
"--listen-addr", strings.Split(listenAddr, "/")[2], | ||
"--endpoints", cfg.acurl, | ||
// pass-through member RPCs | ||
"--advertise-client-url", "", | ||
} | ||
tlsArgs := []string{} | ||
for i := 0; i < len(cfg.tlsArgs); i++ { | ||
switch cfg.tlsArgs[i] { | ||
case "--cert-file": | ||
tlsArgs = append(tlsArgs, "--cert", cfg.tlsArgs[i+1], "--cert-file", cfg.tlsArgs[i+1]) | ||
i++ | ||
case "--key-file": | ||
tlsArgs = append(tlsArgs, "--key", cfg.tlsArgs[i+1], "--key-file", cfg.tlsArgs[i+1]) | ||
i++ | ||
case "--ca-file": | ||
tlsArgs = append(tlsArgs, "--cacert", cfg.tlsArgs[i+1], "--trusted-ca-file", cfg.tlsArgs[i+1]) | ||
i++ | ||
case "--auto-tls": | ||
tlsArgs = append(tlsArgs, "--auto-tls", "--insecure-skip-tls-verify") | ||
case "--peer-ca-file", "--peer-cert-file", "--peer-key-file": | ||
i++ // skip arg | ||
case "--client-cert-auth", "--peer-auto-tls": | ||
default: | ||
tlsArgs = append(tlsArgs, cfg.tlsArgs[i]) | ||
} | ||
} | ||
return &proxyV3Proc{ | ||
proxyProc{ | ||
execPath: cfg.execPath, | ||
args: append(args, tlsArgs...), | ||
ep: listenAddr, | ||
donec: make(chan struct{}), | ||
}, | ||
} | ||
} | ||
|
||
func (v3p *proxyV3Proc) Restart() error { | ||
if err := v3p.Stop(); err != nil { | ||
return err | ||
} | ||
return v3p.Start() | ||
} | ||
|
||
func (v3p *proxyV3Proc) Start() error { | ||
if err := v3p.start(); err != nil { | ||
return err | ||
} | ||
return v3p.waitReady("listening for grpc-proxy client requests") | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why do we have duplicate flags
"--cert-file", cfg.tlsArgs[i+1]
(for etcd) inetcd grpc-proxy
command?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
--cert is proxy <-> etcd (in grpcproxy already), --cert-file is client <-> proxy (new)