From 2ca0c88df491a6b6677b26cdf1f6509a92c72bd4 Mon Sep 17 00:00:00 2001 From: Maru Newby Date: Tue, 6 Aug 2024 10:44:43 -0700 Subject: [PATCH 1/5] [tmpnet] Add check for vm binaries to network and node start --- tests/fixture/tmpnet/network.go | 36 ++++++++++++++++++++++++++++++++- 1 file changed, 35 insertions(+), 1 deletion(-) diff --git a/tests/fixture/tmpnet/network.go b/tests/fixture/tmpnet/network.go index afa59e653c14..80995d1687e6 100644 --- a/tests/fixture/tmpnet/network.go +++ b/tests/fixture/tmpnet/network.go @@ -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 } @@ -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 } @@ -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 } @@ -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) @@ -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 +} From 71a641d59f4dc89858c0cb422f3471e28feda6f9 Mon Sep 17 00:00:00 2001 From: Maru Newby Date: Tue, 6 Aug 2024 11:30:52 -0700 Subject: [PATCH 2/5] fixup: Respond to reviewer feedback --- tests/fixture/tmpnet/network.go | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/tests/fixture/tmpnet/network.go b/tests/fixture/tmpnet/network.go index 80995d1687e6..88f1512e65a2 100644 --- a/tests/fixture/tmpnet/network.go +++ b/tests/fixture/tmpnet/network.go @@ -940,9 +940,8 @@ func checkVMBinariesExist(subnets []*Subnet, pluginDir string) 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 _, err := os.Stat(pluginPath); err != nil { + errs = append(errs, fmt.Errorf("failed to check VM binary for subnet %q: %v ", subnet.Name, err)) } } } From ff4424f440f631cfd19ed334c3a03bb02e5193b5 Mon Sep 17 00:00:00 2001 From: Maru Newby Date: Tue, 6 Aug 2024 11:33:32 -0700 Subject: [PATCH 3/5] fixup: More reviewer feedback --- tests/fixture/tmpnet/network.go | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/tests/fixture/tmpnet/network.go b/tests/fixture/tmpnet/network.go index 88f1512e65a2..c0a5528e69fa 100644 --- a/tests/fixture/tmpnet/network.go +++ b/tests/fixture/tmpnet/network.go @@ -945,8 +945,5 @@ func checkVMBinariesExist(subnets []*Subnet, pluginDir string) error { } } } - if len(errs) > 0 { - return errors.Join(errs...) - } - return nil + return errors.Join(errs...) } From e1483b96face831e204855161287dc14f20e58c5 Mon Sep 17 00:00:00 2001 From: Maru Newby Date: Tue, 6 Aug 2024 11:49:04 -0700 Subject: [PATCH 4/5] fixup: Address feedback from github linter --- tests/fixture/tmpnet/network.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/fixture/tmpnet/network.go b/tests/fixture/tmpnet/network.go index c0a5528e69fa..800432c602fd 100644 --- a/tests/fixture/tmpnet/network.go +++ b/tests/fixture/tmpnet/network.go @@ -941,7 +941,7 @@ func checkVMBinariesExist(subnets []*Subnet, pluginDir string) error { 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: %v ", subnet.Name, err)) + errs = append(errs, fmt.Errorf("failed to check VM binary for subnet %q: %w ", subnet.Name, err)) } } } From f709a67b5c1379df1811775ce39cb587121e97d6 Mon Sep 17 00:00:00 2001 From: Maru Newby Date: Wed, 7 Aug 2024 09:49:03 -0700 Subject: [PATCH 5/5] fixup: Respond to review feedback --- tests/fixture/tmpnet/network.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/fixture/tmpnet/network.go b/tests/fixture/tmpnet/network.go index 800432c602fd..fadbcc6e6a72 100644 --- a/tests/fixture/tmpnet/network.go +++ b/tests/fixture/tmpnet/network.go @@ -941,7 +941,7 @@ func checkVMBinariesExist(subnets []*Subnet, pluginDir string) error { 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)) + errs = append(errs, fmt.Errorf("failed to check VM binary for subnet %q: %w", subnet.Name, err)) } } }