forked from openshift/assisted-service
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcnv_operator_test.go
429 lines (368 loc) · 17.7 KB
/
cnv_operator_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
package cnv_test
import (
"context"
. "github.com/onsi/ginkgo"
"github.com/onsi/ginkgo/extensions/table"
. "github.com/onsi/gomega"
"github.com/openshift/assisted-service/internal/common"
"github.com/openshift/assisted-service/internal/operators/api"
"github.com/openshift/assisted-service/internal/operators/cnv"
"github.com/openshift/assisted-service/internal/operators/lso"
"github.com/openshift/assisted-service/internal/operators/lvm"
"github.com/openshift/assisted-service/models"
"github.com/openshift/assisted-service/pkg/conversions"
"github.com/sirupsen/logrus"
)
var _ = Describe("CNV operator", func() {
var (
log = logrus.New()
operator api.Operator
)
BeforeEach(func() {
cfg := cnv.Config{
SupportedGPUs: map[string]bool{
"10de:1db6": true,
"10de:1eb8": true,
},
SupportedSRIOVNetworkIC: map[string]bool{
"8086:158b": true,
"15b3:1015": true,
}}
operator = cnv.NewCNVOperator(log, cfg, nil)
})
Context("getDependencies", func() {
It("request for lvmo", func() {
haMode := models.ClusterHighAvailabilityModeNone
cluster := common.Cluster{
Cluster: models.Cluster{HighAvailabilityMode: &haMode, OpenshiftVersion: lvm.LvmsMinOpenshiftVersion},
}
requirements, err := operator.GetDependencies(&cluster)
Expect(err).ToNot(HaveOccurred())
Expect(requirements).ToNot(BeNil())
Expect(requirements[0]).To(BeEquivalentTo(lvm.Operator.Name))
})
It("request for lso, ocp version older than 4.11 will not get lvmo", func() {
haMode := models.ClusterHighAvailabilityModeNone
cluster := common.Cluster{
Cluster: models.Cluster{HighAvailabilityMode: &haMode, OpenshiftVersion: "4.11.0-0.0"},
}
requirements, err := operator.GetDependencies(&cluster)
Expect(err).ToNot(HaveOccurred())
Expect(requirements).ToNot(BeNil())
Expect(requirements[0]).To(BeEquivalentTo(lso.Operator.Name))
})
})
Context("host requirements", func() {
var cluster common.Cluster
BeforeEach(func() {
mode := models.ClusterHighAvailabilityModeFull
cluster = common.Cluster{
Cluster: models.Cluster{HighAvailabilityMode: &mode, OpenshiftVersion: lvm.LvmsMinOpenshiftVersion},
}
})
table.DescribeTable("should be returned for no inventory", func(role models.HostRole, expectedRequirements *models.ClusterHostRequirementsDetails) {
host := models.Host{Role: role}
requirements, err := operator.GetHostRequirements(context.TODO(), &cluster, &host)
Expect(err).ToNot(HaveOccurred())
Expect(requirements).ToNot(BeNil())
Expect(requirements).To(BeEquivalentTo(expectedRequirements))
},
table.Entry("for master", models.HostRoleMaster, newRequirements(cnv.MasterCPU, cnv.MasterMemory)),
table.Entry("for worker", models.HostRoleWorker, newRequirements(cnv.WorkerCPU, cnv.WorkerMemory)),
)
table.DescribeTable("should be returned for worker inventory with supported GPUs",
func(gpus []*models.Gpu, expectedRequirements *models.ClusterHostRequirementsDetails) {
host := models.Host{
Role: models.HostRoleWorker,
Inventory: getInventoryWithGPUs(gpus),
}
requirements, err := operator.GetHostRequirements(context.TODO(), &cluster, &host)
Expect(err).ToNot(HaveOccurred())
Expect(requirements).ToNot(BeNil())
Expect(requirements).To(BeEquivalentTo(expectedRequirements))
},
table.Entry("1 supported GPU",
[]*models.Gpu{{DeviceID: "1db6", VendorID: "10de"}},
newRequirements(cnv.WorkerCPU, cnv.WorkerMemory+1024)),
table.Entry("1 supported GPU+1 unsupported",
[]*models.Gpu{{DeviceID: "1db6", VendorID: "10de"}, {DeviceID: "1111", VendorID: "0000"}},
newRequirements(cnv.WorkerCPU, cnv.WorkerMemory+1024)),
table.Entry("2 supported GPUs",
[]*models.Gpu{{DeviceID: "1db6", VendorID: "10de"}, {DeviceID: "1eb8", VendorID: "10de"}},
newRequirements(cnv.WorkerCPU, cnv.WorkerMemory+2*1024)),
table.Entry("3 identical supported GPUs",
[]*models.Gpu{{DeviceID: "1db6", VendorID: "10de"}, {DeviceID: "1db6", VendorID: "10de"}, {DeviceID: "1db6", VendorID: "10de"}},
newRequirements(cnv.WorkerCPU, cnv.WorkerMemory+3*1024)),
table.Entry("2 unsupported GPUs only",
[]*models.Gpu{{DeviceID: "2222", VendorID: "0000"}, {DeviceID: "1111", VendorID: "0000"}},
newRequirements(cnv.WorkerCPU, cnv.WorkerMemory)),
)
table.DescribeTable("should be returned for worker inventory with supported SR-IOV interfaces",
func(interfaces []*models.Interface, expectedRequirements *models.ClusterHostRequirementsDetails) {
host := models.Host{
Role: models.HostRoleWorker,
Inventory: getInventoryWithInterfaces(interfaces),
}
requirements, err := operator.GetHostRequirements(context.TODO(), &cluster, &host)
Expect(err).ToNot(HaveOccurred())
Expect(requirements).ToNot(BeNil())
Expect(requirements).To(BeEquivalentTo(expectedRequirements))
},
table.Entry("1 supported SR-IOV Interface",
[]*models.Interface{{Product: "0x158b", Vendor: "0x8086"}},
newRequirements(cnv.WorkerCPU, cnv.WorkerMemory+1024)),
table.Entry("1 supported SR-IOV Interface+1 unsupported",
[]*models.Interface{{Product: "0x158B", Vendor: "0x8086"}, {Product: "1111", Vendor: "0000"}},
newRequirements(cnv.WorkerCPU, cnv.WorkerMemory+1024)),
table.Entry("2 supported SR-IOV Interfaces",
[]*models.Interface{{Product: "0x158b", Vendor: "0x8086"}, {Product: "1015", Vendor: "15b3"}},
newRequirements(cnv.WorkerCPU, cnv.WorkerMemory+2*1024)),
table.Entry("3 identical supported SR-IOV Interfaces",
[]*models.Interface{{Product: "0x158b", Vendor: "0x8086"}, {Product: "0x158b", Vendor: "0x8086"}, {Product: "0x158b", Vendor: "0x8086"}},
newRequirements(cnv.WorkerCPU, cnv.WorkerMemory+3*1024)),
table.Entry("2 unsupported SR-IOV Interfaces only",
[]*models.Interface{{Product: "2222", Vendor: "0000"}, {Product: "1111", Vendor: "0000"}},
newRequirements(cnv.WorkerCPU, cnv.WorkerMemory)),
)
table.DescribeTable("should be returned for master inventory with GPUs", func(gpus []*models.Gpu) {
host := models.Host{
Role: models.HostRoleMaster,
Inventory: getInventoryWithGPUs(gpus),
}
requirements, err := operator.GetHostRequirements(context.TODO(), &cluster, &host)
Expect(err).ToNot(HaveOccurred())
Expect(requirements).ToNot(BeNil())
Expect(requirements).To(BeEquivalentTo(newRequirements(cnv.MasterCPU, cnv.MasterMemory)))
},
table.Entry("1 supported GPU",
[]*models.Gpu{{DeviceID: "1db6", VendorID: "10de"}}),
table.Entry("2 supported GPUs",
[]*models.Gpu{{DeviceID: "1db6", VendorID: "10de"}, {DeviceID: "1eb8", VendorID: "10de"}}),
table.Entry("3 identical supported GPUs",
[]*models.Gpu{{DeviceID: "1db6", VendorID: "10de"}, {DeviceID: "1db6", VendorID: "10de"}, {DeviceID: "1db6", VendorID: "10de"}}),
table.Entry("1 unsupported GPU",
[]*models.Gpu{{DeviceID: "1111", VendorID: "0000"}}),
table.Entry("2 unsupported GPUs only",
[]*models.Gpu{{DeviceID: "2222", VendorID: "0000"}, {DeviceID: "1111", VendorID: "0000"}}),
)
table.DescribeTable("should be returned for master inventory with SR-IOV interfaces",
func(interfaces []*models.Interface) {
host := models.Host{
Role: models.HostRoleMaster,
Inventory: getInventoryWithInterfaces(interfaces),
}
requirements, err := operator.GetHostRequirements(context.TODO(), &cluster, &host)
Expect(err).ToNot(HaveOccurred())
Expect(requirements).ToNot(BeNil())
Expect(requirements).To(BeEquivalentTo(newRequirements(cnv.MasterCPU, cnv.MasterMemory)))
},
table.Entry("1 supported SR-IOV Interface",
[]*models.Interface{{Product: "0x158b", Vendor: "0x8086"}}),
table.Entry("1 supported SR-IOV Interface+1 unsupported",
[]*models.Interface{{Product: "0x158b", Vendor: "0x8086"}, {Product: "1111", Vendor: "0000"}}),
table.Entry("2 supported SR-IOV Interfaces",
[]*models.Interface{{Product: "0x158b", Vendor: "0x8086"}, {Product: "0x1015", Vendor: "0x15b3"}}),
table.Entry("3 identical supported SR-IOV Interfaces",
[]*models.Interface{{Product: "0x158b", Vendor: "0x8086"}, {Product: "0x158b", Vendor: "0x8086"}, {Product: "0x158b", Vendor: "0x8086"}}),
table.Entry("2 unsupported SR-IOV Interfaces only",
[]*models.Interface{{Product: "2222", Vendor: "0000"}, {Product: "1111", Vendor: "0000"}}),
)
It("should be returned for worker with supported GPU and SR-IOV interface", func() {
host := models.Host{
Role: models.HostRoleWorker,
Inventory: getInventoryWith(
[]*models.Gpu{{DeviceID: "1db6", VendorID: "10de"}},
[]*models.Interface{{Product: "0x158b", Vendor: "0x8086"}},
),
}
requirements, err := operator.GetHostRequirements(context.TODO(), &cluster, &host)
Expect(err).ToNot(HaveOccurred())
Expect(requirements).ToNot(BeNil())
Expect(requirements).To(BeEquivalentTo(newRequirements(cnv.WorkerCPU, cnv.WorkerMemory+2*1024)))
})
It("should fail for worker with malformed inventory JSON", func() {
host := models.Host{
Role: models.HostRoleWorker,
Inventory: "garbage...garbage...trash",
}
_, err := operator.GetHostRequirements(context.TODO(), &cluster, &host)
Expect(err).To(HaveOccurred())
})
It("should return reqs for SNO", func() {
host := models.Host{Role: models.HostRoleMaster}
haMode := models.ClusterHighAvailabilityModeNone
cluster = common.Cluster{
Cluster: models.Cluster{HighAvailabilityMode: &haMode, OpenshiftVersion: lvm.LvmsMinOpenshiftVersion},
}
requirements, err := operator.GetHostRequirements(context.TODO(), &cluster, &host)
Expect(err).ToNot(HaveOccurred())
Expect(requirements).ToNot(BeNil())
Expect(requirements).To(BeEquivalentTo(newRequirements(cnv.WorkerCPU+cnv.MasterCPU, cnv.WorkerMemory+cnv.MasterMemory)))
})
})
Context("ValidateHost", func() {
cfg := cnv.Config{
SupportedGPUs: map[string]bool{
"10de:1db6": true,
"10de:1eb8": true,
},
SupportedSRIOVNetworkIC: map[string]bool{
"8086:158b": true,
"15b3:1015": true,
},
SNOPoolSizeRequestHPPGib: 50,
SNOInstallHPP: true,
}
cnvOperator := cnv.NewCNVOperator(log, cfg, nil)
fullHaMode := models.ClusterHighAvailabilityModeFull
noneHaMode := models.ClusterHighAvailabilityModeNone
masterWithLessDiskSizeAndVirt := &models.Host{Role: models.HostRoleMaster, InstallationDiskID: "disk1",
Inventory: getInventoryWithCpuFlagsAndDisks([]string{"vmx"}, []*models.Disk{
{SizeBytes: 20 * conversions.GiB, DriveType: models.DriveTypeHDD, ID: "disk1"},
{SizeBytes: 40 * conversions.GiB, DriveType: models.DriveTypeSSD, ID: "disk2"},
{SizeBytes: 20 * conversions.GiB, DriveType: models.DriveTypeSSD, ID: "disk3"},
})}
masterWithOneSatisfyingDiskAndVirt := &models.Host{Role: models.HostRoleMaster, InstallationDiskID: "disk1",
Inventory: getInventoryWithCpuFlagsAndDisks([]string{"vmx"}, []*models.Disk{
{SizeBytes: 20 * conversions.GiB, DriveType: models.DriveTypeHDD, ID: "disk1"},
{SizeBytes: 60 * conversions.GiB, DriveType: models.DriveTypeSSD, ID: "disk2"},
{SizeBytes: 20 * conversions.GiB, DriveType: models.DriveTypeSSD, ID: "disk3"},
})}
masterWithoutVirt := &models.Host{Role: models.HostRoleMaster, InstallationDiskID: "disk1",
Inventory: getInventoryWithCpuFlagsAndDisks([]string{}, []*models.Disk{
{SizeBytes: 20 * conversions.GiB, DriveType: models.DriveTypeHDD, ID: "disk1"},
{SizeBytes: 40 * conversions.GiB, DriveType: models.DriveTypeSSD, ID: "disk2"},
{SizeBytes: 20 * conversions.GiB, DriveType: models.DriveTypeSSD, ID: "disk3"},
})}
table.DescribeTable("validateHost when ", func(cluster *common.Cluster, host *models.Host, expectedResult api.ValidationResult) {
res, _ := cnvOperator.ValidateHost(context.TODO(), cluster, host)
Expect(res).Should(Equal(expectedResult))
},
table.Entry("No virt capabilities",
&common.Cluster{Cluster: models.Cluster{OpenshiftVersion: "4.10", Hosts: []*models.Host{masterWithoutVirt}}},
masterWithoutVirt,
api.ValidationResult{Status: api.Failure, ValidationId: cnvOperator.GetHostValidationID(), Reasons: []string{"CPU does not have virtualization support"}},
),
table.Entry("SNO and there is no disk with bigger size than threshold for HPP",
&common.Cluster{Cluster: models.Cluster{OpenshiftVersion: "4.10", HighAvailabilityMode: &noneHaMode, Hosts: []*models.Host{masterWithLessDiskSizeAndVirt}}},
masterWithLessDiskSizeAndVirt,
api.ValidationResult{Status: api.Failure, ValidationId: cnvOperator.GetHostValidationID(), Reasons: []string{"OpenShift Virtualization on SNO requires an additional disk with 53 GB (50 Gi) in order to provide persistent storage for VMs, using hostpath-provisioner"}},
),
table.Entry("SNO and there is a disk with bigger size than threshold for HPP",
&common.Cluster{Cluster: models.Cluster{OpenshiftVersion: "4.10", HighAvailabilityMode: &noneHaMode, Hosts: []*models.Host{masterWithOneSatisfyingDiskAndVirt}}},
masterWithOneSatisfyingDiskAndVirt,
api.ValidationResult{Status: api.Success, ValidationId: cnvOperator.GetHostValidationID(), Reasons: nil},
),
table.Entry("Non SNO and there is no disk with bigger size than threshold for HPP shouldn't bother us",
&common.Cluster{Cluster: models.Cluster{OpenshiftVersion: "4.10", HighAvailabilityMode: &fullHaMode, Hosts: []*models.Host{masterWithLessDiskSizeAndVirt}}},
masterWithLessDiskSizeAndVirt,
api.ValidationResult{Status: api.Success, ValidationId: cnvOperator.GetHostValidationID(), Reasons: nil},
),
)
})
Context("preflight hardware requirements", func() {
fullHaMode := models.ClusterHighAvailabilityModeFull
noneHaMode := models.ClusterHighAvailabilityModeNone
table.DescribeTable("should be returned", func(cfg cnv.Config, cluster common.Cluster) {
cnvOperator := cnv.NewCNVOperator(log, cfg, nil)
requirements, err := cnvOperator.GetPreflightRequirements(context.TODO(), &cluster)
Expect(err).ToNot(HaveOccurred())
Expect(requirements.Dependencies).To(ConsistOf(lso.Operator.Name))
Expect(requirements.OperatorName).To(BeEquivalentTo(cnv.Operator.Name))
numQualitative := 3
workerRequirements := newRequirements(cnv.WorkerCPU, cnv.WorkerMemory)
masterRequirements := newRequirements(cnv.MasterCPU, cnv.MasterMemory)
if common.IsSingleNodeCluster(&cluster) {
// CNV+SNO installs HPP storage; additional discoverable disk req
if cfg.SNOInstallHPP {
numQualitative += 1
}
masterRequirements = newRequirements(cnv.MasterCPU+cnv.WorkerCPU, cnv.MasterMemory+cnv.WorkerMemory)
}
Expect(requirements.Requirements.Worker.Qualitative).To(HaveLen(numQualitative))
Expect(requirements.Requirements.Worker.Quantitative).To(BeEquivalentTo(workerRequirements))
Expect(requirements.Requirements.Master.Qualitative).To(HaveLen(numQualitative))
Expect(requirements.Requirements.Master.Quantitative).To(BeEquivalentTo(masterRequirements))
Expect(requirements.Requirements.Master.Qualitative).To(BeEquivalentTo(requirements.Requirements.Worker.Qualitative))
},
table.Entry("for non-SNO", cnv.Config{SNOPoolSizeRequestHPPGib: 50}, common.Cluster{Cluster: models.Cluster{
OpenshiftVersion: "4.10",
HighAvailabilityMode: &fullHaMode,
}}),
table.Entry("for SNO", cnv.Config{SNOPoolSizeRequestHPPGib: 50, SNOInstallHPP: true}, common.Cluster{Cluster: models.Cluster{
OpenshiftVersion: "4.10",
HighAvailabilityMode: &noneHaMode,
}}),
table.Entry("for SNO and opt out of HPP via env var", cnv.Config{SNOPoolSizeRequestHPPGib: 50, SNOInstallHPP: false}, common.Cluster{Cluster: models.Cluster{
OpenshiftVersion: "4.10",
HighAvailabilityMode: &noneHaMode,
}}),
)
})
Context("cluster requirements", func() {
It("only x86_64 is supported for CNV operator", func() {
cluster := common.Cluster{}
cluster.CPUArchitecture = common.DefaultCPUArchitecture
validation, err := operator.ValidateCluster(context.TODO(), &cluster)
Expect(err).ToNot(HaveOccurred())
Expect(validation.Status).To(Equal(api.Success))
cluster.CPUArchitecture = "arm64"
validation, err = operator.ValidateCluster(context.TODO(), &cluster)
Expect(err).ToNot(HaveOccurred())
Expect(validation.Status).To(Equal(api.Failure))
Expect(validation.Reasons).To(ContainElements(
"OpenShift Virtualization is supported only for x86_64 CPU architecture."))
})
It("multi-arch is supported for CNV operator", func() {
cluster := common.Cluster{}
cluster.CPUArchitecture = common.MultiCPUArchitecture
validation, err := operator.ValidateCluster(context.TODO(), &cluster)
Expect(err).ToNot(HaveOccurred())
Expect(validation.Status).To(Equal(api.Success))
})
})
})
func getInventoryWithCpuFlagsAndDisks(flags []string, disks []*models.Disk) string {
inventory := models.Inventory{
Interfaces: []*models.Interface{
{
Name: "eth0",
IPV4Addresses: []string{
"1.2.3.4/24",
},
IPV6Addresses: []string{
"1001:db8::10/120",
},
},
},
CPU: &models.CPU{
Count: 12,
Flags: flags,
},
Memory: &models.Memory{
UsableBytes: 32 * conversions.GiB,
},
Disks: disks,
}
return marshal(inventory)
}
func getInventoryWithGPUs(gpus []*models.Gpu) string {
inventory := models.Inventory{Gpus: gpus}
return marshal(inventory)
}
func getInventoryWithInterfaces(interfaces []*models.Interface) string {
inventory := models.Inventory{Interfaces: interfaces}
return marshal(inventory)
}
func getInventoryWith(gpus []*models.Gpu, interfaces []*models.Interface) string {
inventory := models.Inventory{Gpus: gpus, Interfaces: interfaces}
return marshal(inventory)
}
func marshal(inventory models.Inventory) string {
inventoryJSON, err := common.MarshalInventory(&inventory)
Expect(err).ToNot(HaveOccurred())
return inventoryJSON
}
func newRequirements(cpuCores int64, ramMib int64) *models.ClusterHostRequirementsDetails {
return &models.ClusterHostRequirementsDetails{CPUCores: cpuCores, RAMMib: ramMib}
}