Skip to content

Commit

Permalink
Merge pull request #5308 from oasisprotocol/peternose/stable/22.2.x/b…
Browse files Browse the repository at this point in the history
…ackport-5300-5304-5307

[BACKPORT/22.2.x] go/oasis-test-runner: Build key manager runtime with trust root
  • Loading branch information
peternose authored Jul 6, 2023
2 parents 6987cde + 4e69520 commit e539b35
Show file tree
Hide file tree
Showing 56 changed files with 588 additions and 515 deletions.
4 changes: 4 additions & 0 deletions .changelog/5308.internal.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
go/oasis-test-runner: Build key manager runtime with trust root

The runtime trust-root scenarios now build not only the simple key/value
but also the key manager runtime with an embedded trust root.
19 changes: 16 additions & 3 deletions go/oasis-test-runner/cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
package cmd

import (
"context"
"fmt"
"io"
"os"
Expand Down Expand Up @@ -37,6 +38,8 @@ const (
cfgNumRuns = "num_runs"
cfgParallelJobCount = "parallel.job_count"
cfgParallelJobIndex = "parallel.job_index"
cfgTimeout = "timeout"
cfgScenarioTimeout = "scenario_timeout"
)

var (
Expand Down Expand Up @@ -364,6 +367,10 @@ func runRoot(cmd *cobra.Command, args []string) error { // nolint: gocyclo
return fmt.Errorf("root: failed to parse scenario parameters: %w", err)
}

// Allow scenarios to run for a limited amount of time.
ctx, cancel := context.WithTimeout(context.Background(), viper.GetDuration(cfgTimeout))
defer cancel()

// Run all requested scenarios.
index := 0
for run := 0; run < numRuns; run++ {
Expand Down Expand Up @@ -430,7 +437,7 @@ func runRoot(cmd *cobra.Command, args []string) error { // nolint: gocyclo
pusher = pusher.Gatherer(prometheus.DefaultGatherer)
}

if err = doScenario(childEnv, v); err != nil {
if err = doScenario(ctx, childEnv, v); err != nil {
logger.Error("failed to run scenario",
"err", err,
"scenario", name,
Expand Down Expand Up @@ -466,7 +473,7 @@ func runRoot(cmd *cobra.Command, args []string) error { // nolint: gocyclo
return nil
}

func doScenario(childEnv *env.Env, sc scenario.Scenario) (err error) {
func doScenario(ctx context.Context, childEnv *env.Env, sc scenario.Scenario) (err error) {
defer func() {
if r := recover(); r != nil {
err = fmt.Errorf("root: panic caught running scenario: %v: %s", r, debug.Stack())
Expand Down Expand Up @@ -513,7 +520,11 @@ func doScenario(childEnv *env.Env, sc scenario.Scenario) (err error) {
}
}

if err = sc.Run(childEnv); err != nil {
// Allow scenario to run for a limited amount of time.
ctx, cancel := context.WithTimeout(ctx, viper.GetDuration(cfgScenarioTimeout))
defer cancel()

if err = sc.Run(ctx, childEnv); err != nil {
err = fmt.Errorf("root: failed to run scenario: %w", err)
return
}
Expand Down Expand Up @@ -609,6 +620,8 @@ func init() {
rootFlags.IntVarP(&numRuns, cfgNumRuns, "n", 1, "number of runs for given scenario(s)")
rootFlags.Int(cfgParallelJobCount, 1, "(for CI) number of overall parallel jobs")
rootFlags.Int(cfgParallelJobIndex, 0, "(for CI) index of this parallel job")
rootFlags.Duration(cfgTimeout, 24*time.Hour, "the maximum allowable total duration for all scenarios")
rootFlags.Duration(cfgScenarioTimeout, 20*time.Minute, "the maximum allowable duration for an individual scenario")
_ = viper.BindPFlags(rootFlags)
rootCmd.Flags().AddFlagSet(rootFlags)
rootCmd.Flags().AddFlagSet(env.Flags)
Expand Down
33 changes: 16 additions & 17 deletions go/oasis-test-runner/rust/builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,20 +14,18 @@ import (
)

const (
builderSubDir = "cargo-builder"
builderLogConsoleFile = "console.log"
builderSubDir = "cargo-builder"
)

// Builder provides an interface for building Rust runtimes by invoking `cargo`.
type Builder struct {
env *env.Env

teeHardware node.TEEHardware
pkg string

buildDir string
targetDir string

teeHardware node.TEEHardware

envVars map[string]string
}

Expand All @@ -41,12 +39,14 @@ func (b *Builder) ResetEnv() {
b.envVars = make(map[string]string)
}

func (b *Builder) cargoCommand(subCommand string) (*exec.Cmd, error) {
func (b *Builder) cargoCommand(subCommand string, pkg string) (*exec.Cmd, error) {
dir, err := b.env.NewSubDir(builderSubDir)
if err != nil {
return nil, err
}
w, err := dir.NewLogWriter(builderLogConsoleFile)

logFile := fmt.Sprintf("%s.log", subCommand)
w, err := dir.NewLogWriter(logFile)
if err != nil {
return nil, err
}
Expand All @@ -55,7 +55,7 @@ func (b *Builder) cargoCommand(subCommand string) (*exec.Cmd, error) {
})

cmd := exec.Command("cargo", subCommand)
cmd.Dir = b.buildDir
cmd.Dir = filepath.Join(b.buildDir, pkg)
cmd.SysProcAttr = env.CmdAttrs
cmd.Stdout = w
cmd.Stderr = w
Expand All @@ -75,12 +75,13 @@ func (b *Builder) cargoCommand(subCommand string) (*exec.Cmd, error) {
}

// Build starts the build process.
func (b *Builder) Build() error {
cmd, err := b.cargoCommand("build")
func (b *Builder) Build(pkg string) error {
cmd, err := b.cargoCommand("build", pkg)
if err != nil {
return err
}
cmd.Args = append(cmd.Args, "--package", b.pkg)

cmd.Args = append(cmd.Args, "--package", pkg)

if b.teeHardware == node.TEEHardwareIntelSGX {
cmd.Args = append(cmd.Args, "--target", "x86_64-fortanix-unknown-sgx")
Expand All @@ -91,12 +92,12 @@ func (b *Builder) Build() error {
}

if err = cmd.Run(); err != nil {
return fmt.Errorf("failed to build runtime with trust root: %w", err)
return fmt.Errorf("failed to build runtime: %w", err)
}

// When building for SGX, also convert the ELF binary to SGXS format.
if b.teeHardware == node.TEEHardwareIntelSGX {
if cmd, err = b.cargoCommand("elf2sgxs"); err != nil {
if cmd, err = b.cargoCommand("elf2sgxs", pkg); err != nil {
return fmt.Errorf("failed to elf2sgxs runtime: %w", err)
}
if err = cmd.Run(); err != nil {
Expand All @@ -109,17 +110,15 @@ func (b *Builder) Build() error {
// NewBuilder creates a new builder for Rust runtimes.
func NewBuilder(
env *env.Env,
teeHardware node.TEEHardware,
pkg string,
buildDir string,
targetDir string,
teeHardware node.TEEHardware,
) *Builder {
return &Builder{
env: env,
teeHardware: teeHardware,
pkg: pkg,
buildDir: buildDir,
targetDir: targetDir,
teeHardware: teeHardware,
envVars: make(map[string]string),
}
}
4 changes: 1 addition & 3 deletions go/oasis-test-runner/scenario/e2e/byzantine_beacon_vrf.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,13 +93,11 @@ func (sc *byzantineVRFBeaconImpl) Fixture() (*oasis.NetworkFixture, error) {
return f, nil
}

func (sc *byzantineVRFBeaconImpl) Run(childEnv *env.Env) error {
func (sc *byzantineVRFBeaconImpl) Run(ctx context.Context, childEnv *env.Env) error {
if err := sc.Net.Start(); err != nil {
return err
}

ctx := context.Background()

// Wait for the validators to come up.
sc.Logger.Info("waiting for validators to initialize",
"num_validators", len(sc.Net.Validators()),
Expand Down
3 changes: 1 addition & 2 deletions go/oasis-test-runner/scenario/e2e/consensus_state_sync.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,13 +61,12 @@ func (sc *consensusStateSyncImpl) Fixture() (*oasis.NetworkFixture, error) {
return f, nil
}

func (sc *consensusStateSyncImpl) Run(childEnv *env.Env) error {
func (sc *consensusStateSyncImpl) Run(ctx context.Context, childEnv *env.Env) error {
if err := sc.Net.Start(); err != nil {
return err
}

sc.Logger.Info("waiting for network to come up")
ctx := context.Background()
if err := sc.Net.Controller().WaitNodesRegistered(ctx, len(sc.Net.Validators())-1); err != nil {
return err
}
Expand Down
4 changes: 1 addition & 3 deletions go/oasis-test-runner/scenario/e2e/debond.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,13 +77,11 @@ func (s *debondImpl) Fixture() (*oasis.NetworkFixture, error) {
return f, nil
}

func (s *debondImpl) Run(*env.Env) error {
func (s *debondImpl) Run(ctx context.Context, childEnv *env.Env) error {
if err := s.Net.Start(); err != nil {
return fmt.Errorf("net Start: %w", err)
}

ctx := context.Background()

s.Logger.Info("waiting for network to come up")
if err := s.Net.Controller().WaitNodesRegistered(ctx, 3); err != nil {
return fmt.Errorf("WaitNodesRegistered: %w", err)
Expand Down
4 changes: 2 additions & 2 deletions go/oasis-test-runner/scenario/e2e/early_query.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ func (sc *earlyQueryImpl) Fixture() (*oasis.NetworkFixture, error) {
return f, nil
}

func (sc *earlyQueryImpl) Run(childEnv *env.Env) error {
func (sc *earlyQueryImpl) Run(ctx context.Context, childEnv *env.Env) error {
// Start the network.
var err error
if err = sc.Net.Start(); err != nil {
Expand All @@ -66,7 +66,7 @@ func (sc *earlyQueryImpl) Run(childEnv *env.Env) error {

// Perform some queries.
cs := sc.Net.Controller().Consensus
ctx, cancel := context.WithTimeout(context.Background(), 1*time.Second)
ctx, cancel := context.WithTimeout(ctx, 1*time.Second)
defer cancel()

// StateToGenesis.
Expand Down
4 changes: 1 addition & 3 deletions go/oasis-test-runner/scenario/e2e/gas_fees_staking.go
Original file line number Diff line number Diff line change
Expand Up @@ -119,9 +119,7 @@ func (sc *gasFeesImpl) Fixture() (*oasis.NetworkFixture, error) {
return ff, nil
}

func (sc *gasFeesImpl) Run(childEnv *env.Env) error {
ctx := context.Background()

func (sc *gasFeesImpl) Run(ctx context.Context, childEnv *env.Env) error {
if err := sc.runTests(ctx); err != nil {
return err
}
Expand Down
4 changes: 2 additions & 2 deletions go/oasis-test-runner/scenario/e2e/genesis_file.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ func (s *genesisFileImpl) Fixture() (*oasis.NetworkFixture, error) {
return f, nil
}

func (s *genesisFileImpl) Run(childEnv *env.Env) error {
func (s *genesisFileImpl) Run(ctx context.Context, childEnv *env.Env) error {
// Manually provision genesis file.
s.Logger.Info("manually provisioning genesis file before starting the network")
if err := s.Net.MakeGenesis(); err != nil {
Expand All @@ -80,7 +80,7 @@ func (s *genesisFileImpl) Run(childEnv *env.Env) error {
}

s.Logger.Info("waiting for network to come up")
if err := s.Net.Controller().WaitNodesRegistered(context.Background(), 1); err != nil {
if err := s.Net.Controller().WaitNodesRegistered(ctx, 1); err != nil {
return fmt.Errorf("e2e/genesis-file: failed to wait for registered nodes: %w", err)
}

Expand Down
3 changes: 2 additions & 1 deletion go/oasis-test-runner/scenario/e2e/identity_cli.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package e2e

import (
"context"
"fmt"

fileSigner "github.com/oasisprotocol/oasis-core/go/common/crypto/signature/signers/file"
Expand Down Expand Up @@ -48,7 +49,7 @@ func (sc *identityCLIImpl) Fixture() (*oasis.NetworkFixture, error) {
return nil, nil
}

func (sc *identityCLIImpl) Run(childEnv *env.Env) error {
func (sc *identityCLIImpl) Run(ctx context.Context, childEnv *env.Env) error {
// Provision node's identity.
args := []string{
"identity", "init",
Expand Down
4 changes: 1 addition & 3 deletions go/oasis-test-runner/scenario/e2e/min_transact_balance.go
Original file line number Diff line number Diff line change
Expand Up @@ -116,14 +116,12 @@ func (mtb *minTransactBalanceImpl) Fixture() (*oasis.NetworkFixture, error) {
return f, nil
}

func (mtb *minTransactBalanceImpl) Run(childEnv *env.Env) error {
func (mtb *minTransactBalanceImpl) Run(ctx context.Context, childEnv *env.Env) error {
// Start the network
if err := mtb.Net.Start(); err != nil {
return err
}

ctx := context.Background()

mtb.Logger.Info("waiting for network to come up")
if err := mtb.Net.Controller().WaitNodesRegistered(ctx, 3); err != nil {
return fmt.Errorf("WaitNodesRegistered: %w", err)
Expand Down
4 changes: 1 addition & 3 deletions go/oasis-test-runner/scenario/e2e/multiple_seeds.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,13 +43,11 @@ func (sc *multipleSeeds) Clone() scenario.Scenario {
}
}

func (sc *multipleSeeds) Run(childEnv *env.Env) error { // nolint: gocyclo
func (sc *multipleSeeds) Run(ctx context.Context, childEnv *env.Env) error { // nolint: gocyclo
if err := sc.Net.Start(); err != nil {
return fmt.Errorf("net Start: %w", err)
}

ctx := context.Background()

sc.Logger.Info("waiting for network to come up")
if err := sc.Net.Controller().WaitNodesRegistered(ctx, 3); err != nil {
return fmt.Errorf("WaitNodesRegistered: %w", err)
Expand Down
3 changes: 1 addition & 2 deletions go/oasis-test-runner/scenario/e2e/registry_cli.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,12 +67,11 @@ func (sc *registryCLIImpl) Fixture() (*oasis.NetworkFixture, error) {
return f, nil
}

func (sc *registryCLIImpl) Run(childEnv *env.Env) error {
func (sc *registryCLIImpl) Run(ctx context.Context, childEnv *env.Env) error {
if err := sc.Net.Start(); err != nil {
return err
}

ctx := context.Background()
sc.Logger.Info("waiting for nodes to register")
if err := sc.Net.Controller().WaitNodesRegistered(ctx, 3); err != nil {
return fmt.Errorf("waiting for nodes to register: %w", err)
Expand Down
5 changes: 2 additions & 3 deletions go/oasis-test-runner/scenario/e2e/runtime/archive_api.go
Original file line number Diff line number Diff line change
Expand Up @@ -281,8 +281,7 @@ func (sc *archiveAPI) testArchiveAPI(ctx context.Context, archiveCtrl *oasis.Con
return nil
}

func (sc *archiveAPI) Run(childEnv *env.Env) error {
ctx := context.Background()
func (sc *archiveAPI) Run(ctx context.Context, childEnv *env.Env) error {
if err := sc.StartNetworkAndTestClient(ctx, childEnv); err != nil {
return err
}
Expand All @@ -292,7 +291,7 @@ func (sc *archiveAPI) Run(childEnv *env.Env) error {
return err
}
var nextEpoch beacon.EpochTime
if nextEpoch, err = sc.initialEpochTransitions(fixture); err != nil {
if nextEpoch, err = sc.initialEpochTransitions(ctx, fixture); err != nil {
return err
}
nextEpoch++ // Next, after initial transitions.
Expand Down
6 changes: 2 additions & 4 deletions go/oasis-test-runner/scenario/e2e/runtime/byzantine.go
Original file line number Diff line number Diff line change
Expand Up @@ -453,9 +453,7 @@ func (sc *byzantineImpl) Fixture() (*oasis.NetworkFixture, error) {
return f, nil
}

func (sc *byzantineImpl) Run(childEnv *env.Env) error {
ctx := context.Background()

func (sc *byzantineImpl) Run(ctx context.Context, childEnv *env.Env) error {
if err := sc.Net.Start(); err != nil {
return err
}
Expand All @@ -472,7 +470,7 @@ func (sc *byzantineImpl) Run(childEnv *env.Env) error {
}
defer blkSub.Close()

epoch, err := sc.initialEpochTransitions(fixture)
epoch, err := sc.initialEpochTransitions(ctx, fixture)
if err != nil {
return err
}
Expand Down
5 changes: 2 additions & 3 deletions go/oasis-test-runner/scenario/e2e/runtime/dump_restore.go
Original file line number Diff line number Diff line change
Expand Up @@ -118,8 +118,7 @@ func (sc *dumpRestoreImpl) Fixture() (*oasis.NetworkFixture, error) {
return f, nil
}

func (sc *dumpRestoreImpl) Run(childEnv *env.Env) error {
ctx := context.Background()
func (sc *dumpRestoreImpl) Run(ctx context.Context, childEnv *env.Env) error {
if err := sc.StartNetworkAndTestClient(ctx, childEnv); err != nil {
return err
}
Expand Down Expand Up @@ -190,5 +189,5 @@ func (sc *dumpRestoreImpl) Run(childEnv *env.Env) error {

// Check that everything works with restored state.
sc.Scenario.testClient = NewKVTestClient().WithSeed("seed2").WithScenario(RemoveKeyValueScenario)
return sc.Scenario.Run(childEnv)
return sc.Scenario.Run(ctx, childEnv)
}
Loading

0 comments on commit e539b35

Please sign in to comment.