Skip to content

Commit 38feed7

Browse files
committed
Improve integration testcase and mock method
1 parent bbdf589 commit 38feed7

14 files changed

+109
-124
lines changed

CHANGELOG.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@ All releases of the BOSH CPI for Alibaba Cloud will be documented in this file.
66

77
IMPROVEMENTS
88

9-
- Upgrade SDK and support HTTP PROXY ([#63](https://github.com/cloudfoundry-incubator/bosh-alicloud-cpi-release/pull/63))
9+
- Improve integration testcase and mock method ([#67](https://github.com/cloudfoundry-incubator/bosh-alicloud-cpi-release/pull/67))
10+
- Upgrade SDK and support HTTP PROXY ([#66](https://github.com/cloudfoundry-incubator/bosh-alicloud-cpi-release/pull/66))
1011

1112
## [r21]
1213

src/bosh-alicloud-cpi/integration/alicloud_test.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,16 @@ package integration
66
import (
77
. "github.com/onsi/ginkgo"
88
. "github.com/onsi/gomega"
9+
"github.com/aliyun/alibaba-cloud-sdk-go/services/ecs"
910
)
1011

1112
var _ = Describe("integration:alicloud", func() {
1213
It("get regions and zones", func() {
13-
client := caller.Config.NewEcsClient()
14-
regions, err := client.DescribeRegions()
14+
client, _ := caller.Config.NewEcsClient("")
15+
resp, err := client.DescribeRegions(ecs.CreateDescribeRegionsRequest())
1516
Expect(err).NotTo(HaveOccurred())
1617

17-
for _, r := range regions {
18+
for _, r := range resp.Regions.Region {
1819
// region := common.Region(r.RegionId)
1920
// zones, err := client.DescribeZones(region)
2021
// Expect(err).NotTo(HaveOccurred())

src/bosh-alicloud-cpi/integration/assertions.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ package integration
1818
// Expect(err).ToNot(HaveOccurred())
1919
// print(response.Error.Message)
2020
// Expect(response.Error).To(BeNil())
21-
//
2221
// Expect(response.Result).ToNot(BeNil())
2322
// return response.Result
24-
//}
23+
//}

src/bosh-alicloud-cpi/integration/config.go

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,13 @@ var (
1919
accessKeyId = os.Getenv("CPI_ACCESS_KEY_ID")
2020
accessKeySecret = os.Getenv("CPI_ACCESS_KEY_SECRET")
2121

22-
//
23-
// for <light-bosh-stemcell-1008-alicloud-kvm-ubuntu-trusty-go_agent> in beijing
24-
stemcellId = envOrDefault("CPI_STEMCELL_ID", "m-2ze2ct08gslmli5e6fw5")
22+
// Configurable defaults
23+
// A stemcell that will be created in integration_suite_test.go
24+
existingStemcell string
25+
stemcellFile = envOrDefault("CPI_STEMCELL_FILE", "")
26+
stemcellVersion = envOrDefault("CPI_STEMCELL_VERSION", "")
27+
imageOssBucket = envOrDefault("CPI_STEMCELL_OSS_BUCKET", "")
28+
imageOssObject = envOrDefault("CPI_STEMCELL_OSS_OBJECT", "")
2529

2630
securityGroupId = os.Getenv("CPI_SECURITY_GROUP_ID")
2731
vswitchId = os.Getenv("CPI_VSWITCH_ID")
@@ -45,6 +49,9 @@ var (
4549
registryPassword = envOrDefault("CPI_REGISTRY_PASSWORD", "admin-password")
4650
registryHost = envOrDefault("CPI_REGISTRY_ADDRESS", "172.0.0.1")
4751
registryPort = envOrDefault("CPI_REGISTRY_PORT", "25777")
52+
53+
// Channel that will be used to retrieve IPs to use
54+
ips chan string
4855
)
4956

5057
func ApplySystemEnv(config *alicloud.Config) error {

src/bosh-alicloud-cpi/integration/disk_test.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import (
99

1010
. "github.com/onsi/ginkgo"
1111
. "github.com/onsi/gomega"
12+
"fmt"
1213
)
1314

1415
var _ = Describe("integration:disk", func() {
@@ -24,7 +25,7 @@ var _ = Describe("integration:disk", func() {
2425
"size": "40_960",
2526
"category": "cloud_efficiency"
2627
},
27-
"instance_name": "test-cc",
28+
"instance_name": "bosh-test-cpi-integration",
2829
"instance_type": "ecs.n4.small",
2930
"system_disk": {
3031
"size": "61_440",
@@ -56,7 +57,7 @@ var _ = Describe("integration:disk", func() {
5657
"context": {
5758
"director_uuid": "911133bb-7d44-4811-bf8a-b215608bf084"
5859
}
59-
}`).P("STEMCELL_ID", stemcellId).
60+
}`).P("STEMCELL_ID", existingStemcell).
6061
P("SECURITY_GROUP_ID", securityGroupId).
6162
P("VSWITCH_ID", vswitchId).
6263
P("INTERNAL_IP", internalIp).

src/bosh-alicloud-cpi/integration/integration_suite_test.go

Lines changed: 39 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ var configForIntegration = string(`{
3030
"properties": {
3131
"alicloud": {
3232
"region": "${CPI_REGION}",
33-
"availability_zone": "${CPI_ZONE}",
33+
"availability_zone": "${CPI_ZONE}",
3434
"access_key_id": "${CPI_ACCESS_KEY_ID}",
3535
"access_key_secret": "${CPI_ACCESS_KEY_SECRET}"
3636
},
@@ -79,6 +79,44 @@ var _ = BeforeSuite(func() {
7979

8080
err = CleanInstances(config, services.Instances)
8181
Expect(err).NotTo(HaveOccurred())
82+
83+
data := mock.NewBuilder(`{
84+
"method": "create_stemcell",
85+
"arguments": [
86+
"${STEMCELL_FILE}",
87+
{
88+
"architecture": "x86_64",
89+
"container_format": "bare",
90+
"disk": 3072,
91+
"disk_format": "raw",
92+
"hypervisor": "kvm",
93+
"infrastructure": "alicloud",
94+
"name": "bosh-alicloud-kvm-ubuntu-xenial-go_agent",
95+
"os_type": "linux",
96+
"os_distro": "ubuntu",
97+
"root_device_name": "/dev/vda1",
98+
"version": "${STEMCELL_VERSION}"
99+
}
100+
],
101+
"context": {
102+
"director_uuid": "073eac6e-7a35-4a49-8c42-68988ea16ca7"
103+
}
104+
}`).P("STEMCELL_FILE", stemcellFile).
105+
P("STEMCELL_VERSION", stemcellVersion).
106+
ToBytes()
107+
108+
r := caller.Run(data)
109+
Expect(r.GetError()).NotTo(HaveOccurred())
110+
existingStemcell = r.GetResultString()
111+
Expect(existingStemcell).ToNot(BeEmpty())
112+
})
113+
114+
var _ = AfterSuite(func() {
115+
_, err := caller.Call("delete_stemcell", existingStemcell)
116+
Expect(err).NotTo(HaveOccurred())
117+
//Expect(response.Error).To(BeNil())
118+
//Expect(response.Result).To(BeNil())
119+
82120
})
83121

84122
func CleanInstances(config alicloud.Config, manager alicloud.InstanceManager) error {

src/bosh-alicloud-cpi/integration/stemcell_test.go

Lines changed: 18 additions & 79 deletions
Original file line numberDiff line numberDiff line change
@@ -11,101 +11,40 @@ import (
1111
)
1212

1313
var _ = Describe("integration:stemcell", func() {
14-
It("can upload a stemcell(light)", func() {
14+
var stemcellCID string
15+
It("executes the stemcell lifecycle with an oss bucket", func() {
1516
bytes := mock.NewBuilder(`{
1617
"method": "create_stemcell",
1718
"arguments": [
18-
"/var/vcap/data/tmp/director/stemcell20170926-9684-17ncxdz/image",
19+
"",
1920
{
2021
"architecture": "x86_64",
21-
"container_format": "",
22-
"disk": "50",
23-
"disk_format": "rawdisk",
22+
"container_format": "bare",
23+
"disk": 3072,
24+
"disk_format": "raw",
2425
"hypervisor": "kvm",
25-
"image_id": {
26-
"cn-beijing": "${STEMCELL_ID}",
27-
"cn-qingdao": "m-m5e1bdeo0a0ujw2s0ovv",
28-
"cn-zhangjiakou": "m-8vbdd1mi6hwlddicqt2x"
29-
},
3026
"infrastructure": "alicloud",
31-
"name": "bosh-alicloud-kvm-hubuntu-trusty-go_agent",
32-
"os_distro": "ubuntu",
33-
"os_type": "linux",
34-
"root_device_name": "/dev/vda1",
35-
"source_url": "",
36-
"version": 1003
37-
}
38-
],
39-
"context": {
40-
"director_uuid": "073eac6e-7a35-4a49-8c42-68988ea16ca7"
41-
}
42-
}`).P("STEMCELL_ID", stemcellId).ToBytes()
43-
44-
r := caller.Run(bytes)
45-
Expect(r.GetError()).NotTo(HaveOccurred())
46-
Expect(r.GetResultString()).Should(Equal(stemcellId))
47-
})
48-
49-
It("can create a stemcell from oss", func() {
50-
bytes := mock.NewBuilder(`{
51-
"method": "create_stemcell",
52-
"arguments": [
53-
"/var/vcap/data/tmp/director/stemcell20170926-9684-17ncxdz/image",
54-
{
55-
"architecture": "x86_64",
56-
"container_format": "",
57-
"disk": 40960,
58-
"disk_format": "RAW",
59-
"hypervisor": "kvm",
60-
"infrastructure": "alicloud",
61-
"name": "bosh-alicloud-kvm-ubuntu-trusty-go_agent",
62-
"oss_bucket": "bosh-stemcell",
63-
"oss_object": "alicloud-kvm-ubuntu.raw",
27+
"name": "bosh-alicloud-kvm-ubuntu-xenial-go_agent",
6428
"os_type": "linux",
29+
"os_distro": "ubuntu",
6530
"root_device_name": "/dev/vda1",
66-
"version": 1003
31+
"version": "${STEMCELL_VERSION}",
32+
"oss_bucket": "${OSS_BUCKET}",
33+
"oss_object": "${OSS_OBJECT}"
6734
}
68-
],
69-
"context": {
70-
"director_uuid": "073eac6e-7a35-4a49-8c42-68988ea16ca7"
71-
}
72-
}`).P("STEMCELL_ID", stemcellId).ToBytes()
35+
]
36+
}`).P("STEMCELL_VERSION", stemcellVersion).
37+
P("OSS_BUCKET", imageOssBucket).
38+
P("OSS_OBJECT", imageOssObject).
39+
ToBytes()
7340

7441
r := caller.Run(bytes)
7542
Expect(r.GetError()).NotTo(HaveOccurred())
43+
stemcellCID = r.GetResultString()
7644
})
7745

78-
// this case can run pass, but on CI cant not fetch tarball, so annotate it temporary
79-
//FIt("can create a stemcell from tarball", func() {
80-
// bytes := mock.NewBuilder(`{
81-
// "method": "create_stemcell",
82-
// "arguments": [
83-
// "/.bosh/bosh-stemcell-1008-alicloud-kvm-ubuntu-trusty-go_agent.tgz",
84-
// {
85-
// "architecture": "x86_64",
86-
// "container_format": "",
87-
// "disk": 40960,
88-
// "disk_format": "RAW",
89-
// "hypervisor": "kvm",
90-
// "infrastructure": "alicloud",
91-
// "name": "bosh-alicloud-kvm-ubuntu",
92-
// "os_type": "linux",
93-
// "os_distro": "Ubuntu",
94-
// "root_device_name": "/dev/vda1",
95-
// "version": "1008"
96-
// }
97-
// ],
98-
// "context": {
99-
// "director_uuid": "073eac6e-7a35-4a49-8c42-68988ea16ca7"
100-
// }
101-
// }`).P("STEMCELL_ID", stemcellId).ToBytes()
102-
//
103-
// r := caller.Run(bytes)
104-
// Expect(r.GetError()).NotTo(HaveOccurred())
105-
//})
106-
10746
It("can delete a stemcell(light)", func() {
108-
_, err := caller.Call("delete_stemcell", stemcellId)
47+
_, err := caller.Call("delete_stemcell", stemcellCID)
10948
Expect(err).NotTo(HaveOccurred())
11049
})
11150
})

src/bosh-alicloud-cpi/integration/vm_test.go

Lines changed: 10 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ var _ = Describe("integration:vm", func() {
2323
"size": "40_960",
2424
"category": "cloud_efficiency"
2525
},
26-
"instance_name": "test-cc",
26+
"instance_name": "bosh-test-cpi-integration",
2727
"instance_type": "ecs.n4.small",
2828
"system_disk": {
2929
"size": "61_440",
@@ -55,7 +55,7 @@ var _ = Describe("integration:vm", func() {
5555
"director_uuid": "911133bb-7d44-4811-bf8a-b215608bf084"
5656
}
5757
}`).
58-
P("STEMCELL_ID", stemcellId).
58+
P("STEMCELL_ID", existingStemcell).
5959
P("SECURITY_GROUP_ID", securityGroupId).
6060
P("VSWITCH_ID", vswitchId).
6161
P("INTERNAL_IP", internalIp).
@@ -81,9 +81,6 @@ var _ = Describe("integration:vm", func() {
8181
})
8282

8383
It("can run the vm lifecycle with slb", func() {
84-
if slbId == "" {
85-
Skip("no CPI_SLB_IP settings")
86-
}
8784
By("create vm with slb")
8885
in := mock.NewBuilder(`{
8986
"method": "create_vm",
@@ -95,7 +92,7 @@ var _ = Describe("integration:vm", func() {
9592
"size": "40_960",
9693
"category": "cloud_efficiency"
9794
},
98-
"instance_name": "test-cc",
95+
"instance_name": "bosh-test-cpi-integration",
9996
"instance_type": "ecs.n4.small",
10097
"slbs": ["${SLB_ID}"],
10198
"system_disk": {
@@ -128,7 +125,7 @@ var _ = Describe("integration:vm", func() {
128125
"context": {
129126
"director_uuid": "911133bb-7d44-4811-bf8a-b215608bf084"
130127
}
131-
}`).P("STEMCELL_ID", stemcellId).
128+
}`).P("STEMCELL_ID", existingStemcell).
132129
P("SECURITY_GROUP_ID", securityGroupId).
133130
P("VSWITCH_ID", vswitchId).
134131
P("INTERNAL_IP", internalIp).
@@ -155,9 +152,6 @@ var _ = Describe("integration:vm", func() {
155152
})
156153

157154
It("can run the vm lifecycle with external ip", func() {
158-
if externalIp == "" {
159-
Skip("no CPI_EXTERNAL_IP settings")
160-
}
161155
By("create vm with external ip")
162156
in := mock.NewBuilder(`{
163157
"method": "create_vm",
@@ -169,7 +163,7 @@ var _ = Describe("integration:vm", func() {
169163
"size": "40_960",
170164
"category": "cloud_efficiency"
171165
},
172-
"instance_name": "test-cc",
166+
"instance_name": "bosh-test-cpi-integration",
173167
"instance_type": "ecs.n4.small",
174168
"system_disk": {
175169
"size": "61_440",
@@ -207,7 +201,7 @@ var _ = Describe("integration:vm", func() {
207201
"director_uuid": "911133bb-7d44-4811-bf8a-b215608bf084"
208202
}
209203
}`).
210-
P("STEMCELL_ID", stemcellId).
204+
P("STEMCELL_ID", existingStemcell).
211205
P("SECURITY_GROUP_ID", securityGroupId).
212206
P("VSWITCH_ID", vswitchId).
213207
P("INTERNAL_IP", internalIp).
@@ -267,7 +261,7 @@ var _ = Describe("integration:vm", func() {
267261
"size": "40_960",
268262
"category": "cloud_efficiency"
269263
},
270-
"instance_name": "test-cc",
264+
"instance_name": "bosh-test-cpi-integration",
271265
"instance_type": "ecs.n4.small",
272266
"spot_strategy": "${SPOT_STRATEGY}",
273267
"spot_price_limit": ${SPOT_PRICE_LIMIT},
@@ -301,7 +295,7 @@ var _ = Describe("integration:vm", func() {
301295
"director_uuid": "911133bb-7d44-4811-bf8a-b215608bf084"
302296
}
303297
}`).
304-
P("STEMCELL_ID", stemcellId).
298+
P("STEMCELL_ID", existingStemcell).
305299
P("SECURITY_GROUP_ID", securityGroupId).
306300
P("VSWITCH_ID", vswitchId).
307301
P("INTERNAL_IP", internalIp).
@@ -339,7 +333,7 @@ var _ = Describe("integration:vm", func() {
339333
"size": "40_960",
340334
"category": "cloud_efficiency"
341335
},
342-
"instance_name": "test-cc",
336+
"instance_name": "bosh-test-cpi-integration",
343337
"instance_type": "ecs.n4.small",
344338
"password": "Cloud12345",
345339
"ram_role_name": "${RAM_ROLE_NAME}",
@@ -373,7 +367,7 @@ var _ = Describe("integration:vm", func() {
373367
"director_uuid": "911133bb-7d44-4811-bf8a-b215608bf084"
374368
}
375369
}`).
376-
P("STEMCELL_ID", stemcellId).
370+
P("STEMCELL_ID", existingStemcell).
377371
P("SECURITY_GROUP_ID", securityGroupId).
378372
P("VSWITCH_ID", vswitchId).
379373
P("INTERNAL_IP", internalIp).

0 commit comments

Comments
 (0)