Skip to content

Commit 73886f1

Browse files
authored
CNI testing (#397)
Update README.md Update cni_test.go
1 parent bd0bcc4 commit 73886f1

File tree

3 files changed

+241
-8
lines changed

3 files changed

+241
-8
lines changed

validation/provisioning/rke2/README.md

Lines changed: 28 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -68,10 +68,30 @@ Cloud Provider test verifies that node driver clusers can be provisioned with AW
6868
1. `gotestsum --format standard-verbose --packages=github.com/rancher/tests/validation/provisioning/rke2 --junitfile results.xml --jsonfile results.json -- -tags=validation -run TestCloudProvider -timeout=1h -v`
6969

7070

71+
### CNI Test
72+
73+
#### Description:
74+
CNI test verifies that clusters can provision properly with various CNIs.
75+
76+
#### Required Configurations:
77+
1. [Cloud Credential](#cloud-credential-config)
78+
2. [Cluster Config](#cluster-config)
79+
3. [Machine Config](#machine-config)
80+
81+
#### Table Tests
82+
1. `RKE2_Node_Driver|Calico`
83+
2. `RKE2_Node_Driver|Canal`
84+
3. `RKE2_Node_Driver|Flannel`
85+
4. `RKE2_Node_Driver|Cilium`
86+
87+
#### Run Commands:
88+
1. `gotestsum --format standard-verbose --packages=github.com/rancher/tests/validation/provisioning/rke2 --junitfile results.xml --jsonfile results.json -- -tags=validation -run TestCNI -timeout=1h -v`
89+
90+
7191
### Custom Test
7292

7393
#### Description:
74-
Custom test verfies that various custom cluster configurations provision properly.
94+
Custom test verifies that various custom cluster configurations provision properly.
7595

7696
#### Required Configurations:
7797
1. [Cloud Credential](#cloud-credential-config)
@@ -109,7 +129,7 @@ Data Directories test verifies that files related to k8s, systemAgent and provis
109129
### Dynamic Custom Test
110130

111131
#### Description:
112-
Dynamic custom test verfies that a user defined custom cluster provisions properly.
132+
Dynamic custom test verifies that a user defined custom cluster provisions properly.
113133

114134
#### Required Configurations:
115135
1. [Cloud Credential](#cloud-credential-config)
@@ -126,7 +146,7 @@ Dynamic tests do not have a static name
126146
### Dynamic Node Driver Test
127147

128148
#### Description:
129-
Dynamic node driver test verfies that a user defined node driver cluster provisions properly.
149+
Dynamic node driver test verifies that a user defined node driver cluster provisions properly.
130150

131151
#### Required Configurations:
132152
1. [Cloud Credential](#cloud-credential-config)
@@ -143,7 +163,7 @@ Dynamic tests do not have a static name
143163
### Hardened Test
144164

145165
#### Description:
146-
Hardened test verfies that a cluster can deploy the cis-benchmark(2.11<=)/compliance(2.12+) chart on a custom cluster
166+
Hardened test verifies that a cluster can deploy the cis-benchmark(2.11<=)/compliance(2.12+) chart on a custom cluster
147167

148168
#### Required Configurations:
149169
1. [Cloud Credential](#cloud-credential-config)
@@ -160,7 +180,7 @@ Hardened test verfies that a cluster can deploy the cis-benchmark(2.11<=)/compli
160180
### Node Driver Test
161181

162182
#### Description:
163-
Node driver test verfies that various node driver cluster configurations provision properly.
183+
Node driver test verifies that various node driver cluster configurations provision properly.
164184

165185
#### Required Configurations:
166186
1. [Cloud Credential](#cloud-credential-config)
@@ -181,7 +201,7 @@ Node driver test verfies that various node driver cluster configurations provisi
181201
### PSACT Test
182202

183203
#### Description:
184-
PSACT(Pod Security Admission Configuration Template) Test verfies that various node driver clusters with different psact configurations provision properly.
204+
PSACT(Pod Security Admission Configuration Template) Test verifies that various node driver clusters with different psact configurations provision properly.
185205

186206
#### Required Configurations:
187207
1. [Cloud Credential](#cloud-credential-config)
@@ -200,7 +220,7 @@ PSACT(Pod Security Admission Configuration Template) Test verfies that various n
200220
### Template Test
201221

202222
#### Description:
203-
Template Test verfies that an RKE2 template can be used to provision a cluster.
223+
Template Test verifies that an RKE2 template can be used to provision a cluster.
204224

205225
#### Required Configurations:
206226
1. [Cloud Credential](#cloud-credential-config)
@@ -234,7 +254,7 @@ Hostname truncation test verifies that the node hostname is truncated properly.
234254
### All Tests
235255

236256
#### Description:
237-
Template Test verfies that an RKE2 template can be used to provision a cluster.
257+
Template Test verifies that an RKE2 template can be used to provision a cluster.
238258

239259
#### Required Configurations:
240260
1. [Cloud Credential](#cloud-credential-config)
Lines changed: 113 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,113 @@
1+
//go:build validation || recurring
2+
3+
package rke2
4+
5+
import (
6+
"os"
7+
"testing"
8+
9+
"github.com/rancher/shepherd/clients/rancher"
10+
"github.com/rancher/shepherd/extensions/cloudcredentials"
11+
"github.com/rancher/shepherd/pkg/config"
12+
"github.com/rancher/shepherd/pkg/config/operations"
13+
"github.com/rancher/shepherd/pkg/session"
14+
"github.com/rancher/tests/actions/clusters"
15+
"github.com/rancher/tests/actions/config/defaults"
16+
"github.com/rancher/tests/actions/logging"
17+
"github.com/rancher/tests/actions/provisioning"
18+
"github.com/rancher/tests/actions/qase"
19+
"github.com/rancher/tests/actions/workloads/pods"
20+
standard "github.com/rancher/tests/validation/provisioning/resources/standarduser"
21+
"github.com/sirupsen/logrus"
22+
"github.com/stretchr/testify/require"
23+
)
24+
25+
type cniTest struct {
26+
client *rancher.Client
27+
session *session.Session
28+
standardUserClient *rancher.Client
29+
cattleConfig map[string]any
30+
}
31+
32+
func cniSetup(t *testing.T) cniTest {
33+
var r cniTest
34+
testSession := session.NewSession()
35+
r.session = testSession
36+
37+
client, err := rancher.NewClient("", testSession)
38+
require.NoError(t, err)
39+
r.client = client
40+
41+
r.cattleConfig = config.LoadConfigFromFile(os.Getenv(config.ConfigEnvironmentKey))
42+
43+
r.cattleConfig, err = defaults.LoadPackageDefaults(r.cattleConfig, "")
44+
require.NoError(t, err)
45+
46+
loggingConfig := new(logging.Logging)
47+
operations.LoadObjectFromMap(logging.LoggingKey, r.cattleConfig, loggingConfig)
48+
49+
err = logging.SetLogger(loggingConfig)
50+
require.NoError(t, err)
51+
52+
r.cattleConfig, err = defaults.SetK8sDefault(r.client, defaults.RKE2, r.cattleConfig)
53+
require.NoError(t, err)
54+
55+
r.standardUserClient, _, _, err = standard.CreateStandardUser(r.client)
56+
require.NoError(t, err)
57+
58+
return r
59+
}
60+
61+
func TestCNI(t *testing.T) {
62+
t.Parallel()
63+
r := cniSetup(t)
64+
65+
tests := []struct {
66+
name string
67+
client *rancher.Client
68+
cni string
69+
}{
70+
{"RKE2_Node_Driver|Calico", r.standardUserClient, "calico"},
71+
{"RKE2_Node_Driver|Canal", r.standardUserClient, "canal"},
72+
{"RKE2_Node_Driver|Flannel", r.standardUserClient, "flannel"},
73+
{"RKE2_Node_Driver|Cilium", r.standardUserClient, "cilium"},
74+
}
75+
76+
for _, tt := range tests {
77+
var err error
78+
t.Cleanup(func() {
79+
logrus.Infof("Running cleanup (%s)", tt.name)
80+
r.session.Cleanup()
81+
})
82+
83+
t.Run(tt.name, func(t *testing.T) {
84+
t.Parallel()
85+
86+
clusterConfig := new(clusters.ClusterConfig)
87+
operations.LoadObjectFromMap(defaults.ClusterConfigKey, r.cattleConfig, clusterConfig)
88+
require.NotNil(t, clusterConfig.Provider)
89+
90+
clusterConfig.CNI = tt.cni
91+
92+
provider := provisioning.CreateProvider(clusterConfig.Provider)
93+
credentialSpec := cloudcredentials.LoadCloudCredential(string(provider.Name))
94+
machineConfigSpec := provider.LoadMachineConfigFunc(r.cattleConfig)
95+
96+
logrus.Info("Provisioning cluster")
97+
cluster, err := provisioning.CreateProvisioningCluster(tt.client, provider, credentialSpec, clusterConfig, machineConfigSpec, nil)
98+
require.NoError(t, err)
99+
100+
logrus.Infof("Verifying the cluster is ready (%s)", cluster.Name)
101+
provisioning.VerifyClusterReady(t, r.client, cluster)
102+
103+
logrus.Infof("Verifying cluster pods (%s)", cluster.Name)
104+
pods.VerifyClusterPods(t, r.client, cluster)
105+
})
106+
107+
params := provisioning.GetProvisioningSchemaParams(tt.client, r.cattleConfig)
108+
err = qase.UpdateSchemaParameters(tt.name, params)
109+
if err != nil {
110+
logrus.Warningf("Failed to upload schema parameters %s", err)
111+
}
112+
}
113+
}

validation/provisioning/rke2/schemas/hostbusters_schemas.yaml

Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -767,6 +767,106 @@
767767
data: ""
768768
position: 3
769769
attachments: []
770+
custom_field:
771+
"14": Validation
772+
"18": Hostbusters
773+
- description: Provisions a 3 node split roles node driver cluster
774+
title: RKE2_Node_Driver|Calico
775+
priority: 4
776+
type: 8
777+
is_flaky: 0
778+
automation: 2
779+
steps:
780+
- action: Create rancher provider credentials
781+
expectedresult: ""
782+
data: ""
783+
position: 1
784+
attachments: []
785+
- action: Provision rke2 node driver cluster
786+
expectedresult: ""
787+
data: ""
788+
position: 2
789+
attachments: []
790+
- action: Verify cluster state
791+
expectedresult: ""
792+
data: ""
793+
position: 3
794+
attachments: []
795+
custom_field:
796+
"14": Validation
797+
"18": Hostbusters
798+
- description: Provisions a 3 node split roles node driver cluster
799+
title: RKE2_Node_Driver|Canal
800+
priority: 4
801+
type: 8
802+
is_flaky: 0
803+
automation: 2
804+
steps:
805+
- action: Create rancher provider credentials
806+
expectedresult: ""
807+
data: ""
808+
position: 1
809+
attachments: []
810+
- action: Provision rke2 node driver cluster
811+
expectedresult: ""
812+
data: ""
813+
position: 2
814+
attachments: []
815+
- action: Verify cluster state
816+
expectedresult: ""
817+
data: ""
818+
position: 3
819+
attachments: []
820+
custom_field:
821+
"14": Validation
822+
"18": Hostbusters
823+
- description: Provisions a 3 node split roles node driver cluster
824+
title: RKE2_Node_Driver|Flannel
825+
priority: 4
826+
type: 8
827+
is_flaky: 0
828+
automation: 2
829+
steps:
830+
- action: Create rancher provider credentials
831+
expectedresult: ""
832+
data: ""
833+
position: 1
834+
attachments: []
835+
- action: Provision rke2 node driver cluster
836+
expectedresult: ""
837+
data: ""
838+
position: 2
839+
attachments: []
840+
- action: Verify cluster state
841+
expectedresult: ""
842+
data: ""
843+
position: 3
844+
attachments: []
845+
custom_field:
846+
"14": Validation
847+
"18": Hostbusters
848+
- description: Provisions a 3 node split roles node driver cluster
849+
title: RKE2_Node_Driver|Cilium
850+
priority: 4
851+
type: 8
852+
is_flaky: 0
853+
automation: 2
854+
steps:
855+
- action: Create rancher provider credentials
856+
expectedresult: ""
857+
data: ""
858+
position: 1
859+
attachments: []
860+
- action: Provision rke2 node driver cluster
861+
expectedresult: ""
862+
data: ""
863+
position: 2
864+
attachments: []
865+
- action: Verify cluster state
866+
expectedresult: ""
867+
data: ""
868+
position: 3
869+
attachments: []
770870
custom_field:
771871
"14": Validation
772872
"18": Hostbusters

0 commit comments

Comments
 (0)