Skip to content

Commit

Permalink
fix recently-invalidated assumption about bindings[0]; add test cases
Browse files Browse the repository at this point in the history
  • Loading branch information
chrismarget-j committed Oct 13, 2024
1 parent 6359cb7 commit d51cfc2
Show file tree
Hide file tree
Showing 2 changed files with 106 additions and 11 deletions.
3 changes: 2 additions & 1 deletion apstra/blueprint/datacenter_virtual_network.go
Original file line number Diff line number Diff line change
Expand Up @@ -574,7 +574,8 @@ func (o *DatacenterVirtualNetwork) Request(ctx context.Context, diags *diag.Diag
if o.Type.ValueString() == apstra.VnTypeVlan.String() {
// Exactly one binding is required when type==vlan.
// Apstra requires vlan == vni when creating a "vlan" type VN.
if vnBindings[0].VlanId != nil {
// VNI attribute is forbidden when type == VLAN
if len(vnBindings) > 0 && vnBindings[0].VlanId != nil { //todo is this right?
v := apstra.VNI(*vnBindings[0].VlanId)
vnId = &v
}
Expand Down
114 changes: 104 additions & 10 deletions apstra/resource_datacenter_virtual_network_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ type resourceDatacenterVirtualNetworkTemplate struct {
func (o resourceDatacenterVirtualNetworkTemplate) render(rType, rName string) string {
bindings := new(strings.Builder)
if o.bindings == nil {
return "null"
bindings.WriteString("null")
} else {
bindings.WriteString("{")
for _, binding := range o.bindings {
Expand Down Expand Up @@ -146,11 +146,11 @@ func TestAccDatacenterVirtualNetwork(t *testing.T) {
client := testutils.GetTestClient(t, ctx)
apiVersion := version.Must(version.NewVersion(client.ApiVersion()))

bp, err := client.NewTwoStageL3ClosClient(ctx, "ab4468ce-c007-441c-876c-5cec6566496b")
szId := apstra.ObjectId("H0NOxllV2AQ2qRroxA")
////Create blueprint and routing zone
//bp := testutils.BlueprintC(t, ctx)
//szId := testutils.SecurityZoneA(t, ctx, bp, true)
//bp, err := client.NewTwoStageL3ClosClient(ctx, "ab4468ce-c007-441c-876c-5cec6566496b")
//szId := apstra.ObjectId("H0NOxllV2AQ2qRroxA")
//Create blueprint and routing zone
bp := testutils.BlueprintC(t, ctx)
szId := testutils.SecurityZoneA(t, ctx, bp, true)

type node struct {
Label string `json:"label"`
Expand All @@ -160,7 +160,7 @@ func TestAccDatacenterVirtualNetwork(t *testing.T) {
var systemNodesResponse struct {
Nodes map[string]node `json:"nodes"`
}
err = bp.GetNodes(ctx, apstra.NodeTypeSystem, &systemNodesResponse)
err := bp.GetNodes(ctx, apstra.NodeTypeSystem, &systemNodesResponse)
require.NoError(t, err)

var redundancyGroupNodesResponse struct {
Expand All @@ -187,14 +187,25 @@ func TestAccDatacenterVirtualNetwork(t *testing.T) {
}

testCases := map[string]testCase{
"no_bindings": {
"no_bindings_vlan": {
apiVersionConstraints: compatibility.VnEmptyBindingsOk,
steps: []testStep{
{
config: resourceDatacenterVirtualNetworkTemplate{
blueprintId: bp.Id(),
name: acctest.RandString(6),
vnType: apstra.VnTypeVxlan.String(),
vnType: apstra.VnTypeVlan.String(),
vni: nil,
routingZoneId: szId,
l3Mtu: nil,
bindings: nil,
},
},
{
config: resourceDatacenterVirtualNetworkTemplate{
blueprintId: bp.Id(),
name: acctest.RandString(6),
vnType: apstra.VnTypeVlan.String(),
vni: nil,
routingZoneId: szId,
l3Mtu: nil,
Expand All @@ -203,7 +214,7 @@ func TestAccDatacenterVirtualNetwork(t *testing.T) {
},
},
},
"single_leaf_binding": {
"no_bindings_vlxlan": {
apiVersionConstraints: compatibility.VnEmptyBindingsOk,
steps: []testStep{
{
Expand All @@ -214,6 +225,33 @@ func TestAccDatacenterVirtualNetwork(t *testing.T) {
vni: nil,
routingZoneId: szId,
l3Mtu: nil,
bindings: nil,
},
},
{
config: resourceDatacenterVirtualNetworkTemplate{
blueprintId: bp.Id(),
name: acctest.RandString(6),
vnType: apstra.VnTypeVxlan.String(),
vni: nil,
routingZoneId: szId,
l3Mtu: nil,
bindings: nil,
},
},
},
},
"single_leaf_binding_vlan": {
apiVersionConstraints: compatibility.VnEmptyBindingsOk,
steps: []testStep{
{
config: resourceDatacenterVirtualNetworkTemplate{
blueprintId: bp.Id(),
name: acctest.RandString(6),
vnType: apstra.VnTypeVlan.String(),
vni: nil,
routingZoneId: szId,
l3Mtu: nil,
bindings: []resourceDatacenterVirtualNetworkTemplateBinding{
{
leafId: labelToNodeId["l2_one_access_001_leaf1"],
Expand All @@ -223,6 +261,62 @@ func TestAccDatacenterVirtualNetwork(t *testing.T) {
},
},
},
{
config: resourceDatacenterVirtualNetworkTemplate{
blueprintId: bp.Id(),
name: acctest.RandString(6),
vnType: apstra.VnTypeVlan.String(),
vni: nil,
routingZoneId: szId,
l3Mtu: nil,
bindings: []resourceDatacenterVirtualNetworkTemplateBinding{
{
leafId: labelToNodeId["l2_one_access_001_leaf1"],
vlanId: utils.ToPtr(11),
accessIds: []string{labelToNodeId["l2_one_access_001_access1"]},
},
},
},
},
},
},
"single_leaf_binding_vxlan": {
apiVersionConstraints: compatibility.VnEmptyBindingsOk,
steps: []testStep{
{
config: resourceDatacenterVirtualNetworkTemplate{
blueprintId: bp.Id(),
name: acctest.RandString(6),
vnType: apstra.VnTypeVxlan.String(),
vni: nil,
routingZoneId: szId,
l3Mtu: nil,
bindings: []resourceDatacenterVirtualNetworkTemplateBinding{
{
leafId: labelToNodeId["l2_one_access_001_leaf1"],
vlanId: utils.ToPtr(20),
accessIds: []string{labelToNodeId["l2_one_access_001_access1"]},
},
},
},
},
{
config: resourceDatacenterVirtualNetworkTemplate{
blueprintId: bp.Id(),
name: acctest.RandString(6),
vnType: apstra.VnTypeVxlan.String(),
vni: nil,
routingZoneId: szId,
l3Mtu: nil,
bindings: []resourceDatacenterVirtualNetworkTemplateBinding{
{
leafId: labelToNodeId["l2_one_access_001_leaf1"],
vlanId: utils.ToPtr(21),
accessIds: []string{labelToNodeId["l2_one_access_001_access1"]},
},
},
},
},
},
},
}
Expand Down

0 comments on commit d51cfc2

Please sign in to comment.