Skip to content

Commit e5955fd

Browse files
authored
Fixup acceptance tests (#96)
1 parent c7f0776 commit e5955fd

11 files changed

+72
-52
lines changed

.github/workflows/testacc.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ jobs:
6565
6666
echo "CLOUDSTACK_API_KEY=$CLOUDSTACK_API_KEY" >> $GITHUB_ENV
6767
echo "CLOUDSTACK_SECRET_KEY=$CLOUDSTACK_SECRET_KEY" >> $GITHUB_ENV
68+
echo "CLOUDSTACK_TEMPLATE_URL=http://dl.openvm.eu/cloudstack/macchinina/x86_64/macchinina-xen.vhd.bz2" >> $GITHUB_ENV
6869
- name: Install CMK
6970
run: |
7071
curl -sfL https://github.com/apache/cloudstack-cloudmonkey/releases/download/6.3.0/cmk.linux.x86-64 -o /usr/local/bin/cmk
@@ -81,6 +82,7 @@ jobs:
8182
ports:
8283
- 8080:5050
8384
strategy:
85+
fail-fast: false
8486
matrix:
8587
cloudstack_version:
8688
- 4.17.2.0

cloudstack/data_source_cloudstack_instance_test.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,9 +50,8 @@ const testAccInstanceDataSourceConfig_basic = `
5050
resource "cloudstack_instance" "my_instance" {
5151
name = "server-a"
5252
service_offering = "Small Instance"
53-
network_id = "b9c953a0-8686-4240-b8a4-43849f7079ff"
54-
template = "CentOS 5.5(64-bit) no GUI (KVM)"
55-
zone = "DC"
53+
template = "CentOS 5.6 (64-bit) no GUI (Simulator)"
54+
zone = "Sandbox-simulator"
5655
}
5756
data "cloudstack_instance" "my_instance_test" {
5857
filter {

cloudstack/data_source_cloudstack_ipaddress_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,13 +46,13 @@ func TestAccIPAddressDataSource_basic(t *testing.T) {
4646

4747
const testIPAddressDataSourceConfig_basic = `
4848
resource "cloudstack_ipaddress" "ipaddress-resource" {
49-
zone = "DC"
49+
zone = "Sandbox-simulator"
5050
}
5151
5252
data "cloudstack_ipaddress" "ipaddress-data-source"{
5353
filter{
5454
name = "zone_name"
55-
value= "DC"
55+
value= "Sandbox-simulator"
5656
}
5757
depends_on = [
5858
cloudstack_ipaddress.ipaddress-resource

cloudstack/data_source_cloudstack_service_offering_test.go

Lines changed: 13 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ import (
2727

2828
func TestAccServiceOfferingDataSource_basic(t *testing.T) {
2929
resourceName := "cloudstack_service_offering.service-offering-resource"
30-
datasourceName := "cloudstack_service_offering.service-offering-data-source"
30+
datasourceName := "data.cloudstack_service_offering.service-offering-data-source"
3131

3232
resource.Test(t, resource.TestCase{
3333
PreCheck: func() { testAccPreCheck(t) },
@@ -45,18 +45,16 @@ func TestAccServiceOfferingDataSource_basic(t *testing.T) {
4545
}
4646

4747
const testServiceOfferingDataSourceConfig_basic = `
48-
resource "cloudstack_service_offering" "service-offering-resource"{
49-
name = "TestServiceUpdate"
50-
display_text = "DisplayService"
51-
}
48+
resource "cloudstack_service_offering" "service-offering-resource" {
49+
name = "TestServiceUpdate"
50+
display_text = "DisplayService"
51+
}
5252
53-
data "cloudstack_service_offering" "service-offering-data-source"{
54-
filter{
55-
name = "name"
56-
value="TestServiceUpdate"
57-
}
58-
depends_on = [
59-
cloudstack_service_offering.service-resource
60-
]
61-
}
62-
`
53+
data "cloudstack_service_offering" "service-offering-data-source" {
54+
filter {
55+
name = "name"
56+
value = "TestServiceUpdate"
57+
}
58+
depends_on = [cloudstack_service_offering.service-offering-resource]
59+
}
60+
`

cloudstack/data_source_cloudstack_volume_test.go

Lines changed: 23 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -45,19 +45,30 @@ func TestAccVolumeDataSource_basic(t *testing.T) {
4545
}
4646

4747
const testVolumeDataSourceConfig_basic = `
48+
resource "cloudstack_disk_offering" "disk-offering" {
49+
name = "TestDiskOffering"
50+
display_text = "TestDiskOffering"
51+
disk_size = 1
52+
}
53+
54+
data "cloudstack_zone" "zone-data-source" {
55+
filter {
56+
name = "name"
57+
value = "Sandbox-simulator"
58+
}
59+
}
60+
4861
resource "cloudstack_volume" "volume-resource"{
49-
name = "TestVolume"
50-
disk_offering_id = "0038adec-5e3e-47df-b4b4-77b5dc8e3338"
51-
zone_id = "9a7002b2-09a2-44dc-a332-f2e4e7f01539"
62+
name = "TestVolume"
63+
disk_offering_id = "${cloudstack_disk_offering.disk-offering.id}"
64+
zone_id = "${data.cloudstack_zone.zone-data-source.id}"
5265
}
5366
54-
data "cloudstack_volume" "volume-data-source"{
55-
filter{
56-
name = "name"
57-
value="TestVolume"
67+
data "cloudstack_volume" "volume-data-source"{
68+
filter {
69+
name = "name"
70+
value = "TestVolume"
5871
}
59-
depends_on = [
60-
cloudstack_volume.volume-resource
61-
]
62-
}
63-
`
72+
depends_on = [cloudstack_volume.volume-resource]
73+
}
74+
`

cloudstack/data_source_cloudstack_vpc_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ resource "cloudstack_vpc" "vpc-resource" {
4949
name = "test-vpc"
5050
cidr = "10.0.0.0/16"
5151
vpc_offering = "Default VPC Offering"
52-
zone = "DC"
52+
zone = "Sandbox-simulator"
5353
}
5454
5555
data "cloudstack_vpc" "vpc-data-source"{

cloudstack/resource_cloudstack_instance_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,7 @@ func TestAccCloudStackInstance_import(t *testing.T) {
185185
ResourceName: "cloudstack_instance.foobar",
186186
ImportState: true,
187187
ImportStateVerify: true,
188-
ImportStateVerifyIgnore: []string{"expunge", "user_data"},
188+
ImportStateVerifyIgnore: []string{"expunge", "user_data", "uefi"},
189189
},
190190
},
191191
})
@@ -206,7 +206,7 @@ func TestAccCloudStackInstance_importProject(t *testing.T) {
206206
ImportState: true,
207207
ImportStateIdPrefix: "terraform/",
208208
ImportStateVerify: true,
209-
ImportStateVerifyIgnore: []string{"expunge", "user_data"},
209+
ImportStateVerifyIgnore: []string{"expunge", "user_data", "uefi"},
210210
},
211211
},
212212
})

cloudstack/resource_cloudstack_private_gateway.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ func resourceCloudStackPrivateGatewayRead(d *schema.ResourceData, meta interface
148148
d.Set("gateway", gw.Gateway)
149149
d.Set("ip_address", gw.Ipaddress)
150150
d.Set("netmask", gw.Netmask)
151-
d.Set("vlan", gw.Vlan)
151+
d.Set("vlan", strings.Replace(gw.Vlan, "vlan://", "", -1))
152152
d.Set("acl_id", gw.Aclid)
153153
d.Set("vpc_id", gw.Vpcid)
154154

cloudstack/resource_cloudstack_private_gateway_test.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,7 @@ resource "cloudstack_vpc" "foo" {
148148
resource "cloudstack_network_acl" "foo" {
149149
name = "terraform-acl"
150150
vpc_id = "${cloudstack_vpc.foo.id}"
151+
depends_on = ["cloudstack_vpc.foo"]
151152
}
152153
153154
resource "cloudstack_private_gateway" "foo" {
@@ -157,4 +158,5 @@ resource "cloudstack_private_gateway" "foo" {
157158
vlan = "1"
158159
vpc_id = "${cloudstack_vpc.foo.id}"
159160
acl_id = "${cloudstack_network_acl.foo.id}"
161+
depends_on = ["cloudstack_vpc.foo","cloudstack_network_acl.foo"]
160162
}`

cloudstack/resource_cloudstack_template.go

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -243,22 +243,30 @@ func resourceCloudStackTemplateRead(d *schema.ResourceData, meta interface{}) er
243243
p := cs.Template.NewListTemplatesParams("executable")
244244
p.SetId(d.Id())
245245
p.SetShowunique(true)
246-
p.SetProjectid(d.Get("project").(string))
246+
project := d.Get("project").(string)
247+
if project != "" {
248+
if !cloudstack.IsID(project) {
249+
id, _, err := cs.Project.GetProjectID(project)
250+
if err != nil {
251+
return err
252+
}
253+
project = id
254+
}
255+
p.SetProjectid(project)
256+
}
247257

248258
r, err := cs.Template.ListTemplates(p)
249-
count := r.Count
250-
t := r.Templates[0]
251259
if err != nil {
252-
if count == 0 {
253-
log.Printf(
254-
"[DEBUG] Template %s no longer exists", d.Get("name").(string))
255-
d.SetId("")
256-
return nil
257-
}
258-
259260
return err
261+
} else if r.Count == 0 {
262+
log.Printf(
263+
"[DEBUG] Template %s no longer exists", d.Get("name").(string))
264+
d.SetId("")
265+
return nil
260266
}
261267

268+
t := r.Templates[0]
269+
262270
d.Set("name", t.Name)
263271
d.Set("display_text", t.Displaytext)
264272
d.Set("format", t.Format)

0 commit comments

Comments
 (0)