Skip to content

Commit

Permalink
go/oasis-test-runner/scenario/e2e: Test bundles clean-up
Browse files Browse the repository at this point in the history
  • Loading branch information
martintomazic committed Jan 22, 2025
1 parent 175312c commit 1e99fcf
Showing 1 changed file with 70 additions and 0 deletions.
70 changes: 70 additions & 0 deletions go/oasis-test-runner/scenario/e2e/runtime/runtime_upgrade.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,15 @@ import (
"sync/atomic"
"time"

"github.com/oasisprotocol/oasis-core/go/common/crypto/hash"
"github.com/oasisprotocol/oasis-core/go/common/logging"
cmSync "github.com/oasisprotocol/oasis-core/go/common/sync"
consensus "github.com/oasisprotocol/oasis-core/go/consensus/api"
"github.com/oasisprotocol/oasis-core/go/oasis-test-runner/env"
"github.com/oasisprotocol/oasis-core/go/oasis-test-runner/oasis"
"github.com/oasisprotocol/oasis-core/go/oasis-test-runner/oasis/cli"
"github.com/oasisprotocol/oasis-core/go/oasis-test-runner/scenario"
registry "github.com/oasisprotocol/oasis-core/go/registry/api"
"github.com/oasisprotocol/oasis-core/go/runtime/bundle"
)

Expand Down Expand Up @@ -106,9 +109,76 @@ func (sc *runtimeUpgradeImpl) Run(ctx context.Context, childEnv *env.Env) error
// Run client again.
sc.Logger.Info("starting a second client to check if runtime works")
sc.Scenario.TestClient = NewTestClient().WithSeed("seed2").WithScenario(InsertRemoveEncWithSecretsScenarioV2)

// Ensure that after upgrade, every compute worker had its old exploded
// bundle removed from its bundles dir.
for _, worker := range sc.Net.ComputeWorkers() {
if err := sc.verifyBundleDir(ctx, worker); err != nil {
return fmt.Errorf("failed to clean %s's bundle dir after upgrade: %w", worker.Name, err)
}
}

return sc.RunTestClientAndCheckLogs(ctx, childEnv)
}

func (sc *runtimeUpgradeImpl) verifyBundleDir(ctx context.Context, worker *oasis.Compute) error {
sc.Logger.Info("ensuring cached exploded bundle for version 0.0.0 was removed",
"worker", worker.Name,
)

// There should be only one exploded bundle dir.
bundlesDir := bundle.ExplodedPath(worker.DataDir())
entries, err := os.ReadDir(bundlesDir)
if err != nil {
return err
}
if n := len(entries); n != 1 {
return fmt.Errorf("unexpected number of dir entries: expected 1, got %d", n)
}
entry := entries[0]
if !entry.IsDir() {
return fmt.Errorf("%s is not a dir", entry.Name())
}

// Ensure exploded cached bundle is for the latest version (0.1.0).
// We do so by getting the manifest hash of the active deployment,
// and ensuring there is a dir with corresponding hash.

// Fetch registry descriptor.
rt, err := sc.Net.Controller().Registry.GetRuntime(ctx, &registry.GetRuntimeQuery{
Height: consensus.HeightLatest,
ID: KeyValueRuntimeID,
})
if err != nil {
return fmt.Errorf("failed to get runtime descriptor: %w", err)
}
// Fetch current epoch.
epoch, err := sc.Net.Controller().Beacon.GetEpoch(ctx, consensus.HeightLatest)
if err != nil {
return fmt.Errorf("failed to get current epoch: %w", err)
}
// Get active deployment manifest hash.
active := rt.ActiveDeployment(epoch)
if active == nil {
return fmt.Errorf("missing active descriptor for epoch %v", epoch)
}
manifestHash := active.BundleChecksum

// Ensure single entry name (exploded bundle dir) equals to fetched manifest hash.
var want hash.Hash
if err = want.UnmarshalBinary(manifestHash); err != nil {
return fmt.Errorf("failed to unmarshal active deployment manifest hash")
}
var got hash.Hash
if err := got.UnmarshalHex(entry.Name()); err != nil {
return fmt.Errorf("failed to unmarshal dir name to hash")
}
if !want.Equal(&got) {
return fmt.Errorf("unexpected folder name: want %v, got %v", want, got)
}
return nil
}

type bundleServer struct {
startOne cmSync.One

Expand Down

0 comments on commit 1e99fcf

Please sign in to comment.