Skip to content

Commit

Permalink
go/oasis-test-runner: Add dynamic runtime registration tests
Browse files Browse the repository at this point in the history
  • Loading branch information
kostko committed Jan 8, 2020
1 parent a4e737b commit c6acc1d
Show file tree
Hide file tree
Showing 16 changed files with 397 additions and 62 deletions.
5 changes: 5 additions & 0 deletions go/oasis-test-runner/oasis/args.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,11 @@ type argBuilder struct {
vec []string
}

func (args *argBuilder) internalSocketAddress(path string) *argBuilder {
args.vec = append(args.vec, "--"+grpc.CfgAddress, "unix:"+path)
return args
}

func (args *argBuilder) debugDontBlameOasis() *argBuilder {
args.vec = append(args.vec, "--"+flags.CfgDebugDontBlameOasis)
return args
Expand Down
5 changes: 5 additions & 0 deletions go/oasis-test-runner/oasis/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,11 @@ func (client *Client) startNode() error {
return nil
}

// Start starts an Oasis node.
func (client *Client) Start() error {
return client.startNode()
}

// NewClient provisions a new client node and adds it to the network.
func (net *Network) NewClient() (*Client, error) {
clientName := fmt.Sprintf("client-%d", len(net.clients))
Expand Down
5 changes: 5 additions & 0 deletions go/oasis-test-runner/oasis/compute.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,11 @@ func (worker *Compute) ExportsPath() string {
return nodeExportsPath(worker.dir)
}

// Start starts an Oasis node.
func (worker *Compute) Start() error {
return worker.startNode()
}

func (worker *Compute) startNode() error {
args := newArgBuilder().
debugDontBlameOasis().
Expand Down
7 changes: 5 additions & 2 deletions go/oasis-test-runner/oasis/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
cmnGrpc "github.com/oasislabs/oasis-core/go/common/grpc"
consensus "github.com/oasislabs/oasis-core/go/consensus/api"
control "github.com/oasislabs/oasis-core/go/control/api"
registry "github.com/oasislabs/oasis-core/go/registry/api"
runtimeClient "github.com/oasislabs/oasis-core/go/runtime/client/api"
staking "github.com/oasislabs/oasis-core/go/staking/api"
)
Expand All @@ -16,8 +17,9 @@ type Controller struct {
control.DebugController
control.NodeController

Staking staking.Backend
Consensus consensus.ClientBackend
Staking staking.Backend
Registry registry.Backend
RuntimeClient runtimeClient.RuntimeClient
}

Expand All @@ -36,8 +38,9 @@ func NewController(socketPath string) (*Controller, error) {
return &Controller{
DebugController: control.NewDebugControllerClient(conn),
NodeController: control.NewNodeControllerClient(conn),
Staking: staking.NewStakingClient(conn),
Consensus: consensus.NewConsensusClient(conn),
Staking: staking.NewStakingClient(conn),
Registry: registry.NewRegistryClient(conn),
RuntimeClient: runtimeClient.NewRuntimeClient(conn),
}, nil
}
38 changes: 22 additions & 16 deletions go/oasis-test-runner/oasis/fixture.go
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ func (f *ValidatorFixture) Create(net *Network) (*Validator, error) {
}

// RuntimeFixture is a runtime fixture.
type RuntimeFixture struct {
type RuntimeFixture struct { // nolint: maligned
ID common.Namespace `json:"id"`
Kind registry.RuntimeKind `json:"kind"`
Entity int `json:"entity"`
Expand All @@ -166,6 +166,8 @@ type RuntimeFixture struct {
Storage registry.StorageParameters `json:"storage"`

Pruner RuntimePrunerCfg `json:"pruner,omitempty"`

ExcludeFromGenesis bool `json:"exclude_from_genesis,omitempty"`
}

// Create instantiates the runtime described by the fixture.
Expand All @@ -188,20 +190,21 @@ func (f *RuntimeFixture) Create(netFixture *NetworkFixture, net *Network) (*Runt
}

return net.NewRuntime(&RuntimeCfg{
ID: f.ID,
Kind: f.Kind,
Entity: entity,
Keymanager: km,
TEEHardware: netFixture.TEE.Hardware,
MrSigner: netFixture.TEE.MrSigner,
Compute: f.Compute,
Merge: f.Merge,
TxnScheduler: f.TxnScheduler,
Storage: f.Storage,
Binary: f.Binary,
GenesisState: f.GenesisState,
GenesisRound: f.GenesisRound,
Pruner: f.Pruner,
ID: f.ID,
Kind: f.Kind,
Entity: entity,
Keymanager: km,
TEEHardware: netFixture.TEE.Hardware,
MrSigner: netFixture.TEE.MrSigner,
Compute: f.Compute,
Merge: f.Merge,
TxnScheduler: f.TxnScheduler,
Storage: f.Storage,
Binary: f.Binary,
GenesisState: f.GenesisState,
GenesisRound: f.GenesisRound,
Pruner: f.Pruner,
ExcludeFromGenesis: f.ExcludeFromGenesis,
})
}

Expand Down Expand Up @@ -237,10 +240,12 @@ func (f *KeymanagerFixture) Create(net *Network) (*Keymanager, error) {
}

// StorageWorkerFixture is a storage worker fixture.
type StorageWorkerFixture struct {
type StorageWorkerFixture struct { // nolint: maligned
Backend string `json:"backend"`
Entity int `json:"entity"`

Restartable bool `json:"restartable"`

LogWatcherHandlerFactories []log.WatcherHandlerFactory `json:"-"`

IgnoreApplies bool `json:"ignore_applies,omitempty"`
Expand All @@ -255,6 +260,7 @@ func (f *StorageWorkerFixture) Create(net *Network) (*Storage, error) {

return net.NewStorage(&StorageCfg{
NodeCfg: NodeCfg{
Restartable: f.Restartable,
LogWatcherHandlerFactories: f.LogWatcherHandlerFactories,
},
Backend: f.Backend,
Expand Down
12 changes: 9 additions & 3 deletions go/oasis-test-runner/oasis/ias.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ var mockSPID []byte
type iasProxy struct {
Node

grpcPort uint16
useRegistry bool
grpcPort uint16
}

func (ias *iasProxy) tlsCertPath() string {
Expand All @@ -29,9 +30,13 @@ func (ias *iasProxy) startNode() error {
debugDontBlameOasis().
debugAllowTestKeys().
grpcServerPort(ias.grpcPort).
iasUseGenesis().
iasDebugMock().
iasSPID(mockSPID)
if ias.useRegistry {
args = args.internalSocketAddress(ias.net.validators[0].SocketPath())
} else {
args = args.iasUseGenesis()
}

var err error
if ias.cmd, ias.exitCh, err = ias.net.startOasisNode(
Expand Down Expand Up @@ -79,7 +84,8 @@ func (net *Network) newIASProxy() (*iasProxy, error) {
net: net,
dir: iasDir,
},
grpcPort: net.nextNodePort,
useRegistry: net.cfg.IASUseRegistry,
grpcPort: net.nextNodePort,
}
net.iasProxy.doStartNode = net.iasProxy.startNode

Expand Down
7 changes: 6 additions & 1 deletion go/oasis-test-runner/oasis/keymanager.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,11 +59,16 @@ func (km *Keymanager) TLSCertPath() string {
return nodeTLSCertPath(km.dir)
}

// Exports path returns the path to the node's exports data dir.
// ExportsPath returns the path to the node's exports data dir.
func (km *Keymanager) ExportsPath() string {
return nodeExportsPath(km.dir)
}

// Start starts an Oasis node.
func (km *Keymanager) Start() error {
return km.startNode()
}

func (km *Keymanager) provisionGenesis() error {
// Provision status and policy. We can only provision this here as we need
// a list of runtimes allowed to query the key manager.
Expand Down
16 changes: 14 additions & 2 deletions go/oasis-test-runner/oasis/oasis.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,11 @@ func (n *Node) stopNode() error {
return nil
}

// Stop stops the node.
func (n *Node) Stop() error {
return n.stopNode()
}

// Restart kills the node, waits for it to stop, and starts it again.
func (n *Node) Restart() error {
if err := n.stopNode(); err != nil {
Expand Down Expand Up @@ -179,7 +184,9 @@ type NetworkCfg struct { // nolint: maligned
// DeterministicIdentities is the deterministic identities flag.
DeterministicIdentities bool `json:"deterministic_identities"`

// XXX: Config for IAS proxy
// IASUseRegistry specifies whether the IAS proxy should use the registry instead of the
// genesis document for authenticating runtime IDs.
IASUseRegistry bool `json:"ias_use_registry,omitempty"`

// StakingGenesis is the name of a file with a staking genesis document to use if GenesisFile isn't set.
StakingGenesis string `json:"staking_genesis"`
Expand Down Expand Up @@ -259,8 +266,13 @@ func (net *Network) ClientController() *Controller {

// NumRegisterNodes returns the number of all nodes that need to register.
func (net *Network) NumRegisterNodes() int {
var keyManagers int
if net.keymanager != nil {
keyManagers = 1
}

return len(net.validators) +
1 + // Key manager.
keyManagers +
len(net.storageWorkers) +
len(net.computeWorkers) +
len(net.byzantine)
Expand Down
61 changes: 51 additions & 10 deletions go/oasis-test-runner/oasis/runtime.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"github.com/pkg/errors"

"github.com/oasislabs/oasis-core/go/common"
"github.com/oasislabs/oasis-core/go/common/cbor"
"github.com/oasislabs/oasis-core/go/common/node"
"github.com/oasislabs/oasis-core/go/common/sgx"
cmdCommon "github.com/oasislabs/oasis-core/go/oasis-node/cmd/common"
Expand All @@ -32,6 +33,9 @@ type Runtime struct { // nolint: maligned
mrSigner *sgx.MrSigner

pruner RuntimePrunerCfg

excludeFromGenesis bool
descriptor registry.Runtime
}

// RuntimeCfg is the Oasis runtime provisioning configuration.
Expand All @@ -53,6 +57,8 @@ type RuntimeCfg struct { // nolint: maligned
Storage registry.StorageParameters

Pruner RuntimePrunerCfg

ExcludeFromGenesis bool
}

// RuntimePrunerCfg is the pruner configuration for an Oasis runtime.
Expand All @@ -69,13 +75,32 @@ func (rt *Runtime) ID() common.Namespace {
}

func (rt *Runtime) toGenesisArgs() []string {
if rt.excludeFromGenesis {
return []string{}
}

return []string{
"--runtime", filepath.Join(rt.dir.String(), rtDescriptorFile),
}
}

// ToRuntimeDescriptor returns a registry runtime descriptor for this runtime.
func (rt *Runtime) ToRuntimeDescriptor() registry.Runtime {
return rt.descriptor
}

// NewRuntime provisions a new runtime and adds it to the network.
func (net *Network) NewRuntime(cfg *RuntimeCfg) (*Runtime, error) {
descriptor := registry.Runtime{
ID: cfg.ID,
Kind: cfg.Kind,
TEEHardware: cfg.TEEHardware,
Compute: cfg.Compute,
Merge: cfg.Merge,
TxnScheduler: cfg.TxnScheduler,
Storage: cfg.Storage,
}

rtDir, err := net.baseDir.NewSubDir("runtime-" + cfg.ID.String())
if err != nil {
net.logger.Error("failed to create runtime subdir",
Expand All @@ -89,7 +114,6 @@ func (net *Network) NewRuntime(cfg *RuntimeCfg) (*Runtime, error) {
"--" + cmdCommon.CfgDataDir, rtDir.String(),
"--" + cmdRegRt.CfgID, cfg.ID.String(),
"--" + cmdRegRt.CfgKind, cfg.Kind.String(),
"--" + cmdRegRt.CfgGenesisRound, strconv.FormatUint(cfg.GenesisRound, 10),
}
if cfg.Kind == registry.KindCompute {
args = append(args, []string{
Expand All @@ -110,7 +134,13 @@ func (net *Network) NewRuntime(cfg *RuntimeCfg) (*Runtime, error) {
}...)

if cfg.GenesisState != "" {
args = append(args, "--"+cmdRegRt.CfgGenesisState, cfg.GenesisState)
args = append(args,
"--"+cmdRegRt.CfgGenesisRound, strconv.FormatUint(cfg.GenesisRound, 10),
"--"+cmdRegRt.CfgGenesisState, cfg.GenesisState,
)

descriptor.Genesis.Round = cfg.GenesisRound
// TODO: Support genesis state.
}
}
var mrEnclave *sgx.MrEnclave
Expand All @@ -123,11 +153,20 @@ func (net *Network) NewRuntime(cfg *RuntimeCfg) (*Runtime, error) {
"--" + cmdRegRt.CfgTEEHardware, cfg.TEEHardware.String(),
"--" + cmdRegRt.CfgVersionEnclave, mrEnclave.String() + cfg.MrSigner.String(),
}...)

descriptor.Version.TEE = cbor.Marshal(registry.VersionInfoIntelSGX{
Enclaves: []sgx.EnclaveIdentity{
{MrEnclave: *mrEnclave, MrSigner: *cfg.MrSigner},
},
})
}
if cfg.Keymanager != nil {
args = append(args, []string{
"--" + cmdRegRt.CfgKeyManager, cfg.Keymanager.id.String(),
}...)

descriptor.KeyManager = new(common.Namespace)
*descriptor.KeyManager = cfg.Keymanager.id
}
args = append(args, cfg.Entity.toGenesisArgs()...)

Expand All @@ -145,14 +184,16 @@ func (net *Network) NewRuntime(cfg *RuntimeCfg) (*Runtime, error) {
}

rt := &Runtime{
dir: rtDir,
id: cfg.ID,
kind: cfg.Kind,
binary: cfg.Binary,
teeHardware: cfg.TEEHardware,
mrEnclave: mrEnclave,
mrSigner: cfg.MrSigner,
pruner: cfg.Pruner,
dir: rtDir,
id: cfg.ID,
kind: cfg.Kind,
binary: cfg.Binary,
teeHardware: cfg.TEEHardware,
mrEnclave: mrEnclave,
mrSigner: cfg.MrSigner,
pruner: cfg.Pruner,
excludeFromGenesis: cfg.ExcludeFromGenesis,
descriptor: descriptor,
}
net.runtimes = append(net.runtimes, rt)

Expand Down
5 changes: 5 additions & 0 deletions go/oasis-test-runner/oasis/storage.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,11 @@ func (worker *Storage) DatabasePath() string {
return filepath.Join(worker.dir.String(), database.DefaultFileName(worker.backend))
}

// Start starts an Oasis node.
func (worker *Storage) Start() error {
return worker.startNode()
}

func (worker *Storage) startNode() error {
args := newArgBuilder().
debugDontBlameOasis().
Expand Down
5 changes: 5 additions & 0 deletions go/oasis-test-runner/oasis/validator.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,11 @@ func (val *Validator) ExportsPath() string {
return nodeExportsPath(val.dir)
}

// Start starts an Oasis node.
func (val *Validator) Start() error {
return val.startNode()
}

func (val *Validator) startNode() error {
args := newArgBuilder().
debugDontBlameOasis().
Expand Down
Loading

0 comments on commit c6acc1d

Please sign in to comment.