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 17, 2025
1 parent 279da84 commit ce3f6fc
Show file tree
Hide file tree
Showing 2 changed files with 74 additions and 0 deletions.
4 changes: 4 additions & 0 deletions go/oasis-test-runner/oasis/oasis.go
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,10 @@ type Node struct { // nolint: maligned
entity *Entity
}

func (n *Node) Dir() string {
return n.dir.String()
}

// SetArchiveMode sets the archive mode.
func (n *Node) SetArchiveMode(archive bool) {
n.consensus.EnableArchiveMode = archive
Expand Down
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 @@ -16,6 +16,7 @@ import (

"github.com/oasisprotocol/oasis-core/go/common/logging"
cmSync "github.com/oasisprotocol/oasis-core/go/common/sync"
"github.com/oasisprotocol/oasis-core/go/common/version"
"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"
Expand Down Expand Up @@ -106,9 +107,78 @@ 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 := ensureCorrectBundlesDir(sc.Logger, worker.Name, worker.Dir()); err != nil {
sc.Logger.Error("compute worker bundle dir clean-up error",
"worker", worker.Name,
"err", err,
)
return err
}
}

return sc.RunTestClientAndCheckLogs(ctx, childEnv)
}

func ensureCorrectBundlesDir(logger *logging.Logger, workerName, workerDir string) error {
logger.Info("ensuring cached exploded bundle for version 0.0.0 was removed",
"worker", workerName)

// There should be only one exploded bundle dir.
bundlesDir := bundle.ExplodedPath(workerDir)
entry, err := ensureSingleEntry(logger, bundlesDir)
explDir := path.Join(bundlesDir, entry)
if err != nil {
return fmt.Errorf("ensureSingleEntry(logger, %s): %w", workerDir, err)
}

// Ensure exploded cached bundle is for the latest version (0.1.0).
manifest, err := bundle.ReadManifest(explDir)
if err != nil {
return fmt.Errorf("bundle.ReadManifest(%s)", explDir)
}
want := version.Version{Minor: uint16(1)}
got := manifest.GetVersion()
if want != got {
return fmt.Errorf("unexpected bundle version: want %v, but %v got", want, got)
}
return nil
}

func ensureSingleEntry(logger *logging.Logger, dir string) (string, error) {
entries, err := os.ReadDir(dir)
if err != nil {
logger.Error("failed to read dir")
return "", err
}

if n := len(entries); n != 1 {
var entryNames []string
for _, entry := range entries {
entryNames = append(entryNames, entry.Name())
}
logger.Error("failed to ensure only single dir entry",
"entries", strings.Join(entryNames, "; "),
"dir", dir,
)
return "", fmt.Errorf("unexpected number of dir entries: expected 1, but %d got", n)
}

entry := entries[0]

if !entry.IsDir() {
logger.Error("failed to ensure single dir entry: entry is not dir",
"entry", entry.Name(),
)
return "", fmt.Errorf("%s is not a dir", entry)
}

return entry.Name(), nil
}

type bundleServer struct {
startOne cmSync.One

Expand Down

0 comments on commit ce3f6fc

Please sign in to comment.