/
cluster.go
264 lines (209 loc) · 7.21 KB
/
cluster.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
/*
Copyright 2017 Portworx
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package sanity
import (
"context"
"time"
"github.com/libopenstorage/openstorage/api"
"github.com/libopenstorage/openstorage/api/client"
clusterclient "github.com/libopenstorage/openstorage/api/client/cluster"
volumeclient "github.com/libopenstorage/openstorage/api/client/volume"
"github.com/libopenstorage/openstorage/cluster"
"github.com/libopenstorage/openstorage/volume"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
)
var _ = Describe("Cluster [Cluster Tests]", func() {
var (
restClient *client.Client
manager cluster.Cluster
)
BeforeEach(func() {
var err error
restClient, err = clusterclient.NewClusterClient(osdAddress, cluster.APIVersion)
Expect(err).ToNot(HaveOccurred())
manager = clusterclient.ClusterManager(restClient)
})
AfterEach(func() {
})
Describe("Cluster Status", func() {
It("should have OK status for the cluster", func() {
By("Enumerating the nodes")
cluster, err := manager.Enumerate()
Expect(err).NotTo(HaveOccurred())
By("checking status the cluster")
Expect(cluster.Id).NotTo(BeEmpty())
Expect(cluster.NodeId).NotTo(BeEmpty())
Expect(cluster.Nodes).NotTo(BeEmpty())
Expect(cluster.Status).To(Equal(api.Status_STATUS_OK))
})
It("should have OK status for all nodes", func() {
By("Enumerating the nodes")
cluster, err := manager.Enumerate()
Expect(err).NotTo(HaveOccurred())
By("checking status for each node")
for _, n := range cluster.Nodes {
Expect(n.Id).NotTo(BeEmpty())
Expect(n.Hostname).NotTo(BeEmpty())
Expect(n.Status).To(Equal(api.Status_STATUS_OK))
Expect(n.Cpu).To(BeNumerically(">", 0))
Expect(n.MemTotal).To(BeNumerically(">", 0))
Expect(n.MemUsed).To(BeNumerically(">", 0))
Expect(n.MemFree).To(BeNumerically(">", 0))
}
})
})
Describe("Cluster Inspect", func() {
It("should have ok inspecting each node", func() {
By("Enumerating the nodes")
cluster, err := manager.Enumerate()
Expect(err).NotTo(HaveOccurred())
By("checking inspecting node")
for _, n := range cluster.Nodes {
node, err := manager.Inspect(n.Id)
Expect(err).NotTo(HaveOccurred())
Expect(node.Id).To(Equal(n.Id))
Expect(node.Status).To(Equal(n.Status))
Expect(node.MgmtIp).To(Equal(n.MgmtIp))
Expect(node.DataIp).To(Equal(n.DataIp))
Expect(node.Hostname).To(Equal(n.Hostname))
}
})
})
Describe("Node Status", func() {
It("Should have an ok status for the node", func() {
By("Checking the status of the node")
nodeStatus, err := manager.NodeStatus()
Expect(err).NotTo(HaveOccurred())
Expect(nodeStatus).To(BeEquivalentTo(api.Status_STATUS_OK))
})
})
Describe("Gossip State", func() {
It("Should get Gossip state", func() {
By("Querying for gossip state")
gossipState := manager.GetGossipState()
Expect(len(gossipState.NodeStatus)).ToNot(BeZero())
Expect(gossipState).NotTo(BeNil())
})
})
Describe("Enumerate Alerts", func() {
var (
err error
volumeID string
numVolumesBefore int
volumedriver volume.VolumeDriver
restClient *client.Client
)
BeforeEach(func() {
restClient, err = volumeclient.NewDriverClient(osdAddress, volumeDriver, volume.APIVersion, "")
Expect(err).ToNot(HaveOccurred())
volumedriver = volumeclient.VolumeDriver(restClient)
volumes, err := volumedriver.Enumerate(&api.VolumeLocator{}, nil)
numVolumesBefore = len(volumes)
Expect(err).NotTo(HaveOccurred())
})
It("Should Enumerate Alerts for volume created / deleted", func() {
By("Creating the volume first")
var size = 3
vr := &api.VolumeCreateRequest{
Locator: &api.VolumeLocator{
Name: "volume-to-enumerate-alerts",
VolumeLabels: map[string]string{
"class": "enumerate-alerts-class",
},
},
Source: &api.Source{},
Spec: &api.VolumeSpec{
Size: uint64(size * GIGABYTE),
HaLevel: 1,
BlockSize: 256,
Format: api.FSType_FS_TYPE_EXT4,
},
}
volumeID, err = volumedriver.Create(context.TODO(), vr.GetLocator(), vr.GetSource(), vr.GetSpec())
Expect(err).NotTo(HaveOccurred())
By("Checking if no of volumes present in cluster increases by 1")
testIfVolumeCreatedSuccessfully(volumedriver, volumeID, numVolumesBefore, vr)
By("Deleting the created volume")
err = volumedriver.Delete(context.TODO(), volumeID)
Expect(err).NotTo(HaveOccurred())
endTime := time.Now()
// 30 seconds before
startTime := endTime.Add(-30 * time.Second)
alerts, err := manager.EnumerateAlerts(startTime, endTime, api.ResourceType_RESOURCE_TYPE_VOLUME)
Expect(err).NotTo(HaveOccurred())
noOfOccurence := 0
for _, alert := range alerts.Alert {
if alert.ResourceId == volumeID {
noOfOccurence++
}
}
// No of occurence should be 2 [one for create and one for delete]
Expect(noOfOccurence).To(BeEquivalentTo(2))
})
It("Should enumerate alerts for all resource types ", func() {
By("Enumeraing alerts")
endTime := time.Now()
startTime := endTime.Add(-5 * time.Hour)
for _, v := range api.ResourceType_value {
alerts, err := manager.EnumerateAlerts(startTime, endTime, api.ResourceType(v))
Expect(err).NotTo(HaveOccurred())
Expect(alerts).NotTo(BeNil())
}
})
})
Describe("Clear and Erase Alerts", func() {
var (
startTime time.Time
endTime time.Time
)
It("Should clear and erase alerts", func() {
By("Taking a random alertID from volume resource type")
endTime = time.Now()
startTime = endTime.Add(-5 * time.Hour)
alerts, err := manager.EnumerateAlerts(startTime, endTime, api.ResourceType_RESOURCE_TYPE_NODE)
Expect(err).NotTo(HaveOccurred())
Expect(alerts.Alert).NotTo(BeEmpty())
randomVolumeAlertID := alerts.Alert[random(0, len(alerts.Alert))].Id
By("Erasing alerts")
err = manager.EraseAlert(api.ResourceType_RESOURCE_TYPE_NODE, randomVolumeAlertID)
Expect(err).NotTo(HaveOccurred())
By("Enumerating the alerts again and checking if the alert cleared")
alerts, err = manager.EnumerateAlerts(startTime, endTime, api.ResourceType_RESOURCE_TYPE_NODE)
Expect(err).NotTo(HaveOccurred())
Expect(alerts).NotTo(BeNil())
noOfOccurence := 0
for _, alert := range alerts.Alert {
if alert.Id == randomVolumeAlertID {
noOfOccurence++
}
}
// Alert should not present
Expect(noOfOccurence).To(BeEquivalentTo(0))
})
})
Describe("Cluster Enable Gossip", func() {
It("Should Enable Gossip ", func() {
By("enabling updates")
err := manager.EnableUpdates()
Expect(err).NotTo(HaveOccurred())
})
})
Describe("Cluster Disable Gossip", func() {
It("Should Enable Gossip ", func() {
By("disabling updates")
err := manager.DisableUpdates()
Expect(err).NotTo(HaveOccurred())
})
})
})