-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #327 from NetApp/old-name-svm
Add old name support for SVM
- Loading branch information
Showing
9 changed files
with
287 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
package svm_test | ||
|
||
import ( | ||
"fmt" | ||
"os" | ||
"regexp" | ||
"testing" | ||
|
||
ntest "github.com/netapp/terraform-provider-netapp-ontap/internal/provider" | ||
|
||
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" | ||
) | ||
|
||
func TestAccSvmPeerResourceAlias(t *testing.T) { | ||
resource.Test(t, resource.TestCase{ | ||
PreCheck: func() { ntest.TestAccPreCheck(t) }, | ||
ProtoV6ProviderFactories: ntest.TestAccProtoV6ProviderFactories, | ||
Steps: []resource.TestStep{ | ||
// Test cluster peer non existant to do svm peer | ||
{ | ||
Config: testAccSvmPeerResourceConfigAlias("testme", "testme2", "abcd", "snapmirror"), | ||
ExpectError: regexp.MustCompile("9895941"), | ||
}, | ||
// Testing in VSIM is failing to peer | ||
// // Create svm peer and read | ||
// { | ||
// Config: testAccSvmPeersResourceConfig("acc_test_peer2", "acc_test2", "swenjuncluster-1", "snapmirror"), | ||
// Check: resource.ComposeTestCheckFunc( | ||
// resource.TestCheckResourceAttr("netapp-ontap_svm_peers_resources.example", "svm.name", "acc_test_peer2"), | ||
// ), | ||
// }, | ||
// // Update applications | ||
// { | ||
// Config: testAccSvmPeersResourceConfig("acc_test_peer2", "acc_test2", "swenjuncluster-1", "flexcache"), | ||
// Check: resource.ComposeTestCheckFunc( | ||
// resource.TestCheckResourceAttr("netapp-ontap_svm_peers_resources.example", "applications.0", "flexcache"), | ||
// resource.TestCheckResourceAttr("netapp-ontap_svm_peers_resources.example", "svm.name", "acc_test_peer2"), | ||
// ), | ||
// }, | ||
// Import and read | ||
{ | ||
ResourceName: "netapp-ontap_svm_peers_resource.example", | ||
ImportState: true, | ||
ImportStateId: fmt.Sprintf("%s,%s,%s,%s", "terraform", "tf_peer", "swenjuncluster-1", "cluster4"), | ||
Check: resource.ComposeTestCheckFunc( | ||
resource.TestCheckResourceAttr("netapp-ontap_svm_peers_resource.example", "svm.name", "snapmirror_dest_dp"), | ||
), | ||
}, | ||
}, | ||
}) | ||
} | ||
func testAccSvmPeerResourceConfigAlias(svm, peerSvm, peerCluster, applications string) string { | ||
host := os.Getenv("TF_ACC_NETAPP_HOST5") | ||
admin := os.Getenv("TF_ACC_NETAPP_USER") | ||
password := os.Getenv("TF_ACC_NETAPP_PASS") | ||
password2 := os.Getenv("TF_ACC_NETAPP_PASS2") | ||
host2 := os.Getenv("TF_ACC_NETAPP_HOST2") | ||
if host == "" || admin == "" || password == "" { | ||
fmt.Println("TF_ACC_NETAPP_HOST2, TF_ACC_NETAPP_HOST5, TF_ACC_NETAPP_USER, TF_ACC_NETAPP_PASS2 and TF_ACC_NETAPP_PASS must be set for acceptance tests") | ||
os.Exit(1) | ||
} | ||
return fmt.Sprintf(` | ||
provider "netapp-ontap" { | ||
connection_profiles = [ | ||
{ | ||
name = "cluster4" | ||
hostname = "%s" | ||
username = "%s" | ||
password = "%s" | ||
validate_certs = false | ||
}, | ||
{ | ||
name = "cluster3" | ||
hostname = "%s" | ||
username = "%s" | ||
password = "%s" | ||
validate_certs = false | ||
}, | ||
] | ||
} | ||
resource "netapp-ontap_svm_peers_resource" "example" { | ||
cx_profile_name = "cluster4" | ||
svm = { | ||
name = "%s" | ||
} | ||
peer = { | ||
svm = { | ||
name = "%s" | ||
} | ||
cluster = { | ||
name = "%s" | ||
} | ||
peer_cx_profile_name = "cluster3" | ||
} | ||
applications = ["%s"] | ||
}`, host, admin, password2, host2, admin, password2, svm, peerSvm, peerCluster, applications) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,123 @@ | ||
package svm_test | ||
|
||
import ( | ||
"fmt" | ||
"os" | ||
"regexp" | ||
"testing" | ||
|
||
ntest "github.com/netapp/terraform-provider-netapp-ontap/internal/provider" | ||
|
||
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" | ||
) | ||
|
||
func TestAccSvmResourceAlias(t *testing.T) { | ||
resource.Test(t, resource.TestCase{ | ||
PreCheck: func() { ntest.TestAccPreCheck(t) }, | ||
ProtoV6ProviderFactories: ntest.TestAccProtoV6ProviderFactories, | ||
Steps: []resource.TestStep{ | ||
{ | ||
Config: testAccSvmResourceConfigAlias("tfsvm4", "test", "default"), | ||
Check: resource.ComposeTestCheckFunc( | ||
// Check to see the svm name is correct, | ||
resource.TestCheckResourceAttr("netapp-ontap_svm_resource.example", "name", "tfsvm4"), | ||
// Check to see if Ipspace is set correctly | ||
resource.TestCheckResourceAttr("netapp-ontap_svm_resource.example", "ipspace", "ansibleIpspace_newname"), | ||
// Check that a ID has been set (we don't know what the vaule is as it changes | ||
resource.TestCheckResourceAttrSet("netapp-ontap_svm_resource.example", "id"), | ||
resource.TestCheckResourceAttr("netapp-ontap_svm_resource.example", "comment", "test")), | ||
}, | ||
// Update a comment | ||
{ | ||
Config: testAccSvmResourceConfigAlias("tfsvm4", "carchi8py was here", "default"), | ||
Check: resource.ComposeTestCheckFunc( | ||
resource.TestCheckResourceAttr("netapp-ontap_svm_resource.example", "comment", "carchi8py was here"), | ||
resource.TestCheckResourceAttr("netapp-ontap_svm_resource.example", "name", "tfsvm4")), | ||
}, | ||
// Update a comment with an empty string | ||
{ | ||
Config: testAccSvmResourceConfigAlias("tfsvm4", "", "default"), | ||
Check: resource.ComposeTestCheckFunc( | ||
resource.TestCheckResourceAttr("netapp-ontap_svm_resource.example", "comment", ""), | ||
resource.TestCheckResourceAttr("netapp-ontap_svm_resource.example", "name", "tfsvm4")), | ||
}, | ||
// Update snapshot policy default-1weekly and comment "carchi8py was here" | ||
{ | ||
Config: testAccSvmResourceConfigAlias("tfsvm4", "carchi8py was here", "default-1weekly"), | ||
Check: resource.ComposeTestCheckFunc( | ||
resource.TestCheckResourceAttr("netapp-ontap_svm_resource.example", "comment", "carchi8py was here"), | ||
resource.TestCheckResourceAttr("netapp-ontap_svm_resource.example", "snapshot_policy", "default-1weekly"), | ||
resource.TestCheckResourceAttr("netapp-ontap_svm_resource.example", "name", "tfsvm4")), | ||
}, | ||
// Update snapshot policy with empty string | ||
{ | ||
Config: testAccSvmResourceConfigAlias("tfsvm4", "carchi8py was here", ""), | ||
ExpectError: regexp.MustCompile("cannot be updated with empty string"), | ||
}, | ||
// change SVM name | ||
{ | ||
Config: testAccSvmResourceConfigAlias("tfsvm3", "carchi8py was here", "default"), | ||
Check: resource.ComposeTestCheckFunc( | ||
resource.TestCheckResourceAttr("netapp-ontap_svm_resource.example", "comment", "carchi8py was here"), | ||
resource.TestCheckResourceAttr("netapp-ontap_svm_resource.example", "name", "tfsvm3")), | ||
}, | ||
// Fail if the name already exist | ||
{ | ||
Config: testAccSvmResourceConfigAlias("svm5", "carchi8py was here", "default"), | ||
ExpectError: regexp.MustCompile("13434908"), | ||
}, | ||
// Import and read | ||
{ | ||
ResourceName: "netapp-ontap_svm_resource.example", | ||
ImportState: true, | ||
ImportStateId: fmt.Sprintf("%s,%s", "ansibleSVM", "cluster4"), | ||
Check: resource.ComposeTestCheckFunc( | ||
resource.TestCheckResourceAttr("netapp-ontap_svm_resource.example", "name", "ansibleSVM"), | ||
), | ||
}, | ||
}, | ||
}) | ||
} | ||
func testAccSvmResourceConfigAlias(svm, comment string, snapshotPolicy string) string { | ||
host := os.Getenv("TF_ACC_NETAPP_HOST") | ||
admin := os.Getenv("TF_ACC_NETAPP_USER") | ||
password := os.Getenv("TF_ACC_NETAPP_PASS") | ||
if host == "" || admin == "" || password == "" { | ||
fmt.Println("TF_ACC_NETAPP_HOST, TF_ACC_NETAPP_USER, and TF_ACC_NETAPP_PASS must be set for acceptance tests") | ||
os.Exit(1) | ||
} | ||
return fmt.Sprintf(` | ||
provider "netapp-ontap" { | ||
connection_profiles = [ | ||
{ | ||
name = "cluster4" | ||
hostname = "%s" | ||
username = "%s" | ||
password = "%s" | ||
validate_certs = false | ||
}, | ||
] | ||
} | ||
resource "netapp-ontap_svm_resource" "example" { | ||
cx_profile_name = "cluster4" | ||
name = "%s" | ||
ipspace = "ansibleIpspace_newname" | ||
comment = "%s" | ||
snapshot_policy = "%s" | ||
subtype = "default" | ||
language = "en_us.utf_8" | ||
aggregates = [ | ||
{ | ||
name = "aggr1" | ||
}, | ||
{ | ||
name = "aggr2" | ||
}, | ||
{ | ||
name = "aggr3" | ||
}, | ||
] | ||
max_volumes = "unlimited" | ||
}`, host, admin, password, svm, comment, snapshotPolicy) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters