Skip to content

Commit eee86d5

Browse files
committed
Make it easier to run the cloudstack acceptance tests
* Document what should go in the environment variables * Generate set hash for egress firewall based on selected public ip
1 parent 8eaee5e commit eee86d5

2 files changed

Lines changed: 86 additions & 25 deletions

File tree

builtin/providers/cloudstack/provider_test.go

Lines changed: 50 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -117,9 +117,6 @@ func testAccPreCheck(t *testing.T) {
117117
if v := os.Getenv("CLOUDSTACK_PUBLIC_IPADDRESS"); v == "" {
118118
t.Fatal("CLOUDSTACK_PUBLIC_IPADDRESS must be set for acceptance tests")
119119
}
120-
if v := os.Getenv("CLOUDSTACK_SSH_KEYPAIR"); v == "" {
121-
t.Fatal("CLOUDSTACK_SSH_KEYPAIR must be set for acceptance tests")
122-
}
123120
if v := os.Getenv("CLOUDSTACK_SSH_PUBLIC_KEY"); v == "" {
124121
t.Fatal("CLOUDSTACK_SSH_PUBLIC_KEY must be set for acceptance tests")
125122
}
@@ -146,30 +143,77 @@ func testAccPreCheck(t *testing.T) {
146143
}
147144
}
148145

149-
var CLOUDSTACK_2ND_NIC_IPADDRESS = os.Getenv("CLOUDSTACK_2ND_NIC_IPADDRESS")
150-
var CLOUDSTACK_2ND_NIC_NETWORK = os.Getenv("CLOUDSTACK_2ND_NIC_NETWORK")
146+
// Name of a valid disk offering
151147
var CLOUDSTACK_DISK_OFFERING_1 = os.Getenv("CLOUDSTACK_DISK_OFFERING_1")
148+
149+
// Name of a disk offering that CLOUDSTACK_DISK_OFFERING_1 can resize to
152150
var CLOUDSTACK_DISK_OFFERING_2 = os.Getenv("CLOUDSTACK_DISK_OFFERING_2")
153-
var CLOUDSTACK_HYPERVISOR = os.Getenv("CLOUDSTACK_HYPERVISOR")
151+
152+
// Name of a valid service offering
154153
var CLOUDSTACK_SERVICE_OFFERING_1 = os.Getenv("CLOUDSTACK_SERVICE_OFFERING_1")
154+
155+
// Name of a service offering that CLOUDSTACK_SERVICE_OFFERING_1 can resize to
155156
var CLOUDSTACK_SERVICE_OFFERING_2 = os.Getenv("CLOUDSTACK_SERVICE_OFFERING_2")
157+
158+
// Name of a network that already exists
156159
var CLOUDSTACK_NETWORK_1 = os.Getenv("CLOUDSTACK_NETWORK_1")
160+
161+
// A valid IP address in CLOUDSTACK_NETWORK_1
157162
var CLOUDSTACK_NETWORK_1_IPADDRESS = os.Getenv("CLOUDSTACK_NETWORK_1_IPADDRESS")
163+
164+
// Name for a network that will be created
158165
var CLOUDSTACK_NETWORK_2 = os.Getenv("CLOUDSTACK_NETWORK_2")
166+
167+
// Any range
159168
var CLOUDSTACK_NETWORK_2_CIDR = os.Getenv("CLOUDSTACK_NETWORK_2_CIDR")
169+
170+
// Name of an available network offering with specifyvlan=false
160171
var CLOUDSTACK_NETWORK_2_OFFERING = os.Getenv("CLOUDSTACK_NETWORK_2_OFFERING")
172+
173+
// An IP address in CLOUDSTACK_NETWORK_2_CIDR
161174
var CLOUDSTACK_NETWORK_2_IPADDRESS = os.Getenv("CLOUDSTACK_NETWORK_2_IPADDRESS")
175+
176+
// A network that already exists and isnt CLOUDSTACK_NETWORK_1
177+
var CLOUDSTACK_2ND_NIC_NETWORK = os.Getenv("CLOUDSTACK_2ND_NIC_NETWORK")
178+
179+
// An IP address in CLOUDSTACK_2ND_NIC_NETWORK
180+
var CLOUDSTACK_2ND_NIC_IPADDRESS = os.Getenv("CLOUDSTACK_2ND_NIC_IPADDRESS")
181+
182+
// Any range
162183
var CLOUDSTACK_VPC_CIDR_1 = os.Getenv("CLOUDSTACK_VPC_CIDR_1")
184+
185+
// Any range that doesn't overlap to CLOUDSTACK_VPC_CIDR_1, will be VPNed
163186
var CLOUDSTACK_VPC_CIDR_2 = os.Getenv("CLOUDSTACK_VPC_CIDR_2")
187+
188+
// An available VPC offering
164189
var CLOUDSTACK_VPC_OFFERING = os.Getenv("CLOUDSTACK_VPC_OFFERING")
190+
191+
// A sub-range of CLOUDSTACK_VPC_CIDR_1 with same starting point
165192
var CLOUDSTACK_VPC_NETWORK_CIDR = os.Getenv("CLOUDSTACK_VPC_NETWORK_CIDR")
193+
194+
// Name of an available network offering with forvpc=true
166195
var CLOUDSTACK_VPC_NETWORK_OFFERING = os.Getenv("CLOUDSTACK_VPC_NETWORK_OFFERING")
196+
197+
// Path to a public IP that exists for CLOUDSTACK_NETWORK_1
167198
var CLOUDSTACK_PUBLIC_IPADDRESS = os.Getenv("CLOUDSTACK_PUBLIC_IPADDRESS")
199+
200+
// Path to a public key on local disk
168201
var CLOUDSTACK_SSH_PUBLIC_KEY = os.Getenv("CLOUDSTACK_SSH_PUBLIC_KEY")
202+
203+
// Name of a template that exists already for building VMs
169204
var CLOUDSTACK_TEMPLATE = os.Getenv("CLOUDSTACK_TEMPLATE")
205+
206+
// Details of a template that will be added
170207
var CLOUDSTACK_TEMPLATE_FORMAT = os.Getenv("CLOUDSTACK_TEMPLATE_FORMAT")
208+
var CLOUDSTACK_HYPERVISOR = os.Getenv("CLOUDSTACK_HYPERVISOR")
171209
var CLOUDSTACK_TEMPLATE_URL = os.Getenv("CLOUDSTACK_TEMPLATE_URL")
172210
var CLOUDSTACK_TEMPLATE_OS_TYPE = os.Getenv("CLOUDSTACK_TEMPLATE_OS_TYPE")
211+
212+
// Name of a project that exists already
173213
var CLOUDSTACK_PROJECT_NAME = os.Getenv("CLOUDSTACK_PROJECT_NAME")
214+
215+
// Name of a network that exists already in CLOUDSTACK_PROJECT_NAME
174216
var CLOUDSTACK_PROJECT_NETWORK = os.Getenv("CLOUDSTACK_PROJECT_NETWORK")
217+
218+
// Name of a zone that exists already
175219
var CLOUDSTACK_ZONE = os.Getenv("CLOUDSTACK_ZONE")

builtin/providers/cloudstack/resource_cloudstack_egress_firewall_test.go

Lines changed: 36 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,19 @@ package cloudstack
22

33
import (
44
"fmt"
5+
"strconv"
56
"strings"
67
"testing"
78

89
"github.com/hashicorp/terraform/helper/resource"
10+
"github.com/hashicorp/terraform/helper/schema"
911
"github.com/hashicorp/terraform/terraform"
1012
"github.com/xanzy/go-cloudstack/cloudstack"
1113
)
1214

1315
func TestAccCloudStackEgressFirewall_basic(t *testing.T) {
16+
hash := makeTestCloudStackEgressFirewallRuleHash([]interface{}{"1000-2000", "80"})
17+
1418
resource.Test(t, resource.TestCase{
1519
PreCheck: func() { testAccPreCheck(t) },
1620
Providers: testAccProviders,
@@ -24,23 +28,26 @@ func TestAccCloudStackEgressFirewall_basic(t *testing.T) {
2428
"cloudstack_egress_firewall.foo", "network", CLOUDSTACK_NETWORK_1),
2529
resource.TestCheckResourceAttr(
2630
"cloudstack_egress_firewall.foo",
27-
"rule.411689741.source_cidr",
31+
"rule."+hash+".source_cidr",
2832
CLOUDSTACK_NETWORK_1_IPADDRESS+"/32"),
2933
resource.TestCheckResourceAttr(
30-
"cloudstack_egress_firewall.foo", "rule.411689741.protocol", "tcp"),
34+
"cloudstack_egress_firewall.foo", "rule."+hash+".protocol", "tcp"),
3135
resource.TestCheckResourceAttr(
32-
"cloudstack_egress_firewall.foo", "rule.411689741.ports.#", "2"),
36+
"cloudstack_egress_firewall.foo", "rule."+hash+".ports.#", "2"),
3337
resource.TestCheckResourceAttr(
34-
"cloudstack_egress_firewall.foo", "rule.411689741.ports.1209010669", "1000-2000"),
38+
"cloudstack_egress_firewall.foo", "rule."+hash+".ports.1209010669", "1000-2000"),
3539
resource.TestCheckResourceAttr(
36-
"cloudstack_egress_firewall.foo", "rule.411689741.ports.1889509032", "80"),
40+
"cloudstack_egress_firewall.foo", "rule."+hash+".ports.1889509032", "80"),
3741
),
3842
},
3943
},
4044
})
4145
}
4246

4347
func TestAccCloudStackEgressFirewall_update(t *testing.T) {
48+
hash1 := makeTestCloudStackEgressFirewallRuleHash([]interface{}{"1000-2000", "80"})
49+
hash2 := makeTestCloudStackEgressFirewallRuleHash([]interface{}{"443"})
50+
4451
resource.Test(t, resource.TestCase{
4552
PreCheck: func() { testAccPreCheck(t) },
4653
Providers: testAccProviders,
@@ -56,16 +63,16 @@ func TestAccCloudStackEgressFirewall_update(t *testing.T) {
5663
"cloudstack_egress_firewall.foo", "rule.#", "1"),
5764
resource.TestCheckResourceAttr(
5865
"cloudstack_egress_firewall.foo",
59-
"rule.411689741.source_cidr",
66+
"rule."+hash1+".source_cidr",
6067
CLOUDSTACK_NETWORK_1_IPADDRESS+"/32"),
6168
resource.TestCheckResourceAttr(
62-
"cloudstack_egress_firewall.foo", "rule.411689741.protocol", "tcp"),
69+
"cloudstack_egress_firewall.foo", "rule."+hash1+".protocol", "tcp"),
6370
resource.TestCheckResourceAttr(
64-
"cloudstack_egress_firewall.foo", "rule.411689741.ports.#", "2"),
71+
"cloudstack_egress_firewall.foo", "rule."+hash1+".ports.#", "2"),
6572
resource.TestCheckResourceAttr(
66-
"cloudstack_egress_firewall.foo", "rule.411689741.ports.1209010669", "1000-2000"),
73+
"cloudstack_egress_firewall.foo", "rule."+hash1+".ports.1209010669", "1000-2000"),
6774
resource.TestCheckResourceAttr(
68-
"cloudstack_egress_firewall.foo", "rule.411689741.ports.1889509032", "80"),
75+
"cloudstack_egress_firewall.foo", "rule."+hash1+".ports.1889509032", "80"),
6976
),
7077
},
7178

@@ -79,26 +86,26 @@ func TestAccCloudStackEgressFirewall_update(t *testing.T) {
7986
"cloudstack_egress_firewall.foo", "rule.#", "2"),
8087
resource.TestCheckResourceAttr(
8188
"cloudstack_egress_firewall.foo",
82-
"rule.411689741.source_cidr",
89+
"rule."+hash1+".source_cidr",
8390
CLOUDSTACK_NETWORK_1_IPADDRESS+"/32"),
8491
resource.TestCheckResourceAttr(
85-
"cloudstack_egress_firewall.foo", "rule.411689741.protocol", "tcp"),
92+
"cloudstack_egress_firewall.foo", "rule."+hash1+".protocol", "tcp"),
8693
resource.TestCheckResourceAttr(
87-
"cloudstack_egress_firewall.foo", "rule.411689741.ports.#", "2"),
94+
"cloudstack_egress_firewall.foo", "rule."+hash1+".ports.#", "2"),
8895
resource.TestCheckResourceAttr(
89-
"cloudstack_egress_firewall.foo", "rule.411689741.ports.1209010669", "1000-2000"),
96+
"cloudstack_egress_firewall.foo", "rule."+hash1+".ports.1209010669", "1000-2000"),
9097
resource.TestCheckResourceAttr(
91-
"cloudstack_egress_firewall.foo", "rule.411689741.ports.1889509032", "80"),
98+
"cloudstack_egress_firewall.foo", "rule."+hash1+".ports.1889509032", "80"),
9299
resource.TestCheckResourceAttr(
93100
"cloudstack_egress_firewall.foo",
94-
"rule.845479598.source_cidr",
101+
"rule."+hash2+".source_cidr",
95102
CLOUDSTACK_NETWORK_1_IPADDRESS+"/32"),
96103
resource.TestCheckResourceAttr(
97-
"cloudstack_egress_firewall.foo", "rule.845479598.protocol", "tcp"),
104+
"cloudstack_egress_firewall.foo", "rule."+hash2+".protocol", "tcp"),
98105
resource.TestCheckResourceAttr(
99-
"cloudstack_egress_firewall.foo", "rule.845479598.ports.#", "1"),
106+
"cloudstack_egress_firewall.foo", "rule."+hash2+".ports.#", "1"),
100107
resource.TestCheckResourceAttr(
101-
"cloudstack_egress_firewall.foo", "rule.845479598.ports.3638101695", "443"),
108+
"cloudstack_egress_firewall.foo", "rule."+hash2+".ports.3638101695", "443"),
102109
),
103110
},
104111
},
@@ -164,6 +171,16 @@ func testAccCheckCloudStackEgressFirewallDestroy(s *terraform.State) error {
164171
return nil
165172
}
166173

174+
func makeTestCloudStackEgressFirewallRuleHash(ports []interface{}) string {
175+
return strconv.Itoa(resourceCloudStackEgressFirewallRuleHash(map[string]interface{}{
176+
"source_cidr": CLOUDSTACK_NETWORK_1_IPADDRESS + "/32",
177+
"protocol": "tcp",
178+
"ports": schema.NewSet(schema.HashString, ports),
179+
"icmp_type": 0,
180+
"icmp_code": 0,
181+
}))
182+
}
183+
167184
var testAccCloudStackEgressFirewall_basic = fmt.Sprintf(`
168185
resource "cloudstack_egress_firewall" "foo" {
169186
network = "%s"

0 commit comments

Comments
 (0)