This repository has been archived by the owner on Apr 9, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 24
/
Copy pathvirtual_guest_lifecycle_test.go
247 lines (191 loc) · 10.7 KB
/
virtual_guest_lifecycle_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
package virtual_guest_lifecycle_test
import (
"fmt"
"time"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
datatypes "github.com/maximilien/softlayer-go/data_types"
"github.com/maximilien/softlayer-go/softlayer"
testhelpers "github.com/maximilien/softlayer-go/test_helpers"
)
var _ = Describe("SoftLayer Virtual Guest Lifecycle", func() {
var (
err error
accountService softlayer.SoftLayer_Account_Service
virtualGuestService softlayer.SoftLayer_Virtual_Guest_Service
)
BeforeEach(func() {
accountService, err = testhelpers.CreateAccountService()
Expect(err).ToNot(HaveOccurred())
virtualGuestService, err = testhelpers.CreateVirtualGuestService()
Expect(err).ToNot(HaveOccurred())
testhelpers.TIMEOUT = 35 * time.Minute
testhelpers.POLLING_INTERVAL = 10 * time.Second
})
Context("SoftLayer_Account#<getSshKeys, getVirtualGuests>", func() {
It("returns an array of SoftLayer_Virtual_Guest objects", func() {
virtualGuests, err := accountService.GetVirtualGuests()
Expect(err).ToNot(HaveOccurred())
Expect(len(virtualGuests)).To(BeNumerically(">=", 0))
})
It("returns an array of SoftLayer_Security_Ssh_Keys objects", func() {
sshKeys, err := accountService.GetSshKeys()
Expect(err).ToNot(HaveOccurred())
Expect(len(sshKeys)).To(BeNumerically(">=", 0))
})
})
Context("SoftLayer_SecuritySshKey#CreateObject and SoftLayer_SecuritySshKey#DeleteObject", func() {
It("creates the ssh key and verify it is present and then deletes it", func() {
createdSshKey, _ := testhelpers.CreateTestSshKey()
testhelpers.WaitForCreatedSshKeyToBePresent(createdSshKey.Id)
sshKeyService, err := testhelpers.CreateSecuritySshKeyService()
Expect(err).ToNot(HaveOccurred())
deleted, err := sshKeyService.DeleteObject(createdSshKey.Id)
Expect(err).ToNot(HaveOccurred())
Expect(deleted).To(BeTrue())
testhelpers.WaitForDeletedSshKeyToNoLongerBePresent(createdSshKey.Id)
})
})
Context("SoftLayer_VirtualGuest#CreateObject, SoftLayer_VirtualGuest#GetVirtualGuestPrimaryIpAddress, and SoftLayer_VirtualGuest#DeleteObject", func() {
It("creates the virtual guest instance and waits for it to be active, get it's IP address, and then delete it", func() {
virtualGuest := testhelpers.CreateVirtualGuestAndMarkItTest([]datatypes.SoftLayer_Security_Ssh_Key{})
defer testhelpers.CleanUpVirtualGuest(virtualGuest.Id)
testhelpers.WaitForVirtualGuestToBeRunning(virtualGuest.Id)
testhelpers.WaitForVirtualGuestToHaveNoActiveTransactions(virtualGuest.Id)
ipAddress := testhelpers.GetVirtualGuestPrimaryIpAddress(virtualGuest.Id)
Expect(ipAddress).ToNot(Equal(""))
})
It("creates the virtual guest instance and waits for it to be active, get it's network VLANS, and then delete it", func() {
virtualGuest := testhelpers.CreateVirtualGuestAndMarkItTest([]datatypes.SoftLayer_Security_Ssh_Key{})
defer testhelpers.CleanUpVirtualGuest(virtualGuest.Id)
testhelpers.WaitForVirtualGuestToBeRunning(virtualGuest.Id)
networkVlans, err := virtualGuestService.GetNetworkVlans(virtualGuest.Id)
Expect(err).ToNot(HaveOccurred())
Expect(len(networkVlans)).To(BeNumerically(">", 0))
})
It("creates the virtual guest and waits for it to be active and checks that the host could create a 1MB disk", func() {
virtualGuest := testhelpers.CreateVirtualGuestAndMarkItTest([]datatypes.SoftLayer_Security_Ssh_Key{})
defer testhelpers.CleanUpVirtualGuest(virtualGuest.Id)
testhelpers.WaitForVirtualGuestToBeRunning(virtualGuest.Id)
testhelpers.WaitForVirtualGuestToHaveNoActiveTransactions(virtualGuest.Id)
virtualGuestService, err := testhelpers.CreateVirtualGuestService()
Expect(err).ToNot(HaveOccurred())
available, err := virtualGuestService.CheckHostDiskAvailability(virtualGuest.Id, 1)
Expect(err).ToNot(HaveOccurred())
Expect(available).To(BeTrue())
})
It("creates the virtual guest and waits for it to be active and checks if the disk type is local", func() {
virtualGuest := testhelpers.CreateVirtualGuestAndMarkItTest([]datatypes.SoftLayer_Security_Ssh_Key{})
defer testhelpers.CleanUpVirtualGuest(virtualGuest.Id)
testhelpers.WaitForVirtualGuestToBeRunning(virtualGuest.Id)
testhelpers.WaitForVirtualGuestToHaveNoActiveTransactions(virtualGuest.Id)
virtualGuestService, err := testhelpers.CreateVirtualGuestService()
Expect(err).ToNot(HaveOccurred())
disktype, err := virtualGuestService.GetLocalDiskFlag(virtualGuest.Id)
Expect(err).ToNot(HaveOccurred())
Expect(disktype).To(BeTrue())
})
})
Context("SoftLayer_VirtualGuest#CreateObject, SoftLayer_VirtualGuest#rebootSoft, wait for reboot to complete, and SoftLayer_VirtualGuest#DeleteObject", func() {
It("creates the virtual guest instance, wait for active, SOFT reboots it, wait for RUNNING, then delete it", func() {
virtualGuest := testhelpers.CreateVirtualGuestAndMarkItTest([]datatypes.SoftLayer_Security_Ssh_Key{})
defer testhelpers.CleanUpVirtualGuest(virtualGuest.Id)
testhelpers.WaitForVirtualGuestToBeRunning(virtualGuest.Id)
testhelpers.WaitForVirtualGuestToHaveNoActiveTransactions(virtualGuest.Id)
virtualGuestService, err := testhelpers.CreateVirtualGuestService()
Expect(err).ToNot(HaveOccurred())
fmt.Printf("----> will attempt to SOFT reboot virtual guest `%d`\n", virtualGuest.Id)
rebooted, err := virtualGuestService.RebootSoft(virtualGuest.Id)
Expect(err).ToNot(HaveOccurred())
Expect(rebooted).To(BeTrue())
fmt.Printf("----> successfully SOFT rebooted virtual guest `%d`\n", virtualGuest.Id)
testhelpers.WaitForVirtualGuestToBeRunning(virtualGuest.Id)
})
})
Context("SoftLayer_VirtualGuest#CreateObject, SoftLayer_VirtualGuest#rebootHard, wait for reboot to complete, and SoftLayer_VirtualGuest#DeleteObject", func() {
It("creates the virtual guest instance, wait for active, HARD reboots it, wait for RUNNING, then delete it", func() {
virtualGuest := testhelpers.CreateVirtualGuestAndMarkItTest([]datatypes.SoftLayer_Security_Ssh_Key{})
defer testhelpers.CleanUpVirtualGuest(virtualGuest.Id)
testhelpers.WaitForVirtualGuestToBeRunning(virtualGuest.Id)
testhelpers.WaitForVirtualGuestToHaveNoActiveTransactions(virtualGuest.Id)
virtualGuestService, err := testhelpers.CreateVirtualGuestService()
Expect(err).ToNot(HaveOccurred())
fmt.Printf("----> will attempt to HARD reboot virtual guest `%d`\n", virtualGuest.Id)
rebooted, err := virtualGuestService.RebootHard(virtualGuest.Id)
Expect(err).ToNot(HaveOccurred())
Expect(rebooted).To(BeTrue())
fmt.Printf("----> successfully HARD rebooted virtual guest `%d`\n", virtualGuest.Id)
testhelpers.WaitForVirtualGuestToBeRunning(virtualGuest.Id)
})
})
Context("SoftLayer_SecuritySshKey#CreateObject and SoftLayer_VirtualGuest#CreateObject", func() {
It("creates key, creates virtual guest and adds key to list of VG", func() {
createdSshKey, _ := testhelpers.CreateTestSshKey()
testhelpers.WaitForCreatedSshKeyToBePresent(createdSshKey.Id)
defer testhelpers.DeleteSshKey(createdSshKey.Id)
virtualGuest := testhelpers.CreateVirtualGuestAndMarkItTest([]datatypes.SoftLayer_Security_Ssh_Key{createdSshKey})
defer testhelpers.WaitForVirtualGuestToHaveNoActiveTransactionsOrToErr(virtualGuest.Id)
defer testhelpers.CleanUpVirtualGuest(virtualGuest.Id)
testhelpers.WaitForVirtualGuestToBeRunning(virtualGuest.Id)
})
})
Context("SoftLayer_VirtualGuest#CreateObject, SoftLayer_VirtualGuest#setTags, and SoftLayer_VirtualGuest#DeleteObject", func() {
It("creates the virtual guest instance, wait for active, wait for RUNNING, set some tags, verify that tags are added, then delete it", func() {
virtualGuest := testhelpers.CreateVirtualGuestAndMarkItTest([]datatypes.SoftLayer_Security_Ssh_Key{})
defer testhelpers.CleanUpVirtualGuest(virtualGuest.Id)
testhelpers.WaitForVirtualGuestToBeRunning(virtualGuest.Id)
testhelpers.WaitForVirtualGuestToHaveNoActiveTransactions(virtualGuest.Id)
virtualGuestService, err := testhelpers.CreateVirtualGuestService()
Expect(err).ToNot(HaveOccurred())
fmt.Printf("----> will attempt to set tags to the virtual guest `%d`\n", virtualGuest.Id)
tags := []string{"tag0", "tag1", "tag2"}
tagsWasSet, err := virtualGuestService.SetTags(virtualGuest.Id, tags)
Expect(err).ToNot(HaveOccurred())
Expect(tagsWasSet).To(BeTrue())
fmt.Printf("----> verifying that tags were set the tags virtual guest `%d`\n", virtualGuest.Id)
tagReferences, err := virtualGuestService.GetTagReferences(virtualGuest.Id)
Expect(err).ToNot(HaveOccurred())
Expect(len(tagReferences)).To(Equal(3))
fmt.Printf("----> verify that each tag was set to virtual guest: `%d`\n", virtualGuest.Id)
found := false
for _, tag := range tags {
for _, tagReference := range tagReferences {
if tag == tagReference.Tag.Name {
found = true
break
}
}
Expect(found).To(BeTrue())
found = false
}
fmt.Printf("----> successfully set the tags and verified tags were set in virtual guest `%d`\n", virtualGuest.Id)
})
})
Context("SoftLayer_VirtualGuest#CreateObject, SoftLayer_VirtualGuest#UpgradeObject and SoftLayer_VirtualGuest#DeleteObject", func() {
It("creates the virtual guest instance, waits for active, waits for RUNNING, upgrades cpu, ram and network speed, waits for upgrade to complete, verify that upgrade worked, then delete it", func() {
virtualGuest := testhelpers.CreateVirtualGuestAndMarkItTest([]datatypes.SoftLayer_Security_Ssh_Key{})
defer testhelpers.CleanUpVirtualGuest(virtualGuest.Id)
testhelpers.WaitForVirtualGuestToBeRunning(virtualGuest.Id)
testhelpers.WaitForVirtualGuestToHaveNoActiveTransactions(virtualGuest.Id)
virtualGuestService, err := testhelpers.CreateVirtualGuestService()
Expect(err).ToNot(HaveOccurred())
fmt.Printf("----> will attempt to upgrade virtual guest `%d`: [CPUs --> 2; RAM --> 2Gb; Network speed --> 1000]\n", virtualGuest.Id)
_, err = virtualGuestService.UpgradeObject(virtualGuest.Id, &softlayer.UpgradeOptions{
Cpus: 2,
MemoryInGB: 2,
NicSpeed: 1000,
})
Expect(err).ToNot(HaveOccurred())
fmt.Printf("----> verifying that upgrade successfully completed for virtual guest `%d`\n", virtualGuest.Id)
testhelpers.WaitForVirtualGuestTransactionWithStatus(virtualGuest.Id, "UPGRADE")
testhelpers.WaitForVirtualGuestToHaveNoActiveTransactions(virtualGuest.Id)
fmt.Printf("----> verify that cpu, ram and memory of virtual guest `%d` are upgraded\n", virtualGuest.Id)
upgradedVirtualGuest, err := virtualGuestService.GetObject(virtualGuest.Id)
Expect(err).ToNot(HaveOccurred())
Expect(upgradedVirtualGuest.MaxMemory).To(Equal(2048))
Expect(upgradedVirtualGuest.NetworkComponents[0].MaxSpeed).To(Equal(1000))
Expect(upgradedVirtualGuest.StartCpus).To(Equal(2))
fmt.Printf("----> successfully upgraded virtual guest `%d`\n", virtualGuest.Id)
})
})
})