Skip to content

Commit 0520300

Browse files
akabhaskmdmohan
authored andcommitted
Acceptance cases for 4 fabric types msite_ext_net, ipfm, evpn_vxlan and evpn_msd module
1 parent 9e47937 commit 0520300

File tree

15 files changed

+809
-1
lines changed

15 files changed

+809
-1
lines changed

generator/defs/fabric_msite_ext_net.yaml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ resource:
1717
tf_name: fabric_name
1818
description: 'Fabric name to be created, updated or deleted (Max Size 64).'
1919
type: String
20-
example: TF_FABRIC_ISN
20+
example: TF_FABRIC_MSITE_EXT_NET
2121
mandatory: true
2222
tf_requires_replace: true
2323
- model_name: AAA_REMOTE_IP_ENABLED
@@ -37,6 +37,7 @@ resource:
3737
ASN for each Fabric.
3838
type: String
3939
mandatory: true
40+
example: 65000
4041
- model_name: BOOTSTRAP_CONF
4142
tf_name: bootstrap_conf
4243
description: Additional CLIs required during device bootup/login e.g. AAA/Radius

internal/provider/fabrics_test.go

Lines changed: 142 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,142 @@
1+
// Copyright (c) 2024 Cisco Systems, Inc. and its affiliates
2+
//
3+
// This Source Code Form is subject to the terms of the Mozilla Public
4+
// License, v. 2.0. If a copy of the MPL was not distributed with this
5+
// file, You can obtain one at https://mozilla.org/MPL/2.0/.
6+
//
7+
// SPDX-License-Identifier: MPL-2.0
8+
9+
package provider
10+
11+
import (
12+
"regexp"
13+
helper "terraform-provider-ndfc/internal/provider/testing"
14+
"testing"
15+
16+
"github.com/hashicorp/terraform-plugin-testing/helper/resource"
17+
)
18+
19+
func TestAccFabricVxlanEvpnResource(t *testing.T) {
20+
cfg := map[string]string{
21+
"FabricType": "fabric_vxlan_evpn",
22+
"User": helper.GetConfig("ndfc_fabric_vxlan_evpn").NDFC.User,
23+
"Password": helper.GetConfig("ndfc_fabric_vxlan_evpn").NDFC.Password,
24+
"Host": helper.GetConfig("ndfc_fabric_vxlan_evpn").NDFC.URL,
25+
"Insecure": helper.GetConfig("ndfc_fabric_vxlan_evpn").NDFC.Insecure,
26+
}
27+
resource.Test(t, resource.TestCase{
28+
PreCheck: func() { testAccPreCheck(t, "fabric_vxlan_evpn") },
29+
ProtoV6ProviderFactories: testAccProtoV6ProviderFactories,
30+
Steps: []resource.TestStep{
31+
{ // Create fabric and update bfd_enable
32+
Config: func() string {
33+
return helper.GenerateFabricConfig(cfg, helper.Base_file)
34+
}(),
35+
//Check: resource.ComposeTestCheckFunc(FabricVxlanEvpnModelHelperStateCheck("ndfc_fabric_vxlan_evpn.test_resource_fabric_vxlan_evpn_1", FabricRsc, path.Empty())...),
36+
}, { // update bgp_as, it capture failure
37+
Config: func() string {
38+
return helper.GenerateFabricConfig(cfg, helper.Bgp_as_change_file)
39+
}(),
40+
//Check: resource.ComposeTestCheckFunc(FabricVxlanEvpnModelHelperStateCheck("ndfc_fabric_vxlan_evpn.test_resource_fabric_vxlan_evpn_1", FabricRsc, path.Empty())...),
41+
ExpectError: regexp.MustCompile("bgp_as cannot be updated"),
42+
}, { // modify fields like CDP_ENABLE, BFD_ENABLE and MTU with different values and deploy true
43+
Config: func() string {
44+
return helper.GenerateFabricConfig(cfg, helper.Modified_file)
45+
}(),
46+
//Check: resource.ComposeTestCheckFunc(FabricVxlanEvpnModelHelperStateCheck("ndfc_fabric_vxlan_evpn.test_resource_fabric_vxlan_evpn_1", FabricRsc, path.Empty())...),
47+
},
48+
},
49+
})
50+
51+
}
52+
53+
func TestAccFabricVxlanMsdResource(t *testing.T) {
54+
cfg := map[string]string{
55+
"FabricType": "fabric_vxlan_msd",
56+
"User": helper.GetConfig("ndfc_fabric_vxlan_msd").NDFC.User,
57+
"Password": helper.GetConfig("ndfc_fabric_vxlan_msd").NDFC.Password,
58+
"Host": helper.GetConfig("ndfc_fabric_vxlan_msd").NDFC.URL,
59+
"Insecure": helper.GetConfig("ndfc_fabric_vxlan_msd").NDFC.Insecure,
60+
}
61+
62+
resource.Test(t, resource.TestCase{
63+
PreCheck: func() { testAccPreCheck(t, "fabric_vxlan_msd") },
64+
ProtoV6ProviderFactories: testAccProtoV6ProviderFactories,
65+
Steps: []resource.TestStep{
66+
{ // Create fabric
67+
Config: func() string {
68+
return helper.GenerateFabricConfig(cfg, helper.Base_file)
69+
}(),
70+
//Check: resource.ComposeTestCheckFunc(FabricVxlanMsdModelHelperStateCheck("ndfc_fabric_vxlan_msd.test_resource_fabric_vxlan_msd_1", FabricRsc, path.Empty())...),
71+
}, { // modify fields like ANYCAST_GW_MAC, BGW_ROUTING_TAG and DELAY_RESTORE with different values and deploy true
72+
Config: func() string {
73+
return helper.GenerateFabricConfig(cfg, helper.Modified_file)
74+
}(),
75+
//Check: resource.ComposeTestCheckFunc(FabricVxlanMsdModelHelperStateCheck("ndfc_fabric_vxlan_msd.test_resource_fabric_vxlan_msd_1", FabricRsc, path.Empty())...),
76+
},
77+
},
78+
})
79+
80+
}
81+
82+
func TestAccFabricLanClassicResource(t *testing.T) {
83+
cfg := map[string]string{
84+
"FabricType": "fabric_lan_classic",
85+
"User": helper.GetConfig("ndfc_fabric_lan_classic").NDFC.User,
86+
"Password": helper.GetConfig("ndfc_fabric_lan_classic").NDFC.Password,
87+
"Host": helper.GetConfig("ndfc_fabric_lan_classic").NDFC.URL,
88+
"Insecure": helper.GetConfig("ndfc_fabric_lan_classic").NDFC.Insecure,
89+
}
90+
resource.Test(t, resource.TestCase{
91+
PreCheck: func() { testAccPreCheck(t, "fabric_lan_classic") },
92+
ProtoV6ProviderFactories: testAccProtoV6ProviderFactories,
93+
Steps: []resource.TestStep{
94+
{ // Create fabric and update bfd_enable
95+
Config: func() string {
96+
return helper.GenerateFabricConfig(cfg, helper.Base_file)
97+
}(),
98+
//Check: resource.ComposeTestCheckFunc(FabricLanClassicModelHelperStateCheck("ndfc_fabric_lan_classic.test_resource_fabric_lan_classic_1", FabricRsc, path.Empty())...),
99+
}, { // modify fields like CDP_ENABLE, BFD_ENABLE and MTU with different values
100+
Config: func() string {
101+
return helper.GenerateFabricConfig(cfg, helper.Modified_file)
102+
}(),
103+
//Check: resource.ComposeTestCheckFunc(FabricLanClassicModelHelperStateCheck("ndfc_fabric_lan_classic.test_resource_fabric_lan_classic_1", FabricRsc, path.Empty())...),
104+
},
105+
},
106+
})
107+
108+
}
109+
func TestAccFabricMsiteExtNetResource(t *testing.T) {
110+
111+
cfg := map[string]string{
112+
"FabricType": "fabric_msite_ext_net",
113+
"User": helper.GetConfig("ndfc_fabric_msite_ext_net").NDFC.User,
114+
"Password": helper.GetConfig("ndfc_fabric_msite_ext_net").NDFC.Password,
115+
"Host": helper.GetConfig("ndfc_fabric_msite_ext_net").NDFC.URL,
116+
"Insecure": helper.GetConfig("ndfc_fabric_msite_ext_net").NDFC.Insecure,
117+
}
118+
resource.Test(t, resource.TestCase{
119+
PreCheck: func() { testAccPreCheck(t, "fabric_msite_ext_net") },
120+
ProtoV6ProviderFactories: testAccProtoV6ProviderFactories,
121+
Steps: []resource.TestStep{
122+
{ // Create fabric and update bfd_enable
123+
Config: func() string {
124+
return helper.GenerateFabricConfig(cfg, helper.Base_file)
125+
}(),
126+
//Check: resource.ComposeTestCheckFunc(FabricMsiteExtNetModelHelperStateCheck("ndfc_fabric_msite_ext_net.test_resource_fabric_msite_ext_net_1", FabricRsc, path.Empty())...),
127+
}, { // update bgp_as, it capture failure
128+
Config: func() string {
129+
return helper.GenerateFabricConfig(cfg, helper.Bgp_as_change_file)
130+
}(),
131+
//Check: resource.ComposeTestCheckFunc(FabricMsiteExtNetModelHelperStateCheck("ndfc_fabric_msite_ext_net.test_resource_fabric_msite_ext_net_1", FabricRsc, path.Empty())...),
132+
ExpectError: regexp.MustCompile("bgp_as cannot be updated"),
133+
}, { // modify fields like CDP_ENABLE, BFD_ENABLE and MTU with different values
134+
Config: func() string {
135+
return helper.GenerateFabricConfig(cfg, helper.Modified_file)
136+
}(),
137+
//Check: resource.ComposeTestCheckFunc(FabricMsiteExtNetModelHelperStateCheck("ndfc_fabric_msite_ext_net.test_resource_fabric_msite_ext_net_1", FabricRsc, path.Empty())...),
138+
},
139+
},
140+
})
141+
142+
}
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
// Copyright (c) 2024 Cisco Systems, Inc. and its affiliates
2+
//
3+
// This Source Code Form is subject to the terms of the Mozilla Public
4+
// License, v. 2.0. If a copy of the MPL was not distributed with this
5+
// file, You can obtain one at https://mozilla.org/MPL/2.0/.
6+
//
7+
// SPDX-License-Identifier: MPL-2.0
8+
9+
package testing
10+
11+
import (
12+
"log"
13+
"os"
14+
)
15+
16+
const (
17+
Base_file = iota
18+
Modified_file
19+
Bgp_as_change_file
20+
)
21+
22+
func GenerateFabricConfig(cfg map[string]string, fileType int) string {
23+
24+
var tf_config = `
25+
terraform {
26+
required_providers {
27+
ndfc = {
28+
source = "registry.terraform.io/cisco/ndfc"
29+
}
30+
}
31+
}
32+
provider "ndfc" {
33+
host = "` + cfg["Host"] + `"
34+
username = "` + cfg["User"] + `"
35+
password = "` + cfg["Password"] + `"
36+
insecure = true
37+
}
38+
`
39+
var filePath string
40+
folder := os.Getenv("GOPATH") + "/src/terraform-provider-ndfc/testdata/" + cfg["FabricType"]
41+
if fileType == Base_file {
42+
filePath = folder + "/resource.tf"
43+
} else if fileType == Modified_file {
44+
filePath = folder + "/resource_modified.tf"
45+
} else if fileType == Bgp_as_change_file {
46+
filePath = folder + "/resource_bgp_as_change.tf"
47+
} else {
48+
log.Fatalf("Invalid file type: %d", fileType)
49+
}
50+
rscFile, err := os.ReadFile(filePath)
51+
if err != nil {
52+
log.Fatalf("Failed to open resource config file: %s", err)
53+
}
54+
55+
tf_config += string(rscFile)
56+
log.Printf("TF Config: %s", tf_config)
57+
return tf_config
58+
}

testdata/fabric_ipfm/resource.tf

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
2+
resource "ndfc_fabric_ipfm" "test_resource_fabric_ipfm_1" {
3+
fabric_name = "IP_FABRIC_MEDIA"
4+
aaa_remote_ip_enabled = false
5+
bootstrap_enable = false
6+
bootstrap_multisubnet = "#Scope_Start_IP, Scope_End_IP, Scope_Default_Gateway, Scope_Subnet_Prefix"
7+
cdp_enable = false
8+
dhcp_enable = false
9+
enable_aaa = false
10+
enable_asm = false
11+
enable_nbm_passive = false
12+
fabric_interface_type = "p2p"
13+
fabric_mtu = 9216
14+
feature_ptp = false
15+
isis_auth_enable = false
16+
isis_level = "level-2"
17+
l2_host_intf_mtu = 9216
18+
link_state_routing = "ospf"
19+
link_state_routing_tag = "1"
20+
loopback0_ip_range = "10.2.0.0/22"
21+
nxapi_vrf = "management"
22+
ospf_area_id = "0.0.0.0"
23+
ospf_auth_enable = false
24+
pim_hello_auth_enable = false
25+
pm_enable = false
26+
power_redundancy_mode = "ps-redundant"
27+
routing_lb_id = 0
28+
snmp_server_host_trap = true
29+
static_underlay_ip_alloc = false
30+
subnet_range = "10.4.0.0/16"
31+
subnet_target_mask = 30
32+
deploy = false
33+
}
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
2+
resource "ndfc_fabric_ipfm" "test_resource_fabric_ipfm_1" {
3+
fabric_name = "IP_FABRIC_MEDIA"
4+
aaa_remote_ip_enabled = false
5+
bootstrap_enable = false
6+
bootstrap_multisubnet = "#Scope_Start_IP, Scope_End_IP, Scope_Default_Gateway, Scope_Subnet_Prefix"
7+
cdp_enable = true
8+
dhcp_enable = false
9+
enable_aaa = false
10+
enable_asm = false
11+
enable_nbm_passive = false
12+
fabric_interface_type = "p2p"
13+
fabric_mtu = 9230
14+
feature_ptp = false
15+
isis_auth_enable = false
16+
isis_level = "level-2"
17+
l2_host_intf_mtu = 9200
18+
link_state_routing = "ospf"
19+
link_state_routing_tag = "1"
20+
loopback0_ip_range = "10.2.0.0/22"
21+
nxapi_vrf = "management"
22+
ospf_area_id = "0.0.0.0"
23+
ospf_auth_enable = false
24+
pim_hello_auth_enable = false
25+
pm_enable = true
26+
power_redundancy_mode = "ps-redundant"
27+
routing_lb_id = 0
28+
snmp_server_host_trap = true
29+
static_underlay_ip_alloc = false
30+
subnet_range = "10.4.0.0/16"
31+
subnet_target_mask = 30
32+
deploy = true
33+
}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
2+
resource "ndfc_fabric_lan_classic" "test_resource_fabric_lan_classic_1" {
3+
fabric_name = "TF_FABRIC_LAN_CLASSIC"
4+
aaa_remote_ip_enabled = false
5+
bootstrap_multisubnet = "#Scope_Start_IP, Scope_End_IP, Scope_Default_Gateway, Scope_Subnet_Prefix"
6+
cdp_enable = false
7+
dhcp_enable = false
8+
enable_netflow = false
9+
enable_nxapi = false
10+
enable_nxapi_http = false
11+
feature_ptp = false
12+
inband_mgmt = false
13+
is_read_only = true
14+
mpls_handoff = false
15+
netflow_exporter_list = jsonencode({ "NETFLOW_EXPORTER_LIST" : [{ "EXPORTER_NAME" : "Test2", "IP" : "10.1.1.1", "VRF" : "", "SRC_IF_NAME" : "eth1/1", "UDP_PORT" : "800" }] })
16+
netflow_monitor_list = jsonencode({ "NETFLOW_MONITOR_LIST" : [{ "MONITOR_NAME" : "Test", "RECORD_NAME" : "Test1", "EXPORTER1" : "Test2", "EXPORTER2" : "" }] })
17+
netflow_record_list = jsonencode({ "NETFLOW_RECORD_LIST" : [{ "RECORD_NAME" : "Test1", "RECORD_TEMPLATE" : "netflow_ipv4_record", "LAYER2_RECORD" : "false" }] })
18+
netflow_sampler_list = jsonencode({ "NETFLOW_SAMPLER_LIST" : [{ "SAMPLER_NAME" : "Test1", "NUM_SAMPLES" : 12, "SAMPLING_RATE" : 10 }] })
19+
nxapi_https_port = 443
20+
nxapi_http_port = 80
21+
pm_enable = false
22+
power_redundancy_mode = "ps-redundant"
23+
snmp_server_host_trap = true
24+
subinterface_range = "2-511"
25+
enable_realtime_backup = false
26+
enable_scheduled_backup = false
27+
deploy = false
28+
}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
2+
resource "ndfc_fabric_lan_classic" "test_resource_fabric_lan_classic_1" {
3+
fabric_name = "TF_FABRIC_LAN_CLASSIC"
4+
aaa_remote_ip_enabled = false
5+
bootstrap_multisubnet = "#Scope_Start_IP, Scope_End_IP, Scope_Default_Gateway, Scope_Subnet_Prefix"
6+
cdp_enable = true
7+
dhcp_enable = false
8+
enable_netflow = false
9+
enable_nxapi = true
10+
enable_nxapi_http = false
11+
feature_ptp = false
12+
inband_mgmt = false
13+
is_read_only = true
14+
mpls_handoff = false
15+
netflow_exporter_list = jsonencode({ "NETFLOW_EXPORTER_LIST" : [{ "EXPORTER_NAME" : "Test2", "IP" : "10.1.1.1", "VRF" : "", "SRC_IF_NAME" : "eth1/1", "UDP_PORT" : "800" }] })
16+
netflow_monitor_list = jsonencode({ "NETFLOW_MONITOR_LIST" : [{ "MONITOR_NAME" : "Test", "RECORD_NAME" : "Test1", "EXPORTER1" : "Test2", "EXPORTER2" : "" }] })
17+
netflow_record_list = jsonencode({ "NETFLOW_RECORD_LIST" : [{ "RECORD_NAME" : "Test1", "RECORD_TEMPLATE" : "netflow_ipv4_record", "LAYER2_RECORD" : "false" }] })
18+
netflow_sampler_list = jsonencode({ "NETFLOW_SAMPLER_LIST" : [{ "SAMPLER_NAME" : "Test1", "NUM_SAMPLES" : 12, "SAMPLING_RATE" : 10 }] })
19+
nxapi_https_port = 443
20+
nxapi_http_port = 80
21+
pm_enable = true
22+
power_redundancy_mode = "ps-redundant"
23+
snmp_server_host_trap = true
24+
subinterface_range = "2-511"
25+
enable_realtime_backup = false
26+
enable_scheduled_backup = false
27+
deploy = true
28+
}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
2+
resource "ndfc_fabric_msite_ext_net" "test_resource_fabric_msite_ext_net_1" {
3+
fabric_name = "TF_FABRIC_MSITE_EXT_NET"
4+
aaa_remote_ip_enabled = false
5+
bootstrap_multisubnet = "#Scope_Start_IP, Scope_End_IP, Scope_Default_Gateway, Scope_Subnet_Prefix"
6+
cdp_enable = false
7+
dhcp_enable = false
8+
enable_netflow = false
9+
bgp_as = 60000
10+
enable_nxapi = false
11+
enable_nxapi_http = false
12+
enable_rt_intf_stats = false
13+
feature_ptp = false
14+
inband_mgmt = false
15+
is_read_only = true
16+
mpls_handoff = false
17+
netflow_exporter_list = jsonencode({ "NETFLOW_EXPORTER_LIST" : [{ "EXPORTER_NAME" : "Test2", "IP" : "10.1.1.1", "VRF" : "", "SRC_IF_NAME" : "eth1/1", "UDP_PORT" : "800" }] })
18+
netflow_monitor_list = jsonencode({ "NETFLOW_MONITOR_LIST" : [{ "MONITOR_NAME" : "Test", "RECORD_NAME" : "Test1", "EXPORTER1" : "Test2", "EXPORTER2" : "" }] })
19+
netflow_record_list = jsonencode({ "NETFLOW_RECORD_LIST" : [{ "RECORD_NAME" : "Test1", "RECORD_TEMPLATE" : "netflow_ipv4_record", "LAYER2_RECORD" : "false" }] })
20+
netflow_sampler_list = jsonencode({ "NETFLOW_SAMPLER_LIST" : [{ "SAMPLER_NAME" : "Test1", "NUM_SAMPLES" : 12, "SAMPLING_RATE" : 10 }] })
21+
nxapi_https_port = 443
22+
nxapi_http_port = 80
23+
pm_enable = false
24+
power_redundancy_mode = "ps-redundant"
25+
snmp_server_host_trap = true
26+
subinterface_range = "2-511"
27+
deploy = false
28+
}

0 commit comments

Comments
 (0)