|
1 | 1 | // Copyright (C) 2019-2023, Ava Labs, Inc. All rights reserved. |
2 | 2 | // See the file LICENSE for licensing terms. |
3 | 3 |
|
4 | | -// Runs upgrade tests. |
5 | | -package upgrade_test |
| 4 | +package upgrade |
6 | 5 |
|
7 | 6 | import ( |
8 | | - "context" |
9 | 7 | "flag" |
10 | 8 | "fmt" |
11 | | - "os" |
| 9 | + "strings" |
12 | 10 | "testing" |
13 | | - "time" |
14 | 11 |
|
15 | 12 | "github.com/onsi/ginkgo/v2" |
| 13 | + |
16 | 14 | "github.com/onsi/gomega" |
17 | 15 |
|
18 | | - runner_sdk "github.com/ava-labs/avalanche-network-runner-sdk" |
| 16 | + "github.com/stretchr/testify/require" |
19 | 17 |
|
20 | | - "github.com/ava-labs/avalanchego/tests" |
| 18 | + "github.com/ava-labs/avalanchego/config" |
| 19 | + "github.com/ava-labs/avalanchego/tests/e2e" |
21 | 20 | ) |
22 | 21 |
|
23 | | -const DefaultTimeout = 2 * time.Minute |
24 | | - |
25 | 22 | func TestUpgrade(t *testing.T) { |
26 | 23 | gomega.RegisterFailHandler(ginkgo.Fail) |
27 | 24 | ginkgo.RunSpecs(t, "upgrade test suites") |
28 | 25 | } |
29 | 26 |
|
30 | 27 | var ( |
31 | | - logLevel string |
32 | | - networkRunnerGRPCEp string |
33 | | - networkRunnerAvalancheGoExecPath string |
34 | | - networkRunnerAvalancheGoExecPathToUpgrade string |
35 | | - networkRunnerAvalancheGoLogLevel string |
| 28 | + avalancheGoExecPath string |
| 29 | + avalancheGoExecPathToUpgradeTo string |
36 | 30 | ) |
37 | 31 |
|
38 | 32 | func init() { |
39 | 33 | flag.StringVar( |
40 | | - &logLevel, |
41 | | - "log-level", |
42 | | - "info", |
43 | | - "log level", |
44 | | - ) |
45 | | - flag.StringVar( |
46 | | - &networkRunnerGRPCEp, |
47 | | - "network-runner-grpc-endpoint", |
48 | | - "", |
49 | | - "gRPC server endpoint for network-runner", |
50 | | - ) |
51 | | - flag.StringVar( |
52 | | - &networkRunnerAvalancheGoExecPath, |
53 | | - "network-runner-avalanchego-path", |
| 34 | + &avalancheGoExecPath, |
| 35 | + "avalanchego-path", |
54 | 36 | "", |
55 | 37 | "avalanchego executable path", |
56 | 38 | ) |
57 | 39 | flag.StringVar( |
58 | | - &networkRunnerAvalancheGoExecPathToUpgrade, |
59 | | - "network-runner-avalanchego-path-to-upgrade", |
| 40 | + &avalancheGoExecPathToUpgradeTo, |
| 41 | + "avalanchego-path-to-upgrade-to", |
60 | 42 | "", |
61 | | - "avalanchego executable path (to upgrade to, only required for upgrade tests with local network-runner)", |
62 | | - ) |
63 | | - flag.StringVar( |
64 | | - &networkRunnerAvalancheGoLogLevel, |
65 | | - "network-runner-avalanchego-log-level", |
66 | | - "INFO", |
67 | | - "avalanchego log-level", |
| 43 | + "avalanchego executable path to upgrade to", |
68 | 44 | ) |
69 | 45 | } |
70 | 46 |
|
71 | | -var runnerCli runner_sdk.Client |
72 | | - |
73 | | -var _ = ginkgo.BeforeSuite(func() { |
74 | | - _, err := os.Stat(networkRunnerAvalancheGoExecPath) |
75 | | - gomega.Expect(err).Should(gomega.BeNil()) |
76 | | - |
77 | | - _, err = os.Stat(networkRunnerAvalancheGoExecPathToUpgrade) |
78 | | - gomega.Expect(err).Should(gomega.BeNil()) |
79 | | - |
80 | | - runnerCli, err = runner_sdk.New(runner_sdk.Config{ |
81 | | - LogLevel: logLevel, |
82 | | - Endpoint: networkRunnerGRPCEp, |
83 | | - DialTimeout: 10 * time.Second, |
84 | | - }) |
85 | | - gomega.Expect(err).Should(gomega.BeNil()) |
86 | | - |
87 | | - ctx, cancel := context.WithTimeout(context.Background(), DefaultTimeout) |
88 | | - presp, err := runnerCli.Ping(ctx) |
89 | | - cancel() |
90 | | - gomega.Expect(err).Should(gomega.BeNil()) |
91 | | - tests.Outf("{{green}}network-runner running in PID %d{{/}}\n", presp.Pid) |
92 | | - |
93 | | - tests.Outf("{{magenta}}starting network-runner with %q{{/}}\n", networkRunnerAvalancheGoExecPath) |
94 | | - ctx, cancel = context.WithTimeout(context.Background(), DefaultTimeout) |
95 | | - resp, err := runnerCli.Start(ctx, networkRunnerAvalancheGoExecPath, |
96 | | - runner_sdk.WithNumNodes(5), |
97 | | - runner_sdk.WithGlobalNodeConfig(fmt.Sprintf(`{"log-level":"%s"}`, networkRunnerAvalancheGoLogLevel)), |
98 | | - ) |
99 | | - cancel() |
100 | | - gomega.Expect(err).Should(gomega.BeNil()) |
101 | | - tests.Outf("{{green}}successfully started network-runner: {{/}} %+v\n", resp.ClusterInfo.NodeNames) |
102 | | - |
103 | | - ctx, cancel = context.WithTimeout(context.Background(), DefaultTimeout) |
104 | | - _, err = runnerCli.Health(ctx) |
105 | | - cancel() |
106 | | - gomega.Expect(err).Should(gomega.BeNil()) |
107 | | -}) |
108 | | - |
109 | | -var _ = ginkgo.AfterSuite(func() { |
110 | | - tests.Outf("{{red}}shutting down network-runner cluster{{/}}\n") |
111 | | - ctx, cancel := context.WithTimeout(context.Background(), DefaultTimeout) |
112 | | - _, err := runnerCli.Stop(ctx) |
113 | | - cancel() |
114 | | - gomega.Expect(err).Should(gomega.BeNil()) |
115 | | - |
116 | | - tests.Outf("{{red}}shutting down network-runner client{{/}}\n") |
117 | | - err = runnerCli.Close() |
118 | | - gomega.Expect(err).Should(gomega.BeNil()) |
119 | | -}) |
120 | | - |
121 | 47 | var _ = ginkgo.Describe("[Upgrade]", func() { |
122 | | - ginkgo.It("can upgrade versions", func() { |
123 | | - tests.Outf("{{magenta}}starting upgrade tests %q{{/}}\n", networkRunnerAvalancheGoExecPathToUpgrade) |
124 | | - ctx, cancel := context.WithTimeout(context.Background(), DefaultTimeout) |
125 | | - sresp, err := runnerCli.Status(ctx) |
126 | | - cancel() |
127 | | - gomega.Expect(err).Should(gomega.BeNil()) |
128 | | - |
129 | | - for _, name := range sresp.ClusterInfo.NodeNames { |
130 | | - tests.Outf("{{magenta}}restarting the node %q{{/}} with %q\n", name, networkRunnerAvalancheGoExecPathToUpgrade) |
131 | | - ctx, cancel := context.WithTimeout(context.Background(), DefaultTimeout) |
132 | | - resp, err := runnerCli.RestartNode(ctx, name, runner_sdk.WithExecPath(networkRunnerAvalancheGoExecPathToUpgrade)) |
133 | | - cancel() |
134 | | - gomega.Expect(err).Should(gomega.BeNil()) |
| 48 | + require := require.New(ginkgo.GinkgoT()) |
135 | 49 |
|
136 | | - ctx, cancel = context.WithTimeout(context.Background(), DefaultTimeout) |
137 | | - _, err = runnerCli.Health(ctx) |
138 | | - cancel() |
139 | | - gomega.Expect(err).Should(gomega.BeNil()) |
140 | | - tests.Outf("{{green}}successfully upgraded %q to %q{{/}} (current info: %+v)\n", name, networkRunnerAvalancheGoExecPathToUpgrade, resp.ClusterInfo.NodeInfos) |
| 50 | + ginkgo.It("can upgrade versions", func() { |
| 51 | + // TODO(marun) How many nodes should the target network have to best validate upgrade? |
| 52 | + network := e2e.StartLocalNetwork(avalancheGoExecPath, e2e.DefaultNetworkDir) |
| 53 | + |
| 54 | + ginkgo.By(fmt.Sprintf("restarting all nodes with %q binary", avalancheGoExecPathToUpgradeTo)) |
| 55 | + for _, node := range network.Nodes { |
| 56 | + ginkgo.By(fmt.Sprintf("restarting node %q with %q binary", node.GetID(), avalancheGoExecPathToUpgradeTo)) |
| 57 | + require.NoError(node.Stop()) |
| 58 | + |
| 59 | + // A node must start with sufficient bootstrap nodes to represent a quorum. Since the node's current |
| 60 | + // bootstrap configuration may not satisfy this requirement (i.e. if on network start the node was one of |
| 61 | + // the first validators), updating the node to bootstrap from all running validators maximizes the |
| 62 | + // chances of a successful start. |
| 63 | + // |
| 64 | + // TODO(marun) Refactor node start to do this automatically |
| 65 | + bootstrapIPs, bootstrapIDs, err := network.GetBootstrapIPsAndIds() |
| 66 | + require.NoError(err) |
| 67 | + require.NotEmpty(bootstrapIDs) |
| 68 | + node.Flags[config.BootstrapIDsKey] = strings.Join(bootstrapIDs, ",") |
| 69 | + node.Flags[config.BootstrapIPsKey] = strings.Join(bootstrapIPs, ",") |
| 70 | + require.NoError(node.WriteConfig()) |
| 71 | + |
| 72 | + require.NoError(node.Start(ginkgo.GinkgoWriter, avalancheGoExecPath)) |
| 73 | + |
| 74 | + ginkgo.By(fmt.Sprintf("waiting for node %q to report healthy after restart", node.GetID())) |
| 75 | + e2e.WaitForHealthy(node) |
141 | 76 | } |
142 | 77 | }) |
143 | 78 | }) |
0 commit comments