Skip to content

Commit 07532fe

Browse files
committed
update test
1 parent f558a6f commit 07532fe

File tree

2 files changed

+24
-175
lines changed

2 files changed

+24
-175
lines changed

cloudstack/resource_cloudstack_nic.go

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -58,11 +58,6 @@ func resourceCloudStackNIC() *schema.Resource {
5858
Optional: true,
5959
Computed: true,
6060
},
61-
"dhcp_options": {
62-
Type: schema.TypeMap,
63-
Optional: true,
64-
ForceNew: true,
65-
},
6661
},
6762
}
6863
}
@@ -86,15 +81,6 @@ func resourceCloudStackNICCreate(d *schema.ResourceData, meta interface{}) error
8681
p.SetMacaddress(macaddress.(string))
8782
}
8883

89-
// If there are dhcp options supplied, add them to the parameter struct
90-
if dhcpOptions, ok := d.GetOk("dhcp_options"); ok {
91-
dhcpOpts := make(map[string]string)
92-
for k, v := range dhcpOptions.(map[string]interface{}) {
93-
dhcpOpts[k] = v.(string)
94-
}
95-
p.SetDhcpoptions(dhcpOpts)
96-
}
97-
9884
// Create and attach the new NIC
9985
r, err := Retry(10, retryableAddNicFunc(cs, p))
10086
if err != nil {

cloudstack/resource_cloudstack_nic_test.go

Lines changed: 24 additions & 161 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ func TestAccCloudStackNIC_basic(t *testing.T) {
4848
})
4949
}
5050

51-
func TestAccCloudStackNIC_ipaddress(t *testing.T) {
51+
func TestAccCloudStackNIC_update(t *testing.T) {
5252
var nic cloudstack.Nic
5353

5454
resource.Test(t, resource.TestCase{
@@ -57,66 +57,29 @@ func TestAccCloudStackNIC_ipaddress(t *testing.T) {
5757
CheckDestroy: testAccCheckCloudStackNICDestroy,
5858
Steps: []resource.TestStep{
5959
{
60-
Config: testAccCloudStackNIC_ipaddress,
60+
Config: testAccCloudStackNIC_basic,
6161
Check: resource.ComposeTestCheckFunc(
6262
testAccCheckCloudStackNICExists(
6363
"cloudstack_instance.foobar", "cloudstack_nic.foo", &nic),
64-
testAccCheckCloudStackNICIPAddress(&nic),
65-
resource.TestCheckResourceAttr(
66-
"cloudstack_nic.foo", "ip_address", "10.1.2.123"),
64+
testAccCheckCloudStackNICAttributes(&nic),
6765
),
6866
},
69-
},
70-
})
71-
}
72-
73-
func TestAccCloudStackNIC_macaddress(t *testing.T) {
74-
var nic cloudstack.Nic
7567

76-
resource.Test(t, resource.TestCase{
77-
PreCheck: func() { testAccPreCheck(t) },
78-
Providers: testAccProviders,
79-
CheckDestroy: testAccCheckCloudStackNICDestroy,
80-
Steps: []resource.TestStep{
8168
{
82-
Config: testAccCloudStackNIC_macaddress,
83-
Check: resource.ComposeTestCheckFunc(
84-
testAccCheckCloudStackNICExists(
85-
"cloudstack_instance.foobar", "cloudstack_nic.foo", &nic),
86-
testAccCheckCloudStackNICMacAddress(&nic),
87-
resource.TestCheckResourceAttr(
88-
"cloudstack_nic.foo", "mac_address", "02:1A:4B:3C:5D:6E"),
89-
),
90-
},
91-
},
92-
})
93-
}
94-
95-
func TestAccCloudStackNIC_dhcpoptions(t *testing.T) {
96-
var nic cloudstack.Nic
97-
98-
resource.Test(t, resource.TestCase{
99-
PreCheck: func() { testAccPreCheck(t) },
100-
Providers: testAccProviders,
101-
CheckDestroy: testAccCheckCloudStackNICDestroy,
102-
Steps: []resource.TestStep{
103-
{
104-
Config: testAccCloudStackNIC_dhcpoptions,
69+
Config: testAccCloudStackNIC_ipaddress,
10570
Check: resource.ComposeTestCheckFunc(
10671
testAccCheckCloudStackNICExists(
10772
"cloudstack_instance.foobar", "cloudstack_nic.foo", &nic),
108-
testAccCheckCloudStackNICAttributes(&nic),
109-
resource.TestCheckResourceAttr(
110-
"cloudstack_nic.foo", "dhcp_options.dhcp:15", "example.com"),
73+
testAccCheckCloudStackNICIPAddress(&nic),
11174
resource.TestCheckResourceAttr(
112-
"cloudstack_nic.foo", "dhcp_options.dhcp:6", "8.8.8.8,8.8.4.4"),
75+
"cloudstack_nic.foo", "ip_address", "10.1.2.123"),
11376
),
11477
},
11578
},
11679
})
11780
}
11881

119-
func TestAccCloudStackNIC_complete(t *testing.T) {
82+
func TestAccCloudStackNIC_macaddress(t *testing.T) {
12083
var nic cloudstack.Nic
12184

12285
resource.Test(t, resource.TestCase{
@@ -125,19 +88,13 @@ func TestAccCloudStackNIC_complete(t *testing.T) {
12588
CheckDestroy: testAccCheckCloudStackNICDestroy,
12689
Steps: []resource.TestStep{
12790
{
128-
Config: testAccCloudStackNIC_complete,
91+
Config: testAccCloudStackNIC_macaddress,
12992
Check: resource.ComposeTestCheckFunc(
13093
testAccCheckCloudStackNICExists(
13194
"cloudstack_instance.foobar", "cloudstack_nic.foo", &nic),
132-
testAccCheckCloudStackNICCompleteAttributes(&nic),
133-
resource.TestCheckResourceAttr(
134-
"cloudstack_nic.foo", "ip_address", "10.1.2.150"),
95+
testAccCheckCloudStackNICMacAddress(&nic),
13596
resource.TestCheckResourceAttr(
13697
"cloudstack_nic.foo", "mac_address", "02:1A:4B:3C:5D:6E"),
137-
resource.TestCheckResourceAttr(
138-
"cloudstack_nic.foo", "dhcp_options.dhcp:15", "test.com"),
139-
resource.TestCheckResourceAttr(
140-
"cloudstack_nic.foo", "dhcp_options.dhcp:6", "1.1.1.1,1.0.0.1"),
14198
),
14299
},
143100
},
@@ -187,7 +144,7 @@ func testAccCheckCloudStackNICAttributes(
187144
nic *cloudstack.Nic) resource.TestCheckFunc {
188145
return func(s *terraform.State) error {
189146

190-
if nic.Networkname != "terraform-network" {
147+
if nic.Networkname != "terraform-network-secondary" {
191148
return fmt.Errorf("Bad network name: %s", nic.Networkname)
192149
}
193150

@@ -199,7 +156,7 @@ func testAccCheckCloudStackNICIPAddress(
199156
nic *cloudstack.Nic) resource.TestCheckFunc {
200157
return func(s *terraform.State) error {
201158

202-
if nic.Networkname != "terraform-network" {
159+
if nic.Networkname != "terraform-network-secondary" {
203160
return fmt.Errorf("Bad network name: %s", nic.Networkname)
204161
}
205162

@@ -215,7 +172,7 @@ func testAccCheckCloudStackNICMacAddress(
215172
nic *cloudstack.Nic) resource.TestCheckFunc {
216173
return func(s *terraform.State) error {
217174

218-
if nic.Networkname != "terraform-network" {
175+
if nic.Networkname != "terraform-network-secondary" {
219176
return fmt.Errorf("Bad network name: %s", nic.Networkname)
220177
}
221178

@@ -227,26 +184,6 @@ func testAccCheckCloudStackNICMacAddress(
227184
}
228185
}
229186

230-
func testAccCheckCloudStackNICCompleteAttributes(
231-
nic *cloudstack.Nic) resource.TestCheckFunc {
232-
return func(s *terraform.State) error {
233-
234-
if nic.Networkname != "terraform-network" {
235-
return fmt.Errorf("Bad network name: %s", nic.Networkname)
236-
}
237-
238-
if nic.Ipaddress != "10.1.2.150" {
239-
return fmt.Errorf("Bad IP address: %s", nic.Ipaddress)
240-
}
241-
242-
if nic.Macaddress != "02:1A:4B:3C:5D:6E" {
243-
return fmt.Errorf("Bad MAC address: %s", nic.Macaddress)
244-
}
245-
246-
return nil
247-
}
248-
}
249-
250187
func testAccCheckCloudStackNICDestroy(s *terraform.State) error {
251188
cs := testAccProvider.Meta().(*cloudstack.CloudStackClient)
252189

@@ -271,16 +208,16 @@ func testAccCheckCloudStackNICDestroy(s *terraform.State) error {
271208

272209
const testAccCloudStackNIC_basic = `
273210
resource "cloudstack_network" "foo" {
274-
name = "terraform-network"
275-
display_text = "terraform-network"
211+
name = "terraform-network-primary"
212+
display_text = "terraform-network-primary"
276213
cidr = "10.1.1.0/24"
277214
network_offering = "DefaultIsolatedNetworkOfferingWithSourceNatService"
278215
zone = "Sandbox-simulator"
279216
}
280217
281218
resource "cloudstack_network" "bar" {
282-
name = "terraform-network"
283-
display_text = "terraform-network"
219+
name = "terraform-network-secondary"
220+
display_text = "terraform-network-secondary"
284221
cidr = "10.1.2.0/24"
285222
network_offering = "DefaultIsolatedNetworkOfferingWithSourceNatService"
286223
zone = "Sandbox-simulator"
@@ -303,16 +240,16 @@ resource "cloudstack_nic" "foo" {
303240

304241
const testAccCloudStackNIC_ipaddress = `
305242
resource "cloudstack_network" "foo" {
306-
name = "terraform-network"
307-
display_text = "terraform-network"
243+
name = "terraform-network-primary"
244+
display_text = "terraform-network-primary"
308245
cidr = "10.1.1.0/24"
309246
network_offering = "DefaultIsolatedNetworkOfferingWithSourceNatService"
310247
zone = "Sandbox-simulator"
311248
}
312249
313250
resource "cloudstack_network" "bar" {
314-
name = "terraform-network"
315-
display_text = "terraform-network"
251+
name = "terraform-network-secondary"
252+
display_text = "terraform-network-secondary"
316253
cidr = "10.1.2.0/24"
317254
network_offering = "DefaultIsolatedNetworkOfferingWithSourceNatService"
318255
zone = "Sandbox-simulator"
@@ -336,85 +273,16 @@ resource "cloudstack_nic" "foo" {
336273

337274
const testAccCloudStackNIC_macaddress = `
338275
resource "cloudstack_network" "foo" {
339-
name = "terraform-network"
340-
display_text = "terraform-network"
341-
cidr = "10.1.1.0/24"
342-
network_offering = "DefaultIsolatedNetworkOfferingWithSourceNatService"
343-
zone = "Sandbox-simulator"
344-
}
345-
346-
resource "cloudstack_network" "bar" {
347-
name = "terraform-network"
348-
display_text = "terraform-network"
349-
cidr = "10.1.2.0/24"
350-
network_offering = "DefaultIsolatedNetworkOfferingWithSourceNatService"
351-
zone = "Sandbox-simulator"
352-
}
353-
354-
resource "cloudstack_instance" "foobar" {
355-
name = "terraform-test"
356-
display_name = "terraform"
357-
service_offering= "Medium Instance"
358-
network_id = cloudstack_network.foo.id
359-
template = "CentOS 5.6 (64-bit) no GUI (Simulator)"
360-
zone = "Sandbox-simulator"
361-
expunge = true
362-
}
363-
364-
resource "cloudstack_nic" "foo" {
365-
network_id = cloudstack_network.bar.id
366-
virtual_machine_id = cloudstack_instance.foobar.id
367-
mac_address = "02:1A:4B:3C:5D:6E"
368-
}`
369-
370-
const testAccCloudStackNIC_dhcpoptions = `
371-
resource "cloudstack_network" "foo" {
372-
name = "terraform-network"
373-
display_text = "terraform-network"
374-
cidr = "10.1.1.0/24"
375-
network_offering = "DefaultIsolatedNetworkOfferingWithSourceNatService"
376-
zone = "Sandbox-simulator"
377-
}
378-
379-
resource "cloudstack_network" "bar" {
380-
name = "terraform-network"
381-
display_text = "terraform-network"
382-
cidr = "10.1.2.0/24"
383-
network_offering = "DefaultIsolatedNetworkOfferingWithSourceNatService"
384-
zone = "Sandbox-simulator"
385-
}
386-
387-
resource "cloudstack_instance" "foobar" {
388-
name = "terraform-test"
389-
display_name = "terraform"
390-
service_offering= "Medium Instance"
391-
network_id = cloudstack_network.foo.id
392-
template = "CentOS 5.6 (64-bit) no GUI (Simulator)"
393-
zone = "Sandbox-simulator"
394-
expunge = true
395-
}
396-
397-
resource "cloudstack_nic" "foo" {
398-
network_id = cloudstack_network.bar.id
399-
virtual_machine_id = cloudstack_instance.foobar.id
400-
dhcp_options = {
401-
"dhcp:15" = "example.com"
402-
"dhcp:6" = "8.8.8.8,8.8.4.4"
403-
}
404-
}`
405-
406-
const testAccCloudStackNIC_complete = `
407-
resource "cloudstack_network" "foo" {
408-
name = "terraform-network"
409-
display_text = "terraform-network"
276+
name = "terraform-network-primary"
277+
display_text = "terraform-network-primary"
410278
cidr = "10.1.1.0/24"
411279
network_offering = "DefaultIsolatedNetworkOfferingWithSourceNatService"
412280
zone = "Sandbox-simulator"
413281
}
414282
415283
resource "cloudstack_network" "bar" {
416-
name = "terraform-network"
417-
display_text = "terraform-network"
284+
name = "terraform-network-secondary"
285+
display_text = "terraform-network-secondary"
418286
cidr = "10.1.2.0/24"
419287
network_offering = "DefaultIsolatedNetworkOfferingWithSourceNatService"
420288
zone = "Sandbox-simulator"
@@ -433,10 +301,5 @@ resource "cloudstack_instance" "foobar" {
433301
resource "cloudstack_nic" "foo" {
434302
network_id = cloudstack_network.bar.id
435303
virtual_machine_id = cloudstack_instance.foobar.id
436-
ip_address = "10.1.2.150"
437304
mac_address = "02:1A:4B:3C:5D:6E"
438-
dhcp_options = {
439-
"dhcp:15" = "test.com"
440-
"dhcp:6" = "1.1.1.1,1.0.0.1"
441-
}
442305
}`

0 commit comments

Comments
 (0)