-
Notifications
You must be signed in to change notification settings - Fork 232
/
Copy pathoperator_test.go
144 lines (111 loc) · 4.41 KB
/
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
package osc
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/models"
"github.com/openshift/assisted-service/pkg/conversions"
"github.com/sirupsen/logrus"
)
var _ = Describe("OSC Operator", func() {
const (
minCpu = 1
minRamMib = 1024
)
var (
log = logrus.New()
operator api.Operator
)
Context("operator", func() {
BeforeEach(func() {
operator = NewOscOperator(log)
})
It("should return the right validations ids", func() {
Expect(operator.GetClusterValidationID()).To(Equal(string(models.ClusterValidationIDOscRequirementsSatisfied)))
Expect(operator.GetHostValidationID()).To(Equal(string(models.HostValidationIDOscRequirementsSatisfied)))
})
It("should return the right feature support id", func() {
Expect(operator.GetFeatureSupportID()).To(Equal(models.FeatureSupportLevelIDOSC))
})
})
Context("host requirements", func() {
BeforeEach(func() {
operator = NewOscOperator(log)
})
var cluster common.Cluster
BeforeEach(func() {
cluster = common.Cluster{
Cluster: models.Cluster{ControlPlaneCount: common.MinMasterHostsNeededForInstallationInHaMode},
}
})
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))
},
Entry("min requirements", models.HostRoleMaster, newRequirements(minCpu, minRamMib)),
Entry("min requirements", models.HostRoleWorker, newRequirements(minCpu, minRamMib)),
)
})
Context("Validate host", func() {
BeforeEach(func() {
operator = NewOscOperator(log)
})
var cluster common.Cluster
BeforeEach(func() {
cluster = common.Cluster{
Cluster: models.Cluster{ControlPlaneCount: common.MinMasterHostsNeededForInstallationInHaMode},
}
})
It("master host should be valid", func() {
host := models.Host{Role: models.HostRoleMaster, Inventory: getInventory(int64(1024))}
result, err := operator.ValidateHost(context.TODO(), &cluster, &host, nil)
Expect(err).To(BeNil())
Expect(result.Status).To(Equal(api.Success))
})
It("worker host should be valid", func() {
host := models.Host{Role: models.HostRoleWorker, Inventory: getInventory(int64(1024))}
result, err := operator.ValidateHost(context.TODO(), &cluster, &host, nil)
Expect(err).To(BeNil())
Expect(result.Status).To(Equal(api.Success))
})
It("master host should be fail - not enough memory", func() {
host := models.Host{Role: models.HostRoleMaster, Inventory: getInventory(int64(300))}
result, err := operator.ValidateHost(context.TODO(), &cluster, &host, nil)
Expect(err).To(BeNil())
Expect(result.Status).To(Equal(api.Failure))
})
It("worker host should be fail - not enough memory", func() {
host := models.Host{Role: models.HostRoleWorker, Inventory: getInventory(int64(300))}
result, err := operator.ValidateHost(context.TODO(), &cluster, &host, nil)
Expect(err).To(BeNil())
Expect(result.Status).To(Equal(api.Failure))
})
It("master host should be fail - no inventory", func() {
host := models.Host{Role: models.HostRoleMaster}
result, err := operator.ValidateHost(context.TODO(), &cluster, &host, nil)
Expect(err).To(BeNil())
Expect(result.Status).To(Equal(api.Pending))
})
It("worker host should be fail - no inventory", func() {
host := models.Host{Role: models.HostRoleWorker}
result, err := operator.ValidateHost(context.TODO(), &cluster, &host, nil)
Expect(err).To(BeNil())
Expect(result.Status).To(Equal(api.Pending))
})
})
})
func newRequirements(cpuCores int64, ramMib int64) *models.ClusterHostRequirementsDetails {
return &models.ClusterHostRequirementsDetails{CPUCores: cpuCores, RAMMib: ramMib}
}
func getInventory(memMiB int64) string {
inventory := models.Inventory{CPU: &models.CPU{Architecture: "x86_64", Count: 1}, Memory: &models.Memory{UsableBytes: conversions.MibToBytes(memMiB)}}
inventoryJSON, err := common.MarshalInventory(&inventory)
Expect(err).ToNot(HaveOccurred())
return inventoryJSON
}