Skip to content

855 grouping legal graph #908

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 41 commits into from
Oct 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
41 commits
Select commit Hold shift + click to select a range
ad8c18f
test that demonstrates the problem - that the resulting grouped cidr …
ShiriMoran Sep 29, 2024
7c6a90f
Merge remote-tracking branch 'origin/main' into 855_grouping_legal_graph
ShiriMoran Sep 30, 2024
2ae832b
added relevant tests to work with while developing
ShiriMoran Sep 30, 2024
782abe3
towards solution of https://github.com/np-guard/vpc-network-config-an…
ShiriMoran Sep 30, 2024
21e2916
Merge branch 'main' into 855_grouping_legal_graph
ShiriMoran Oct 1, 2024
4d6338f
code to add edges; not yet checked
ShiriMoran Oct 1, 2024
67b52a9
refactor: new code to another file
ShiriMoran Oct 6, 2024
7fd6f41
self CR fixed
ShiriMoran Oct 6, 2024
b5fe16a
added new parm to tests
ShiriMoran Oct 6, 2024
564c734
Export parm
ShiriMoran Oct 6, 2024
cd24c4d
initialization bug fixes
ShiriMoran Oct 6, 2024
a18daa4
typo bug fix
ShiriMoran Oct 6, 2024
ded2434
added to test name and added test; test not working yet (same as before)
ShiriMoran Oct 6, 2024
90f2de4
use NameForAnalyzerOut(..) instead of Name()
ShiriMoran Oct 6, 2024
bb14f73
bug fix, test is now working properly
ShiriMoran Oct 6, 2024
0bed373
added tests; with grouping not working properly yet
ShiriMoran Oct 7, 2024
9ba4bc0
somehow it got deleted
ShiriMoran Oct 7, 2024
59fbb7c
generalization
ShiriMoran Oct 7, 2024
48169a9
added todos as to what should be done
ShiriMoran Oct 8, 2024
8ad74a9
refactored first 3 stages to work with srcToDst and dstToSrc
ShiriMoran Oct 8, 2024
189752c
typo fix
ShiriMoran Oct 8, 2024
ab47848
computations adjustments
ShiriMoran Oct 8, 2024
d5f418a
adding edges
ShiriMoran Oct 8, 2024
26b43f1
add edges
ShiriMoran Oct 8, 2024
d53a243
fix bug
ShiriMoran Oct 8, 2024
06087a1
not working since external networks are oblivious to sub cidrs
ShiriMoran Oct 8, 2024
b4ca0b6
restoring the older version - which now seems ok, given that adding t…
ShiriMoran Oct 8, 2024
488ff33
removed temp code
ShiriMoran Oct 8, 2024
6d1e004
adjusted tests to the new code
ShiriMoran Oct 9, 2024
f21e7f1
lint
ShiriMoran Oct 9, 2024
efbabc1
refactored alg
ShiriMoran Oct 9, 2024
62fc9a1
added example yet to complete manually verification
ShiriMoran Oct 9, 2024
59e4cbd
test verified manually
ShiriMoran Oct 9, 2024
7dc07d8
added html test
ShiriMoran Oct 9, 2024
8b6cd6f
CR: merge grouping and consistencyEdges parms
ShiriMoran Oct 9, 2024
bd4b85d
lint
ShiriMoran Oct 9, 2024
448944d
Update pkg/vpcmodel/groupingGraphical.go
ShiriMoran Oct 9, 2024
aafaeac
Update pkg/vpcmodel/groupingGraphical.go
ShiriMoran Oct 9, 2024
9137aaf
CR
ShiriMoran Oct 9, 2024
b02cc08
Merge remote-tracking branch 'origin/855_grouping_legal_graph' into 8…
ShiriMoran Oct 9, 2024
99ad366
CR
ShiriMoran Oct 9, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 15 additions & 1 deletion cmd/analyzer/subcmds/analysis.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ package subcmds
import (
"errors"
"fmt"
"slices"

"github.com/spf13/cobra"

Expand Down Expand Up @@ -79,8 +80,21 @@ func analysisVPCConfigs(cmd *cobra.Command, inArgs *inArgs, analysisType vpcmode
return err
}
outFormat := inArgs.outputFormat.ToModelFormat()
consistencyEdgesExternal := slices.Contains([]vpcmodel.OutFormat{vpcmodel.DRAWIO, vpcmodel.SVG, vpcmodel.HTML},
outFormat)
var groupingType int
switch {
case !inArgs.grouping && !consistencyEdgesExternal:
groupingType = vpcmodel.NoGroupingNoConsistencyEdges
case !inArgs.grouping && consistencyEdgesExternal:
groupingType = vpcmodel.NoGroupingWithConsistencyEdges
case inArgs.grouping && !consistencyEdgesExternal:
groupingType = vpcmodel.GroupingNoConsistencyEdges
default:
groupingType = vpcmodel.GroupingWithConsistencyEdges
}
og, err := vpcmodel.NewOutputGenerator(vpcConfigs,
inArgs.grouping,
groupingType,
analysisType,
false,
inArgs.explanationArgs, outFormat, inArgs.lbAbstraction)
Expand Down
4 changes: 2 additions & 2 deletions pkg/commonvpc/testfunc/analysis_output_test_functionality.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import (

type VpcAnalysisTest struct {
VpcTestCommon
Grouping bool
GroupingType int
NoLbAbstract bool
}

Expand All @@ -24,6 +24,6 @@ func (tt *VpcAnalysisTest) TestAnalysisSingleTest(t *testing.T, mode testMode, r
tt.setMode(mode)
t.Run(tt.Name, func(t *testing.T) {
t.Parallel()
tt.runSingleCommonTest(t, testDir, rc, tt.Grouping, tt.NoLbAbstract, nil)
tt.runSingleCommonTest(t, testDir, rc, tt.GroupingType, tt.NoLbAbstract, nil)
})
}
27 changes: 20 additions & 7 deletions pkg/commonvpc/testfunc/common_test_functionality.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ const (
suffixOutFileDiffEndpoints = "endpointsDiff"
suffixOutFileExplain = "explain"
suffixOutFileDetail = "_detail"
consistencyEdgesExternal = "_EdgeConsistent"
txtOutSuffix = ".txt"
mdOutSuffix = ".md"
JSONOutSuffix = ".json"
Expand Down Expand Up @@ -86,6 +87,7 @@ func getTestFileName(testName string,
grouping bool,
noLbAbstract bool,
detailExplain bool,
addConsistencyEdgesExternal bool,
format vpcmodel.OutFormat,
configName string,
allVPCs bool,
Expand Down Expand Up @@ -128,6 +130,9 @@ func getTestFileName(testName string,
if detailExplain {
res += suffixOutFileDetail
}
if addConsistencyEdgesExternal {
res += consistencyEdgesExternal
}
if !allVPCs {
res += strings.ReplaceAll(strings.Join(vpcIDs, ""), ":", "")
}
Expand Down Expand Up @@ -174,9 +179,10 @@ func (tt *VpcTestCommon) initTest() {
}

func (tt *VpcTestCommon) initTestFileNames(uc vpcmodel.OutputUseCase,
vpcName string, allVPCs, detailExplain bool, testDirOut string, grouping, noLbAbstract bool) error {
vpcName string, allVPCs, detailExplain bool, testDirOut string, grouping, noLbAbstract,
addConsistencyEdgesExternal bool) error {
expectedFileName, actualFileName, err := getTestFileName(
tt.Name, uc, grouping, noLbAbstract, detailExplain, tt.Format, vpcName, allVPCs, tt.VpcList)
tt.Name, uc, grouping, noLbAbstract, detailExplain, addConsistencyEdgesExternal, tt.Format, vpcName, allVPCs, tt.VpcList)
if err != nil {
return err
}
Expand All @@ -191,17 +197,23 @@ func (tt *VpcTestCommon) runTestPerUseCase(t *testing.T,
uc vpcmodel.OutputUseCase,
mode testMode,
outDir string,
grouping, noLbAbstract bool,
groupingType int,
noLbAbstract bool,
explanationArgs *vpcmodel.ExplanationArgs) error {
detailExplain := false
if explanationArgs != nil {
detailExplain = explanationArgs.Detail
}
allVpcs := len(tt.VpcList) == 0
if err := tt.initTestFileNames(uc, "", allVpcs, detailExplain, outDir, grouping, noLbAbstract); err != nil {
grouping := groupingType == vpcmodel.GroupingNoConsistencyEdges ||
groupingType == vpcmodel.GroupingWithConsistencyEdges
addConsistencyEdgesExternal := groupingType == vpcmodel.NoGroupingWithConsistencyEdges ||
groupingType == vpcmodel.GroupingWithConsistencyEdges
if err := tt.initTestFileNames(uc, "", allVpcs, detailExplain, outDir, grouping, noLbAbstract,
addConsistencyEdgesExternal); err != nil {
return err
}
og, err := vpcmodel.NewOutputGenerator(cConfigs, grouping, uc, tt.Format == vpcmodel.ARCHDRAWIO,
og, err := vpcmodel.NewOutputGenerator(cConfigs, groupingType, uc, tt.Format == vpcmodel.ARCHDRAWIO,
explanationArgs, tt.Format, !noLbAbstract)
if err != nil {
return err
Expand Down Expand Up @@ -326,7 +338,7 @@ func (tt *VpcTestCommon) setMode(mode testMode) {
}

func (tt *VpcTestCommon) runSingleCommonTest(t *testing.T, testDir string, rc commonvpc.ResourcesContainer,
grouping, noLbAbstract bool, explanationArgs *vpcmodel.ExplanationArgs) {
groupingType int, noLbAbstract bool, explanationArgs *vpcmodel.ExplanationArgs) {
// init test - set the input/output file names according to test name
tt.initTest()

Expand All @@ -335,7 +347,8 @@ func (tt *VpcTestCommon) runSingleCommonTest(t *testing.T, testDir string, rc co

// generate actual output for all use cases specified for this test
for _, uc := range tt.UseCases {
err := tt.runTestPerUseCase(t, vpcConfigs, uc, tt.Mode, testDir, grouping, noLbAbstract, explanationArgs)
err := tt.runTestPerUseCase(t, vpcConfigs, uc, tt.Mode, testDir, groupingType, noLbAbstract,
explanationArgs)
require.Equal(t, tt.ErrPerUseCase[uc], err, "comparing actual err to expected err")
}
for uc, outFile := range tt.ActualOutput {
Expand Down
2 changes: 1 addition & 1 deletion pkg/commonvpc/testfunc/explain_test_functionality.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,6 @@ func (tt *VpcExplainTest) TestSingleExplain(t *testing.T, mode testMode, rc comm
tt.Format = vpcmodel.Text
t.Run(tt.Name, func(t *testing.T) {
t.Parallel()
tt.runSingleCommonTest(t, explainOut, rc, false, false, explanationArgs)
tt.runSingleCommonTest(t, explainOut, rc, vpcmodel.NoGroupingNoConsistencyEdges, false, explanationArgs)
})
}
4 changes: 3 additions & 1 deletion pkg/commonvpc/testfunc/semantic_diff_test_functionality.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import (
"github.com/stretchr/testify/require"

"github.com/np-guard/vpc-network-config-analyzer/pkg/commonvpc"
"github.com/np-guard/vpc-network-config-analyzer/pkg/vpcmodel"
)

const secJSONOutSuffix = "_2nd.json"
Expand Down Expand Up @@ -44,7 +45,8 @@ func (tt *VpcDiffTest) runDiffSingleTest(t *testing.T, testDir string, rc common

// generate actual output for all use cases specified for this test
for _, uc := range tt.UseCases {
err := tt.runTestPerUseCase(t, vpcConfigs, uc, tt.Mode, testDir, false, false, nil)
err := tt.runTestPerUseCase(t, vpcConfigs, uc, tt.Mode, testDir, vpcmodel.NoGroupingNoConsistencyEdges, false,
nil)
require.Equal(t, tt.ErrPerUseCase[uc], err, "comparing diff's actual err to expected err")
}
for uc, outFile := range tt.ActualOutput {
Expand Down
Loading