Skip to content

Commit

Permalink
CR comments: add ", subnets-diff-info:" anyways
Browse files Browse the repository at this point in the history
  • Loading branch information
ShiriMoran committed Nov 12, 2023
1 parent b96d4f0 commit c22f773
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 37 deletions.
18 changes: 9 additions & 9 deletions pkg/ibmvpc/examples/acl_testing5subnetsDiff.txt
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
Analysis for diff between VPC test-vpc-ky1 and VPC test-vpc-ky2
diff-type: added, source: sub1-2-ky, destination: sub1-1-ky, config1: protocol: TCP, config2: No connection
diff-type: added, source: sub1-3-ky, destination: sub1-1-ky, config1: protocol: TCP, config2: No connection
diff-type: changed, source: sub1-1-ky, destination: sub1-2-ky, config1: protocol: TCP, config2: protocol: TCP *
diff-type: changed, source: sub1-1-ky, destination: sub1-3-ky, config1: protocol: TCP, config2: protocol: TCP *
diff-type: changed, source: sub2-1-ky, destination: Public Internet [8.8.8.8/32], config1: protocol: UDP dst-ports: 53, config2: protocol: UDP dst-ports: 43,53
diff-type: removed, source: sub2-1-ky, destination: Public Internet [8.8.8.0/29], config1: No connection, config2: protocol: UDP dst-ports: 53 *
diff-type: removed, source: sub2-1-ky, destination: Public Internet [8.8.8.10/31], config1: No connection, config2: protocol: UDP dst-ports: 53 *
diff-type: removed, source: sub2-1-ky, destination: Public Internet [8.8.8.12/30], config1: No connection, config2: protocol: UDP dst-ports: 53 *
diff-type: removed, source: sub2-1-ky, destination: Public Internet [8.8.8.9/32], config1: No connection, config2: protocol: UDP dst-ports: 53 *
diff-type: added, source: sub1-2-ky, destination: sub1-1-ky, config1: protocol: TCP, config2: No connection, subnets-diff-info:
diff-type: added, source: sub1-3-ky, destination: sub1-1-ky, config1: protocol: TCP, config2: No connection, subnets-diff-info:
diff-type: changed, source: sub1-1-ky, destination: sub1-2-ky, config1: protocol: TCP, config2: protocol: TCP *, subnets-diff-info:
diff-type: changed, source: sub1-1-ky, destination: sub1-3-ky, config1: protocol: TCP, config2: protocol: TCP *, subnets-diff-info:
diff-type: changed, source: sub2-1-ky, destination: Public Internet [8.8.8.8/32], config1: protocol: UDP dst-ports: 53, config2: protocol: UDP dst-ports: 43,53, subnets-diff-info:
diff-type: removed, source: sub2-1-ky, destination: Public Internet [8.8.8.0/29], config1: No connection, config2: protocol: UDP dst-ports: 53 *, subnets-diff-info:
diff-type: removed, source: sub2-1-ky, destination: Public Internet [8.8.8.10/31], config1: No connection, config2: protocol: UDP dst-ports: 53 *, subnets-diff-info:
diff-type: removed, source: sub2-1-ky, destination: Public Internet [8.8.8.12/30], config1: No connection, config2: protocol: UDP dst-ports: 53 *, subnets-diff-info:
diff-type: removed, source: sub2-1-ky, destination: Public Internet [8.8.8.9/32], config1: No connection, config2: protocol: UDP dst-ports: 53 *, subnets-diff-info:
34 changes: 17 additions & 17 deletions pkg/vpcmodel/diffSubnets_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,15 @@ import (
// subnet3 -> subnet2
// subnet3 -> subnet4

// expected diff cfg1 subtract cfg2:
// cfg1 subtract cfg2
// expected diff cfg1 connMissingOrChanged cfg2:
// cfg1 connMissingOrChanged cfg2
// subnet0 -> subnet1 missing src and dst
// subnet1 -> subnet2 missing src
// subnet3 -> subnet1 missing dst
// subnet2 -> subnet3 missing connection
//
// cfg2 subtract cfg1
// subnet1 subtract subnet2:
// cfg2 connMissingOrChanged cfg1
// subnet1 connMissingOrChanged subnet2:
// subnet3 -> subnet4 different connection

func configSimpleSubnetSubtract() (subnetConfigConn1, subnetConfigConn2 *SubnetConfigConnectivity) {
Expand Down Expand Up @@ -80,7 +80,7 @@ func configSimpleSubnetSubtract() (subnetConfigConn1, subnetConfigConn2 *SubnetC

func TestSimpleSubnetSubtract(t *testing.T) {
subnetConfigConn1, subnetConfigConn2 := configSimpleSubnetSubtract()
subnet1Subtract2, err := subnetConfigConn1.subtract(subnetConfigConn2, true)
subnet1Subtract2, err := subnetConfigConn1.connMissingOrChanged(subnetConfigConn2, true)
if err != nil {
fmt.Println("error:", err.Error())
}
Expand All @@ -94,13 +94,13 @@ func TestSimpleSubnetSubtract(t *testing.T) {
require.Contains(t, subnet1Subtract2Str, "diff-type: added, source: subnet1, destination: subnet2, "+
"config1: All Connections, config2: No connection, subnets-diff-info: subnet1 added")
require.Contains(t, subnet1Subtract2Str, "diff-type: added, source: subnet2, destination: subnet3, "+
"config1: All Connections, config2: No connection")
"config1: All Connections, config2: No connection, subnets-diff-info:")
require.Contains(t, subnet1Subtract2Str, "diff-type: added, source: subnet3, destination: subnet1, "+
"config1: All Connections, config2: No connection, subnets-diff-info: subnet1 added")
require.Contains(t, subnet1Subtract2Str, "diff-type: changed, source: subnet3, destination: subnet4, config1: "+
"protocol: TCP src-ports: 10-100 dst-ports: 443, config2: All Connections\n")
require.Contains(t, subnet1Subtract2Str, "diff-type: changed, source: subnet3, destination: subnet4, "+
"config1: protocol: TCP src-ports: 10-100 dst-ports: 443, config2: All Connections, subnets-diff-info:")

cfg2Subtract1, err := subnetConfigConn2.subtract(subnetConfigConn1, false)
cfg2Subtract1, err := subnetConfigConn2.connMissingOrChanged(subnetConfigConn1, false)
if err != nil {
fmt.Println("error:", err.Error())
}
Expand Down Expand Up @@ -165,7 +165,7 @@ func TestSimpleIPAndSubnetSubtract(t *testing.T) {
}

// verified bit by bit :-)
cfg1SubCfg2, err := alignedCfgConn1.subtract(alignedCfgConn2, true)
cfg1SubCfg2, err := alignedCfgConn1.connMissingOrChanged(alignedCfgConn2, true)
if err != nil {
fmt.Println("error:", err.Error())
}
Expand All @@ -175,17 +175,17 @@ func TestSimpleIPAndSubnetSubtract(t *testing.T) {
newLines := strings.Count(cfg1SubtractCfg2Str, "\n")
require.Equal(t, 7, newLines)
require.Contains(t, cfg1SubtractCfg2Str, "diff-type: added, source: Public Internet [250.2.4.128/25], destination: subnet2, "+
"config1: All Connections, config2: No connection")
"config1: All Connections, config2: No connection, subnets-diff-info:")
require.Contains(t, cfg1SubtractCfg2Str, "diff-type: added, source: Public Internet [250.2.4.16/28], destination: subnet2, "+
"config1: All Connections, config2: No connection")
"config1: All Connections, config2: No connection, subnets-diff-info:")
require.Contains(t, cfg1SubtractCfg2Str, "diff-type: added, source: Public Internet [250.2.4.32/27], destination: subnet2, "+
"config1: All Connections, config2: No connection")
"config1: All Connections, config2: No connection, subnets-diff-info:")
require.Contains(t, cfg1SubtractCfg2Str, "diff-type: added, source: Public Internet [250.2.4.4/30], destination: subnet2, "+
"config1: All Connections, config2: No connection")
"config1: All Connections, config2: No connection, subnets-diff-info:")
require.Contains(t, cfg1SubtractCfg2Str, "diff-type: added, source: Public Internet [250.2.4.64/26], destination: subnet2, "+
"config1: All Connections, config2: No connection")
"config1: All Connections, config2: No connection, subnets-diff-info:")
require.Contains(t, cfg1SubtractCfg2Str, "diff-type: added, source: Public Internet [250.2.4.8/29], destination: subnet2, "+
"config1: All Connections, config2: No connection")
"config1: All Connections, config2: No connection, subnets-diff-info:")
require.Contains(t, cfg1SubtractCfg2Str, "diff-type: changed, source: subnet2, destination: Public Internet [200.2.4.0/24], "+
"config1: All Connections, config2: protocol: TCP src-ports: 0-1000 dst-ports: 0-443")
"config1: All Connections, config2: protocol: TCP src-ports: 0-1000 dst-ports: 0-443, subnets-diff-info:")
}
21 changes: 10 additions & 11 deletions pkg/vpcmodel/semanticDiffSubnets.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,11 +67,11 @@ func (configs ConfigsForDiff) GetSubnetsDiff(grouping bool) (*DiffBetweenSubnets
if err != nil {
return nil, err
}
subnet1Subtract2, err1 := alignedConfigConnectivity1.subtract(alignedConfigConnectivity2, true)
subnet1Subtract2, err1 := alignedConfigConnectivity1.connMissingOrChanged(alignedConfigConnectivity2, true)
if err1 != nil {
return nil, err1
}
subnet2Subtract1, err2 := alignedConfigConnectivity2.subtract(alignedConfigConnectivity1, false)
subnet2Subtract1, err2 := alignedConfigConnectivity2.connMissingOrChanged(alignedConfigConnectivity1, false)
if err2 != nil {
return nil, err2
}
Expand Down Expand Up @@ -105,12 +105,12 @@ func (c *VPCConfig) getVPCResourceInfInOtherConfig(other *VPCConfig, ep VPCResou
return nil, nil
}

// subtract Subtract one SubnetConnectivityMap from the other:
// connMissingOrChanged of subnetConfConnectivity w.r.t. the other:
// connections may be identical, non-existing in other or existing in other but changed;
// the latter are included only if includeChanged, to avoid duplication in the final presentation
//
// assumption: any connection from connectivity and "other" have src (dst) which are either disjoint or equal
func (subnetConfConnectivity *SubnetConfigConnectivity) subtract(other *SubnetConfigConnectivity, includeChanged bool) (
func (subnetConfConnectivity *SubnetConfigConnectivity) connMissingOrChanged(other *SubnetConfigConnectivity, includeChanged bool) (
connectivitySubtract SubnetsDiff, err error) {
connectivitySubtract = map[VPCResourceIntf]map[VPCResourceIntf]*connectionDiff{}
for src, endpointConns := range subnetConfConnectivity.subnetConnectivity {
Expand Down Expand Up @@ -194,7 +194,7 @@ func (subnetDiff *SubnetsDiff) EnhancedString(thisMinusOther bool) string {
conn2Str = connStr(connDiff.conn1)
}
diffType, endpointsDiff := diffAndEndpointsDisc(connDiff.diff, src, dst, thisMinusOther)
printDiff := fmt.Sprintf("diff-type: %s, source: %s, destination: %s, config1: %s, config2: %s%s\n",
printDiff := fmt.Sprintf("diff-type: %s, source: %s, destination: %s, config1: %s, config2: %s, subnets-diff-info: %s\n",
diffType, src.Name(), dst.Name(), conn1Str, conn2Str, endpointsDiff)
strList = append(strList, printDiff)
}
Expand All @@ -214,8 +214,7 @@ func connStr(conn *common.ConnectionSet) string {

func diffAndEndpointsDisc(diff DiffType, src, dst VPCResourceIntf, thisMinusOther bool) (diffDisc, workLoad string) {
const (
subnetsDiffInfo = ", subnets-diff-info:"
tripleString = "%s %s %s"
doubleString = "%s %s"
)
addOrRemoved := ""
if thisMinusOther {
Expand All @@ -225,12 +224,12 @@ func diffAndEndpointsDisc(diff DiffType, src, dst VPCResourceIntf, thisMinusOthe
}
switch diff {
case missingSrcEP:
return addOrRemoved, fmt.Sprintf(tripleString, subnetsDiffInfo, src.Name(), addOrRemoved)
return addOrRemoved, fmt.Sprintf(doubleString, src.Name(), addOrRemoved)
case missingDstEP:
return addOrRemoved, fmt.Sprintf(tripleString, subnetsDiffInfo, dst.Name(), addOrRemoved)
return addOrRemoved, fmt.Sprintf(doubleString, dst.Name(), addOrRemoved)
case missingSrcDstEP:
return addOrRemoved, fmt.Sprintf("%s %s and %s %s",
subnetsDiffInfo, src.Name(), dst.Name(), addOrRemoved)
return addOrRemoved, fmt.Sprintf("%s and %s %s",
src.Name(), dst.Name(), addOrRemoved)
case missingConnection:
return addOrRemoved, ""
case changedConnection:
Expand Down

0 comments on commit c22f773

Please sign in to comment.