Merge "veyron/services/mgmt/device/impl: fix shell expansion of TIMESTAMP"
diff --git a/lib/flags/flags.go b/lib/flags/flags.go
index 634e688..b2c767e 100644
--- a/lib/flags/flags.go
+++ b/lib/flags/flags.go
@@ -240,7 +240,7 @@
// group with the supplied flag.FlagSet.
func createAndRegisterListenFlags(fs *flag.FlagSet) *ListenFlags {
f := &ListenFlags{
- protocol: TCPProtocolFlag{"tcp"},
+ protocol: TCPProtocolFlag{"wsh"},
addresses: ipHostPortFlagVar{validator: IPHostPortFlag{Port: "0"}},
}
f.addresses.flags = f
diff --git a/lib/flags/flags_test.go b/lib/flags/flags_test.go
index a1e163c..6ec6e37 100644
--- a/lib/flags/flags_test.go
+++ b/lib/flags/flags_test.go
@@ -220,26 +220,31 @@
if got, want := len(lf.Addrs), 1; got != want {
t.Errorf("got %d, want %d", got, want)
}
- def := struct{ Protocol, Address string }{"tcp", ":0"}
+
+ // Test the default protocol and address is "wsh" and ":0".
+ def := struct{ Protocol, Address string }{"wsh", ":0"}
if got, want := lf.Addrs[0], def; !reflect.DeepEqual(got, want) {
t.Errorf("got %v, want %v", got, want)
}
fl = flags.CreateAndRegister(flag.NewFlagSet("test", flag.ContinueOnError), flags.Listen)
if err := fl.Parse([]string{
- "--veyron.tcp.address=172.0.0.1:10", "--veyron.tcp.protocol=ws", "--veyron.tcp.address=127.0.0.10:34", "--veyron.tcp.protocol=tcp6", "--veyron.tcp.address=172.0.0.100:100"}, nil); err != nil {
+ "--veyron.tcp.address=172.0.0.1:10", // Will default to protocol "wsh".
+ "--veyron.tcp.protocol=tcp", "--veyron.tcp.address=127.0.0.10:34",
+ "--veyron.tcp.protocol=ws4", "--veyron.tcp.address=127.0.0.10:44",
+ "--veyron.tcp.protocol=tcp6", "--veyron.tcp.address=172.0.0.100:100"}, nil); err != nil {
t.Fatalf("unexpected error: %s", err)
}
lf = fl.ListenFlags()
- if got, want := len(lf.Addrs), 3; got != want {
+ if got, want := len(lf.Addrs), 4; got != want {
t.Errorf("got %d, want %d", got, want)
}
- for i, p := range []string{"tcp", "ws", "tcp6"} {
+ for i, p := range []string{"wsh", "tcp", "ws4", "tcp6"} {
if got, want := lf.Addrs[i].Protocol, p; got != want {
t.Errorf("got %q, want %q", got, want)
}
}
- for i, p := range []string{"172.0.0.1:10", "127.0.0.10:34", "172.0.0.100:100"} {
+ for i, p := range []string{"172.0.0.1:10", "127.0.0.10:34", "127.0.0.10:44", "172.0.0.100:100"} {
if got, want := lf.Addrs[i].Address, p; got != want {
t.Errorf("got %q, want %q", got, want)
}
@@ -249,14 +254,18 @@
func TestDuplicateFlags(t *testing.T) {
fl := flags.CreateAndRegister(flag.NewFlagSet("test", flag.ContinueOnError), flags.Listen)
if err := fl.Parse([]string{
- "--veyron.tcp.address=172.0.0.1:10", "--veyron.tcp.address=172.0.0.1:10", "--veyron.tcp.address=172.0.0.1:34", "--veyron.tcp.protocol=ws", "--veyron.tcp.address=172.0.0.1:10", "--veyron.tcp.address=172.0.0.1:34", "--veyron.tcp.address=172.0.0.1:34"}, nil); err != nil {
+ "--veyron.tcp.address=172.0.0.1:10", "--veyron.tcp.address=172.0.0.1:10", "--veyron.tcp.address=172.0.0.1:34",
+ "--veyron.tcp.protocol=tcp", "--veyron.tcp.address=172.0.0.1:10", "--veyron.tcp.address=172.0.0.1:10", "--veyron.tcp.address=172.0.0.1:34",
+ "--veyron.tcp.protocol=ws", "--veyron.tcp.address=172.0.0.1:10", "--veyron.tcp.address=172.0.0.1:34", "--veyron.tcp.address=172.0.0.1:34"}, nil); err != nil {
t.Fatalf("unexpected error: %s", err)
}
lf := fl.ListenFlags()
- if got, want := len(lf.Addrs), 4; got != want {
+ if got, want := len(lf.Addrs), 6; got != want {
t.Errorf("got %d, want %d", got, want)
}
expected := flags.ListenAddrs{
+ {"wsh", "172.0.0.1:10"},
+ {"wsh", "172.0.0.1:34"},
{"tcp", "172.0.0.1:10"},
{"tcp", "172.0.0.1:34"},
{"ws", "172.0.0.1:10"},
@@ -266,10 +275,12 @@
t.Fatalf("got %#v, want %#v", got, want)
}
if err := fl.Parse([]string{
- "--veyron.tcp.address=172.0.0.1:10", "--veyron.tcp.address=172.0.0.1:10", "--veyron.tcp.address=172.0.0.1:34", "--veyron.tcp.protocol=ws", "--veyron.tcp.address=172.0.0.1:10", "--veyron.tcp.address=127.0.0.1:34", "--veyron.tcp.address=127.0.0.1:34"}, nil); err != nil {
+ "--veyron.tcp.address=172.0.0.1:10", "--veyron.tcp.address=172.0.0.1:10", "--veyron.tcp.address=172.0.0.1:34",
+ "--veyron.tcp.protocol=tcp", "--veyron.tcp.address=172.0.0.1:10", "--veyron.tcp.address=127.0.0.1:34", "--veyron.tcp.address=127.0.0.1:34",
+ "--veyron.tcp.protocol=ws", "--veyron.tcp.address=172.0.0.1:10", "--veyron.tcp.address=127.0.0.1:34", "--veyron.tcp.address=127.0.0.1:34"}, nil); err != nil {
t.Fatalf("unexpected error: %s", err)
}
- if got, want := len(lf.Addrs), 4; got != want {
+ if got, want := len(lf.Addrs), 6; got != want {
t.Errorf("got %d, want %d", got, want)
}
if got, want := lf.Addrs, expected; !reflect.DeepEqual(got, want) {
diff --git a/lib/flags/listen.go b/lib/flags/listen.go
index 1812fe4..344bae4 100644
--- a/lib/flags/listen.go
+++ b/lib/flags/listen.go
@@ -6,8 +6,8 @@
"strconv"
)
-// TCPProtocolFlag implements flag.Value to provide validation of the
-// command line values passed to it: tcp, tcp4 or tcp6, ws, ws4 and ws6
+// TCPProtocolFlag implements flag.Value to provide validation of the command
+// line values passed to it: tcp, tcp4, tcp6, ws, ws4, ws6, wsh, wsh4, and wsh6
// being the only allowed values.
type TCPProtocolFlag struct{ Protocol string }
@@ -19,7 +19,7 @@
// Implements flag.Value.Set
func (t *TCPProtocolFlag) Set(s string) error {
switch s {
- case "tcp", "tcp4", "tcp6", "ws", "ws4", "ws6":
+ case "tcp", "tcp4", "tcp6", "ws", "ws4", "ws6", "wsh", "wsh4", "wsh6":
t.Protocol = s
return nil
default:
diff --git a/lib/modules/core/core_test.go b/lib/modules/core/core_test.go
index 64eeabb..e5071c2 100644
--- a/lib/modules/core/core_test.go
+++ b/lib/modules/core/core_test.go
@@ -10,6 +10,7 @@
"testing"
"time"
+ "v.io/core/veyron2"
"v.io/core/veyron2/vlog"
"v.io/core/veyron/lib/expect"
@@ -18,7 +19,6 @@
"v.io/core/veyron/lib/modules/core"
"v.io/core/veyron/lib/testutil"
_ "v.io/core/veyron/profiles"
- "v.io/core/veyron2/rt"
)
func TestCommands(t *testing.T) {
@@ -38,11 +38,9 @@
// TODO(cnicolaou): add test for proxyd
func newShell(t *testing.T) (*modules.Shell, func()) {
- runtime, err := rt.New()
- if err != nil {
- panic(err)
- }
- sh, err := modules.NewShell(runtime.NewContext(), nil)
+ ctx, shutdown := veyron2.Init()
+
+ sh, err := modules.NewShell(ctx, nil)
if err != nil {
t.Fatalf("unexpected error: %s", err)
}
@@ -53,7 +51,7 @@
} else {
sh.Cleanup(nil, nil)
}
- runtime.Cleanup()
+ shutdown()
}
}
diff --git a/lib/modules/core/echo.go b/lib/modules/core/echo.go
index 34c11b8..92160b9 100644
--- a/lib/modules/core/echo.go
+++ b/lib/modules/core/echo.go
@@ -8,7 +8,6 @@
"v.io/core/veyron2"
"v.io/core/veyron2/ipc"
- "v.io/core/veyron2/rt"
"v.io/core/veyron2/security"
"v.io/core/veyron/lib/modules"
@@ -48,12 +47,8 @@
}
func echoServer(stdin io.Reader, stdout, stderr io.Writer, env map[string]string, args ...string) error {
- runtime, err := rt.New()
- if err != nil {
- panic(err)
- }
- defer runtime.Cleanup()
- ctx := runtime.NewContext()
+ ctx, shutdown := veyron2.Init()
+ defer shutdown()
fl, args, err := parseListenFlags(args)
if err != nil {
@@ -85,12 +80,8 @@
}
func echoClient(stdin io.Reader, stdout, stderr io.Writer, env map[string]string, args ...string) error {
- runtime, err := rt.New()
- if err != nil {
- panic(err)
- }
- defer runtime.Cleanup()
- ctx := runtime.NewContext()
+ ctx, shutdown := veyron2.Init()
+ defer shutdown()
args = args[1:]
name := args[0]
diff --git a/lib/modules/core/mounttable.go b/lib/modules/core/mounttable.go
index b549b65..6046c91 100644
--- a/lib/modules/core/mounttable.go
+++ b/lib/modules/core/mounttable.go
@@ -8,7 +8,6 @@
"v.io/core/veyron2"
"v.io/core/veyron2/options"
- "v.io/core/veyron2/rt"
"v.io/core/veyron/lib/modules"
mounttable "v.io/core/veyron/services/mounttable/lib"
@@ -32,12 +31,8 @@
}
func runMT(root bool, stdin io.Reader, stdout, stderr io.Writer, env map[string]string, args ...string) error {
- r, err := rt.New()
- if err != nil {
- panic(err)
- }
- defer r.Cleanup()
- ctx := r.NewContext()
+ ctx, shutdown := veyron2.Init()
+ defer shutdown()
fl, args, err := parseListenFlags(args)
if err != nil {
@@ -75,13 +70,8 @@
}
func ls(stdin io.Reader, stdout, stderr io.Writer, env map[string]string, args ...string) error {
- r, err := rt.New()
- if err != nil {
- panic(err)
- }
- defer r.Cleanup()
-
- ctx := r.NewContext()
+ ctx, shutdown := veyron2.Init()
+ defer shutdown()
details := false
args = args[1:] // skip over command name
diff --git a/lib/modules/core/proxy.go b/lib/modules/core/proxy.go
index 00d1977..f137cf8 100644
--- a/lib/modules/core/proxy.go
+++ b/lib/modules/core/proxy.go
@@ -8,7 +8,6 @@
"v.io/core/veyron2"
"v.io/core/veyron2/naming"
- "v.io/core/veyron2/rt"
"v.io/core/veyron/lib/modules"
"v.io/core/veyron/runtimes/google/ipc/stream/proxy"
@@ -20,11 +19,8 @@
}
func proxyServer(stdin io.Reader, stdout, stderr io.Writer, env map[string]string, args ...string) error {
- r, err := rt.New()
- if err != nil {
- panic(err)
- }
- ctx := r.NewContext()
+ ctx, shutdown := veyron2.Init()
+ defer shutdown()
fl, args, err := parseListenFlags(args)
if err != nil {
@@ -46,7 +42,6 @@
fmt.Fprintf(stdout, "PID=%d\n", os.Getpid())
fmt.Fprintf(stdout, "PROXY_NAME=%s\n", proxy.Endpoint().Name())
if expected > 0 {
- defer r.Cleanup()
pub := publisher.New(ctx, veyron2.GetNamespace(ctx), time.Minute)
defer pub.WaitForStop()
defer pub.Stop()
diff --git a/lib/modules/core/test_identityd.go b/lib/modules/core/test_identityd.go
index 8951102..f1bc19a 100644
--- a/lib/modules/core/test_identityd.go
+++ b/lib/modules/core/test_identityd.go
@@ -8,7 +8,7 @@
"strconv"
"time"
- "v.io/core/veyron2/rt"
+ "v.io/core/veyron2"
"v.io/core/veyron/lib/flags"
"v.io/core/veyron/lib/modules"
@@ -87,12 +87,9 @@
caveats.NewMockCaveatSelector())
l := initListenSpec(ifl)
- r, err := rt.New()
- if err != nil {
- return fmt.Errorf("rt.New() failed: %v", err)
- }
- defer r.Cleanup()
- ctx := r.NewContext()
+
+ ctx, shutdown := veyron2.Init()
+ defer shutdown()
_, veyronEPs, externalHttpaddress := s.Listen(ctx, &l, *host, *httpaddr, *tlsconfig)
diff --git a/lib/modules/examples_test.go b/lib/modules/examples_test.go
index ee78224..2784a03 100644
--- a/lib/modules/examples_test.go
+++ b/lib/modules/examples_test.go
@@ -6,6 +6,7 @@
"os"
"v.io/core/veyron/lib/modules"
+ "v.io/core/veyron2"
)
func init() {
@@ -20,6 +21,8 @@
}
func ExampleDispatch() {
+ ctx, shutdown := veyron2.Init()
+ defer shutdown()
if modules.IsModulesProcess() {
// Child process. Dispatch will invoke the 'echo' command
if err := modules.Dispatch(); err != nil {
@@ -28,7 +31,7 @@
return
}
// Parent process.
- sh, _ := modules.NewShell(runtime.NewContext(), nil)
+ sh, _ := modules.NewShell(ctx, nil)
defer sh.Cleanup(nil, nil)
h, _ := sh.Start("echo", nil, "a", "b")
h.Shutdown(os.Stdout, os.Stderr)
@@ -39,9 +42,11 @@
}
func ExampleDispatchAndExit() {
+ ctx, shutdown := veyron2.Init()
+ defer shutdown()
// DispatchAndExit will call os.Exit(0) when executed within the child.
modules.DispatchAndExit()
- sh, _ := modules.NewShell(runtime.NewContext(), nil)
+ sh, _ := modules.NewShell(ctx, nil)
defer sh.Cleanup(nil, nil)
h, _ := sh.Start("echo", nil, "c", "d")
h.Shutdown(os.Stdout, os.Stderr)
diff --git a/lib/modules/modules_internal_test.go b/lib/modules/modules_internal_test.go
index 3c26937..d3f9328 100644
--- a/lib/modules/modules_internal_test.go
+++ b/lib/modules/modules_internal_test.go
@@ -9,7 +9,7 @@
_ "v.io/core/veyron/profiles"
- "v.io/core/veyron2/rt"
+ "v.io/core/veyron2"
)
func Echo(stdin io.Reader, stdout, stderr io.Writer, env map[string]string, args ...string) error {
@@ -30,12 +30,10 @@
}
func TestState(t *testing.T) {
- r, err := rt.New()
- if err != nil {
- panic(err)
- }
- defer r.Cleanup()
- sh, err := NewShell(r.NewContext(), nil)
+ ctx, shutdown := veyron2.Init()
+ defer shutdown()
+
+ sh, err := NewShell(ctx, nil)
if err != nil {
t.Fatalf("unexpected error: %s", err)
}
diff --git a/lib/modules/modules_test.go b/lib/modules/modules_test.go
index 1f4e311..b92a696 100644
--- a/lib/modules/modules_test.go
+++ b/lib/modules/modules_test.go
@@ -21,13 +21,10 @@
_ "v.io/core/veyron/profiles"
"v.io/core/veyron2"
- "v.io/core/veyron2/rt"
)
const credentialsEnvPrefix = "\"" + consts.VeyronCredentials + "="
-var runtime veyron2.Runtime
-
func init() {
testutil.Init()
modules.RegisterChild("envtest", "envtest: <variables to print>...", PrintFromEnv)
@@ -40,11 +37,6 @@
modules.RegisterFunction("envtestf", "envtest: <variables to print>...", PrintFromEnv)
modules.RegisterFunction("echof", "[args]*", Echo)
modules.RegisterFunction("errortestFunc", "", ErrorMain)
- var err error
- runtime, err = rt.New()
- if err != nil {
- panic(err)
- }
}
func ignoresStdin(io.Reader, io.Writer, io.Writer, map[string]string, ...string) error {
@@ -61,7 +53,10 @@
}
func PrintBlessing(stdin io.Reader, stdout, stderr io.Writer, env map[string]string, args ...string) error {
- blessing := veyron2.GetPrincipal(runtime.NewContext()).BlessingStore().Default()
+ ctx, shutdown := veyron2.Init()
+ defer shutdown()
+
+ blessing := veyron2.GetPrincipal(ctx).BlessingStore().Default()
fmt.Fprintf(stdout, "%s", blessing)
return nil
}
@@ -159,7 +154,10 @@
}
func TestChild(t *testing.T) {
- sh, err := modules.NewShell(runtime.NewContext(), nil)
+ ctx, shutdown := veyron2.Init()
+ defer shutdown()
+
+ sh, err := modules.NewShell(ctx, nil)
if err != nil {
t.Fatalf("unexpected error: %s", err)
}
@@ -170,7 +168,10 @@
}
func TestAgent(t *testing.T) {
- sh, err := modules.NewShell(runtime.NewContext(), nil)
+ ctx, shutdown := veyron2.Init()
+ defer shutdown()
+
+ sh, err := modules.NewShell(ctx, nil)
if err != nil {
t.Fatalf("unexpected error: %s", err)
}
@@ -180,7 +181,7 @@
if a != b {
t.Errorf("Expected same blessing for children, got %s and %s", a, b)
}
- sh2, err := modules.NewShell(runtime.NewContext(), nil)
+ sh2, err := modules.NewShell(ctx, nil)
if err != nil {
t.Fatalf("unexpected error: %s", err)
}
@@ -192,9 +193,12 @@
}
func TestCustomPrincipal(t *testing.T) {
+ ctx, shutdown := veyron2.Init()
+ defer shutdown()
+
p := security.NewPrincipal("myshell")
cleanDebug := p.BlessingStore().DebugString()
- sh, err := modules.NewShell(runtime.NewContext(), p)
+ sh, err := modules.NewShell(ctx, p)
if err != nil {
t.Fatalf("unexpected error: %s", err)
}
@@ -224,7 +228,10 @@
}
func TestChildNoRegistration(t *testing.T) {
- sh, err := modules.NewShell(runtime.NewContext(), nil)
+ ctx, shutdown := veyron2.Init()
+ defer shutdown()
+
+ sh, err := modules.NewShell(ctx, nil)
if err != nil {
t.Fatalf("unexpected error: %s", err)
}
@@ -239,7 +246,10 @@
}
func TestFunction(t *testing.T) {
- sh, err := modules.NewShell(runtime.NewContext(), nil)
+ ctx, shutdown := veyron2.Init()
+ defer shutdown()
+
+ sh, err := modules.NewShell(ctx, nil)
if err != nil {
t.Fatalf("unexpected error: %s", err)
}
@@ -250,7 +260,10 @@
}
func TestErrorChild(t *testing.T) {
- sh, err := modules.NewShell(runtime.NewContext(), nil)
+ ctx, shutdown := veyron2.Init()
+ defer shutdown()
+
+ sh, err := modules.NewShell(ctx, nil)
if err != nil {
t.Fatalf("unexpected error: %s", err)
}
@@ -290,7 +303,10 @@
}
func TestShutdownSubprocess(t *testing.T) {
- sh, err := modules.NewShell(runtime.NewContext(), nil)
+ ctx, shutdown := veyron2.Init()
+ defer shutdown()
+
+ sh, err := modules.NewShell(ctx, nil)
if err != nil {
t.Fatalf("unexpected error: %s", err)
}
@@ -302,7 +318,10 @@
// forever if a child does not die upon closing stdin; but instead times out and
// returns an appropriate error.
func TestShutdownSubprocessIgnoresStdin(t *testing.T) {
- sh, err := modules.NewShell(runtime.NewContext(), nil)
+ ctx, shutdown := veyron2.Init()
+ defer shutdown()
+
+ sh, err := modules.NewShell(ctx, nil)
if err != nil {
t.Fatalf("unexpected error: %s", err)
}
@@ -327,7 +346,10 @@
// implementation inappropriately sets stdout to the file that is to be closed
// in Wait.
func TestStdoutRace(t *testing.T) {
- sh, err := modules.NewShell(runtime.NewContext(), nil)
+ ctx, shutdown := veyron2.Init()
+ defer shutdown()
+
+ sh, err := modules.NewShell(ctx, nil)
if err != nil {
t.Fatalf("unexpected error: %s", err)
}
@@ -359,7 +381,10 @@
}
func TestShutdownFunction(t *testing.T) {
- sh, err := modules.NewShell(runtime.NewContext(), nil)
+ ctx, shutdown := veyron2.Init()
+ defer shutdown()
+
+ sh, err := modules.NewShell(ctx, nil)
if err != nil {
t.Fatalf("unexpected error: %s", err)
}
@@ -368,7 +393,10 @@
}
func TestErrorFunc(t *testing.T) {
- sh, err := modules.NewShell(runtime.NewContext(), nil)
+ ctx, shutdown := veyron2.Init()
+ defer shutdown()
+
+ sh, err := modules.NewShell(ctx, nil)
if err != nil {
t.Fatalf("unexpected error: %s", err)
}
@@ -392,7 +420,10 @@
}
func TestEnvelope(t *testing.T) {
- sh, err := modules.NewShell(runtime.NewContext(), nil)
+ ctx, shutdown := veyron2.Init()
+ defer shutdown()
+
+ sh, err := modules.NewShell(ctx, nil)
if err != nil {
t.Fatalf("unexpected error: %s", err)
}
@@ -444,7 +475,10 @@
}
func TestEnvMerge(t *testing.T) {
- sh, err := modules.NewShell(runtime.NewContext(), nil)
+ ctx, shutdown := veyron2.Init()
+ defer shutdown()
+
+ sh, err := modules.NewShell(ctx, nil)
if err != nil {
t.Fatalf("unexpected error: %s", err)
}
diff --git a/lib/modules/shell.go b/lib/modules/shell.go
index 6ed18d4..c80aae7 100644
--- a/lib/modules/shell.go
+++ b/lib/modules/shell.go
@@ -150,11 +150,14 @@
return nil, err
}
defer cancel()
+ syscall.ForkLock.RLock()
fd, err := syscall.Dup(int(conn.Fd()))
if err != nil {
+ syscall.ForkLock.RUnlock()
return nil, err
}
syscall.CloseOnExec(fd)
+ syscall.ForkLock.RUnlock()
p, err := agent.NewAgentPrincipal(ctx, fd, veyron2.GetClient(ctx))
if err != nil {
return nil, err
diff --git a/lib/signals/signals_test.go b/lib/signals/signals_test.go
index 21d3430..83f3438 100644
--- a/lib/signals/signals_test.go
+++ b/lib/signals/signals_test.go
@@ -16,8 +16,8 @@
"v.io/core/veyron2/ipc"
"v.io/core/veyron2/mgmt"
"v.io/core/veyron2/naming"
- "v.io/core/veyron2/rt"
"v.io/core/veyron2/services/mgmt/appcycle"
+ "v.io/core/veyron2/vtrace"
"v.io/core/veyron/lib/expect"
"v.io/core/veyron/lib/modules"
@@ -54,19 +54,14 @@
}
func program(stdin io.Reader, stdout io.Writer, signals ...os.Signal) {
- runtime, err := rt.New()
- if err != nil {
- panic(err)
- }
-
- ctx := runtime.NewContext()
+ ctx, shutdown := veyron2.Init()
closeStopLoop := make(chan struct{})
go stopLoop(ctx, stdin, closeStopLoop)
wait := ShutdownOnSignals(ctx, signals...)
fmt.Fprintf(stdout, "ready\n")
fmt.Fprintf(stdout, "received signal %s\n", <-wait)
- runtime.Cleanup()
+ shutdown()
<-closeStopLoop
}
@@ -86,13 +81,8 @@
}
func handleDefaultsIgnoreChan(stdin io.Reader, stdout, stderr io.Writer, env map[string]string, args ...string) error {
- runtime, err := rt.New()
- if err != nil {
- panic(err)
- }
- defer runtime.Cleanup()
-
- ctx := runtime.NewContext()
+ ctx, shutdown := veyron2.Init()
+ defer shutdown()
closeStopLoop := make(chan struct{})
go stopLoop(ctx, stdin, closeStopLoop)
@@ -123,8 +113,8 @@
}
}
-func newShell(t *testing.T, r veyron2.Runtime, command string) (*modules.Shell, modules.Handle, *expect.Session) {
- sh, err := modules.NewShell(r.NewContext(), nil)
+func newShell(t *testing.T, ctx *context.T, command string) (*modules.Shell, modules.Handle, *expect.Session) {
+ sh, err := modules.NewShell(ctx, nil)
if err != nil {
t.Fatalf("unexpected error: %s", err)
}
@@ -141,12 +131,10 @@
// TestCleanShutdownSignal verifies that sending a signal to a child that
// handles it by default causes the child to shut down cleanly.
func TestCleanShutdownSignal(t *testing.T) {
- runtime, err := rt.New()
- if err != nil {
- panic(err)
- }
- defer runtime.Cleanup()
- sh, h, s := newShell(t, runtime, "handleDefaults")
+ ctx, shutdown := veyron2.Init()
+ defer shutdown()
+
+ sh, h, s := newShell(t, ctx, "handleDefaults")
defer sh.Cleanup(os.Stderr, os.Stderr)
s.Expect("ready")
checkSignalIsDefault(t, syscall.SIGINT)
@@ -159,12 +147,10 @@
// TestCleanShutdownStop verifies that sending a stop comamnd to a child that
// handles stop commands by default causes the child to shut down cleanly.
func TestCleanShutdownStop(t *testing.T) {
- runtime, err := rt.New()
- if err != nil {
- panic(err)
- }
- defer runtime.Cleanup()
- sh, h, s := newShell(t, runtime, "handleDefaults")
+ ctx, shutdown := veyron2.Init()
+ defer shutdown()
+
+ sh, h, s := newShell(t, ctx, "handleDefaults")
defer sh.Cleanup(os.Stderr, os.Stderr)
s.Expect("ready")
fmt.Fprintf(h.Stdin(), "stop\n")
@@ -178,12 +164,10 @@
// that handles stop command as part of a custom set of signals handled, causes
// the child to shut down cleanly.
func TestCleanShutdownStopCustom(t *testing.T) {
- runtime, err := rt.New()
- if err != nil {
- panic(err)
- }
- defer runtime.Cleanup()
- sh, h, s := newShell(t, runtime, "handleCustomWithStop")
+ ctx, shutdown := veyron2.Init()
+ defer shutdown()
+
+ sh, h, s := newShell(t, ctx, "handleCustomWithStop")
defer sh.Cleanup(os.Stderr, os.Stderr)
s.Expect("ready")
fmt.Fprintf(h.Stdin(), "stop\n")
@@ -204,12 +188,10 @@
// TestStopNoHandler verifies that sending a stop command to a child that does
// not handle stop commands causes the child to exit immediately.
func TestStopNoHandler(t *testing.T) {
- runtime, err := rt.New()
- if err != nil {
- panic(err)
- }
- defer runtime.Cleanup()
- sh, h, s := newShell(t, runtime, "handleCustom")
+ ctx, shutdown := veyron2.Init()
+ defer shutdown()
+
+ sh, h, s := newShell(t, ctx, "handleCustom")
defer sh.Cleanup(os.Stderr, os.Stderr)
s.Expect("ready")
fmt.Fprintf(h.Stdin(), "stop\n")
@@ -220,12 +202,10 @@
// that handles these signals by default causes the child to exit immediately
// upon receiving the second signal.
func TestDoubleSignal(t *testing.T) {
- runtime, err := rt.New()
- if err != nil {
- panic(err)
- }
- defer runtime.Cleanup()
- sh, h, s := newShell(t, runtime, "handleDefaults")
+ ctx, shutdown := veyron2.Init()
+ defer shutdown()
+
+ sh, h, s := newShell(t, ctx, "handleDefaults")
defer sh.Cleanup(os.Stderr, os.Stderr)
s.Expect("ready")
checkSignalIsDefault(t, syscall.SIGTERM)
@@ -240,12 +220,10 @@
// to a child that handles these by default causes the child to exit immediately
// upon receiving the stop command.
func TestSignalAndStop(t *testing.T) {
- runtime, err := rt.New()
- if err != nil {
- panic(err)
- }
- defer runtime.Cleanup()
- sh, h, s := newShell(t, runtime, "handleDefaults")
+ ctx, shutdown := veyron2.Init()
+ defer shutdown()
+
+ sh, h, s := newShell(t, ctx, "handleDefaults")
defer sh.Cleanup(os.Stderr, os.Stderr)
s.Expect("ready")
checkSignalIsDefault(t, syscall.SIGTERM)
@@ -259,12 +237,10 @@
// that handles stop commands by default causes the child to exit immediately
// upon receiving the second stop command.
func TestDoubleStop(t *testing.T) {
- runtime, err := rt.New()
- if err != nil {
- panic(err)
- }
- defer runtime.Cleanup()
- sh, h, s := newShell(t, runtime, "handleDefaults")
+ ctx, shutdown := veyron2.Init()
+ defer shutdown()
+
+ sh, h, s := newShell(t, ctx, "handleDefaults")
defer sh.Cleanup(os.Stderr, os.Stderr)
s.Expect("ready")
fmt.Fprintf(h.Stdin(), "stop\n")
@@ -276,12 +252,10 @@
// TestSendUnhandledSignal verifies that sending a signal that the child does
// not handle causes the child to exit as per the signal being sent.
func TestSendUnhandledSignal(t *testing.T) {
- runtime, err := rt.New()
- if err != nil {
- panic(err)
- }
- defer runtime.Cleanup()
- sh, h, s := newShell(t, runtime, "handleDefaults")
+ ctx, shutdown := veyron2.Init()
+ defer shutdown()
+
+ sh, h, s := newShell(t, ctx, "handleDefaults")
defer sh.Cleanup(os.Stderr, os.Stderr)
s.Expect("ready")
checkSignalIsNotDefault(t, syscall.SIGABRT)
@@ -294,12 +268,10 @@
// process to exit (ensures that there is no dependency in ShutdownOnSignals
// on having a goroutine read from the returned channel).
func TestDoubleSignalIgnoreChan(t *testing.T) {
- runtime, err := rt.New()
- if err != nil {
- panic(err)
- }
- defer runtime.Cleanup()
- sh, h, s := newShell(t, runtime, "handleDefaultsIgnoreChan")
+ ctx, shutdown := veyron2.Init()
+ defer shutdown()
+
+ sh, h, s := newShell(t, ctx, "handleDefaultsIgnoreChan")
defer sh.Cleanup(os.Stderr, os.Stderr)
s.Expect("ready")
// Even if we ignore the channel that ShutdownOnSignals returns,
@@ -314,12 +286,10 @@
// TestHandlerCustomSignal verifies that sending a non-default signal to a
// server that listens for that signal causes the server to shut down cleanly.
func TestHandlerCustomSignal(t *testing.T) {
- runtime, err := rt.New()
- if err != nil {
- panic(err)
- }
- defer runtime.Cleanup()
- sh, h, s := newShell(t, runtime, "handleCustom")
+ ctx, shutdown := veyron2.Init()
+ defer shutdown()
+
+ sh, h, s := newShell(t, ctx, "handleCustom")
defer sh.Cleanup(os.Stderr, os.Stderr)
s.Expect("ready")
checkSignalIsNotDefault(t, syscall.SIGABRT)
@@ -333,13 +303,12 @@
// to a server that listens for that signal causes the server to shut down
// cleanly, even when a STOP signal is also among the handled signals.
func TestHandlerCustomSignalWithStop(t *testing.T) {
- runtime, err := rt.New()
- if err != nil {
- panic(err)
- }
- defer runtime.Cleanup()
+ rootCtx, shutdown := veyron2.Init()
+ defer shutdown()
+
for _, signal := range []syscall.Signal{syscall.SIGABRT, syscall.SIGHUP} {
- sh, h, s := newShell(t, runtime, "handleCustomWithStop")
+ ctx, _ := vtrace.SetNewTrace(rootCtx)
+ sh, h, s := newShell(t, ctx, "handleCustomWithStop")
s.Expect("ready")
checkSignalIsNotDefault(t, signal)
syscall.Kill(h.Pid(), signal)
@@ -395,14 +364,10 @@
// TestCleanRemoteShutdown verifies that remote shutdown works correctly.
func TestCleanRemoteShutdown(t *testing.T) {
- runtime, err := rt.New()
- if err != nil {
- panic(err)
- }
- defer runtime.Cleanup()
- ctx := runtime.NewContext()
+ ctx, shutdown := veyron2.Init()
+ defer shutdown()
- sh, err := modules.NewShell(runtime.NewContext(), nil)
+ sh, err := modules.NewShell(ctx, nil)
if err != nil {
t.Fatalf("unexpected error: %s", err)
}
diff --git a/lib/testutil/integration/util.go b/lib/testutil/integration/util.go
index 61de99d..335150d 100644
--- a/lib/testutil/integration/util.go
+++ b/lib/testutil/integration/util.go
@@ -40,8 +40,7 @@
"v.io/core/veyron/lib/modules"
"v.io/core/veyron/lib/modules/core"
tsecurity "v.io/core/veyron/lib/testutil/security"
- "v.io/core/veyron2/options"
- "v.io/core/veyron2/rt"
+ "v.io/core/veyron2"
"v.io/core/veyron2/security"
)
@@ -132,6 +131,9 @@
// The testing framework.
t *testing.T
+ // The function to shutdown the context used to create the environment.
+ shutdown veyron2.Shutdown
+
// The shell to use to start commands.
shell *modules.Shell
@@ -261,6 +263,8 @@
}
func (e *integrationTestEnvironment) Cleanup() {
+ e.shutdown()
+
for _, binary := range e.builtBinaries {
binary.cleanupFunc()
}
@@ -397,13 +401,16 @@
// ...
// }
func NewTestEnvironment(t *testing.T) TestEnvironment {
+ ctx, shutdown := veyron2.Init()
+
t.Log("creating root principal")
principal := tsecurity.NewPrincipal("root")
- runtime, err := rt.New(options.RuntimePrincipal{principal})
+ ctx, err := veyron2.SetPrincipal(ctx, principal)
if err != nil {
- t.Fatalf("rt.New() failed: %v", err)
+ t.Fatalf("failed to set principal: %v", err)
}
- shell, err := modules.NewShell(runtime.NewContext(), principal)
+
+ shell, err := modules.NewShell(ctx, principal)
if err != nil {
t.Fatalf("NewShell() failed: %v", err)
}
@@ -424,6 +431,7 @@
mtEndpoint: mtEndpoint,
tempFiles: []*os.File{},
tempDirs: []string{},
+ shutdown: shutdown,
}
}
diff --git a/lib/testutil/security/util_test.go b/lib/testutil/security/util_test.go
index 2057f54..440533a 100644
--- a/lib/testutil/security/util_test.go
+++ b/lib/testutil/security/util_test.go
@@ -7,7 +7,6 @@
"sort"
"testing"
- "v.io/core/veyron2/rt"
"v.io/core/veyron2/security"
"v.io/core/veyron2/services/security/access"
@@ -65,11 +64,6 @@
}
func TestSaveACLToFile(t *testing.T) {
- r, err := rt.New()
- if err != nil {
- t.Fatalf("rt.New failed: %v", err)
- }
- defer r.Cleanup()
acl := access.TaggedACLMap{
"Admin": access.ACL{
In: []security.BlessingPattern{"comics/..."},
diff --git a/lib/unixfd/unixfd.go b/lib/unixfd/unixfd.go
index 3611c7a..fd17a93 100644
--- a/lib/unixfd/unixfd.go
+++ b/lib/unixfd/unixfd.go
@@ -173,7 +173,7 @@
// Socketpair returns a pair of connected sockets for communicating with a child process.
func Socketpair() (*net.UnixConn, *os.File, error) {
- lfd, rfd, err := socketpair(false)
+ lfd, rfd, err := socketpair()
if err != nil {
return nil, nil, err
}
@@ -188,14 +188,12 @@
return conn.(*net.UnixConn), rfd.releaseFile(), nil
}
-func socketpair(closeRemoteOnExec bool) (local, remote *fileDescriptor, err error) {
+func socketpair() (local, remote *fileDescriptor, err error) {
syscall.ForkLock.RLock()
fds, err := syscall.Socketpair(syscall.AF_UNIX, syscall.SOCK_STREAM, 0)
if err == nil {
syscall.CloseOnExec(fds[0])
- if closeRemoteOnExec {
- syscall.CloseOnExec(fds[1])
- }
+ syscall.CloseOnExec(fds[1])
}
syscall.ForkLock.RUnlock()
if err != nil {
@@ -209,11 +207,11 @@
// the local end of the socketpair.
// Note that the returned address is an open file descriptor,
// which you must close if you do not Dial or Listen to the address.
-func SendConnection(conn *net.UnixConn, data []byte, closeOnExec bool) (addr net.Addr, err error) {
+func SendConnection(conn *net.UnixConn, data []byte) (addr net.Addr, err error) {
if len(data) < 1 {
return nil, errors.New("cannot send a socket without data.")
}
- remote, local, err := socketpair(closeOnExec)
+ remote, local, err := socketpair()
if err != nil {
return nil, err
}
diff --git a/lib/unixfd/unixfd_test.go b/lib/unixfd/unixfd_test.go
index e4c1678..801258c 100644
--- a/lib/unixfd/unixfd_test.go
+++ b/lib/unixfd/unixfd_test.go
@@ -46,7 +46,7 @@
}
func TestDial(t *testing.T) {
- local, remote, err := socketpair(true)
+ local, remote, err := socketpair()
if err != nil {
t.Fatalf("socketpair: %v", err)
}
@@ -79,7 +79,7 @@
}
func TestListen(t *testing.T) {
- local, remote, err := socketpair(true)
+ local, remote, err := socketpair()
if err != nil {
t.Fatalf("socketpair: %v", err)
}
@@ -149,7 +149,7 @@
}
close(done)
}()
- caddr, err := SendConnection(uclient.(*net.UnixConn), []byte("hello"), true)
+ caddr, err := SendConnection(uclient.(*net.UnixConn), []byte("hello"))
if err != nil {
t.Fatalf("SendConnection: %v", err)
}
diff --git a/profiles/roaming/net_watcher.go b/profiles/roaming/net_watcher.go
index 82348ea..607bcd4 100644
--- a/profiles/roaming/net_watcher.go
+++ b/profiles/roaming/net_watcher.go
@@ -8,21 +8,14 @@
"v.io/core/veyron2"
"v.io/core/veyron2/config"
- "v.io/core/veyron2/rt"
- "v.io/core/veyron2/vlog"
"v.io/core/veyron/lib/netstate"
"v.io/core/veyron/profiles/roaming"
)
func main() {
- r, err := rt.New()
- if err != nil {
- vlog.Fatalf("Could not initialize runtime: %s", err)
- }
- defer r.Cleanup()
-
- ctx := r.NewContext()
+ ctx, shutdown := veyron2.Init()
+ defer shutdown()
profileName := veyron2.GetProfile(ctx).Name()
fmt.Println("Profile: ", profileName)
@@ -31,14 +24,15 @@
routes := netstate.GetRoutes()
fmt.Printf("Routes:\n%s\n", strings.Replace(routes.String(), ")", ")\n", -1))
- chooser := roaming.ListenSpec.AddressChooser
+ listenSpec := veyron2.GetListenSpec(ctx)
+ chooser := listenSpec.AddressChooser
if chooser != nil {
if gce, err := chooser("", nil); err == nil {
fmt.Printf("%s: 1:1 NAT address is %s\n", profileName, gce)
}
}
- if chosen, err := roaming.ListenSpec.AddressChooser("tcp", accessible); err != nil {
+ if chosen, err := listenSpec.AddressChooser("tcp", accessible); err != nil {
fmt.Printf("Failed to chosen address %s\n", err)
} else {
al := netstate.AddrList(chosen)
diff --git a/profiles/roaming/roaming_server.go b/profiles/roaming/roaming_server.go
index e49caa8..e85f22e 100644
--- a/profiles/roaming/roaming_server.go
+++ b/profiles/roaming/roaming_server.go
@@ -5,29 +5,26 @@
import (
"fmt"
+ "v.io/core/veyron2"
"v.io/core/veyron2/ipc"
- "v.io/core/veyron2/rt"
- "v.io/core/veyron2/vlog"
"v.io/core/veyron/profiles/roaming"
)
func main() {
- r, err := rt.New()
- if err != nil {
- vlog.Fatalf("Could not initialize runtime: %s", err)
- }
- defer r.Cleanup()
- log := r.Logger()
+ ctx, shutdown := veyron2.Init()
+ defer shutdown()
+ log := veyron2.GetLogger(ctx)
- server, err := r.NewServer()
- defer server.Stop()
+ server, err := veyron2.NewServer(ctx)
if err != nil {
log.Fatalf("unexpected error: %q", err)
}
- fmt.Printf("listen spec: %v\n", roaming.ListenSpec)
- ep, err := server.Listen(roaming.ListenSpec)
+ listenSpec := veyron2.GetListenSpec(ctx)
+
+ fmt.Printf("listen spec: %v\n", listenSpec)
+ ep, err := server.Listen(listenSpec)
if err != nil {
log.Fatalf("unexpected error: %q", err)
}
diff --git a/profiles/static/staticinit.go b/profiles/static/staticinit.go
index a28ddab..57b7f2c 100644
--- a/profiles/static/staticinit.go
+++ b/profiles/static/staticinit.go
@@ -60,7 +60,11 @@
if err != nil {
return nil, nil, nil, err
}
- return runtime, ctx, shutdown, nil
+ profileShutdown := func() {
+ ac.Shutdown()
+ shutdown()
+ }
+ return runtime, ctx, profileShutdown, nil
}
}
listenSpec.AddressChooser = internal.IPAddressChooser
diff --git a/runtimes/google/ipc/benchmark/README.txt b/runtimes/google/ipc/benchmark/README.txt
index 9230cd2..bc076c6 100644
--- a/runtimes/google/ipc/benchmark/README.txt
+++ b/runtimes/google/ipc/benchmark/README.txt
@@ -53,7 +53,7 @@
the first RPC.
$ v23 go run bmserver/main.go \
- -veyron.tcp.address=localhost:8888 -acl='{"In":{"...":"R"}}'
+ -veyron.tcp.address=localhost:8888 -veyron.acl.literal='{"Read": {"In": ["..."]}}'
(In a different shell)
$ v23 go run bmclient/main.go \
diff --git a/runtimes/google/ipc/benchmark/benchmark_test.go b/runtimes/google/ipc/benchmark/benchmark_test.go
index 941a22d..f16eea1 100644
--- a/runtimes/google/ipc/benchmark/benchmark_test.go
+++ b/runtimes/google/ipc/benchmark/benchmark_test.go
@@ -6,20 +6,20 @@
"v.io/core/veyron/lib/testutil/benchmark"
tsecurity "v.io/core/veyron/lib/testutil/security"
- "v.io/core/veyron/profiles"
+ _ "v.io/core/veyron/profiles"
"v.io/core/veyron2"
- "v.io/core/veyron2/rt"
+ "v.io/core/veyron2/context"
)
var (
- vrt veyron2.Runtime
serverAddr string
+ ctx *context.T
)
// Benchmarks for non-streaming RPC.
func runEcho(b *testing.B, payloadSize int) {
- CallEcho(b, vrt.NewContext(), serverAddr, b.N, payloadSize, benchmark.AddStats(b, 16))
+ CallEcho(b, ctx, serverAddr, b.N, payloadSize, benchmark.AddStats(b, 16))
}
func Benchmark____1B(b *testing.B) { runEcho(b, 1) }
@@ -31,7 +31,7 @@
// Benchmarks for streaming RPC.
func runEchoStream(b *testing.B, chunkCnt, payloadSize int) {
- CallEchoStream(b, vrt.NewContext(), serverAddr, b.N, chunkCnt, payloadSize, benchmark.AddStats(b, 16))
+ CallEchoStream(b, ctx, serverAddr, b.N, chunkCnt, payloadSize, benchmark.AddStats(b, 16))
}
func Benchmark____1_chunk_____1B(b *testing.B) { runEchoStream(b, 1, 1) }
@@ -61,7 +61,7 @@
// Benchmarks for per-chunk throughput in streaming RPC.
func runPerChunk(b *testing.B, payloadSize int) {
- CallEchoStream(b, vrt.NewContext(), serverAddr, 1, b.N, payloadSize, benchmark.NewStats(1))
+ CallEchoStream(b, ctx, serverAddr, 1, b.N, payloadSize, benchmark.NewStats(1))
}
func Benchmark__per_chunk____1B(b *testing.B) { runPerChunk(b, 1) }
@@ -73,8 +73,8 @@
// Benchmarks for non-streaming RPC while running streaming RPC in background.
func runMux(b *testing.B, payloadSize, chunkCntB, payloadSizeB int) {
- _, stop := StartEchoStream(&testing.B{}, vrt.NewContext(), serverAddr, 0, chunkCntB, payloadSizeB, benchmark.NewStats(1))
- CallEcho(b, vrt.NewContext(), serverAddr, b.N, payloadSize, benchmark.AddStats(b, 16))
+ _, stop := StartEchoStream(&testing.B{}, ctx, serverAddr, 0, chunkCntB, payloadSizeB, benchmark.NewStats(1))
+ CallEcho(b, ctx, serverAddr, b.N, payloadSize, benchmark.AddStats(b, 16))
stop()
}
@@ -101,18 +101,18 @@
func TestNoOp(t *testing.T) {}
func TestMain(m *testing.M) {
+ // We do not use defer here since this program will exit at the end of
+ // this function through os.Exit().
+ var shutdown veyron2.Shutdown
+ ctx, shutdown = veyron2.Init()
+
var err error
- vrt, err = rt.New()
+ ctx, err = veyron2.SetPrincipal(ctx, tsecurity.NewPrincipal("test-blessing"))
if err != nil {
panic(err)
}
- ctx := vrt.NewContext()
- if ctx, err = veyron2.SetPrincipal(ctx, tsecurity.NewPrincipal("test-blessing")); err != nil {
- panic(err)
- }
- var serverStop func()
- serverAddr, serverStop = StartServer(ctx, profiles.LocalListenSpec)
+ serverAddr, serverStop := StartServer(ctx, veyron2.GetListenSpec(ctx))
// Create a VC to exclude the VC setup time from the benchmark.
CallEcho(&testing.B{}, ctx, serverAddr, 1, 0, benchmark.NewStats(1))
@@ -120,7 +120,7 @@
r := benchmark.RunTestMain(m)
serverStop()
- vrt.Cleanup()
+ shutdown()
os.Exit(r)
}
diff --git a/runtimes/google/ipc/benchmark/bmclient/main.go b/runtimes/google/ipc/benchmark/bmclient/main.go
index e6fc5d3..f3145cf 100644
--- a/runtimes/google/ipc/benchmark/bmclient/main.go
+++ b/runtimes/google/ipc/benchmark/bmclient/main.go
@@ -12,7 +12,7 @@
_ "v.io/core/veyron/profiles"
"v.io/core/veyron/runtimes/google/ipc/benchmark"
- "v.io/core/veyron2/rt"
+ "v.io/core/veyron2"
"v.io/core/veyron2/vlog"
)
@@ -28,15 +28,12 @@
)
func main() {
- vrt, err := rt.New()
- if err != nil {
- vlog.Fatalf("Could not initialize runtime: %s", err)
- }
- defer vrt.Cleanup()
+ ctx, shutdown := veyron2.Init()
+ defer shutdown()
if *chunkCntMux > 0 && *payloadSizeMux > 0 {
dummyB := testing.B{}
- _, stop := benchmark.StartEchoStream(&dummyB, vrt.NewContext(), *server, 0, *chunkCntMux, *payloadSizeMux, nil)
+ _, stop := benchmark.StartEchoStream(&dummyB, ctx, *server, 0, *chunkCntMux, *payloadSizeMux, nil)
defer stop()
vlog.Infof("Started background streaming (chunk_size=%d, payload_size=%d)", *chunkCntMux, *payloadSizeMux)
}
@@ -45,7 +42,6 @@
stats := tbm.NewStats(16)
now := time.Now()
- ctx := vrt.NewContext()
if *chunkCnt == 0 {
benchmark.CallEcho(&dummyB, ctx, *server, *iterations, *payloadSize, stats)
} else {
diff --git a/runtimes/google/ipc/benchmark/bmserver/main.go b/runtimes/google/ipc/benchmark/bmserver/main.go
index 9c3fcd8..416762c 100644
--- a/runtimes/google/ipc/benchmark/bmserver/main.go
+++ b/runtimes/google/ipc/benchmark/bmserver/main.go
@@ -6,18 +6,13 @@
"v.io/core/veyron/profiles/roaming"
"v.io/core/veyron/runtimes/google/ipc/benchmark"
- "v.io/core/veyron2/rt"
+ "v.io/core/veyron2"
"v.io/core/veyron2/vlog"
)
func main() {
- vrt, err := rt.New()
- if err != nil {
- vlog.Fatalf("Could not initialize runtime: %s", err)
- }
- defer vrt.Cleanup()
-
- ctx := vrt.NewContext()
+ ctx, shutdown := veyron2.Init()
+ defer shutdown()
addr, stop := benchmark.StartServer(ctx, roaming.ListenSpec)
vlog.Infof("Listening on %s", addr)
diff --git a/runtimes/google/ipc/benchmark/glob/glob_test.go b/runtimes/google/ipc/benchmark/glob/glob_test.go
index 951b16d..c8f1cf4 100644
--- a/runtimes/google/ipc/benchmark/glob/glob_test.go
+++ b/runtimes/google/ipc/benchmark/glob/glob_test.go
@@ -8,7 +8,6 @@
"v.io/core/veyron2/context"
"v.io/core/veyron2/ipc"
"v.io/core/veyron2/naming"
- "v.io/core/veyron2/rt"
"v.io/core/veyron2/security"
tsecurity "v.io/core/veyron/lib/testutil/security"
@@ -156,15 +155,12 @@
}
func RunBenchmarkGlob(b *testing.B, obj interface{}) {
- runtime, err := rt.New()
+ ctx, shutdown := veyron2.Init()
+ defer shutdown()
+ ctx, err := veyron2.SetPrincipal(ctx, tsecurity.NewPrincipal("test-blessing"))
if err != nil {
panic(err)
}
- defer runtime.Cleanup()
- ctx := runtime.NewContext()
- if ctx, err = veyron2.SetPrincipal(ctx, tsecurity.NewPrincipal("test-blessing")); err != nil {
- panic(err)
- }
addr, stop, err := startServer(b, ctx, obj)
if err != nil {
diff --git a/runtimes/google/ipc/benchmark/service.vdl.go b/runtimes/google/ipc/benchmark/service.vdl.go
index a09b115..a2a64ff 100644
--- a/runtimes/google/ipc/benchmark/service.vdl.go
+++ b/runtimes/google/ipc/benchmark/service.vdl.go
@@ -13,7 +13,7 @@
__veyron2 "v.io/core/veyron2"
__context "v.io/core/veyron2/context"
__ipc "v.io/core/veyron2/ipc"
- __vdlutil "v.io/core/veyron2/vdl/vdlutil"
+ __vdl "v.io/core/veyron2/vdl"
)
// BenchmarkClientMethods is the client interface
@@ -261,7 +261,7 @@
{"", ``}, // []byte
{"", ``}, // error
},
- Tags: []__vdlutil.Any{access.Tag("Read")},
+ Tags: []__vdl.AnyRep{access.Tag("Read")},
},
{
Name: "EchoStream",
@@ -269,7 +269,7 @@
OutArgs: []__ipc.ArgDesc{
{"", ``}, // error
},
- Tags: []__vdlutil.Any{access.Tag("Read")},
+ Tags: []__vdl.AnyRep{access.Tag("Read")},
},
},
}
diff --git a/runtimes/google/ipc/client.go b/runtimes/google/ipc/client.go
index 7c59e5d..9afb81d 100644
--- a/runtimes/google/ipc/client.go
+++ b/runtimes/google/ipc/client.go
@@ -17,7 +17,7 @@
"v.io/core/veyron2/naming"
"v.io/core/veyron2/options"
"v.io/core/veyron2/security"
- "v.io/core/veyron2/vdl/vdlutil"
+ "v.io/core/veyron2/vdl"
old_verror "v.io/core/veyron2/verror"
verror "v.io/core/veyron2/verror2"
"v.io/core/veyron2/vlog"
@@ -200,29 +200,6 @@
return flow, nil
}
-// connectFlow parses an endpoint and a suffix out of the server and establishes
-// a flow to the endpoint, returning the parsed suffix.
-// The server name passed in should be a rooted name, of the form "/ep/suffix" or
-// "/ep//suffix", or just "/ep".
-func (c *client) connectFlow(ctx *context.T, server string, vcOpts []stream.VCOpt) (stream.Flow, string, verror.E) {
- address, suffix := naming.SplitAddressName(server)
- if len(address) == 0 {
- return nil, "", verror.Make(errNonRootedName, ctx, server)
- }
- ep, err := inaming.NewEndpoint(address)
- if err != nil {
- return nil, "", verror.Make(errInvalidEndpoint, ctx, address)
- }
- if err = version.CheckCompatibility(ep); err != nil {
- return nil, "", verror.Make(errIncompatibleEndpoint, ctx, ep)
- }
- flow, verr := c.createFlow(ctx, ep, vcOpts)
- if verr != nil {
- return nil, "", verr
- }
- return flow, suffix, nil
-}
-
// A randomized exponential backoff. The randomness deters error convoys from forming.
// TODO(cnicolaou): rationalize this and the backoff in ipc.Server. Note
// that rand is not thread safe and may crash.
@@ -295,6 +272,15 @@
return
}
+func allowCancel(opts []ipc.CallOpt) bool {
+ for _, o := range opts {
+ if _, ok := o.(inaming.NoCancel); ok {
+ return false
+ }
+ }
+ return true
+}
+
func mkDischargeImpetus(serverBlessings []string, method string, args []interface{}) security.DischargeImpetus {
var impetus security.DischargeImpetus
if len(serverBlessings) > 0 {
@@ -305,9 +291,9 @@
}
impetus.Method = method
if len(args) > 0 {
- impetus.Arguments = make([]vdlutil.Any, len(args))
+ impetus.Arguments = make([]vdl.AnyRep, len(args))
for i, a := range args {
- impetus.Arguments[i] = vdlutil.Any(a)
+ impetus.Arguments[i] = vdl.AnyRep(a)
}
}
return impetus
@@ -373,32 +359,49 @@
err verror.E
}
+// tryCreateFlow attempts to establish a Flow to "server" (which must be a
+// rooted name), over which a method invocation request could be sent.
// TODO(cnicolaou): implement real, configurable load balancing.
-func (c *client) tryServer(ctx *context.T, index int, server string, ch chan<- *serverStatus, vcOpts []stream.VCOpt) {
+func (c *client) tryCreateFlow(ctx *context.T, index int, server string, ch chan<- *serverStatus, vcOpts []stream.VCOpt) {
status := &serverStatus{index: index}
- var err verror.E
var span vtrace.Span
- ctx, span = vtrace.SetNewSpan(ctx, "<client>connectFlow")
+ ctx, span = vtrace.SetNewSpan(ctx, "<client>tryCreateFlow")
span.Annotatef("address:%v", server)
- defer span.Finish()
- if status.flow, status.suffix, err = c.connectFlow(ctx, server, vcOpts); err != nil {
- vlog.VI(2).Infof("ipc: connect to %s: %s", server, err)
- status.err = err
- status.flow = nil
+ defer func() {
+ ch <- status
+ span.Finish()
+ }()
+ address, suffix := naming.SplitAddressName(server)
+ if len(address) == 0 {
+ status.err = verror.Make(errNonRootedName, ctx, server)
+ return
}
- ch <- status
+ ep, err := inaming.NewEndpoint(address)
+ if err != nil {
+ status.err = verror.Make(errInvalidEndpoint, ctx, address)
+ return
+ }
+ if err = version.CheckCompatibility(ep); err != nil {
+ status.err = verror.Make(errIncompatibleEndpoint, ctx, ep)
+ return
+ }
+ if status.flow, status.err = c.createFlow(ctx, ep, vcOpts); status.err != nil {
+ vlog.VI(2).Infof("ipc: connect to %v: %v", server, status.err)
+ return
+ }
+ status.suffix = suffix
+ return
}
-// tryCall makes a single attempt at a call, against possibly multiple servers.
+// tryCall makes a single attempt at a call. It may connect to multiple servers
+// (all that serve "name"), but will invoke the method on at most one of them
+// (the server running on the most preferred protcol and network amongst all
+// the servers that were successfully connected to and authorized).
func (c *client) tryCall(ctx *context.T, name, method string, args []interface{}, opts []ipc.CallOpt) (ipc.Call, verror.ActionCode, verror.E) {
- // Get CallOpts that are also VCOpts.
- vcOpts := getVCOpts(opts)
- // Get CallOpts that are also ResolveOpts.
- resolveOpts := getResolveOpts(opts)
- var servers []string
+ var resolved *naming.MountEntry
var pattern security.BlessingPattern
-
- if resolved, err := c.ns.Resolve(ctx, name, resolveOpts...); err != nil {
+ var err error
+ if resolved, err = c.ns.Resolve(ctx, name, getResolveOpts(opts)...); err != nil {
vlog.Errorf("Resolve: %v", err)
if verror.Is(err, naming.ErrNoSuchName.ID) {
return nil, verror.RetryRefetch, verror.Make(verror.NoServers, ctx, name)
@@ -410,36 +413,27 @@
return nil, verror.RetryRefetch, verror.Make(verror.NoServers, ctx, name)
}
// An empty set of protocols means all protocols...
- ordered, err := filterAndOrderServers(resolved.Names(), c.preferredProtocols)
- if err != nil {
+ if resolved.Servers, err = filterAndOrderServers(resolved.Servers, c.preferredProtocols); err != nil {
return nil, verror.RetryRefetch, verror.Make(verror.NoServers, ctx, name, err)
- } else if len(ordered) == 0 {
- // sooo annoying....
- r := []interface{}{err}
- r = append(r, name)
- for _, s := range resolved.Servers {
- r = append(r, s)
- }
- return nil, verror.RetryRefetch, verror.Make(verror.NoServers, ctx, r)
}
- servers = ordered
}
// servers is now orderd by the priority heurestic implemented in
// filterAndOrderServers.
- attempts := len(servers)
-
- // Try to connect to all servers in parallel. Provide sufficient buffering
- // for all of the connections to finish instantaneously. This is important
- // because we want to process the responses in priority order; that order is
- // indicated by the order of entries in servers. So, if two respones come in
- // at the same 'instant', we prefer the first in the slice.
+ //
+ // Try to connect to all servers in parallel. Provide sufficient
+ // buffering for all of the connections to finish instantaneously. This
+ // is important because we want to process the responses in priority
+ // order; that order is indicated by the order of entries in servers.
+ // So, if two respones come in at the same 'instant', we prefer the
+ // first in the resolved.Servers)
+ attempts := len(resolved.Servers)
responses := make([]*serverStatus, attempts)
ch := make(chan *serverStatus, attempts)
- vcOpts = append(vcOpts, c.vcOpts...)
+ vcOpts := append(getVCOpts(opts), c.vcOpts...)
vcOpts = append(vcOpts, vc.DialContext{ctx})
- for i, server := range servers {
- go c.tryServer(ctx, i, server, ch, vcOpts)
+ for i, server := range resolved.Names() {
+ go c.tryCreateFlow(ctx, i, server, ch, vcOpts)
}
delay := time.Duration(ipc.NoTimeout)
@@ -465,7 +459,7 @@
}
case <-timeoutChan:
vlog.VI(2).Infof("ipc: timeout on connection to server %v ", name)
- _, _, err := c.failedTryCall(ctx, name, method, servers, responses, ch)
+ _, _, err := c.failedTryCall(ctx, name, method, responses, ch)
if !verror.Is(err, verror.Timeout.ID) {
return nil, verror.NoRetry, verror.Make(verror.Timeout, ctx, err)
}
@@ -482,7 +476,12 @@
if r == nil || r.flow == nil {
continue
}
- r.flow.SetDeadline(ctx.Done())
+
+ var doneChan <-chan struct{}
+ if allowCancel(opts) {
+ doneChan = ctx.Done()
+ }
+ r.flow.SetDeadline(doneChan)
var (
serverB []string
@@ -495,8 +494,7 @@
// Validate caveats on the server's identity for the context associated with this call.
var err error
if serverB, grantedB, err = c.authorizeServer(ctx, r.flow, name, method, pattern, opts); err != nil {
- r.err = verror.Make(errNotTrusted, ctx,
- name, r.flow.RemoteBlessings(), err)
+ r.err = verror.Make(errNotTrusted, ctx, name, r.flow.RemoteBlessings(), err)
vlog.VI(2).Infof("ipc: err: %s", r.err)
r.flow.Close()
r.flow = nil
@@ -524,10 +522,10 @@
return nil, verror.NoRetry, err.(verror.E)
}
- if doneChan := ctx.Done(); doneChan != nil {
+ if doneChan != nil {
go func() {
select {
- case <-ctx.Done():
+ case <-doneChan:
vtrace.GetSpan(fc.ctx).Annotate("Cancelled")
fc.flow.Cancel()
case <-fc.flow.Closed():
@@ -548,12 +546,12 @@
return fc, verror.NoRetry, nil
}
if numResponses == len(responses) {
- return c.failedTryCall(ctx, name, method, servers, responses, ch)
+ return c.failedTryCall(ctx, name, method, responses, ch)
}
}
}
-// cleanupTryCall ensures we've waited for every response from the tryServer
+// cleanupTryCall ensures we've waited for every response from the tryCreateFlow
// goroutines, and have closed the flow from each one except skip. This is a
// blocking function; it should be called in its own goroutine.
func cleanupTryCall(skip *serverStatus, responses []*serverStatus, ch chan *serverStatus) {
@@ -582,13 +580,12 @@
// failedTryCall performs asynchronous cleanup for tryCall, and returns an
// appropriate error from the responses we've already received. All parallel
// calls in tryCall failed or we timed out if we get here.
-func (c *client) failedTryCall(ctx *context.T, name, method string, servers []string, responses []*serverStatus, ch chan *serverStatus) (ipc.Call, verror.ActionCode, verror.E) {
+func (c *client) failedTryCall(ctx *context.T, name, method string, responses []*serverStatus, ch chan *serverStatus) (ipc.Call, verror.ActionCode, verror.E) {
go cleanupTryCall(nil, responses, ch)
c.ns.FlushCacheEntry(name)
noconn, untrusted := []string{}, []string{}
- for i, r := range responses {
+ for _, r := range responses {
if r != nil && r.err != nil {
- vlog.VI(2).Infof("Server: %s: %s", servers[i], r.err)
switch {
case verror.Is(r.err, errNotTrusted.ID) || verror.Is(r.err, errAuthError.ID):
untrusted = append(untrusted, "("+r.err.Error()+") ")
@@ -732,7 +729,7 @@
blessingsRequest = clientEncodeBlessings(fc.flow.VCDataCache(), fc.blessings)
}
// TODO(suharshs, ataly): Make security.Discharge a vdl type.
- anyDischarges := make([]vdlutil.Any, len(fc.discharges))
+ anyDischarges := make([]vdl.AnyRep, len(fc.discharges))
for i, d := range fc.discharges {
anyDischarges[i] = d
}
diff --git a/runtimes/google/ipc/client_test.go b/runtimes/google/ipc/client_test.go
index 499c7bc..d9ebb6a 100644
--- a/runtimes/google/ipc/client_test.go
+++ b/runtimes/google/ipc/client_test.go
@@ -13,8 +13,6 @@
"v.io/core/veyron2"
"v.io/core/veyron2/context"
"v.io/core/veyron2/naming"
- "v.io/core/veyron2/options"
- "v.io/core/veyron2/rt"
verror "v.io/core/veyron2/verror2"
"v.io/core/veyron2/vlog"
@@ -32,17 +30,14 @@
}
func newCtx() (*context.T, veyron2.Shutdown) {
- r, err := rt.New()
+ ctx, shutdown := veyron2.Init()
+ ctx, err := veyron2.SetPrincipal(ctx, tsecurity.NewPrincipal("test-blessing"))
if err != nil {
panic(err)
}
- ctx := r.NewContext()
- if ctx, err = veyron2.SetPrincipal(ctx, tsecurity.NewPrincipal("test-blessing")); err != nil {
- panic(err)
- }
veyron2.GetNamespace(ctx).CacheCtl(naming.DisableCache(true))
- return ctx, r.Cleanup
+ return ctx, shutdown
}
func testArgs(args ...string) []string {
@@ -115,6 +110,7 @@
func TestMultipleEndpoints(t *testing.T) {
ctx, shutdown := newCtx()
defer shutdown()
+
sh, fn := runMountTable(t, ctx)
defer fn()
srv, err := sh.Start(core.EchoServerCommand, nil, testArgs("echoServer", "echoServer")...)
@@ -127,7 +123,7 @@
// Verify that there are 1 entries for echoServer in the mount table.
if got, want := numServers(t, ctx, "echoServer"), 1; got != want {
- t.Fatalf("got: %q, want: %q", got, want)
+ t.Fatalf("got: %d, want: %d", got, want)
}
runClient(t, sh)
@@ -176,11 +172,8 @@
}
func childPing(stdin io.Reader, stdout, stderr io.Writer, env map[string]string, args ...string) error {
- r, err := rt.New()
- if err != nil {
- panic(err)
- }
- ctx := r.NewContext()
+ ctx, shutdown := veyron2.Init()
+ defer shutdown()
veyron2.GetNamespace(ctx).CacheCtl(naming.DisableCache(true))
name := args[1]
@@ -278,23 +271,19 @@
}
func TestAccessDenied(t *testing.T) {
- r1, _ := rt.New()
- r2, _ := rt.New()
+ rootCtx, shutdown := veyron2.Init()
+ defer shutdown()
- // The server and client use different runtimes and hence different
- // principals and without any shared blessings the server will deny
- // access to the client
- ctx1 := r1.NewContext()
- var err error
- if ctx1, err = veyron2.SetPrincipal(ctx1, tsecurity.NewPrincipal("test-blessing")); err != nil {
+ ctx1, err := veyron2.SetPrincipal(rootCtx, tsecurity.NewPrincipal("test-blessing"))
+ if err != nil {
t.Fatal(err)
}
name, fn := initServer(t, ctx1)
defer fn()
- ctx2 := r2.NewContext()
- if ctx2, err = veyron2.SetPrincipal(ctx2, tsecurity.NewPrincipal("test-blessing")); err != nil {
+ ctx2, err := veyron2.SetPrincipal(rootCtx, tsecurity.NewPrincipal("test-blessing"))
+ if err != nil {
t.Fatal(err)
}
client2 := veyron2.GetClient(ctx2)
@@ -506,12 +495,15 @@
// connection to the server if the server dies and comes back (on the same
// endpoint).
func TestReconnect(t *testing.T) {
+ rootCtx, shutdown := veyron2.Init()
+ defer shutdown()
+
principal := tsecurity.NewPrincipal("client")
- r, err := rt.New(options.RuntimePrincipal{principal})
+ ctx, err := veyron2.SetPrincipal(rootCtx, principal)
if err != nil {
- t.Fatalf("unexpected error: %s", err)
+ t.Fatal(err)
}
- sh, err := modules.NewShell(r.NewContext(), principal)
+ sh, err := modules.NewShell(ctx, principal)
if err != nil {
t.Fatalf("unexpected error: %s", err)
}
@@ -525,8 +517,9 @@
serverName := session.ExpectVar("NAME")
serverEP, _ := naming.SplitAddressName(serverName)
ep, _ := inaming.NewEndpoint(serverEP)
- makeCall := func() (string, error) {
- ctx, _ := context.WithDeadline(r.NewContext(), time.Now().Add(10*time.Second))
+
+ makeCall := func(ctx *context.T) (string, error) {
+ ctx, _ = context.WithDeadline(ctx, time.Now().Add(10*time.Second))
call, err := veyron2.GetClient(ctx).StartCall(ctx, serverName, "Echo", []interface{}{"bratman"})
if err != nil {
return "", fmt.Errorf("START: %s", err)
@@ -538,8 +531,9 @@
}
return result, nil
}
+
expected := "mymessage: bratman\n"
- if result, err := makeCall(); err != nil || result != expected {
+ if result, err := makeCall(ctx); err != nil || result != expected {
t.Errorf("Got (%q, %v) want (%q, nil)", result, err, expected)
}
// Kill the server, verify client can't talk to it anymore.
@@ -548,7 +542,7 @@
t.Fatalf("unexpected error: %s", err)
}
- if _, err := makeCall(); err == nil || (!strings.HasPrefix(err.Error(), "START") && !strings.Contains(err.Error(), "EOF")) {
+ if _, err := makeCall(ctx); err == nil || (!strings.HasPrefix(err.Error(), "START") && !strings.Contains(err.Error(), "EOF")) {
t.Fatalf(`Got (%v) want ("START: <err>" or "EOF") as server is down`, err)
}
@@ -562,7 +556,7 @@
session = expect.NewSession(t, server.Stdout(), time.Minute)
defer server.Shutdown(os.Stderr, os.Stderr)
expected = "mymessage again: bratman\n"
- if result, err := makeCall(); err != nil || result != expected {
+ if result, err := makeCall(ctx); err != nil || result != expected {
t.Errorf("Got (%q, %v) want (%q, nil)", result, err, expected)
}
diff --git a/runtimes/google/ipc/debug_test.go b/runtimes/google/ipc/debug_test.go
index ce4c5b1..04ea5b3 100644
--- a/runtimes/google/ipc/debug_test.go
+++ b/runtimes/google/ipc/debug_test.go
@@ -35,7 +35,8 @@
sm := manager.InternalNew(naming.FixedRoutingID(0x555555555))
defer sm.Shutdown()
ns := tnaming.NewSimpleNamespace()
- server, err := InternalNewServer(testContext(), sm, ns, nil, options.ReservedNameDispatcher{debugDisp}, vc.LocalPrincipal{pserver})
+ ctx := testContext()
+ server, err := InternalNewServer(ctx, sm, ns, nil, options.ReservedNameDispatcher{debugDisp}, vc.LocalPrincipal{pserver})
if err != nil {
t.Fatalf("InternalNewServer failed: %v", err)
}
@@ -50,7 +51,6 @@
t.Fatalf("InternalNewClient failed: %v", err)
}
defer client.Close()
- ctx := testContext()
ep := eps[0]
// Call the Foo method on ""
{
diff --git a/runtimes/google/ipc/discharges.go b/runtimes/google/ipc/discharges.go
index f12f554..8334bbb 100644
--- a/runtimes/google/ipc/discharges.go
+++ b/runtimes/google/ipc/discharges.go
@@ -8,7 +8,7 @@
"v.io/core/veyron2/context"
"v.io/core/veyron2/ipc"
"v.io/core/veyron2/security"
- "v.io/core/veyron2/vdl/vdlutil"
+ "v.io/core/veyron2/vdl"
"v.io/core/veyron2/vlog"
"v.io/core/veyron2/vtrace"
)
@@ -107,7 +107,7 @@
vlog.VI(3).Infof("Discharge fetch for %v failed: %v", cav, err)
return
}
- var dAny vdlutil.Any
+ var dAny vdl.AnyRep
if ierr := call.Finish(&dAny, &err); ierr != nil || err != nil {
vlog.VI(3).Infof("Discharge fetch for %v failed: (%v, %v)", cav, err, ierr)
return
@@ -195,7 +195,7 @@
after.Method = before.Method
}
if r.ReportArguments && len(before.Arguments) > 0 {
- after.Arguments = make([]vdlutil.Any, len(before.Arguments))
+ after.Arguments = make([]vdl.AnyRep, len(before.Arguments))
for i := range before.Arguments {
after.Arguments[i] = before.Arguments[i]
}
diff --git a/runtimes/google/ipc/full_test.go b/runtimes/google/ipc/full_test.go
index 2612001..e0c3164 100644
--- a/runtimes/google/ipc/full_test.go
+++ b/runtimes/google/ipc/full_test.go
@@ -24,7 +24,6 @@
"v.io/core/veyron2/services/security/access"
"v.io/core/veyron2/uniqueid"
"v.io/core/veyron2/vdl"
- "v.io/core/veyron2/vdl/vdlutil"
verror "v.io/core/veyron2/verror2"
"v.io/core/veyron2/vlog"
"v.io/core/veyron2/vtrace"
@@ -186,7 +185,7 @@
type dischargeServer struct{}
-func (*dischargeServer) Discharge(ctx ipc.ServerCall, cav vdlutil.Any, _ security.DischargeImpetus) (vdlutil.Any, error) {
+func (*dischargeServer) Discharge(ctx ipc.ServerCall, cav vdl.AnyRep, _ security.DischargeImpetus) (vdl.AnyRep, error) {
c, ok := cav.(security.ThirdPartyCaveat)
if !ok {
return nil, fmt.Errorf("discharger: unknown caveat(%T)", cav)
@@ -205,7 +204,8 @@
func startServerWS(t *testing.T, principal security.Principal, sm stream.Manager, ns naming.Namespace, name string, disp ipc.Dispatcher, shouldUseWebsocket websocketMode, opts ...ipc.ServerOpt) (naming.Endpoint, ipc.Server) {
vlog.VI(1).Info("InternalNewServer")
opts = append(opts, vc.LocalPrincipal{principal})
- server, err := InternalNewServer(testContext(), sm, ns, opts...)
+ ctx := testContext()
+ server, err := InternalNewServer(ctx, sm, ns, opts...)
if err != nil {
t.Errorf("InternalNewServer failed: %v", err)
}
@@ -347,7 +347,8 @@
func TestMultipleCallsToServeAndName(t *testing.T) {
sm := imanager.InternalNew(naming.FixedRoutingID(0x555555555))
ns := tnaming.NewSimpleNamespace()
- server, err := InternalNewServer(testContext(), sm, ns, nil, vc.LocalPrincipal{tsecurity.NewPrincipal()})
+ ctx := testContext()
+ server, err := InternalNewServer(ctx, sm, ns, nil, vc.LocalPrincipal{tsecurity.NewPrincipal()})
if err != nil {
t.Errorf("InternalNewServer failed: %v", err)
}
@@ -715,7 +716,7 @@
traceid []uniqueid.ID
}
-func (s *dischargeTestServer) Discharge(ctx ipc.ServerContext, cav vdlutil.Any, impetus security.DischargeImpetus) (vdlutil.Any, error) {
+func (s *dischargeTestServer) Discharge(ctx ipc.ServerContext, cav vdl.AnyRep, impetus security.DischargeImpetus) (vdl.AnyRep, error) {
s.impetus = append(s.impetus, impetus)
s.traceid = append(s.traceid, vtrace.GetSpan(ctx.Context()).Trace())
return nil, fmt.Errorf("discharges not issued")
@@ -769,7 +770,8 @@
// Setup the discharge server.
var tester dischargeTestServer
- dischargeServer, err := InternalNewServer(testContext(), sm, ns, nil, vc.LocalPrincipal{pdischarger})
+ ctx := testContext()
+ dischargeServer, err := InternalNewServer(ctx, sm, ns, nil, vc.LocalPrincipal{pdischarger})
if err != nil {
t.Fatal(err)
}
@@ -782,7 +784,7 @@
}
// Setup the application server.
- appServer, err := InternalNewServer(testContext(), sm, ns, nil, vc.LocalPrincipal{pserver})
+ appServer, err := InternalNewServer(ctx, sm, ns, nil, vc.LocalPrincipal{pserver})
if err != nil {
t.Fatal(err)
}
@@ -820,7 +822,7 @@
},
{ // Require everything
Requirements: security.ThirdPartyRequirements{ReportServer: true, ReportMethod: true, ReportArguments: true},
- Impetus: security.DischargeImpetus{Server: []security.BlessingPattern{"server"}, Method: "Method", Arguments: []vdlutil.Any{vdlutil.Any("argument")}},
+ Impetus: security.DischargeImpetus{Server: []security.BlessingPattern{"server"}, Method: "Method", Arguments: []vdl.AnyRep{vdl.AnyRep("argument")}},
},
{ // Require only the method name
Requirements: security.ThirdPartyRequirements{ReportMethod: true},
@@ -1236,7 +1238,8 @@
a.IP = net.ParseIP("1.1.1.1")
return []ipc.Address{&netstate.AddrIfc{Addr: a}}, nil
}
- server, err := InternalNewServer(testContext(), sm, ns, nil, vc.LocalPrincipal{tsecurity.NewPrincipal("server")})
+ ctx := testContext()
+ server, err := InternalNewServer(ctx, sm, ns, nil, vc.LocalPrincipal{tsecurity.NewPrincipal("server")})
if err != nil {
t.Errorf("InternalNewServer failed: %v", err)
}
@@ -1277,7 +1280,8 @@
paerr := func(_ string, a []ipc.Address) ([]ipc.Address, error) {
return nil, fmt.Errorf("oops")
}
- server, err := InternalNewServer(testContext(), sm, ns, nil, vc.LocalPrincipal{tsecurity.NewPrincipal("server")})
+ ctx := testContext()
+ server, err := InternalNewServer(ctx, sm, ns, nil, vc.LocalPrincipal{tsecurity.NewPrincipal("server")})
if err != nil {
t.Errorf("InternalNewServer failed: %v", err)
}
@@ -1305,7 +1309,8 @@
sm := imanager.InternalNew(naming.FixedRoutingID(0x66666666))
defer sm.Shutdown()
ns := tnaming.NewSimpleNamespace()
- server, err := InternalNewServer(testContext(), sm, ns, nil, options.VCSecurityNone)
+ ctx := testContext()
+ server, err := InternalNewServer(ctx, sm, ns, nil, options.VCSecurityNone)
if err != nil {
t.Fatalf("InternalNewServer failed: %v", err)
}
@@ -1322,7 +1327,7 @@
}
// When using VCSecurityNone, all authorization checks should be skipped, so
// unauthorized methods should be callable.
- call, err := client.StartCall(testContext(), "mp/server", "Unauthorized", nil, options.VCSecurityNone)
+ call, err := client.StartCall(ctx, "mp/server", "Unauthorized", nil, options.VCSecurityNone)
if err != nil {
t.Fatalf("client.StartCall failed: %v", err)
}
@@ -1369,6 +1374,7 @@
// Start a server that uses the ServerBlessings option to configure itself
// to act as batman (as opposed to using the default blessing).
ns := tnaming.NewSimpleNamespace()
+ ctx := testContext()
runServer := func(name string, opts ...ipc.ServerOpt) stream.Manager {
opts = append(opts, vc.LocalPrincipal{pserver})
rid, err := naming.NewRoutingID()
@@ -1376,11 +1382,7 @@
t.Fatal(err)
}
sm := imanager.InternalNew(rid)
- server, err := InternalNewServer(
- testContext(),
- sm,
- ns,
- opts...)
+ server, err := InternalNewServer(ctx, sm, ns, opts...)
if err != nil {
t.Fatal(err)
}
@@ -1431,7 +1433,7 @@
called bool
}
-func (m *mockDischarger) Discharge(ctx ipc.ServerContext, caveatAny vdlutil.Any, _ security.DischargeImpetus) (vdlutil.Any, error) {
+func (m *mockDischarger) Discharge(ctx ipc.ServerContext, caveatAny vdl.AnyRep, _ security.DischargeImpetus) (vdl.AnyRep, error) {
m.mu.Lock()
m.called = true
m.mu.Unlock()
@@ -1467,13 +1469,14 @@
}
ns := tnaming.NewSimpleNamespace()
+ ctx := testContext()
runServer := func(name string, obj interface{}, principal security.Principal) stream.Manager {
rid, err := naming.NewRoutingID()
if err != nil {
t.Fatal(err)
}
sm := imanager.InternalNew(rid)
- server, err := InternalNewServer(testContext(), sm, ns, nil, vc.LocalPrincipal{principal})
+ server, err := InternalNewServer(ctx, sm, ns, nil, vc.LocalPrincipal{principal})
if err != nil {
t.Fatal(err)
}
@@ -1542,13 +1545,14 @@
}
ns := tnaming.NewSimpleNamespace()
+ ctx := testContext()
runServer := func(name string, obj interface{}, principal security.Principal) stream.Manager {
rid, err := naming.NewRoutingID()
if err != nil {
t.Fatal(err)
}
sm := imanager.InternalNew(rid)
- server, err := InternalNewServer(testContext(), sm, ns, nil, vc.LocalPrincipal{principal})
+ server, err := InternalNewServer(ctx, sm, ns, nil, vc.LocalPrincipal{principal})
if err != nil {
t.Fatal(err)
}
@@ -1606,13 +1610,14 @@
}
ns := tnaming.NewSimpleNamespace()
+ ctx := testContext()
rid, err := naming.NewRoutingID()
if err != nil {
t.Fatal(err)
}
runServer := func(principal security.Principal, rid naming.RoutingID) (ipc.Server, stream.Manager, naming.Endpoint) {
sm := imanager.InternalNew(rid)
- server, err := InternalNewServer(testContext(), sm, ns, nil, vc.LocalPrincipal{principal})
+ server, err := InternalNewServer(ctx, sm, ns, nil, vc.LocalPrincipal{principal})
if err != nil {
t.Fatal(err)
}
diff --git a/runtimes/google/ipc/glob_test.go b/runtimes/google/ipc/glob_test.go
index 799a67e..cb50932 100644
--- a/runtimes/google/ipc/glob_test.go
+++ b/runtimes/google/ipc/glob_test.go
@@ -10,7 +10,6 @@
"v.io/core/veyron2/context"
"v.io/core/veyron2/ipc"
"v.io/core/veyron2/naming"
- "v.io/core/veyron2/rt"
"v.io/core/veyron2/security"
"v.io/core/veyron/lib/glob"
@@ -36,13 +35,10 @@
}
func TestGlob(t *testing.T) {
- runtime, err := rt.New()
+ ctx, shutdown := veyron2.Init()
+ defer shutdown()
+ ctx, err := veyron2.SetPrincipal(ctx, tsecurity.NewPrincipal("test-blessing"))
if err != nil {
- panic(err)
- }
- defer runtime.Cleanup()
- ctx := runtime.NewContext()
- if ctx, err = veyron2.SetPrincipal(ctx, tsecurity.NewPrincipal("test-blessing")); err != nil {
t.Fatal(err)
}
diff --git a/runtimes/google/ipc/resolve_test.go b/runtimes/google/ipc/resolve_test.go
index 53dfdbc..1b22f21 100644
--- a/runtimes/google/ipc/resolve_test.go
+++ b/runtimes/google/ipc/resolve_test.go
@@ -7,7 +7,6 @@
"v.io/core/veyron2"
"v.io/core/veyron2/naming"
- "v.io/core/veyron2/rt"
"v.io/core/veyron/lib/expect"
"v.io/core/veyron/lib/modules"
@@ -35,12 +34,8 @@
defer sh.Cleanup(nil, nil)
root := startMT(t, sh)
- runtime, err := rt.New()
- if err != nil {
- t.Fatalf("rt.New failed: %s", err)
- }
- defer runtime.Cleanup()
- ctx := runtime.NewContext()
+ ctx, shutdown := veyron2.Init()
+ defer shutdown()
if ctx, err = veyron2.SetPrincipal(ctx, tsecurity.NewPrincipal("test-blessing")); err != nil {
t.Fatal(err)
}
diff --git a/runtimes/google/ipc/server.go b/runtimes/google/ipc/server.go
index 5a473d8..20af110 100644
--- a/runtimes/google/ipc/server.go
+++ b/runtimes/google/ipc/server.go
@@ -151,29 +151,29 @@
// resolveToEndpoint resolves an object name or address to an endpoint.
func (s *server) resolveToEndpoint(address string) (string, error) {
- var names []string
+ var resolved *naming.MountEntry
+ var err error
if s.ns != nil {
- var entry *naming.MountEntry
- var err error
- if entry, err = s.ns.Resolve(s.ctx, address); err != nil {
+ if resolved, err = s.ns.Resolve(s.ctx, address); err != nil {
return "", err
}
- names = entry.Names()
} else {
- names = append(names, address)
+ // Fake a namespace resolution
+ resolved = &naming.MountEntry{Servers: []naming.MountedServer{
+ {Server: address},
+ }}
}
// An empty set of protocols means all protocols...
- ordered, err := filterAndOrderServers(names, s.preferredProtocols)
- if err != nil {
+ if resolved.Servers, err = filterAndOrderServers(resolved.Servers, s.preferredProtocols); err != nil {
return "", err
}
- for _, n := range ordered {
+ for _, n := range resolved.Names() {
address, suffix := naming.SplitAddressName(n)
if suffix != "" {
continue
}
- if _, err := inaming.NewEndpoint(address); err == nil {
- return address, nil
+ if ep, err := inaming.NewEndpoint(address); err == nil {
+ return ep.String(), nil
}
}
return "", fmt.Errorf("unable to resolve %q to an endpoint", address)
diff --git a/runtimes/google/ipc/server_test.go b/runtimes/google/ipc/server_test.go
index b71aed9..e59f933 100644
--- a/runtimes/google/ipc/server_test.go
+++ b/runtimes/google/ipc/server_test.go
@@ -45,7 +45,8 @@
sm := imanager.InternalNew(naming.FixedRoutingID(0x555555555))
ns := tnaming.NewSimpleNamespace()
- server, err := InternalNewServer(testContext(), sm, ns, nil)
+ ctx := testContext()
+ server, err := InternalNewServer(ctx, sm, ns, nil)
if err != nil {
t.Fatal(err)
}
@@ -69,7 +70,7 @@
if err != nil {
t.Fatalf("InternalNewClient failed: %v", err)
}
- ctx, _ := context.WithDeadline(testContext(), time.Now().Add(10*time.Second))
+ ctx, _ = context.WithDeadline(testContext(), time.Now().Add(10*time.Second))
call, err := client.StartCall(ctx, "servername", "SomeMethod", nil)
if err != nil {
t.Fatalf("StartCall failed: %v", err)
@@ -148,7 +149,8 @@
t.Fatal(err)
}
defer client.Close()
- server, err := InternalNewServer(testContext(), sm, ns, nil, vc.LocalPrincipal{tsecurity.NewPrincipal("server")})
+ ctx := testContext()
+ server, err := InternalNewServer(ctx, sm, ns, nil, vc.LocalPrincipal{tsecurity.NewPrincipal("server")})
if err != nil {
t.Fatal(err)
}
diff --git a/runtimes/google/ipc/signature_test.go b/runtimes/google/ipc/signature_test.go
index a0604c8..0f98e6a 100644
--- a/runtimes/google/ipc/signature_test.go
+++ b/runtimes/google/ipc/signature_test.go
@@ -10,7 +10,6 @@
"v.io/core/veyron2/ipc"
"v.io/core/veyron2/ipc/reserved"
"v.io/core/veyron2/naming"
- "v.io/core/veyron2/rt"
"v.io/core/veyron2/vdl"
"v.io/core/veyron2/vdl/vdlroot/src/signature"
@@ -60,13 +59,10 @@
}
func TestMethodSignature(t *testing.T) {
- runtime, err := rt.New()
+ ctx, shutdown := veyron2.Init()
+ defer shutdown()
+ ctx, err := veyron2.SetPrincipal(ctx, tsecurity.NewPrincipal("test-blessing"))
if err != nil {
- t.Fatalf("Couldn't initialize runtime: %s", err)
- }
- defer runtime.Cleanup()
- ctx := runtime.NewContext()
- if ctx, err = veyron2.SetPrincipal(ctx, tsecurity.NewPrincipal("test-blessing")); err != nil {
t.Fatal(err)
}
ep, stop, err := startSigServer(ctx, sigImpl{})
@@ -113,13 +109,10 @@
}
func TestSignature(t *testing.T) {
- runtime, err := rt.New()
+ ctx, shutdown := veyron2.Init()
+ defer shutdown()
+ ctx, err := veyron2.SetPrincipal(ctx, tsecurity.NewPrincipal("test-blessing"))
if err != nil {
- t.Fatalf("Couldn't initialize runtime: %s", err)
- }
- defer runtime.Cleanup()
- ctx := runtime.NewContext()
- if ctx, err = veyron2.SetPrincipal(ctx, tsecurity.NewPrincipal("test-blessing")); err != nil {
t.Fatal(err)
}
ep, stop, err := startSigServer(ctx, sigImpl{})
diff --git a/runtimes/google/ipc/sort_endpoints.go b/runtimes/google/ipc/sort_endpoints.go
index 58a6d57..93b8af0 100644
--- a/runtimes/google/ipc/sort_endpoints.go
+++ b/runtimes/google/ipc/sort_endpoints.go
@@ -3,7 +3,7 @@
import (
"fmt"
"net"
- "strings"
+ "sort"
"v.io/core/veyron2/naming"
"v.io/core/veyron2/vlog"
@@ -33,148 +33,51 @@
return r
}
-// TODO(cnicolaou): simplify this code, especially the use of maps+slices
-// and special cases.
-
func newErrorAccumulator() *errorAccumulator {
return &errorAccumulator{errs: make([]error, 0, 4)}
}
-type serverEndpoint struct {
- iep *inaming.Endpoint
- suffix string
+type serverLocality int
+
+const (
+ unknownNetwork serverLocality = iota
+ remoteNetwork
+ localNetwork
+)
+
+type sortableServer struct {
+ server naming.MountedServer
+ protocolRank int // larger values are preferred.
+ locality serverLocality // larger values are preferred.
}
-func (se *serverEndpoint) String() string {
- return fmt.Sprintf("(%s, %q)", se.iep, se.suffix)
+func (s *sortableServer) String() string {
+ return fmt.Sprintf("%v", s.server)
}
-func filterCompatibleEndpoints(errs *errorAccumulator, servers []string) []*serverEndpoint {
- se := make([]*serverEndpoint, 0, len(servers))
- for _, server := range servers {
- name := server
- address, suffix := naming.SplitAddressName(name)
- if len(address) == 0 {
- // Maybe it's not a rooted endpoint, just a bare one.
- address = name
- suffix = ""
- }
- iep, err := inaming.NewEndpoint(address)
- if err != nil {
- errs.add(fmt.Errorf("failed to parse %q: %s", name, err))
- continue
- }
- if err = version.CheckCompatibility(iep); err != nil {
- errs.add(fmt.Errorf("%q: %s", name, err))
- continue
- }
- sep := &serverEndpoint{iep, suffix}
- se = append(se, sep)
+type sortableServerList []sortableServer
+
+func (l sortableServerList) Len() int { return len(l) }
+func (l sortableServerList) Swap(i, j int) { l[i], l[j] = l[j], l[i] }
+func (l sortableServerList) Less(i, j int) bool {
+ if l[i].protocolRank == l[j].protocolRank {
+ return l[i].locality > l[j].locality
}
- return se
+ return l[i].protocolRank > l[j].protocolRank
}
-// sortByProtocols sorts the supplied slice of serverEndpoints into a hash
-// map keyed by the protocol of each of those endpoints where that protocol
-// is listed in the protocols parameter and keyed by '*' if not so listed.
-func sortByProtocol(eps []*serverEndpoint, protocols []string) (bool, map[string][]*serverEndpoint) {
- byProtocol := make(map[string][]*serverEndpoint)
- matched := false
- for _, ep := range eps {
- if ep.iep.Protocol == naming.UnknownProtocol {
- byProtocol[naming.UnknownProtocol] = append(byProtocol[naming.UnknownProtocol], ep)
- matched = true
- break
- }
- found := false
- for _, p := range protocols {
- if ep.iep.Protocol == p ||
- (p == "tcp" && strings.HasPrefix(ep.iep.Protocol, "tcp")) ||
- (p == "wsh" && strings.HasPrefix(ep.iep.Protocol, "wsh")) ||
- // Can't use strings.HasPrefix below because of "wsh" has the prefix "ws" but is a different protocol.
- (p == "ws" && (ep.iep.Protocol == "ws4" || ep.iep.Protocol == "ws6")) {
- byProtocol[p] = append(byProtocol[p], ep)
- found = true
- matched = true
- break
- }
- }
- if !found {
- byProtocol["*"] = append(byProtocol["*"], ep)
- }
+func mkProtocolRankMap(list []string) map[string]int {
+ if len(list) == 0 {
+ return nil
}
- return matched, byProtocol
+ m := make(map[string]int)
+ for idx, protocol := range list {
+ m[protocol] = len(list) - idx
+ }
+ return m
}
-func orderByLocality(ifcs netstate.AddrList, eps []*serverEndpoint) []*serverEndpoint {
- if len(ifcs) <= 1 {
- return append([]*serverEndpoint{}, eps...)
- }
- ipnets := make([]*net.IPNet, 0, len(ifcs))
- for _, a := range ifcs {
- // Try IP
- _, ipnet, err := net.ParseCIDR(a.Address().String())
- if err != nil {
- continue
- }
- ipnets = append(ipnets, ipnet)
- }
- if len(ipnets) == 0 {
- return eps
- }
- // TODO(cnicolaou): this can obviously be made more efficient...
- local := make([]*serverEndpoint, 0, len(eps))
- remote := make([]*serverEndpoint, 0, len(eps))
- notip := make([]*serverEndpoint, 0, len(eps))
- for _, ep := range eps {
- if strings.HasPrefix(ep.iep.Protocol, "tcp") || strings.HasPrefix(ep.iep.Protocol, "ws") {
- // Take care to use the Address directly, since the network
- // may be marked as a 'websocket'. This throws out any thought
- // of dealing with IPv6 etc and web sockets.
- host, _, err := net.SplitHostPort(ep.iep.Address)
- if err != nil {
- host = ep.iep.Address
- }
- ip := net.ParseIP(host)
- if ip == nil {
- notip = append(notip, ep)
- continue
- }
- found := false
- for _, ipnet := range ipnets {
- if ipnet.Contains(ip) {
- local = append(local, ep)
- found = true
- break
- }
- }
- if !found {
- remote = append(remote, ep)
- }
- } else {
- notip = append(notip, ep)
- }
- }
- return append(local, append(remote, notip...)...)
-}
-
-func slice(eps []*serverEndpoint) []string {
- r := make([]string, len(eps))
- for i, a := range eps {
- r[i] = naming.JoinAddressName(a.iep.String(), a.suffix)
- }
- return r
-}
-
-func sliceByProtocol(eps map[string][]*serverEndpoint, protocols []string) []string {
- r := make([]string, 0, 10)
- for _, p := range protocols {
- r = append(r, slice(eps[p])...)
- }
- return r
-}
-
-var defaultPreferredProtocolOrder = []string{"unixfd", "tcp4", "tcp", "*"}
+var defaultPreferredProtocolOrder = mkProtocolRankMap([]string{"unixfd", "wsh", "tcp4", "tcp", "*"})
// filterAndOrderServers returns a set of servers that are compatible with
// the current client in order of 'preference' specified by the supplied
@@ -189,49 +92,128 @@
// will be used, but unlike the previous case, any servers that don't support
// these protocols will be returned also, but following the default
// preferences.
-func filterAndOrderServers(servers []string, protocols []string) ([]string, error) {
- errs := newErrorAccumulator()
- vlog.VI(3).Infof("Candidates[%v]: %v", protocols, servers)
-
- // TODO(cnicolaou): ideally we should filter out unsupported protocols
- // here - e.g. no point dialing on a ws protocol if it's not registered
- // etc.
- compatible := filterCompatibleEndpoints(errs, servers)
- if len(compatible) == 0 {
- return nil, fmt.Errorf("failed to find any compatible servers: %s", errs)
+func filterAndOrderServers(servers []naming.MountedServer, protocols []string) ([]naming.MountedServer, error) {
+ vlog.VI(3).Infof("filterAndOrderServers%v: %v", protocols, servers)
+ var (
+ errs = newErrorAccumulator()
+ list = make(sortableServerList, 0, len(servers))
+ protoRanks = mkProtocolRankMap(protocols)
+ ipnets = ipNetworks()
+ )
+ if len(protoRanks) == 0 {
+ protoRanks = defaultPreferredProtocolOrder
}
- vlog.VI(3).Infof("Version Compatible: %v", compatible)
-
- defaultOrdering := len(protocols) == 0
- preferredProtocolOrder := defaultPreferredProtocolOrder
- if !defaultOrdering {
- preferredProtocolOrder = protocols
+ for _, server := range servers {
+ name := server.Server
+ ep, err := name2endpoint(name)
+ if err != nil {
+ errs.add(fmt.Errorf("malformed endpoint %q: %v", name, err))
+ continue
+ }
+ if err = version.CheckCompatibility(ep); err != nil {
+ errs.add(fmt.Errorf("%q: %v", name, err))
+ continue
+ }
+ rank, err := protocol2rank(ep.Addr().Network(), protoRanks)
+ if err != nil {
+ errs.add(fmt.Errorf("%q: %v", name, err))
+ continue
+ }
+ list = append(list, sortableServer{
+ server: server,
+ protocolRank: rank,
+ locality: locality(ep, ipnets),
+ })
}
-
- // Add unknown protocol to the order last.
- preferredProtocolOrder = append(preferredProtocolOrder, naming.UnknownProtocol)
-
- // put the server endpoints into per-protocol lists
- matched, byProtocol := sortByProtocol(compatible, preferredProtocolOrder)
- if !defaultOrdering && !matched {
- return nil, fmt.Errorf("failed to find any servers compatible with %v from %s", protocols, servers)
+ if len(list) == 0 {
+ return nil, fmt.Errorf("failed to find any compatible servers: %v", errs)
}
+ // TODO(ashankar): Don't have to use stable sorting, could
+ // just use sort.Sort. The only problem with that is the
+ // unittest.
+ sort.Stable(list)
+ // Convert to []naming.MountedServer
+ ret := make([]naming.MountedServer, len(list))
+ for idx, item := range list {
+ ret[idx] = item.server
+ }
+ return ret, nil
+}
- vlog.VI(3).Infof("Have Protocols(%v): %v", protocols, byProtocol)
+// name2endpoint returns the naming.Endpoint encoded in a name.
+func name2endpoint(name string) (naming.Endpoint, error) {
+ addr := name
+ if naming.Rooted(name) {
+ addr, _ = naming.SplitAddressName(name)
+ }
+ return inaming.NewEndpoint(addr)
+}
- networks, err := netstate.GetAll()
+// protocol2rank returns the "rank" of a protocol (given a map of ranks).
+// The higher the rank, the more preferable the protocol.
+func protocol2rank(protocol string, ranks map[string]int) (int, error) {
+ if r, ok := ranks[protocol]; ok {
+ return r, nil
+ }
+ // Special case: if "wsh" has a rank but "wsh4"/"wsh6" don't,
+ // then they get the same rank as "wsh". Similar for "tcp" and "ws".
+ if p := protocol; p == "wsh4" || p == "wsh6" || p == "tcp4" || p == "tcp6" || p == "ws4" || p == "ws6" {
+ if r, ok := ranks[p[:len(p)-1]]; ok {
+ return r, nil
+ }
+ }
+ // "*" means that any protocol is acceptable.
+ if r, ok := ranks["*"]; ok {
+ return r, nil
+ }
+ // UnknownProtocol should be rare, it typically happens when
+ // the endpoint is described in <host>:<port> format instead of
+ // the full fidelity description (@<version>@<protocol>@...).
+ if protocol == naming.UnknownProtocol {
+ return -1, nil
+ }
+ return 0, fmt.Errorf("undesired protocol %q", protocol)
+}
+
+// ipNetworks returns the IP networks on this machine.
+func ipNetworks() []*net.IPNet {
+ ifcs, err := netstate.GetAll()
if err != nil {
- // return whatever we have now, just not sorted by locality.
- return sliceByProtocol(byProtocol, preferredProtocolOrder), nil
+ vlog.VI(5).Infof("netstate.GetAll failed: %v", err)
+ return nil
}
-
- ordered := make([]*serverEndpoint, 0, len(byProtocol))
- for _, protocol := range preferredProtocolOrder {
- o := orderByLocality(networks, byProtocol[protocol])
- vlog.VI(3).Infof("Protocol: %q ordered by locality: %v", protocol, o)
- ordered = append(ordered, o...)
+ ret := make([]*net.IPNet, 0, len(ifcs))
+ for _, a := range ifcs {
+ _, ipnet, err := net.ParseCIDR(a.Address().String())
+ if err != nil {
+ vlog.VI(5).Infof("net.ParseCIDR(%q) failed: %v", a.Address(), err)
+ continue
+ }
+ ret = append(ret, ipnet)
}
+ return ret
+}
- vlog.VI(2).Infof("Ordered By Locality: %v", ordered)
- return slice(ordered), nil
+// locality returns the serverLocality to use given an endpoint and the
+// set of IP networks configured on this machine.
+func locality(ep naming.Endpoint, networks []*net.IPNet) serverLocality {
+ if len(networks) < 1 {
+ return unknownNetwork // 0 IP networks, locality doesn't matter.
+
+ }
+ host, _, err := net.SplitHostPort(ep.Addr().String())
+ if err != nil {
+ host = ep.Addr().String()
+ }
+ ip := net.ParseIP(host)
+ if ip == nil {
+ // Not an IP address (possibly not an IP network).
+ return unknownNetwork
+ }
+ for _, ipnet := range networks {
+ if ipnet.Contains(ip) {
+ return localNetwork
+ }
+ }
+ return remoteNetwork
}
diff --git a/runtimes/google/ipc/sort_internal_test.go b/runtimes/google/ipc/sort_internal_test.go
index 20b9663..041cacd 100644
--- a/runtimes/google/ipc/sort_internal_test.go
+++ b/runtimes/google/ipc/sort_internal_test.go
@@ -7,11 +7,15 @@
"v.io/core/veyron2/ipc/version"
"v.io/core/veyron2/naming"
- "v.io/core/veyron2/vlog"
)
+func servers2names(servers []naming.MountedServer) []string {
+ e := naming.MountEntry{Servers: servers}
+ return e.Names()
+}
+
func TestIncompatible(t *testing.T) {
- servers := []string{}
+ servers := []naming.MountedServer{}
_, err := filterAndOrderServers(servers, []string{"tcp"})
if err == nil || err.Error() != "failed to find any compatible servers: " {
@@ -21,64 +25,68 @@
for _, a := range []string{"127.0.0.1", "127.0.0.2"} {
addr := naming.FormatEndpoint("tcp", a, version.IPCVersionRange{100, 200})
name := naming.JoinAddressName(addr, "")
- servers = append(servers, name)
+ servers = append(servers, naming.MountedServer{Server: name})
}
_, err = filterAndOrderServers(servers, []string{"tcp"})
if err == nil || (!strings.HasPrefix(err.Error(), "failed to find any compatible servers:") && !strings.Contains(err.Error(), "No compatible IPC versions available")) {
- vlog.Infof("A: %t . %t", strings.HasPrefix(err.Error(), "failed to find any compatible servers:"), !strings.Contains(err.Error(), "No compatible IPC versions available"))
t.Errorf("expected a different error to: %v", err)
}
for _, a := range []string{"127.0.0.3", "127.0.0.4"} {
name := naming.JoinAddressName(naming.FormatEndpoint("tcp", a), "")
- servers = append(servers, name)
+ servers = append(servers, naming.MountedServer{Server: name})
}
_, err = filterAndOrderServers(servers, []string{"foobar"})
- if err == nil || !strings.HasPrefix(err.Error(), "failed to find any servers compatible with [foobar] ") {
+ if err == nil || !strings.HasSuffix(err.Error(), "undesired protocol \"tcp\")") {
t.Errorf("expected a different error to: %v", err)
}
}
func TestOrderingByProtocol(t *testing.T) {
- servers := []string{}
+ servers := []naming.MountedServer{}
for _, a := range []string{"127.0.0.3", "127.0.0.4"} {
name := naming.JoinAddressName(naming.FormatEndpoint("tcp", a), "")
- servers = append(servers, name)
+ servers = append(servers, naming.MountedServer{Server: name})
}
for _, a := range []string{"127.0.0.1", "127.0.0.2"} {
name := naming.JoinAddressName(naming.FormatEndpoint("tcp4", a), "")
- servers = append(servers, name)
+ servers = append(servers, naming.MountedServer{Server: name})
}
for _, a := range []string{"127.0.0.10", "127.0.0.11"} {
name := naming.JoinAddressName(naming.FormatEndpoint("foobar", a), "")
- servers = append(servers, name)
+ servers = append(servers, naming.MountedServer{Server: name})
}
for _, a := range []string{"127.0.0.7", "127.0.0.8"} {
name := naming.JoinAddressName(naming.FormatEndpoint("tcp6", a), "")
- servers = append(servers, name)
+ servers = append(servers, naming.MountedServer{Server: name})
}
-
- got, err := filterAndOrderServers(servers, []string{"batman"})
- if err == nil {
+ if _, err := filterAndOrderServers(servers, []string{"batman"}); err == nil {
t.Fatalf("expected an error")
}
- got, err = filterAndOrderServers(servers, []string{"foobar", "tcp4"})
- if err != nil {
- t.Fatalf("unexpected error: %s", err)
- }
+ // Add a server with naming.UnknownProtocol. This typically happens
+ // when the endpoint is in <host>:<port> format. Currently, the sorting
+ // is setup to always allow UnknownProtocol, but put it in the end.
+ // May want to revisit this choice, but for now the test captures what
+ // the current state of the code intends.
+ servers = append(servers, naming.MountedServer{Server: "127.0.0.12:14141"})
// Just foobar and tcp4
want := []string{
- "/@3@foobar@127.0.0.10@00000000000000000000000000000000@@@m@@",
- "/@3@foobar@127.0.0.11@00000000000000000000000000000000@@@m@@",
- "/@3@tcp4@127.0.0.1@00000000000000000000000000000000@@@m@@",
- "/@3@tcp4@127.0.0.2@00000000000000000000000000000000@@@m@@",
+ "/@2@foobar@127.0.0.10@@@@@",
+ "/@2@foobar@127.0.0.11@@@@@",
+ "/@2@tcp4@127.0.0.1@@@@@",
+ "/@2@tcp4@127.0.0.2@@@@@",
+ "/127.0.0.12:14141",
}
- if !reflect.DeepEqual(got, want) {
+ result, err := filterAndOrderServers(servers, []string{"foobar", "tcp4"})
+ if err != nil {
+ t.Fatalf("unexpected error: %s", err)
+ }
+ if got := servers2names(result); !reflect.DeepEqual(got, want) {
t.Errorf("got: %v, want %v", got, want)
}
@@ -87,117 +95,119 @@
// The order will be the default preferred order for protocols, the
// original ordering within each protocol, with protocols that
// are not in the default ordering list at the end.
- got, err = filterAndOrderServers(servers, nil)
- if err != nil {
+ want = []string{
+ "/@2@tcp4@127.0.0.1@@@@@",
+ "/@2@tcp4@127.0.0.2@@@@@",
+ "/@2@tcp@127.0.0.3@@@@@",
+ "/@2@tcp@127.0.0.4@@@@@",
+ "/@2@tcp6@127.0.0.7@@@@@",
+ "/@2@tcp6@127.0.0.8@@@@@",
+ "/@2@foobar@127.0.0.10@@@@@",
+ "/@2@foobar@127.0.0.11@@@@@",
+ "/127.0.0.12:14141",
+ }
+ if result, err = filterAndOrderServers(servers, nil); err != nil {
t.Fatalf("unexpected error: %s", err)
}
-
- want = []string{
- "/@3@tcp4@127.0.0.1@00000000000000000000000000000000@@@m@@",
- "/@3@tcp4@127.0.0.2@00000000000000000000000000000000@@@m@@",
- "/@3@tcp@127.0.0.3@00000000000000000000000000000000@@@m@@",
- "/@3@tcp@127.0.0.4@00000000000000000000000000000000@@@m@@",
- "/@3@tcp6@127.0.0.7@00000000000000000000000000000000@@@m@@",
- "/@3@tcp6@127.0.0.8@00000000000000000000000000000000@@@m@@",
- "/@3@foobar@127.0.0.10@00000000000000000000000000000000@@@m@@",
- "/@3@foobar@127.0.0.11@00000000000000000000000000000000@@@m@@",
- }
- if !reflect.DeepEqual(got, want) {
+ if got := servers2names(result); !reflect.DeepEqual(got, want) {
t.Errorf("got: %v, want %v", got, want)
}
- got, err = filterAndOrderServers(servers, []string{})
- if err != nil {
+ if result, err = filterAndOrderServers(servers, []string{}); err != nil {
t.Fatalf("unexpected error: %s", err)
}
-
- if !reflect.DeepEqual(got, want) {
+ if got := servers2names(result); !reflect.DeepEqual(got, want) {
t.Errorf("got: %v, want %v", got, want)
}
- got, err = filterAndOrderServers(servers, []string{"tcp"})
- if err != nil {
+ // Just "tcp" implies tcp4 and tcp6 as well.
+ want = []string{
+ "/@2@tcp@127.0.0.3@@@@@",
+ "/@2@tcp@127.0.0.4@@@@@",
+ "/@2@tcp4@127.0.0.1@@@@@",
+ "/@2@tcp4@127.0.0.2@@@@@",
+ "/@2@tcp6@127.0.0.7@@@@@",
+ "/@2@tcp6@127.0.0.8@@@@@",
+ "/127.0.0.12:14141",
+ }
+ if result, err = filterAndOrderServers(servers, []string{"tcp"}); err != nil {
t.Fatalf("unexpected error: %s", err)
}
- // tcp or tcp4
- want = []string{
- "/@3@tcp4@127.0.0.1@00000000000000000000000000000000@@@m@@",
- "/@3@tcp4@127.0.0.2@00000000000000000000000000000000@@@m@@",
- "/@3@tcp@127.0.0.3@00000000000000000000000000000000@@@m@@",
- "/@3@tcp@127.0.0.4@00000000000000000000000000000000@@@m@@",
+ if got := servers2names(result); !reflect.DeepEqual(got, want) {
+ t.Errorf("got: %v, want %v", got, want)
}
// Ask for all protocols, with no ordering, except for locality
- servers = []string{}
+ want = []string{
+ "/@2@tcp@127.0.0.3@@@@@",
+ "/@2@tcp@127.0.0.1@@@@@",
+ "/@2@tcp@74.125.69.139@@@@@",
+ "/@2@tcp@192.168.1.10@@@@@",
+ "/@2@tcp@74.125.142.83@@@@@",
+ "/127.0.0.12:14141",
+ "/@2@foobar@127.0.0.10@@@@@",
+ "/@2@foobar@127.0.0.11@@@@@",
+ }
+ servers = []naming.MountedServer{}
+ // naming.UnknownProtocol
+ servers = append(servers, naming.MountedServer{Server: "127.0.0.12:14141"})
for _, a := range []string{"74.125.69.139", "127.0.0.3", "127.0.0.1", "192.168.1.10", "74.125.142.83"} {
name := naming.JoinAddressName(naming.FormatEndpoint("tcp", a), "")
- servers = append(servers, name)
+ servers = append(servers, naming.MountedServer{Server: name})
}
for _, a := range []string{"127.0.0.10", "127.0.0.11"} {
name := naming.JoinAddressName(naming.FormatEndpoint("foobar", a), "")
- servers = append(servers, name)
+ servers = append(servers, naming.MountedServer{Server: name})
}
- // Everything, since we didn't specify a protocol
- got, err = filterAndOrderServers(servers, []string{})
- if err != nil {
+ if result, err = filterAndOrderServers(servers, []string{}); err != nil {
t.Fatalf("unexpected error: %s", err)
}
- want = []string{
- "/@3@tcp@127.0.0.3@00000000000000000000000000000000@@@m@@",
- "/@3@tcp@127.0.0.1@00000000000000000000000000000000@@@m@@",
- "/@3@tcp@74.125.69.139@00000000000000000000000000000000@@@m@@",
- "/@3@tcp@192.168.1.10@00000000000000000000000000000000@@@m@@",
- "/@3@tcp@74.125.142.83@00000000000000000000000000000000@@@m@@",
- "/@3@foobar@127.0.0.10@00000000000000000000000000000000@@@m@@",
- "/@3@foobar@127.0.0.11@00000000000000000000000000000000@@@m@@",
- }
- if !reflect.DeepEqual(got, want) {
+ if got := servers2names(result); !reflect.DeepEqual(got, want) {
t.Errorf("got: %v, want %v", got, want)
}
}
-func TestOrderByNetwork(t *testing.T) {
- servers := []string{}
+func TestOrderingByLocality(t *testing.T) {
+ servers := []naming.MountedServer{}
for _, a := range []string{"74.125.69.139", "127.0.0.3", "127.0.0.1", "192.168.1.10", "74.125.142.83"} {
name := naming.JoinAddressName(naming.FormatEndpoint("tcp", a), "")
- servers = append(servers, name)
+ servers = append(servers, naming.MountedServer{Server: name})
}
- got, err := filterAndOrderServers(servers, []string{"tcp"})
+ result, err := filterAndOrderServers(servers, []string{"tcp"})
if err != nil {
t.Fatalf("unexpected error: %s", err)
}
want := []string{
- "/@3@tcp@127.0.0.3@00000000000000000000000000000000@@@m@@",
- "/@3@tcp@127.0.0.1@00000000000000000000000000000000@@@m@@",
- "/@3@tcp@74.125.69.139@00000000000000000000000000000000@@@m@@",
- "/@3@tcp@192.168.1.10@00000000000000000000000000000000@@@m@@",
- "/@3@tcp@74.125.142.83@00000000000000000000000000000000@@@m@@",
+ "/@2@tcp@127.0.0.3@@@@@",
+ "/@2@tcp@127.0.0.1@@@@@",
+ "/@2@tcp@74.125.69.139@@@@@",
+ "/@2@tcp@192.168.1.10@@@@@",
+ "/@2@tcp@74.125.142.83@@@@@",
}
- if !reflect.DeepEqual(got, want) {
+ if got := servers2names(result); !reflect.DeepEqual(got, want) {
t.Errorf("got: %v, want %v", got, want)
}
for _, a := range []string{"74.125.69.139", "127.0.0.3:123", "127.0.0.1", "192.168.1.10", "74.125.142.83"} {
name := naming.JoinAddressName(naming.FormatEndpoint("ws", a), "")
- servers = append(servers, name)
+ servers = append(servers, naming.MountedServer{Server: name})
}
- got, err = filterAndOrderServers(servers, []string{"ws", "tcp"})
- if err != nil {
+ if result, err = filterAndOrderServers(servers, []string{"ws", "tcp"}); err != nil {
t.Fatalf("unexpected error: %s", err)
}
want = []string{
- "/@3@ws@127.0.0.3:123@00000000000000000000000000000000@@@m@@",
- "/@3@ws@127.0.0.1@00000000000000000000000000000000@@@m@@",
- "/@3@ws@74.125.69.139@00000000000000000000000000000000@@@m@@",
- "/@3@ws@192.168.1.10@00000000000000000000000000000000@@@m@@",
- "/@3@ws@74.125.142.83@00000000000000000000000000000000@@@m@@",
- "/@3@tcp@127.0.0.3@00000000000000000000000000000000@@@m@@",
- "/@3@tcp@127.0.0.1@00000000000000000000000000000000@@@m@@",
- "/@3@tcp@74.125.69.139@00000000000000000000000000000000@@@m@@",
- "/@3@tcp@192.168.1.10@00000000000000000000000000000000@@@m@@",
- "/@3@tcp@74.125.142.83@00000000000000000000000000000000@@@m@@",
+ "/@2@ws@127.0.0.3:123@@@@@",
+ "/@2@ws@127.0.0.1@@@@@",
+ "/@2@ws@74.125.69.139@@@@@",
+ "/@2@ws@192.168.1.10@@@@@",
+ "/@2@ws@74.125.142.83@@@@@",
+ "/@2@tcp@127.0.0.3@@@@@",
+ "/@2@tcp@127.0.0.1@@@@@",
+ "/@2@tcp@74.125.69.139@@@@@",
+ "/@2@tcp@192.168.1.10@@@@@",
+ "/@2@tcp@74.125.142.83@@@@@",
}
- if !reflect.DeepEqual(got, want) {
+ if got := servers2names(result); !reflect.DeepEqual(got, want) {
t.Errorf("got: %v, want %v", got, want)
}
}
diff --git a/runtimes/google/naming/namespace/all_test.go b/runtimes/google/naming/namespace/all_test.go
index 4590568..29c4932 100644
--- a/runtimes/google/naming/namespace/all_test.go
+++ b/runtimes/google/naming/namespace/all_test.go
@@ -12,7 +12,6 @@
"v.io/core/veyron2/ipc"
"v.io/core/veyron2/naming"
"v.io/core/veyron2/options"
- "v.io/core/veyron2/rt"
"v.io/core/veyron2/security"
verror "v.io/core/veyron2/verror2"
"v.io/core/veyron2/vlog"
@@ -29,31 +28,19 @@
testutil.Init()
}
-func createRuntimes(t *testing.T) (sc, c *context.T, cleanup func()) {
- // Create a runtime for the server.
- sr, err := rt.New()
- if err != nil {
- t.Fatalf("Could not initialize runtime: %v", err)
- }
- sc = sr.NewContext()
- if sc, err = veyron2.SetPrincipal(sc, tsecurity.NewPrincipal("test-blessing")); err != nil {
+func createContexts(t *testing.T) (sc, c *context.T, cleanup func()) {
+ ctx, shutdown := veyron2.Init()
+
+ var err error
+ if sc, err = veyron2.SetPrincipal(ctx, tsecurity.NewPrincipal("test-blessing")); err != nil {
t.Fatal(err)
}
- // We use a different runtime for the client side.
- r, err := rt.New()
- if err != nil {
- t.Fatalf("Could not initialize runtime: %v", err)
- }
- c = r.NewContext()
- if c, err = veyron2.SetPrincipal(c, tsecurity.NewPrincipal("test-blessing")); err != nil {
+ if c, err = veyron2.SetPrincipal(ctx, tsecurity.NewPrincipal("test-blessing")); err != nil {
t.Fatal(err)
}
- return sc, c, func() {
- sr.Cleanup()
- r.Cleanup()
- }
+ return sc, c, shutdown
}
func boom(t *testing.T, f string, v ...interface{}) {
@@ -282,7 +269,7 @@
// TestNamespaceCommon tests common use of the Namespace library
// against a root mount table and some mount tables mounted on it.
func TestNamespaceCommon(t *testing.T) {
- _, c, cleanup := createRuntimes(t)
+ _, c, cleanup := createContexts(t)
defer cleanup()
root, mts, jokes, stopper := createNamespace(t, c)
@@ -314,7 +301,7 @@
// TestNamespaceDetails tests more detailed use of the Namespace library.
func TestNamespaceDetails(t *testing.T) {
- sc, c, cleanup := createRuntimes(t)
+ sc, c, cleanup := createContexts(t)
defer cleanup()
root, mts, _, stopper := createNamespace(t, sc)
@@ -368,7 +355,7 @@
// TestNestedMounts tests some more deeply nested mounts
func TestNestedMounts(t *testing.T) {
- sc, c, cleanup := createRuntimes(t)
+ sc, c, cleanup := createContexts(t)
defer cleanup()
root, mts, _, stopper := createNamespace(t, sc)
@@ -393,7 +380,7 @@
// TestServers tests invoking RPCs on simple servers
func TestServers(t *testing.T) {
- sc, c, cleanup := createRuntimes(t)
+ sc, c, cleanup := createContexts(t)
defer cleanup()
root, mts, jokes, stopper := createNamespace(t, sc)
@@ -418,7 +405,7 @@
// TestGlob tests some glob patterns.
func TestGlob(t *testing.T) {
- sc, c, cleanup := createRuntimes(t)
+ sc, c, cleanup := createContexts(t)
defer cleanup()
root, mts, _, stopper := createNamespace(t, sc)
@@ -489,7 +476,7 @@
// TestGlobEarlyStop tests that Glob doesn't query terminal servers with finished patterns.
func TestGlobEarlyStop(t *testing.T) {
- sc, c, cleanup := createRuntimes(t)
+ sc, c, cleanup := createContexts(t)
defer cleanup()
root, mts, _, stopper := createNamespace(t, sc)
@@ -529,7 +516,7 @@
}
func TestCycles(t *testing.T) {
- sc, c, cleanup := createRuntimes(t)
+ sc, c, cleanup := createContexts(t)
defer cleanup()
root, _, _, stopper := createNamespace(t, sc)
@@ -580,7 +567,7 @@
// TestGoroutineLeaks tests for leaking goroutines - we have many:-(
func TestGoroutineLeaks(t *testing.T) {
t.Skip()
- sc, _, cleanup := createRuntimes(t)
+ sc, _, cleanup := createContexts(t)
defer cleanup()
_, _, _, stopper := createNamespace(t, sc)
@@ -612,7 +599,7 @@
}
func TestRootBlessing(t *testing.T) {
- c, cc, cleanup := createRuntimes(t)
+ c, cc, cleanup := createContexts(t)
defer cleanup()
proot, err := vsecurity.NewPrincipal()
diff --git a/runtimes/google/naming/namespace/mount.go b/runtimes/google/naming/namespace/mount.go
index 66bf6d0..7b7ce3a 100644
--- a/runtimes/google/naming/namespace/mount.go
+++ b/runtimes/google/naming/namespace/mount.go
@@ -37,7 +37,7 @@
func unmountFromMountTable(ctx *context.T, client ipc.Client, name, server string, id string) (s status) {
s.id = id
ctx, _ = context.WithTimeout(ctx, callTimeout)
- call, err := client.StartCall(ctx, name, "Unmount", []interface{}{server}, options.NoResolve{})
+ call, err := client.StartCall(ctx, name, "Unmount", []interface{}{server}, options.NoResolve{}, inaming.NoCancel{})
s.err = err
if err != nil {
return
@@ -83,9 +83,9 @@
}
// dispatch executes f in parallel for each mount table implementing mTName.
-func (ns *namespace) dispatch(ctx *context.T, mTName string, f func(*context.T, string, string) status) error {
+func (ns *namespace) dispatch(ctx *context.T, mTName string, f func(*context.T, string, string) status, opts ...naming.ResolveOpt) error {
// Resolve to all the mount tables implementing name.
- me, err := ns.ResolveToMountTable(ctx, mTName)
+ me, err := ns.ResolveToMountTable(ctx, mTName, opts...)
if err != nil {
return err
}
@@ -139,7 +139,7 @@
f := func(context *context.T, mt, id string) status {
return unmountFromMountTable(ctx, client, mt, server, id)
}
- err := ns.dispatch(ctx, name, f)
+ err := ns.dispatch(ctx, name, f, inaming.NoCancel{})
vlog.VI(1).Infof("Unmount(%s, %s) -> %v", name, server, err)
return err
}
diff --git a/runtimes/google/naming/namespace/resolve.go b/runtimes/google/naming/namespace/resolve.go
index 97f8e9b..4e54b4d 100644
--- a/runtimes/google/naming/namespace/resolve.go
+++ b/runtimes/google/naming/namespace/resolve.go
@@ -85,12 +85,8 @@
}
pattern := getRootPattern(opts)
client := veyron2.GetClient(ctx)
- var callOpts []ipc.CallOpt
- for _, opt := range opts {
- if callOpt, ok := opt.(ipc.CallOpt); ok {
- callOpts = append(callOpts, callOpt)
- }
- }
+ callOpts := getCallOpts(opts)
+
// Iterate walking through mount table servers.
for remaining := ns.maxResolveDepth; remaining > 0; remaining-- {
vlog.VI(2).Infof("Resolve(%s) loop %v", name, *e)
@@ -131,6 +127,7 @@
return nil, verror.Make(naming.ErrNoMountTable, ctx)
}
pattern := getRootPattern(opts)
+ callOpts := getCallOpts(opts)
client := veyron2.GetClient(ctx)
last := e
for remaining := ns.maxResolveDepth; remaining > 0; remaining-- {
@@ -142,7 +139,7 @@
vlog.VI(1).Infof("ResolveToMountTable(%s) -> %v", name, last)
return last, nil
}
- if e, err = ns.resolveAgainstMountTable(ctx, client, e, pattern); err != nil {
+ if e, err = ns.resolveAgainstMountTable(ctx, client, e, pattern, callOpts...); err != nil {
if verror.Is(err, naming.ErrNoSuchNameRoot.ID) {
vlog.VI(1).Infof("ResolveToMountTable(%s) -> %v (NoSuchRoot: %v)", name, last, curr)
return last, nil
@@ -210,3 +207,13 @@
}
return ""
}
+
+func getCallOpts(opts []naming.ResolveOpt) []ipc.CallOpt {
+ var out []ipc.CallOpt
+ for _, o := range opts {
+ if co, ok := o.(ipc.CallOpt); ok {
+ out = append(out, co)
+ }
+ }
+ return out
+}
diff --git a/runtimes/google/naming/nocancel.go b/runtimes/google/naming/nocancel.go
new file mode 100644
index 0000000..85e1658
--- /dev/null
+++ b/runtimes/google/naming/nocancel.go
@@ -0,0 +1,11 @@
+package naming
+
+// NoCancel is an option passed to a resolve or an IPC call that
+// instructs it to ignore cancellation for that call.
+// This is used to allow servers to unmount even after their context
+// has been cancelled.
+// TODO(mattr): Find a better mechanism for this.
+type NoCancel struct{}
+
+func (NoCancel) IPCCallOpt() {}
+func (NoCancel) NSResolveOpt() {}
diff --git a/runtimes/google/rt/ipc_test.go b/runtimes/google/rt/ipc_test.go
index f62178a..8dee8a4 100644
--- a/runtimes/google/rt/ipc_test.go
+++ b/runtimes/google/rt/ipc_test.go
@@ -15,7 +15,7 @@
"v.io/core/veyron/lib/testutil"
tsecurity "v.io/core/veyron/lib/testutil/security"
"v.io/core/veyron/profiles"
- "v.io/core/veyron2/vdl/vdlutil"
+ "v.io/core/veyron2/vdl"
"v.io/core/veyron2/verror"
)
@@ -29,7 +29,7 @@
type dischargeService struct{}
-func (dischargeService) Discharge(ctx ipc.ServerCall, cav vdlutil.Any, _ security.DischargeImpetus) (vdlutil.Any, error) {
+func (dischargeService) Discharge(ctx ipc.ServerCall, cav vdl.AnyRep, _ security.DischargeImpetus) (vdl.AnyRep, error) {
c, ok := cav.(security.ThirdPartyCaveat)
if !ok {
return nil, fmt.Errorf("discharger: unknown caveat(%T)", cav)
diff --git a/runtimes/google/rt/runtimex.go b/runtimes/google/rt/runtimex.go
index 1e9bd5a..618ddf7 100644
--- a/runtimes/google/rt/runtimex.go
+++ b/runtimes/google/rt/runtimex.go
@@ -50,16 +50,20 @@
backgroundKey
)
+type vtraceDependency struct{}
+
// TODO(suharshs,mattr): Panic instead of flagsOnce after the transition to veyron.Init is completed.
var flagsOnce sync.Once
var runtimeFlags *flags.Flags
-var signals chan os.Signal
+
+var hackruntime *RuntimeX
func init() {
// TODO(mattr): Remove this hacky registration.
- r := &RuntimeX{}
- r.wait = sync.NewCond(&r.mu)
- veyron2.RegisterRuntime("google", r)
+ hackruntime = &RuntimeX{deps: make(map[interface{}]*depSet)}
+ hackruntime.newDepSetLocked(hackruntime)
+ hackruntime.newDepSetLocked(vtraceDependency{})
+ veyron2.RegisterRuntime("google", hackruntime)
runtimeFlags = flags.CreateAndRegister(flag.CommandLine, flags.Runtime)
}
@@ -73,7 +77,9 @@
ctx = context.WithValue(ctx, reservedNameKey,
&reservedNameDispatcher{rt.reservedDisp, rt.reservedOpts})
ctx = context.WithValue(ctx, streamManagerKey, rt.sm[0])
+ hackruntime.addChild(ctx, rt.sm[0], func() {})
ctx = SetClient(ctx, rt.client)
+ hackruntime.addChild(ctx, rt.client, func() {})
ctx = context.WithValue(ctx, namespaceKey, rt.ns)
ctx = context.WithValue(ctx, loggerKey, vlog.Log)
ctx = context.WithValue(ctx, principalKey, rt.principal)
@@ -82,14 +88,17 @@
return ctx
}
+type depSet struct {
+ count int
+ cond *sync.Cond
+}
+
// RuntimeX implements the veyron2.RuntimeX interface. It is stateless.
// Please see the interface definition for documentation of the
// individiual methods.
type RuntimeX struct {
- mu sync.Mutex
- closed bool
- children int
- wait *sync.Cond
+ mu sync.Mutex
+ deps map[interface{}]*depSet
}
type reservedNameDispatcher struct {
@@ -99,8 +108,8 @@
// TODO(mattr,suharshs): Decide if ROpts would be better than this.
func Init(ctx *context.T, appCycle veyron2.AppCycle, protocols []string, listenSpec *ipc.ListenSpec, reservedDispatcher ipc.Dispatcher, dispatcherOpts ...ipc.ServerOpt) (*RuntimeX, *context.T, veyron2.Shutdown, error) {
- r := &RuntimeX{}
- r.wait = sync.NewCond(&r.mu)
+ r := &RuntimeX{deps: make(map[interface{}]*depSet)}
+ r.newDepSetLocked(r)
handle, err := exec.GetChildHandle()
switch err {
@@ -127,6 +136,16 @@
r.initLogging(ctx)
ctx = context.WithValue(ctx, loggerKey, vlog.Log)
+ // Setup the initial trace.
+ ctx, err = ivtrace.Init(ctx, flags.Vtrace)
+ if err != nil {
+ return nil, nil, nil, err
+ }
+ ctx, _ = vtrace.SetNewTrace(ctx)
+ r.addChild(ctx, vtraceDependency{}, func() {
+ vtrace.FormatTraces(os.Stderr, vtrace.GetStore(ctx).TraceRecords(), nil)
+ })
+
if reservedDispatcher != nil {
ctx = context.WithValue(ctx, reservedNameKey, &reservedNameDispatcher{reservedDispatcher, dispatcherOpts})
}
@@ -158,13 +177,6 @@
// Setup the program name.
ctx = verror2.ContextWithComponentName(ctx, filepath.Base(os.Args[0]))
- // Setup the initial trace.
- ctx, err = ivtrace.Init(ctx, flags.Vtrace)
- if err != nil {
- return nil, nil, nil, err
- }
- ctx, _ = vtrace.SetNewTrace(ctx)
-
// Enable signal handling.
r.initSignalHandling(ctx)
@@ -214,49 +226,90 @@
return r, ctx, r.cancel, nil
}
-func (r *RuntimeX) addChild(ctx *context.T, stop func()) error {
+func (r *RuntimeX) addChild(ctx *context.T, me interface{}, stop func(), dependsOn ...interface{}) error {
// TODO(mattr): Remove this hack once the transition is over.
if r == nil {
return nil
}
- if r.wait == nil {
- panic("no wait???")
- }
+
+ // Note that we keep a depSet for the runtime itself
+ // (which we say every child depends on) and we use that to determine
+ // when the runtime can be cleaned up.
+ dependsOn = append(dependsOn, r)
+
r.mu.Lock()
- if r.closed {
+ r.newDepSetLocked(me)
+ deps, err := r.getDepsLocked(dependsOn)
+ if err != nil {
r.mu.Unlock()
stop()
- return fmt.Errorf("The runtime has already been shutdown.")
+ return err
}
- r.children++
+ r.incrLocked(deps)
r.mu.Unlock()
if done := ctx.Done(); done != nil {
go func() {
<-done
+ r.wait(me)
stop()
- r.mu.Lock()
- r.children--
- if r.children == 0 {
- r.wait.Broadcast()
- }
- r.mu.Unlock()
+ r.decr(deps)
}()
}
return nil
}
+func (r *RuntimeX) newDepSetLocked(key interface{}) {
+ r.deps[key] = &depSet{cond: sync.NewCond(&r.mu)}
+}
+
+func (r *RuntimeX) getDepsLocked(keys []interface{}) ([]*depSet, error) {
+ out := make([]*depSet, len(keys))
+ for i := range keys {
+ out[i] = r.deps[keys[i]]
+ if out[i] == nil {
+ return nil, fmt.Errorf("You are creating an object but it depends on something that is already shutdown: %v.", keys[i])
+ }
+ }
+ return out, nil
+}
+
+func (r *RuntimeX) incrLocked(sets []*depSet) {
+ for _, ds := range sets {
+ ds.count++
+ }
+}
+
+func (r *RuntimeX) decr(sets []*depSet) {
+ r.mu.Lock()
+ for _, ds := range sets {
+ ds.count--
+ if ds.count == 0 {
+ ds.cond.Broadcast()
+ }
+ }
+ r.mu.Unlock()
+}
+
+func (r *RuntimeX) wait(key interface{}) {
+ r.mu.Lock()
+ ds := r.deps[key]
+ if ds == nil {
+ panic(fmt.Sprintf("ds is gone for %#v", key))
+ }
+ delete(r.deps, key)
+ for ds.count > 0 {
+ ds.cond.Wait()
+ }
+ r.mu.Unlock()
+}
+
func (r *RuntimeX) cancel() {
// TODO(mattr): Remove this hack once the transition is over.
if r == nil {
return
}
- r.mu.Lock()
- r.closed = true
- for r.children > 0 {
- r.wait.Wait()
- }
- r.mu.Unlock()
+ r.wait(r)
vlog.FlushLog()
}
@@ -274,7 +327,7 @@
// Automatically handle SIGHUP to prevent applications started as
// daemons from being killed. The developer can choose to still listen
// on SIGHUP and take a different action if desired.
- signals = make(chan os.Signal, 1)
+ signals := make(chan os.Signal, 1)
signal.Notify(signals, syscall.SIGHUP)
go func() {
for {
@@ -285,7 +338,7 @@
vlog.Infof("Received signal %v", sig)
}
}()
- r.addChild(ctx, func() {
+ r.addChild(ctx, signals, func() {
signal.Stop(signals)
close(signals)
})
@@ -304,6 +357,7 @@
ns, _ := ctx.Value(namespaceKey).(naming.Namespace)
principal, _ := ctx.Value(principalKey).(security.Principal)
+ client, _ := ctx.Value(clientKey).(ipc.Client)
otherOpts := append([]ipc.ServerOpt{}, opts...)
otherOpts = append(otherOpts, vc.LocalPrincipal{principal})
@@ -324,7 +378,7 @@
}
sm.Shutdown()
}
- if err = r.addChild(ctx, stop); err != nil {
+ if err = r.addChild(ctx, server, stop, client, vtraceDependency{}); err != nil {
return nil, err
}
return server, nil
@@ -342,7 +396,7 @@
func (r *RuntimeX) setNewStreamManager(ctx *context.T, opts ...stream.ManagerOpt) (*context.T, stream.Manager, error) {
sm, err := newStreamManager(opts...)
newctx := context.WithValue(ctx, streamManagerKey, sm)
- if err = r.addChild(ctx, sm.Shutdown); err != nil {
+ if err = r.addChild(ctx, sm, sm.Shutdown); err != nil {
return ctx, nil, err
}
return newctx, sm, err
@@ -416,7 +470,7 @@
return ctx, nil, err
}
newctx := SetClient(ctx, client)
- if err = r.addChild(ctx, client.Close); err != nil {
+ if err = r.addChild(ctx, client, client.Close, sm, vtraceDependency{}); err != nil {
return ctx, nil, err
}
return newctx, client, err
@@ -437,6 +491,7 @@
func (*RuntimeX) setNewNamespace(ctx *context.T, roots ...string) (*context.T, naming.Namespace, error) {
ns, err := namespace.New(roots...)
+ // TODO(mattr): Copy cache settings.
if err == nil {
ctx = context.WithValue(ctx, namespaceKey, ns)
}
diff --git a/security/agent/agent_test.go b/security/agent/agent_test.go
index bfc7ddd..8b1f757 100644
--- a/security/agent/agent_test.go
+++ b/security/agent/agent_test.go
@@ -13,7 +13,6 @@
"v.io/core/veyron2"
"v.io/core/veyron2/context"
- "v.io/core/veyron2/rt"
"v.io/core/veyron2/security"
"v.io/core/veyron2/verror2"
)
@@ -49,16 +48,13 @@
)
func TestAgent(t *testing.T) {
- r, err := rt.New()
- if err != nil {
- t.Fatalf("Could not initialize runtime: %s", err)
- }
- defer r.Cleanup()
+ ctx, shutdown := veyron2.Init()
+ defer shutdown()
var (
thirdPartyCaveat, discharge = newThirdPartyCaveatAndDischarge(t)
mockP = newMockPrincipal()
- agent = setupAgent(t, r.NewContext(), mockP)
+ agent = setupAgent(t, ctx, mockP)
)
tests := []testInfo{
{"BlessSelf", V{"self"}, newBlessing(t, "blessing"), nil},
diff --git a/security/agent/agentd/main.go b/security/agent/agentd/main.go
index 3896545..c011d8a 100644
--- a/security/agent/agentd/main.go
+++ b/security/agent/agentd/main.go
@@ -20,8 +20,6 @@
"v.io/core/veyron/security/agent/server"
"v.io/core/veyron2"
- "v.io/core/veyron2/options"
- "v.io/core/veyron2/rt"
"v.io/core/veyron2/security"
"v.io/core/veyron2/vlog"
)
@@ -76,13 +74,12 @@
vlog.Fatalf("failed to create new principal from dir(%s): %v", dir, err)
}
- runtime, err := rt.New(options.RuntimePrincipal{p})
- if err != nil {
- panic("Could not initialize runtime: " + err.Error())
- }
- defer runtime.Cleanup()
+ ctx, shutdown := veyron2.Init()
+ defer shutdown()
- ctx := runtime.NewContext()
+ if ctx, err = veyron2.SetPrincipal(ctx, p); err != nil {
+ vlog.Panic("failed to set principal for ctx: %v", err)
+ }
log := veyron2.GetLogger(ctx)
diff --git a/security/agent/client.go b/security/agent/client.go
index 0c2912a..f3128f9 100644
--- a/security/agent/client.go
+++ b/security/agent/client.go
@@ -13,7 +13,7 @@
"v.io/core/veyron2/naming"
"v.io/core/veyron2/options"
"v.io/core/veyron2/security"
- "v.io/core/veyron2/vdl/vdlutil"
+ "v.io/core/veyron2/vdl"
"v.io/core/veyron2/vlog"
"v.io/core/veyron2/vtrace"
)
@@ -67,7 +67,7 @@
}
// This is just an arbitrary 1 byte string. The value is ignored.
data := make([]byte, 1)
- addr, err := unixfd.SendConnection(conn.(*net.UnixConn), data, true)
+ addr, err := unixfd.SendConnection(conn.(*net.UnixConn), data)
if err != nil {
return nil, err
}
@@ -121,7 +121,7 @@
func (c *client) MintDischarge(tp security.ThirdPartyCaveat, caveat security.Caveat, additionalCaveats ...security.Caveat) (security.Discharge, error) {
var discharge security.Discharge
- err := c.caller.call("MintDischarge", results(&discharge), vdlutil.Any(tp), caveat, additionalCaveats)
+ err := c.caller.call("MintDischarge", results(&discharge), vdl.AnyRep(tp), caveat, additionalCaveats)
if err != nil {
return nil, err
}
diff --git a/security/agent/keymgr/client.go b/security/agent/keymgr/client.go
index 65f175e..b2f34f7 100644
--- a/security/agent/keymgr/client.go
+++ b/security/agent/keymgr/client.go
@@ -7,7 +7,6 @@
"os"
"strconv"
"sync"
- "syscall"
"v.io/core/veyron/lib/unixfd"
"v.io/core/veyron/security/agent/server"
@@ -42,7 +41,6 @@
if err != nil {
return nil, err
}
- syscall.CloseOnExec(int(file.Fd()))
conn, err := net.FileConn(file)
if err != nil {
return nil, err
@@ -91,8 +89,7 @@
}
func (a *Agent) connect(req []byte) (*os.File, error) {
- // We're passing this to a child, so no CLOEXEC.
- addr, err := unixfd.SendConnection(a.conn, req, false)
+ addr, err := unixfd.SendConnection(a.conn, req)
if err != nil {
return nil, err
}
diff --git a/security/agent/keymgr/keymgr_test.go b/security/agent/keymgr/keymgr_test.go
index 422767a..b78c454 100644
--- a/security/agent/keymgr/keymgr_test.go
+++ b/security/agent/keymgr/keymgr_test.go
@@ -14,7 +14,6 @@
"v.io/core/veyron2"
"v.io/core/veyron2/context"
- "v.io/core/veyron2/rt"
"v.io/core/veyron2/security"
)
@@ -40,13 +39,10 @@
}
func TestNoDeviceManager(t *testing.T) {
- runtime, err := rt.New()
- if err != nil {
- t.Fatalf("Could not initialize runtime: %s", err)
- }
- defer runtime.Cleanup()
+ ctx, shutdown := veyron2.Init()
+ defer shutdown()
- agent, cleanup, err := createAgent(runtime.NewContext(), "")
+ agent, cleanup, err := createAgent(ctx, "")
defer cleanup()
if err == nil {
t.Fatal(err)
@@ -75,12 +71,8 @@
}
func TestSigning(t *testing.T) {
- runtime, err := rt.New()
- if err != nil {
- t.Fatalf("Could not initialize runtime: %s", err)
- }
- defer runtime.Cleanup()
- ctx := runtime.NewContext()
+ ctx, shutdown := veyron2.Init()
+ defer shutdown()
path, err := ioutil.TempDir("", "agent")
if err != nil {
@@ -146,12 +138,8 @@
}
func TestInMemorySigning(t *testing.T) {
- runtime, err := rt.New()
- if err != nil {
- t.Fatalf("Could not initialize runtime: %s", err)
- }
- defer runtime.Cleanup()
- ctx := runtime.NewContext()
+ ctx, shutdown := veyron2.Init()
+ defer shutdown()
path, err := ioutil.TempDir("", "agent")
if err != nil {
@@ -163,7 +151,7 @@
t.Fatal(err)
}
- id, conn, err := agent.NewPrincipal(runtime.NewContext(), true)
+ id, conn, err := agent.NewPrincipal(ctx, true)
if err != nil {
t.Fatal(err)
}
diff --git a/security/agent/pingpong/main.go b/security/agent/pingpong/main.go
index 8bc1354..532edd9 100644
--- a/security/agent/pingpong/main.go
+++ b/security/agent/pingpong/main.go
@@ -7,9 +7,7 @@
"v.io/core/veyron2"
"v.io/core/veyron2/context"
"v.io/core/veyron2/ipc"
- "v.io/core/veyron2/rt"
"v.io/core/veyron2/security"
- "v.io/core/veyron2/vlog"
"v.io/core/veyron/lib/signals"
_ "v.io/core/veyron/profiles"
@@ -67,13 +65,8 @@
func main() {
flag.Parse()
- runtime, err := rt.New()
- if err != nil {
- vlog.Fatalf("Could not initialize runtime: %s", err)
- }
- defer runtime.Cleanup()
-
- ctx := runtime.NewContext()
+ ctx, shutdown := veyron2.Init()
+ defer shutdown()
if *runServer {
serverMain(ctx)
diff --git a/security/agent/server/server.go b/security/agent/server/server.go
index 808b5a5..7175a57 100644
--- a/security/agent/server/server.go
+++ b/security/agent/server/server.go
@@ -22,7 +22,7 @@
"v.io/core/veyron2/ipc"
"v.io/core/veyron2/options"
"v.io/core/veyron2/security"
- "v.io/core/veyron2/vdl/vdlutil"
+ "v.io/core/veyron2/vdl"
verror "v.io/core/veyron2/verror2"
"v.io/core/veyron2/vlog"
)
@@ -253,7 +253,7 @@
return a.principal.Sign(message)
}
-func (a agentd) MintDischarge(_ ipc.ServerContext, tp vdlutil.Any, caveat security.Caveat, additionalCaveats []security.Caveat) (vdlutil.Any, error) {
+func (a agentd) MintDischarge(_ ipc.ServerContext, tp vdl.AnyRep, caveat security.Caveat, additionalCaveats []security.Caveat) (vdl.AnyRep, error) {
tpCaveat, ok := tp.(security.ThirdPartyCaveat)
if !ok {
return nil, fmt.Errorf("provided caveat of type %T does not implement security.ThirdPartyCaveat", tp)
diff --git a/security/agent/server/wire.vdl.go b/security/agent/server/wire.vdl.go
index ddd4eab..4a8922a 100644
--- a/security/agent/server/wire.vdl.go
+++ b/security/agent/server/wire.vdl.go
@@ -10,7 +10,7 @@
__veyron2 "v.io/core/veyron2"
__context "v.io/core/veyron2/context"
__ipc "v.io/core/veyron2/ipc"
- __vdlutil "v.io/core/veyron2/vdl/vdlutil"
+ __vdl "v.io/core/veyron2/vdl"
)
// AgentClientMethods is the client interface
@@ -19,7 +19,7 @@
Bless(ctx *__context.T, key []byte, wit security.WireBlessings, extension string, caveat security.Caveat, additionalCaveats []security.Caveat, opts ...__ipc.CallOpt) (security.WireBlessings, error)
BlessSelf(ctx *__context.T, name string, caveats []security.Caveat, opts ...__ipc.CallOpt) (security.WireBlessings, error)
Sign(ctx *__context.T, message []byte, opts ...__ipc.CallOpt) (security.Signature, error)
- MintDischarge(ctx *__context.T, tp __vdlutil.Any, caveat security.Caveat, additionalCaveats []security.Caveat, opts ...__ipc.CallOpt) (__vdlutil.Any, error)
+ MintDischarge(ctx *__context.T, tp __vdl.AnyRep, caveat security.Caveat, additionalCaveats []security.Caveat, opts ...__ipc.CallOpt) (__vdl.AnyRep, error)
PublicKey(*__context.T, ...__ipc.CallOpt) ([]byte, error)
BlessingsByName(ctx *__context.T, name security.BlessingPattern, opts ...__ipc.CallOpt) ([]security.WireBlessings, error)
BlessingsInfo(ctx *__context.T, blessings security.WireBlessings, opts ...__ipc.CallOpt) (map[string][]security.Caveat, error)
@@ -97,7 +97,7 @@
return
}
-func (c implAgentClientStub) MintDischarge(ctx *__context.T, i0 __vdlutil.Any, i1 security.Caveat, i2 []security.Caveat, opts ...__ipc.CallOpt) (o0 __vdlutil.Any, err error) {
+func (c implAgentClientStub) MintDischarge(ctx *__context.T, i0 __vdl.AnyRep, i1 security.Caveat, i2 []security.Caveat, opts ...__ipc.CallOpt) (o0 __vdl.AnyRep, err error) {
var call __ipc.Call
if call, err = c.c(ctx).StartCall(ctx, c.name, "MintDischarge", []interface{}{i0, i1, i2}, opts...); err != nil {
return
@@ -257,7 +257,7 @@
Bless(ctx __ipc.ServerContext, key []byte, wit security.WireBlessings, extension string, caveat security.Caveat, additionalCaveats []security.Caveat) (security.WireBlessings, error)
BlessSelf(ctx __ipc.ServerContext, name string, caveats []security.Caveat) (security.WireBlessings, error)
Sign(ctx __ipc.ServerContext, message []byte) (security.Signature, error)
- MintDischarge(ctx __ipc.ServerContext, tp __vdlutil.Any, caveat security.Caveat, additionalCaveats []security.Caveat) (__vdlutil.Any, error)
+ MintDischarge(ctx __ipc.ServerContext, tp __vdl.AnyRep, caveat security.Caveat, additionalCaveats []security.Caveat) (__vdl.AnyRep, error)
PublicKey(__ipc.ServerContext) ([]byte, error)
BlessingsByName(ctx __ipc.ServerContext, name security.BlessingPattern) ([]security.WireBlessings, error)
BlessingsInfo(ctx __ipc.ServerContext, blessings security.WireBlessings) (map[string][]security.Caveat, error)
@@ -320,7 +320,7 @@
return s.impl.Sign(ctx, i0)
}
-func (s implAgentServerStub) MintDischarge(ctx __ipc.ServerContext, i0 __vdlutil.Any, i1 security.Caveat, i2 []security.Caveat) (__vdlutil.Any, error) {
+func (s implAgentServerStub) MintDischarge(ctx __ipc.ServerContext, i0 __vdl.AnyRep, i1 security.Caveat, i2 []security.Caveat) (__vdl.AnyRep, error) {
return s.impl.MintDischarge(ctx, i0, i1, i2)
}
@@ -430,12 +430,12 @@
{
Name: "MintDischarge",
InArgs: []__ipc.ArgDesc{
- {"tp", ``}, // __vdlutil.Any
+ {"tp", ``}, // __vdl.AnyRep
{"caveat", ``}, // security.Caveat
{"additionalCaveats", ``}, // []security.Caveat
},
OutArgs: []__ipc.ArgDesc{
- {"", ``}, // __vdlutil.Any
+ {"", ``}, // __vdl.AnyRep
{"", ``}, // error
},
},
diff --git a/services/identity/identityd/main.go b/services/identity/identityd/main.go
index e747f34..ebdf5b6 100644
--- a/services/identity/identityd/main.go
+++ b/services/identity/identityd/main.go
@@ -12,10 +12,10 @@
_ "github.com/go-sql-driver/mysql"
- "v.io/core/veyron2/rt"
+ "v.io/core/veyron2"
"v.io/core/veyron2/vlog"
- "v.io/core/veyron/profiles/static"
+ _ "v.io/core/veyron/profiles/static"
"v.io/core/veyron/services/identity/auditor"
"v.io/core/veyron/services/identity/blesser"
"v.io/core/veyron/services/identity/caveats"
@@ -72,13 +72,10 @@
vlog.Fatalf("Failed to start RevocationManager: %v", err)
}
- runtime, err := rt.New()
- if err != nil {
- vlog.Fatalf("Failed to create Runtime: %v", err)
- }
- defer runtime.Cleanup()
- ctx := runtime.NewContext()
+ ctx, shutdown := veyron2.Init()
+ defer shutdown()
+ listenSpec := veyron2.GetListenSpec(ctx)
s := server.NewIdentityServer(
googleoauth,
auditor,
@@ -86,7 +83,7 @@
revocationManager,
googleOAuthBlesserParams(googleoauth, revocationManager),
caveats.NewBrowserCaveatSelector())
- s.Serve(ctx, &static.ListenSpec, *host, *httpaddr, *tlsconfig)
+ s.Serve(ctx, &listenSpec, *host, *httpaddr, *tlsconfig)
}
func usage() {
diff --git a/services/identity/identityd_test/main.go b/services/identity/identityd_test/main.go
index 63ab350..d9c8a23 100644
--- a/services/identity/identityd_test/main.go
+++ b/services/identity/identityd_test/main.go
@@ -7,10 +7,10 @@
"os"
"time"
- "v.io/core/veyron2/rt"
+ "v.io/core/veyron2"
"v.io/core/veyron2/vlog"
- "v.io/core/veyron/profiles/static"
+ _ "v.io/core/veyron/profiles/static"
"v.io/core/veyron/services/identity/auditor"
"v.io/core/veyron/services/identity/blesser"
"v.io/core/veyron/services/identity/caveats"
@@ -58,13 +58,10 @@
RevocationManager: revocationManager,
}
- runtime, err := rt.New()
- if err != nil {
- vlog.Fatalf("Failed to create Runtime: %v", err)
- }
- defer runtime.Cleanup()
- ctx := runtime.NewContext()
+ ctx, shutdown := veyron2.Init()
+ defer shutdown()
+ listenSpec := veyron2.GetListenSpec(ctx)
s := server.NewIdentityServer(
oauthProvider,
auditor,
@@ -72,7 +69,7 @@
revocationManager,
params,
caveats.NewMockCaveatSelector())
- s.Serve(ctx, &static.ListenSpec, *host, *httpaddr, *tlsconfig)
+ s.Serve(ctx, &listenSpec, *host, *httpaddr, *tlsconfig)
}
func usage() {
diff --git a/services/identity/revocation/revocation_test.go b/services/identity/revocation/revocation_test.go
index 0283459..c43b94f 100644
--- a/services/identity/revocation/revocation_test.go
+++ b/services/identity/revocation/revocation_test.go
@@ -3,13 +3,12 @@
import (
"testing"
- "v.io/core/veyron/profiles"
+ _ "v.io/core/veyron/profiles"
services "v.io/core/veyron/services/security"
"v.io/core/veyron/services/security/discharger"
"v.io/core/veyron2"
"v.io/core/veyron2/context"
- "v.io/core/veyron2/rt"
"v.io/core/veyron2/security"
"v.io/core/veyron2/vom"
)
@@ -20,7 +19,7 @@
if err != nil {
t.Fatalf("r.NewServer: %s", err)
}
- dischargerEPs, err := dischargerServer.Listen(profiles.LocalListenSpec)
+ dischargerEPs, err := dischargerServer.Listen(veyron2.GetListenSpec(ctx))
if err != nil {
t.Fatalf("dischargerServer.Listen failed: %v", err)
}
@@ -37,12 +36,8 @@
}
func TestDischargeRevokeDischargeRevokeDischarge(t *testing.T) {
- r, err := rt.New()
- if err != nil {
- t.Fatalf("Could not initialize runtime: %v", err)
- }
- defer r.Cleanup()
- ctx := r.NewContext()
+ ctx, shutdown := veyron2.Init()
+ defer shutdown()
dcKey, dc, revoker, closeFunc := revokerSetup(t, ctx)
defer closeFunc()
@@ -59,19 +54,19 @@
var impetus security.DischargeImpetus
- if _, err = discharger.Discharge(r.NewContext(), cav, impetus); err != nil {
+ if _, err = discharger.Discharge(ctx, cav, impetus); err != nil {
t.Fatalf("failed to get discharge: %s", err)
}
if err = revoker.Revoke(cav.ID()); err != nil {
t.Fatalf("failed to revoke: %s", err)
}
- if discharge, err := discharger.Discharge(r.NewContext(), cav, impetus); err == nil || discharge != nil {
+ if discharge, err := discharger.Discharge(ctx, cav, impetus); err == nil || discharge != nil {
t.Fatalf("got a discharge for a revoked caveat: %s", err)
}
if err = revoker.Revoke(cav.ID()); err != nil {
t.Fatalf("failed to revoke again: %s", err)
}
- if discharge, err := discharger.Discharge(r.NewContext(), cav, impetus); err == nil || discharge != nil {
+ if discharge, err := discharger.Discharge(ctx, cav, impetus); err == nil || discharge != nil {
t.Fatalf("got a discharge for a doubly revoked caveat: %s", err)
}
}
diff --git a/services/mgmt/application/applicationd/main.go b/services/mgmt/application/applicationd/main.go
index aed66ab..7faae65 100644
--- a/services/mgmt/application/applicationd/main.go
+++ b/services/mgmt/application/applicationd/main.go
@@ -4,11 +4,10 @@
"flag"
"v.io/core/veyron2"
- "v.io/core/veyron2/rt"
"v.io/core/veyron2/vlog"
"v.io/core/veyron/lib/signals"
- "v.io/core/veyron/profiles/roaming"
+ _ "v.io/core/veyron/profiles/roaming"
"v.io/core/veyron/services/mgmt/application/impl"
)
@@ -18,17 +17,12 @@
)
func main() {
- flag.Parse()
+ ctx, shutdown := veyron2.Init()
+ defer shutdown()
+
if *store == "" {
vlog.Fatalf("Specify a directory for storing application envelopes using --store=<name>")
}
- runtime, err := rt.New()
- if err != nil {
- vlog.Fatalf("Could not initialize runtime: %v", err)
- }
- defer runtime.Cleanup()
-
- ctx := runtime.NewContext()
server, err := veyron2.NewServer(ctx)
if err != nil {
@@ -41,9 +35,10 @@
vlog.Fatalf("NewDispatcher() failed: %v", err)
}
- endpoints, err := server.Listen(roaming.ListenSpec)
+ ls := veyron2.GetListenSpec(ctx)
+ endpoints, err := server.Listen(ls)
if err != nil {
- vlog.Fatalf("Listen(%s) failed: %v", roaming.ListenSpec, err)
+ vlog.Fatalf("Listen(%s) failed: %v", ls, err)
}
if err := server.ServeDispatcher(*name, dispatcher); err != nil {
vlog.Fatalf("Serve(%v) failed: %v", *name, err)
diff --git a/services/mgmt/application/impl/acl_test.go b/services/mgmt/application/impl/acl_test.go
index 90933ce..34c71c7 100644
--- a/services/mgmt/application/impl/acl_test.go
+++ b/services/mgmt/application/impl/acl_test.go
@@ -10,9 +10,7 @@
"testing"
"v.io/core/veyron2"
- "v.io/core/veyron2/context"
"v.io/core/veyron2/naming"
- "v.io/core/veyron2/rt"
"v.io/core/veyron2/security"
"v.io/core/veyron2/services/mgmt/application"
"v.io/core/veyron2/services/security/access"
@@ -32,20 +30,9 @@
repoCmd = "repository"
)
-var globalCtx *context.T
-var globalCancel context.CancelFunc
-
func init() {
modules.RegisterChild(repoCmd, "", appRepository)
testutil.Init()
-
- globalRT, err := rt.New()
- if err != nil {
- panic(err)
- }
- globalCtx = globalRT.NewContext()
- globalCancel = globalRT.Cleanup
- veyron2.GetNamespace(globalCtx).CacheCtl(naming.DisableCache(true))
}
// TestHelperProcess is the entrypoint for the modules commands in a
@@ -62,10 +49,13 @@
publishName := args[0]
storedir := args[1]
+ ctx, shutdown := veyron2.Init()
+ defer shutdown()
+ veyron2.GetNamespace(ctx).CacheCtl(naming.DisableCache(true))
+
defer fmt.Fprintf(stdout, "%v terminating\n", publishName)
defer vlog.VI(1).Infof("%v terminating", publishName)
- defer globalCancel()
- server, endpoint := mgmttest.NewServer(globalCtx)
+ server, endpoint := mgmttest.NewServer(ctx)
defer server.Stop()
name := naming.JoinAddressName(endpoint, "")
@@ -80,20 +70,24 @@
}
fmt.Fprintf(stdout, "ready:%d\n", os.Getpid())
- <-signals.ShutdownOnSignals(globalCtx)
+ <-signals.ShutdownOnSignals(ctx)
return nil
}
func TestApplicationUpdateACL(t *testing.T) {
- sh, deferFn := mgmttest.CreateShellAndMountTable(t, globalCtx, nil)
+ ctx, shutdown := veyron2.Init()
+ defer shutdown()
+ veyron2.GetNamespace(ctx).CacheCtl(naming.DisableCache(true))
+
+ sh, deferFn := mgmttest.CreateShellAndMountTable(t, ctx, nil)
defer deferFn()
// setup mock up directory to put state in
storedir, cleanup := mgmttest.SetupRootDir(t, "application")
defer cleanup()
- otherCtx, otherCancel := mgmttest.NewRuntime(t, globalCtx)
+ otherCtx, otherCancel := mgmttest.NewRuntime(t, ctx)
defer otherCancel()
idp := tsecurity.NewIDProvider("root")
@@ -101,14 +95,14 @@
// By default, globalRT and otherRT will have blessings generated based on the
// username/machine name running this process. Since these blessings will appear
// in ACLs, give them recognizable names.
- if err := idp.Bless(veyron2.GetPrincipal(globalCtx), "self"); err != nil {
+ if err := idp.Bless(veyron2.GetPrincipal(ctx), "self"); err != nil {
t.Fatal(err)
}
if err := idp.Bless(veyron2.GetPrincipal(otherCtx), "other"); err != nil {
t.Fatal(err)
}
- crDir, crEnv := mgmttest.CredentialsForChild(globalCtx, "repo")
+ crDir, crEnv := mgmttest.CredentialsForChild(ctx, "repo")
defer os.RemoveAll(crDir)
// Make server credentials derived from the test harness.
@@ -133,11 +127,11 @@
}
// Envelope putting as global should succeed.
- if err := v1stub.Put(globalCtx, []string{"base"}, envelopeV1); err != nil {
+ if err := v1stub.Put(ctx, []string{"base"}, envelopeV1); err != nil {
t.Fatalf("Put() failed: %v", err)
}
- acl, etag, err := repostub.GetACL(globalCtx)
+ acl, etag, err := repostub.GetACL(ctx)
if !verror.Is(err, impl.ErrNotFound.ID) {
t.Fatalf("GetACL should have failed with ErrNotFound but was: %v", err)
}
@@ -154,11 +148,11 @@
newACL.Add("root/self", string(tag))
newACL.Add("root/other", string(tag))
}
- if err := repostub.SetACL(globalCtx, newACL, ""); err != nil {
+ if err := repostub.SetACL(ctx, newACL, ""); err != nil {
t.Fatalf("SetACL failed: %v", err)
}
- acl, etag, err = repostub.GetACL(globalCtx)
+ acl, etag, err = repostub.GetACL(ctx)
if err != nil {
t.Fatalf("GetACL should not have failed: %v", err)
}
@@ -185,7 +179,7 @@
}
// Self is now locked out but other isn't.
- if _, _, err = repostub.GetACL(globalCtx); err == nil {
+ if _, _, err = repostub.GetACL(ctx); err == nil {
t.Fatalf("GetACL should not have succeeded")
}
acl, _, err = repostub.GetACL(otherCtx)
@@ -215,28 +209,32 @@
}
func TestPerAppACL(t *testing.T) {
- sh, deferFn := mgmttest.CreateShellAndMountTable(t, globalCtx, nil)
+ ctx, shutdown := veyron2.Init()
+ defer shutdown()
+ veyron2.GetNamespace(ctx).CacheCtl(naming.DisableCache(true))
+
+ sh, deferFn := mgmttest.CreateShellAndMountTable(t, ctx, nil)
defer deferFn()
// setup mock up directory to put state in
storedir, cleanup := mgmttest.SetupRootDir(t, "application")
defer cleanup()
- otherCtx, otherCancel := mgmttest.NewRuntime(t, globalCtx)
+ otherCtx, otherCancel := mgmttest.NewRuntime(t, ctx)
defer otherCancel()
idp := tsecurity.NewIDProvider("root")
// By default, globalRT and otherRT will have blessings generated based on the
// username/machine name running this process. Since these blessings will appear
// in ACLs, give them recognizable names.
- if err := idp.Bless(veyron2.GetPrincipal(globalCtx), "self"); err != nil {
+ if err := idp.Bless(veyron2.GetPrincipal(ctx), "self"); err != nil {
t.Fatal(err)
}
if err := idp.Bless(veyron2.GetPrincipal(otherCtx), "other"); err != nil {
t.Fatal(err)
}
- crDir, crEnv := mgmttest.CredentialsForChild(globalCtx, "repo")
+ crDir, crEnv := mgmttest.CredentialsForChild(ctx, "repo")
defer os.RemoveAll(crDir)
// Make a server with the same credential as test harness.
@@ -253,18 +251,18 @@
// Upload the envelope at two different names.
v1stub := repository.ApplicationClient("repo/search/v1")
- if err := v1stub.Put(globalCtx, []string{"base"}, envelopeV1); err != nil {
+ if err := v1stub.Put(ctx, []string{"base"}, envelopeV1); err != nil {
t.Fatalf("Put() failed: %v", err)
}
v2stub := repository.ApplicationClient("repo/search/v2")
- if err := v2stub.Put(globalCtx, []string{"base"}, envelopeV1); err != nil {
+ if err := v2stub.Put(ctx, []string{"base"}, envelopeV1); err != nil {
t.Fatalf("Put() failed: %v", err)
}
// Self can access ACLs but other can't.
for _, path := range []string{"repo/search", "repo/search/v1", "repo/search/v2"} {
stub := repository.ApplicationClient(path)
- acl, etag, err := stub.GetACL(globalCtx)
+ acl, etag, err := stub.GetACL(ctx)
if !verror.Is(err, impl.ErrNotFound.ID) {
t.Fatalf("GetACL should have failed with ErrNotFound but was: %v", err)
}
@@ -285,7 +283,7 @@
newACL.Add("root/self", string(tag))
newACL.Add("root/other", string(tag))
}
- if err := v1stub.SetACL(globalCtx, newACL, ""); err != nil {
+ if err := v1stub.SetACL(ctx, newACL, ""); err != nil {
t.Fatalf("SetACL failed: %v", err)
}
@@ -330,7 +328,7 @@
newACL.Add("root/self", string(tag))
}
newACL["Write"] = access.ACL{In: []security.BlessingPattern{"root/other", "root/self"}}
- if err := repostub.SetACL(globalCtx, newACL, ""); err != nil {
+ if err := repostub.SetACL(ctx, newACL, ""); err != nil {
t.Fatalf("SetACL failed: %v", err)
}
@@ -351,7 +349,11 @@
}
func TestInitialACLSet(t *testing.T) {
- sh, deferFn := mgmttest.CreateShellAndMountTable(t, globalCtx, nil)
+ ctx, shutdown := veyron2.Init()
+ defer shutdown()
+ veyron2.GetNamespace(ctx).CacheCtl(naming.DisableCache(true))
+
+ sh, deferFn := mgmttest.CreateShellAndMountTable(t, ctx, nil)
defer deferFn()
// Setup mock up directory to put state in.
@@ -361,10 +363,10 @@
idp := tsecurity.NewIDProvider("root")
// Make a recognizable principal name.
- if err := idp.Bless(veyron2.GetPrincipal(globalCtx), "self"); err != nil {
+ if err := idp.Bless(veyron2.GetPrincipal(ctx), "self"); err != nil {
t.Fatal(err)
}
- crDir, crEnv := mgmttest.CredentialsForChild(globalCtx, "repo")
+ crDir, crEnv := mgmttest.CredentialsForChild(ctx, "repo")
defer os.RemoveAll(crDir)
// Make an TAM for use on the command line.
@@ -388,7 +390,7 @@
// It should have the correct starting ACLs from the command line.
stub := repository.ApplicationClient("repo")
- acl, _, err := stub.GetACL(globalCtx)
+ acl, _, err := stub.GetACL(ctx)
if err != nil {
t.Fatalf("GetACL should not have failed: %v", err)
}
diff --git a/services/mgmt/application/impl/impl_test.go b/services/mgmt/application/impl/impl_test.go
index f826e2f..3b8287a 100644
--- a/services/mgmt/application/impl/impl_test.go
+++ b/services/mgmt/application/impl/impl_test.go
@@ -6,6 +6,7 @@
"reflect"
"testing"
+ "v.io/core/veyron2"
"v.io/core/veyron2/naming"
"v.io/core/veyron2/services/mgmt/application"
"v.io/core/veyron2/verror2"
@@ -20,6 +21,9 @@
// TestInterface tests that the implementation correctly implements
// the Application interface.
func TestInterface(t *testing.T) {
+ ctx, shutdown := veyron2.Init()
+ defer shutdown()
+
dir, prefix := "", ""
store, err := ioutil.TempDir(dir, prefix)
if err != nil {
@@ -31,7 +35,7 @@
t.Fatalf("impl.NewDispatcher() failed: %v", err)
}
- server, endpoint := mgmttest.NewServer(globalCtx)
+ server, endpoint := mgmttest.NewServer(ctx)
defer server.Stop()
if err := server.ServeDispatcher("", dispatcher); err != nil {
@@ -56,43 +60,43 @@
}
// Test Put(), adding a number of application envelopes.
- if err := stubV1.Put(globalCtx, []string{"base", "media"}, envelopeV1); err != nil {
+ if err := stubV1.Put(ctx, []string{"base", "media"}, envelopeV1); err != nil {
t.Fatalf("Put() failed: %v", err)
}
- if err := stubV2.Put(globalCtx, []string{"base"}, envelopeV2); err != nil {
+ if err := stubV2.Put(ctx, []string{"base"}, envelopeV2); err != nil {
t.Fatalf("Put() failed: %v", err)
}
- if err := stub.Put(globalCtx, []string{"base", "media"}, envelopeV1); err == nil || !verror2.Is(err, impl.ErrInvalidSuffix.ID) {
+ if err := stub.Put(ctx, []string{"base", "media"}, envelopeV1); err == nil || !verror2.Is(err, impl.ErrInvalidSuffix.ID) {
t.Fatalf("Unexpected error: expected %v, got %v", impl.ErrInvalidSuffix, err)
}
// Test Match(), trying to retrieve both existing and non-existing
// application envelopes.
var output application.Envelope
- if output, err = stubV2.Match(globalCtx, []string{"base", "media"}); err != nil {
+ if output, err = stubV2.Match(ctx, []string{"base", "media"}); err != nil {
t.Fatalf("Match() failed: %v", err)
}
if !reflect.DeepEqual(envelopeV2, output) {
t.Fatalf("Incorrect output: expected %v, got %v", envelopeV2, output)
}
- if output, err = stubV1.Match(globalCtx, []string{"media"}); err != nil {
+ if output, err = stubV1.Match(ctx, []string{"media"}); err != nil {
t.Fatalf("Match() failed: %v", err)
}
if !reflect.DeepEqual(envelopeV1, output) {
t.Fatalf("Unexpected output: expected %v, got %v", envelopeV1, output)
}
- if _, err := stubV2.Match(globalCtx, []string{"media"}); err == nil || !verror2.Is(err, impl.ErrNotFound.ID) {
+ if _, err := stubV2.Match(ctx, []string{"media"}); err == nil || !verror2.Is(err, impl.ErrNotFound.ID) {
t.Fatalf("Unexpected error: expected %v, got %v", impl.ErrNotFound, err)
}
- if _, err := stubV2.Match(globalCtx, []string{}); err == nil || !verror2.Is(err, impl.ErrNotFound.ID) {
+ if _, err := stubV2.Match(ctx, []string{}); err == nil || !verror2.Is(err, impl.ErrNotFound.ID) {
t.Fatalf("Unexpected error: expected %v, got %v", impl.ErrNotFound, err)
}
- if _, err := stub.Match(globalCtx, []string{"media"}); err == nil || !verror2.Is(err, impl.ErrInvalidSuffix.ID) {
+ if _, err := stub.Match(ctx, []string{"media"}); err == nil || !verror2.Is(err, impl.ErrInvalidSuffix.ID) {
t.Fatalf("Unexpected error: expected %v, got %v", impl.ErrInvalidSuffix, err)
}
// Test Glob
- matches, err := testutil.GlobName(globalCtx, naming.JoinAddressName(endpoint, ""), "...")
+ matches, err := testutil.GlobName(ctx, naming.JoinAddressName(endpoint, ""), "...")
if err != nil {
t.Errorf("Unexpected Glob error: %v", err)
}
@@ -108,34 +112,34 @@
// Test Remove(), trying to remove both existing and non-existing
// application envelopes.
- if err := stubV1.Remove(globalCtx, "base"); err != nil {
+ if err := stubV1.Remove(ctx, "base"); err != nil {
t.Fatalf("Remove() failed: %v", err)
}
- if output, err = stubV1.Match(globalCtx, []string{"media"}); err != nil {
+ if output, err = stubV1.Match(ctx, []string{"media"}); err != nil {
t.Fatalf("Match() failed: %v", err)
}
- if err := stubV1.Remove(globalCtx, "base"); err == nil || !verror2.Is(err, impl.ErrNotFound.ID) {
+ if err := stubV1.Remove(ctx, "base"); err == nil || !verror2.Is(err, impl.ErrNotFound.ID) {
t.Fatalf("Unexpected error: expected %v, got %v", impl.ErrNotFound, err)
}
- if err := stub.Remove(globalCtx, "base"); err != nil {
+ if err := stub.Remove(ctx, "base"); err != nil {
t.Fatalf("Remove() failed: %v", err)
}
- if err := stubV2.Remove(globalCtx, "media"); err == nil || !verror2.Is(err, impl.ErrNotFound.ID) {
+ if err := stubV2.Remove(ctx, "media"); err == nil || !verror2.Is(err, impl.ErrNotFound.ID) {
t.Fatalf("Unexpected error: expected %v, got %v", impl.ErrNotFound, err)
}
- if err := stubV1.Remove(globalCtx, "media"); err != nil {
+ if err := stubV1.Remove(ctx, "media"); err != nil {
t.Fatalf("Remove() failed: %v", err)
}
// Finally, use Match() to test that Remove really removed the
// application envelopes.
- if _, err := stubV1.Match(globalCtx, []string{"base"}); err == nil || !verror2.Is(err, impl.ErrNotFound.ID) {
+ if _, err := stubV1.Match(ctx, []string{"base"}); err == nil || !verror2.Is(err, impl.ErrNotFound.ID) {
t.Fatalf("Unexpected error: expected %v, got %v", impl.ErrNotFound, err)
}
- if _, err := stubV1.Match(globalCtx, []string{"media"}); err == nil || !verror2.Is(err, impl.ErrNotFound.ID) {
+ if _, err := stubV1.Match(ctx, []string{"media"}); err == nil || !verror2.Is(err, impl.ErrNotFound.ID) {
t.Fatalf("Unexpected error: expected %v, got %v", impl.ErrNotFound, err)
}
- if _, err := stubV2.Match(globalCtx, []string{"base"}); err == nil || !verror2.Is(err, impl.ErrNotFound.ID) {
+ if _, err := stubV2.Match(ctx, []string{"base"}); err == nil || !verror2.Is(err, impl.ErrNotFound.ID) {
t.Fatalf("Unexpected error: expected %v, got %v", impl.ErrNotFound, err)
}
@@ -146,6 +150,9 @@
}
func TestPreserveAcrossRestarts(t *testing.T) {
+ ctx, shutdown := veyron2.Init()
+ defer shutdown()
+
dir, prefix := "", ""
storedir, err := ioutil.TempDir(dir, prefix)
if err != nil {
@@ -158,8 +165,7 @@
t.Fatalf("impl.NewDispatcher() failed: %v", err)
}
- server, endpoint := mgmttest.NewServer(globalCtx)
- defer server.Stop()
+ server, endpoint := mgmttest.NewServer(ctx)
if err := server.ServeDispatcher("", dispatcher); err != nil {
t.Fatalf("Serve(%v) failed: %v", dispatcher, err)
@@ -175,12 +181,12 @@
Binary: "/veyron/name/of/binary",
}
- if err := stubV1.Put(globalCtx, []string{"media"}, envelopeV1); err != nil {
+ if err := stubV1.Put(ctx, []string{"media"}, envelopeV1); err != nil {
t.Fatalf("Put() failed: %v", err)
}
// There is content here now.
- output, err := stubV1.Match(globalCtx, []string{"media"})
+ output, err := stubV1.Match(ctx, []string{"media"})
if err != nil {
t.Fatalf("Match(%v) failed: %v", "media", err)
}
@@ -196,7 +202,7 @@
t.Fatalf("impl.NewDispatcher() failed: %v", err)
}
- server, endpoint = mgmttest.NewServer(globalCtx)
+ server, endpoint = mgmttest.NewServer(ctx)
defer server.Stop()
if err := server.ServeDispatcher("", dispatcher); err != nil {
@@ -205,7 +211,7 @@
stubV1 = repository.ApplicationClient(naming.JoinAddressName(endpoint, "search/v1"))
- output, err = stubV1.Match(globalCtx, []string{"media"})
+ output, err = stubV1.Match(ctx, []string{"media"})
if err != nil {
t.Fatalf("Match(%v) failed: %v", "media", err)
}
diff --git a/services/mgmt/build/buildd/main.go b/services/mgmt/build/buildd/main.go
index a752edd..52aa663 100644
--- a/services/mgmt/build/buildd/main.go
+++ b/services/mgmt/build/buildd/main.go
@@ -5,12 +5,11 @@
"os"
"v.io/core/veyron2"
- "v.io/core/veyron2/rt"
"v.io/core/veyron2/services/mgmt/build"
"v.io/core/veyron2/vlog"
"v.io/core/veyron/lib/signals"
- "v.io/core/veyron/profiles/roaming"
+ _ "v.io/core/veyron/profiles/roaming"
vflag "v.io/core/veyron/security/flag"
"v.io/core/veyron/services/mgmt/build/impl"
)
@@ -22,24 +21,18 @@
)
func main() {
- flag.Parse()
- runtime, err := rt.New()
- if err != nil {
- vlog.Fatalf("Could not initialize runtime: %v", err)
- }
- defer runtime.Cleanup()
-
- ctx := runtime.NewContext()
+ ctx, shutdown := veyron2.Init()
+ defer shutdown()
server, err := veyron2.NewServer(ctx)
if err != nil {
vlog.Errorf("NewServer() failed: %v", err)
return
}
- defer server.Stop()
- endpoint, err := server.Listen(roaming.ListenSpec)
+ ls := veyron2.GetListenSpec(ctx)
+ endpoint, err := server.Listen(ls)
if err != nil {
- vlog.Errorf("Listen(%s) failed: %v", roaming.ListenSpec, err)
+ vlog.Errorf("Listen(%s) failed: %v", ls, err)
return
}
if err := server.Serve(*name, build.BuilderServer(impl.NewBuilderService(*gobin, *goroot)), vflag.NewAuthorizerOrDie()); err != nil {
diff --git a/services/mgmt/build/impl/impl_test.go b/services/mgmt/build/impl/impl_test.go
index 55eddf2..7c2d84d 100644
--- a/services/mgmt/build/impl/impl_test.go
+++ b/services/mgmt/build/impl/impl_test.go
@@ -10,22 +10,14 @@
"v.io/core/veyron2"
"v.io/core/veyron2/context"
- "v.io/core/veyron2/rt"
"v.io/core/veyron2/services/mgmt/build"
"v.io/core/veyron/lib/testutil"
"v.io/core/veyron/profiles"
)
-var globalCtx *context.T
-
func init() {
testutil.Init()
- globalRT, err := rt.New()
- if err != nil {
- panic(err)
- }
- globalCtx = globalRT.NewContext()
}
// findGoBinary returns the path to the given Go binary and
@@ -54,9 +46,9 @@
}
// startServer starts the build server.
-func startServer(t *testing.T) (build.BuilderClientMethods, func()) {
+func startServer(t *testing.T, ctx *context.T) build.BuilderClientMethods {
gobin, goroot := findGoBinary(t, "go")
- server, err := veyron2.NewServer(globalCtx)
+ server, err := veyron2.NewServer(ctx)
if err != nil {
t.Fatalf("NewServer() failed: %v", err)
}
@@ -69,16 +61,12 @@
t.Fatalf("Serve(%q) failed: %v", unpublished, err)
}
name := "/" + endpoints[0].String()
- return build.BuilderClient(name), func() {
- if err := server.Stop(); err != nil {
- t.Fatalf("Stop() failed: %v", err)
- }
- }
+ return build.BuilderClient(name)
}
-func invokeBuild(t *testing.T, client build.BuilderClientMethods, files []build.File) ([]byte, []build.File, error) {
+func invokeBuild(t *testing.T, ctx *context.T, client build.BuilderClientMethods, files []build.File) ([]byte, []build.File, error) {
arch, opsys := getArch(), getOS()
- ctx, cancel := context.WithCancel(globalCtx)
+ ctx, cancel := context.WithCancel(ctx)
defer cancel()
stream, err := client.Build(ctx, arch, opsys)
if err != nil {
@@ -125,8 +113,10 @@
// TestSuccess checks that the build server successfully builds a
// package that depends on the standard Go library.
func TestSuccess(t *testing.T) {
- client, cleanup := startServer(t)
- defer cleanup()
+ ctx, shutdown := veyron2.Init()
+ defer shutdown()
+
+ client := startServer(t, ctx)
files := []build.File{
build.File{
@@ -134,7 +124,7 @@
Contents: []byte(mainSrc),
},
}
- output, bins, err := invokeBuild(t, client, files)
+ output, bins, err := invokeBuild(t, ctx, client, files)
if err != nil {
t.FailNow()
}
@@ -158,8 +148,10 @@
// TestEmpty checks that the build server successfully builds a
// package that does not produce a binary.
func TestEmpty(t *testing.T) {
- client, cleanup := startServer(t)
- defer cleanup()
+ ctx, shutdown := veyron2.Init()
+ defer shutdown()
+
+ client := startServer(t, ctx)
files := []build.File{
build.File{
@@ -167,7 +159,7 @@
Contents: []byte(fooSrc),
},
}
- output, bins, err := invokeBuild(t, client, files)
+ output, bins, err := invokeBuild(t, ctx, client, files)
if err != nil {
t.FailNow()
}
@@ -191,8 +183,10 @@
// TestFailure checks that the build server fails to build a package
// consisting of an empty file.
func TestFailure(t *testing.T) {
- client, cleanup := startServer(t)
- defer cleanup()
+ ctx, shutdown := veyron2.Init()
+ defer shutdown()
+
+ client := startServer(t, ctx)
files := []build.File{
build.File{
@@ -200,7 +194,7 @@
Contents: []byte(failSrc),
},
}
- if output, _, err := invokeBuild(t, client, files); err == nil {
+ if output, _, err := invokeBuild(t, ctx, client, files); err == nil {
t.Logf("%v", string(output))
t.FailNow()
}
diff --git a/services/mgmt/debug/dispatcher_test.go b/services/mgmt/debug/dispatcher_test.go
index 4aa7b3c..ab7560b 100644
--- a/services/mgmt/debug/dispatcher_test.go
+++ b/services/mgmt/debug/dispatcher_test.go
@@ -16,7 +16,6 @@
"v.io/core/veyron2/context"
"v.io/core/veyron2/ipc"
"v.io/core/veyron2/naming"
- "v.io/core/veyron2/rt"
"v.io/core/veyron2/services/mgmt/logreader"
"v.io/core/veyron2/services/mgmt/stats"
vtracesvc "v.io/core/veyron2/services/mgmt/vtrace"
@@ -50,12 +49,8 @@
}
func TestDebugServer(t *testing.T) {
- runtime, err := rt.New()
- if err != nil {
- t.Fatalf("Could not initialize runtime: %v", err)
- }
- defer runtime.Cleanup()
- ctx := runtime.NewContext()
+ ctx, shutdown := veyron2.Init()
+ defer shutdown()
tracedContext := func(ctx *context.T) *context.T {
ctx, _ = vtrace.SetNewTrace(ctx)
@@ -81,7 +76,7 @@
// Access a logs directory that exists.
{
- results, err := testutil.GlobName(runtime.NewContext(), naming.JoinAddressName(endpoint, "debug/logs"), "*")
+ results, err := testutil.GlobName(ctx, naming.JoinAddressName(endpoint, "debug/logs"), "*")
if err != nil {
t.Errorf("Glob failed: %v", err)
}
@@ -92,7 +87,7 @@
// Access a logs directory that doesn't exist.
{
- results, err := testutil.GlobName(runtime.NewContext(), naming.JoinAddressName(endpoint, "debug/logs/nowheretobefound"), "*")
+ results, err := testutil.GlobName(ctx, naming.JoinAddressName(endpoint, "debug/logs/nowheretobefound"), "*")
if len(results) != 0 {
t.Errorf("unexpected result. Got %v, want ''", results)
}
@@ -149,7 +144,7 @@
// Access vtrace.
{
vt := vtracesvc.StoreClient(naming.JoinAddressName(endpoint, "debug/vtrace"))
- call, err := vt.AllTraces(runtime.NewContext())
+ call, err := vt.AllTraces(ctx)
if err != nil {
t.Errorf("AllTraces failed: %v", err)
}
@@ -169,7 +164,7 @@
// Glob from the root.
{
- ctx, cancel := context.WithTimeout(runtime.NewContext(), 10*time.Second)
+ ctx, cancel := context.WithTimeout(ctx, 10*time.Second)
defer cancel()
ns := veyron2.GetNamespace(ctx)
diff --git a/services/mgmt/device/deviced/commands.go b/services/mgmt/device/deviced/commands.go
index 1689b77..1022747 100644
--- a/services/mgmt/device/deviced/commands.go
+++ b/services/mgmt/device/deviced/commands.go
@@ -7,7 +7,7 @@
"v.io/lib/cmdline"
"v.io/core/veyron/services/mgmt/device/impl"
- "v.io/core/veyron2/rt"
+ "v.io/core/veyron2"
"v.io/core/veyron2/vlog"
)
@@ -118,13 +118,9 @@
}
func runStop(cmd *cmdline.Command, _ []string) error {
- runtime, err := rt.New()
- if err != nil {
- vlog.Errorf("Could not initialize runtime: %v", err)
- return err
- }
- defer runtime.Cleanup()
- if err := impl.Stop(runtime.NewContext(), installationDir(), cmd.Stderr(), cmd.Stdout()); err != nil {
+ ctx, shutdown := veyron2.Init()
+ defer shutdown()
+ if err := impl.Stop(ctx, installationDir(), cmd.Stderr(), cmd.Stdout()); err != nil {
vlog.Errorf("Stop failed: %v", err)
return err
}
diff --git a/services/mgmt/device/deviced/server.go b/services/mgmt/device/deviced/server.go
index 69eef3a..33d7919 100644
--- a/services/mgmt/device/deviced/server.go
+++ b/services/mgmt/device/deviced/server.go
@@ -7,11 +7,10 @@
"v.io/lib/cmdline"
"v.io/core/veyron/lib/signals"
- "v.io/core/veyron/profiles/roaming"
+ _ "v.io/core/veyron/profiles/roaming"
"v.io/core/veyron/services/mgmt/device/config"
"v.io/core/veyron/services/mgmt/device/impl"
"v.io/core/veyron2"
- "v.io/core/veyron2/rt"
"v.io/core/veyron2/vlog"
)
@@ -23,13 +22,8 @@
)
func runServer(*cmdline.Command, []string) error {
- runtime, err := rt.New()
- if err != nil {
- vlog.Errorf("Could not initialize runtime: %v", err)
- return err
- }
- defer runtime.Cleanup()
- ctx := runtime.NewContext()
+ ctx, shutdown := veyron2.Init()
+ defer shutdown()
server, err := veyron2.NewServer(ctx)
if err != nil {
@@ -37,9 +31,10 @@
return err
}
defer server.Stop()
- endpoints, err := server.Listen(roaming.ListenSpec)
+ ls := veyron2.GetListenSpec(ctx)
+ endpoints, err := server.Listen(ls)
if err != nil {
- vlog.Errorf("Listen(%s) failed: %v", roaming.ListenSpec, err)
+ vlog.Errorf("Listen(%s) failed: %v", ls, err)
return err
}
name := endpoints[0].Name()
@@ -65,7 +60,7 @@
return err
}
vlog.VI(0).Infof("Device manager published as: %v", *publishAs)
- impl.InvokeCallback(runtime.NewContext(), name)
+ impl.InvokeCallback(ctx, name)
// Wait until shutdown. Ignore duplicate signals (sent by agent and
// received as part of process group).
diff --git a/services/mgmt/device/impl/impl_test.go b/services/mgmt/device/impl/impl_test.go
index 5037905..4a6fee9 100644
--- a/services/mgmt/device/impl/impl_test.go
+++ b/services/mgmt/device/impl/impl_test.go
@@ -31,8 +31,6 @@
"v.io/core/veyron2/context"
"v.io/core/veyron2/ipc"
"v.io/core/veyron2/naming"
- "v.io/core/veyron2/options"
- "v.io/core/veyron2/rt"
"v.io/core/veyron2/security"
"v.io/core/veyron2/services/mgmt/application"
"v.io/core/veyron2/services/mgmt/device"
@@ -84,31 +82,11 @@
if modules.IsModulesProcess() {
return
}
- initRT(options.RuntimePrincipal{tsecurity.NewPrincipal("test-principal")})
-}
-
-var globalCtx *context.T
-var globalCancel context.CancelFunc
-
-func initRT(opts ...veyron2.ROpt) {
- globalRT, err := rt.New(opts...)
- if err != nil {
- panic(err)
- }
-
- globalCtx = globalRT.NewContext()
- globalCancel = globalRT.Cleanup
-
- // Disable the cache because we will be manipulating/using the namespace
- // across multiple processes and want predictable behaviour without
- // relying on timeouts.
- veyron2.GetNamespace(globalCtx).CacheCtl(naming.DisableCache(true))
}
// TestHelperProcess is the entrypoint for the modules commands in a
// a test subprocess.
func TestHelperProcess(t *testing.T) {
- initRT()
modules.DispatchInTest()
}
@@ -152,17 +130,20 @@
// publish the server under as an argument. Additional arguments can optionally
// specify device manager config settings.
func deviceManager(stdin io.Reader, stdout, stderr io.Writer, env map[string]string, args ...string) error {
+ ctx, shutdown := veyron2.Init()
+
args = args[1:]
if len(args) == 0 {
vlog.Fatalf("deviceManager expected at least an argument")
}
publishName := args[0]
args = args[1:]
- defer fmt.Fprintf(stdout, "%v terminating\n", publishName)
- defer vlog.VI(1).Infof("%v terminating", publishName)
- defer globalCancel()
- server, endpoint := mgmttest.NewServer(globalCtx)
- defer server.Stop()
+ defer fmt.Fprintf(stdout, "%v terminated\n", publishName)
+ defer vlog.VI(1).Infof("%v terminated", publishName)
+ defer shutdown()
+ veyron2.GetNamespace(ctx).CacheCtl(naming.DisableCache(true))
+
+ server, endpoint := mgmttest.NewServer(ctx)
name := naming.JoinAddressName(endpoint, "")
vlog.VI(1).Infof("Device manager name: %v", name)
@@ -183,18 +164,18 @@
}
configState.Root, configState.Helper, configState.Origin, configState.CurrentLink = args[0], args[1], args[2], args[3]
}
- dispatcher, err := impl.NewDispatcher(veyron2.GetPrincipal(globalCtx), configState, func() { fmt.Println("restart handler") })
+ dispatcher, err := impl.NewDispatcher(veyron2.GetPrincipal(ctx), configState, func() { fmt.Println("restart handler") })
if err != nil {
vlog.Fatalf("Failed to create device manager dispatcher: %v", err)
}
if err := server.ServeDispatcher(publishName, dispatcher); err != nil {
vlog.Fatalf("Serve(%v) failed: %v", publishName, err)
}
- impl.InvokeCallback(globalCtx, name)
+ impl.InvokeCallback(ctx, name)
fmt.Fprintf(stdout, "ready:%d\n", os.Getpid())
- <-signals.ShutdownOnSignals(globalCtx)
+ <-signals.ShutdownOnSignals(ctx)
if val, present := env["PAUSE_BEFORE_STOP"]; present && val == "1" {
modules.WaitForEOF(stdin)
@@ -229,7 +210,7 @@
Username, FlagValue, EnvValue string
}
-func ping() {
+func ping(ctx *context.T) {
helperEnv := os.Getenv(suidhelper.SavedArgs)
d := json.NewDecoder(strings.NewReader(helperEnv))
var savedArgs suidhelper.ArgsSavedForTest
@@ -243,18 +224,18 @@
FlagValue: *flagValue,
EnvValue: os.Getenv(testEnvVarName),
}
- client := veyron2.GetClient(globalCtx)
- if call, err := client.StartCall(globalCtx, "pingserver", "Ping", []interface{}{args}); err != nil {
+ client := veyron2.GetClient(ctx)
+ if call, err := client.StartCall(ctx, "pingserver", "Ping", []interface{}{args}); err != nil {
vlog.Fatalf("StartCall failed: %v", err)
} else if err := call.Finish(); err != nil {
vlog.Fatalf("Finish failed: %v", err)
}
}
-func cat(name, file string) (string, error) {
- ctx, cancel := context.WithTimeout(globalCtx, time.Minute)
+func cat(ctx *context.T, name, file string) (string, error) {
+ ctx, cancel := context.WithTimeout(ctx, time.Minute)
defer cancel()
- client := veyron2.GetClient(globalCtx)
+ client := veyron2.GetClient(ctx)
call, err := client.StartCall(ctx, name, "Cat", []interface{}{file})
if err != nil {
return "", err
@@ -267,14 +248,17 @@
}
func app(stdin io.Reader, stdout, stderr io.Writer, env map[string]string, args ...string) error {
+ ctx, shutdown := veyron2.Init()
+ defer shutdown()
+ veyron2.GetNamespace(ctx).CacheCtl(naming.DisableCache(true))
+
args = args[1:]
if expected, got := 1, len(args); expected != got {
vlog.Fatalf("Unexpected number of arguments: expected %d, got %d", expected, got)
}
publishName := args[0]
- defer globalCancel()
- server, _ := mgmttest.NewServer(globalCtx)
+ server, _ := mgmttest.NewServer(ctx)
defer server.Stop()
if err := server.Serve(publishName, new(appService), nil); err != nil {
vlog.Fatalf("Serve(%v) failed: %v", publishName, err)
@@ -282,9 +266,9 @@
// Some of our tests look for log files, so make sure they are flushed
// to ensure that at least the files exist.
vlog.FlushLog()
- ping()
+ ping(ctx)
- <-signals.ShutdownOnSignals(globalCtx)
+ <-signals.ShutdownOnSignals(ctx)
if err := ioutil.WriteFile("testfile", []byte("goodbye world"), 0600); err != nil {
vlog.Fatalf("Failed to write testfile: %v", err)
}
@@ -323,11 +307,19 @@
// command. Further versions are started through the soft link that the device
// manager itself updates.
func TestDeviceManagerUpdateAndRevert(t *testing.T) {
- sh, deferFn := mgmttest.CreateShellAndMountTable(t, globalCtx, veyron2.GetPrincipal(globalCtx))
+ ctx, shutdown := veyron2.Init()
+ defer shutdown()
+ ctx, err := veyron2.SetPrincipal(ctx, tsecurity.NewPrincipal("test-principal"))
+ if err != nil {
+ panic(err)
+ }
+ veyron2.GetNamespace(ctx).CacheCtl(naming.DisableCache(true))
+
+ sh, deferFn := mgmttest.CreateShellAndMountTable(t, ctx, veyron2.GetPrincipal(ctx))
defer deferFn()
// Set up mock application and binary repositories.
- envelope, cleanup := startMockRepos(t)
+ envelope, cleanup := startMockRepos(t, ctx)
defer cleanup()
root, cleanup := mgmttest.SetupRootDir(t, "devicemanager")
@@ -363,21 +355,21 @@
}()
mgmttest.ReadPID(t, dms)
- resolve(t, "factoryDM", 1) // Verify the device manager has published itself.
+ resolve(t, ctx, "factoryDM", 1) // Verify the device manager has published itself.
// Simulate an invalid envelope in the application repository.
*envelope = envelopeFromShell(sh, dmPauseBeforeStopEnv, deviceManagerCmd, "bogus", dmArgs...)
- updateDeviceExpectError(t, "factoryDM", impl.ErrAppTitleMismatch.ID)
- revertDeviceExpectError(t, "factoryDM", impl.ErrUpdateNoOp.ID)
+ updateDeviceExpectError(t, ctx, "factoryDM", impl.ErrAppTitleMismatch.ID)
+ revertDeviceExpectError(t, ctx, "factoryDM", impl.ErrUpdateNoOp.ID)
// Set up a second version of the device manager. The information in the
// envelope will be used by the device manager to stage the next
// version.
- crDir, crEnv := mgmttest.CredentialsForChild(globalCtx, "child")
+ crDir, crEnv := mgmttest.CredentialsForChild(ctx, "child")
defer os.RemoveAll(crDir)
*envelope = envelopeFromShell(sh, crEnv, deviceManagerCmd, application.DeviceManagerTitle, "v2DM")
- updateDevice(t, "factoryDM")
+ updateDevice(t, ctx, "factoryDM")
// Current link should have been updated to point to v2.
evalLink := func() string {
@@ -392,36 +384,36 @@
t.Fatalf("current link didn't change")
}
- updateDeviceExpectError(t, "factoryDM", impl.ErrOperationInProgress.ID)
+ updateDeviceExpectError(t, ctx, "factoryDM", impl.ErrOperationInProgress.ID)
dmh.CloseStdin()
dms.Expect("restart handler")
- dms.Expect("factoryDM terminating")
+ dms.Expect("factoryDM terminated")
dmh.Shutdown(os.Stderr, os.Stderr)
// A successful update means the device manager has stopped itself. We
// relaunch it from the current link.
- resolveExpectNotFound(t, "v2DM") // Ensure a clean slate.
+ resolveExpectNotFound(t, ctx, "v2DM") // Ensure a clean slate.
dmh, dms = mgmttest.RunShellCommand(t, sh, nil, execScriptCmd, currLink)
mgmttest.ReadPID(t, dms)
- resolve(t, "v2DM", 1) // Current link should have been launching v2.
+ resolve(t, ctx, "v2DM", 1) // Current link should have been launching v2.
// Try issuing an update without changing the envelope in the
// application repository: this should fail, and current link should be
// unchanged.
- updateDeviceExpectError(t, "v2DM", impl.ErrUpdateNoOp.ID)
+ updateDeviceExpectError(t, ctx, "v2DM", impl.ErrUpdateNoOp.ID)
if evalLink() != scriptPathV2 {
t.Fatalf("script changed")
}
// Create a third version of the device manager and issue an update.
- crDir, crEnv = mgmttest.CredentialsForChild(globalCtx, "child")
+ crDir, crEnv = mgmttest.CredentialsForChild(ctx, "child")
defer os.RemoveAll(crDir)
*envelope = envelopeFromShell(sh, crEnv, deviceManagerCmd, application.DeviceManagerTitle, "v3DM")
- updateDevice(t, "v2DM")
+ updateDevice(t, ctx, "v2DM")
scriptPathV3 := evalLink()
if scriptPathV3 == scriptPathV2 {
@@ -429,11 +421,11 @@
}
dms.Expect("restart handler")
- dms.Expect("v2DM terminating")
+ dms.Expect("v2DM terminated")
dmh.Shutdown(os.Stderr, os.Stderr)
- resolveExpectNotFound(t, "v3DM") // Ensure a clean slate.
+ resolveExpectNotFound(t, ctx, "v3DM") // Ensure a clean slate.
// Re-lanuch the device manager from current link. We instruct the
// device manager to pause before stopping its server, so that we can
@@ -441,51 +433,51 @@
dmh, dms = mgmttest.RunShellCommand(t, sh, dmPauseBeforeStopEnv, execScriptCmd, currLink)
mgmttest.ReadPID(t, dms)
- resolve(t, "v3DM", 1) // Current link should have been launching v3.
+ resolve(t, ctx, "v3DM", 1) // Current link should have been launching v3.
// Revert the device manager to its previous version (v2).
- revertDevice(t, "v3DM")
- revertDeviceExpectError(t, "v3DM", impl.ErrOperationInProgress.ID) // Revert already in progress.
+ revertDevice(t, ctx, "v3DM")
+ revertDeviceExpectError(t, ctx, "v3DM", impl.ErrOperationInProgress.ID) // Revert already in progress.
dmh.CloseStdin()
dms.Expect("restart handler")
- dms.Expect("v3DM terminating")
+ dms.Expect("v3DM terminated")
if evalLink() != scriptPathV2 {
t.Fatalf("current link was not reverted correctly")
}
dmh.Shutdown(os.Stderr, os.Stderr)
- resolveExpectNotFound(t, "v2DM") // Ensure a clean slate.
+ resolveExpectNotFound(t, ctx, "v2DM") // Ensure a clean slate.
dmh, dms = mgmttest.RunShellCommand(t, sh, nil, execScriptCmd, currLink)
mgmttest.ReadPID(t, dms)
- resolve(t, "v2DM", 1) // Current link should have been launching v2.
+ resolve(t, ctx, "v2DM", 1) // Current link should have been launching v2.
// Revert the device manager to its previous version (factory).
- revertDevice(t, "v2DM")
+ revertDevice(t, ctx, "v2DM")
dms.Expect("restart handler")
- dms.Expect("v2DM terminating")
+ dms.Expect("v2DM terminated")
if evalLink() != scriptPathFactory {
t.Fatalf("current link was not reverted correctly")
}
dmh.Shutdown(os.Stderr, os.Stderr)
- resolveExpectNotFound(t, "factoryDM") // Ensure a clean slate.
+ resolveExpectNotFound(t, ctx, "factoryDM") // Ensure a clean slate.
dmh, dms = mgmttest.RunShellCommand(t, sh, nil, execScriptCmd, currLink)
mgmttest.ReadPID(t, dms)
- resolve(t, "factoryDM", 1) // Current link should have been launching factory version.
- stopDevice(t, "factoryDM")
- dms.Expect("factoryDM terminating")
+ resolve(t, ctx, "factoryDM", 1) // Current link should have been launching factory version.
+ stopDevice(t, ctx, "factoryDM")
+ dms.Expect("factoryDM terminated")
dms.ExpectEOF()
// Re-launch the device manager, to exercise the behavior of Suspend.
- resolveExpectNotFound(t, "factoryDM") // Ensure a clean slate.
+ resolveExpectNotFound(t, ctx, "factoryDM") // Ensure a clean slate.
dmh, dms = mgmttest.RunShellCommand(t, sh, nil, execScriptCmd, currLink)
mgmttest.ReadPID(t, dms)
- resolve(t, "factoryDM", 1)
- suspendDevice(t, "factoryDM")
+ resolve(t, ctx, "factoryDM", 1)
+ suspendDevice(t, ctx, "factoryDM")
dms.Expect("restart handler")
- dms.Expect("factoryDM terminating")
+ dms.Expect("factoryDM terminated")
dms.ExpectEOF()
}
@@ -501,8 +493,8 @@
// setupPingServer creates a server listening for a ping from a child app; it
// returns a channel on which the app's ping message is returned, and a cleanup
// function.
-func setupPingServer(t *testing.T) (<-chan pingArgs, func()) {
- server, _ := mgmttest.NewServer(globalCtx)
+func setupPingServer(t *testing.T, ctx *context.T) (<-chan pingArgs, func()) {
+ server, _ := mgmttest.NewServer(ctx)
pingCh := make(chan pingArgs, 1)
if err := server.Serve("pingserver", pingServer(pingCh), &openAuthorizer{}); err != nil {
t.Fatalf("Serve(%q, <dispatcher>) failed: %v", "pingserver", err)
@@ -560,11 +552,19 @@
// TestAppLifeCycle installs an app, starts it, suspends it, resumes it, and
// then stops it.
func TestAppLifeCycle(t *testing.T) {
- sh, deferFn := mgmttest.CreateShellAndMountTable(t, globalCtx, nil)
+ ctx, shutdown := veyron2.Init()
+ defer shutdown()
+ ctx, err := veyron2.SetPrincipal(ctx, tsecurity.NewPrincipal("test-principal"))
+ if err != nil {
+ panic(err)
+ }
+ veyron2.GetNamespace(ctx).CacheCtl(naming.DisableCache(true))
+
+ sh, deferFn := mgmttest.CreateShellAndMountTable(t, ctx, nil)
defer deferFn()
// Set up mock application and binary repositories.
- envelope, cleanup := startMockRepos(t)
+ envelope, cleanup := startMockRepos(t, ctx)
defer cleanup()
root, cleanup := mgmttest.SetupRootDir(t, "devicemanager")
@@ -573,7 +573,7 @@
// Create a script wrapping the test target that implements suidhelper.
helperPath := generateSuidHelperScript(t, root)
- crDir, crEnv := mgmttest.CredentialsForChild(globalCtx, "devicemanager")
+ crDir, crEnv := mgmttest.CredentialsForChild(ctx, "devicemanager")
defer os.RemoveAll(crDir)
// Set up the device manager. Since we won't do device manager updates,
@@ -582,49 +582,49 @@
mgmttest.ReadPID(t, dms)
// Create the local server that the app uses to let us know it's ready.
- pingCh, cleanup := setupPingServer(t)
+ pingCh, cleanup := setupPingServer(t, ctx)
defer cleanup()
- resolve(t, "pingserver", 1)
+ resolve(t, ctx, "pingserver", 1)
// Create an envelope for a first version of the app.
*envelope = envelopeFromShell(sh, []string{testEnvVarName + "=env-val-envelope"}, appCmd, "google naps", fmt.Sprintf("--%s=flag-val-envelope", testFlagName), "appV1")
// Install the app. The config-specified flag value for testFlagName
// should override the value specified in the envelope above.
- appID := installApp(t, globalCtx, device.Config{testFlagName: "flag-val-install"})
+ appID := installApp(t, ctx, device.Config{testFlagName: "flag-val-install"})
// Start requires the caller to grant a blessing for the app instance.
- if _, err := startAppImpl(t, globalCtx, appID, ""); err == nil || !verror.Is(err, impl.ErrInvalidBlessing.ID) {
+ if _, err := startAppImpl(t, ctx, appID, ""); err == nil || !verror.Is(err, impl.ErrInvalidBlessing.ID) {
t.Fatalf("Start(%v) expected to fail with %v, got %v instead", appID, impl.ErrInvalidBlessing.ID, err)
}
// Start an instance of the app.
- instance1ID := startApp(t, globalCtx, appID)
+ instance1ID := startApp(t, ctx, appID)
// Wait until the app pings us that it's ready.
verifyPingArgs(t, pingCh, userName(t), "flag-val-install", "env-val-envelope")
- v1EP1 := resolve(t, "appV1", 1)[0]
+ v1EP1 := resolve(t, ctx, "appV1", 1)[0]
// Suspend the app instance.
- suspendApp(t, globalCtx, appID, instance1ID)
- resolveExpectNotFound(t, "appV1")
+ suspendApp(t, ctx, appID, instance1ID)
+ resolveExpectNotFound(t, ctx, "appV1")
- resumeApp(t, globalCtx, appID, instance1ID)
+ resumeApp(t, ctx, appID, instance1ID)
verifyPingArgs(t, pingCh, userName(t), "flag-val-install", "env-val-envelope") // Wait until the app pings us that it's ready.
oldV1EP1 := v1EP1
- if v1EP1 = resolve(t, "appV1", 1)[0]; v1EP1 == oldV1EP1 {
+ if v1EP1 = resolve(t, ctx, "appV1", 1)[0]; v1EP1 == oldV1EP1 {
t.Fatalf("Expected a new endpoint for the app after suspend/resume")
}
// Start a second instance.
- instance2ID := startApp(t, globalCtx, appID)
+ instance2ID := startApp(t, ctx, appID)
verifyPingArgs(t, pingCh, userName(t), "flag-val-install", "env-val-envelope") // Wait until the app pings us that it's ready.
// There should be two endpoints mounted as "appV1", one for each
// instance of the app.
- endpoints := resolve(t, "appV1", 2)
+ endpoints := resolve(t, ctx, "appV1", 2)
v1EP2 := endpoints[0]
if endpoints[0] == v1EP1 {
v1EP2 = endpoints[1]
@@ -640,37 +640,37 @@
// running; stop while suspended).
// Suspend the first instance.
- suspendApp(t, globalCtx, appID, instance1ID)
+ suspendApp(t, ctx, appID, instance1ID)
// Only the second instance should still be running and mounted.
- if want, got := v1EP2, resolve(t, "appV1", 1)[0]; want != got {
+ if want, got := v1EP2, resolve(t, ctx, "appV1", 1)[0]; want != got {
t.Fatalf("Resolve(%v): want: %v, got %v", "appV1", want, got)
}
// Updating the installation to itself is a no-op.
- updateAppExpectError(t, appID, impl.ErrUpdateNoOp.ID)
+ updateAppExpectError(t, ctx, appID, impl.ErrUpdateNoOp.ID)
// Updating the installation should not work with a mismatched title.
*envelope = envelopeFromShell(sh, nil, appCmd, "bogus")
- updateAppExpectError(t, appID, impl.ErrAppTitleMismatch.ID)
+ updateAppExpectError(t, ctx, appID, impl.ErrAppTitleMismatch.ID)
// Create a second version of the app and update the app to it.
*envelope = envelopeFromShell(sh, []string{testEnvVarName + "=env-val-envelope"}, appCmd, "google naps", "appV2")
- updateApp(t, globalCtx, appID)
+ updateApp(t, ctx, appID)
// Second instance should still be running.
- if want, got := v1EP2, resolve(t, "appV1", 1)[0]; want != got {
+ if want, got := v1EP2, resolve(t, ctx, "appV1", 1)[0]; want != got {
t.Fatalf("Resolve(%v): want: %v, got %v", "appV1", want, got)
}
// Resume first instance.
- resumeApp(t, globalCtx, appID, instance1ID)
+ resumeApp(t, ctx, appID, instance1ID)
verifyPingArgs(t, pingCh, userName(t), "flag-val-install", "env-val-envelope") // Wait until the app pings us that it's ready.
// Both instances should still be running the first version of the app.
// Check that the mounttable contains two endpoints, one of which is
// v1EP2.
- endpoints = resolve(t, "appV1", 2)
+ endpoints = resolve(t, ctx, "appV1", 2)
if endpoints[0] == v1EP2 {
if endpoints[1] == v1EP2 {
t.Fatalf("Both endpoints are the same")
@@ -680,61 +680,61 @@
}
// Stop first instance.
- stopApp(t, globalCtx, appID, instance1ID)
+ stopApp(t, ctx, appID, instance1ID)
verifyAppWorkspace(t, root, appID, instance1ID)
// Only second instance is still running.
- if want, got := v1EP2, resolve(t, "appV1", 1)[0]; want != got {
+ if want, got := v1EP2, resolve(t, ctx, "appV1", 1)[0]; want != got {
t.Fatalf("Resolve(%v): want: %v, got %v", "appV1", want, got)
}
// Start a third instance.
- instance3ID := startApp(t, globalCtx, appID)
+ instance3ID := startApp(t, ctx, appID)
// Wait until the app pings us that it's ready.
verifyPingArgs(t, pingCh, userName(t), "flag-val-install", "env-val-envelope")
- resolve(t, "appV2", 1)
+ resolve(t, ctx, "appV2", 1)
// Stop second instance.
- stopApp(t, globalCtx, appID, instance2ID)
- resolveExpectNotFound(t, "appV1")
+ stopApp(t, ctx, appID, instance2ID)
+ resolveExpectNotFound(t, ctx, "appV1")
// Stop third instance.
- stopApp(t, globalCtx, appID, instance3ID)
- resolveExpectNotFound(t, "appV2")
+ stopApp(t, ctx, appID, instance3ID)
+ resolveExpectNotFound(t, ctx, "appV2")
// Revert the app.
- revertApp(t, appID)
+ revertApp(t, ctx, appID)
// Start a fourth instance. It should be started from version 1.
- instance4ID := startApp(t, globalCtx, appID)
+ instance4ID := startApp(t, ctx, appID)
verifyPingArgs(t, pingCh, userName(t), "flag-val-install", "env-val-envelope") // Wait until the app pings us that it's ready.
- resolve(t, "appV1", 1)
- stopApp(t, globalCtx, appID, instance4ID)
- resolveExpectNotFound(t, "appV1")
+ resolve(t, ctx, "appV1", 1)
+ stopApp(t, ctx, appID, instance4ID)
+ resolveExpectNotFound(t, ctx, "appV1")
// We are already on the first version, no further revert possible.
- revertAppExpectError(t, appID, impl.ErrUpdateNoOp.ID)
+ revertAppExpectError(t, ctx, appID, impl.ErrUpdateNoOp.ID)
// Uninstall the app.
- uninstallApp(t, appID)
+ uninstallApp(t, ctx, appID)
// Updating the installation should no longer be allowed.
- updateAppExpectError(t, appID, impl.ErrInvalidOperation.ID)
+ updateAppExpectError(t, ctx, appID, impl.ErrInvalidOperation.ID)
// Reverting the installation should no longer be allowed.
- revertAppExpectError(t, appID, impl.ErrInvalidOperation.ID)
+ revertAppExpectError(t, ctx, appID, impl.ErrInvalidOperation.ID)
// Starting new instances should no longer be allowed.
- startAppExpectError(t, globalCtx, appID, impl.ErrInvalidOperation.ID)
+ startAppExpectError(t, ctx, appID, impl.ErrInvalidOperation.ID)
// Cleanly shut down the device manager.
syscall.Kill(dmh.Pid(), syscall.SIGINT)
- dms.Expect("dm terminating")
+ dms.Expect("dm terminated")
dms.ExpectEOF()
}
-func startRealBinaryRepository(t *testing.T) func() {
+func startRealBinaryRepository(t *testing.T, ctx *context.T) func() {
rootDir, err := binaryimpl.SetupRootDir("")
if err != nil {
t.Fatalf("binaryimpl.SetupRootDir failed: %v", err)
@@ -743,9 +743,9 @@
if err != nil {
t.Fatalf("binaryimpl.NewState failed: %v", err)
}
- server, _ := mgmttest.NewServer(globalCtx)
+ server, _ := mgmttest.NewServer(ctx)
name := "realbin"
- d, err := binaryimpl.NewDispatcher(veyron2.GetPrincipal(globalCtx), state)
+ d, err := binaryimpl.NewDispatcher(veyron2.GetPrincipal(ctx), state)
if err != nil {
t.Fatalf("server.NewDispatcher failed: %v", err)
}
@@ -761,7 +761,7 @@
if err := ioutil.WriteFile(filepath.Join(tmpdir, "hello.txt"), []byte("Hello World!"), 0600); err != nil {
t.Fatalf("ioutil.WriteFile failed: %v", err)
}
- if err := libbinary.UploadFromDir(globalCtx, naming.Join(name, "testpkg"), tmpdir); err != nil {
+ if err := libbinary.UploadFromDir(ctx, naming.Join(name, "testpkg"), tmpdir); err != nil {
t.Fatalf("libbinary.UploadFromDir failed: %v", err)
}
return func() {
@@ -777,17 +777,25 @@
// TestDeviceManagerClaim claims a devicemanager and tests ACL permissions on
// its methods.
func TestDeviceManagerClaim(t *testing.T) {
- sh, deferFn := mgmttest.CreateShellAndMountTable(t, globalCtx, nil)
+ ctx, shutdown := veyron2.Init()
+ defer shutdown()
+ ctx, err := veyron2.SetPrincipal(ctx, tsecurity.NewPrincipal("test-principal"))
+ if err != nil {
+ panic(err)
+ }
+ veyron2.GetNamespace(ctx).CacheCtl(naming.DisableCache(true))
+
+ sh, deferFn := mgmttest.CreateShellAndMountTable(t, ctx, nil)
defer deferFn()
// Set up mock application and binary repositories.
- envelope, cleanup := startMockRepos(t)
+ envelope, cleanup := startMockRepos(t, ctx)
defer cleanup()
root, cleanup := mgmttest.SetupRootDir(t, "devicemanager")
defer cleanup()
- crDir, crEnv := mgmttest.CredentialsForChild(globalCtx, "devicemanager")
+ crDir, crEnv := mgmttest.CredentialsForChild(ctx, "devicemanager")
defer os.RemoveAll(crDir)
// Create a script wrapping the test target that implements suidhelper.
@@ -802,10 +810,15 @@
*envelope = envelopeFromShell(sh, nil, appCmd, "google naps", "trapp")
deviceStub := device.DeviceClient("dm/device")
- claimantCtx, claimantCancel := mgmttest.NewRuntime(t, globalCtx, options.RuntimePrincipal{tsecurity.NewPrincipal("claimant")})
- defer claimantCancel()
- octx, otherCancel := mgmttest.NewRuntime(t, globalCtx, options.RuntimePrincipal{tsecurity.NewPrincipal("other")})
- defer otherCancel()
+
+ claimantCtx, err := veyron2.SetPrincipal(ctx, tsecurity.NewPrincipal("claimant"))
+ if err != nil {
+ t.Fatalf("Could not create claimant principal: %v", err)
+ }
+ octx, err := veyron2.SetPrincipal(ctx, tsecurity.NewPrincipal("other"))
+ if err != nil {
+ t.Fatalf("Could not create other principal: %v", err)
+ }
// Devicemanager should have open ACLs before we claim it and so an
// Install from octx should succeed.
@@ -824,7 +837,7 @@
installAppExpectError(t, octx, verror.NoAccess.ID)
// Create the local server that the app uses to let us know it's ready.
- pingCh, cleanup := setupPingServer(t)
+ pingCh, cleanup := setupPingServer(t, ctx)
defer cleanup()
// Start an instance of the app.
@@ -836,34 +849,43 @@
case <-time.After(pingTimeout):
t.Fatalf("failed to get ping")
}
- resolve(t, "trapp", 1)
+ resolve(t, ctx, "trapp", 1)
suspendApp(t, claimantCtx, appID, instanceID)
// TODO(gauthamt): Test that ACLs persist across devicemanager restarts
}
func TestDeviceManagerUpdateACL(t *testing.T) {
- sh, deferFn := mgmttest.CreateShellAndMountTable(t, globalCtx, nil)
+ ctx, shutdown := veyron2.Init()
+ defer shutdown()
+ ctx, err := veyron2.SetPrincipal(ctx, tsecurity.NewPrincipal("test-principal"))
+ if err != nil {
+ panic(err)
+ }
+ veyron2.GetNamespace(ctx).CacheCtl(naming.DisableCache(true))
+
+ sh, deferFn := mgmttest.CreateShellAndMountTable(t, ctx, nil)
defer deferFn()
// Set up mock application and binary repositories.
- envelope, cleanup := startMockRepos(t)
+ envelope, cleanup := startMockRepos(t, ctx)
defer cleanup()
root, cleanup := mgmttest.SetupRootDir(t, "devicemanager")
defer cleanup()
- var (
- idp = tsecurity.NewIDProvider("root")
- // The two "processes"/runtimes which will act as IPC clients to
- // the devicemanager process.
- selfCtx = globalCtx
- octx, ocancel = mgmttest.NewRuntime(t, globalCtx)
- )
- defer ocancel()
+ // The two "processes"/runtimes which will act as IPC clients to
+ // the devicemanager process.
+ selfCtx := ctx
+ octx, err := veyron2.SetPrincipal(ctx, tsecurity.NewPrincipal())
+ if err != nil {
+ t.Fatalf("Could not create other principal: %v", err)
+ }
+
// By default, selfCtx and octx will have blessings generated based on
// the username/machine name running this process. Since these blessings
// will appear in ACLs, give them recognizable names.
+ idp := tsecurity.NewIDProvider("root")
if err := idp.Bless(veyron2.GetPrincipal(selfCtx), "self"); err != nil {
t.Fatal(err)
}
@@ -871,7 +893,7 @@
t.Fatal(err)
}
- crDir, crEnv := mgmttest.CredentialsForChild(globalCtx, "devicemanager")
+ crDir, crEnv := mgmttest.CredentialsForChild(ctx, "devicemanager")
defer os.RemoveAll(crDir)
// Set up the device manager. Since we won't do device manager updates,
@@ -945,7 +967,15 @@
// This should bring up a functioning device manager. In the end it runs
// Uninstall and verifies that the installation is gone.
func TestDeviceManagerInstallation(t *testing.T) {
- sh, deferFn := mgmttest.CreateShellAndMountTable(t, globalCtx, nil)
+ ctx, shutdown := veyron2.Init()
+ defer shutdown()
+ ctx, err := veyron2.SetPrincipal(ctx, tsecurity.NewPrincipal("test-principal"))
+ if err != nil {
+ panic(err)
+ }
+ veyron2.GetNamespace(ctx).CacheCtl(naming.DisableCache(true))
+
+ sh, deferFn := mgmttest.CreateShellAndMountTable(t, ctx, nil)
defer deferFn()
testDir, cleanup := mgmttest.SetupRootDir(t, "devicemanager")
defer cleanup()
@@ -967,7 +997,7 @@
t.Fatalf("SelfInstall failed: %v", err)
}
- resolveExpectNotFound(t, "dm")
+ resolveExpectNotFound(t, ctx, "dm")
// Start the device manager.
stdout := make(simpleRW, 100)
if err := impl.Start(dmDir, os.Stderr, stdout); err != nil {
@@ -975,14 +1005,14 @@
}
dms := expect.NewSession(t, stdout, mgmttest.ExpectTimeout)
mgmttest.ReadPID(t, dms)
- resolve(t, "dm", 1)
- revertDeviceExpectError(t, "dm", impl.ErrUpdateNoOp.ID) // No previous version available.
+ resolve(t, ctx, "dm", 1)
+ revertDeviceExpectError(t, ctx, "dm", impl.ErrUpdateNoOp.ID) // No previous version available.
// Stop the device manager.
- if err := impl.Stop(globalCtx, dmDir, os.Stderr, os.Stdout); err != nil {
+ if err := impl.Stop(ctx, dmDir, os.Stderr, os.Stdout); err != nil {
t.Fatalf("Stop failed: %v", err)
}
- dms.Expect("dm terminating")
+ dms.Expect("dm terminated")
// Uninstall.
if err := impl.Uninstall(dmDir, os.Stderr, os.Stdout); err != nil {
@@ -999,17 +1029,25 @@
}
func TestDeviceManagerGlobAndDebug(t *testing.T) {
- sh, deferFn := mgmttest.CreateShellAndMountTable(t, globalCtx, nil)
+ ctx, shutdown := veyron2.Init()
+ defer shutdown()
+ ctx, err := veyron2.SetPrincipal(ctx, tsecurity.NewPrincipal("test-principal"))
+ if err != nil {
+ panic(err)
+ }
+ veyron2.GetNamespace(ctx).CacheCtl(naming.DisableCache(true))
+
+ sh, deferFn := mgmttest.CreateShellAndMountTable(t, ctx, nil)
defer deferFn()
// Set up mock application and binary repositories.
- envelope, cleanup := startMockRepos(t)
+ envelope, cleanup := startMockRepos(t, ctx)
defer cleanup()
root, cleanup := mgmttest.SetupRootDir(t, "devicemanager")
defer cleanup()
- crDir, crEnv := mgmttest.CredentialsForChild(globalCtx, "devicemanager")
+ crDir, crEnv := mgmttest.CredentialsForChild(ctx, "devicemanager")
defer os.RemoveAll(crDir)
// Create a script wrapping the test target that implements suidhelper.
@@ -1022,18 +1060,18 @@
defer syscall.Kill(pid, syscall.SIGINT)
// Create the local server that the app uses to let us know it's ready.
- pingCh, cleanup := setupPingServer(t)
+ pingCh, cleanup := setupPingServer(t, ctx)
defer cleanup()
// Create the envelope for the first version of the app.
*envelope = envelopeFromShell(sh, nil, appCmd, "google naps", "appV1")
// Install the app.
- appID := installApp(t, globalCtx)
+ appID := installApp(t, ctx)
install1ID := path.Base(appID)
// Start an instance of the app.
- instance1ID := startApp(t, globalCtx, appID)
+ instance1ID := startApp(t, ctx, appID)
// Wait until the app pings us that it's ready.
select {
@@ -1042,7 +1080,7 @@
t.Fatalf("failed to get ping")
}
- app2ID := installApp(t, globalCtx)
+ app2ID := installApp(t, ctx)
install2ID := path.Base(app2ID)
testcases := []struct {
@@ -1086,7 +1124,7 @@
logFileRemoveErrorFatalWarningRE := regexp.MustCompile("(ERROR|FATAL|WARNING)")
statsTrimRE := regexp.MustCompile("/stats/(ipc|system(/start-time.*)?)$")
for _, tc := range testcases {
- results, err := testutil.GlobName(globalCtx, tc.name, tc.pattern)
+ results, err := testutil.GlobName(ctx, tc.name, tc.pattern)
if err != nil {
t.Errorf("unexpected glob error for (%q, %q): %v", tc.name, tc.pattern, err)
continue
@@ -1114,7 +1152,7 @@
}
// Call Size() on the log file objects.
- files, err := testutil.GlobName(globalCtx, "dm", "apps/google naps/"+install1ID+"/"+instance1ID+"/logs/*")
+ files, err := testutil.GlobName(ctx, "dm", "apps/google naps/"+install1ID+"/"+instance1ID+"/logs/*")
if err != nil {
t.Errorf("unexpected glob error: %v", err)
}
@@ -1124,13 +1162,13 @@
for _, file := range files {
name := naming.Join("dm", file)
c := logreader.LogFileClient(name)
- if _, err := c.Size(globalCtx); err != nil {
+ if _, err := c.Size(ctx); err != nil {
t.Errorf("Size(%q) failed: %v", name, err)
}
}
// Call Value() on some of the stats objects.
- objects, err := testutil.GlobName(globalCtx, "dm", "apps/google naps/"+install1ID+"/"+instance1ID+"/stats/system/start-time*")
+ objects, err := testutil.GlobName(ctx, "dm", "apps/google naps/"+install1ID+"/"+instance1ID+"/stats/system/start-time*")
if err != nil {
t.Errorf("unexpected glob error: %v", err)
}
@@ -1140,7 +1178,7 @@
for _, obj := range objects {
name := naming.Join("dm", obj)
c := stats.StatsClient(name)
- if _, err := c.Value(globalCtx); err != nil {
+ if _, err := c.Value(ctx); err != nil {
t.Errorf("Value(%q) failed: %v", name, err)
}
}
@@ -1149,7 +1187,7 @@
{
name := "dm/apps/google naps/" + install1ID + "/" + instance1ID + "/pprof"
c := pprof.PProfClient(name)
- v, err := c.CmdLine(globalCtx)
+ v, err := c.CmdLine(ctx)
if err != nil {
t.Errorf("CmdLine(%q) failed: %v", name, err)
}
@@ -1163,19 +1201,27 @@
}
func TestDeviceManagerPackages(t *testing.T) {
- sh, deferFn := mgmttest.CreateShellAndMountTable(t, globalCtx, nil)
+ ctx, shutdown := veyron2.Init()
+ defer shutdown()
+ ctx, err := veyron2.SetPrincipal(ctx, tsecurity.NewPrincipal("test-principal"))
+ if err != nil {
+ panic(err)
+ }
+ veyron2.GetNamespace(ctx).CacheCtl(naming.DisableCache(true))
+
+ sh, deferFn := mgmttest.CreateShellAndMountTable(t, ctx, nil)
defer deferFn()
// Set up mock application and binary repositories.
- envelope, cleanup := startMockRepos(t)
+ envelope, cleanup := startMockRepos(t, ctx)
defer cleanup()
- defer startRealBinaryRepository(t)()
+ defer startRealBinaryRepository(t, ctx)()
root, cleanup := mgmttest.SetupRootDir(t, "devicemanager")
defer cleanup()
- crDir, crEnv := mgmttest.CredentialsForChild(globalCtx, "devicemanager")
+ crDir, crEnv := mgmttest.CredentialsForChild(ctx, "devicemanager")
defer os.RemoveAll(crDir)
// Create a script wrapping the test target that implements suidhelper.
@@ -1188,7 +1234,7 @@
defer syscall.Kill(pid, syscall.SIGINT)
// Create the local server that the app uses to let us know it's ready.
- pingCh, cleanup := setupPingServer(t)
+ pingCh, cleanup := setupPingServer(t, ctx)
defer cleanup()
// Create the envelope for the first version of the app.
@@ -1198,10 +1244,10 @@
}
// Install the app.
- appID := installApp(t, globalCtx)
+ appID := installApp(t, ctx)
// Start an instance of the app.
- startApp(t, globalCtx, appID)
+ startApp(t, ctx, appID)
// Wait until the app pings us that it's ready.
select {
@@ -1213,7 +1259,7 @@
// Ask the app to cat a file from the package.
file := filepath.Join("packages", "test", "hello.txt")
name := "appV1"
- content, err := cat(name, file)
+ content, err := cat(ctx, name, file)
if err != nil {
t.Errorf("cat(%q, %q) failed: %v", name, file, err)
}
@@ -1233,30 +1279,39 @@
// TODO(rjkroege): Verify that associations persist across restarts once
// permanent storage is added.
func TestAccountAssociation(t *testing.T) {
- sh, deferFn := mgmttest.CreateShellAndMountTable(t, globalCtx, nil)
+ ctx, shutdown := veyron2.Init()
+ defer shutdown()
+ ctx, err := veyron2.SetPrincipal(ctx, tsecurity.NewPrincipal("test-principal"))
+ if err != nil {
+ panic(err)
+ }
+ veyron2.GetNamespace(ctx).CacheCtl(naming.DisableCache(true))
+
+ sh, deferFn := mgmttest.CreateShellAndMountTable(t, ctx, nil)
defer deferFn()
root, cleanup := mgmttest.SetupRootDir(t, "devicemanager")
defer cleanup()
- var (
- idp = tsecurity.NewIDProvider("root")
- // The two "processes"/runtimes which will act as IPC clients to
- // the devicemanager process.
- selfCtx = globalCtx
- otherCtx, otherCancel = mgmttest.NewRuntime(t, globalCtx)
- )
- defer otherCancel()
+ // The two "processes"/contexts which will act as IPC clients to
+ // the devicemanager process.
+ selfCtx := ctx
+ otherCtx, err := veyron2.SetPrincipal(ctx, tsecurity.NewPrincipal())
+ if err != nil {
+ t.Fatalf("Could not create other principal: %v", err)
+ }
+
// By default, selfCtx and otherCtx will have blessings generated based
// on the username/machine name running this process. Since these
// blessings will appear in test expecations, give them readable names.
+ idp := tsecurity.NewIDProvider("root")
if err := idp.Bless(veyron2.GetPrincipal(selfCtx), "self"); err != nil {
t.Fatal(err)
}
if err := idp.Bless(veyron2.GetPrincipal(otherCtx), "other"); err != nil {
t.Fatal(err)
}
- crFile, crEnv := mgmttest.CredentialsForChild(globalCtx, "devicemanager")
+ crFile, crEnv := mgmttest.CredentialsForChild(ctx, "devicemanager")
defer os.RemoveAll(crFile)
_, dms := mgmttest.RunShellCommand(t, sh, crEnv, deviceManagerCmd, "dm", root, "unused_helper", "unused_app_repo_name", "unused_curr_link")
@@ -1332,29 +1387,37 @@
}
func TestAppWithSuidHelper(t *testing.T) {
- sh, deferFn := mgmttest.CreateShellAndMountTable(t, globalCtx, nil)
+ ctx, shutdown := veyron2.Init()
+ defer shutdown()
+ ctx, err := veyron2.SetPrincipal(ctx, tsecurity.NewPrincipal("test-principal"))
+ if err != nil {
+ panic(err)
+ }
+ veyron2.GetNamespace(ctx).CacheCtl(naming.DisableCache(true))
+
+ sh, deferFn := mgmttest.CreateShellAndMountTable(t, ctx, nil)
defer deferFn()
// Set up mock application and binary repositories.
- envelope, cleanup := startMockRepos(t)
+ envelope, cleanup := startMockRepos(t, ctx)
defer cleanup()
root, cleanup := mgmttest.SetupRootDir(t, "devicemanager")
defer cleanup()
- var (
- idp = tsecurity.NewIDProvider("root")
- // The two "processes"/runtimes which will act as IPC clients to
- // the devicemanager process.
- selfCtx = globalCtx
- otherCtx, otherCancel = mgmttest.NewRuntime(t, globalCtx)
- )
- defer otherCancel()
+ // The two "processes"/runtimes which will act as IPC clients to
+ // the devicemanager process.
+ selfCtx := ctx
+ otherCtx, err := veyron2.SetPrincipal(ctx, tsecurity.NewPrincipal())
+ if err != nil {
+ t.Fatalf("Could not create other principal: %v", err)
+ }
// By default, selfCtx and otherCtx will have blessings generated based
// on the username/machine name running this process. Since these
// blessings can appear in debugging output, give them recognizable
// names.
+ idp := tsecurity.NewIDProvider("root")
if err := idp.Bless(veyron2.GetPrincipal(selfCtx), "self"); err != nil {
t.Fatal(err)
}
@@ -1362,7 +1425,7 @@
t.Fatal(err)
}
- crDir, crEnv := mgmttest.CredentialsForChild(globalCtx, "devicemanager")
+ crDir, crEnv := mgmttest.CredentialsForChild(ctx, "devicemanager")
defer os.RemoveAll(crDir)
// Create a script wrapping the test target that implements suidhelper.
@@ -1376,7 +1439,7 @@
// Create the local server that the app uses to tell us which system
// name the device manager wished to run it as.
- pingCh, cleanup := setupPingServer(t)
+ pingCh, cleanup := setupPingServer(t, ctx)
defer cleanup()
// Create an envelope for a first version of the app.
diff --git a/services/mgmt/device/impl/mock_repo_test.go b/services/mgmt/device/impl/mock_repo_test.go
index eca07b1..3c9e387 100644
--- a/services/mgmt/device/impl/mock_repo_test.go
+++ b/services/mgmt/device/impl/mock_repo_test.go
@@ -10,6 +10,7 @@
"reflect"
"testing"
+ "v.io/core/veyron2/context"
"v.io/core/veyron2/ipc"
"v.io/core/veyron2/security"
"v.io/core/veyron2/services/mgmt/application"
@@ -25,9 +26,9 @@
const mockBinaryRepoName = "br"
const mockApplicationRepoName = "ar"
-func startMockRepos(t *testing.T) (*application.Envelope, func()) {
- envelope, appCleanup := startApplicationRepository()
- binaryCleanup := startBinaryRepository()
+func startMockRepos(t *testing.T, ctx *context.T) (*application.Envelope, func()) {
+ envelope, appCleanup := startApplicationRepository(ctx)
+ binaryCleanup := startBinaryRepository(ctx)
return envelope, func() {
binaryCleanup()
@@ -38,8 +39,8 @@
// startApplicationRepository sets up a server running the application
// repository. It returns a pointer to the envelope that the repository returns
// to clients (so that it can be changed). It also returns a cleanup function.
-func startApplicationRepository() (*application.Envelope, func()) {
- server, _ := mgmttest.NewServer(globalCtx)
+func startApplicationRepository(ctx *context.T) (*application.Envelope, func()) {
+ server, _ := mgmttest.NewServer(ctx)
invoker := new(arInvoker)
name := mockApplicationRepoName
if err := server.Serve(name, repository.ApplicationServer(invoker), &openAuthorizer{}); err != nil {
@@ -86,8 +87,8 @@
// startBinaryRepository sets up a server running the binary repository and
// returns a cleanup function.
-func startBinaryRepository() func() {
- server, _ := mgmttest.NewServer(globalCtx)
+func startBinaryRepository(ctx *context.T) func() {
+ server, _ := mgmttest.NewServer(ctx)
name := mockBinaryRepoName
if err := server.Serve(name, repository.BinaryServer(new(brInvoker)), &openAuthorizer{}); err != nil {
vlog.Fatalf("Serve(%q) failed: %v", name, err)
diff --git a/services/mgmt/device/impl/util_test.go b/services/mgmt/device/impl/util_test.go
index 4d8be6d..0ac22f6 100644
--- a/services/mgmt/device/impl/util_test.go
+++ b/services/mgmt/device/impl/util_test.go
@@ -44,17 +44,17 @@
}
// resolveExpectNotFound verifies that the given name is not in the mounttable.
-func resolveExpectNotFound(t *testing.T, name string) {
- if me, err := veyron2.GetNamespace(globalCtx).Resolve(globalCtx, name); err == nil {
- t.Fatalf(testutil.FormatLogLine(2, "Resolve(%v) succeeded with results %v when it was expected to fail", name, me.Names()))
+func resolveExpectNotFound(t *testing.T, ctx *context.T, name string) {
+ if me, err := veyron2.GetNamespace(ctx).Resolve(ctx, name); err == nil {
+ t.Fatalf(testutil.FormatLogLine(2, "Resolve(%v) succeeded with results %v when it was expected to fail", name, me.Names))
} else if expectErr := naming.ErrNoSuchName.ID; !verror2.Is(err, expectErr) {
t.Fatalf(testutil.FormatLogLine(2, "Resolve(%v) failed with error %v, expected error ID %v", name, err, expectErr))
}
}
// resolve looks up the given name in the mounttable.
-func resolve(t *testing.T, name string, replicas int) []string {
- me, err := veyron2.GetNamespace(globalCtx).Resolve(globalCtx, name)
+func resolve(t *testing.T, ctx *context.T, name string, replicas int) []string {
+ me, err := veyron2.GetNamespace(ctx).Resolve(ctx, name)
if err != nil {
t.Fatalf("Resolve(%v) failed: %v", name, err)
}
@@ -80,38 +80,38 @@
return device.DeviceClient(deviceName)
}
-func updateDeviceExpectError(t *testing.T, name string, errID verror.ID) {
- if err := deviceStub(name).Update(globalCtx); !verror2.Is(err, errID) {
+func updateDeviceExpectError(t *testing.T, ctx *context.T, name string, errID verror.ID) {
+ if err := deviceStub(name).Update(ctx); !verror2.Is(err, errID) {
t.Fatalf(testutil.FormatLogLine(2, "Update(%v) expected to fail with %v, got %v instead", name, errID, err))
}
}
-func updateDevice(t *testing.T, name string) {
- if err := deviceStub(name).Update(globalCtx); err != nil {
+func updateDevice(t *testing.T, ctx *context.T, name string) {
+ if err := deviceStub(name).Update(ctx); err != nil {
t.Fatalf(testutil.FormatLogLine(2, "Update(%v) failed: %v", name, err))
}
}
-func revertDeviceExpectError(t *testing.T, name string, errID verror.ID) {
- if err := deviceStub(name).Revert(globalCtx); !verror2.Is(err, errID) {
+func revertDeviceExpectError(t *testing.T, ctx *context.T, name string, errID verror.ID) {
+ if err := deviceStub(name).Revert(ctx); !verror2.Is(err, errID) {
t.Fatalf(testutil.FormatLogLine(2, "Revert(%v) expected to fail with %v, got %v instead", name, errID, err))
}
}
-func revertDevice(t *testing.T, name string) {
- if err := deviceStub(name).Revert(globalCtx); err != nil {
+func revertDevice(t *testing.T, ctx *context.T, name string) {
+ if err := deviceStub(name).Revert(ctx); err != nil {
t.Fatalf(testutil.FormatLogLine(2, "Revert(%v) failed: %v", name, err))
}
}
-func stopDevice(t *testing.T, name string) {
- if err := deviceStub(name).Stop(globalCtx, stopTimeout); err != nil {
+func stopDevice(t *testing.T, ctx *context.T, name string) {
+ if err := deviceStub(name).Stop(ctx, stopTimeout); err != nil {
t.Fatalf(testutil.FormatLogLine(1+1, "%s: Stop(%v) failed: %v", name, err))
}
}
-func suspendDevice(t *testing.T, name string) {
- if err := deviceStub(name).Suspend(globalCtx); err != nil {
+func suspendDevice(t *testing.T, ctx *context.T, name string) {
+ if err := deviceStub(name).Suspend(ctx); err != nil {
t.Fatalf(testutil.FormatLogLine(1+1, "%s: Suspend(%v) failed: %v", name, err))
}
}
@@ -217,26 +217,26 @@
}
}
-func updateAppExpectError(t *testing.T, appID string, expectedError verror.ID) {
- if err := appStub(appID).Update(globalCtx); err == nil || !verror2.Is(err, expectedError) {
+func updateAppExpectError(t *testing.T, ctx *context.T, appID string, expectedError verror.ID) {
+ if err := appStub(appID).Update(ctx); err == nil || !verror2.Is(err, expectedError) {
t.Fatalf(testutil.FormatLogLine(2, "Update(%v) expected to fail with %v, got %v instead", appID, expectedError, err))
}
}
-func revertApp(t *testing.T, appID string) {
- if err := appStub(appID).Revert(globalCtx); err != nil {
+func revertApp(t *testing.T, ctx *context.T, appID string) {
+ if err := appStub(appID).Revert(ctx); err != nil {
t.Fatalf(testutil.FormatLogLine(2, "Revert(%v) failed: %v", appID, err))
}
}
-func revertAppExpectError(t *testing.T, appID string, expectedError verror.ID) {
- if err := appStub(appID).Revert(globalCtx); err == nil || !verror2.Is(err, expectedError) {
+func revertAppExpectError(t *testing.T, ctx *context.T, appID string, expectedError verror.ID) {
+ if err := appStub(appID).Revert(ctx); err == nil || !verror2.Is(err, expectedError) {
t.Fatalf(testutil.FormatLogLine(2, "Revert(%v) expected to fail with %v, got %v instead", appID, expectedError, err))
}
}
-func uninstallApp(t *testing.T, appID string) {
- if err := appStub(appID).Uninstall(globalCtx); err != nil {
+func uninstallApp(t *testing.T, ctx *context.T, appID string) {
+ if err := appStub(appID).Uninstall(ctx); err != nil {
t.Fatalf(testutil.FormatLogLine(2, "Uninstall(%v) failed: %v", appID, err))
}
}
diff --git a/services/mgmt/logreader/impl/logfile_test.go b/services/mgmt/logreader/impl/logfile_test.go
index 7f493b0..f4adfc9 100644
--- a/services/mgmt/logreader/impl/logfile_test.go
+++ b/services/mgmt/logreader/impl/logfile_test.go
@@ -13,7 +13,6 @@
"v.io/core/veyron2/context"
"v.io/core/veyron2/ipc"
"v.io/core/veyron2/naming"
- "v.io/core/veyron2/rt"
"v.io/core/veyron2/security"
"v.io/core/veyron2/services/mgmt/logreader"
"v.io/core/veyron2/services/mgmt/logreader/types"
@@ -62,12 +61,8 @@
}
func TestReadLogImplNoFollow(t *testing.T) {
- runtime, err := rt.New()
- if err != nil {
- t.Fatalf("Could not initialize runtime: %v", err)
- }
- defer runtime.Cleanup()
- ctx := runtime.NewContext()
+ ctx, shutdown := veyron2.Init()
+ defer shutdown()
workdir, err := ioutil.TempDir("", "logreadertest")
if err != nil {
@@ -153,12 +148,8 @@
}
func TestReadLogImplWithFollow(t *testing.T) {
- runtime, err := rt.New()
- if err != nil {
- t.Fatalf("Could not initialize runtime: %v", err)
- }
- defer runtime.Cleanup()
- ctx := runtime.NewContext()
+ ctx, shutdown := veyron2.Init()
+ defer shutdown()
workdir, err := ioutil.TempDir("", "logreadertest")
if err != nil {
diff --git a/services/mgmt/pprof/client/proxy.go b/services/mgmt/pprof/client/proxy.go
index a185d0c..7ad3cfb 100644
--- a/services/mgmt/pprof/client/proxy.go
+++ b/services/mgmt/pprof/client/proxy.go
@@ -16,17 +16,18 @@
"strings"
"time"
- "v.io/core/veyron2"
+ "v.io/core/veyron2/context"
"v.io/core/veyron2/services/mgmt/pprof"
+ "v.io/core/veyron2/vtrace"
)
// StartProxy starts the pprof proxy to a remote pprof object.
-func StartProxy(rt veyron2.Runtime, name string) (net.Listener, error) {
+func StartProxy(ctx *context.T, name string) (net.Listener, error) {
listener, err := net.Listen("tcp", "127.0.0.1:0")
if err != nil {
return nil, err
}
- p := &proxy{rt, name}
+ p := &proxy{ctx, name}
mux := http.NewServeMux()
mux.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
w.Header().Add("Location", "/pprof/")
@@ -47,7 +48,7 @@
}
type proxy struct {
- rt veyron2.Runtime
+ ctx *context.T
name string
}
@@ -66,7 +67,8 @@
}
}
c := pprof.PProfClient(p.name)
- profiles, err := c.Profiles(p.rt.NewContext())
+ ctx, _ := vtrace.SetNewTrace(p.ctx)
+ profiles, err := c.Profiles(ctx)
if err != nil {
replyUnavailable(w, err)
return
@@ -83,7 +85,8 @@
w.Header().Set("Content-Type", "text/plain; charset=utf-8")
debug, _ := strconv.Atoi(r.FormValue("debug"))
c := pprof.PProfClient(p.name)
- prof, err := c.Profile(p.rt.NewContext(), name, int32(debug))
+ ctx, _ := vtrace.SetNewTrace(p.ctx)
+ prof, err := c.Profile(ctx, name, int32(debug))
if err != nil {
replyUnavailable(w, err)
return
@@ -113,7 +116,8 @@
}
w.Header().Set("Content-Type", "application/octet-stream")
c := pprof.PProfClient(p.name)
- prof, err := c.CPUProfile(p.rt.NewContext(), int32(sec))
+ ctx, _ := vtrace.SetNewTrace(p.ctx)
+ prof, err := c.CPUProfile(ctx, int32(sec))
if err != nil {
replyUnavailable(w, err)
return
@@ -138,7 +142,8 @@
// cmdLine replies with the command-line arguments of the process.
func (p *proxy) cmdLine(w http.ResponseWriter, r *http.Request) {
c := pprof.PProfClient(p.name)
- cmdline, err := c.CmdLine(p.rt.NewContext())
+ ctx, _ := vtrace.SetNewTrace(p.ctx)
+ cmdline, err := c.CmdLine(ctx)
if err != nil {
replyUnavailable(w, err)
return
@@ -175,7 +180,8 @@
}
}
c := pprof.PProfClient(p.name)
- pcMap, err := c.Symbol(p.rt.NewContext(), pcList)
+ ctx, _ := vtrace.SetNewTrace(p.ctx)
+ pcMap, err := c.Symbol(ctx, pcList)
if err != nil {
replyUnavailable(w, err)
return
diff --git a/services/mgmt/pprof/client/proxy_test.go b/services/mgmt/pprof/client/proxy_test.go
index 174719a..a5c4630 100644
--- a/services/mgmt/pprof/client/proxy_test.go
+++ b/services/mgmt/pprof/client/proxy_test.go
@@ -7,10 +7,9 @@
"testing"
"v.io/core/veyron2"
- "v.io/core/veyron2/rt"
"v.io/core/veyron2/security"
- "v.io/core/veyron/profiles"
+ _ "v.io/core/veyron/profiles"
"v.io/core/veyron/services/mgmt/pprof/client"
"v.io/core/veyron/services/mgmt/pprof/impl"
)
@@ -24,26 +23,22 @@
}
func TestPProfProxy(t *testing.T) {
- r, err := rt.New()
- if err != nil {
- t.Fatalf("Could not initialize runtime: %v", err)
- }
- defer r.Cleanup()
- ctx := r.NewContext()
+ ctx, shutdown := veyron2.Init()
+ defer shutdown()
s, err := veyron2.NewServer(ctx)
if err != nil {
t.Fatalf("failed to start server: %v", err)
}
defer s.Stop()
- endpoints, err := s.Listen(profiles.LocalListenSpec)
+ endpoints, err := s.Listen(veyron2.GetListenSpec(ctx))
if err != nil {
t.Fatalf("failed to listen: %v", err)
}
if err := s.ServeDispatcher("", &dispatcher{impl.NewPProfService()}); err != nil {
t.Fatalf("failed to serve: %v", err)
}
- l, err := client.StartProxy(r, endpoints[0].Name())
+ l, err := client.StartProxy(ctx, endpoints[0].Name())
if err != nil {
t.Fatalf("failed to start proxy: %v", err)
}
diff --git a/services/mgmt/profile/impl/impl_test.go b/services/mgmt/profile/impl/impl_test.go
index 5ed1325..a7dcb40 100644
--- a/services/mgmt/profile/impl/impl_test.go
+++ b/services/mgmt/profile/impl/impl_test.go
@@ -7,9 +7,7 @@
"testing"
"v.io/core/veyron2"
- "v.io/core/veyron2/context"
"v.io/core/veyron2/naming"
- "v.io/core/veyron2/rt"
"v.io/core/veyron2/services/mgmt/build"
"v.io/core/veyron/profiles"
@@ -32,8 +30,11 @@
// TestInterface tests that the implementation correctly implements
// the Profile interface.
func TestInterface(t *testing.T) {
+ ctx, shutdown := veyron2.Init()
+ defer shutdown()
+
// Setup and start the profile repository server.
- server, err := veyron2.NewServer(gctx)
+ server, err := veyron2.NewServer(ctx)
if err != nil {
t.Fatalf("NewServer() failed: %v", err)
}
@@ -63,12 +64,12 @@
stub := repository.ProfileClient(naming.JoinAddressName(endpoint.String(), "linux/base"))
// Put
- if err := stub.Put(gctx, spec); err != nil {
+ if err := stub.Put(ctx, spec); err != nil {
t.Fatalf("Put() failed: %v", err)
}
// Label
- label, err := stub.Label(gctx)
+ label, err := stub.Label(ctx)
if err != nil {
t.Fatalf("Label() failed: %v", err)
}
@@ -77,7 +78,7 @@
}
// Description
- description, err := stub.Description(gctx)
+ description, err := stub.Description(ctx)
if err != nil {
t.Fatalf("Description() failed: %v", err)
}
@@ -86,7 +87,7 @@
}
// Specification
- specification, err := stub.Specification(gctx)
+ specification, err := stub.Specification(ctx)
if err != nil {
t.Fatalf("Specification() failed: %v", err)
}
@@ -95,7 +96,7 @@
}
// Remove
- if err := stub.Remove(gctx); err != nil {
+ if err := stub.Remove(ctx); err != nil {
t.Fatalf("Remove() failed: %v", err)
}
@@ -105,19 +106,12 @@
}
}
-var gctx *context.T
-
-func init() {
- runtime, err := rt.New()
- if err != nil {
- panic(err)
- }
- gctx = runtime.NewContext()
-}
-
func TestPreserveAcrossRestarts(t *testing.T) {
+ ctx, shutdown := veyron2.Init()
+ defer shutdown()
+
// Setup and start the profile repository server.
- server, err := veyron2.NewServer(gctx)
+ server, err := veyron2.NewServer(ctx)
if err != nil {
t.Fatalf("NewServer() failed: %v", err)
}
@@ -147,11 +141,11 @@
// Create client stubs for talking to the server.
stub := repository.ProfileClient(naming.JoinAddressName(endpoint.String(), "linux/base"))
- if err := stub.Put(gctx, spec); err != nil {
+ if err := stub.Put(ctx, spec); err != nil {
t.Fatalf("Put() failed: %v", err)
}
- label, err := stub.Label(gctx)
+ label, err := stub.Label(ctx)
if err != nil {
t.Fatalf("Label() failed: %v", err)
}
@@ -163,7 +157,7 @@
server.Stop()
// Setup and start a second server.
- server, err = veyron2.NewServer(gctx)
+ server, err = veyron2.NewServer(ctx)
if err != nil {
t.Fatalf("NewServer() failed: %v", err)
}
@@ -185,7 +179,7 @@
stub = repository.ProfileClient(naming.JoinAddressName(endpoints[0].String(), "linux/base"))
// Label
- label, err = stub.Label(gctx)
+ label, err = stub.Label(ctx)
if err != nil {
t.Fatalf("Label() failed: %v", err)
}
diff --git a/services/mgmt/profile/profiled/main.go b/services/mgmt/profile/profiled/main.go
index e11d1cb..6a5938d 100644
--- a/services/mgmt/profile/profiled/main.go
+++ b/services/mgmt/profile/profiled/main.go
@@ -4,11 +4,10 @@
"flag"
"v.io/core/veyron2"
- "v.io/core/veyron2/rt"
"v.io/core/veyron2/vlog"
"v.io/core/veyron/lib/signals"
- "v.io/core/veyron/profiles/roaming"
+ _ "v.io/core/veyron/profiles/roaming"
vflag "v.io/core/veyron/security/flag"
"v.io/core/veyron/services/mgmt/profile/impl"
)
@@ -19,32 +18,27 @@
)
func main() {
- flag.Parse()
+ ctx, shutdown := veyron2.Init()
+ defer shutdown()
+
if *store == "" {
vlog.Fatalf("Specify a directory for storing profiles using --store=<name>")
}
- runtime, err := rt.New()
- if err != nil {
- vlog.Fatalf("Could not initialize runtime: %v", err)
- }
- defer runtime.Cleanup()
-
- ctx := runtime.NewContext()
server, err := veyron2.NewServer(ctx)
if err != nil {
vlog.Fatalf("NewServer() failed: %v", err)
}
- defer server.Stop()
dispatcher, err := impl.NewDispatcher(*store, vflag.NewAuthorizerOrDie())
if err != nil {
vlog.Fatalf("NewDispatcher() failed: %v", err)
}
- endpoint, err := server.Listen(roaming.ListenSpec)
+ ls := veyron2.GetListenSpec(ctx)
+ endpoint, err := server.Listen(ls)
if err != nil {
- vlog.Fatalf("Listen(%s) failed: %v", roaming.ListenSpec, err)
+ vlog.Fatalf("Listen(%s) failed: %v", ls, err)
}
if err := server.ServeDispatcher(*name, dispatcher); err != nil {
vlog.Fatalf("ServeDispatcher(%v) failed: %v", *name, err)
diff --git a/services/mgmt/profile/profiled/testdata/integration_test.go b/services/mgmt/profile/profiled/testdata/integration_test.go
index 2dedcc1..d331fd0 100644
--- a/services/mgmt/profile/profiled/testdata/integration_test.go
+++ b/services/mgmt/profile/profiled/testdata/integration_test.go
@@ -104,7 +104,7 @@
// Retrieve the profile specification and check it matches the
// expected specification.
profileSpec := profileCommandOutput(t, env, clientBin, false, "specification", clientCred, profileRepoName, profile)
- if got, want := profileSpec, `profile.Specification{Arch:"amd64", Description:"Example profile to test the profile manager implementation.", Format:"ELF", Libraries:map[profile.Library]struct {}{profile.Library{Name:"foo", MajorVersion:"1", MinorVersion:"0"}:struct {}{}}, Label:"example", OS:"linux"}`; got != want {
+ if got, want := profileSpec, `profile.Specification{Label:"example", Description:"Example profile to test the profile manager implementation.", Arch:"amd64", OS:"linux", Format:"ELF", Libraries:map[profile.Library]struct {}{profile.Library{Name:"foo", MajorVersion:"1", MinorVersion:"0"}:struct {}{}}}`; got != want {
t.Fatalf("unexpected output: got %v, want %v", got, want)
}
diff --git a/services/mgmt/repository/repository.vdl.go b/services/mgmt/repository/repository.vdl.go
index b320b6c..1812a12 100644
--- a/services/mgmt/repository/repository.vdl.go
+++ b/services/mgmt/repository/repository.vdl.go
@@ -18,7 +18,7 @@
__veyron2 "v.io/core/veyron2"
__context "v.io/core/veyron2/context"
__ipc "v.io/core/veyron2/ipc"
- __vdlutil "v.io/core/veyron2/vdl/vdlutil"
+ __vdl "v.io/core/veyron2/vdl"
)
// ApplicationClientMethods is the client interface
@@ -213,7 +213,7 @@
OutArgs: []__ipc.ArgDesc{
{"", ``}, // error
},
- Tags: []__vdlutil.Any{access.Tag("Write")},
+ Tags: []__vdl.AnyRep{access.Tag("Write")},
},
{
Name: "Remove",
@@ -224,7 +224,7 @@
OutArgs: []__ipc.ArgDesc{
{"", ``}, // error
},
- Tags: []__vdlutil.Any{access.Tag("Write")},
+ Tags: []__vdl.AnyRep{access.Tag("Write")},
},
},
}
@@ -413,7 +413,7 @@
{"", ``}, // profile.Specification
{"", ``}, // error
},
- Tags: []__vdlutil.Any{access.Tag("Read")},
+ Tags: []__vdl.AnyRep{access.Tag("Read")},
},
{
Name: "Put",
@@ -424,7 +424,7 @@
OutArgs: []__ipc.ArgDesc{
{"", ``}, // error
},
- Tags: []__vdlutil.Any{access.Tag("Write")},
+ Tags: []__vdl.AnyRep{access.Tag("Write")},
},
{
Name: "Remove",
@@ -432,7 +432,7 @@
OutArgs: []__ipc.ArgDesc{
{"", ``}, // error
},
- Tags: []__vdlutil.Any{access.Tag("Write")},
+ Tags: []__vdl.AnyRep{access.Tag("Write")},
},
},
}
diff --git a/services/mgmt/stats/impl/stats.go b/services/mgmt/stats/impl/stats.go
index ed51f98..c4d2277 100644
--- a/services/mgmt/stats/impl/stats.go
+++ b/services/mgmt/stats/impl/stats.go
@@ -13,7 +13,7 @@
"v.io/core/veyron2/services/mgmt/stats/types"
"v.io/core/veyron2/services/watch"
watchtypes "v.io/core/veyron2/services/watch/types"
- "v.io/core/veyron2/vdl/vdlutil"
+ "v.io/core/veyron2/vdl"
verror "v.io/core/veyron2/verror2"
"v.io/core/veyron2/vlog"
)
@@ -96,7 +96,7 @@
}
// Value returns the value of the receiver object.
-func (i *statsService) Value(ctx ipc.ServerContext) (vdlutil.Any, error) {
+func (i *statsService) Value(ctx ipc.ServerContext) (vdl.AnyRep, error) {
vlog.VI(1).Infof("%v.Value()", i.suffix)
v, err := libstats.Value(i.suffix)
diff --git a/services/mgmt/stats/impl/stats_test.go b/services/mgmt/stats/impl/stats_test.go
index 091586f..f972e83 100644
--- a/services/mgmt/stats/impl/stats_test.go
+++ b/services/mgmt/stats/impl/stats_test.go
@@ -9,7 +9,6 @@
"v.io/core/veyron2"
"v.io/core/veyron2/context"
"v.io/core/veyron2/naming"
- "v.io/core/veyron2/rt"
"v.io/core/veyron2/security"
"v.io/core/veyron2/services/mgmt/stats"
"v.io/core/veyron2/services/watch/types"
@@ -49,9 +48,8 @@
}
func TestStatsImpl(t *testing.T) {
- runtime, _ := rt.New()
- defer runtime.Cleanup()
- ctx := runtime.NewContext()
+ ctx, shutdown := veyron2.Init()
+ defer shutdown()
endpoint, stop := startServer(t, ctx)
defer stop()
diff --git a/services/mgmt/vtrace/impl/vtrace_test.go b/services/mgmt/vtrace/impl/vtrace_test.go
index 1be99a4..3bd0324 100644
--- a/services/mgmt/vtrace/impl/vtrace_test.go
+++ b/services/mgmt/vtrace/impl/vtrace_test.go
@@ -5,10 +5,6 @@
"testing"
"v.io/core/veyron2"
- "v.io/core/veyron2/context"
- "v.io/core/veyron2/ipc"
- "v.io/core/veyron2/naming"
- "v.io/core/veyron2/rt"
service "v.io/core/veyron2/services/mgmt/vtrace"
"v.io/core/veyron2/vtrace"
@@ -16,12 +12,9 @@
"v.io/core/veyron/services/mgmt/vtrace/impl"
)
-func setup(t *testing.T) (string, ipc.Server, *context.T) {
- runtime, err := rt.New()
- if err != nil {
- t.Fatalf("Could not create runtime: %s", err)
- }
- ctx := runtime.NewContext()
+func TestVtraceServer(t *testing.T) {
+ ctx, shutdown := veyron2.Init()
+ defer shutdown()
server, err := veyron2.NewServer(ctx)
if err != nil {
@@ -34,19 +27,13 @@
if err := server.Serve("", impl.NewVtraceService(), nil); err != nil {
t.Fatalf("Serve failed: %s", err)
}
- return endpoints[0].String(), server, ctx
-}
-func TestVtraceServer(t *testing.T) {
- endpoint, server, sctx := setup(t)
- defer server.Stop()
-
- sctx, span := vtrace.SetNewSpan(sctx, "The Span")
+ sctx, span := vtrace.SetNewSpan(ctx, "The Span")
vtrace.ForceCollect(sctx)
span.Finish()
id := span.Trace()
- client := service.StoreClient(naming.JoinAddressName(endpoint, ""))
+ client := service.StoreClient(endpoints[0].Name())
sctx, _ = vtrace.SetNewTrace(sctx)
trace, err := client.Trace(sctx, id)
diff --git a/services/mounttable/lib/mounttable_test.go b/services/mounttable/lib/mounttable_test.go
index 85cb3ff..06a8120 100644
--- a/services/mounttable/lib/mounttable_test.go
+++ b/services/mounttable/lib/mounttable_test.go
@@ -15,19 +15,17 @@
"v.io/core/veyron2/ipc"
"v.io/core/veyron2/naming"
"v.io/core/veyron2/options"
- "v.io/core/veyron2/rt"
"v.io/core/veyron2/security"
"v.io/core/veyron2/services/security/access"
"v.io/core/veyron2/vlog"
"v.io/core/veyron/lib/testutil"
+ tsecurity "v.io/core/veyron/lib/testutil/security"
"v.io/core/veyron/profiles"
)
// Simulate different processes with different runtimes.
// rootCtx is the one running the mounttable service.
-var rootCtx, aliceCtx, bobCtx *context.T
-
const ttlSecs = 60 * 60
func boom(t *testing.T, f string, v ...interface{}) {
@@ -255,7 +253,7 @@
}
}
-func newMT(t *testing.T, acl string) (ipc.Server, string) {
+func newMT(t *testing.T, acl string, rootCtx *context.T) (ipc.Server, string) {
server, err := veyron2.NewServer(rootCtx, options.ServesMountTable(true))
if err != nil {
boom(t, "r.NewServer: %s", err)
@@ -278,7 +276,7 @@
return server, estr
}
-func newCollection(t *testing.T, acl string) (ipc.Server, string) {
+func newCollection(t *testing.T, acl string, rootCtx *context.T) (ipc.Server, string) {
server, err := veyron2.NewServer(rootCtx)
if err != nil {
boom(t, "r.NewServer: %s", err)
@@ -300,9 +298,12 @@
}
func TestMountTable(t *testing.T) {
- mt, mtAddr := newMT(t, "testdata/test.acl")
+ rootCtx, aliceCtx, bobCtx, shutdown := initTest()
+ defer shutdown()
+
+ mt, mtAddr := newMT(t, "testdata/test.acl", rootCtx)
defer mt.Stop()
- collection, collectionAddr := newCollection(t, "testdata/test.acl")
+ collection, collectionAddr := newCollection(t, "testdata/test.acl", rootCtx)
defer collection.Stop()
collectionName := naming.JoinAddressName(collectionAddr, "collection")
@@ -447,7 +448,10 @@
}
func TestGlob(t *testing.T) {
- server, estr := newMT(t, "")
+ rootCtx, shutdown := veyron2.Init()
+ defer shutdown()
+
+ server, estr := newMT(t, "", rootCtx)
defer server.Stop()
// set up a mount space
@@ -491,7 +495,10 @@
}
func TestACLTemplate(t *testing.T) {
- server, estr := newMT(t, "testdata/test.acl")
+ rootCtx, aliceCtx, bobCtx, shutdown := initTest()
+ defer shutdown()
+
+ server, estr := newMT(t, "testdata/test.acl", rootCtx)
defer server.Stop()
fakeServer := naming.JoinAddressName(estr, "quux")
@@ -507,7 +514,10 @@
}
func TestGlobACLs(t *testing.T) {
- server, estr := newMT(t, "testdata/test.acl")
+ rootCtx, aliceCtx, bobCtx, shutdown := initTest()
+ defer shutdown()
+
+ server, estr := newMT(t, "testdata/test.acl", rootCtx)
defer server.Stop()
// set up a mount space
@@ -537,7 +547,10 @@
}
func TestCleanup(t *testing.T) {
- server, estr := newMT(t, "")
+ rootCtx, shutdown := veyron2.Init()
+ defer shutdown()
+
+ server, estr := newMT(t, "", rootCtx)
defer server.Stop()
// Set up one mount.
@@ -561,7 +574,10 @@
}
func TestDelete(t *testing.T) {
- server, estr := newMT(t, "testdata/test.acl")
+ rootCtx, aliceCtx, bobCtx, shutdown := initTest()
+ defer shutdown()
+
+ server, estr := newMT(t, "testdata/test.acl", rootCtx)
defer server.Stop()
// set up a mount space
@@ -585,7 +601,10 @@
}
func TestServerFormat(t *testing.T) {
- server, estr := newMT(t, "")
+ rootCtx, shutdown := veyron2.Init()
+ defer shutdown()
+
+ server, estr := newMT(t, "", rootCtx)
defer server.Stop()
doMount(t, rootCtx, estr, "endpoint", naming.JoinAddressName(estr, "life/on/the/mississippi"), true)
@@ -597,9 +616,12 @@
}
func TestExpiry(t *testing.T) {
- server, estr := newMT(t, "")
+ rootCtx, shutdown := veyron2.Init()
+ defer shutdown()
+
+ server, estr := newMT(t, "", rootCtx)
defer server.Stop()
- collection, collectionAddr := newCollection(t, "testdata/test.acl")
+ collection, collectionAddr := newCollection(t, "testdata/test.acl", rootCtx)
defer collection.Stop()
collectionName := naming.JoinAddressName(collectionAddr, "collection")
@@ -634,24 +656,20 @@
}
}
-func init() {
+func initTest() (rootCtx *context.T, aliceCtx *context.T, bobCtx *context.T, shutdown veyron2.Shutdown) {
testutil.Init()
- // Create the runtime for each of the three "processes"
+ ctx, shutdown := veyron2.Init()
- var rootRT, aliceRT, bobRT veyron2.Runtime
var err error
- if rootRT, err = rt.New(); err != nil {
- panic(err)
+ if rootCtx, err = veyron2.SetPrincipal(ctx, tsecurity.NewPrincipal("root")); err != nil {
+ panic("failed to set root principal")
}
- rootCtx = rootRT.NewContext()
- if aliceRT, err = rt.New(); err != nil {
- panic(err)
+ if aliceCtx, err = veyron2.SetPrincipal(ctx, tsecurity.NewPrincipal("alice")); err != nil {
+ panic("failed to set alice principal")
}
- aliceCtx = aliceRT.NewContext()
- if bobRT, err = rt.New(); err != nil {
- panic(err)
+ if bobCtx, err = veyron2.SetPrincipal(ctx, tsecurity.NewPrincipal("bob")); err != nil {
+ panic("failed to set bob principal")
}
- bobCtx = bobRT.NewContext()
// A hack to set the namespace roots to a value that won't work.
for _, r := range []*context.T{rootCtx, aliceCtx, bobCtx} {
@@ -684,4 +702,6 @@
}
}
}
+
+ return rootCtx, aliceCtx, bobCtx, shutdown
}
diff --git a/services/mounttable/lib/neighborhood.go b/services/mounttable/lib/neighborhood.go
index 0f9103e..f915124 100644
--- a/services/mounttable/lib/neighborhood.go
+++ b/services/mounttable/lib/neighborhood.go
@@ -49,7 +49,9 @@
if addr == nil {
return 0
}
- if addr.Network() != "tcp" {
+ switch addr.Network() {
+ case "tcp", "tcp4", "tcp6", "ws", "ws4", "ws6", "wsh", "wsh4", "wsh6":
+ default:
return 0
}
_, pstr, err := net.SplitHostPort(addr.String())
diff --git a/services/mounttable/lib/neighborhood_test.go b/services/mounttable/lib/neighborhood_test.go
index 6f197d6..b22e724 100644
--- a/services/mounttable/lib/neighborhood_test.go
+++ b/services/mounttable/lib/neighborhood_test.go
@@ -27,6 +27,8 @@
}
func TestNeighborhood(t *testing.T) {
+ rootCtx, shutdown := veyron2.Init()
+ defer shutdown()
vlog.Infof("TestNeighborhood")
server, err := veyron2.NewServer(rootCtx)
if err != nil {
diff --git a/services/mounttable/mounttabled/mounttable.go b/services/mounttable/mounttabled/mounttable.go
index fd8081f..b6d60b9 100644
--- a/services/mounttable/mounttabled/mounttable.go
+++ b/services/mounttable/mounttabled/mounttable.go
@@ -9,11 +9,10 @@
"v.io/core/veyron2"
"v.io/core/veyron2/naming"
"v.io/core/veyron2/options"
- "v.io/core/veyron2/rt"
"v.io/core/veyron2/vlog"
"v.io/core/veyron/lib/signals"
- "v.io/core/veyron/profiles/roaming"
+ _ "v.io/core/veyron/profiles/roaming"
mounttable "v.io/core/veyron/services/mounttable/lib"
)
@@ -24,13 +23,8 @@
)
func main() {
- r, err := rt.New()
- if err != nil {
- vlog.Fatalf("Could not initialize runtime: %v", err)
- }
- defer r.Cleanup()
-
- ctx := r.NewContext()
+ ctx, shutdown := veyron2.Init()
+ defer shutdown()
mtServer, err := veyron2.NewServer(ctx, options.ServesMountTable(true))
if err != nil {
@@ -43,7 +37,8 @@
vlog.Errorf("r.NewMountTable failed: %v", err)
os.Exit(1)
}
- mtEndpoints, err := mtServer.Listen(roaming.ListenSpec)
+ listenSpec := veyron2.GetListenSpec(ctx)
+ mtEndpoints, err := mtServer.Listen(listenSpec)
if err != nil {
vlog.Errorf("mtServer.Listen failed: %v", err)
os.Exit(1)
@@ -58,9 +53,9 @@
vlog.Infof("Mount table service at: %q endpoint: %s", name, mtEndpoint.Name())
if len(*nhName) > 0 {
- neighborhoodListenSpec := roaming.ListenSpec
+ neighborhoodListenSpec := listenSpec
// The ListenSpec code ensures that we have a valid address here.
- host, port, _ := net.SplitHostPort(roaming.ListenSpec.Addrs[0].Address)
+ host, port, _ := net.SplitHostPort(listenSpec.Addrs[0].Address)
if port != "" {
neighborhoodListenSpec.Addrs[0].Address = net.JoinHostPort(host, "0")
}
diff --git a/services/mounttable/mounttabled/test.sh b/services/mounttable/mounttabled/test.sh
index 54d8b98..da912c5 100755
--- a/services/mounttable/mounttabled/test.sh
+++ b/services/mounttable/mounttabled/test.sh
@@ -33,7 +33,7 @@
shell::run_server "${shell_test_DEFAULT_SERVER_TIMEOUT}" "${MTLOG}" "${MTLOG}" \
"${VRUN}" "${MOUNTTABLED_BIN}" --veyron.tcp.address=127.0.0.1:0 -vmodule=publisher=2 --neighborhood_name="${NHNAME}" &> /dev/null \
- || shell_test::fail "line ${LINENO}: failed to start mounttabled"
+ || shell_test::fail "line ${LINENO}: failed to start mounttabled: $(cat ${MTLOG})"
shell::timed_wait_for "${shell_test_DEFAULT_MESSAGE_TIMEOUT}" "${MTLOG}" "ipc pub: mount" \
|| shell_test::fail "line ${LINENO}: failed to mount mounttabled"
EP=$(grep "Mount table service at:" "${MTLOG}" | sed -e 's/^.*endpoint: //') \
diff --git a/services/proxy/proxyd/main.go b/services/proxy/proxyd/main.go
index 6307dd8..63bf175 100644
--- a/services/proxy/proxyd/main.go
+++ b/services/proxy/proxyd/main.go
@@ -10,7 +10,6 @@
"v.io/core/veyron2"
"v.io/core/veyron2/naming"
- "v.io/core/veyron2/rt"
"v.io/core/veyron2/vlog"
_ "v.io/core/veyron/profiles"
@@ -21,7 +20,7 @@
var (
// TODO(rthellend): Remove the protocol and address flags when the config
// manager is working.
- protocol = flag.String("protocol", "tcp", "protocol to listen on")
+ protocol = flag.String("protocol", "wsh", "protocol to listen on")
address = flag.String("address", ":0", "address to listen on")
pubAddress = flag.String("published_address", "", "Network address the proxy publishes. If empty, the value of --address will be used")
@@ -31,12 +30,8 @@
)
func main() {
- r, err := rt.New()
- if err != nil {
- vlog.Fatalf("Could not initialize runtime: %s", err)
- }
- defer r.Cleanup()
- ctx := r.NewContext()
+ ctx, shutdown := veyron2.Init()
+ defer shutdown()
rid, err := naming.NewRoutingID()
if err != nil {
diff --git a/services/security/discharger.vdl.go b/services/security/discharger.vdl.go
index 46805eb..771c5f1 100644
--- a/services/security/discharger.vdl.go
+++ b/services/security/discharger.vdl.go
@@ -10,7 +10,7 @@
__veyron2 "v.io/core/veyron2"
__context "v.io/core/veyron2/context"
__ipc "v.io/core/veyron2/ipc"
- __vdlutil "v.io/core/veyron2/vdl/vdlutil"
+ __vdl "v.io/core/veyron2/vdl"
)
// DischargerClientMethods is the client interface
@@ -26,7 +26,7 @@
// respectively. (not enforced here because vdl does not know these types)
// TODO(ataly,ashankar): Figure out a VDL representation for ThirdPartyCaveat
// and Discharge and use those here?
- Discharge(ctx *__context.T, Caveat __vdlutil.Any, Impetus security.DischargeImpetus, opts ...__ipc.CallOpt) (Discharge __vdlutil.Any, err error)
+ Discharge(ctx *__context.T, Caveat __vdl.AnyRep, Impetus security.DischargeImpetus, opts ...__ipc.CallOpt) (Discharge __vdl.AnyRep, err error)
}
// DischargerClientStub adds universal methods to DischargerClientMethods.
@@ -58,7 +58,7 @@
return __veyron2.GetClient(ctx)
}
-func (c implDischargerClientStub) Discharge(ctx *__context.T, i0 __vdlutil.Any, i1 security.DischargeImpetus, opts ...__ipc.CallOpt) (o0 __vdlutil.Any, err error) {
+func (c implDischargerClientStub) Discharge(ctx *__context.T, i0 __vdl.AnyRep, i1 security.DischargeImpetus, opts ...__ipc.CallOpt) (o0 __vdl.AnyRep, err error) {
var call __ipc.Call
if call, err = c.c(ctx).StartCall(ctx, c.name, "Discharge", []interface{}{i0, i1}, opts...); err != nil {
return
@@ -82,7 +82,7 @@
// respectively. (not enforced here because vdl does not know these types)
// TODO(ataly,ashankar): Figure out a VDL representation for ThirdPartyCaveat
// and Discharge and use those here?
- Discharge(ctx __ipc.ServerContext, Caveat __vdlutil.Any, Impetus security.DischargeImpetus) (Discharge __vdlutil.Any, err error)
+ Discharge(ctx __ipc.ServerContext, Caveat __vdl.AnyRep, Impetus security.DischargeImpetus) (Discharge __vdl.AnyRep, err error)
}
// DischargerServerStubMethods is the server interface containing
@@ -120,7 +120,7 @@
gs *__ipc.GlobState
}
-func (s implDischargerServerStub) Discharge(ctx __ipc.ServerContext, i0 __vdlutil.Any, i1 security.DischargeImpetus) (__vdlutil.Any, error) {
+func (s implDischargerServerStub) Discharge(ctx __ipc.ServerContext, i0 __vdl.AnyRep, i1 security.DischargeImpetus) (__vdl.AnyRep, error) {
return s.impl.Discharge(ctx, i0, i1)
}
@@ -145,11 +145,11 @@
Name: "Discharge",
Doc: "// Discharge is called by a principal that holds a blessing with a third\n// party caveat and seeks to get a discharge that proves the fulfillment of\n// this caveat.\n//\n// Caveat and Discharge are of type ThirdPartyCaveat and Discharge\n// respectively. (not enforced here because vdl does not know these types)\n// TODO(ataly,ashankar): Figure out a VDL representation for ThirdPartyCaveat\n// and Discharge and use those here?",
InArgs: []__ipc.ArgDesc{
- {"Caveat", ``}, // __vdlutil.Any
+ {"Caveat", ``}, // __vdl.AnyRep
{"Impetus", ``}, // security.DischargeImpetus
},
OutArgs: []__ipc.ArgDesc{
- {"Discharge", ``}, // __vdlutil.Any
+ {"Discharge", ``}, // __vdl.AnyRep
{"err", ``}, // error
},
},
diff --git a/services/security/discharger/discharger.go b/services/security/discharger/discharger.go
index dfc4247..86dfbc5 100644
--- a/services/security/discharger/discharger.go
+++ b/services/security/discharger/discharger.go
@@ -7,14 +7,14 @@
services "v.io/core/veyron/services/security"
"v.io/core/veyron2/ipc"
"v.io/core/veyron2/security"
- "v.io/core/veyron2/vdl/vdlutil"
+ "v.io/core/veyron2/vdl"
)
// dischargerd issues discharges for all caveats present in the current
// namespace with no additional caveats iff the caveat is valid.
type dischargerd struct{}
-func (dischargerd) Discharge(ctx ipc.ServerContext, caveatAny vdlutil.Any, _ security.DischargeImpetus) (vdlutil.Any, error) {
+func (dischargerd) Discharge(ctx ipc.ServerContext, caveatAny vdl.AnyRep, _ security.DischargeImpetus) (vdl.AnyRep, error) {
caveat, ok := caveatAny.(security.ThirdPartyCaveat)
if !ok {
return nil, fmt.Errorf("type %T does not implement security.ThirdPartyCaveat", caveatAny)
diff --git a/tools/application/impl.go b/tools/application/impl.go
index 3471add..026f2c3 100644
--- a/tools/application/impl.go
+++ b/tools/application/impl.go
@@ -66,7 +66,7 @@
}
name, profiles := args[0], args[1]
app := repository.ApplicationClient(name)
- ctx, cancel := context.WithTimeout(runtime.NewContext(), time.Minute)
+ ctx, cancel := context.WithTimeout(gctx, time.Minute)
defer cancel()
j, err := getEnvelopeJSON(ctx, app, profiles)
if err != nil {
@@ -98,7 +98,7 @@
if err != nil {
return fmt.Errorf("ReadFile(%v): %v", envelope, err)
}
- ctx, cancel := context.WithTimeout(runtime.NewContext(), time.Minute)
+ ctx, cancel := context.WithTimeout(gctx, time.Minute)
defer cancel()
if err = putEnvelopeJSON(ctx, app, profiles, j); err != nil {
return err
@@ -124,7 +124,7 @@
}
name, profile := args[0], args[1]
app := repository.ApplicationClient(name)
- ctx, cancel := context.WithTimeout(runtime.NewContext(), time.Minute)
+ ctx, cancel := context.WithTimeout(gctx, time.Minute)
defer cancel()
if err := app.Remove(ctx, profile); err != nil {
return err
@@ -158,7 +158,7 @@
f.Close()
defer os.Remove(fileName)
- ctx, cancel := context.WithTimeout(runtime.NewContext(), time.Minute)
+ ctx, cancel := context.WithTimeout(gctx, time.Minute)
defer cancel()
envData, err := getEnvelopeJSON(ctx, app, profile)
if err != nil {
diff --git a/tools/application/impl_test.go b/tools/application/impl_test.go
index 4917d7d..4bd9452 100644
--- a/tools/application/impl_test.go
+++ b/tools/application/impl_test.go
@@ -11,8 +11,6 @@
"v.io/core/veyron2/context"
"v.io/core/veyron2/ipc"
"v.io/core/veyron2/naming"
- "v.io/core/veyron2/options"
- "v.io/core/veyron2/rt"
"v.io/core/veyron2/security"
"v.io/core/veyron2/services/mgmt/application"
"v.io/core/veyron2/services/security/access"
@@ -118,18 +116,15 @@
}
func TestApplicationClient(t *testing.T) {
+ var shutdown veyron2.Shutdown
+ gctx, shutdown = veyron2.Init()
+ defer shutdown()
var err error
- // TODO(ataly, mattr, suharshs): This is a HACK to ensure that the server and the
- // client have the same freshly created principal. One way to avoid the RuntimePrincipal
- // option is to have a global client context.T (in main.go) instead of a veyron2.Runtime.
- runtime, err = rt.New(options.RuntimePrincipal{tsecurity.NewPrincipal("test-blessing")})
- if err != nil {
- t.Fatalf("Unexpected error initializing runtime: %s", err)
+ if gctx, err = veyron2.SetPrincipal(gctx, tsecurity.NewPrincipal("test-blessing")); err != nil {
+ panic(err)
}
- defer runtime.Cleanup()
- ctx := runtime.NewContext()
- server, endpoint, err := startServer(t, ctx)
+ server, endpoint, err := startServer(t, gctx)
if err != nil {
return
}
diff --git a/tools/application/main.go b/tools/application/main.go
index 539e0f3..65f7187 100644
--- a/tools/application/main.go
+++ b/tools/application/main.go
@@ -7,20 +7,17 @@
"os"
"v.io/core/veyron2"
- "v.io/core/veyron2/rt"
+ "v.io/core/veyron2/context"
_ "v.io/core/veyron/profiles"
)
-var runtime veyron2.Runtime
+var gctx *context.T
func main() {
- var err error
- runtime, err = rt.New()
- if err != nil {
- panic(err)
- }
+ var shutdown veyron2.Shutdown
+ gctx, shutdown = veyron2.Init()
exitCode := root().Main()
- runtime.Cleanup()
+ shutdown()
os.Exit(exitCode)
}
diff --git a/tools/binary/impl_test.go b/tools/binary/impl_test.go
index d0f7ca6..28b62b2 100644
--- a/tools/binary/impl_test.go
+++ b/tools/binary/impl_test.go
@@ -15,7 +15,6 @@
"v.io/core/veyron2/context"
"v.io/core/veyron2/ipc"
"v.io/core/veyron2/naming"
- "v.io/core/veyron2/rt"
"v.io/core/veyron2/security"
"v.io/core/veyron2/services/mgmt/binary"
"v.io/core/veyron2/services/mgmt/repository"
@@ -121,12 +120,10 @@
}
func TestBinaryClient(t *testing.T) {
- runtime, err := rt.New()
- if err != nil {
- t.Fatalf("Unexpected error initializing runtime: %s", err)
- }
- defer runtime.Cleanup()
- gctx = runtime.NewContext()
+ var shutdown veyron2.Shutdown
+ gctx, shutdown = veyron2.Init()
+ defer shutdown()
+ var err error
if gctx, err = veyron2.SetPrincipal(gctx, tsecurity.NewPrincipal("test-blessing")); err != nil {
panic(err)
}
diff --git a/tools/binary/main.go b/tools/binary/main.go
index a2b7bfa..65f7187 100644
--- a/tools/binary/main.go
+++ b/tools/binary/main.go
@@ -6,8 +6,8 @@
import (
"os"
+ "v.io/core/veyron2"
"v.io/core/veyron2/context"
- "v.io/core/veyron2/rt"
_ "v.io/core/veyron/profiles"
)
@@ -15,12 +15,9 @@
var gctx *context.T
func main() {
- runtime, err := rt.New()
- if err != nil {
- panic(err)
- }
- gctx = runtime.NewContext()
+ var shutdown veyron2.Shutdown
+ gctx, shutdown = veyron2.Init()
exitCode := root().Main()
- runtime.Cleanup()
+ shutdown()
os.Exit(exitCode)
}
diff --git a/tools/build/impl.go b/tools/build/impl.go
index 2a91d30..b8e0b90 100644
--- a/tools/build/impl.go
+++ b/tools/build/impl.go
@@ -215,7 +215,7 @@
errchan := make(chan error)
defer close(errchan)
- ctx, ctxCancel := context.WithTimeout(runtime.NewContext(), time.Minute)
+ ctx, ctxCancel := context.WithTimeout(gctx, time.Minute)
defer ctxCancel()
// Start all stages of the pipeline.
diff --git a/tools/build/impl_test.go b/tools/build/impl_test.go
index 83e085c..76e1a13 100644
--- a/tools/build/impl_test.go
+++ b/tools/build/impl_test.go
@@ -9,8 +9,6 @@
"v.io/core/veyron2/context"
"v.io/core/veyron2/ipc"
"v.io/core/veyron2/naming"
- "v.io/core/veyron2/options"
- "v.io/core/veyron2/rt"
"v.io/core/veyron2/services/mgmt/binary"
"v.io/core/veyron2/services/mgmt/build"
verror "v.io/core/veyron2/verror2"
@@ -64,16 +62,15 @@
}
func TestBuildClient(t *testing.T) {
+ var shutdown veyron2.Shutdown
+ gctx, shutdown = veyron2.Init()
+ defer shutdown()
var err error
- // TODO(ataly, mattr, suharshs): This is a HACK to ensure that the server and the
- // client have the same freshly created principal. One way to avoid the RuntimePrincipal
- // option is to have a global client context.T (in main.go) instead of a veyron2.Runtime.
- runtime, err = rt.New(options.RuntimePrincipal{tsecurity.NewPrincipal("test-blessing")})
- if err != nil {
- t.Fatalf("Unexpected error initializing runtime: %s", err)
+ if gctx, err = veyron2.SetPrincipal(gctx, tsecurity.NewPrincipal("test-blessing")); err != nil {
+ panic(err)
}
- ctx := runtime.NewContext()
- server, endpoint := startServer(ctx, t)
+
+ server, endpoint := startServer(gctx, t)
defer stopServer(t, server)
cmd := root()
diff --git a/tools/build/main.go b/tools/build/main.go
index 049d55b..65f7187 100644
--- a/tools/build/main.go
+++ b/tools/build/main.go
@@ -7,22 +7,17 @@
"os"
"v.io/core/veyron2"
- "v.io/core/veyron2/rt"
+ "v.io/core/veyron2/context"
_ "v.io/core/veyron/profiles"
)
-var runtime veyron2.Runtime
+var gctx *context.T
func main() {
- var err error
- runtime, err = rt.New()
- if err != nil {
- panic(err)
- }
-
+ var shutdown veyron2.Shutdown
+ gctx, shutdown = veyron2.Init()
exitCode := root().Main()
- runtime.Cleanup()
-
+ shutdown()
os.Exit(exitCode)
}
diff --git a/tools/debug/impl.go b/tools/debug/impl.go
index 0165eb8..a846c55 100644
--- a/tools/debug/impl.go
+++ b/tools/debug/impl.go
@@ -84,7 +84,6 @@
}
func runVtrace(cmd *cmdline.Command, args []string) error {
- ctx := runtime.NewContext()
arglen := len(args)
if arglen == 0 {
return cmd.UsageErrorf("vtrace: incorrect number of arguments, got %d want >= 1", arglen)
@@ -93,7 +92,7 @@
name := args[0]
client := vtracesvc.StoreClient(name)
if arglen == 1 {
- call, err := client.AllTraces(ctx)
+ call, err := client.AllTraces(gctx)
if err != nil {
return err
}
@@ -118,7 +117,7 @@
if err != nil {
return err
}
- go doFetchTrace(ctx, &wg, client, id, traces, errors)
+ go doFetchTrace(gctx, &wg, client, id, traces, errors)
}
go func() {
wg.Wait()
@@ -151,7 +150,7 @@
}
results := make(chan naming.MountEntry)
errors := make(chan error)
- doGlobs(runtime.NewContext(), args, results, errors)
+ doGlobs(gctx, args, results, errors)
var lastErr error
for {
select {
@@ -217,7 +216,7 @@
}
name := args[0]
lf := logreader.LogFileClient(name)
- stream, err := lf.ReadLog(runtime.NewContext(), startPos, int32(numEntries), follow)
+ stream, err := lf.ReadLog(gctx, startPos, int32(numEntries), follow)
if err != nil {
return err
}
@@ -260,7 +259,7 @@
}
name := args[0]
lf := logreader.LogFileClient(name)
- size, err := lf.Size(runtime.NewContext())
+ size, err := lf.Size(gctx)
if err != nil {
return err
}
@@ -284,17 +283,16 @@
if min, got := 1, len(args); got < min {
return cmd.UsageErrorf("read: incorrect number of arguments, got %d, want >=%d", got, min)
}
- ctx := runtime.NewContext()
globResults := make(chan naming.MountEntry)
errors := make(chan error)
- doGlobs(ctx, args, globResults, errors)
+ doGlobs(gctx, args, globResults, errors)
output := make(chan string)
go func() {
var wg sync.WaitGroup
for me := range globResults {
wg.Add(1)
- go doValue(ctx, me.Name, output, errors, &wg)
+ go doValue(gctx, me.Name, output, errors, &wg)
}
wg.Wait()
close(output)
@@ -345,11 +343,10 @@
results := make(chan string)
errors := make(chan error)
- ctx := runtime.NewContext()
var wg sync.WaitGroup
wg.Add(len(args))
for _, arg := range args {
- go doWatch(ctx, arg, results, errors, &wg)
+ go doWatch(gctx, arg, results, errors, &wg)
}
go func() {
wg.Wait()
@@ -453,7 +450,7 @@
return showPProfProfiles(cmd, name)
}
profile := args[1]
- listener, err := client.StartProxy(runtime, name)
+ listener, err := client.StartProxy(gctx, name)
if err != nil {
return err
}
@@ -476,7 +473,7 @@
}
func showPProfProfiles(cmd *cmdline.Command, name string) error {
- v, err := pprof.PProfClient(name).Profiles(runtime.NewContext())
+ v, err := pprof.PProfClient(name).Profiles(gctx)
if err != nil {
return err
}
@@ -513,7 +510,7 @@
return cmd.UsageErrorf("proxy: incorrect number of arguments, got %d, want %d", got, want)
}
name := args[0]
- listener, err := client.StartProxy(runtime, name)
+ listener, err := client.StartProxy(gctx, name)
if err != nil {
return err
}
@@ -524,9 +521,7 @@
fmt.Fprintln(cmd.Stdout())
fmt.Fprintln(cmd.Stdout(), "Hit CTRL-C to exit")
- ctx := runtime.NewContext()
-
- <-signals.ShutdownOnSignals(ctx)
+ <-signals.ShutdownOnSignals(gctx)
return nil
}
diff --git a/tools/debug/main.go b/tools/debug/main.go
index cab2605..65f7187 100644
--- a/tools/debug/main.go
+++ b/tools/debug/main.go
@@ -7,21 +7,17 @@
"os"
"v.io/core/veyron2"
- "v.io/core/veyron2/rt"
+ "v.io/core/veyron2/context"
_ "v.io/core/veyron/profiles"
)
-var runtime veyron2.Runtime
+var gctx *context.T
func main() {
- var err error
- runtime, err = rt.New()
- if err != nil {
- panic(err)
- }
-
+ var shutdown veyron2.Shutdown
+ gctx, shutdown = veyron2.Init()
exitCode := root().Main()
- runtime.Cleanup()
+ shutdown()
os.Exit(exitCode)
}
diff --git a/tools/mgmt/device/acl_test.go b/tools/mgmt/device/acl_test.go
index b242182..a146e82 100644
--- a/tools/mgmt/device/acl_test.go
+++ b/tools/mgmt/device/acl_test.go
@@ -20,6 +20,9 @@
)
func TestACLGetCommand(t *testing.T) {
+ shutdown := initTest()
+ defer shutdown()
+
tape := NewTape()
server, endpoint, err := startServer(t, gctx, tape)
if err != nil {
@@ -66,6 +69,9 @@
}
func TestACLSetCommand(t *testing.T) {
+ shutdown := initTest()
+ defer shutdown()
+
tape := NewTape()
server, endpoint, err := startServer(t, gctx, tape)
if err != nil {
diff --git a/tools/mgmt/device/impl_test.go b/tools/mgmt/device/impl_test.go
index 1e38b25..065574c 100644
--- a/tools/mgmt/device/impl_test.go
+++ b/tools/mgmt/device/impl_test.go
@@ -12,23 +12,23 @@
"v.io/core/veyron2"
"v.io/core/veyron2/naming"
- "v.io/core/veyron2/rt"
"v.io/core/veyron2/services/mgmt/device"
verror "v.io/core/veyron2/verror2"
)
-func init() {
- runtime, err := rt.New()
- if err != nil {
- panic(err)
- }
- gctx = runtime.NewContext()
+func initTest() (shutdown veyron2.Shutdown) {
+ var err error
+ gctx, shutdown = veyron2.Init()
if gctx, err = veyron2.SetPrincipal(gctx, tsecurity.NewPrincipal("test-blessing")); err != nil {
panic(err)
}
+ return shutdown
}
func TestListCommand(t *testing.T) {
+ shutdown := initTest()
+ defer shutdown()
+
tape := NewTape()
server, endpoint, err := startServer(t, gctx, tape)
if err != nil {
@@ -81,6 +81,9 @@
}
func TestAddCommand(t *testing.T) {
+ shutdown := initTest()
+ defer shutdown()
+
tape := NewTape()
server, endpoint, err := startServer(t, gctx, tape)
if err != nil {
@@ -131,6 +134,9 @@
}
func TestRemoveCommand(t *testing.T) {
+ shutdown := initTest()
+ defer shutdown()
+
tape := NewTape()
server, endpoint, err := startServer(t, gctx, tape)
if err != nil {
@@ -168,6 +174,9 @@
}
func TestInstallCommand(t *testing.T) {
+ shutdown := initTest()
+ defer shutdown()
+
tape := NewTape()
server, endpoint, err := startServer(t, gctx, tape)
if err != nil {
@@ -258,6 +267,9 @@
}
func TestClaimCommand(t *testing.T) {
+ shutdown := initTest()
+ defer shutdown()
+
tape := NewTape()
server, endpoint, err := startServer(t, gctx, tape)
if err != nil {
@@ -335,6 +347,9 @@
}
func TestStartCommand(t *testing.T) {
+ shutdown := initTest()
+ defer shutdown()
+
tape := NewTape()
server, endpoint, err := startServer(t, gctx, tape)
if err != nil {
diff --git a/tools/mgmt/device/instance_impl_test.go b/tools/mgmt/device/instance_impl_test.go
index 97e567f..10f6702 100644
--- a/tools/mgmt/device/instance_impl_test.go
+++ b/tools/mgmt/device/instance_impl_test.go
@@ -11,6 +11,9 @@
)
func TestStopCommand(t *testing.T) {
+ shutdown := initTest()
+ defer shutdown()
+
tape := NewTape()
server, endpoint, err := startServer(t, gctx, tape)
if err != nil {
@@ -83,6 +86,9 @@
}
func testHelper(t *testing.T, lower, upper string) {
+ shutdown := initTest()
+ defer shutdown()
+
tape := NewTape()
server, endpoint, err := startServer(t, gctx, tape)
if err != nil {
diff --git a/tools/mgmt/device/main.go b/tools/mgmt/device/main.go
index c23c137..65f7187 100644
--- a/tools/mgmt/device/main.go
+++ b/tools/mgmt/device/main.go
@@ -6,8 +6,8 @@
import (
"os"
+ "v.io/core/veyron2"
"v.io/core/veyron2/context"
- "v.io/core/veyron2/rt"
_ "v.io/core/veyron/profiles"
)
@@ -15,13 +15,9 @@
var gctx *context.T
func main() {
- runtime, err := rt.New()
- if err != nil {
- panic(err)
- }
- gctx = runtime.NewContext()
-
+ var shutdown veyron2.Shutdown
+ gctx, shutdown = veyron2.Init()
exitCode := root().Main()
- runtime.Cleanup()
+ shutdown()
os.Exit(exitCode)
}
diff --git a/tools/mounttable/impl.go b/tools/mounttable/impl.go
index d949dab..5046a09 100644
--- a/tools/mounttable/impl.go
+++ b/tools/mounttable/impl.go
@@ -27,7 +27,7 @@
}
func runGlob(cmd *cmdline.Command, args []string) error {
- ctx, cancel := context.WithTimeout(runtime.NewContext(), time.Minute)
+ ctx, cancel := context.WithTimeout(gctx, time.Minute)
defer cancel()
if len(args) == 1 {
@@ -102,7 +102,7 @@
}
}
}
- ctx, cancel := context.WithTimeout(runtime.NewContext(), time.Minute)
+ ctx, cancel := context.WithTimeout(gctx, time.Minute)
defer cancel()
client := veyron2.GetClient(ctx)
call, err := client.StartCall(ctx, args[0], "Mount", []interface{}{args[1], seconds, 0}, options.NoResolve{})
@@ -136,7 +136,7 @@
if expected, got := 2, len(args); expected != got {
return cmd.UsageErrorf("unmount: incorrect number of arguments, expected %d, got %d", expected, got)
}
- ctx, cancel := context.WithTimeout(runtime.NewContext(), time.Minute)
+ ctx, cancel := context.WithTimeout(gctx, time.Minute)
defer cancel()
client := veyron2.GetClient(ctx)
call, err := client.StartCall(ctx, args[0], "Unmount", []interface{}{args[1]}, options.NoResolve{})
@@ -169,7 +169,7 @@
if expected, got := 1, len(args); expected != got {
return cmd.UsageErrorf("mount: incorrect number of arguments, expected %d, got %d", expected, got)
}
- ctx, cancel := context.WithTimeout(runtime.NewContext(), time.Minute)
+ ctx, cancel := context.WithTimeout(gctx, time.Minute)
defer cancel()
client := veyron2.GetClient(ctx)
call, err := client.StartCall(ctx, args[0], "ResolveStep", []interface{}{}, options.NoResolve{})
diff --git a/tools/mounttable/impl_test.go b/tools/mounttable/impl_test.go
index 0e7efad..d1aefc9 100644
--- a/tools/mounttable/impl_test.go
+++ b/tools/mounttable/impl_test.go
@@ -9,15 +9,13 @@
"v.io/core/veyron2/context"
"v.io/core/veyron2/ipc"
"v.io/core/veyron2/naming"
- "v.io/core/veyron2/options"
- "v.io/core/veyron2/rt"
"v.io/core/veyron2/security"
"v.io/core/veyron2/services/mounttable"
"v.io/core/veyron2/services/security/access"
"v.io/core/veyron2/vlog"
tsecurity "v.io/core/veyron/lib/testutil/security"
- "v.io/core/veyron/profiles"
+ _ "v.io/core/veyron/profiles"
)
type server struct {
@@ -85,7 +83,7 @@
t.Errorf("NewServer failed: %v", err)
return nil, nil, err
}
- endpoints, err := server.Listen(profiles.LocalListenSpec)
+ endpoints, err := server.Listen(veyron2.GetListenSpec(ctx))
if err != nil {
t.Errorf("Listen failed: %v", err)
return nil, nil, err
@@ -104,18 +102,15 @@
}
func TestMountTableClient(t *testing.T) {
+ var shutdown veyron2.Shutdown
+ gctx, shutdown = veyron2.Init()
+ defer shutdown()
var err error
- // TODO(ataly, mattr, suharshs): This is a HACK to ensure that the server and the
- // client have the same freshly created principal. One way to avoid the RuntimePrincipal
- // option is to have a global client context.T (in main.go) instead of a veyron2.Runtime.
- runtime, err = rt.New(options.RuntimePrincipal{tsecurity.NewPrincipal("test-blessing")})
- if err != nil {
- t.Fatalf("Unexpected error initializing runtime: %s", err)
+ if gctx, err = veyron2.SetPrincipal(gctx, tsecurity.NewPrincipal("test-blessing")); err != nil {
+ panic(err)
}
- defer runtime.Cleanup()
- ctx := runtime.NewContext()
- server, endpoint, err := startServer(t, ctx)
+ server, endpoint, err := startServer(t, gctx)
if err != nil {
return
}
diff --git a/tools/mounttable/main.go b/tools/mounttable/main.go
index cab2605..65f7187 100644
--- a/tools/mounttable/main.go
+++ b/tools/mounttable/main.go
@@ -7,21 +7,17 @@
"os"
"v.io/core/veyron2"
- "v.io/core/veyron2/rt"
+ "v.io/core/veyron2/context"
_ "v.io/core/veyron/profiles"
)
-var runtime veyron2.Runtime
+var gctx *context.T
func main() {
- var err error
- runtime, err = rt.New()
- if err != nil {
- panic(err)
- }
-
+ var shutdown veyron2.Shutdown
+ gctx, shutdown = veyron2.Init()
exitCode := root().Main()
- runtime.Cleanup()
+ shutdown()
os.Exit(exitCode)
}
diff --git a/tools/namespace/impl.go b/tools/namespace/impl.go
index cae7c40..53f73ae 100644
--- a/tools/namespace/impl.go
+++ b/tools/namespace/impl.go
@@ -29,7 +29,7 @@
}
pattern := args[0]
- ctx, cancel := context.WithTimeout(runtime.NewContext(), time.Minute)
+ ctx, cancel := context.WithTimeout(gctx, time.Minute)
defer cancel()
ns := veyron2.GetNamespace(ctx)
@@ -80,7 +80,7 @@
return fmt.Errorf("TTL parse error: %v", err)
}
- ctx, cancel := context.WithTimeout(runtime.NewContext(), time.Minute)
+ ctx, cancel := context.WithTimeout(gctx, time.Minute)
defer cancel()
ns := veyron2.GetNamespace(ctx)
@@ -112,7 +112,7 @@
name := args[0]
server := args[1]
- ctx, cancel := context.WithTimeout(runtime.NewContext(), time.Minute)
+ ctx, cancel := context.WithTimeout(gctx, time.Minute)
defer cancel()
ns := veyron2.GetNamespace(ctx)
@@ -140,7 +140,7 @@
}
name := args[0]
- ctx, cancel := context.WithTimeout(runtime.NewContext(), time.Minute)
+ ctx, cancel := context.WithTimeout(gctx, time.Minute)
defer cancel()
ns := veyron2.GetNamespace(ctx)
@@ -171,7 +171,7 @@
}
name := args[0]
- ctx, cancel := context.WithTimeout(runtime.NewContext(), time.Minute)
+ ctx, cancel := context.WithTimeout(gctx, time.Minute)
defer cancel()
ns := veyron2.GetNamespace(ctx)
diff --git a/tools/namespace/main.go b/tools/namespace/main.go
index 539e0f3..65f7187 100644
--- a/tools/namespace/main.go
+++ b/tools/namespace/main.go
@@ -7,20 +7,17 @@
"os"
"v.io/core/veyron2"
- "v.io/core/veyron2/rt"
+ "v.io/core/veyron2/context"
_ "v.io/core/veyron/profiles"
)
-var runtime veyron2.Runtime
+var gctx *context.T
func main() {
- var err error
- runtime, err = rt.New()
- if err != nil {
- panic(err)
- }
+ var shutdown veyron2.Shutdown
+ gctx, shutdown = veyron2.Init()
exitCode := root().Main()
- runtime.Cleanup()
+ shutdown()
os.Exit(exitCode)
}
diff --git a/tools/naming/simulator/driver.go b/tools/naming/simulator/driver.go
index 685f19a..34c6e91 100644
--- a/tools/naming/simulator/driver.go
+++ b/tools/naming/simulator/driver.go
@@ -18,7 +18,6 @@
"v.io/core/veyron2"
"v.io/core/veyron2/context"
- "v.io/core/veyron2/rt"
"v.io/core/veyron/lib/expect"
"v.io/core/veyron/lib/modules"
@@ -96,21 +95,17 @@
}
}
-var runtime veyron2.Runtime
var ctx *context.T
func main() {
- var err error
- if runtime, err = rt.New(); err != nil {
- panic(err)
- }
- defer runtime.Cleanup()
- ctx = runtime.NewContext()
+ var shutdown veyron2.Shutdown
+ ctx, shutdown = veyron2.Init()
// Subprocesses commands are run by fork/execing this binary
// so we must test to see if this instance is a subprocess or the
// the original command line instance.
if modules.IsModulesProcess() {
+ shutdown()
// Subprocess, run the requested command.
if err := modules.Dispatch(); err != nil {
fmt.Fprintf(os.Stderr, "failed: %v\n", err)
@@ -118,6 +113,7 @@
}
return
}
+ defer shutdown()
shell, err := modules.NewShell(ctx, nil)
if err != nil {
diff --git a/tools/principal/main.go b/tools/principal/main.go
index bb2debd..f39f63c 100644
--- a/tools/principal/main.go
+++ b/tools/principal/main.go
@@ -12,13 +12,12 @@
"os/user"
"time"
- profile "v.io/core/veyron/profiles/static"
+ _ "v.io/core/veyron/profiles/static"
vsecurity "v.io/core/veyron/security"
"v.io/core/veyron/services/identity"
"v.io/core/veyron2"
"v.io/core/veyron2/context"
"v.io/core/veyron2/ipc"
- "v.io/core/veyron2/rt"
"v.io/core/veyron2/security"
"v.io/core/veyron2/vom"
"v.io/lib/cmdline"
@@ -60,13 +59,10 @@
that this tool is running in.
`,
Run: func(cmd *cmdline.Command, args []string) error {
- runtime, err := rt.New()
- if err != nil {
- panic(err)
- }
- defer runtime.Cleanup()
+ ctx, shutdown := veyron2.Init()
+ defer shutdown()
- p := veyron2.GetPrincipal(runtime.NewContext())
+ p := veyron2.GetPrincipal(ctx)
fmt.Printf("Public key : %v\n", p.PublicKey())
fmt.Println("---------------- BlessingStore ----------------")
fmt.Printf("%v", p.BlessingStore().DebugString())
@@ -154,12 +150,9 @@
caveats = append(caveats, cav)
}
- runtime, err := rt.New()
- if err != nil {
- panic(err)
- }
- defer runtime.Cleanup()
- principal := veyron2.GetPrincipal(runtime.NewContext())
+ ctx, shutdown := veyron2.Init()
+ defer shutdown()
+ principal := veyron2.GetPrincipal(ctx)
blessing, err := principal.BlessSelf(name, caveats...)
if err != nil {
return fmt.Errorf("failed to create self-signed blessing for name %q: %v", name, err)
@@ -210,14 +203,12 @@
return fmt.Errorf("require exactly two arguments, provided %d", len(args))
}
- runtime, err := rt.New()
- if err != nil {
- panic(err)
- }
- defer runtime.Cleanup()
+ ctx, shutdown := veyron2.Init()
+ defer shutdown()
- p := veyron2.GetPrincipal(runtime.NewContext())
+ p := veyron2.GetPrincipal(ctx)
+ var err error
var with security.Blessings
var caveats []security.Caveat
if len(flagBlessWith) > 0 {
@@ -242,7 +233,7 @@
if len(flagBlessRemoteKey) > 0 {
// Send blessings to a "server" started by a "recvblessings" command
granter := &granter{p, with, extension, caveats, flagBlessRemoteKey}
- return sendBlessings(runtime.NewContext(), tobless, granter, flagBlessRemoteToken)
+ return sendBlessings(ctx, tobless, granter, flagBlessRemoteToken)
}
// Blessing a principal whose key is available locally.
var key security.PublicKey
@@ -285,12 +276,9 @@
blessings set on the store with the "..." pattern).
`,
Run: func(cmd *cmdline.Command, args []string) error {
- runtime, err := rt.New()
- if err != nil {
- panic(err)
- }
- defer runtime.Cleanup()
- principal := veyron2.GetPrincipal(runtime.NewContext())
+ ctx, shutdown := veyron2.Init()
+ defer shutdown()
+ principal := veyron2.GetPrincipal(ctx)
return dumpBlessings(principal.BlessingStore().ForPeer(args...))
},
}
@@ -303,12 +291,9 @@
the environment that this tool is running in.
`,
Run: func(cmd *cmdline.Command, args []string) error {
- runtime, err := rt.New()
- if err != nil {
- panic(err)
- }
- defer runtime.Cleanup()
- principal := veyron2.GetPrincipal(runtime.NewContext())
+ ctx, shutdown := veyron2.Init()
+ defer shutdown()
+ principal := veyron2.GetPrincipal(ctx)
return dumpBlessings(principal.BlessingStore().Default())
},
}
@@ -348,13 +333,10 @@
}
pattern := security.BlessingPattern(args[1])
- runtime, err := rt.New()
- if err != nil {
- panic(err)
- }
- defer runtime.Cleanup()
+ ctx, shutdown := veyron2.Init()
+ defer shutdown()
- p := veyron2.GetPrincipal(runtime.NewContext())
+ p := veyron2.GetPrincipal(ctx)
if _, err := p.BlessingStore().Set(blessings, pattern); err != nil {
return fmt.Errorf("failed to set blessings %v for peers %v: %v", blessings, pattern, err)
}
@@ -396,13 +378,10 @@
return fmt.Errorf("failed to decode provided blessings: %v", err)
}
- runtime, err := rt.New()
- if err != nil {
- panic(err)
- }
- defer runtime.Cleanup()
+ ctx, shutdown := veyron2.Init()
+ defer shutdown()
- p := veyron2.GetPrincipal(runtime.NewContext())
+ p := veyron2.GetPrincipal(ctx)
if err := p.AddToRoots(blessings); err != nil {
return fmt.Errorf("AddToRoots failed: %v", err)
}
@@ -434,13 +413,10 @@
return fmt.Errorf("failed to decode provided blessings: %v", err)
}
- runtime, err := rt.New()
- if err != nil {
- panic(err)
- }
- defer runtime.Cleanup()
+ ctx, shutdown := veyron2.Init()
+ defer shutdown()
- p := veyron2.GetPrincipal(runtime.NewContext())
+ p := veyron2.GetPrincipal(ctx)
if err := p.BlessingStore().SetDefault(blessings); err != nil {
return fmt.Errorf("failed to set blessings %v as default: %v", blessings, err)
}
@@ -531,11 +507,8 @@
return err
}
- runtime, err := rt.New()
- if err != nil {
- return err
- }
- defer runtime.Cleanup()
+ ctx, shutdown := veyron2.Init()
+ defer shutdown()
var (
with security.Blessings
@@ -546,7 +519,7 @@
return fmt.Errorf("failed to read blessings from --with=%q: %v", flagForkWith, err)
}
} else {
- with = veyron2.GetPrincipal(runtime.NewContext()).BlessingStore().Default()
+ with = veyron2.GetPrincipal(ctx).BlessingStore().Default()
}
if c, err := security.ExpiryCaveat(time.Now().Add(flagForkFor)); err != nil {
return fmt.Errorf("failed to create ExpiryCaveat: %v", err)
@@ -557,7 +530,7 @@
// revocation, method etc.
key := p.PublicKey()
- rp := veyron2.GetPrincipal(runtime.NewContext())
+ rp := veyron2.GetPrincipal(ctx)
blessings, err := rp.Bless(key, with, extension, caveats[0], caveats[1:]...)
if err != nil {
return fmt.Errorf("Bless(%v, %v, %q, ...) failed: %v", key, with, extension, err)
@@ -587,11 +560,8 @@
Run: func(cmd *cmdline.Command, args []string) error {
// Initialize the runtime first so that any local errors are reported
// before the HTTP roundtrips for obtaining the macaroon begin.
- runtime, err := rt.New()
- if err != nil {
- panic(err)
- }
- defer runtime.Cleanup()
+ ctx, shutdown := veyron2.Init()
+ defer shutdown()
blessedChan := make(chan string)
defer close(blessedChan)
@@ -601,7 +571,7 @@
}
macaroon := <-macaroonChan
service := <-macaroonChan
- ctx, cancel := context.WithTimeout(runtime.NewContext(), time.Minute)
+ ctx, cancel := context.WithTimeout(ctx, time.Minute)
defer cancel()
var reply security.WireBlessings
@@ -617,7 +587,7 @@
// Wait for getTokenForBlessRPC to clean up:
<-macaroonChan
- p := veyron2.GetPrincipal(runtime.NewContext())
+ p := veyron2.GetPrincipal(ctx)
if flagSeekBlessingsSetDefault {
if err := p.BlessingStore().SetDefault(blessings); err != nil {
@@ -677,18 +647,15 @@
return fmt.Errorf("command accepts no arguments")
}
- runtime, err := rt.New()
- if err != nil {
- panic(err)
- }
- defer runtime.Cleanup()
+ ctx, shutdown := veyron2.Init()
+ defer shutdown()
- server, err := veyron2.NewServer(runtime.NewContext())
+ server, err := veyron2.NewServer(ctx)
if err != nil {
return fmt.Errorf("failed to create server to listen for blessings: %v", err)
}
defer server.Stop()
- eps, err := server.Listen(profile.ListenSpec)
+ eps, err := server.Listen(veyron2.GetListenSpec(ctx))
if err != nil {
return fmt.Errorf("failed to setup listening: %v", err)
}
@@ -697,7 +664,7 @@
return fmt.Errorf("unable to generate token: %v", err)
}
- p := veyron2.GetPrincipal(runtime.NewContext())
+ p := veyron2.GetPrincipal(ctx)
service := &recvBlessingsService{
principal: p,
token: base64.URLEncoding.EncodeToString(token[:]),
diff --git a/tools/profile/impl.go b/tools/profile/impl.go
index 1925450..029d8ff 100644
--- a/tools/profile/impl.go
+++ b/tools/profile/impl.go
@@ -26,7 +26,7 @@
}
name := args[0]
p := repository.ProfileClient(name)
- ctx, cancel := context.WithTimeout(runtime.NewContext(), time.Minute)
+ ctx, cancel := context.WithTimeout(gctx, time.Minute)
defer cancel()
label, err := p.Label(ctx)
if err != nil {
@@ -51,7 +51,7 @@
}
name := args[0]
p := repository.ProfileClient(name)
- ctx, cancel := context.WithTimeout(runtime.NewContext(), time.Minute)
+ ctx, cancel := context.WithTimeout(gctx, time.Minute)
defer cancel()
desc, err := p.Description(ctx)
if err != nil {
@@ -76,7 +76,7 @@
}
name := args[0]
p := repository.ProfileClient(name)
- ctx, cancel := context.WithTimeout(runtime.NewContext(), time.Minute)
+ ctx, cancel := context.WithTimeout(gctx, time.Minute)
defer cancel()
spec, err := p.Specification(ctx)
if err != nil {
@@ -111,7 +111,7 @@
Label: "example",
OS: build.Linux,
}
- ctx, cancel := context.WithTimeout(runtime.NewContext(), time.Minute)
+ ctx, cancel := context.WithTimeout(gctx, time.Minute)
defer cancel()
if err := p.Put(ctx, spec); err != nil {
return err
@@ -135,7 +135,7 @@
}
name := args[0]
p := repository.ProfileClient(name)
- ctx, cancel := context.WithTimeout(runtime.NewContext(), time.Minute)
+ ctx, cancel := context.WithTimeout(gctx, time.Minute)
defer cancel()
if err := p.Remove(ctx); err != nil {
return err
diff --git a/tools/profile/impl_test.go b/tools/profile/impl_test.go
index 75e14d6..25de771 100644
--- a/tools/profile/impl_test.go
+++ b/tools/profile/impl_test.go
@@ -10,14 +10,12 @@
"v.io/core/veyron2/context"
"v.io/core/veyron2/ipc"
"v.io/core/veyron2/naming"
- "v.io/core/veyron2/options"
- "v.io/core/veyron2/rt"
"v.io/core/veyron2/security"
"v.io/core/veyron2/services/mgmt/build"
"v.io/core/veyron2/vlog"
tsecurity "v.io/core/veyron/lib/testutil/security"
- "v.io/core/veyron/profiles"
+ _ "v.io/core/veyron/profiles"
"v.io/core/veyron/services/mgmt/profile"
"v.io/core/veyron/services/mgmt/repository"
)
@@ -92,7 +90,7 @@
t.Errorf("NewServer failed: %v", err)
return nil, nil, err
}
- endpoints, err := server.Listen(profiles.LocalListenSpec)
+ endpoints, err := server.Listen(veyron2.GetListenSpec(ctx))
if err != nil {
t.Errorf("Listen failed: %v", err)
return nil, nil, err
@@ -111,18 +109,15 @@
}
func TestProfileClient(t *testing.T) {
+ var shutdown veyron2.Shutdown
+ gctx, shutdown = veyron2.Init()
+ defer shutdown()
var err error
- // TODO(ataly, mattr, suharshs): This is a HACK to ensure that the server and the
- // client have the same freshly created principal. One way to avoid the RuntimePrincipal
- // option is to have a global client context.T (in main.go) instead of a veyron2.Runtime.
- runtime, err = rt.New(options.RuntimePrincipal{tsecurity.NewPrincipal("test-blessing")})
- if err != nil {
- t.Fatalf("Unexpected error initializing runtime: %s", err)
+ if gctx, err = veyron2.SetPrincipal(gctx, tsecurity.NewPrincipal("test-blessing")); err != nil {
+ panic(err)
}
- defer runtime.Cleanup()
- ctx := runtime.NewContext()
- server, endpoint, err := startServer(t, ctx)
+ server, endpoint, err := startServer(t, gctx)
if err != nil {
return
}
diff --git a/tools/profile/main.go b/tools/profile/main.go
index 49f20c5..e9b7573 100644
--- a/tools/profile/main.go
+++ b/tools/profile/main.go
@@ -7,21 +7,17 @@
"os"
"v.io/core/veyron2"
- "v.io/core/veyron2/rt"
+ "v.io/core/veyron2/context"
_ "v.io/core/veyron/profiles"
)
-var runtime veyron2.Runtime
+var gctx *context.T
func main() {
- var err error
- runtime, err = rt.New()
- if err != nil {
- panic(err)
- }
-
+ var shutdown veyron2.Shutdown
+ gctx, shutdown = veyron2.Init()
exitCode := root().Main()
- runtime.Cleanup()
+ shutdown()
os.Exit(exitCode)
}
diff --git a/tools/servicerunner/main.go b/tools/servicerunner/main.go
index 09a8e37..225e19a 100644
--- a/tools/servicerunner/main.go
+++ b/tools/servicerunner/main.go
@@ -9,7 +9,7 @@
"strings"
"time"
- "v.io/core/veyron2/rt"
+ "v.io/core/veyron2"
"v.io/core/veyron/lib/expect"
"v.io/core/veyron/lib/flags/consts"
@@ -55,20 +55,24 @@
}
func main() {
- r, err := rt.New()
- if err != nil {
- panic(fmt.Sprintf("Could not initialize runtime %s", err))
- }
- defer r.Cleanup()
+ ctx, shutdown := veyron2.Init()
if modules.IsModulesProcess() {
+ // TODO(suharshs): This is a hack and we should find a better way to parse flags in the modules.
+ // This is needed because the modules commands call veyron2.Init and multiple runtimes cannot
+ // be initialized simultaneously.
+ // In addition the modules read their args from flag.Args() (all flags after "--") which means
+ // the flags must still be parsed before calling modules.Dispatch(). Thus moving veyron2.Init
+ // below this clause solves nothing.
+ shutdown()
panicOnError(modules.Dispatch())
return
}
+ defer shutdown()
vars := map[string]string{}
- sh, err := modules.NewShell(r.NewContext(), nil)
+ sh, err := modules.NewShell(ctx, nil)
if err != nil {
panic(fmt.Sprintf("modules.NewShell: %s", err))
}
diff --git a/tools/vrpc/vrpc.go b/tools/vrpc/vrpc.go
index 66d7b05..a10cf56 100644
--- a/tools/vrpc/vrpc.go
+++ b/tools/vrpc/vrpc.go
@@ -13,7 +13,6 @@
"v.io/core/veyron2"
"v.io/core/veyron2/context"
"v.io/core/veyron2/ipc/reserved"
- "v.io/core/veyron2/rt"
"v.io/core/veyron2/vdl"
"v.io/core/veyron2/vdl/build"
"v.io/core/veyron2/vdl/codegen/vdlgen"
@@ -24,16 +23,13 @@
_ "v.io/core/veyron/profiles"
)
-var runtime veyron2.Runtime
+var gctx *context.T
func main() {
- var err error
- runtime, err = rt.New()
- if err != nil {
- panic(err)
- }
+ var shutdown veyron2.Shutdown
+ gctx, shutdown = veyron2.Init()
exitCode := cmdVRPC.Main()
- runtime.Cleanup()
+ shutdown()
os.Exit(exitCode)
}
@@ -129,7 +125,7 @@
}
// Get the interface or method signature, and pretty-print. We print the
// named types after the signatures, to aid in readability.
- ctx, cancel := context.WithTimeout(runtime.NewContext(), time.Minute)
+ ctx, cancel := context.WithTimeout(gctx, time.Minute)
defer cancel()
var types signature.NamedTypes
if method != "" {
@@ -176,7 +172,7 @@
}
}
// Get the method signature and parse args.
- ctx, cancel := context.WithTimeout(runtime.NewContext(), time.Minute)
+ ctx, cancel := context.WithTimeout(gctx, time.Minute)
defer cancel()
methodSig, err := reserved.MethodSignature(ctx, server, method)
if err != nil {
@@ -264,7 +260,7 @@
return cmd.UsageErrorf("wrong number of arguments")
}
server := args[0]
- ctx, cancel := context.WithTimeout(runtime.NewContext(), time.Minute)
+ ctx, cancel := context.WithTimeout(gctx, time.Minute)
defer cancel()
// The method name does not matter - only interested in authentication,
// not in actually making an RPC.
diff --git a/tools/vrpc/vrpc_test.go b/tools/vrpc/vrpc_test.go
index f8fd359..e039db9 100644
--- a/tools/vrpc/vrpc_test.go
+++ b/tools/vrpc/vrpc_test.go
@@ -7,12 +7,10 @@
"v.io/core/veyron2"
"v.io/core/veyron2/ipc"
- "v.io/core/veyron2/options"
- "v.io/core/veyron2/rt"
"v.io/core/veyron2/vlog"
tsecurity "v.io/core/veyron/lib/testutil/security"
- "v.io/core/veyron/profiles"
+ _ "v.io/core/veyron/profiles"
"v.io/core/veyron/tools/vrpc/test_base"
)
@@ -109,34 +107,20 @@
return nil
}
-func initTest(t *testing.T) (name string, cleanup func()) {
- // The runtime initialized here is the global runtime defined in vrpc.go.
- var ipcServer ipc.Server
- cleanup = func() {
- if ipcServer != nil {
- if err := ipcServer.Stop(); err != nil {
- t.Errorf("server.Stop failed: %v", err)
- }
- }
- if runtime != nil {
- runtime.Cleanup()
- }
- }
+func initTest(t *testing.T) (name string, shutdown veyron2.Shutdown) {
+ // The gctx initialized here is the global context defined in vrpc.go.
+ gctx, shutdown = veyron2.Init()
var err error
- // TODO(ataly, mattr, suharshs): This is a HACK to ensure that the server and the
- // client have the same freshly created principal. One way to avoid the RuntimePrincipal
- // option is to have a global client context.T (in main.go) instead of a veyron2.Runtime.
- if runtime, err = rt.New(options.RuntimePrincipal{tsecurity.NewPrincipal("test-blessing")}); err != nil {
- t.Fatalf("rt.New() failed: %v", err)
- return
+ if gctx, err = veyron2.SetPrincipal(gctx, tsecurity.NewPrincipal("test-blessing")); err != nil {
+ panic(err)
}
- ctx := runtime.NewContext()
- if ipcServer, err = veyron2.NewServer(ctx); err != nil {
+ ipcServer, err := veyron2.NewServer(gctx)
+ if err != nil {
t.Fatalf("NewServer failed: %v", err)
return
}
- endpoints, err := ipcServer.Listen(profiles.LocalListenSpec)
+ endpoints, err := ipcServer.Listen(veyron2.GetListenSpec(gctx))
if err != nil {
t.Fatalf("Listen failed: %v", err)
return
@@ -145,14 +129,14 @@
obj := test_base.TypeTesterServer(&server{})
if err := ipcServer.Serve("", obj, nil); err != nil {
t.Fatalf("Serve failed: %v", err)
- return
+ return name, shutdown
}
- return
+ return name, shutdown
}
func TestSignature(t *testing.T) {
- name, cleanup := initTest(t)
- defer cleanup()
+ name, shutdown := initTest(t)
+ defer shutdown()
var stdout, stderr bytes.Buffer
cmdVRPC.Init(nil, &stdout, &stderr)
@@ -240,8 +224,8 @@
}
func TestMethodSignature(t *testing.T) {
- name, cleanup := initTest(t)
- defer cleanup()
+ name, shutdown := initTest(t)
+ defer shutdown()
tests := []struct {
Method, Want string
@@ -275,8 +259,8 @@
}
func TestCall(t *testing.T) {
- name, cleanup := initTest(t)
- defer cleanup()
+ name, shutdown := initTest(t)
+ defer shutdown()
tests := []struct {
Method, InArgs, Want string
diff --git a/tools/vrun/vrun.go b/tools/vrun/vrun.go
index eb34737..fb3bec2 100644
--- a/tools/vrun/vrun.go
+++ b/tools/vrun/vrun.go
@@ -14,7 +14,6 @@
"v.io/core/veyron2"
"v.io/core/veyron2/context"
- "v.io/core/veyron2/rt"
"v.io/core/veyron2/security"
"v.io/core/veyron2/vlog"
@@ -45,13 +44,8 @@
}
func vrun(cmd *cmdline.Command, args []string) error {
- runtime, err := rt.New()
- if err != nil {
- vlog.Errorf("Could not initialize runtime")
- return err
- }
- defer runtime.Cleanup()
- ctx := runtime.NewContext()
+ ctx, shutdown := veyron2.Init()
+ defer shutdown()
if len(args) == 0 {
return cmd.UsageErrorf("vrun: no command specified")