Skip to content

Commit

Permalink
[tmpnet] Add check for vm binaries to network and node start (#3273)
Browse files Browse the repository at this point in the history
  • Loading branch information
marun authored Aug 12, 2024
1 parent 9e67efe commit 5196934
Showing 1 changed file with 31 additions and 1 deletion.
32 changes: 31 additions & 1 deletion tests/fixture/tmpnet/network.go
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,9 @@ func BootstrapNewNetwork(
if len(network.Nodes) == 0 {
return errInsufficientNodes
}
if err := checkVMBinariesExist(network.Subnets, pluginDir); err != nil {
return err
}
if err := network.EnsureDefaultConfig(w, avalancheGoExecPath, pluginDir); err != nil {
return err
}
Expand Down Expand Up @@ -284,7 +287,7 @@ func (n *Network) Create(rootDir string) error {
n.Dir = canonicalDir

// Ensure the existence of the plugin directory or nodes won't be able to start.
pluginDir, err := n.DefaultFlags.GetStringVal(config.PluginDirKey)
pluginDir, err := n.getPluginDir()
if err != nil {
return err
}
Expand Down Expand Up @@ -452,6 +455,16 @@ func (n *Network) Bootstrap(ctx context.Context, w io.Writer) error {

// Starts the provided node after configuring it for the network.
func (n *Network) StartNode(ctx context.Context, w io.Writer, node *Node) error {
// This check is duplicative for a network that is starting, but ensures
// that individual node start/restart won't fail due to missing binaries.
pluginDir, err := n.getPluginDir()
if err != nil {
return err
}
if err := checkVMBinariesExist(n.Subnets, pluginDir); err != nil {
return err
}

if err := n.EnsureNodeConfig(node); err != nil {
return err
}
Expand Down Expand Up @@ -856,6 +869,10 @@ func (n *Network) GetNetworkID() uint32 {
return n.NetworkID
}

func (n *Network) getPluginDir() (string, error) {
return n.DefaultFlags.GetStringVal(config.PluginDirKey)
}

// Waits until the provided nodes are healthy.
func waitForHealthy(ctx context.Context, w io.Writer, nodes []*Node) error {
ticker := time.NewTicker(networkHealthCheckInterval)
Expand Down Expand Up @@ -917,3 +934,16 @@ func GetReusableNetworkPathForOwner(owner string) (string, error) {
}
return filepath.Join(networkPath, "latest_"+owner), nil
}

func checkVMBinariesExist(subnets []*Subnet, pluginDir string) error {
errs := []error{}
for _, subnet := range subnets {
for _, chain := range subnet.Chains {
pluginPath := filepath.Join(pluginDir, chain.VMID.String())
if _, err := os.Stat(pluginPath); err != nil {
errs = append(errs, fmt.Errorf("failed to check VM binary for subnet %q: %w", subnet.Name, err))
}
}
}
return errors.Join(errs...)
}

0 comments on commit 5196934

Please sign in to comment.