-
Notifications
You must be signed in to change notification settings - Fork 232
/
Copy pathmce_operator_test.go
107 lines (99 loc) · 4.71 KB
/
mce_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
package mce
import (
"context"
"fmt"
. "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/models"
"github.com/openshift/assisted-service/pkg/conversions"
)
var _ = Describe("MCE Operator", func() {
var (
ctx = context.TODO()
operator = NewMceOperator(common.GetTestLog())
hostWithNoInventory = &models.Host{}
hostWithInsufficientResources = &models.Host{
Inventory: Inventory(&InventoryResources{
Cpus: 12,
Ram: 8 * conversions.GiB,
}),
}
hostWithSufficientResources = &models.Host{
Inventory: Inventory(&InventoryResources{
Cpus: 12,
Ram: 32 * conversions.GiB,
}),
}
)
Context("GetHostRequirements", func() {
table.DescribeTable("get host requirements when ", func(cluster *common.Cluster, host *models.Host, expectedResult *models.ClusterHostRequirementsDetails) {
res, _ := operator.GetHostRequirements(ctx, cluster, host)
Expect(res).Should(Equal(expectedResult))
},
table.Entry("on a multinode cluster",
&common.Cluster{Cluster: models.Cluster{ControlPlaneCount: common.MinMasterHostsNeededForInstallationInHaMode, OpenshiftVersion: "4.13.0", Hosts: []*models.Host{hostWithSufficientResources}}},
hostWithSufficientResources,
&models.ClusterHostRequirementsDetails{CPUCores: MinimumCPU, RAMMib: conversions.GibToMib(MinimumMemory)},
),
table.Entry("on an SNO cluster",
&common.Cluster{Cluster: models.Cluster{ControlPlaneCount: 1, OpenshiftVersion: "4.13.0", Hosts: []*models.Host{hostWithSufficientResources}}},
hostWithSufficientResources,
&models.ClusterHostRequirementsDetails{CPUCores: SNOMinimumCpu, RAMMib: conversions.GibToMib(SNOMinimumMemory)},
),
)
})
Context("ValidateHost", func() {
table.DescribeTable("validate host when ", func(cluster *common.Cluster, host *models.Host, expectedResult api.ValidationResult) {
res, _ := operator.ValidateHost(ctx, cluster, host, nil)
Expect(res).Should(Equal(expectedResult))
},
table.Entry("host with no inventory",
&common.Cluster{Cluster: models.Cluster{Hosts: []*models.Host{hostWithNoInventory}}},
hostWithNoInventory,
api.ValidationResult{Status: api.Pending, ValidationId: operator.GetHostValidationID(), Reasons: []string{"Missing Inventory in the host"}},
),
table.Entry("host with insufficient memory",
&common.Cluster{Cluster: models.Cluster{Hosts: []*models.Host{hostWithInsufficientResources}}},
hostWithInsufficientResources,
api.ValidationResult{Status: api.Failure, ValidationId: operator.GetHostValidationID(), Reasons: []string{"Insufficient memory to deploy multicluster engine. Required memory is 16384 MiB but found 8192 MiB"}},
),
table.Entry("master with sufficient resources",
&common.Cluster{Cluster: models.Cluster{Hosts: []*models.Host{hostWithSufficientResources}}},
hostWithSufficientResources,
api.ValidationResult{Status: api.Success, ValidationId: operator.GetHostValidationID()},
),
)
})
Context("ValidateCluster", func() {
table.DescribeTable("validate cluster when ", func(cluster *common.Cluster, expectedResult api.ValidationResult) {
res, _ := operator.ValidateCluster(ctx, cluster)
Expect(res).Should(Equal(expectedResult))
},
table.Entry("Openshift version less than minimal",
&common.Cluster{Cluster: models.Cluster{Hosts: []*models.Host{hostWithSufficientResources}, OpenshiftVersion: "4.9.0"}},
api.ValidationResult{Status: api.Failure, ValidationId: operator.GetHostValidationID(), Reasons: []string{fmt.Sprintf("multicluster engine is only supported for openshift versions %s and above", MceMinOpenshiftVersion)}},
),
table.Entry("Openshift version more than minimal",
&common.Cluster{Cluster: models.Cluster{Hosts: []*models.Host{hostWithSufficientResources}, OpenshiftVersion: MceMinOpenshiftVersion}},
api.ValidationResult{Status: api.Success, ValidationId: operator.GetHostValidationID()},
),
)
})
})
var _ = Describe("GetMinDiskSizeGB", func() {
It("should return the sum of all required PVCs when cluster is SNO", func() {
cluster := &models.Cluster{ControlPlaneCount: 1}
minDiskSize := GetMinDiskSizeGB(cluster)
expectedMinDiskSize := int64(70)
Expect(expectedMinDiskSize).To(Equal(minDiskSize))
})
It("should return the maximum value of any required PVCs when cluster is HA", func() {
cluster := &models.Cluster{ControlPlaneCount: common.MinMasterHostsNeededForInstallationInHaMode}
minDiskSize := GetMinDiskSizeGB(cluster)
expectedMinDiskSize := int64(50)
Expect(expectedMinDiskSize).To(Equal(minDiskSize))
})
})