Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

[tmpnet] Add check for vm binaries to network and node start #3273

Merged
merged 5 commits into from
Aug 12, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 35 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,20 @@ 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())
_, err := os.Stat(pluginPath)
if err != nil {
errs = append(errs, fmt.Errorf("VM binary for subnet %q not found at %q", subnet.Name, pluginPath))
}
}
}
if len(errs) > 0 {
return errors.Join(errs...)
}
return nil
marun marked this conversation as resolved.
Show resolved Hide resolved
}
Loading