Skip to content

Commit 86d246b

Browse files
committed
Initial attempt at support for storage controllers.
#84. Also, clean up error messages to prevent maddening code-analysis warnings.
1 parent f87b183 commit 86d246b

31 files changed

+502
-240
lines changed

ddcloud/datasource_networkdomain_test.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ func testCheckDDCloudNetworkDomainMatchesDataSource(resourceName string, dataSou
9191
}
9292

9393
if res.Primary.ID != ds.Primary.ID {
94-
return fmt.Errorf("Bad: Resource '%s' has Id '%s', but data-source '%s' has Id '%s' (expected the IDs to match)",
94+
return fmt.Errorf("bad: Resource '%s' has Id '%s', but data-source '%s' has Id '%s' (expected the IDs to match)",
9595
resourceName,
9696
res.Primary.ID,
9797
dataSourceName,
@@ -103,7 +103,7 @@ func testCheckDDCloudNetworkDomainMatchesDataSource(resourceName string, dataSou
103103
dsAttributes := ds.Primary.Attributes
104104

105105
if resAttributes[resourceKeyNetworkDomainDescription] != dsAttributes[resourceKeyNetworkDomainDescription] {
106-
return fmt.Errorf("Bad: Resource '%s' has description '%s', but data-source '%s' has description '%s' (expected the plans to match)",
106+
return fmt.Errorf("bad: Resource '%s' has description '%s', but data-source '%s' has description '%s' (expected the plans to match)",
107107
resourceName,
108108
resAttributes[resourceKeyNetworkDomainDescription],
109109
dataSourceName,
@@ -112,7 +112,7 @@ func testCheckDDCloudNetworkDomainMatchesDataSource(resourceName string, dataSou
112112
}
113113

114114
if resAttributes[resourceKeyNetworkDomainPlan] != dsAttributes[resourceKeyNetworkDomainPlan] {
115-
return fmt.Errorf("Bad: Resource '%s' has plan '%s', but data-source '%s' has plan '%s' (expected the plans to match)",
115+
return fmt.Errorf("bad: Resource '%s' has plan '%s', but data-source '%s' has plan '%s' (expected the plans to match)",
116116
resourceName,
117117
resAttributes[resourceKeyNetworkDomainPlan],
118118
dataSourceName,
@@ -121,7 +121,7 @@ func testCheckDDCloudNetworkDomainMatchesDataSource(resourceName string, dataSou
121121
}
122122

123123
if res.Primary.Attributes[resourceKeyNetworkDomainNatIPv4Address] != ds.Primary.Attributes[resourceKeyNetworkDomainNatIPv4Address] {
124-
return fmt.Errorf("Bad: Resource '%s' has S/NAT address '%s', but data-source '%s' has S/NAT address '%s' (expected the addresses to match)",
124+
return fmt.Errorf("bad: Resource '%s' has S/NAT address '%s', but data-source '%s' has S/NAT address '%s' (expected the addresses to match)",
125125
resourceName,
126126
resAttributes[resourceKeyNetworkDomainNatIPv4Address],
127127
dataSourceName,

ddcloud/provider.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -138,22 +138,22 @@ func configureProvider(providerSettings *schema.ResourceData) (interface{}, erro
138138
)
139139
customEndPoint := providerSettings.Get("cloudcontrol_endpoint").(string)
140140
if region == "" && customEndPoint == "" {
141-
return nil, fmt.Errorf("Neither the 'region' nor the 'cloudcontrol_endpoint' provider properties were specified (the 'ddcloud' provider requires exactly one of these properties to be configured).")
141+
return nil, fmt.Errorf("neither the 'region' nor the 'cloudcontrol_endpoint' provider properties were specified (the 'ddcloud' provider requires exactly one of these properties to be configured)")
142142
}
143143

144144
username := providerSettings.Get("username").(string)
145145
if isEmpty(username) {
146146
username = os.Getenv("MCP_USER")
147147
if isEmpty(username) {
148-
return nil, fmt.Errorf("The 'username' property was not specified for the 'ddcloud' provider, and the 'MCP_USER' environment variable is not present. Please supply either one of these to configure the user name used to authenticate to Dimension Data CloudControl.")
148+
return nil, fmt.Errorf("the 'username' property was not specified for the 'ddcloud' provider, and the 'MCP_USER' environment variable is not present. Please supply either one of these to configure the user name used to authenticate to Dimension Data CloudControl")
149149
}
150150
}
151151

152152
password := providerSettings.Get("password").(string)
153153
if isEmpty(password) {
154154
password = os.Getenv("MCP_PASSWORD")
155155
if isEmpty(password) {
156-
return nil, fmt.Errorf("The 'password' property was not specified for the 'ddcloud' provider, and the 'MCP_PASSWORD' environment variable is not present. Please supply either one of these to configure the password used to authenticate to Dimension Data CloudControl.")
156+
return nil, fmt.Errorf("the 'password' property was not specified for the 'ddcloud' provider, and the 'MCP_PASSWORD' environment variable is not present. Please supply either one of these to configure the password used to authenticate to Dimension Data CloudControl")
157157
}
158158
}
159159

ddcloud/public_ip_block.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ func addPublicIPBlock(networkDomainID string, apiClient *compute.Client) (*compu
1717
return nil, err
1818
}
1919
if publicIPBlock == nil {
20-
return nil, fmt.Errorf("Cannot find newly-added public IPv4 address block '%s'.", blockID)
20+
return nil, fmt.Errorf("cannot find newly-added public IPv4 address block '%s'", blockID)
2121
}
2222

2323
return publicIPBlock, nil

ddcloud/resource_address_list_test.go

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -174,12 +174,12 @@ func testCheckDDCloudAddressListExists(name string, exists bool) resource.TestCh
174174
client := testAccProvider.Meta().(*providerState).Client()
175175
addressList, err := client.GetIPAddressList(addressListID)
176176
if err != nil {
177-
return fmt.Errorf("Bad: Get address list: %s", err)
177+
return fmt.Errorf("bad: Get address list: %s", err)
178178
}
179179
if exists && addressList == nil {
180-
return fmt.Errorf("Bad: address list not found with Id '%s'.", addressListID)
180+
return fmt.Errorf("bad: address list not found with Id '%s'", addressListID)
181181
} else if !exists && addressList != nil {
182-
return fmt.Errorf("Bad: address list still exists with Id '%s'.", addressListID)
182+
return fmt.Errorf("bad: address list still exists with Id '%s'", addressListID)
183183
}
184184

185185
return nil
@@ -203,22 +203,22 @@ func testCheckDDCloudAddressListMatches(name string, expected compute.IPAddressL
203203
client := testAccProvider.Meta().(*providerState).Client()
204204
addressList, err := client.GetIPAddressList(addressListID)
205205
if err != nil {
206-
return fmt.Errorf("Bad: Get address list: %s", err)
206+
return fmt.Errorf("bad: Get address list: %s", err)
207207
}
208208
if addressList == nil {
209-
return fmt.Errorf("Bad: address list not found with Id '%s'", addressListID)
209+
return fmt.Errorf("bad: address list not found with Id '%s'", addressListID)
210210
}
211211

212212
if addressList.Name != expected.Name {
213-
return fmt.Errorf("Bad: address list '%s' has name '%s' (expected '%s')", addressListID, addressList.Name, expected.Name)
213+
return fmt.Errorf("bad: address list '%s' has name '%s' (expected '%s')", addressListID, addressList.Name, expected.Name)
214214
}
215215

216216
if addressList.Description != expected.Description {
217-
return fmt.Errorf("Bad: address list '%s' has description '%s' (expected '%s')", addressListID, addressList.Description, expected.Description)
217+
return fmt.Errorf("bad: address list '%s' has description '%s' (expected '%s')", addressListID, addressList.Description, expected.Description)
218218
}
219219

220220
if len(addressList.Addresses) != len(expected.Addresses) {
221-
return fmt.Errorf("Bad: address list '%s' has %d addresses or address-ranges (expected '%d')", addressListID, len(addressList.Addresses), len(expected.Addresses))
221+
return fmt.Errorf("bad: address list '%s' has %d addresses or address-ranges (expected '%d')", addressListID, len(addressList.Addresses), len(expected.Addresses))
222222
}
223223

224224
err = compareAddressListEntries(expected, *addressList)
@@ -227,15 +227,15 @@ func testCheckDDCloudAddressListMatches(name string, expected compute.IPAddressL
227227
}
228228

229229
if len(addressList.ChildLists) != len(expected.ChildLists) {
230-
return fmt.Errorf("Bad: address list '%s' has %d child lists (expected '%d')", addressListID, len(addressList.ChildLists), len(expected.ChildLists))
230+
return fmt.Errorf("bad: address list '%s' has %d child lists (expected '%d')", addressListID, len(addressList.ChildLists), len(expected.ChildLists))
231231
}
232232

233233
for index := range addressList.ChildLists {
234234
expectedChildListID := expected.ChildLists[index].ID
235235
actualChildListID := addressList.ChildLists[index].ID
236236

237237
if actualChildListID != expectedChildListID {
238-
return fmt.Errorf("Bad: address list '%s' has child list at index %d with Id %s (expected '%s')",
238+
return fmt.Errorf("bad: address list '%s' has child list at index %d with Id %s (expected '%s')",
239239
addressListID, index, actualChildListID, expectedChildListID,
240240
)
241241
}
@@ -277,15 +277,15 @@ func compareAddressListEntries(expectedAddressList compute.IPAddressList, actual
277277
actualAddress := actualAddressList.Addresses[index]
278278

279279
if expectedAddress.Begin != actualAddress.Begin {
280-
return fmt.Errorf("Bad: address list '%s' has entry at index %d with begin address %s (expected '%s')",
280+
return fmt.Errorf("bad: address list '%s' has entry at index %d with begin address %s (expected '%s')",
281281
addressListID, index, formatAddress(actualAddress.Begin), formatAddress(expectedAddress.Begin),
282282
)
283283
}
284284

285285
expectedAddressEnd := formatAddress(expectedAddress.End)
286286
actualAddressEnd := formatAddress(actualAddress.End)
287287
if expectedAddressEnd != actualAddressEnd {
288-
return fmt.Errorf("Bad: address list '%s' has entry at index %d with end address %s (expected %s)",
288+
return fmt.Errorf("bad: address list '%s' has entry at index %d with end address %s (expected %s)",
289289
addressListID, index, actualAddressEnd, expectedAddressEnd,
290290
)
291291
}

ddcloud/resource_firewall_rule_test.go

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,12 @@ package ddcloud
22

33
import (
44
"fmt"
5+
"strings"
6+
"testing"
7+
58
"github.com/DimensionDataResearch/go-dd-cloud-compute/compute"
69
"github.com/hashicorp/terraform/helper/resource"
710
"github.com/hashicorp/terraform/terraform"
8-
"strings"
9-
"testing"
1011
)
1112

1213
// ipv6.internode.on.net (CloudControl does not allow "ANY" as a source address for IPv6 rules)
@@ -605,12 +606,12 @@ func testCheckDDCloudFirewallRuleExists(name string, exists bool) resource.TestC
605606
client := testAccProvider.Meta().(*providerState).Client()
606607
firewallRule, err := client.GetFirewallRule(firewallRuleID)
607608
if err != nil {
608-
return fmt.Errorf("Bad: Get firewall rule: %s", err)
609+
return fmt.Errorf("bad: Get firewall rule: %s", err)
609610
}
610611
if exists && firewallRule == nil {
611-
return fmt.Errorf("Bad: Firewall rule not found with Id '%s'.", firewallRuleID)
612+
return fmt.Errorf("bad: Firewall rule not found with Id '%s'", firewallRuleID)
612613
} else if !exists && firewallRule != nil {
613-
return fmt.Errorf("Bad: Firewall rule still exists with Id '%s'.", firewallRuleID)
614+
return fmt.Errorf("bad: Firewall rule still exists with Id '%s'", firewallRuleID)
614615
}
615616

616617
return nil
@@ -632,35 +633,35 @@ func testCheckDDCloudFirewallRuleMatches(name string, expected compute.FirewallR
632633
client := testAccProvider.Meta().(*providerState).Client()
633634
firewallRule, err := client.GetFirewallRule(firewallRuleID)
634635
if err != nil {
635-
return fmt.Errorf("Bad: Get firewall rule: %s", err)
636+
return fmt.Errorf("bad: Get firewall rule: %s", err)
636637
}
637638
if firewallRule == nil {
638-
return fmt.Errorf("Bad: Firewall rule not found with Id '%s'", firewallRuleID)
639+
return fmt.Errorf("bad: Firewall rule not found with Id '%s'", firewallRuleID)
639640
}
640641

641642
if firewallRule.Name != expected.Name {
642-
return fmt.Errorf("Bad: Firewall rule '%s' has name '%s' (expected '%s')", firewallRuleID, firewallRule.Name, expected.Name)
643+
return fmt.Errorf("bad: Firewall rule '%s' has name '%s' (expected '%s')", firewallRuleID, firewallRule.Name, expected.Name)
643644
}
644645

645646
if firewallRule.Action != expected.Action {
646-
return fmt.Errorf("Bad: Firewall rule '%s' has action '%s' (expected '%s')", firewallRuleID, firewallRule.Action, expected.Action)
647+
return fmt.Errorf("bad: Firewall rule '%s' has action '%s' (expected '%s')", firewallRuleID, firewallRule.Action, expected.Action)
647648
}
648649

649650
if firewallRule.Action != expected.Action {
650-
return fmt.Errorf("Bad: Firewall rule '%s' has enablement '%t' (expected '%t')", firewallRuleID, firewallRule.Enabled, expected.Enabled)
651+
return fmt.Errorf("bad: Firewall rule '%s' has enablement '%t' (expected '%t')", firewallRuleID, firewallRule.Enabled, expected.Enabled)
651652
}
652653

653654
sourceDifferences := firewallRule.Source.Diff(expected.Source)
654655
if len(sourceDifferences) > 0 {
655-
return fmt.Errorf("Bad: Firewall rule '%s' has unexpected source scope: %s",
656+
return fmt.Errorf("bad: Firewall rule '%s' has unexpected source scope: %s",
656657
firewallRuleID,
657658
strings.Join(sourceDifferences, ", "),
658659
)
659660
}
660661

661662
destinationDifferences := firewallRule.Destination.Diff(expected.Destination)
662663
if len(destinationDifferences) > 0 {
663-
return fmt.Errorf("Bad: Firewall rule '%s' has unexpected destination scope: %s",
664+
return fmt.Errorf("bad: Firewall rule '%s' has unexpected destination scope: %s",
664665
firewallRuleID,
665666
strings.Join(destinationDifferences, ", "),
666667
)
@@ -687,7 +688,7 @@ func testCheckDDCloudFirewallRuleDestroy(state *terraform.State) error {
687688
return nil
688689
}
689690
if firewallRule != nil {
690-
return fmt.Errorf("Firewall rule '%s' still exists.", firewallRuleID)
691+
return fmt.Errorf("firewall rule '%s' still exists", firewallRuleID)
691692
}
692693
}
693694

ddcloud/resource_nat.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ func resourceNATCreate(data *schema.ResourceData, provider interface{}) error {
138138
}
139139

140140
if natRule == nil {
141-
return fmt.Errorf("Cannot find newly-added NAT rule '%s'.", natRuleID)
141+
return fmt.Errorf("cannot find newly-added NAT rule '%s'", natRuleID)
142142
}
143143

144144
data.Set(resourceKeyNATPublicAddress, natRule.ExternalIPAddress)
@@ -217,7 +217,7 @@ func calculateBlockAddresses(block compute.PublicIPBlock) ([]string, error) {
217217

218218
baseAddressComponents := strings.Split(block.BaseIP, ".")
219219
if len(baseAddressComponents) != 4 {
220-
return addresses, fmt.Errorf("Invalid base IP address '%s'.", block.BaseIP)
220+
return addresses, fmt.Errorf("invalid base IP address '%s'", block.BaseIP)
221221
}
222222
baseOctet, err := strconv.Atoi(baseAddressComponents[3])
223223
if err != nil {

ddcloud/resource_network_adapter.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -380,8 +380,8 @@ func validateNetworkAdapterAdapterType(value interface{}, propertyName string) (
380380
switch adapterType {
381381
case compute.NetworkAdapterTypeE1000:
382382
case compute.NetworkAdapterTypeE1000E:
383-
case compute.NetworkAdapterTypeENHANCED_VMXNET2:
384-
case compute.NetworkAdapterTypeFLEXIBLE_PCNET32:
383+
case compute.NetworkAdapterTypeEnhancedVMXNET2:
384+
case compute.NetworkAdapterTypeFlexiblePCNET32:
385385
case compute.NetworkAdapterTypeVMXNET3:
386386
break
387387
default:

ddcloud/resource_networkdomain_test.go

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,11 @@ package ddcloud
22

33
import (
44
"fmt"
5+
"testing"
6+
57
"github.com/DimensionDataResearch/go-dd-cloud-compute/compute"
68
"github.com/hashicorp/terraform/helper/resource"
79
"github.com/hashicorp/terraform/terraform"
8-
"testing"
910
)
1011

1112
/*
@@ -119,12 +120,12 @@ func testCheckDDCloudNetworkDomainExists(name string, exists bool) resource.Test
119120
client := testAccProvider.Meta().(*providerState).Client()
120121
networkDomain, err := client.GetNetworkDomain(networkDomainID)
121122
if err != nil {
122-
return fmt.Errorf("Bad: Get network domain: %s", err)
123+
return fmt.Errorf("bad: Get network domain: %s", err)
123124
}
124125
if exists && networkDomain == nil {
125-
return fmt.Errorf("Bad: Network domain not found with Id '%s'.", networkDomainID)
126+
return fmt.Errorf("bad: Network domain not found with Id '%s'", networkDomainID)
126127
} else if !exists && networkDomain != nil {
127-
return fmt.Errorf("Bad: Network domain still exists with Id '%s'.", networkDomainID)
128+
return fmt.Errorf("bad: Network domain still exists with Id '%s'", networkDomainID)
128129
}
129130

130131
return nil
@@ -147,18 +148,18 @@ func testCheckDDCloudNetworkDomainMatches(name string, expected compute.NetworkD
147148
client := testAccProvider.Meta().(*providerState).Client()
148149
networkDomain, err := client.GetNetworkDomain(networkDomainID)
149150
if err != nil {
150-
return fmt.Errorf("Bad: Get network domain: %s", err)
151+
return fmt.Errorf("bad: Get network domain: %s", err)
151152
}
152153
if networkDomain == nil {
153-
return fmt.Errorf("Bad: Network domain not found with Id '%s'.", networkDomainID)
154+
return fmt.Errorf("bad: Network domain not found with Id '%s'", networkDomainID)
154155
}
155156

156157
if networkDomain.Name != expected.Name {
157-
return fmt.Errorf("Bad: Network domain '%s' has name '%s' (expected '%s').", networkDomainID, networkDomain.Name, expected.Name)
158+
return fmt.Errorf("bad: Network domain '%s' has name '%s' (expected '%s')", networkDomainID, networkDomain.Name, expected.Name)
158159
}
159160

160161
if networkDomain.Description != expected.Description {
161-
return fmt.Errorf("Bad: Network domain '%s' has name '%s' (expected '%s').", networkDomainID, networkDomain.Description, expected.Description)
162+
return fmt.Errorf("bad: Network domain '%s' has name '%s' (expected '%s')", networkDomainID, networkDomain.Description, expected.Description)
162163
}
163164

164165
return nil
@@ -182,7 +183,7 @@ func testCheckDDCloudNetworkDomainDestroy(state *terraform.State) error {
182183
return nil
183184
}
184185
if networkDomain != nil {
185-
return fmt.Errorf("Network domain '%s' still exists.", networkDomainID)
186+
return fmt.Errorf("network domain '%s' still exists", networkDomainID)
186187
}
187188
}
188189

0 commit comments

Comments
 (0)