Skip to content

Commit 05071d6

Browse files
authored
rane sot uniq versions (#2471)
1 parent dc70cec commit 05071d6

File tree

8 files changed

+386
-111
lines changed

8 files changed

+386
-111
lines changed

.github/workflows/test.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,9 @@ jobs:
2525
- path: framework
2626
vm: ubuntu-latest
2727
regex: TestDX
28+
- path: framework
29+
vm: ubuntu-latest
30+
regex: TestChaos
2831
- path: wasp
2932
vm: ubuntu22.04-16cores-64GB # ghv-ignore!
3033
regex: TestSmoke

book/src/framework/compat.md

Lines changed: 38 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
## Prerequisites
44

55
Authorize in our SDLC ECR registry first. Get the creds and run
6+
67
```bash
78
aws ecr get-login-password --region us-west-2 | docker login --username AWS --password-stdin <sdlc_ecr_registry>
89
```
@@ -23,7 +24,7 @@ ctf compat backward \
2324
--refs 2.33.0 \
2425
--refs 2.34.0 \
2526
--refs 2.35.0 \
26-
--nodes 3
27+
--upgrade-nodes 3
2728
```
2829

2930
Keep in mind that `refs` should be present in regsitry you are testing against, the first (oldest) `ref` should also have a valid end-to-end test that works.
@@ -32,27 +33,52 @@ In CI we detect SemVer tags automatically, whenever a new tag appears we select
3233

3334
```bash
3435
ctf compat backward \
35-
--registry <sdlc_ecr_registry> \
36+
--registry <sdlc_ecr_chainlink_registry> \
3637
--buildcmd "just cli" \
37-
--envcmd "cl r" \
38+
--envcmd "cl r env.toml,products/ocr2/basic.toml" \
3839
--testcmd "cl test ocr2 TestSmoke/rounds" \
39-
--nodes 3 \
40-
--versions-back 3
40+
--strip-image-suffix v \
41+
--upgrade-nodes 2 \
42+
--versions-back 2
4143
```
4244

4345
In case you have multiple DONs in your product and names of nodes are different please use `--node-name-template custom-cl-node-%d` option
4446

45-
## Modelling Node Operators Cluster
47+
## Modelling Node Operators Cluster (WIP)
4648

47-
It is possible to fetch versions node operators are currently running and model DON upgrade sequence locally. Logic is the same, get all the versions, rollback to the oldest one, setup product, verify, try to upgrade all the versions running the oldest test for each upgrade.
49+
It is possible to fetch versions node operators are currently running and model DON upgrade sequence locally. When `product` is specified, `compat` will fetch the current versions from the RANE SOT data source and model the upgrade sequence for versions found on real DONs up to the latest one, each node one at a time.
4850

4951
```bash
5052
ctf compat backward \
51-
--registry <sdlc_ecr_registry>\
53+
--registry <sdlc_ecr_chainlink_registry> \
5254
--buildcmd "just cli" \
53-
--envcmd "cl r" \
55+
--envcmd "cl r env.toml,products/ocr2/basic.toml" \
56+
--testcmd "cl test ocr2 TestSmoke/rounds" \
57+
--product data-feeds \
58+
--no-git-rollback \
59+
--don_nodes 5
60+
```
61+
62+
The tool will check out earliest Git `ref` and setup environment and tests.
63+
64+
If you don't have tests on this tag you can use `--no-git-rollback` to skip the rollback step.
65+
66+
Since not all the versions from SOT are currently having corresponding Git tags or images, you can provide refs directly using `--refs` flag, useful for testing.
67+
68+
```bash
69+
ctf compat backward \
70+
--registry <sdlc_ecr_chainlink_registry>\
71+
--buildcmd "just cli" \
72+
--envcmd "cl r env.toml,products/ocr2/basic.toml" \
5473
--testcmd "cl test ocr2 TestSmoke/rounds" \
55-
--nop northwestnodes \
56-
--versions-back 3 \
57-
--nodes 3
74+
--product data-feeds \
75+
--refs "2.36.1-rc.0" \
76+
--refs "2.36.1-beta.0" \
77+
--refs "2.36.1-beta.2" \
78+
--refs "2.37.0-rc.0" \
79+
--refs "2.37.0-beta.0" \
80+
--refs "2.38.0-rc.0" \
81+
--refs "2.38.0-beta.0" \
82+
--no-git-rollback \
83+
--don_nodes 5
5884
```

framework/.changeset/v0.15.6.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
- Model DONs from SOT data source for upgrade testing

framework/chaos/chaos.go

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ func NewDockerChaos(ctx context.Context) (*DockerChaos, error) {
5858
Image: "lukaszlach/docker-tc",
5959
Name: dockerTCContainerName,
6060
CapAdd: []string{"NET_ADMIN"},
61-
WaitingFor: wait.ForLog("Starting Docker Traffic Control"),
61+
WaitingFor: wait.ForLog("Forwarding requests to /docker-tc"),
6262
HostConfigModifier: func(h *container.HostConfig) {
6363
h.Privileged = true
6464
h.NetworkMode = "host"
@@ -75,7 +75,6 @@ func NewDockerChaos(ctx context.Context) (*DockerChaos, error) {
7575
_, err := testcontainers.GenericContainer(ctx, testcontainers.GenericContainerRequest{
7676
ContainerRequest: req,
7777
Started: true,
78-
Reuse: true,
7978
})
8079
if err != nil {
8180
return nil, fmt.Errorf("failed to start docker-tc container: %w", err)
@@ -87,13 +86,13 @@ func NewDockerChaos(ctx context.Context) (*DockerChaos, error) {
8786

8887
// RemoveAll removes all the experiments
8988
func (m *DockerChaos) RemoveAll() error {
90-
for containerName, experimentCmd := range m.Experiments {
89+
for containerName, experimentRemoveCmd := range m.Experiments {
9190
framework.L.Info().
9291
Str("Container", containerName).
93-
Str("Cmd", experimentCmd).
92+
Str("Cmd", experimentRemoveCmd).
9493
Msg("Removing chaos for container")
95-
if _, err := framework.ExecCmd(experimentCmd); err != nil {
96-
return fmt.Errorf("failed to remove chaos experiment: name: %s, command:%s, err: %w", containerName, experimentCmd, err)
94+
if _, err := framework.ExecCmd(experimentRemoveCmd); err != nil {
95+
return fmt.Errorf("failed to remove chaos experiment: name: %s, command:%s, err: %w", containerName, experimentRemoveCmd, err)
9796
}
9897
}
9998
m.Experiments = make(map[string]string)

framework/chaos/chaos_test.go

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,21 +6,22 @@ import (
66

77
"github.com/stretchr/testify/require"
88

9+
"github.com/smartcontractkit/chainlink-testing-framework/framework"
910
"github.com/smartcontractkit/chainlink-testing-framework/framework/chaos"
1011
"github.com/smartcontractkit/chainlink-testing-framework/framework/rpc"
1112
)
1213

13-
func TestSmokeChaos(t *testing.T) {
14-
c, err := rpc.StartAnvil([]string{"--balance", "1", "--block-time", "5"})
14+
func TestChaos(t *testing.T) {
15+
err := framework.DefaultNetwork(nil)
1516
require.NoError(t, err)
16-
17-
i, err := c.Inspect(t.Context())
17+
_, err = rpc.StartAnvil([]string{"--balance", "1", "--block-time", "5"})
1818
require.NoError(t, err)
19-
containerName := i.Name[1:]
2019

2120
dtc, err := chaos.NewDockerChaos(t.Context())
2221
require.NoError(t, err)
2322

23+
containerName := "anvil"
24+
2425
tests := []struct {
2526
name string
2627
containerName string

framework/cmd/main.go

Lines changed: 65 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -281,18 +281,27 @@ Be aware that any TODO requires your attention before your run the final test!
281281
Name: "backward",
282282
Aliases: []string{"b"},
283283
Flags: []cli.Flag{
284+
&cli.BoolFlag{
285+
Name: "no-git-rollback",
286+
Usage: "Disable Git rollback, run current version of env and command",
287+
},
284288
&cli.IntFlag{
285289
Name: "versions-back",
286290
Aliases: []string{"v"},
287291
Usage: "How many versions back to test",
288292
Value: 1,
289293
},
290294
&cli.IntFlag{
291-
Name: "nodes",
295+
Name: "upgrade-nodes",
292296
Aliases: []string{"n"},
293297
Usage: "How many nodes to upgrade",
294298
Value: 3,
295299
},
300+
&cli.IntFlag{
301+
Name: "don_nodes",
302+
Usage: "How many total nodes DON have",
303+
Value: 5,
304+
},
296305
&cli.StringFlag{
297306
Name: "registry",
298307
Aliases: []string{"r"},
@@ -301,7 +310,11 @@ Be aware that any TODO requires your attention before your run the final test!
301310
},
302311
&cli.StringFlag{
303312
Name: "strip-image-suffix",
304-
Usage: "Stripts image suffix from ref to map it to registry images",
313+
Usage: "Strips image suffix from ref to map it to registry images",
314+
},
315+
&cli.StringFlag{
316+
Name: "rane-add-git-tag-prefix",
317+
Usage: "Add Git tag prefix to RANE's refs to match Git tags",
305318
},
306319
&cli.StringFlag{
307320
Name: "buildcmd",
@@ -320,8 +333,8 @@ Be aware that any TODO requires your attention before your run the final test!
320333
Usage: "Test verification command",
321334
},
322335
&cli.StringFlag{
323-
Name: "nop",
324-
Usage: "Find specific NOPs ref upgrade sequence",
336+
Name: "product",
337+
Usage: "Find specific NOPs ref upgrade sequence by product. See RANE SOT default URL, maps to 'jq '.nodes[].jobs[].product' from data source",
325338
},
326339
&cli.StringFlag{
327340
Name: "node-name-template",
@@ -352,6 +365,7 @@ Be aware that any TODO requires your attention before your run the final test!
352365
},
353366
Usage: "Rollbacks N versions back, runs the test the upgrades CL nodes with new versions",
354367
Action: func(c *cli.Context) error {
368+
noGitRollback := c.Bool("no-git-rollback")
355369
versionsBack := c.Int("versions-back")
356370
registry := c.String("registry")
357371
refs := c.StringSlice("refs")
@@ -361,13 +375,15 @@ Be aware that any TODO requires your attention before your run the final test!
361375
buildcmd := c.String("buildcmd")
362376
envcmd := c.String("envcmd")
363377
testcmd := c.String("testcmd")
364-
nodes := c.Int("nodes")
378+
upgradeNodes := c.Int("upgrade-nodes")
379+
donNodes := c.Int("don_nodes")
365380
nodeNameTemplate := c.String("node-name-template")
366381

367-
nop := c.String("nop")
368-
sotURL := c.String("sot-url")
382+
product := c.String("product")
369383
skipPull := c.Bool("skip-pull")
370384

385+
sotURL := c.String("sot-url")
386+
371387
// test logic is:
372388
// - rollback to selected ref
373389
// - spin up the env and perform the initial smoke test
@@ -377,33 +393,51 @@ Be aware that any TODO requires your attention before your run the final test!
377393

378394
// if no refs provided find refs (tags) sequence SemVer sequence for last N versions_back
379395
// else, use refs param slice
380-
//
396+
397+
// Step 1: Find upgrade sequence either from Git refs or product unique versions found in SOT data source
398+
381399
var err error
382-
if len(refs) == 0 && nop == "" {
400+
if len(refs) == 0 && product == "" {
383401
refs, err = framework.FindSemVerRefSequence(versionsBack, include, exclude)
384402
if err != nil {
385403
return err
386404
}
387405
}
388-
if nop != "" {
389-
refs, err = framework.FindNOPRefs(sotURL, nop, exclude)
406+
407+
if product != "" {
408+
// TODO: Stub, until versions are mapped properly and not skipped this is just an example
409+
// Both Git, ECR and "versions" from SOT data do not match
410+
// so we fetch the data but do not use it for now
411+
// test refs are populated from --refs, see docs and CI in core
412+
_, err := framework.FindNOPsVersionsByProduct(sotURL, product, exclude)
390413
if err != nil {
391414
return err
392415
}
393416
}
417+
394418
framework.L.Info().
395419
Int("TotalSemVerRefs", len(refs)).
396420
Strs("SelectedRefs", refs).
397421
Str("EarliestRefs", refs[0]).
398422
Msg("Formed upgrade sequence")
423+
399424
// if no commands just show the tags and return
400425
if buildcmd == "" || envcmd == "" || testcmd == "" {
401426
framework.L.Info().Msg("No envcmd or testcmd or buildcmd provided, skipping")
402427
return nil
403428
}
404-
// checkout the oldest ref
405-
if err := framework.CheckOut(refs[0]); err != nil {
406-
return err
429+
430+
// RANE doesn't have Git tags so we are mapping field "version" to Git tag
431+
gitTagPrefix := c.String("rane-add-git-tag-prefix")
432+
for i := range refs {
433+
refs[i] = fmt.Sprintf("%s%s", gitTagPrefix, refs[i])
434+
}
435+
436+
// checkout the oldest ref if we need to preserve test setup isolation
437+
if !noGitRollback {
438+
if err := framework.CheckOut(refs[0]); err != nil {
439+
return err
440+
}
407441
}
408442

409443
// this is a hack allowing us to match what we have in Git to registry or NOP version
@@ -413,42 +447,25 @@ Be aware that any TODO requires your attention before your run the final test!
413447
refs[i] = strings.ReplaceAll(refs[i], testImgSuffix, "")
414448
}
415449

416-
// setup the env and verify with test command
417-
framework.L.Info().Strs("Sequence", refs).Msg("Running upgrade sequence")
418-
// first env var is used by devenv, second by simple nodeset to override the image
419-
os.Setenv("CHAINLINK_IMAGE", fmt.Sprintf("%s:%s", registry, refs[0]))
420-
os.Setenv("CTF_CHAINLINK_IMAGE", fmt.Sprintf("%s:%s", registry, refs[0]))
421-
if _, err := framework.ExecCmdWithContext(c.Context, buildcmd); err != nil {
422-
return err
423-
}
424-
if _, err := framework.ExecCmdWithContext(c.Context, envcmd); err != nil {
425-
return err
450+
// Step 2: Perform upgrade testing with either upgrading through last N versions
451+
// or by modelling versions from SOT data source, then upgrading to the latest version
452+
upgradeContext := framework.UpgradeContext{
453+
ProductName: product,
454+
Refs: refs,
455+
DonNodes: donNodes,
456+
UpgradeNodes: upgradeNodes,
457+
NodeNameTemplate: nodeNameTemplate,
458+
Registry: registry,
459+
Buildcmd: buildcmd,
460+
Envcmd: envcmd,
461+
Testcmd: testcmd,
462+
SkipPull: skipPull,
426463
}
427-
if _, err := framework.ExecCmdWithContext(c.Context, testcmd); err != nil {
428-
return err
429-
}
430-
// start upgrading nodes and verifying with tests, all the versions except the oldest one
431-
for _, tag := range refs[1:] {
432-
framework.L.Info().
433-
Int("Nodes", nodes).
434-
Str("Version", tag).
435-
Msg("Upgrading nodes")
436-
img := fmt.Sprintf("%s:%s", registry, tag)
437-
if !skipPull {
438-
if _, err := framework.ExecCmdWithContext(c.Context, fmt.Sprintf("docker pull %s", img)); err != nil {
439-
return fmt.Errorf("failed to pull image %s: %w", img, err)
440-
}
441-
}
442-
for i := range nodes {
443-
if err := framework.UpgradeContainer(c.Context, fmt.Sprintf(nodeNameTemplate, i), img); err != nil {
444-
return err
445-
}
446-
}
447-
if _, err := framework.ExecCmd(testcmd); err != nil {
448-
return err
449-
}
464+
465+
if product != "" {
466+
return framework.UpgradeNProductUniqueVersionsRolling(c.Context, upgradeContext)
450467
}
451-
return nil
468+
return framework.UpgradeNRolling(c.Context, upgradeContext)
452469
},
453470
},
454471
},

0 commit comments

Comments
 (0)